-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathAampProfiler.h
More file actions
472 lines (417 loc) · 14.9 KB
/
AampProfiler.h
File metadata and controls
472 lines (417 loc) · 14.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
/*
* If not stated otherwise in this file or this component's license file the
* following copyright and licenses apply:
*
* Copyright 2020 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file AampProfiler.h
* @brief ProfileEventAAMP header file
*/
#ifndef __AAMP_PROFILER_H__
#define __AAMP_PROFILER_H__
#include <mutex>
#include <list>
#include <sstream>
#include <string>
#include <cjson/cJSON.h>
#include "AampLogManager.h"
/**
* @addtogroup AAMP_COMMON_TYPES
* @{
*/
/**
* @enum ProfilerBucketType
* @brief Bucket types of AAMP profiler
*/
typedef enum
{
PROFILE_BUCKET_MANIFEST, /**< Manifest download bucket*/
PROFILE_BUCKET_PLAYLIST_VIDEO, /**< Video playlist download bucket*/
PROFILE_BUCKET_PLAYLIST_AUDIO, /**< Audio playlist download bucket*/
PROFILE_BUCKET_PLAYLIST_SUBTITLE, /**< Subtitle playlist download bucket*/
PROFILE_BUCKET_INIT_VIDEO, /**< Video init fragment download bucket*/
PROFILE_BUCKET_INIT_AUDIO, /**< Audio init fragment download bucket*/
PROFILE_BUCKET_INIT_SUBTITLE, /**< Subtitle fragment download bucket*/
PROFILE_BUCKET_FRAGMENT_VIDEO, /**< Video fragment download bucket*/
PROFILE_BUCKET_FRAGMENT_AUDIO, /**< Audio fragment download bucket*/
PROFILE_BUCKET_FRAGMENT_SUBTITLE, /**< Subtitle fragment download bucket*/
PROFILE_BUCKET_DECRYPT_VIDEO, /**< Video decryption bucket*/
PROFILE_BUCKET_DECRYPT_AUDIO, /**< Audio decryption bucket*/
PROFILE_BUCKET_DECRYPT_SUBTITLE, /**< Subtitle decryption bucket*/
PROFILE_BUCKET_LA_TOTAL, /**< License acquisition total bucket*/
PROFILE_BUCKET_LA_PREPROC, /**< License acquisition pre-processing bucket*/
PROFILE_BUCKET_LA_NETWORK, /**< License acquisition network operation bucket*/
PROFILE_BUCKET_LA_POSTPROC, /**< License acquisition post-processing bucket*/
PROFILE_BUCKET_FIRST_BUFFER, /**< First buffer to gstreamer bucket*/
PROFILE_BUCKET_FIRST_FRAME, /**< First frame displayed bucket*/
PROFILE_BUCKET_PLAYER_PRE_BUFFERED, /**< Prebuffer bucket ( BG to FG )*/
PROFILE_BUCKET_DISCO_TOTAL, /**< Discontinuity transition total bucket*/
PROFILE_BUCKET_DISCO_FLUSH, /**< Discontinuity transition pipeline flush bucket*/
PROFILE_BUCKET_DISCO_FIRST_FRAME, /**< Discontinuity transition first frame displayed bucket*/
PROFILE_BUCKET_TYPE_COUNT, /**< Bucket count*/
PROFILE_BUCKET_INVALID =255
} ProfilerBucketType;
/**
* @enum ClassicProfilerBucketType
* @brief Bucket types of classic profiler
*/
typedef enum
{
TuneTimeBaseTime, /**< Tune time base*/
TuneTimeBeginLoad, /**< Player load time*/
TuneTimePrepareToPlay, /**< Manifest ready time*/
TuneTimePlay, /**< Profiles ready time*/
TuneTimeDrmReady, /**< DRM ready time*/
TuneTimeStartStream, /**< First buffer insert time*/
TuneTimeStreaming, /**< First frame display time*/
TuneTimeBackToXre, /**< Tune status back to XRE time*/
TuneTimeMax /**< Max bucket type*/
} ClassicProfilerBucketType;
/**
* @enum ContentType
* @brief Asset's content types
*/
enum CountType
{
Count_RateCorrection, /**< 0 - Rate correction count */
Count_BufferChange, /**< 1 - Buffer change count*/
Count_BitrateChange, /**< 2 - Bitrate change count */
};
/**
* @enum ContentType
* @brief Asset's content types
*/
enum ContentType
{
ContentType_UNKNOWN, /**< 0 - Unknown type */
ContentType_CDVR, /**< 1 - CDVR */
ContentType_VOD, /**< 2 - VOD */
ContentType_LINEAR, /**< 3 - Linear */
ContentType_IVOD, /**< 4 - IVOD */
ContentType_EAS, /**< 5 - EAS */
ContentType_CAMERA, /**< 6 - Camera */
ContentType_DVR, /**< 7 - DVR */
ContentType_MDVR, /**< 8 - MDVR */
ContentType_IPDVR, /**< 9 - IPDVR */
ContentType_PPV, /**< 10 - PPV */
ContentType_OTT, /**< 11 - OTT */
ContentType_OTA, /**< 12 - OTA*/
ContentType_HDMIIN, /**< 13 - HDMI Input */
ContentType_COMPOSITEIN, /**< 14 - COMPOSITE Input*/
ContentType_SLE, /**< 15 - SLE - Single Live Event (kind of iVOD)*/
ContentType_MAX /**< 16 - Type Count*/
};
/**
* @struct TuneEndMetrics
* @brief TuneEndMetrics structure to store tunemetrics data
*/
typedef struct
{
int success; /**< Flag indicate whether the tune is success or not */
int streamType; /**< Media stream Type */
int mTimedMetadata; /**< Total no.of TimedMetaData(Ads) processed in the manifest*/
long long mTimedMetadataStartTime; /**< Time at which timedmetadata event starts sending */
int mTimedMetadataDuration; /**< Time Taken to send TiedMetaData event*/
int mTuneAttempts; /**< No of tune attempts taken */
bool mFirstTune; /**< To identify the first tune after load.*/
bool mFogTSBEnabled; /**< Flag to indicate TSB is enabled or not */
int mTotalTime;
ContentType contentType;
}TuneEndMetrics;
/**
* @}
*/
/**
* @class ProfileEventAAMP
* @brief Class for AAMP event Profiling
*/
class ProfileEventAAMP
{
private:
// TODO: include settop type (to distinguish settop performance)
// TODO: include flag to indicate whether FOG used (to isolate FOG overhead)
/**
* @brief Class corresponding to tune time events.
*/
class TuneEvent
{
public:
ProfilerBucketType id; /**< Event identifier */
unsigned int start; /**< Event start time */
unsigned int duration; /**< Event duration */
int result; /**< Event result */
/**
* @brief TuneEvent Constructor
* @param[in] i - Event id
* @param[in] s - Event start time
* @param[in] d - Event duration
* @param[in] r - Event result
*/
TuneEvent(ProfilerBucketType i, unsigned int s, unsigned int d, int r):
id(i), start(s), duration(d), result(r)
{
}
};
/**
* @brief Data structure corresponding to profiler bucket
*/
struct ProfilerBucket
{
unsigned int tStart; /**< Relative start time of operation, based on tuneStartMonotonicBase */
unsigned int tFinish; /**< Relative end time of operation, based on tuneStartMonotonicBase */
int errorCount; /**< non-zero if errors/retries occurred during this operation */
bool complete; /**< true if this step already accounted for, and further profiling should be ignored */
bool profileStarted; /**< Flag that indicates,whether the profiler is started or not */
} buckets[PROFILE_BUCKET_TYPE_COUNT];
/**
* @brief Calculating effecting duration of overlapping buckets, id1 & id2
*/
#define bucketsOverlap(id1,id2) \
buckets[id1].complete && buckets[id2].complete && \
(buckets[id1].tStart <= buckets[id2].tFinish) && (buckets[id2].tStart <= buckets[id1].tFinish)
/**
* @brief Calculating total duration a bucket id
*/
#define bucketDuration(id) \
(buckets[id].complete?(buckets[id].tFinish - buckets[id].tStart):0)
long long tuneStartMonotonicBase; /**< Base time from Monotonic clock for interval calculation */
long long tuneStartBaseUTCMS; /**< common UTC base for start of tune */
long long xreTimeBuckets[TuneTimeMax]; /**< Start time of each buckets for classic metrics conversion */
BitsPerSecond bandwidthBitsPerSecondVideo; /**< Video bandwidth in bps */
BitsPerSecond bandwidthBitsPerSecondAudio; /**< Audio bandwidth in bps */
int drmErrorCode; /**< DRM error code */
bool enabled; /**< Profiler started or not */
std::list<TuneEvent> tuneEventList; /**< List of events happened during tuning */
std::mutex tuneEventListMtx; /**< Mutex protecting tuneEventList */
ProfilerBucketType mTuneFailBucketType; /**< ProfilerBucketType in case of error */
int mTuneFailErrorCode; /**< tune Fail Error Code */
int rateCorrection; /**< Rate correction change count */
int bitrateChange; /**< Bitrate change count */
int bufferChange; /**< buffer change count */
cJSON *telemetryParam; /**< telemetry json object */
cJSON* mLldLowBuffObject; /**< LLD Low Buffer Data json object for telemetry*/
std::mutex discontinuityParamMutex; /**< mutex protecting discontinuity telemetry parameter */
/**
* @brief Calculating effective time of two overlapping buckets.
*
* @param[in] id1 - Bucket type 1
* @param[in] id2 - Bucket type 2
* @return void
*/
inline unsigned int effectiveBucketTime(ProfilerBucketType id1, ProfilerBucketType id2)
{
#if 0
if(bucketsOverlap(id1, id2))
return MAX(buckets[id1].tFinish, buckets[id2].tFinish) - fmin(buckets[id1].tStart, buckets[id2].tStart);
#endif
return bucketDuration(id1) + bucketDuration(id2);
}
public:
/**
* @fn ProfileEventAAMP Constructor
*/
ProfileEventAAMP();
/**
* @brief ProfileEventAAMP Destructor
*/
~ProfileEventAAMP()
{
if(telemetryParam != NULL)
{
cJSON_Delete(telemetryParam);
// mLldLowBuffObject is a child of telemetryParam, so it's automatically deleted above
}
}
/**
* @brief Copy constructor disabled
*
*/
ProfileEventAAMP(const ProfileEventAAMP&) = delete;
/**
* @brief assignment operator disabled
*
*/
ProfileEventAAMP& operator=(const ProfileEventAAMP&) = delete;
/**
* @brief Setting video bandwidth in bps
*
* @param[in] bw - Bandwidth in bps
* @return void
*/
void SetBandwidthBitsPerSecondVideo(BitsPerSecond bw)
{
bandwidthBitsPerSecondVideo = bw;
}
/**
* @brief Setting audio bandwidth in bps
*
* @param[in] bw - Bandwidth in bps
* @return void
*/
void SetBandwidthBitsPerSecondAudio(BitsPerSecond bw)
{
bandwidthBitsPerSecondAudio = bw;
}
/**
* @brief Setting DRM error code
*
* @param[in] errCode - Error code
* @return void
*/
void SetDrmErrorCode(int errCode)
{
drmErrorCode = errCode;
}
/**
* @fn getTuneEventsJSON
*
* @param[out] outSS - Output JSON string
* @param[in] streamType - Stream type
* @param[in] url - Tune URL
* @param[in] success - Tune success/failure
* @return void
*/
void getTuneEventsJSON(std::string &outSS, const std::string &streamType, const char *url, bool success);
/**
* @fn GetTuneMetricInfoasJson
*
* @param[in] tuneMetricsData - tuneend metric data
* @param[in] licenseAcqNWTime - license Acq Network Time
* @param[in] playerPreBuffered - prebuffered mode
* @param[in] durationSeconds - Asset duration in seconds
* @param[in] interfaceWifi - Connection is wifi or not - wifi(1) ethernet(0)
* @param[in] failureReason - Failure Reason
* @param[in] appName - App name
* @return string
*/
std::string GetTuneTimeMetricAsJson(TuneEndMetrics tuneMetricsData, const char *tuneTimeStrPrefix,
unsigned int licenseAcqNWTime, bool playerPreBuffered,
unsigned int durationSeconds, bool interfaceWifi, std::string failureReason, std::string appName);
/**
* @fn TuneBegin
*
* @return void
*/
void TuneBegin(void);
/**
* @fn TuneEnd
* @param[in] mTuneendmetrics - Tune End metrics values
* @param[in] appName - Application Name
* @param[in] playerActiveMode - Aamp Player mode
* @param[in] playerId - Aamp Player id
* @param[in] playerPreBuffered - True/false Player has pre buffered content
* @param[in] durationSeconds - Asset duration in seconds
* @param[in] interfaceWifi - Active connection is Wifi or Ethernet
* @param[in] failureReason - Aamp player failure reason
* @param[out] tuneMetricData - Output JSON string
* @return void
*/
void TuneEnd(TuneEndMetrics &mTuneendmetrics, std::string appName, std::string playerActiveMode, int playerId, bool playerPreBuffered, unsigned int durationSeconds, bool interfaceWifi, std::string failureReason, std::string *tuneMetricData);
/**
* @fn ProfileBegin
*
* @param[in] type - Bucket type
* @return void
*/
void ProfileBegin(ProfilerBucketType type);
/**
* @fn ProfileError
*
* @param[in] type - Bucket type
* @param[in] result - Error code
* @return void
*/
void ProfileError(ProfilerBucketType type, int result = -1);
/**
* @fn ProfileEnd
*
* @param[in] type - Bucket type
* @return void
*/
void ProfileEnd(ProfilerBucketType type);
/**
* @fn ProfileReset
*
* @param[in] type - Bucket type
* @return void
*/
void ProfileReset(ProfilerBucketType type);
/**
* @fn ProfilePerformed
*
* @param[in] type - Bucket type
* @return void
*/
void ProfilePerformed(ProfilerBucketType type);
/**
* @fn SetTuneFailCode
*
* @param[in] tuneFailCode - tune Fail Code
* @param[in] failBucketType - Profiler Bucket type
* @return void
*/
void SetTuneFailCode(int tuneFailCode, ProfilerBucketType failBucketType);
/**
* @fn SetDiscontinuityParam - to mark the discontinuity switch and save the parameters
* @return void
*/
void SetDiscontinuityParam();
/**
* @fn SetLatencyParam - to mark the latency parameters
* @param latency - latency value
* @param buffer - buffer value
* @param playbackRate - current playback rate
* @param bw - current bandwidth
* @return void
*/
void SetLatencyParam(double latency, double buffer, double playbackRate, double bw);
/**
* @fn AddLLDLowBufferObject - API to Add LLD Low buffer object to the telemetry data
* @return void
*/
void AddLLDLowBufferObject();
/**
* @fn AddWithPrecisionNumber - Add 2 digit precision number to json data
* @param item - cjson object to add the item
* @param label -label of the item
* @param num - value of the item
* @return void
*/
void AddWithPrecisionNumber(cJSON* item, const char* label, double num);
/**
* @fn SetLLDLowBufferParam - to mark the LLD low buffer specific latency parameters
* @param latency - latency value
* @param buffer - buffer value
* @param rate - current playback rate
* @param bw - current bandwidth
* @param buffLowCount - Low buffer hit count; Increment continuous data only
* @return void
*/
void SetLLDLowBufferParam(double latency, double buff, double rate, double bw, double buffLowCount);
/**
* @fn IncrementChangeCount - to increment the changes in buffer, ratecorrection and bitrate
* @param[in] type - type (buffer/ratecorrection/bitrate)
* @return void
*/
void IncrementChangeCount(CountType type);
/**
* @fn GetTelemetryParam - to log the telemetry parameters
* @return void
*/
void GetTelemetryParam();
unsigned int mStopDurationMs; /**< Duration of Previous stop call in ms */
};
#endif /* __AAMP_PROFILER_H__ */