Repository navigation
Expand file tree
/
Copy pathAampLogManager.h
More file actions
271 lines (230 loc) · 7.16 KB
/
Copy pathAampLogManager.h
File metadata and controls
271 lines (230 loc) · 7.16 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
/*
* 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
#include <vector>
#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
*/
#define AAMPLOG(LEVEL,FORMAT, ...) \
do { if (gpGlobalConfig->logging.isLogLevelAllowed(LEVEL)) { \
logprintf(FORMAT, ##__VA_ARGS__); \
} } while (0)
/**
* @brief Macro for Triage Level Logging Support
*/
#define AAMP_LOG_NETWORK_LATENCY gpGlobalConfig->logging.LogNetworkLatency
#define AAMP_LOG_NETWORK_ERROR gpGlobalConfig->logging.LogNetworkError
#define AAMP_LOG_DRM_ERROR gpGlobalConfig->logging.LogDRMError
#define AAMP_LOG_ABR_INFO gpGlobalConfig->logging.LogABRInfo
#define AAMP_IS_LOG_WORTHY_ERROR gpGlobalConfig->logging.isLogworthyErrorCode
/**
* @brief AAMP logging defines, this can be enabled through setLogLevel() as per the need
*/
#define AAMPLOG_TRACE(FORMAT, ...) AAMPLOG(eLOGLEVEL_TRACE, FORMAT, ##__VA_ARGS__)
#define AAMPLOG_INFO(FORMAT, ...) AAMPLOG(eLOGLEVEL_INFO, FORMAT, ##__VA_ARGS__)
#define AAMPLOG_WARN(FORMAT, ...) AAMPLOG(eLOGLEVEL_WARN, FORMAT, ##__VA_ARGS__)
#define AAMPLOG_ERR(FORMAT, ...) AAMPLOG(eLOGLEVEL_ERROR, FORMAT, ##__VA_ARGS__)
#define AAMPLOG_FAILOVER(FORMAT, ...) \
if (gpGlobalConfig->logging.failover) { \
logprintf(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 */
};
/**
* @brief Log level network error enum
*/
enum AAMPNetworkErrorType
{
/* 0 */ AAMPNetworkErrorNone,
/* 1 */ AAMPNetworkErrorHttp,
/* 2 */ AAMPNetworkErrorTimeout,
/* 3 */ AAMPNetworkErrorCurl
};
/**
* @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;
};
/**
* @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 curlHeader; /**< Curl header logs*/
bool logMetadata; /**< Timed metadata logs*/
static bool disableLogRedirection;
/**
* @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)
{
}
/* ---------- Triage Level Logging Support ---------- */
/**
* @brief Print the network latency level logging for triage purpose
*
* @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
* @retuen void
*/
void LogNetworkLatency(const char* url, int downloadTime, int downloadThresholdTimeoutMs, MediaType type);
/**
* @brief Print the network error level logging for triage purpose
*
* @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
* @retuen void
*/
void LogNetworkError(const char* url, AAMPNetworkErrorType errorType, int errorCode, MediaType type);
/**
* @brief To get the issue symptom based on the error type for triage purpose
*
* @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
* @retuen void
*/
void ParseContentUrl(const char* url, std::string& contentType, std::string& location, std::string& symptom, MediaType type);
/**
* @brief Print the DRM error level logging for triage purpose
*
* @param[in] major - drm major error code
* @param[in] minor - drm minor error code
* @retuen void
*/
void LogDRMError(int major, int minor);
/**
* @brief Log ABR info for triage purpose
*
* @param[in] pstAbrInfo - pointer to a structure which will have abr info to be logged
* @retuen void
*/
void LogABRInfo(AAMPAbrInfo *pstAbrInfo);
/* !---------- Triage Level Logging Support ---------- */
/**
* @brief To check the given log level is allowed to print mechanism
*
* @param[in] chkLevel - log level
* @retval true if the log level allowed for print mechanism
*/
bool isLogLevelAllowed(AAMP_LogLevel chkLevel);
/**
* @brief Set the log level for print mechanism
*
* @param[in] newLevel - log level new value
* @retuen void
*/
void setLogLevel(AAMP_LogLevel newLevel);
/**
* @brief Set log file and cfg directory index.
*/
void setLogAndCfgDirectory(char driveName);
/**
* @brief Check curl error before log on console.
*/
bool isLogworthyErrorCode(int errorCode);
/**
* @brief Get aamp cfg directory.
*/
const char* getAampCfgPath(void);
/**
* @brief Get aampcli cfg directory.
*/
const char* getAampCliCfgPath(void);
/*
* @brief Get a hex string representation of a vector of bytes
*/
static std::string getHexDebugStr(const std::vector<uint8_t>& data);
private:
AAMP_LogLevel aampLoglevel;
};
/* Context-free utility function */
/**
* @brief Print logs to console / log file
* @param[in] format - printf style string
* @retuen void
*/
extern void logprintf(const char *format, ...);
/**
* @brief Compactly log blobs of binary data
*
* @param[in] ptr to the buffer
* @param[in] size_t length of buffer
*
* @return void
*/
void DumpBlob(const unsigned char *ptr, size_t len);
#endif /* AAMPLOGMANAGER_H */