-
Notifications
You must be signed in to change notification settings - Fork 0
/
AampUtils.h
314 lines (272 loc) · 8.43 KB
/
AampUtils.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
/*
* If not stated otherwise in this file or this component's license file the
* following copyright and licenses apply:
*
* Copyright 2018 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 AampDRMutils.h
* @brief Context-free common utility functions.
*/
#ifndef __AAMP_UTILS_H__
#define __AAMP_UTILS_H__
#include "AampDrmSystems.h"
#include "main_aamp.h"
#include "iso639map.h"
#include <string>
#include <sstream>
#include <chrono>
#include <curl/curl.h>
#define NOW_SYSTEM_TS_MS std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() /**< Getting current system clock in milliseconds */
#define NOW_STEADY_TS_MS std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count() /**< Getting current steady clock in milliseconds */
#define ARRAY_SIZE(A) (sizeof(A)/sizeof(A[0]))
//Delete non-array object
#define SAFE_DELETE(ptr) { delete(ptr); ptr = NULL; }
//Delete Array object
#define SAFE_DELETE_ARRAY(ptr) { delete [] ptr; ptr = NULL; }
/** FHD height*/
#define AAMP_FHD_HEIGHT (1080)
#define CURL_SHARE_SETOPT( SH, OPT, PARAM ) \
{ \
CURLSHcode rc = curl_share_setopt( SH, OPT, PARAM ); \
if( rc != CURLSHE_OK ) \
{ \
AAMPLOG_WARN( "curl_share_setopt fail %d\n", rc ); \
} \
}
#define CURL_EASY_SETOPT_POINTER( handle, option, parameter )\
if (curl_easy_setopt( handle, option, parameter ) != CURLE_OK ) {\
AAMPLOG_WARN("CURL_EASY_SETOPT_POINTER failure" );\
}
#define CURL_EASY_SETOPT_STRING( handle, option, parameter)\
if (curl_easy_setopt( handle, option, parameter ) != CURLE_OK ) {\
AAMPLOG_WARN("CURL_EASY_SETOPT_STRING failure" );\
}
#define CURL_EASY_SETOPT_LONG( handle, option, parameter )\
if (curl_easy_setopt( handle, option, (long)parameter ) != CURLE_OK ) {\
AAMPLOG_WARN("CURL_EASY_SETOPT_LONG failure" );\
}
#define CURL_EASY_SETOPT_FUNC( handle, option, parameter )\
if (curl_easy_setopt( handle, option, parameter ) != CURLE_OK) {\
AAMPLOG_WARN("CURL_EASY_SETOPT_FUNC failure" );\
}
#define CURL_EASY_SETOPT_LIST( handle, option, parameter )\
if (curl_easy_setopt( handle, option, parameter ) != CURLE_OK) {\
AAMPLOG_WARN("CURL_EASY_SETOPT_LIST failure" );\
}
double aamp_CurlEasyGetinfoDouble( CURL *handle, CURLINFO info );
int aamp_CurlEasyGetinfoInt( CURL *handle, CURLINFO info );
long aamp_CurlEasyGetinfoLong( CURL *handle, CURLINFO info );
char *aamp_CurlEasyGetinfoString( CURL *handle, CURLINFO info );
/**
* @struct FormatMap
* @brief FormatMap structure for stream codec/format information
*/
struct FormatMap
{
const char* codec;
StreamOutputFormat format;
};
/*
* @fn GetAudioFormatStringForCodec
* @brief Function to get audio codec string from the map.
*
* @param[in] input Audio codec type
* @return Audio codec string
*/
const char * GetAudioFormatStringForCodec ( StreamOutputFormat input);
/*
* @fn GetAudioFormatForCodec
* @brief Function to get audio codec from the map.
*
* @param[in] Audio codec string
* @return Audio codec map
*/
const FormatMap * GetAudioFormatForCodec( const char *codecs );
/*
* @fn GetVideoFormatForCodec
* @brief Function to get video codec from the map.
*
* @param[in] Video codec string
* @return Video codec map
*/
const FormatMap * GetVideoFormatForCodec( const char *codecs );
/**
* @fn aamp_GetCurrentTimeMS
*
*/
long long aamp_GetCurrentTimeMS(void); //TODO: Use NOW_STEADY_TS_MS/NOW_SYSTEM_TS_MS instead
/**
* @fn aamp_IsAbsoluteURL
*
* @param[in] url - Input URL
*/
bool aamp_IsAbsoluteURL( const std::string &url );
/**
* @fn aamp_getHostFromURL
*
* @param[in] url - Input URL
* @retval host of input url
*/
std::string aamp_getHostFromURL(std::string url);
/**
* @fn aamp_IsLocalHost
*
* @param[in] Hostname - Hostname parsed from url
* @retval true if localhost false otherwise.
*/
bool aamp_IsLocalHost ( std::string Hostname );
/**
* @fn aamp_ResolveURL
*
* @param[out] dst - Created URL
* @param[in] base - Base URL
* @param[in] uri - File path
* @param[in] bPropagateUriParams - flag to use base uri params
* @retval void
*/
void aamp_ResolveURL(std::string& dst, std::string base, const char *uri , bool bPropagateUriParams);
/**
* @fn aamp_StartsWith
*
* @param[in] inputStr - Input string
* @param[in] prefix - substring to be searched
*/
bool aamp_StartsWith( const char *inputStr, const char *prefix);
/**
* @fn aamp_Base64_URL_Encode
* @param src pointer to first byte of binary data to be encoded
* @param len number of bytes to encode
*/
char *aamp_Base64_URL_Encode(const unsigned char *src, size_t len);
/**
* @fn aamp_Base64_URL_Decode
* @param src pointer to cstring containing base64-URL-encoded data
* @param len receives byte length of returned pointer, or zero upon failure
* @param srcLen source data length
*/
unsigned char *aamp_Base64_URL_Decode(const char *src, size_t *len, size_t srcLen);
/**
* @brief unescape uri-encoded uri parameter
* @param uriParam string to un-escape
*/
void aamp_DecodeUrlParameter( std::string &uriParam );
/**
* @fn ISO8601DateTimeToUTCSeconds
* @param ptr ISO8601 string
*/
double ISO8601DateTimeToUTCSeconds(const char *ptr);
/**
* @fn aamp_PostJsonRPC
* @param[in] id string containing player id
* @param[in] method string containing JSON method
* @param[in] params string containing params:value pair list
*/
std::string aamp_PostJsonRPC( std::string id, std::string method, std::string params );
/**
* @fn aamp_GetDeferTimeMs
*
* @param maxTimeSeconds Maximum time allowed for deferred license acquisition
*/
int aamp_GetDeferTimeMs(long maxTimeSeconds);
/**
* @fn GetDrmSystemName
* @param drmSystem drm system
*/
const char * GetDrmSystemName(DRMSystems drmSystem);
/**
* @fn GetDrmSystem
* @param drmSystemID - Id of the DRM system, empty string if not supported
*/
DRMSystems GetDrmSystem(std::string drmSystemID);
/**
* @fn GetDrmSystemID
* @param drmSystem - drm system
*/
const char * GetDrmSystemID(DRMSystems drmSystem);
/**
* @fn UrlEncode
*
* @param[in] inStr - Input URL
* @param[out] outStr - Encoded URL
*/
void UrlEncode(std::string inStr, std::string &outStr);
/**
* @fn trim
* @param[in][out] src Buffer containing string
*/
void trim(std::string& src);
/**
* @fn Getiso639map_NormalizeLanguageCode
* @param[in] lang - Language in string format
* @param[in] preferFormat - Preferred language foramt
*/
std::string Getiso639map_NormalizeLanguageCode(std::string lang, LangCodePreference preferFormat );
/**
* @fn aamp_GetTimespec
* @param[in] timeInMs
*/
struct timespec aamp_GetTimespec(int timeInMs);
/**
* @fn aamp_WriteFile
* @param fileName - out file name
* @param data - buffer
* @param len - length of buffer
* @param fileType - Media type of file
* @param count - for manifest or playlist update
* @param prefix - prefix name
*/
bool aamp_WriteFile(std::string fileName, const char* data, size_t len, MediaType &fileType, unsigned int count,const char *prefix);
/**
* @fn getHarvestConfigForMedia
* @param fileType - meida file type
*/
int getHarvestConfigForMedia(MediaType fileType);
/**
* @fn getWorkingTrickplayRate
* @param rate input rate
*/
float getWorkingTrickplayRate(float rate);
/**
* @fn getPseudoTrickplayRate
* @param rate working rate
*/
float getPseudoTrickplayRate(float rate);
/**
* @fn getDefaultHarvestPath
* @param[in] value - harvest path
* @return void
*/
void getDefaultHarvestPath(std::string &value);
/**
* @fn stream2hex
* @param[in] str input string
* @param[out] hexstr output hex string
* @param[in] capital - Boolean to enable capital letter conversion flag
*/
void stream2hex(const std::string str, std::string& hexstr, bool capital = false);
/**
* @fn mssleep
* @param milliseconds Time to sleep
*/
void mssleep(int milliseconds);
std::size_t GetPrintableThreadID( const std::thread &t );
#define MAX_RANGE_STRING_CHARS 128
#define WRITE_HASCII( DST, BYTE ) \
{ \
*DST++ = "0123456789abcdef"[BYTE>>4]; \
*DST++ = "0123456789abcdef"[BYTE&0xf]; \
}
#endif /* __AAMP_UTILS_H__ */