forked from rdkcmf/rdk-aamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AampUtils.h
161 lines (136 loc) · 4.49 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
/*
* 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>
#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]))
/**
* @brief Get current time from epoch is milliseconds
*
* @retval - current time in milliseconds
*/
long long aamp_GetCurrentTimeMS(void); //TODO: Use NOW_STEADY_TS_MS/NOW_SYSTEM_TS_MS instead
/**
* @brief Get curl IPRESOLVE based on current IP protocol
*
* @retval - current IPRESOLVE
*/
long aamp_GetIPResolveValue();
/**
* @brief Extract host string from url
*
* @param url - Input URL
* @retval - host of input url
*/
std::string aamp_getHostFromURL(std::string url);
/**
* @brief Create file URL from the base and file path
*
* @param[out] dst - Created URL
* @param[in] base - Base URL
* @param[in] uri - File path
* @retval void
*/
void aamp_ResolveURL(std::string& dst, std::string base, const char *uri);
/**
* @brief Check if string start with a prefix
*
* @param[in] inputStr - Input string
* @param[in] prefix - substring to be searched
* @retval TRUE if substring is found in bigstring
*/
bool aamp_StartsWith( const char *inputStr, const char *prefix);
char *aamp_Base64_URL_Encode(const unsigned char *src, size_t len);
unsigned char *aamp_Base64_URL_Decode(const char *src, size_t *len, size_t srcLen);
void aamp_DecodeUrlParameter( std::string &uriParam );
/**
* @brief Parse date time from ISO8601 string and return value in seconds
* @param ptr ISO8601 string
* @retval durationMs duration in milliseconds
*/
double ISO8601DateTimeToUTCSeconds(const char *ptr);
/**
* @brief aamp_PostJsonRPC posts JSONRPC data
* @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 );
/**
* @brief Get time to defer DRM acquisition
*
* @param maxTimeSeconds Maximum time allowed for deferred license acquisition
* @return Time in MS to defer DRM acquisition
*/
int aamp_GetDeferTimeMs(long maxTimeSeconds);
/**
* @brief Get name of DRM system
* @param drmSystem drm system
* @retval Name of the DRM system, empty string if not supported
*/
const char * GetDrmSystemName(DRMSystems drmSystem);
/**
* @brief Get DRM system from ID
* @param ID of the DRM system, empty string if not supported
* @retval drmSystem drm system
*/
DRMSystems GetDrmSystem(std::string drmSystemID);
/**
* @brief Get ID of DRM system
* @param drmSystem drm system
* @retval ID of the DRM system, empty string if not supported
*/
const char * GetDrmSystemID(DRMSystems drmSystem);
/**
* @brief Encode URL
*
* @param[in] inStr - Input URL
* @param[out] outStr - Encoded URL
* @return Encoding status
*/
void UrlEncode(std::string inStr, std::string &outStr);
/**
* @brief Trim a string
* @param[in][out] src Buffer containing string
*/
void trim(std::string& src);
/**
* @brief To get the preferred iso639mapped language code
* @param[in] lang
* @retval[out] preferred iso639 mapped language.
*/
std::string Getiso639map_NormalizeLanguageCode(std::string lang );
/**
* @brief To get the timespec
* @param[in] timeInMs
* @retval[out] timespec.
*/
struct timespec aamp_GetTimespec(int timeInMs);
#endif /* __AAMP_UTILS_H__ */