34 #ifdef USE_SYSLOG_HELPER_PRINT
35 #include "syslog_helper_ifc.h"
37 #ifdef USE_SYSTEMD_JOURNAL_PRINT
38 #include <systemd/sd-journal.h>
41 #define MAX_DEBUG_LOG_BUFF_SIZE 1024
154 JSStringRef str = JSStringCreateWithUTF8CString(sz);
155 JSValueRef value = JSValueMakeString(context, str);
156 JSStringRelease(str);
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);
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);
192 JSObjectRef global = JSContextGetGlobalObject(context);
193 JSStringRef arrayProp = JSStringCreateWithUTF8CString(
"Array");
194 JSValueRef arrayVal = JSObjectGetProperty(context, global, arrayProp, NULL);
195 JSStringRelease(arrayProp);
197 if (JSValueIsObject(context, arrayVal))
199 JSObjectRef arrayObj = JSValueToObject(context, arrayVal, NULL);
200 if (JSObjectIsFunction(context, arrayObj) || JSObjectIsConstructor(context, arrayObj))
202 return JSValueIsInstanceOfConstructor(context, value, arrayObj, NULL);
215 std::vector<std::string> retval;
216 JSValueRef exception = NULL;
220 LOG_ERROR_EX(
"Error: value is NULL.");
223 if (!JSValueIsObject(context, arrayRef))
225 LOG_ERROR_EX(
"Error: value is not an object.");
230 LOG_ERROR_EX(
"Error: value is not an array.");
233 JSObjectRef arrayObj = JSValueToObject(context, arrayRef, &exception);
237 LOG_ERROR_EX(
"Error: exception accesing array object.");
241 JSStringRef lengthStrRef = JSStringCreateWithUTF8CString(
"length");
242 JSValueRef lengthRef = JSObjectGetProperty(context, arrayObj, lengthStrRef, &exception);
246 LOG_ERROR_EX(
"Error: exception accesing array length.");
249 int length = JSValueToNumber(context, lengthRef, &exception);
252 LOG_ERROR_EX(
"Error: exception array length in not a number.");
256 retval.reserve(length);
257 for(
int i = 0; i < length; i++)
259 JSValueRef strRef = JSObjectGetPropertyAtIndex(context, arrayObj, i, &exception);
265 retval.push_back(str);
266 SAFE_DELETE_ARRAY(str);
269 JSStringRelease(lengthStrRef);
280 const char *str =
"Generic Error";
285 case AAMPJS_INVALID_ARGUMENT:
286 case AAMPJS_MISSING_OBJECT:
290 str =
"Generic Error";
294 char exceptionMsg[EXCEPTION_ERR_MSG_MAX_LEN];
295 memset(exceptionMsg,
'\0', EXCEPTION_ERR_MSG_MAX_LEN);
299 snprintf(exceptionMsg, EXCEPTION_ERR_MSG_MAX_LEN - 1,
"%s: %s", str, additionalInfo);
303 snprintf(exceptionMsg, EXCEPTION_ERR_MSG_MAX_LEN - 1,
"%s!!", str);
310 JSValueRef exception = NULL;
311 retVal = JSObjectMakeError(context, 1, arguments, &exception);
314 LOG_ERROR_EX(
"Error: exception creating an error object");
329 for (
int i=0; i<numEvents; i++)
346 JSValueRef args[1] = {
event };
347 if (context != NULL && callback != NULL)
349 JSObjectCallAsFunction(context, callback, NULL, 1, args, NULL);
362 for (
int i=0; i<numEvents; i++)
380 if (type > 0 && type < AAMP_MAX_NUM_EVENTS)
400 JSObjectRef timedMetadata = JSObjectMake(context, NULL, NULL);
403 JSValueProtect(context, timedMetadata);
404 bool bGenerateID =
true;
406 name = JSStringCreateWithUTF8CString(
"time");
407 JSObjectSetProperty(context, timedMetadata, name, JSValueMakeNumber(context, std::round(timeMS)), kJSPropertyAttributeReadOnly, NULL);
408 JSStringRelease(name);
411 if(!strcmp(szName,
"SCTE35") &&
id && *
id !=
'\0')
413 name = JSStringCreateWithUTF8CString(
"reservationId");
414 JSObjectSetProperty(context, timedMetadata, name,
aamp_CStringToJSValue(context,
id), kJSPropertyAttributeReadOnly, NULL);
415 JSStringRelease(name);
421 name = JSStringCreateWithUTF8CString(
"duration");
422 JSObjectSetProperty(context, timedMetadata, name, JSValueMakeNumber(context, (
int)durationMS), kJSPropertyAttributeReadOnly, NULL);
423 JSStringRelease(name);
426 name = JSStringCreateWithUTF8CString(
"name");
427 JSObjectSetProperty(context, timedMetadata, name,
aamp_CStringToJSValue(context, szName), kJSPropertyAttributeReadOnly, NULL);
428 JSStringRelease(name);
430 name = JSStringCreateWithUTF8CString(
"content");
431 JSObjectSetProperty(context, timedMetadata, name,
aamp_CStringToJSValue(context, szContent), kJSPropertyAttributeReadOnly, NULL);
432 JSStringRelease(name);
436 name = JSStringCreateWithUTF8CString(
"type");
437 JSObjectSetProperty(context, timedMetadata, name, JSValueMakeNumber(context, 0), kJSPropertyAttributeReadOnly, NULL);
438 JSStringRelease(name);
441 JSObjectRef metadata = JSObjectMake(context, NULL, NULL);
443 JSValueProtect(context, metadata);
444 name = JSStringCreateWithUTF8CString(
"metadata");
445 JSObjectSetProperty(context, timedMetadata, name, metadata, kJSPropertyAttributeReadOnly, NULL);
446 JSStringRelease(name);
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;
457 while (*szStart !=
'\0') {
460 for (szSep = (
char*)szStart; *szSep !=
'=' && *szSep !=
'\0'; szSep++);
463 char* szEnd = (*szSep !=
'\0') ? szSep + 1 : szSep;
464 for (; *szEnd !=
',' && *szEnd !=
'\0'; szEnd++);
467 if ((szStart < szSep) && (szSep < szEnd)) {
469 char chSave = *szSep;
472 name = JSStringCreateWithUTF8CString(szStart);
480 JSObjectSetProperty(context, metadata, name, value, kJSPropertyAttributeReadOnly, NULL);
481 JSStringRelease(name);
484 if (szStart[0] ==
'I' && szStart[1] ==
'D' && szStart[2] ==
'=') {
486 name = JSStringCreateWithUTF8CString(
"id");
487 JSObjectSetProperty(context, timedMetadata, name, value, kJSPropertyAttributeReadOnly, NULL);
488 JSStringRelease(name);
492 szStart = (*szEnd !=
'\0') ? szEnd + 1 : szEnd;
497 const char* szStart = szContent;
499 for (; *szStart !=
':' && *szStart !=
'\0'; szStart++);
505 if (strcmp(szName,
"#EXT-X-TARGETDURATION") == 0) {
508 name = JSStringCreateWithUTF8CString(
"DURATION");
510 name = JSStringCreateWithUTF8CString(
"DATA");
512 JSObjectSetProperty(context, metadata, name, value, kJSPropertyAttributeReadOnly, NULL);
513 JSStringRelease(name);
515 JSValueUnprotect(context, metadata);
520 int hash = (int)timeMS;
521 const char* szStart = szName;
522 for (; *szStart !=
'\0'; szStart++) {
523 hash = (hash * 33) ^ *szStart;
527 sprintf(buf,
"%d", hash);
528 name = JSStringCreateWithUTF8CString(
"id");
529 JSObjectSetProperty(context, timedMetadata, name,
aamp_CStringToJSValue(context, buf), kJSPropertyAttributeReadOnly, NULL);
530 JSStringRelease(name);
532 JSValueUnprotect(context, timedMetadata);
535 return timedMetadata;
542 void jsBindingLogprintf(
int playerId,
const char* levelstr,
const char* functionName,
int line,
const char *format, ...)
548 va_start(args, format);
551 if(playerId != PLAYER_ID_NA )
553 len = sprintf(gDebugPrintBuffer,
"[AAMP-JS] %d :%s : %s : %d :",playerId,levelstr,functionName,line);
557 len = sprintf(gDebugPrintBuffer,
"[AAMP-JS] %s : %s: %d :",levelstr,functionName,line);
564 #if (defined (USE_SYSTEMD_JOURNAL_PRINT) || defined (USE_SYSLOG_HELPER_PRINT))
565 #ifdef USE_SYSTEMD_JOURNAL_PRINT
567 sd_journal_print(LOG_NOTICE,
"%s", gDebugPrintBuffer);
569 send_logs_to_syslog(gDebugPrintBuffer);
573 gettimeofday(&t, NULL);
574 printf(
"[AAMP-JS]%ld:%3ld : %s\n", (
long int)t.tv_sec, (
long int)t.tv_usec / 1000, gDebugPrintBuffer);