RDK Documentation (Open Sourced RDK Components)
jsutils.cpp
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's license file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2018 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 /**
20  * @file jsutils.cpp
21  * @brief JavaScript util functions for AAMP
22  */
23 
24 
25 #include "jsutils.h"
26 
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <cmath>
30 
31 #include <iomanip>
32 #include <algorithm>
33 
34 #ifdef USE_SYSLOG_HELPER_PRINT
35 #include "syslog_helper_ifc.h"
36 #endif
37 #ifdef USE_SYSTEMD_JOURNAL_PRINT
38 #include <systemd/sd-journal.h>
39 #endif
40 
41 #define MAX_DEBUG_LOG_BUFF_SIZE 1024
42 
43 /**
44  * @struct EventTypeMap
45  * @brief Struct to map names of AAMP events and JS events
46  */
48 {
49  AAMPEventType eventType;
50  const char* szName;
51 };
52 
53 
54 /**
55  * @brief Map AAMP events to its corresponding JS event strings (used by JSPP)
56  */
58 {
59  { (AAMPEventType)0, "onEvent"},
60  { AAMP_EVENT_TUNED, "tuned"},
61  { AAMP_EVENT_TUNE_FAILED, "tuneFailed"},
62  { AAMP_EVENT_SPEED_CHANGED, "speedChanged"},
63  { AAMP_EVENT_EOS, "eos"},
64  { AAMP_EVENT_PLAYLIST_INDEXED, "playlistIndexed"},
65  { AAMP_EVENT_PROGRESS, "progress"},
66  { AAMP_EVENT_CC_HANDLE_RECEIVED, "decoderAvailable"},
67  { AAMP_EVENT_JS_EVENT, "jsEvent"},
68  { AAMP_EVENT_MEDIA_METADATA, "metadata"},
69  { AAMP_EVENT_ENTERING_LIVE, "enteringLive"},
70  { AAMP_EVENT_BITRATE_CHANGED, "bitrateChanged"},
71  { AAMP_EVENT_TIMED_METADATA, "timedMetadata"},
72  { AAMP_EVENT_BULK_TIMED_METADATA, "bulkTimedMetadata"},
73  { AAMP_EVENT_STATE_CHANGED, "statusChanged"},
74  { AAMP_EVENT_SPEEDS_CHANGED, "speedsChanged"},
75  { AAMP_EVENT_SEEKED, "seeked"},
76  { AAMP_EVENT_DRM_METADATA, "drmMetadata"},
77  { AAMP_EVENT_REPORT_ANOMALY, "anomalyReport" },
78  { AAMP_EVENT_AD_RESOLVED, "adResolved"},
79  { AAMP_EVENT_AD_RESERVATION_START, "reservationStart" },
80  { AAMP_EVENT_AD_RESERVATION_END, "reservationEnd" },
81  { AAMP_EVENT_AD_PLACEMENT_START, "placementStart" },
82  { AAMP_EVENT_AD_PLACEMENT_END, "placementEnd" },
83  { AAMP_EVENT_AD_PLACEMENT_PROGRESS, "placementProgress" },
84  { AAMP_EVENT_AD_PLACEMENT_ERROR, "placementError" },
85  { AAMP_EVENT_REPORT_METRICS_DATA, "metricsData" },
86  { AAMP_EVENT_BUFFERING_CHANGED, "bufferingChanged"},
87  { AAMP_EVENT_ID3_METADATA, "id3Metadata"},
88  { AAMP_EVENT_DRM_MESSAGE, "drmMessage" },
89  { AAMP_EVENT_AUDIO_TRACKS_CHANGED, "audioTracksChanged"},
90  { AAMP_EVENT_TEXT_TRACKS_CHANGED, "textTracksChanged"},
91  { AAMP_EVENT_CONTENT_GAP, "contentGap" },
92  { AAMP_EVENT_CONTENT_PROTECTION_DATA_UPDATE, "contentProtectionDataUpdate" },
93  { (AAMPEventType)0, "" }
94 };
95 
96 
97 /**
98  * @brief Map AAMP events to its corresponding JS event strings (used by AAMPMediaPlayer/UVE APIs)
99  */
101 {
102 //TODO: Need separate event list to avoid breaking existing viper impl. Unify later.
103  { (AAMPEventType)0, "onEvent"},
104  { AAMP_EVENT_TUNED, "playbackStarted"},
105  { AAMP_EVENT_TUNE_FAILED, "playbackFailed"},
106  { AAMP_EVENT_SPEED_CHANGED, "playbackSpeedChanged"},
107  { AAMP_EVENT_EOS, "playbackCompleted"},
108  { AAMP_EVENT_PLAYLIST_INDEXED, "playlistIndexed"},
109  { AAMP_EVENT_PROGRESS, "playbackProgressUpdate"},
110  { AAMP_EVENT_CC_HANDLE_RECEIVED, "decoderAvailable"},
111  { AAMP_EVENT_JS_EVENT, "jsEvent"},
112  { AAMP_EVENT_MEDIA_METADATA, "mediaMetadata"},
113  { AAMP_EVENT_ENTERING_LIVE, "enteringLive"},
114  { AAMP_EVENT_BITRATE_CHANGED, "bitrateChanged"},
115  { AAMP_EVENT_TIMED_METADATA, "timedMetadata"},
116  { AAMP_EVENT_BULK_TIMED_METADATA, "bulkTimedMetadata"},
117  { AAMP_EVENT_STATE_CHANGED, "playbackStateChanged"},
118  { AAMP_EVENT_SPEEDS_CHANGED, "speedsChanged"},
119  { AAMP_EVENT_SEEKED, "seeked"},
120  { AAMP_EVENT_TUNE_PROFILING, "tuneProfiling"},
121  { AAMP_EVENT_BUFFERING_CHANGED, "bufferingChanged"},
122  { AAMP_EVENT_DURATION_CHANGED, "durationChanged"},
123  { AAMP_EVENT_AUDIO_TRACKS_CHANGED, "audioTracksChanged"},
124  { AAMP_EVENT_TEXT_TRACKS_CHANGED, "textTracksChanged"},
125  { AAMP_EVENT_AD_BREAKS_CHANGED, "contentBreaksChanged"},
126  { AAMP_EVENT_AD_STARTED, "contentStarted"},
127  { AAMP_EVENT_AD_COMPLETED, "contentCompleted"},
128  { AAMP_EVENT_DRM_METADATA, "drmMetadata"},
129  { AAMP_EVENT_REPORT_ANOMALY, "anomalyReport" },
130  { AAMP_EVENT_WEBVTT_CUE_DATA, "vttCueDataListener" },
131  { AAMP_EVENT_AD_RESOLVED, "adResolved"},
132  { AAMP_EVENT_AD_RESERVATION_START, "reservationStart" },
133  { AAMP_EVENT_AD_RESERVATION_END, "reservationEnd" },
134  { AAMP_EVENT_AD_PLACEMENT_START, "placementStart" },
135  { AAMP_EVENT_AD_PLACEMENT_END, "placementEnd" },
136  { AAMP_EVENT_AD_PLACEMENT_ERROR, "placementError" },
137  { AAMP_EVENT_AD_PLACEMENT_PROGRESS, "placementProgress" },
138  { AAMP_EVENT_REPORT_METRICS_DATA, "metricsData" },
139  { AAMP_EVENT_ID3_METADATA, "id3Metadata"},
140  { AAMP_EVENT_DRM_MESSAGE, "drmMessage" },
141  { AAMP_EVENT_BLOCKED, "blocked" },
142  { AAMP_EVENT_CONTENT_GAP, "contentGap" },
143  { AAMP_EVENT_HTTP_RESPONSE_HEADER, "httpResponseHeader"},
144  { AAMP_EVENT_WATERMARK_SESSION_UPDATE, "watermarkSessionUpdate" },
145  { AAMP_EVENT_CONTENT_PROTECTION_DATA_UPDATE, "contentProtectionDataUpdate" },
146  { (AAMPEventType)0, "" }
147 };
148 
149 /**
150  * @brief Convert C string to JSString
151  */
152 JSValueRef aamp_CStringToJSValue(JSContextRef context, const char* sz)
153 {
154  JSStringRef str = JSStringCreateWithUTF8CString(sz);
155  JSValueRef value = JSValueMakeString(context, str);
156  JSStringRelease(str);
157 
158  return value;
159 }
160 
161 /**
162  * @brief Convert JSString to C string
163  */
164 char* aamp_JSValueToCString(JSContextRef context, JSValueRef value, JSValueRef* exception)
165 {
166  JSStringRef jsstr = JSValueToStringCopy(context, value, exception);
167  size_t len = JSStringGetMaximumUTF8CStringSize(jsstr);
168  char* src = new char[len];
169  JSStringGetUTF8CString(jsstr, src, len);
170  JSStringRelease(jsstr);
171  return src;
172 }
173 
174 /**
175  * @brief Convert JSString to JSON C string
176  */
177 char* aamp_JSValueToJSONCString(JSContextRef context, JSValueRef value, JSValueRef* exception)
178 {
179  JSStringRef jsstr = JSValueCreateJSONString(context, value, 0, exception);
180  size_t len = JSStringGetMaximumUTF8CStringSize(jsstr);
181  char* src = new char[len];
182  JSStringGetUTF8CString(jsstr, src, len);
183  JSStringRelease(jsstr);
184  return src;
185 }
186 
187 /**
188  * @brief Check if a JSValue object is array or not
189  */
190 bool aamp_JSValueIsArray(JSContextRef context, JSValueRef value)
191 {
192  JSObjectRef global = JSContextGetGlobalObject(context);
193  JSStringRef arrayProp = JSStringCreateWithUTF8CString("Array");
194  JSValueRef arrayVal = JSObjectGetProperty(context, global, arrayProp, NULL);
195  JSStringRelease(arrayProp);
196 
197  if (JSValueIsObject(context, arrayVal))
198  {
199  JSObjectRef arrayObj = JSValueToObject(context, arrayVal, NULL);
200  if (JSObjectIsFunction(context, arrayObj) || JSObjectIsConstructor(context, arrayObj))
201  {
202  return JSValueIsInstanceOfConstructor(context, value, arrayObj, NULL);
203  }
204  }
205 
206  return false;
207 }
208 
209 
210 /**
211  * @brief Convert an array of JSString to an array of C strings
212  */
213 std::vector<std::string> aamp_StringArrayToCStringArray(JSContextRef context, JSValueRef arrayRef)
214 {
215  std::vector<std::string> retval;
216  JSValueRef exception = NULL;
217 
218  if(!arrayRef)
219  {
220  LOG_ERROR_EX("Error: value is NULL.");
221  return retval;
222  }
223  if (!JSValueIsObject(context, arrayRef))
224  {
225  LOG_ERROR_EX("Error: value is not an object.");
226  return retval;
227  }
228  if(!aamp_JSValueIsArray(context, arrayRef))
229  {
230  LOG_ERROR_EX("Error: value is not an array.");
231  return retval;
232  }
233  JSObjectRef arrayObj = JSValueToObject(context, arrayRef, &exception);
234  if(exception)
235  {
236 
237  LOG_ERROR_EX("Error: exception accesing array object.");
238  return retval;
239  }
240 
241  JSStringRef lengthStrRef = JSStringCreateWithUTF8CString("length");
242  JSValueRef lengthRef = JSObjectGetProperty(context, arrayObj, lengthStrRef, &exception);
243  if(exception)
244  {
245 
246  LOG_ERROR_EX("Error: exception accesing array length.");
247  return retval;
248  }
249  int length = JSValueToNumber(context, lengthRef, &exception);
250  if(exception)
251  {
252  LOG_ERROR_EX("Error: exception array length in not a number.");
253  return retval;
254  }
255 
256  retval.reserve(length);
257  for(int i = 0; i < length; i++)
258  {
259  JSValueRef strRef = JSObjectGetPropertyAtIndex(context, arrayObj, i, &exception);
260  if(exception)
261  continue;
262 
263  char* str = aamp_JSValueToCString(context, strRef, NULL);
264  LOG_TRACE("array[%d] = '%s'.",i,str);
265  retval.push_back(str);
266  SAFE_DELETE_ARRAY(str);
267  }
268 
269  JSStringRelease(lengthStrRef);
270 
271  return retval;
272 }
273 
274 
275 /**
276  * @brief Generate a JSValue object with the exception details
277  */
278 JSValueRef aamp_GetException(JSContextRef context, ErrorCode error, const char *additionalInfo)
279 {
280  const char *str = "Generic Error";
281  JSValueRef retVal;
282 
283  switch(error)
284  {
285  case AAMPJS_INVALID_ARGUMENT:
286  case AAMPJS_MISSING_OBJECT:
287  str = "TypeError";
288  break;
289  default:
290  str = "Generic Error";
291  break;
292  }
293 
294  char exceptionMsg[EXCEPTION_ERR_MSG_MAX_LEN];
295  memset(exceptionMsg, '\0', EXCEPTION_ERR_MSG_MAX_LEN);
296 
297  if(additionalInfo)
298  {
299  snprintf(exceptionMsg, EXCEPTION_ERR_MSG_MAX_LEN - 1, "%s: %s", str, additionalInfo);
300  }
301  else
302  {
303  snprintf(exceptionMsg, EXCEPTION_ERR_MSG_MAX_LEN - 1, "%s!!", str);
304  }
305 
306 
307  LOG_WARN_EX("exception=%s",exceptionMsg);
308 
309  const JSValueRef arguments[] = { aamp_CStringToJSValue(context, exceptionMsg) };
310  JSValueRef exception = NULL;
311  retVal = JSObjectMakeError(context, 1, arguments, &exception);
312  if (exception)
313  {
314  LOG_ERROR_EX("Error: exception creating an error object");
315  return NULL;
316  }
317 
318  return retVal;
319 }
320 
321 /**
322  * @brief Convert JS event name to AAMP event type
323  */
325 {
326  AAMPEventType eventType = AAMP_MAX_NUM_EVENTS;
327  int numEvents = sizeof(aamp_eventTypes) / sizeof(aamp_eventTypes[0]);
328 
329  for (int i=0; i<numEvents; i++)
330  {
331  if (strcasecmp(aamp_eventTypes[i].szName, szName) == 0)
332  {
333  eventType = aamp_eventTypes[i].eventType;
334  break;
335  }
336  }
337 
338  return eventType;
339 }
340 
341 /**
342  * @brief To dispatch a JS event
343  */
344 void aamp_dispatchEventToJS(JSContextRef context, JSObjectRef callback, JSObjectRef event)
345 {
346  JSValueRef args[1] = { event };
347  if (context != NULL && callback != NULL)
348  {
349  JSObjectCallAsFunction(context, callback, NULL, 1, args, NULL);
350  }
351 }
352 
353 /**
354  * @brief Convert JS event name to AAMP event type (AAMPMediaPlayer)
355  */
357 {
358 //TODO: Need separate event list for now to avoid breaking existing viper impl. Unify later
359  AAMPEventType eventType = AAMP_MAX_NUM_EVENTS;
360  int numEvents = sizeof(aampPlayer_eventTypes) / sizeof(aampPlayer_eventTypes[0]);
361 
362  for (int i=0; i<numEvents; i++)
363  {
364  if (strcasecmp(aampPlayer_eventTypes[i].szName, szName) == 0)
365  {
366  eventType = aampPlayer_eventTypes[i].eventType;
367  break;
368  }
369  }
370 
371  return eventType;
372 }
373 
374 /**
375  * @brief Convert AAMP event type to JS event string (AAMPMediaPlayer)
376  */
378 {
379 //TODO: Need separate API to avoid breaking existing viper impl. Unify later.
380  if (type > 0 && type < AAMP_MAX_NUM_EVENTS)
381  {
382  return aampPlayer_eventTypes[type].szName;
383  }
384  else
385  {
386  return NULL;
387  }
388 }
389 
390 
391 /**
392  * @brief Create a TimedMetadata JS object with args passed.
393  * Sample input "#EXT-X-CUE:ID=eae90713-db8e,DURATION=30.063"
394  * Sample output {"time":62062,"duration":0,"name":"#EXT-X-CUE","content":"-X-CUE:ID=eae90713-db8e,DURATION=30.063","type":0,"metadata":{"ID":"eae90713-db8e","DURATION":"30.063"},"id":"eae90713-db8e"}
395  */
396 JSObjectRef aamp_CreateTimedMetadataJSObject(JSContextRef context, long long timeMS, const char* szName, const char* szContent, const char* id, double durationMS)
397 {
398  JSStringRef name;
399 
400  JSObjectRef timedMetadata = JSObjectMake(context, NULL, NULL);
401 
402  if (timedMetadata) {
403  JSValueProtect(context, timedMetadata);
404  bool bGenerateID = true;
405 
406  name = JSStringCreateWithUTF8CString("time");
407  JSObjectSetProperty(context, timedMetadata, name, JSValueMakeNumber(context, std::round(timeMS)), kJSPropertyAttributeReadOnly, NULL);
408  JSStringRelease(name);
409 
410  // For SCTE35 tag, set id as value of key reservationId
411  if(!strcmp(szName, "SCTE35") && id && *id != '\0')
412  {
413  name = JSStringCreateWithUTF8CString("reservationId");
414  JSObjectSetProperty(context, timedMetadata, name, aamp_CStringToJSValue(context, id), kJSPropertyAttributeReadOnly, NULL);
415  JSStringRelease(name);
416  bGenerateID = false;
417  }
418 
419  if (durationMS >= 0)
420  {
421  name = JSStringCreateWithUTF8CString("duration");
422  JSObjectSetProperty(context, timedMetadata, name, JSValueMakeNumber(context, (int)durationMS), kJSPropertyAttributeReadOnly, NULL);
423  JSStringRelease(name);
424  }
425 
426  name = JSStringCreateWithUTF8CString("name");
427  JSObjectSetProperty(context, timedMetadata, name, aamp_CStringToJSValue(context, szName), kJSPropertyAttributeReadOnly, NULL);
428  JSStringRelease(name);
429 
430  name = JSStringCreateWithUTF8CString("content");
431  JSObjectSetProperty(context, timedMetadata, name, aamp_CStringToJSValue(context, szContent), kJSPropertyAttributeReadOnly, NULL);
432  JSStringRelease(name);
433 
434  // Force type=0 (HLS tag) for now.
435  // Does type=1 ID3 need to be supported?
436  name = JSStringCreateWithUTF8CString("type");
437  JSObjectSetProperty(context, timedMetadata, name, JSValueMakeNumber(context, 0), kJSPropertyAttributeReadOnly, NULL);
438  JSStringRelease(name);
439 
440  // Force metadata as empty object
441  JSObjectRef metadata = JSObjectMake(context, NULL, NULL);
442  if (metadata) {
443  JSValueProtect(context, metadata);
444  name = JSStringCreateWithUTF8CString("metadata");
445  JSObjectSetProperty(context, timedMetadata, name, metadata, kJSPropertyAttributeReadOnly, NULL);
446  JSStringRelease(name);
447 
448  // Parse CUE metadata and TRICKMODE-RESTRICTION metadata
449  // Parsed values are used in PlayerPlatform at the time of tag object creation
450  if ((strcmp(szName, "#EXT-X-CUE") == 0) ||
451  (strcmp(szName, "#EXT-X-TRICKMODE-RESTRICTION") == 0) ||
452  (strcmp(szName, "#EXT-X-MARKER") == 0) ||
453  (strcmp(szName, "#EXT-X-SCTE35") == 0)) {
454  const char* szStart = szContent;
455 
456  // Parse comma seperated name=value list.
457  while (*szStart != '\0') {
458  char* szSep;
459  // Find the '=' seperator.
460  for (szSep = (char*)szStart; *szSep != '=' && *szSep != '\0'; szSep++);
461 
462  // Find the end of the value.
463  char* szEnd = (*szSep != '\0') ? szSep + 1 : szSep;
464  for (; *szEnd != ',' && *szEnd != '\0'; szEnd++);
465 
466  // Append the name / value metadata.
467  if ((szStart < szSep) && (szSep < szEnd)) {
468  JSValueRef value;
469  char chSave = *szSep;
470 
471  *szSep = '\0';
472  name = JSStringCreateWithUTF8CString(szStart);
473  *szSep = chSave;
474 
475  chSave = *szEnd;
476  *szEnd = '\0';
477  value = aamp_CStringToJSValue(context, szSep+1);
478  *szEnd = chSave;
479 
480  JSObjectSetProperty(context, metadata, name, value, kJSPropertyAttributeReadOnly, NULL);
481  JSStringRelease(name);
482 
483  // If we just added the 'ID', copy into timedMetadata.id
484  if (szStart[0] == 'I' && szStart[1] == 'D' && szStart[2] == '=') {
485  bGenerateID = false;
486  name = JSStringCreateWithUTF8CString("id");
487  JSObjectSetProperty(context, timedMetadata, name, value, kJSPropertyAttributeReadOnly, NULL);
488  JSStringRelease(name);
489  }
490  }
491 
492  szStart = (*szEnd != '\0') ? szEnd + 1 : szEnd;
493  }
494  }
495  // Parse TARGETDURATION and CONTENT-IDENTIFIER metadata
496  else {
497  const char* szStart = szContent;
498  // Advance to the tag's value.
499  for (; *szStart != ':' && *szStart != '\0'; szStart++);
500  if (*szStart == ':')
501  szStart++;
502 
503  // Stuff all content into DATA name/value pair.
504  JSValueRef value = aamp_CStringToJSValue(context, szStart);
505  if (strcmp(szName, "#EXT-X-TARGETDURATION") == 0) {
506  // Stuff into DURATION if EXT-X-TARGETDURATION content.
507  // Since #EXT-X-TARGETDURATION has only duration as value
508  name = JSStringCreateWithUTF8CString("DURATION");
509  } else {
510  name = JSStringCreateWithUTF8CString("DATA");
511  }
512  JSObjectSetProperty(context, metadata, name, value, kJSPropertyAttributeReadOnly, NULL);
513  JSStringRelease(name);
514  }
515  JSValueUnprotect(context, metadata);
516  }
517 
518  // Generate an ID since the tag is missing one
519  if (bGenerateID) {
520  int hash = (int)timeMS;
521  const char* szStart = szName;
522  for (; *szStart != '\0'; szStart++) {
523  hash = (hash * 33) ^ *szStart;
524  }
525 
526  char buf[32];
527  sprintf(buf, "%d", hash);
528  name = JSStringCreateWithUTF8CString("id");
529  JSObjectSetProperty(context, timedMetadata, name, aamp_CStringToJSValue(context, buf), kJSPropertyAttributeReadOnly, NULL);
530  JSStringRelease(name);
531  }
532  JSValueUnprotect(context, timedMetadata);
533  }
534 
535  return timedMetadata;
536 }
537 
538 
539 /**
540  * @brief Print logs to console / log file
541  */
542 void jsBindingLogprintf(int playerId,const char* levelstr,const char* functionName, int line,const char *format, ...)
543 {
544 
545 
546  int len = 0;
547  va_list args;
548  va_start(args, format);
549 
550  char gDebugPrintBuffer[MAX_DEBUG_LOG_BUFF_SIZE];
551  if(playerId != PLAYER_ID_NA )
552  {
553  len = sprintf(gDebugPrintBuffer,"[AAMP-JS] %d :%s : %s : %d :",playerId,levelstr,functionName,line);
554  }
555  else
556  {
557  len = sprintf(gDebugPrintBuffer,"[AAMP-JS] %s : %s: %d :",levelstr,functionName,line);
558  }
559  vsnprintf(gDebugPrintBuffer+len, MAX_DEBUG_LOG_BUFF_SIZE-len, format, args);
560  gDebugPrintBuffer[(MAX_DEBUG_LOG_BUFF_SIZE-1)] = 0;
561 
562  va_end(args);
563 
564 #if (defined (USE_SYSTEMD_JOURNAL_PRINT) || defined (USE_SYSLOG_HELPER_PRINT))
565 #ifdef USE_SYSTEMD_JOURNAL_PRINT
566 
567  sd_journal_print(LOG_NOTICE, "%s", gDebugPrintBuffer);
568 #else
569  send_logs_to_syslog(gDebugPrintBuffer);
570 #endif
571 #else
572  struct timeval t;
573  gettimeofday(&t, NULL);
574  printf("[AAMP-JS]%ld:%3ld : %s\n", (long int)t.tv_sec, (long int)t.tv_usec / 1000, gDebugPrintBuffer);
575 
576 #endif
577 
578 }
AAMP_EVENT_DRM_METADATA
@ AAMP_EVENT_DRM_METADATA
Definition: AampEvent.h:71
AAMP_EVENT_BULK_TIMED_METADATA
@ AAMP_EVENT_BULK_TIMED_METADATA
Definition: AampEvent.h:59
jsBindingLogprintf
void jsBindingLogprintf(int playerId, const char *levelstr, const char *functionName, int line, const char *format,...)
Print logs to console / log file.
Definition: jsutils.cpp:542
aamp_dispatchEventToJS
void aamp_dispatchEventToJS(JSContextRef context, JSObjectRef callback, JSObjectRef event)
To dispatch a JS event.
Definition: jsutils.cpp:344
aamp_GetException
JSValueRef aamp_GetException(JSContextRef context, ErrorCode error, const char *additionalInfo)
Generate a JSValue object with the exception details.
Definition: jsutils.cpp:278
aamp_eventTypes
static EventTypeMap aamp_eventTypes[]
Map AAMP events to its corresponding JS event strings (used by JSPP)
Definition: jsutils.cpp:57
aampPlayer_getEventTypeFromName
AAMPEventType aampPlayer_getEventTypeFromName(const char *szName)
Convert JS event name to AAMP event type (AAMPMediaPlayer)
Definition: jsutils.cpp:356
AAMP_EVENT_CONTENT_GAP
@ AAMP_EVENT_CONTENT_GAP
Definition: AampEvent.h:85
AAMP_EVENT_AD_PLACEMENT_END
@ AAMP_EVENT_AD_PLACEMENT_END
Definition: AampEvent.h:78
AAMP_EVENT_BUFFERING_CHANGED
@ AAMP_EVENT_BUFFERING_CHANGED
Definition: AampEvent.h:64
AAMP_EVENT_REPORT_ANOMALY
@ AAMP_EVENT_REPORT_ANOMALY
Definition: AampEvent.h:72
AAMP_EVENT_TUNE_FAILED
@ AAMP_EVENT_TUNE_FAILED
Definition: AampEvent.h:48
AAMP_EVENT_DRM_MESSAGE
@ AAMP_EVENT_DRM_MESSAGE
Definition: AampEvent.h:83
AAMP_EVENT_AD_RESERVATION_END
@ AAMP_EVENT_AD_RESERVATION_END
Definition: AampEvent.h:76
AAMP_EVENT_AD_STARTED
@ AAMP_EVENT_AD_STARTED
Definition: AampEvent.h:69
AAMP_EVENT_AD_BREAKS_CHANGED
@ AAMP_EVENT_AD_BREAKS_CHANGED
Definition: AampEvent.h:68
AAMP_EVENT_DURATION_CHANGED
@ AAMP_EVENT_DURATION_CHANGED
Definition: AampEvent.h:65
AAMP_EVENT_AD_COMPLETED
@ AAMP_EVENT_AD_COMPLETED
Definition: AampEvent.h:70
jsutils.h
JavaScript util functions for AAMP.
AAMP_EVENT_WATERMARK_SESSION_UPDATE
@ AAMP_EVENT_WATERMARK_SESSION_UPDATE
Definition: AampEvent.h:87
AAMP_EVENT_ENTERING_LIVE
@ AAMP_EVENT_ENTERING_LIVE
Definition: AampEvent.h:56
aampPlayer_eventTypes
static EventTypeMap aampPlayer_eventTypes[]
Map AAMP events to its corresponding JS event strings (used by AAMPMediaPlayer/UVE APIs)
Definition: jsutils.cpp:100
aamp_StringArrayToCStringArray
std::vector< std::string > aamp_StringArrayToCStringArray(JSContextRef context, JSValueRef arrayRef)
Convert an array of JSString to an array of C strings.
Definition: jsutils.cpp:213
AAMP_EVENT_PLAYLIST_INDEXED
@ AAMP_EVENT_PLAYLIST_INDEXED
Definition: AampEvent.h:51
AAMP_EVENT_STATE_CHANGED
@ AAMP_EVENT_STATE_CHANGED
Definition: AampEvent.h:60
aampPlayer_getNameFromEventType
const char * aampPlayer_getNameFromEventType(AAMPEventType type)
Convert AAMP event type to JS event string (AAMPMediaPlayer)
Definition: jsutils.cpp:377
ErrorCode
ErrorCode
JavaScript error codes.
Definition: jsutils.h:65
AAMP_EVENT_SPEEDS_CHANGED
@ AAMP_EVENT_SPEEDS_CHANGED
Definition: AampEvent.h:61
AAMP_EVENT_BLOCKED
@ AAMP_EVENT_BLOCKED
Definition: AampEvent.h:84
AAMP_EVENT_AD_PLACEMENT_PROGRESS
@ AAMP_EVENT_AD_PLACEMENT_PROGRESS
Definition: AampEvent.h:80
AAMP_EVENT_SPEED_CHANGED
@ AAMP_EVENT_SPEED_CHANGED
Definition: AampEvent.h:49
aamp_getEventTypeFromName
AAMPEventType aamp_getEventTypeFromName(const char *szName)
Convert JS event name to AAMP event type.
Definition: jsutils.cpp:324
aamp_CreateTimedMetadataJSObject
JSObjectRef aamp_CreateTimedMetadataJSObject(JSContextRef context, long long timeMS, const char *szName, const char *szContent, const char *id, double durationMS)
Create a TimedMetadata JS object with args passed. Sample input "#EXT-X-CUE:ID=eae90713-db8e,...
Definition: jsutils.cpp:396
AAMP_EVENT_AD_RESOLVED
@ AAMP_EVENT_AD_RESOLVED
Definition: AampEvent.h:74
AAMP_EVENT_AUDIO_TRACKS_CHANGED
@ AAMP_EVENT_AUDIO_TRACKS_CHANGED
Definition: AampEvent.h:66
AAMP_EVENT_JS_EVENT
@ AAMP_EVENT_JS_EVENT
Definition: AampEvent.h:54
AAMP_EVENT_CONTENT_PROTECTION_DATA_UPDATE
@ AAMP_EVENT_CONTENT_PROTECTION_DATA_UPDATE
Definition: AampEvent.h:88
AAMP_EVENT_TEXT_TRACKS_CHANGED
@ AAMP_EVENT_TEXT_TRACKS_CHANGED
Definition: AampEvent.h:67
LOG_WARN_EX
#define LOG_WARN_EX(FORMAT,...)
Definition: jsutils.h:44
AAMP_EVENT_TUNE_PROFILING
@ AAMP_EVENT_TUNE_PROFILING
Definition: AampEvent.h:63
aamp_JSValueToCString
char * aamp_JSValueToCString(JSContextRef context, JSValueRef value, JSValueRef *exception)
Convert JSString to C string.
Definition: jsutils.cpp:164
AAMP_EVENT_EOS
@ AAMP_EVENT_EOS
Definition: AampEvent.h:50
AAMP_EVENT_ID3_METADATA
@ AAMP_EVENT_ID3_METADATA
Definition: AampEvent.h:82
AAMP_EVENT_TUNED
@ AAMP_EVENT_TUNED
Definition: AampEvent.h:47
AAMP_EVENT_REPORT_METRICS_DATA
@ AAMP_EVENT_REPORT_METRICS_DATA
Definition: AampEvent.h:81
EventTypeMap
Struct to map names of AAMP events and JS events.
Definition: jsutils.cpp:47
AAMP_EVENT_AD_RESERVATION_START
@ AAMP_EVENT_AD_RESERVATION_START
Definition: AampEvent.h:75
AAMP_EVENT_CC_HANDLE_RECEIVED
@ AAMP_EVENT_CC_HANDLE_RECEIVED
Definition: AampEvent.h:53
MAX_DEBUG_LOG_BUFF_SIZE
#define MAX_DEBUG_LOG_BUFF_SIZE
Max debug log buffer size.
Definition: priv_aamp.h:114
AAMP_EVENT_WEBVTT_CUE_DATA
@ AAMP_EVENT_WEBVTT_CUE_DATA
Definition: AampEvent.h:73
AAMP_EVENT_MEDIA_METADATA
@ AAMP_EVENT_MEDIA_METADATA
Definition: AampEvent.h:55
AAMPEventType
AAMPEventType
Type of the events sending to the JSPP player.
Definition: AampEvent.h:44
aamp_CStringToJSValue
JSValueRef aamp_CStringToJSValue(JSContextRef context, const char *sz)
Convert C string to JSString.
Definition: jsutils.cpp:152
AAMP_EVENT_AD_PLACEMENT_START
@ AAMP_EVENT_AD_PLACEMENT_START
Definition: AampEvent.h:77
AAMP_EVENT_TIMED_METADATA
@ AAMP_EVENT_TIMED_METADATA
Definition: AampEvent.h:58
AAMP_EVENT_SEEKED
@ AAMP_EVENT_SEEKED
Definition: AampEvent.h:62
AAMP_EVENT_PROGRESS
@ AAMP_EVENT_PROGRESS
Definition: AampEvent.h:52
aamp_JSValueToJSONCString
char * aamp_JSValueToJSONCString(JSContextRef context, JSValueRef value, JSValueRef *exception)
Convert JSString to JSON C string.
Definition: jsutils.cpp:177
aamp_JSValueIsArray
bool aamp_JSValueIsArray(JSContextRef context, JSValueRef value)
Check if a JSValue object is array or not.
Definition: jsutils.cpp:190
AAMP_EVENT_HTTP_RESPONSE_HEADER
@ AAMP_EVENT_HTTP_RESPONSE_HEADER
Definition: AampEvent.h:86
AAMP_EVENT_BITRATE_CHANGED
@ AAMP_EVENT_BITRATE_CHANGED
Definition: AampEvent.h:57
AAMP_EVENT_AD_PLACEMENT_ERROR
@ AAMP_EVENT_AD_PLACEMENT_ERROR
Definition: AampEvent.h:79
LOG_TRACE
#define LOG_TRACE
Definition: rdk_debug_priv.c:83