-
Notifications
You must be signed in to change notification settings - Fork 0
/
AampLogManager.h
317 lines (278 loc) · 8.41 KB
/
AampLogManager.h
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
/*
* 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.
*/
#ifndef AAMPLOGMANAGER_H
#define AAMPLOGMANAGER_H
/**
* @file AampLogManager.h
* @brief Log managed for Aamp
*/
#include <vector>
#include <string>
#include <memory.h>
#include "AampMediaType.h"
/*================================== AAMP Log Manager =========================================*/
/**
* @brief Direct call for trace printf, can be enabled b defining TRACE here
*/
#ifdef TRACE
#define traceprintf logprintf
#else
#define traceprintf(FORMAT, ...)
#endif
/**
* @brief Macro for validating the log level to be enabled
*
* if mConfig or gpGlobalConfig is not initialized, skip logging
* if mconfig or gpGlobalConfig is initialized, check the LogLevel
*/
#define AAMPLOG( MYLOGOBJ, LEVEL, LEVELSTR, FORMAT, ... ) \
do { \
int PLAYERID; \
if( MYLOGOBJ ) \
{ \
if( !MYLOGOBJ->isLogLevelAllowed(LEVEL) ) break; \
PLAYERID = MYLOGOBJ->getPlayerId(); \
} \
else \
{ \
if( !gpGlobalConfig->logging.isLogLevelAllowed(LEVEL) ) break; \
PLAYERID = -1; \
} \
logprintf_new( PLAYERID, LEVELSTR, __FUNCTION__, __LINE__, FORMAT, ##__VA_ARGS__); \
} while(0)
/**
* @brief Macro for Triage Level Logging Support
*/
#define AAMP_LOG_NETWORK_LATENCY mLogObj->LogNetworkLatency
#define AAMP_LOG_NETWORK_ERROR mLogObj->LogNetworkError
#define AAMP_LOG_DRM_ERROR gpGlobalConfig->logging.LogDRMError
#define AAMP_LOG_ABR_INFO mLogObj->LogABRInfo
#define AAMP_IS_LOG_WORTHY_ERROR mLogObj->isLogworthyErrorCode
#define AAMPLOG_FAILOVER(FORMAT, ...) \
if (mLogObj && mLogObj->failover) { \
logprintf_new(mLogObj->getPlayerId(), "FAILOVER",__FUNCTION__, __LINE__, FORMAT, ##__VA_ARGS__); \
}
/**
* @brief AAMP logging defines, this can be enabled through setLogLevel() as per the need
*/
#define AAMPLOG_TRACE(FORMAT, ...) AAMPLOG(mLogObj,eLOGLEVEL_TRACE, "TRACE", FORMAT, ##__VA_ARGS__)
#define AAMPLOG_INFO(FORMAT, ...) AAMPLOG(mLogObj,eLOGLEVEL_INFO, "INFO", FORMAT, ##__VA_ARGS__)
#define AAMPLOG_WARN(FORMAT, ...) AAMPLOG(mLogObj,eLOGLEVEL_WARN, "WARN", FORMAT, ##__VA_ARGS__)
#define AAMPLOG_ERR(FORMAT, ...) AAMPLOG(mLogObj,eLOGLEVEL_ERROR, "ERROR", FORMAT, ##__VA_ARGS__)
/**
* @brief maximum supported mediatype for latency logging
*/
#define MAX_SUPPORTED_LATENCY_LOGGING_TYPES (eMEDIATYPE_IFRAME+1)
/**
* @brief Log level's of AAMP
*/
enum AAMP_LogLevel
{
eLOGLEVEL_TRACE, /**< Trace level */
eLOGLEVEL_INFO, /**< Info level */
eLOGLEVEL_WARN, /**< Warn level */
eLOGLEVEL_ERROR, /**< Error level */
eLOGLEVEL_FATAL /**< Fatal log level */
};
/**
* @brief Log level network error enum
*/
enum AAMPNetworkErrorType
{
/* 0 */ AAMPNetworkErrorNone, /**< No network Error */
/* 1 */ AAMPNetworkErrorHttp, /**< HTTP error */
/* 2 */ AAMPNetworkErrorTimeout, /**< Timeout Error */
/* 3 */ AAMPNetworkErrorCurl /**< curl Error */
};
/**
* @brief ABR type enum
*/
enum AAMPAbrType
{
/* 0 */ AAMPAbrBandwidthUpdate,
/* 1 */ AAMPAbrManifestDownloadFailed,
/* 2 */ AAMPAbrFragmentDownloadFailed,
/* 3 */ AAMPAbrUnifiedVideoEngine
};
/**
* @brief ABR info structure
*/
struct AAMPAbrInfo
{
AAMPAbrType abrCalledFor;
int currentProfileIndex;
int desiredProfileIndex;
long currentBandwidth;
long desiredBandwidth;
long networkBandwidth;
AAMPNetworkErrorType errorType;
int errorCode;
};
/**
* @class AampLogManager
* @brief AampLogManager Class
*/
class AampLogManager
{
public:
bool info; /**< Info level*/
bool debug; /**< Debug logs*/
bool trace; /**< Trace level*/
bool gst; /**< Gstreamer logs*/
bool curl; /**< Curl logs*/
bool progress; /**< Download progress logs*/
bool failover; /**< server fail over logs*/
bool stream; /**< Display stream contents */
bool curlHeader; /**< Curl header logs*/
bool curlLicense; /**< Curl logs for License request*/
bool logMetadata; /**< Timed metadata logs*/
bool id3; /**< Display ID3 tag from stream logs */
static bool disableLogRedirection;
int mPlayerId; /**< Store PlayerId*/
/**
* @brief AampLogManager constructor
*/
AampLogManager() : aampLoglevel(eLOGLEVEL_WARN), info(false), debug(false), trace(false), gst(false), curl(false), progress(false), failover(false), curlHeader(false),
logMetadata(false), curlLicense(false),stream(false), id3(false),mPlayerId(-1)
{
}
/* ---------- Triage Level Logging Support ---------- */
/**
* @fn LogNetworkLatency
*
* @param[in] url - content url
* @param[in] downloadTime - download time of the fragment or manifest
* @param[in] downloadThresholdTimeoutMs - specified download threshold time out value
* @param[in] type - media type
* @return void
*/
void LogNetworkLatency(const char* url, int downloadTime, int downloadThresholdTimeoutMs, MediaType type);
/**
* @fn LogNetworkError
*
* @param[in] url - content url
* @param[in] errorType - it can be http or curl errors
* @param[in] errorCode - it can be http error or curl error code
* @param[in] type - media type
* @return void
*/
void LogNetworkError(const char* url, AAMPNetworkErrorType errorType, int errorCode, MediaType type);
/**
* @fn ParseContentUrl
*
* @param[in] url - content url
* @param[out] contentType - it could be a manifest or other audio/video/iframe tracks
* @param[out] location - server location
* @param[out] symptom - issue exhibiting scenario for error case
* @param[in] type - media type
* @return void
*/
void ParseContentUrl(const char* url, std::string& contentType, std::string& location, std::string& symptom, MediaType type);
/**
* @fn LogDRMError
*
* @param[in] major - drm major error code
* @param[in] minor - drm minor error code
* @return void
*/
void LogDRMError(int major, int minor);
/**
* @fn LogABRInfo
*
* @param[in] pstAbrInfo - pointer to a structure which will have abr info to be logged
* @return void
*/
void LogABRInfo(AAMPAbrInfo *pstAbrInfo);
/* !---------- Triage Level Logging Support ---------- */
/**
* @fn isLogLevelAllowed
*
* @param[in] chkLevel - log level
* @retval true if the log level allowed for print mechanism
*/
bool isLogLevelAllowed(AAMP_LogLevel chkLevel);
/**
* @brief Set PlayerId
*
* @param[in] playerId - Aamp Player Id
* @return void
*/
void setPlayerId(int playerId) { mPlayerId = playerId;}
/**
* @brief Get PlayerId
*
* @return int - playerId
*/
int getPlayerId() { return mPlayerId;}
/**
* @fn setLogLevel
*
* @param[in] newLevel - log level new value
* @return void
*/
void setLogLevel(AAMP_LogLevel newLevel);
/**
* @fn setLogAndCfgDirectory
*/
void setLogAndCfgDirectory(char driveName);
/**
* @fn isLogworthyErrorCode
* @param[in] errorCode - curl error
* @return true if it is not a curl error 23 and 42, bcasue those are not a real network errors.
*/
bool isLogworthyErrorCode(int errorCode);
/**
* @fn getAampCfgPath
*/
const char* getAampCfgPath(void);
/**
* @fn getAampCliCfgPath
*/
const char* getAampCliCfgPath(void);
/**
* @fn getHexDebugStr
*/
static std::string getHexDebugStr(const std::vector<uint8_t>& data);
private:
AAMP_LogLevel aampLoglevel;
};
extern AampLogManager *mLogObj;
/* Context-free utility function */
/**
* @fn logprintf
* @param[in] format - printf style string
* @return void
*/
extern void logprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));;
/**
* @fn logprintf_new
* @param[in] format - printf style string
* @return void
*/
extern void logprintf_new(int playerId,const char* levelstr,const char* file, int line,const char *format, ...) __attribute__ ((format (printf, 5, 6)));;
/**
* @fn DumpBlob
*
* @param[in] ptr to the buffer
* @param[in] len length of buffer
*
* @return void
*/
void DumpBlob(const unsigned char *ptr, size_t len);
#endif /* AAMPLOGMANAGER_H */