RDK Documentation (Open Sourced RDK Components)
aampMocks.cpp
1 #include <iostream>
2 #include <iomanip>
3 #include <algorithm>
4 #include <unordered_map>
5 #include <memory>
6 
7 #include "AampDRMutils.h"
8 #include "AampConfig.h"
9 #include "priv_aamp.h"
10 #include "aampgstplayer.h"
11 
12 #include "CppUTest/TestHarness.h"
13 #include "CppUTestExt/MockSupport.h"
14 
15 //Enable the define below to get AAMP logging out when running tests
16 //#define ENABLE_LOGGING
17 #define TEST_LOG_LEVEL eLOGLEVEL_TRACE
18 
19 std::shared_ptr<AampConfig> gGlobalConfig;
21 AampLogManager *mLogObj = NULL;
22 
23 static std::unordered_map<std::string, std::vector<std::string>> fCustomHeaders;
24 
25 void MockAampReset(void)
26 {
27  gGlobalConfig = std::make_shared<AampConfig>();
28 
29  gpGlobalConfig = gGlobalConfig.get();
30 }
31 
32 PrivateInstanceAAMP::PrivateInstanceAAMP(AampConfig *config) : mConfig(config), mIsFakeTune(false) {}
34 
35 void PrivateInstanceAAMP::GetCustomLicenseHeaders(std::unordered_map<std::string, std::vector<std::string>>& customHeaders)
36 {
37  customHeaders = fCustomHeaders;
38 }
39 
40 void PrivateInstanceAAMP::SendDrmErrorEvent(DrmMetaDataEventPtr event, bool isRetryEnabled)
41 {
42 }
43 
44 void PrivateInstanceAAMP::SendDRMMetaData(DrmMetaDataEventPtr e)
45 {
46 }
47 
48 void PrivateInstanceAAMP::individualization(const std::string& payload)
49 {
50  mock("Aamp").actualCall("individualization").withStringParameter("payload", payload.c_str());
51 }
52 
53 void PrivateInstanceAAMP::SendEvent(AAMPEventPtr eventData, AAMPEventMode eventMode)
54 {
55 }
56 
58 {
59 }
60 
62 {
63  return std::string();
64 }
65 
67 {
68  std::string url;
69  if (type == eDRM_PlayReady)
70  {
71  GETCONFIGVALUE_PRIV(eAAMPConfig_PRLicenseServerUrl,url);
72  }
73  else if (type == eDRM_WideVine)
74  {
75  GETCONFIGVALUE_PRIV(eAAMPConfig_WVLicenseServerUrl,url);
76  }
77  else if (type == eDRM_ClearKey)
78  {
79  GETCONFIGVALUE_PRIV(eAAMPConfig_CKLicenseServerUrl,url);
80  }
81 
82  if(url.empty())
83  {
84  GETCONFIGVALUE_PRIV(eAAMPConfig_LicenseServerUrl,url);
85  }
86  return url;
87 }
88 
90 {
91  return std::string();
92 }
93 
95 {
96  return false;
97 }
98 
100 {
101  return std::string();
102 }
103 
104 int PrivateInstanceAAMP::HandleSSLProgressCallback ( void *clientp, double dltotal, double dlnow, double ultotal, double ulnow )
105 {
106  return 0;
107 }
108 
109 size_t PrivateInstanceAAMP::HandleSSLHeaderCallback ( const char *ptr, size_t size, size_t nmemb, void* userdata )
110 {
111  return 0;
112 }
113 
114 size_t PrivateInstanceAAMP::HandleSSLWriteCallback ( char *ptr, size_t size, size_t nmemb, void* userdata )
115 {
116  return 0;
117 }
118 
119 #ifdef USE_SECCLIENT
120 void PrivateInstanceAAMP::GetMoneyTraceString(std::string &customHeader) const
121 {
122 }
123 #endif
124 
125 bool AAMPGstPlayer::IsCodecSupported(const std::string &codecName)
126 {
127  return true;
128 }
129 
130 void aamp_Free(struct GrowableBuffer *buffer)
131 {
132  if (buffer && buffer->ptr)
133  {
134  g_free(buffer->ptr);
135  buffer->ptr = NULL;
136  }
137 }
138 
139 void aamp_AppendBytes(struct GrowableBuffer *buffer, const void *ptr, size_t len)
140 {
141  size_t required = buffer->len + len;
142  if (required > buffer->avail)
143  {
144  // For encoded contents, step by step increment 512KB => 1MB => 2MB => ..
145  // In other cases, double the buffer based on availability and requirement.
146  buffer->avail = ((buffer->avail * 2) > required) ? (buffer->avail * 2) : (required * 2);
147  char *ptr = (char *)g_realloc(buffer->ptr, buffer->avail);
148  assert(ptr);
149  if (ptr)
150  {
151  if (buffer->ptr == NULL)
152  { // first alloc (not a realloc)
153  }
154  buffer->ptr = ptr;
155  }
156  }
157  if (buffer->ptr)
158  {
159  memcpy(&buffer->ptr[buffer->len], ptr, len);
160  buffer->len = required;
161  }
162 }
163 
165 {
166  return chkLevel >= TEST_LOG_LEVEL;
167 }
168 
169 std::string AampLogManager::getHexDebugStr(const std::vector<uint8_t>& data)
170 {
171  std::ostringstream hexSs;
172  hexSs << "0x";
173  hexSs << std::hex << std::uppercase << std::setfill('0');
174  std::for_each(data.cbegin(), data.cend(), [&](int c) { hexSs << std::setw(2) << c; });
175  return hexSs.str();
176 }
177 
179 {
180 }
181 
182 void logprintf(const char *format, ...)
183 {
184 #ifdef ENABLE_LOGGING
185  int len = 0;
186  va_list args;
187  va_start(args, format);
188 
189  char gDebugPrintBuffer[MAX_DEBUG_LOG_BUFF_SIZE];
190  len = sprintf(gDebugPrintBuffer, "[AAMP-PLAYER]");
191  vsnprintf(gDebugPrintBuffer+len, MAX_DEBUG_LOG_BUFF_SIZE-len, format, args);
192  gDebugPrintBuffer[(MAX_DEBUG_LOG_BUFF_SIZE-1)] = 0;
193 
194  std::cout << gDebugPrintBuffer << std::endl;
195 
196  va_end(args);
197 #endif
198 }
199 
200 void logprintf_new(int playerId, const char* levelstr, const char* file, int line, const char *format, ...)
201 {
202 #ifdef ENABLE_LOGGING
203  int len = 0;
204  va_list args;
205  va_start(args, format);
206 
207  char gDebugPrintBuffer[MAX_DEBUG_LOG_BUFF_SIZE];
208  len = sprintf(gDebugPrintBuffer, "[AAMP-PLAYER][%d][%s][%s][%d]", playerId, levelstr, file, line);
209  vsnprintf(gDebugPrintBuffer+len, MAX_DEBUG_LOG_BUFF_SIZE-len, format, args);
210  gDebugPrintBuffer[(MAX_DEBUG_LOG_BUFF_SIZE-1)] = 0;
211 
212  std::cout << gDebugPrintBuffer << std::endl;
213 
214  va_end(args);
215 #endif
216 }
217 
218 void DumpBlob(const unsigned char *ptr, size_t len)
219 {
220 }
AAMP_LogLevel
AAMP_LogLevel
Log level's of AAMP.
Definition: AampLogManager.h:97
PrivateInstanceAAMP::GetLicenseServerUrlForDrm
std::string GetLicenseServerUrlForDrm(DRMSystems type)
Get license server url for a drm type.
Definition: priv_aamp.cpp:9950
aamp_Free
void aamp_Free(void *ptr)
wrapper for g_free, used for segment allocation
Definition: AampMemoryUtils.cpp:56
eDRM_WideVine
@ eDRM_WideVine
Definition: AampDrmSystems.h:36
eDRM_PlayReady
@ eDRM_PlayReady
Definition: AampDrmSystems.h:37
eAAMPConfig_WVLicenseServerUrl
@ eAAMPConfig_WVLicenseServerUrl
Definition: AampConfig.h:300
eDRM_ClearKey
@ eDRM_ClearKey
Definition: AampDrmSystems.h:41
logprintf
void logprintf(const char *format,...)
Print logs to console / log fil.
Definition: aamplogging.cpp:432
PrivateInstanceAAMP::HandleSSLWriteCallback
size_t HandleSSLWriteCallback(char *ptr, size_t size, size_t nmemb, void *userdata)
HandleSSLWriteCallback - Handle write callback from CURL.
Definition: priv_aamp.cpp:770
gpGlobalConfig
AampConfig * gpGlobalConfig
Global configuration.
Definition: main_aamp.cpp:48
DumpBlob
void DumpBlob(const unsigned char *ptr, size_t len)
Compactly log blobs of binary data.
Definition: aamplogging.cpp:533
PrivateInstanceAAMP::SetState
void SetState(PrivAAMPState state)
Set player state.
Definition: priv_aamp.cpp:7731
eAAMPConfig_LicenseServerUrl
@ eAAMPConfig_LicenseServerUrl
Definition: AampConfig.h:297
AampLogManager
AampLogManager Class.
Definition: AampLogManager.h:150
PrivateInstanceAAMP::HandleSSLHeaderCallback
size_t HandleSSLHeaderCallback(const char *ptr, size_t size, size_t nmemb, void *userdata)
HandleSSLHeaderCallback - Hanlde header callback from SSL.
Definition: priv_aamp.cpp:863
PrivateInstanceAAMP::PrivateInstanceAAMP
PrivateInstanceAAMP(AampConfig *config=NULL)
PrivateInstanceAAMP Constructor.
Definition: priv_aamp.cpp:1278
AampConfig
AAMP Config Class defn.
Definition: AampConfig.h:457
PrivateInstanceAAMP::IsEventListenerAvailable
bool IsEventListenerAvailable(AAMPEventType eventType)
IsEventListenerAvailable Check if Event is registered.
Definition: priv_aamp.cpp:2261
PrivateInstanceAAMP::SendDrmErrorEvent
void SendDrmErrorEvent(DrmMetaDataEventPtr event, bool isRetryEnabled)
Handles DRM errors and sends events to application if required.
Definition: priv_aamp.cpp:2269
PrivateInstanceAAMP::individualization
void individualization(const std::string &payload)
DRM individualization callback.
Definition: priv_aamp.cpp:9807
AAMPGstPlayer::IsCodecSupported
static bool IsCodecSupported(const std::string &codecName)
Definition: aampgstplayer.cpp:4370
AAMPEventMode
AAMPEventMode
AAMP event modes.
Definition: AampEvent.h:97
PrivateInstanceAAMP::SendEvent
void SendEvent(AAMPEventPtr eventData, AAMPEventMode eventMode=AAMP_EVENT_DEFAULT_MODE)
Send event to listeners.
Definition: priv_aamp.cpp:2530
eAAMPConfig_CKLicenseServerUrl
@ eAAMPConfig_CKLicenseServerUrl
Definition: AampConfig.h:298
logprintf_new
void logprintf_new(int playerId, const char *levelstr, const char *file, int line, const char *format,...)
Print logs to console / log file.
Definition: aamplogging.cpp:482
aampgstplayer.h
Gstreamer based player for AAMP.
AampLogManager::isLogLevelAllowed
bool isLogLevelAllowed(AAMP_LogLevel chkLevel)
To check the given log level is allowed to print mechanism.
Definition: aamplogging.cpp:50
PrivateInstanceAAMP::GetLicenseCustomData
std::string GetLicenseCustomData()
Get License Custom Data.
Definition: priv_aamp.cpp:11994
AampDRMutils.h
Context-free common utility functions.
PrivateInstanceAAMP::GetAppName
std::string GetAppName()
Get the application name.
Definition: priv_aamp.cpp:9799
AampConfig.h
Configurations for AAMP.
priv_aamp.h
Private functions and types used internally by AAMP.
GrowableBuffer
Structure of GrowableBuffer.
Definition: AampMemoryUtils.h:39
PrivAAMPState
PrivAAMPState
Mapping all required status codes based on JS player requirement. These requirements may be forced by...
Definition: AampEvent.h:156
MAX_DEBUG_LOG_BUFF_SIZE
#define MAX_DEBUG_LOG_BUFF_SIZE
Max debug log buffer size.
Definition: priv_aamp.h:114
AAMPEventType
AAMPEventType
Type of the events sending to the JSPP player.
Definition: AampEvent.h:44
aamp_AppendBytes
void aamp_AppendBytes(struct GrowableBuffer *buffer, const void *ptr, size_t len)
append data to GrowableBuffer ADT
Definition: AampMemoryUtils.cpp:108
PrivateInstanceAAMP::GetLicenseReqProxy
std::string GetLicenseReqProxy()
To get the proxy for license request.
Definition: priv_aamp.cpp:9089
PrivateInstanceAAMP::HandleSSLProgressCallback
int HandleSSLProgressCallback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
HandleSSLProgressCallback - Process progress callback from CURL.
Definition: priv_aamp.cpp:1116
PrivateInstanceAAMP::GetCustomLicenseHeaders
void GetCustomLicenseHeaders(std::unordered_map< std::string, std::vector< std::string >> &customHeaders)
To get any custom license HTTP headers that was set by application.
Definition: priv_aamp.cpp:9219
PrivateInstanceAAMP::~PrivateInstanceAAMP
~PrivateInstanceAAMP()
PrivateInstanceAAMP Destructor.
Definition: priv_aamp.cpp:1534
DRMSystems
DRMSystems
DRM system types.
Definition: AampDrmSystems.h:33
AampLogManager::getHexDebugStr
static std::string getHexDebugStr(const std::vector< uint8_t > &data)
Get a hex string representation of a vector of bytes.
Definition: aamplogging.cpp:93
PrivateInstanceAAMP::SendDRMMetaData
void SendDRMMetaData(DrmMetaDataEventPtr e)
Send DRM metadata event.
Definition: priv_aamp.cpp:2656
eAAMPConfig_PRLicenseServerUrl
@ eAAMPConfig_PRLicenseServerUrl
Definition: AampConfig.h:299
AampLogManager::setLogLevel
void setLogLevel(AAMP_LogLevel newLevel)
Set the log level for print mechanism.
Definition: aamplogging.cpp:58