26 #include <JavaScriptCore/JavaScript.h>
32 #include "jsbindings-version.h"
37 #ifdef AAMP_CC_ENABLED
42 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
66 JSGlobalContextRef _ctx;
71 JSObjectRef _eventType;
72 JSObjectRef _subscribedTags;
73 JSObjectRef _promiseCallback;
86 static JSObjectRef
AAMP_class_constructor(JSContextRef context, JSObjectRef constructor,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
88 *exception =
aamp_GetException(context, AAMPJS_GENERIC_ERROR,
"Cannot create an object of AAMP");
108 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
109 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.closedCaptionEnabled on instances of AAMP");
110 return JSValueMakeUndefined(context);
112 return JSValueMakeUndefined(context);
131 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
132 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.closedCaptionEnabled on instances of AAMP");
154 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
155 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.initialBufferTime on instances of AAMP");
156 return JSValueMakeUndefined(context);
158 return JSValueMakeUndefined(context);
177 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
178 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.initialBufferTime on instances of AAMP");
199 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
200 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.trickPlayEnabled on instances of AAMP");
201 return JSValueMakeUndefined(context);
203 return JSValueMakeUndefined(context);
223 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
224 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.trickPlayEnabled on instances of AAMP");
245 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
246 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.EventType on instances of AAMP");
247 return JSValueMakeUndefined(context);
249 return pAAMP->_eventType;
267 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
268 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.mediaType on instances of AAMP");
269 return JSValueMakeUndefined(context);
272 if (pAAMP->_aamp->
IsLive())
291 static JSValueRef
AAMP_getProperty_Version(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
297 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
298 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.version on instances of AAMP");
299 return JSValueMakeUndefined(context);
320 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
321 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.audioLanguage on instances of AAMP");
322 return JSValueMakeUndefined(context);
326 LOG_INFO(pAAMP,
"_aamp->GetCurrentAudioLanguage() %s",language);
344 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
345 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.currentDRM on instances of AAMP");
346 return JSValueMakeUndefined(context);
350 LOG_INFO(pAAMP,
"_aamp->GetCurrentDRM() %s",drm);
369 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
370 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.timedMetadata on instances of AAMP");
371 return JSValueMakeUndefined(context);
375 if (privAAMP == NULL)
377 LOG_ERROR_EX(
"privAAMP not initialized");
378 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"AAMP.timedMetadata - initialization error");
379 return JSValueMakeUndefined(context);
382 int32_t length = privAAMP->timedMetadata.size();
384 JSValueRef* array =
new JSValueRef[length];
385 for (int32_t i = 0; i < length; i++)
392 JSValueRef prop = JSObjectMakeArray(context, length, array, NULL);
393 SAFE_DELETE_ARRAY(array);
414 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
415 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.stallErrorCode on instances of AAMP");
418 LOG_WARN(pAAMP,
"_aamp->SetStallErrorCode context=%p value=%d exception=%p ",context, value, exception);
439 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
440 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.stallTimeout on instances of AAMP");
443 LOG_WARN(pAAMP,
"_aamp->SetStallTimeout context=%p value=%d exception=%p",context, value, exception);
444 pAAMP->_aamp->
SetStallTimeout(JSValueToNumber(context, value, exception));
464 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
465 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.reportInterval on instances of AAMP");
468 LOG_WARN(pAAMP,
"_aamp->SetReportInterval context=%p value=%d exception=%p ",context, value, exception);
488 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
489 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.reportInterval on instances of AAMP");
492 LOG_WARN(pAAMP,
"_aamp->SetNativeCCRendering context=%p value=%d ",context, value);
512 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
513 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.reportInterval on instances of AAMP");
516 LOG_WARN(pAAMP,
"_aamp->SetCEAFormat context=%p value=%d exception=%p ",context, value, exception);
517 pAAMP->_aamp->
SetCEAFormat((
int)JSValueToNumber(context, value, exception));
540 {NULL, NULL, NULL, 0}
557 static void Event_init(JSContextRef ctx, JSObjectRef thisObject)
573 JSObjectSetPrivate(thisObject, NULL);
589 static JSObjectRef
Event_constructor(JSContextRef ctx, JSObjectRef constructor,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* execption)
602 kJSClassAttributeNone,
626 static JSClassRef _classRef = NULL;
654 , _jsCallback(jsCallback)
657 LOG_TRACE(
"ctx=%p, type=%d, jsCallback=%p", _aamp->_ctx, _type, _jsCallback);
658 JSValueProtect(_aamp->_ctx, _jsCallback);
667 LOG_TRACE(
"ctx=%p, type=%d, jsCallback=%p", _aamp->_ctx, _type, _jsCallback);
668 JSValueUnprotect(_aamp->_ctx, _jsCallback);
689 LOG_WARN( _aamp,
"ctx=%p, type=%d, jsCallback=%p", _aamp->_ctx,evtType, _jsCallback);
692 JSObjectRef eventObj = JSObjectMake(_aamp->_ctx,
Event_class_ref(), NULL);
694 JSValueProtect(_aamp->_ctx, eventObj);
695 JSStringRef name = JSStringCreateWithUTF8CString(
"type");
696 JSObjectSetProperty(_aamp->_ctx, eventObj, name, JSValueMakeNumber(_aamp->_ctx, evtType), kJSPropertyAttributeReadOnly, NULL);
697 JSStringRelease(name);
699 JSValueRef args[1] = { eventObj };
702 if (_aamp->_promiseCallback != NULL)
704 JSObjectCallAsFunction(_aamp->_ctx, _aamp->_promiseCallback, NULL, 1, args, NULL);
708 LOG_WARN( _aamp,
"No promise callback registered ctx=%p, jsCallback=%p", _aamp->_ctx, _aamp->_promiseCallback);
714 JSObjectCallAsFunction(_aamp->_ctx, _jsCallback, NULL, 1, args, NULL);
716 JSValueUnprotect(_aamp->_ctx, eventObj);
733 JSObjectRef _jsCallback;
763 ProgressEventPtr evt = std::dynamic_pointer_cast<ProgressEvent>(e);
767 name = JSStringCreateWithUTF8CString(
"durationMiliseconds");
768 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getDuration()), kJSPropertyAttributeReadOnly, NULL);
769 JSStringRelease(name);
771 name = JSStringCreateWithUTF8CString(
"positionMiliseconds");
772 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getPosition()), kJSPropertyAttributeReadOnly, NULL);
773 JSStringRelease(name);
775 name = JSStringCreateWithUTF8CString(
"playbackSpeed");
776 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getSpeed()), kJSPropertyAttributeReadOnly, NULL);
777 JSStringRelease(name);
779 name = JSStringCreateWithUTF8CString(
"startMiliseconds");
780 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getStart()), kJSPropertyAttributeReadOnly, NULL);
781 JSStringRelease(name);
783 name = JSStringCreateWithUTF8CString(
"endMiliseconds");
784 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getEnd()), kJSPropertyAttributeReadOnly, NULL);
785 JSStringRelease(name);
787 name = JSStringCreateWithUTF8CString(
"currentPTS");
788 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getPTS()), kJSPropertyAttributeReadOnly, NULL);
789 JSStringRelease(name);
791 name = JSStringCreateWithUTF8CString(
"videoBufferedMiliseconds");
792 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getBufferedDuration()), kJSPropertyAttributeReadOnly, NULL);
793 JSStringRelease(name);
795 name = JSStringCreateWithUTF8CString(
"timecode");
796 JSObjectSetProperty(context, eventObj, name,
aamp_CStringToJSValue(context, evt->getSEITimeCode()), kJSPropertyAttributeReadOnly, NULL);
797 JSStringRelease(name);
827 BitrateChangeEventPtr evt = std::dynamic_pointer_cast<BitrateChangeEvent>(e);
830 name = JSStringCreateWithUTF8CString(
"time");
831 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getTime()), kJSPropertyAttributeReadOnly, NULL);
832 JSStringRelease(name);
834 name = JSStringCreateWithUTF8CString(
"bitRate");
835 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getBitrate()), kJSPropertyAttributeReadOnly, NULL);
836 JSStringRelease(name);
838 name = JSStringCreateWithUTF8CString(
"description");
839 JSObjectSetProperty(context, eventObj, name,
aamp_CStringToJSValue(context, evt->getDescription().c_str()), kJSPropertyAttributeReadOnly, NULL);
840 JSStringRelease(name);
842 name = JSStringCreateWithUTF8CString(
"width");
843 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getWidth()), kJSPropertyAttributeReadOnly, NULL);
844 JSStringRelease(name);
846 name = JSStringCreateWithUTF8CString(
"height");
847 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getHeight()), kJSPropertyAttributeReadOnly, NULL);
848 JSStringRelease(name);
850 name = JSStringCreateWithUTF8CString(
"framerate");
851 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getFrameRate()), kJSPropertyAttributeReadOnly, NULL);
852 JSStringRelease(name);
854 name = JSStringCreateWithUTF8CString(
"position");
855 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getPosition()), kJSPropertyAttributeReadOnly, NULL);
856 name = JSStringCreateWithUTF8CString(
"cappedProfile");
857 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getCappedProfileStatus()), kJSPropertyAttributeReadOnly, NULL);
859 JSStringRelease(name);
861 name = JSStringCreateWithUTF8CString(
"displayWidth");
862 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getDisplayWidth()), kJSPropertyAttributeReadOnly, NULL);
864 JSStringRelease(name);
866 name = JSStringCreateWithUTF8CString(
"displayHeight");
867 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getDisplayHeight()), kJSPropertyAttributeReadOnly, NULL);
869 JSStringRelease(name);
899 SpeedChangedEventPtr evt = std::dynamic_pointer_cast<SpeedChangedEvent>(e);
903 name = JSStringCreateWithUTF8CString(
"speed");
904 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getRate()), kJSPropertyAttributeReadOnly, NULL);
905 JSStringRelease(name);
907 name = JSStringCreateWithUTF8CString(
"reason");
908 JSObjectSetProperty(context, eventObj, name,
aamp_CStringToJSValue(context,
"unknown"), kJSPropertyAttributeReadOnly, NULL);
909 JSStringRelease(name);
939 MediaErrorEventPtr evt = std::dynamic_pointer_cast<MediaErrorEvent>(e);
941 int code = evt->getCode();
942 const char* description = evt->getDescription().c_str();
944 JSStringRef name = JSStringCreateWithUTF8CString(
"code");
945 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, code), kJSPropertyAttributeReadOnly, NULL);
946 JSStringRelease(name);
948 name = JSStringCreateWithUTF8CString(
"description");
949 JSObjectSetProperty(context, eventObj, name,
aamp_CStringToJSValue(context, description), kJSPropertyAttributeReadOnly, NULL);
950 JSStringRelease(name);
952 name = JSStringCreateWithUTF8CString(
"shouldRetry");
953 JSObjectSetProperty(context, eventObj, name, JSValueMakeBoolean(context, evt->shouldRetry()), kJSPropertyAttributeReadOnly, NULL);
954 JSStringRelease(name);
956 if(-1 != evt->getClass())
958 name = JSStringCreateWithUTF8CString(
"class");
959 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getClass()), kJSPropertyAttributeReadOnly, NULL);
960 JSStringRelease(name);
962 name = JSStringCreateWithUTF8CString(
"reason");
963 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getReason()), kJSPropertyAttributeReadOnly, NULL);
964 JSStringRelease(name);
966 name = JSStringCreateWithUTF8CString(
"businessStatus");
967 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getBusinessStatus()), kJSPropertyAttributeReadOnly, NULL);
968 JSStringRelease(name);
1002 DrmMetaDataEventPtr evt = std::dynamic_pointer_cast<DrmMetaDataEvent>(e);
1005 int code = evt->getAccessStatusValue();
1006 const char* description = evt->getAccessStatus().c_str();
1008 LOG_WARN_EX(
"AAMP_JSListener_DRMMetadata code %d Description %s", code, description);
1009 name = JSStringCreateWithUTF8CString(
"code");
1010 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, code), kJSPropertyAttributeReadOnly, NULL);
1011 JSStringRelease(name);
1013 name = JSStringCreateWithUTF8CString(
"description");
1014 JSObjectSetProperty(context, eventObj, name,
aamp_CStringToJSValue(context, description), kJSPropertyAttributeReadOnly, NULL);
1015 JSStringRelease(name);
1046 AnomalyReportEventPtr evt = std::dynamic_pointer_cast<AnomalyReportEvent>(e);
1049 int severity = evt->getSeverity();
1050 const char* description = evt->getMessage().c_str();
1052 LOG_WARN_EX(
"AAMP_JSListener_AnomalyReport severity %d Description %s",severity,description);
1053 name = JSStringCreateWithUTF8CString(
"severity");
1054 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, severity), kJSPropertyAttributeReadOnly, NULL);
1055 JSStringRelease(name);
1057 name = JSStringCreateWithUTF8CString(
"description");
1058 JSObjectSetProperty(context, eventObj, name,
aamp_CStringToJSValue(context, description), kJSPropertyAttributeReadOnly, NULL);
1059 JSStringRelease(name);
1090 MetricsDataEventPtr evt = std::dynamic_pointer_cast<MetricsDataEvent>(e);
1091 JSStringRef strJSObj;
1093 strJSObj = JSStringCreateWithUTF8CString(
"metricType");
1094 JSObjectSetProperty(context, eventObj, strJSObj, JSValueMakeNumber(context, evt->getMetricsDataType()), kJSPropertyAttributeReadOnly, NULL);
1095 JSStringRelease(strJSObj);
1097 strJSObj = JSStringCreateWithUTF8CString(
"traceID");
1098 JSObjectSetProperty(context, eventObj, strJSObj,
aamp_CStringToJSValue(context, evt->getMetricUUID().c_str()), kJSPropertyAttributeReadOnly, NULL);
1099 JSStringRelease(strJSObj);
1101 strJSObj = JSStringCreateWithUTF8CString(
"metricData");
1102 JSObjectSetProperty(context, eventObj, strJSObj,
aamp_CStringToJSValue(context, evt->getMetricsData().c_str()), kJSPropertyAttributeReadOnly, NULL);
1103 JSStringRelease(strJSObj);
1133 CCHandleEventPtr evt = std::dynamic_pointer_cast<CCHandleEvent>(e);
1136 name = JSStringCreateWithUTF8CString(
"decoderHandle");
1137 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getCCHandle()), kJSPropertyAttributeReadOnly, NULL);
1138 JSStringRelease(name);
1168 MediaMetadataEventPtr evt = std::dynamic_pointer_cast<MediaMetadataEvent>(e);
1171 name = JSStringCreateWithUTF8CString(
"durationMiliseconds");
1172 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getDuration()), kJSPropertyAttributeReadOnly, NULL);
1173 JSStringRelease(name);
1175 int count = evt->getLanguagesCount();
1176 const std::vector<std::string> &langVect = evt->getLanguages();
1177 JSValueRef* array =
new JSValueRef[count];
1178 for (int32_t i = 0; i < count; i++)
1184 JSValueRef prop = JSObjectMakeArray(context, count, array, NULL);
1185 SAFE_DELETE_ARRAY(array);
1187 name = JSStringCreateWithUTF8CString(
"languages");
1188 JSObjectSetProperty(context, eventObj, name, prop, kJSPropertyAttributeReadOnly, NULL);
1189 JSStringRelease(name);
1191 count = evt->getBitratesCount();
1192 const std::vector<long> &bitrateVect = evt->getBitrates();
1193 array =
new JSValueRef[count];
1194 for (int32_t i = 0; i < count; i++)
1196 array[i] = JSValueMakeNumber(context, bitrateVect[i]);
1198 prop = JSObjectMakeArray(context, count, array, NULL);
1199 SAFE_DELETE_ARRAY(array);
1201 name = JSStringCreateWithUTF8CString(
"bitrates");
1202 JSObjectSetProperty(context, eventObj, name, prop, kJSPropertyAttributeReadOnly, NULL);
1203 JSStringRelease(name);
1205 count = evt->getSupportedSpeedCount();
1206 const std::vector<float> &speedVect = evt->getSupportedSpeeds();
1207 array =
new JSValueRef[count];
1208 for (int32_t i = 0; i < count; i++)
1210 array[i] = JSValueMakeNumber(context, speedVect[i]);
1212 prop = JSObjectMakeArray(context, count, array, NULL);
1213 SAFE_DELETE_ARRAY(array);
1215 name = JSStringCreateWithUTF8CString(
"playbackSpeeds");
1216 JSObjectSetProperty(context, eventObj, name, prop, kJSPropertyAttributeReadOnly, NULL);
1217 JSStringRelease(name);
1219 name = JSStringCreateWithUTF8CString(
"width");
1220 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getWidth()), kJSPropertyAttributeReadOnly, NULL);
1221 JSStringRelease(name);
1223 name = JSStringCreateWithUTF8CString(
"height");
1224 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getHeight()), kJSPropertyAttributeReadOnly, NULL);
1225 JSStringRelease(name);
1227 name = JSStringCreateWithUTF8CString(
"hasDrm");
1228 JSObjectSetProperty(context, eventObj, name, JSValueMakeBoolean(context, evt->hasDrm()), kJSPropertyAttributeReadOnly, NULL);
1229 JSStringRelease(name);
1259 BulkTimedMetadataEventPtr evt = std::dynamic_pointer_cast<BulkTimedMetadataEvent>(e);
1260 JSStringRef name = JSStringCreateWithUTF8CString(
"timedMetadatas");
1261 JSObjectSetProperty(context, eventObj, name,
aamp_CStringToJSValue(context, evt->getContent().c_str()), kJSPropertyAttributeReadOnly, NULL);
1262 JSStringRelease(name);
1293 TimedMetadataEventPtr evt = std::dynamic_pointer_cast<TimedMetadataEvent>(e);
1295 JSObjectRef timedMetadata =
aamp_CreateTimedMetadataJSObject(context, evt->getTime(), evt->getName().c_str(), evt->getContent().c_str(), evt->getId().c_str(), evt->getDuration());
1296 if (timedMetadata) {
1297 JSValueProtect(context, timedMetadata);
1298 JSStringRef name = JSStringCreateWithUTF8CString(
"timedMetadata");
1299 JSObjectSetProperty(context, eventObj, name, timedMetadata, kJSPropertyAttributeReadOnly, NULL);
1300 JSStringRelease(name);
1301 JSValueUnprotect(context, timedMetadata);
1331 ContentGapEventPtr evt = std::dynamic_pointer_cast<ContentGapEvent>(e);
1334 double time = evt->getTime();
1335 double durationMs = evt->getDuration();
1337 name = JSStringCreateWithUTF8CString(
"time");
1338 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, std::round(time)), kJSPropertyAttributeReadOnly, NULL);
1339 JSStringRelease(name);
1341 if (durationMs >= 0)
1343 name = JSStringCreateWithUTF8CString(
"duration");
1344 JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, (
int)durationMs), kJSPropertyAttributeReadOnly, NULL);
1345 JSStringRelease(name);
1376 StateChangedEventPtr evt = std::dynamic_pointer_cast<StateChangedEvent>(e);
1380 prop = JSStringCreateWithUTF8CString(
"state");
1381 JSObjectSetProperty(context, eventObj, prop, JSValueMakeNumber(context, evt->getState()), kJSPropertyAttributeReadOnly, NULL);
1382 JSStringRelease(prop);
1414 SupportedSpeedsChangedEventPtr evt = std::dynamic_pointer_cast<SupportedSpeedsChangedEvent>(e);
1416 int count = evt->getSupportedSpeedCount();
1417 const std::vector<float> &speedVect = evt->getSupportedSpeeds();
1418 JSValueRef* array =
new JSValueRef[count];
1419 for (int32_t i = 0; i < count; i++)
1421 array[i] = JSValueMakeNumber(context, speedVect[i]);
1423 JSValueRef prop = JSObjectMakeArray(context, count, array, NULL);
1424 SAFE_DELETE_ARRAY(array);
1426 JSStringRef name = JSStringCreateWithUTF8CString(
"playbackSpeeds");
1427 JSObjectSetProperty(context, eventObj, name, prop, kJSPropertyAttributeReadOnly, NULL);
1428 JSStringRelease(name);
1459 AdResolvedEventPtr evt = std::dynamic_pointer_cast<AdResolvedEvent>(e);
1463 prop = JSStringCreateWithUTF8CString(
"resolvedStatus");
1464 JSObjectSetProperty(context, eventObj, prop, JSValueMakeBoolean(context, evt->getResolveStatus()), kJSPropertyAttributeReadOnly, NULL);
1465 JSStringRelease(prop);
1467 prop = JSStringCreateWithUTF8CString(
"placementId");
1468 JSObjectSetProperty(context, eventObj, prop,
aamp_CStringToJSValue(context, evt->getAdId().c_str()), kJSPropertyAttributeReadOnly, NULL);
1469 JSStringRelease(prop);
1471 prop = JSStringCreateWithUTF8CString(
"placementStartTime");
1472 JSObjectSetProperty(context, eventObj, prop, JSValueMakeNumber(context, evt->getStart()), kJSPropertyAttributeReadOnly, NULL);
1473 JSStringRelease(prop);
1475 prop = JSStringCreateWithUTF8CString(
"placementDuration");
1476 JSObjectSetProperty(context, eventObj, prop, JSValueMakeNumber(context, evt->getDuration()), kJSPropertyAttributeReadOnly, NULL);
1477 JSStringRelease(prop);
1507 AdReservationEventPtr evt = std::dynamic_pointer_cast<AdReservationEvent>(e);
1511 prop = JSStringCreateWithUTF8CString(
"adbreakId");
1512 JSObjectSetProperty(context, eventObj, prop,
aamp_CStringToJSValue(context, evt->getAdBreakId().c_str()), kJSPropertyAttributeReadOnly, NULL);
1513 JSStringRelease(prop);
1515 prop = JSStringCreateWithUTF8CString(
"time");
1516 JSObjectSetProperty(context, eventObj, prop, JSValueMakeNumber(context, evt->getPosition()), kJSPropertyAttributeReadOnly, NULL);
1517 JSStringRelease(prop);
1547 AdReservationEventPtr evt = std::dynamic_pointer_cast<AdReservationEvent>(e);
1551 prop = JSStringCreateWithUTF8CString(
"adbreakId");
1552 JSObjectSetProperty(context, eventObj, prop,
aamp_CStringToJSValue(context, evt->getAdBreakId().c_str()), kJSPropertyAttributeReadOnly, NULL);
1553 JSStringRelease(prop);
1555 prop = JSStringCreateWithUTF8CString(
"time");
1556 JSObjectSetProperty(context, eventObj, prop, JSValueMakeNumber(context, evt->getPosition()), kJSPropertyAttributeReadOnly, NULL);
1557 JSStringRelease(prop);
1587 AdPlacementEventPtr evt = std::dynamic_pointer_cast<AdPlacementEvent>(e);
1591 prop = JSStringCreateWithUTF8CString(
"adId");
1592 JSObjectSetProperty(context, eventObj, prop,
aamp_CStringToJSValue(context, evt->getAdId().c_str()), kJSPropertyAttributeReadOnly, NULL);
1593 JSStringRelease(prop);
1595 prop = JSStringCreateWithUTF8CString(
"time");
1596 JSObjectSetProperty(context, eventObj, prop, JSValueMakeNumber(context, evt->getPosition()), kJSPropertyAttributeReadOnly, NULL);
1597 JSStringRelease(prop);
1627 AdPlacementEventPtr evt = std::dynamic_pointer_cast<AdPlacementEvent>(e);
1631 prop = JSStringCreateWithUTF8CString(
"adId");
1632 JSObjectSetProperty(context, eventObj, prop,
aamp_CStringToJSValue(context, evt->getAdId().c_str()), kJSPropertyAttributeReadOnly, NULL);
1633 JSStringRelease(prop);
1635 prop = JSStringCreateWithUTF8CString(
"time");
1636 JSObjectSetProperty(context, eventObj, prop, JSValueMakeNumber(context, evt->getPosition()), kJSPropertyAttributeReadOnly, NULL);
1637 JSStringRelease(prop);
1668 AdPlacementEventPtr evt = std::dynamic_pointer_cast<AdPlacementEvent>(e);
1672 prop = JSStringCreateWithUTF8CString(
"adId");
1673 JSObjectSetProperty(context, eventObj, prop,
aamp_CStringToJSValue(context, evt->getAdId().c_str()), kJSPropertyAttributeReadOnly, NULL);
1674 JSStringRelease(prop);
1676 prop = JSStringCreateWithUTF8CString(
"time");
1677 JSObjectSetProperty(context, eventObj, prop, JSValueMakeNumber(context, evt->getPosition()), kJSPropertyAttributeReadOnly, NULL);
1678 JSStringRelease(prop);
1708 AdPlacementEventPtr evt = std::dynamic_pointer_cast<AdPlacementEvent>(e);
1712 prop = JSStringCreateWithUTF8CString(
"adId");
1713 JSObjectSetProperty(context, eventObj, prop,
aamp_CStringToJSValue(context, evt->getAdId().c_str()), kJSPropertyAttributeReadOnly, NULL);
1714 JSStringRelease(prop);
1716 prop = JSStringCreateWithUTF8CString(
"time");
1717 JSObjectSetProperty(context, eventObj, prop, JSValueMakeNumber(context, evt->getPosition()), kJSPropertyAttributeReadOnly, NULL);
1718 JSStringRelease(prop);
1720 prop = JSStringCreateWithUTF8CString(
"error");
1721 JSObjectSetProperty(context, eventObj, prop, JSValueMakeNumber(context, evt->getErrorCode()), kJSPropertyAttributeReadOnly, NULL);
1722 JSStringRelease(prop);
1752 BufferingChangedEventPtr evt = std::dynamic_pointer_cast<BufferingChangedEvent>(e);
1756 prop = JSStringCreateWithUTF8CString(
"status");
1757 JSObjectSetProperty(context, eventObj, prop, JSValueMakeBoolean(context, evt->buffering()), kJSPropertyAttributeReadOnly, NULL);
1758 JSStringRelease(prop);
1789 ID3MetadataEventPtr evt = std::dynamic_pointer_cast<ID3MetadataEvent>(e);
1790 std::vector<uint8_t> data = evt->getMetadata();
1791 int len = evt->getMetadataSize();
1794 JSValueRef* array =
new JSValueRef[len];
1795 for (int32_t i = 0; i < len; i++)
1797 array[i] = JSValueMakeNumber(context, data[i]);
1800 prop = JSStringCreateWithUTF8CString(
"data");
1801 JSObjectSetProperty(context, eventObj, prop, JSObjectMakeArray(context, len, array, NULL), kJSPropertyAttributeReadOnly, NULL);
1802 JSStringRelease(prop);
1803 SAFE_DELETE_ARRAY(array);
1805 prop = JSStringCreateWithUTF8CString(
"length");
1806 JSObjectSetProperty(context, eventObj, prop, JSValueMakeNumber(context, len), kJSPropertyAttributeReadOnly, NULL);
1807 JSStringRelease(prop);
1837 DrmMessageEventPtr evt = std::dynamic_pointer_cast<DrmMessageEvent>(e);
1839 prop = JSStringCreateWithUTF8CString(
"data");
1840 JSObjectSetProperty(context, eventObj, prop,
aamp_CStringToJSValue(context, evt->getMessage().c_str()), kJSPropertyAttributeReadOnly, NULL);
1841 JSStringRelease(prop);
1871 ContentProtectionDataEventPtr evt = std::dynamic_pointer_cast<ContentProtectionDataEvent>(e);
1872 std::vector<uint8_t> keyId = evt->getKeyID();
1873 int len = keyId.size();
1875 JSValueRef* array =
new JSValueRef[len];
1876 for (int32_t i = 0; i < len; i++)
1878 array[i] = JSValueMakeNumber(context, keyId[i]);
1881 prop = JSStringCreateWithUTF8CString(
"keyID");
1882 JSObjectSetProperty(context, eventObj, prop, JSObjectMakeArray(context, len, array, NULL), kJSPropertyAttributeReadOnly, NULL);
1883 JSStringRelease(prop);
1884 SAFE_DELETE_ARRAY(array);
1886 prop = JSStringCreateWithUTF8CString(
"streamType");
1887 JSObjectSetProperty(context, eventObj, prop,
aamp_CStringToJSValue(context, evt->getStreamType().c_str()), kJSPropertyAttributeReadOnly, NULL);
1888 JSStringRelease(prop);
1904 static JSValueRef
AAMP_addEventListener(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
1910 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1911 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.addEventListener on instances of AAMP");
1912 return JSValueMakeUndefined(context);
1915 if (argumentCount >= 2)
1917 JSObjectRef callbackObj = JSValueToObject(context, arguments[1], NULL);
1919 if (callbackObj != NULL && JSObjectIsFunction(context, callbackObj))
1923 LOG_TRACE(
"eventType='%s', %d", type, eventType);
1925 if ((eventType >= 0) && (eventType < AAMP_MAX_NUM_EVENTS))
1929 SAFE_DELETE_ARRAY(type);
1933 LOG_ERROR_EX(
"callbackObj=%p, JSObjectIsFunction(context, callbackObj) is NULL", callbackObj);
1934 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.addEventListener' - parameter 2 is not a function");
1939 LOG_ERROR_EX(
"InvalidArgument: argumentCount=%d, expected: 2", argumentCount);
1940 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.addEventListener' - 2 arguments required.");
1943 return JSValueMakeUndefined(context);
1955 LOG_TRACE(
"(%p, %d, %p)", aamp, type, jsCallback);
2064 pListener->_pNext = aamp->_listeners;
2065 aamp->_listeners = pListener;
2080 static JSValueRef
AAMP_removeEventListener(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2086 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2087 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.removeEventListener on instances of AAMP");
2088 return JSValueMakeUndefined(context);
2091 if (argumentCount >= 2)
2093 JSObjectRef callbackObj = JSValueToObject(context, arguments[1], NULL);
2095 if ((callbackObj != NULL) && (JSObjectIsFunction(context, callbackObj)))
2099 LOG_TRACE(
"eventType='%s', %d", type, eventType);
2101 if ((eventType >= 0) && (eventType < AAMP_MAX_NUM_EVENTS))
2106 SAFE_DELETE_ARRAY(type);
2110 LOG_ERROR_EX(
"InvalidArgument: callbackObj=%p, JSObjectIsFunction(context, callbackObj) is NULL", callbackObj);
2111 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.removeEventListener' - parameter 2 is not a function");
2116 LOG_ERROR_EX(
"InvalidArgument: argumentCount=%d, expected: 2", argumentCount);
2117 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.removeEventListener' - 2 arguments required.");
2120 return JSValueMakeUndefined(context);
2132 LOG_TRACE(
"(%p, %d, %p)", aamp, type, jsCallback);
2134 while (*ppListener != NULL)
2137 if ((pListener->_type == type) && (pListener->_jsCallback == jsCallback))
2139 *ppListener = pListener->_pNext;
2140 LOG_WARN_EX(
" type=%d,pListener= %p", type, pListener);
2142 SAFE_DELETE(pListener);
2145 ppListener = &pListener->_pNext;
2160 static JSValueRef
AAMP_setProperties(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2163 return JSValueMakeUndefined(context);
2177 static JSValueRef
AAMP_getProperties(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2180 return JSValueMakeUndefined(context);
2194 static JSValueRef
AAMP_tune(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2200 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2201 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.tune on instances of AAMP");
2202 return JSValueMakeUndefined(context);
2205 char* contentType = NULL;
2206 bool bFinalAttempt =
false;
2207 bool bFirstAttempt =
true;
2208 switch(argumentCount)
2212 bFinalAttempt = JSValueToBoolean(context, arguments[3]);
2216 bFirstAttempt = JSValueToBoolean(context, arguments[2]);
2227 LOG_WARN(pAAMP,
" _aamp->Tune(%d, %s, %d, %d)",
true, contentType, bFirstAttempt, bFinalAttempt);
2228 pAAMP->_aamp->
Tune(url,
true, contentType, bFirstAttempt, bFinalAttempt);
2230 SAFE_DELETE_ARRAY(url);
2232 SAFE_DELETE_ARRAY(contentType);
2235 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1 to 4", argumentCount);
2236 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.tune' - 1 argument required");
2239 return JSValueMakeUndefined(context);
2253 static JSValueRef
AAMP_load(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2259 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2260 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.load on instances of AAMP");
2261 return JSValueMakeUndefined(context);
2264 if (argumentCount == 1 || argumentCount == 2)
2266 char* contentType = NULL;
2267 char* strTraceId = NULL;
2268 char* strAuthToken = NULL;
2269 bool bFinalAttempt =
false;
2270 bool bFirstAttempt =
true;
2271 if (argumentCount == 2 && JSValueIsObject(context, arguments[1]))
2273 JSObjectRef argument = JSValueToObject(context, arguments[1], NULL);
2274 JSStringRef paramName = JSStringCreateWithUTF8CString(
"contentType");
2275 JSValueRef paramValue = JSObjectGetProperty(context, argument, paramName, NULL);
2276 if (JSValueIsString(context, paramValue))
2280 JSStringRelease(paramName);
2282 paramName = JSStringCreateWithUTF8CString(
"traceId");
2283 paramValue = JSObjectGetProperty(context, argument, paramName, NULL);
2284 if (JSValueIsString(context, paramValue))
2288 JSStringRelease(paramName);
2290 paramName = JSStringCreateWithUTF8CString(
"isInitialAttempt");
2291 paramValue = JSObjectGetProperty(context, argument, paramName, NULL);
2292 if (JSValueIsBoolean(context, paramValue))
2294 bFirstAttempt = JSValueToBoolean(context, paramValue);
2296 JSStringRelease(paramName);
2298 paramName = JSStringCreateWithUTF8CString(
"isFinalAttempt");
2299 paramValue = JSObjectGetProperty(context, argument, paramName, NULL);
2300 if (JSValueIsBoolean(context, paramValue))
2302 bFinalAttempt = JSValueToBoolean(context, paramValue);
2304 JSStringRelease(paramName);
2306 paramName = JSStringCreateWithUTF8CString(
"authToken");
2307 paramValue = JSObjectGetProperty(context, argument, paramName, NULL);
2308 if (JSValueIsString(context, paramValue))
2312 JSStringRelease(paramName);
2317 if (strAuthToken != NULL){
2318 LOG_WARN(pAAMP,
"authToken provided by the App");
2322 LOG_WARN(pAAMP,
" _aamp->Tune(%d, %d, %d, %d, %d)",
true, contentType, bFirstAttempt, bFinalAttempt, strTraceId);
2323 pAAMP->_aamp->
Tune(url,
true, contentType, bFirstAttempt, bFinalAttempt, strTraceId);
2326 SAFE_DELETE_ARRAY(url);
2327 SAFE_DELETE_ARRAY(contentType);
2328 SAFE_DELETE_ARRAY(strTraceId);
2329 SAFE_DELETE_ARRAY(strAuthToken);
2333 LOG_ERROR_EX(
"InvalidArgument: argumentCount=%d, expected: 1 or 2", argumentCount);
2334 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.load' - 1 or 2 argument required");
2336 return JSValueMakeUndefined(context);
2350 static JSValueRef
AAMP_stop(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2357 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2358 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.stop on instances of AAMP");
2359 return JSValueMakeUndefined(context);
2361 LOG_WARN(pAAMP,
" aamp->stop()");
2362 pAAMP->_aamp->
Stop();
2363 return JSValueMakeUndefined(context);
2377 static JSValueRef
AAMP_setRate(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2383 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2384 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setRate on instances of AAMP");
2385 return JSValueMakeUndefined(context);
2388 if (argumentCount < 1)
2390 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 2", argumentCount);
2391 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setRate' - 2 arguments required");
2396 float rate = (float)JSValueToNumber(context, arguments[0], exception);
2398 if(argumentCount > 1)
2400 overshoot = (int)JSValueToNumber(context, arguments[1], exception);
2403 LOG_WARN(pAAMP,
"rate=%f, overshoot=%d", rate, overshoot);
2405 LOG_WARN(pAAMP,
" _aamp->SetRate(%d, %d)", rate, overshoot);
2406 pAAMP->_aamp->
SetRate(rate, overshoot);
2409 return JSValueMakeUndefined(context);
2423 static JSValueRef
AAMP_seek(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2430 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2431 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.seek on instances of AAMP");
2432 return JSValueMakeUndefined(context);
2435 if (argumentCount != 1)
2437 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1",argumentCount);
2438 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.seek' - 1 argument required");
2442 double position = JSValueToNumber(context, arguments[0], exception);
2445 LOG_WARN(pAAMP,
"_aamp->Seek(%g)",position);
2446 pAAMP->_aamp->
Seek(position);
2449 return JSValueMakeUndefined(context);
2464 static JSValueRef
AAMP_seekToLive(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2470 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2471 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.seekToLive on instances of AAMP");
2472 return JSValueMakeUndefined(context);
2475 LOG_WARN(pAAMP,
" _aamp->SeekToLive()");
2478 return JSValueMakeUndefined(context);
2492 static JSValueRef
AAMP_setRect(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2498 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2499 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setRect on instances of AAMP");
2500 return JSValueMakeUndefined(context);
2503 if (argumentCount != 4)
2505 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 4", argumentCount);
2506 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setRect' - 4 arguments required");
2510 int x = JSValueToNumber(context, arguments[0], exception);
2511 int y = JSValueToNumber(context, arguments[1], exception);
2512 int w = JSValueToNumber(context, arguments[2], exception);
2513 int h = JSValueToNumber(context, arguments[3], exception);
2515 LOG_WARN(pAAMP,
" _aamp->SetVideoRectangle(%d, %d, %d, %d)", x,y,w,h);
2519 return JSValueMakeUndefined(context);
2533 static JSValueRef
AAMP_setVideoMute(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2539 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2540 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setVideoMute on instances of AAMP");
2541 return JSValueMakeUndefined(context);
2544 if (argumentCount != 1)
2547 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
2548 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setVideoMute' - 1 argument required");
2552 bool muted = JSValueToBoolean(context, arguments[0]);
2553 LOG_WARN(pAAMP,
" _aamp->SetVideoMute(%d)", muted);
2557 return JSValueMakeUndefined(context);
2571 static JSValueRef
AAMP_setAudioVolume(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2578 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2579 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setAudioVolume on instances of AAMP");
2580 return JSValueMakeUndefined(context);
2583 if (argumentCount != 1)
2585 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
2586 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setAudioVolume' - 1 argument required");
2590 unsigned int volume = JSValueToNumber(context, arguments[0], exception);
2591 LOG_WARN(pAAMP,
" aamp->SetAudioVolume(%d)", volume);
2594 return JSValueMakeUndefined(context);
2608 static JSValueRef
AAMP_setZoom(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2615 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2616 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setZoom on instances of AAMP");
2617 return JSValueMakeUndefined(context);
2620 if (argumentCount != 1)
2622 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
2623 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setZoom' - 1 argument required");
2629 LOG_WARN(pAAMP,
"zoomStr %s", zoomStr);
2630 if (0 == strcmp(zoomStr,
"none"))
2639 SAFE_DELETE_ARRAY(zoomStr);
2641 return JSValueMakeUndefined(context);
2655 static JSValueRef
AAMP_setLanguage(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2662 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2663 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setLanguage on instances of AAMP");
2664 return JSValueMakeUndefined(context);
2667 if (argumentCount != 1)
2669 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
2670 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setLanguage' - 1 argument required");
2676 LOG_WARN(pAAMP,
" _aamp->SetLKanguage(%s)", lang);
2679 SAFE_DELETE_ARRAY(lang);
2681 return JSValueMakeUndefined(context);
2694 static JSValueRef
AAMP_setSubscribeTags(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2701 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2702 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.subscribedTags on instances of AAMP");
2703 return JSValueMakeUndefined(context);
2706 if (argumentCount != 1)
2708 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
2709 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setSubscribeTags' - 1 argument required");
2713 LOG_ERROR(pAAMP,
"InvalidArgument: aamp_JSValueIsArray=%d",
aamp_JSValueIsArray(context, arguments[0]));
2714 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setSubscribeTags' - parameter 1 is not an array");
2718 if(pAAMP->_subscribedTags)
2720 JSValueUnprotect(pAAMP->_ctx, pAAMP->_subscribedTags);
2722 pAAMP->_subscribedTags = JSValueToObject(context, arguments[0], NULL);
2723 if(pAAMP->_subscribedTags)
2725 JSValueProtect(pAAMP->_ctx, pAAMP->_subscribedTags);
2727 LOG_WARN(pAAMP,
" _aamp->SetSubscribedTags");
2731 return JSValueMakeUndefined(context);
2745 static JSValueRef
AAMP_addCustomHTTPHeader(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2753 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2754 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.addCustomHTTPHeader on instances of AAMP");
2755 return JSValueMakeUndefined(context);
2758 if (argumentCount != 2)
2761 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 2", argumentCount);
2762 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.addCustomHTTPHeader' - 2 argument required");
2767 std::string headerName(name);
2768 std::vector<std::string> headerVal;
2770 SAFE_DELETE_ARRAY(name);
2776 else if (JSValueIsString(context, arguments[1]))
2778 headerVal.reserve(1);
2780 headerVal.push_back(value);
2781 SAFE_DELETE_ARRAY(value);
2785 if (headerVal.size() == 0)
2788 LOG_ERROR(pAAMP,
"InvalidArgument: Custom header's value is empty");
2789 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.addCustomHTTPHeader' - 2nd argument should be a string or array of strings");
2790 return JSValueMakeUndefined(context);
2792 LOG_WARN(pAAMP,
" _aamp->AddCustomHTTPHeader headerName= %s headerVal= %p",headerName.c_str(), headerVal);
2795 return JSValueMakeUndefined(context);
2809 static JSValueRef
AAMP_removeCustomHTTPHeader(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2817 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2818 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.removeCustomHTTPHeader on instances of AAMP");
2819 return JSValueMakeUndefined(context);
2822 if (argumentCount != 1)
2824 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
2825 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.removeCustomHTTPHeader' - 1 argument required");
2830 std::string headerName(name);
2831 LOG_WARN(pAAMP,
" AAMP_removeCustomHTTPHeader headerName= %s",headerName.c_str());
2833 SAFE_DELETE_ARRAY(name);
2836 return JSValueMakeUndefined(context);
2850 static JSValueRef
AAMP_setAds(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2854 return JSValueMakeUndefined(context);
2868 static JSValueRef
AAMP_getAvailableAudioTracks(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2876 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2877 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.getAvailableAudioTracks on instances of AAMP");
2878 return JSValueMakeUndefined(context);
2880 bool allTrack =
false;
2881 if (argumentCount == 1)
2883 allTrack = JSValueToBoolean(context, arguments[0]);
2886 if (!tracks.empty())
2888 LOG_WARN(pAAMP,
"Exit _aamp->GetAvailableAudioTracks(%d) tracks [%s]",allTrack,tracks.c_str());
2893 LOG_WARN(pAAMP,
" _aamp->GetAvailableAudioTracks(%d) tracks=NULL", allTrack);
2894 return JSValueMakeUndefined(context);
2908 static JSValueRef
AAMP_getAudioTrack(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2915 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2916 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.getAudioTrack on instances of AAMP");
2917 return JSValueMakeUndefined(context);
2919 return JSValueMakeNumber(context, pAAMP->_aamp->
GetAudioTrack());
2932 static JSValueRef
AAMP_getAudioTrackInfo(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2939 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2940 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.getAudioTrackInfo on instances of AAMP");
2941 return JSValueMakeUndefined(context);
2943 LOG_INFO(pAAMP,
" _aamp->GetAudioTrackInfo()");
2947 LOG_INFO(pAAMP,
" _aamp->GetAudioTrackInfo() [%s]",track.c_str());
2952 LOG_WARN(pAAMP,
" _aamp->GetAudioTrackInfo() track=NULL");
2953 return JSValueMakeUndefined(context);
2967 static JSValueRef
AAMP_getTextTrackInfo(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2973 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2974 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.getTextTrackInfo on instances of AAMP");
2975 return JSValueMakeUndefined(context);
2980 LOG_INFO(pAAMP,
"_aamp->GetTextTrackInfo [%s]",track.c_str());
2984 { LOG_WARN(pAAMP,
"_aamp->GetTextTrackInfo track=NULL");
2985 return JSValueMakeUndefined(context);
2999 static JSValueRef
AAMP_getPreferredAudioProperties(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3006 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3007 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.getPreferredAudioProperties on instances of AAMP");
3008 return JSValueMakeUndefined(context);
3011 if (!audioPreference.empty())
3013 LOG_INFO(pAAMP,
" _aamp->GetPreferredAudioProperties() [%s]",audioPreference.c_str());
3018 LOG_WARN(pAAMP,
"_aamp->GetPreferredAudioProperties() audioPreference=NULL");
3019 return JSValueMakeUndefined(context);
3033 static JSValueRef
AAMP_setAudioTrack(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3039 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3040 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setAudioTrack on instances of AAMP");
3041 return JSValueMakeUndefined(context);
3044 if (argumentCount != 1)
3046 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3047 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setAudioTrack' - 1 argument required");
3051 int index = (int) JSValueToNumber(context, arguments[0], NULL);
3055 LOG_WARN(pAAMP,
" _aamp->SetAudioTrack(%d)", index);
3061 LOG_ERROR(pAAMP,
"InvalidArgument: Track index should be >= 0!");
3062 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setAudioTrack' - argument should be >= 0");
3065 return JSValueMakeUndefined(context);
3078 static JSValueRef
AAMP_getPreferredTextProperties(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3086 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3087 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.getPreferredTextProperties on instances of AAMP");
3088 return JSValueMakeUndefined(context);
3091 if (!textPreference.empty())
3093 LOG_INFO(pAAMP,
" _aamp->GetPreferredTextProperties() [%s]",textPreference.c_str());
3098 LOG_WARN(pAAMP,
" _aamp->GetPreferredTextProperties() textPreference=NULL");
3099 return JSValueMakeUndefined(context);
3113 static JSValueRef
AAMP_getAvailableTextTracks(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3120 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3121 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.getAvailableTextTracks on instances of AAMP");
3122 return JSValueMakeUndefined(context);
3124 bool allTrack =
false;
3125 if (argumentCount == 1)
3127 allTrack = JSValueToBoolean(context, arguments[0]);
3130 if (!tracks.empty())
3132 LOG_WARN(pAAMP,
"_aamp->GetAvailableTextTracks(%d) [%s]",allTrack,tracks.c_str());
3137 LOG_WARN(pAAMP,
"_aamp->GetAvailableTextTracks(%d) tracks=NULL",allTrack);
3138 return JSValueMakeUndefined(context);
3153 static JSValueRef
AAMP_getTextTrack(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3159 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3160 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.getTextTrack on instances of AAMP");
3161 return JSValueMakeUndefined(context);
3163 LOG_INFO(pAAMP,
" _aamp->GetTextTrack()");
3164 return JSValueMakeNumber(context, pAAMP->_aamp->
GetTextTrack());
3178 static JSValueRef
AAMP_setTextTrack(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3184 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3185 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setTextTrack on instances of AAMP");
3186 return JSValueMakeUndefined(context);
3189 if (argumentCount != 1)
3191 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1 or 2", argumentCount);
3192 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setTextTrack' - atleast 1 argument required");
3196 int index = (int) JSValueToNumber(context, arguments[0], NULL);
3197 if (index >= MUTE_SUBTITLES_TRACKID)
3199 LOG_WARN(pAAMP,
" _aamp->SetTextTrack(%d)", index);
3204 LOG_ERROR(pAAMP,
"InvalidArgument - track index should be >= 0!");
3205 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Text track index should be >= -1 !");
3208 return JSValueMakeUndefined(context);
3221 static JSValueRef
AAMP_getAvailableVideoTracks(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3227 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3228 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.getAvailableAudioTracks on instances of AAMP");
3229 return JSValueMakeUndefined(context);
3232 if (!tracks.empty())
3234 LOG_INFO(pAAMP,
" _aamp->GetAvailableVideoTracks()[%s]",tracks.c_str());
3239 LOG_INFO(pAAMP,
" _aamp->GetAvailableVideoTracks() tracks=NULL");
3240 return JSValueMakeUndefined(context);
3254 static JSValueRef
AAMP_setVideoTracks(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3260 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3261 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setVideoTrack on instances of AAMP");
3262 return JSValueMakeUndefined(context);
3265 std::vector<long> bitrateList;
3266 for (
int i = 0; i < argumentCount; i++)
3268 long bitrate = JSValueToNumber(context, arguments[i], exception) ;
3269 LOG_WARN(pAAMP,
"_aamp->SetVideoTracks argCount:%d value:%ld",i, bitrate);
3270 bitrateList.push_back(bitrate);
3274 return JSValueMakeUndefined(context);
3287 static JSValueRef
AAMP_setLicenseServerURL(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3293 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3294 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setLicenseServerURL on instances of AAMP");
3295 return JSValueMakeUndefined(context);
3298 if (argumentCount != 1)
3300 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1",argumentCount);
3301 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setLicenseServerURL' - 1 argument required");
3306 LOG_WARN(pAAMP,
" _aamp->SetLicenseServerURL(%s)", url);
3308 SAFE_DELETE_ARRAY(url);
3310 return JSValueMakeUndefined(context);
3324 static JSValueRef
AAMP_setPreferredDRM(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3330 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3331 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setPreferredDRM on instances of AAMP");
3332 return JSValueMakeUndefined(context);
3335 if (argumentCount != 1)
3337 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1",argumentCount);
3338 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setPreferredDRM' - 1 argument required");
3343 if (strncasecmp(drm,
"widevine", 8) == 0)
3345 LOG_WARN(pAAMP,
"_aamp->SetPreferredDRM WideWine");
3348 if (strncasecmp(drm,
"playready", 9) == 0)
3350 LOG_WARN(pAAMP,
"_aamp->SetPreferredDRM PlayReady");
3353 SAFE_DELETE_ARRAY(drm);
3355 return JSValueMakeUndefined(context);
3368 static JSValueRef
AAMP_setAnonymousRequest(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3374 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3375 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setAnonymousRequest on instances of AAMP");
3376 return JSValueMakeUndefined(context);
3379 if (argumentCount != 1)
3381 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3382 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setAnonymousRequest' - 1 argument required");
3386 bool isAnonymousReq = JSValueToBoolean(context, arguments[0]);
3387 LOG_WARN(pAAMP,
" _aamp->SetAnonymousRequest(%d)", isAnonymousReq);
3390 return JSValueMakeUndefined(context);
3404 static JSValueRef
AAMP_setVODTrickplayFPS(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3410 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3411 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setAnonymousRequest on instances of AAMP");
3412 return JSValueMakeUndefined(context);
3415 if (argumentCount != 1)
3417 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3418 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setAnonymousRequest' - 1 argument required");
3422 int vodTrickplayFPS = (int)JSValueToNumber(context, arguments[0], exception);
3423 LOG_WARN(pAAMP,
" _aamp->SetVODTrickplayFPS(%d)", vodTrickplayFPS);
3426 return JSValueMakeUndefined(context);
3441 static JSValueRef
AAMP_setAlternateContent(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3448 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3449 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.SetAlternateContents() on instances of AAMP");
3450 return JSValueMakeUndefined(context);
3453 if (argumentCount != 2)
3455 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 2", argumentCount);
3456 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.SetAlternateContent' - 1 argument required");
3473 char *reservationId = NULL;
3474 int reservationBehavior = -1;
3478 if (JSValueIsObject(context, arguments[0]))
3481 JSObjectRef reservationObject = JSValueToObject(context, arguments[0], NULL);
3482 if (reservationObject == NULL)
3484 LOG_ERROR(pAAMP,
"Unable to convert argument to JSObject");
3485 return JSValueMakeUndefined(context);
3487 JSStringRef propName = JSStringCreateWithUTF8CString(
"reservationId");
3488 JSValueRef propValue = JSObjectGetProperty(context, reservationObject, propName, NULL);
3489 if (JSValueIsString(context, propValue))
3493 JSStringRelease(propName);
3495 propName = JSStringCreateWithUTF8CString(
"reservationBehavior");
3496 propValue = JSObjectGetProperty(context, reservationObject, propName, NULL);
3497 if (JSValueIsNumber(context, propValue))
3499 reservationBehavior = JSValueToNumber(context, propValue, NULL);
3501 JSStringRelease(propName);
3503 propName = JSStringCreateWithUTF8CString(
"placementRequest");
3504 propValue = JSObjectGetProperty(context, reservationObject, propName, NULL);
3505 if (JSValueIsObject(context, propValue))
3507 JSObjectRef adObject = JSValueToObject(context, propValue, NULL);
3509 JSStringRef adPropName = JSStringCreateWithUTF8CString(
"id");
3510 JSValueRef adPropValue = JSObjectGetProperty(context, adObject, adPropName, NULL);
3511 if (JSValueIsString(context, adPropValue))
3515 JSStringRelease(adPropName);
3517 adPropName = JSStringCreateWithUTF8CString(
"pts");
3518 adPropValue = JSObjectGetProperty(context, adObject, adPropName, NULL);
3519 if (JSValueIsNumber(context, adPropValue))
3521 adPTS = (long) JSValueToNumber(context, adPropValue, NULL);
3523 JSStringRelease(adPropName);
3525 adPropName = JSStringCreateWithUTF8CString(
"url");
3526 adPropValue = JSObjectGetProperty(context, adObject, adPropName, NULL);
3527 if (JSValueIsString(context, adPropValue))
3531 JSStringRelease(adPropName);
3533 JSStringRelease(propName);
3536 JSObjectRef callbackObj = JSValueToObject(context, arguments[1], NULL);
3538 if (callbackObj != NULL && JSObjectIsFunction(context, callbackObj) && reservationId && adId && adURL)
3540 if (pAAMP->_promiseCallback)
3542 JSValueUnprotect(context, pAAMP->_promiseCallback);
3544 pAAMP->_promiseCallback = callbackObj;
3545 JSValueProtect(context, pAAMP->_promiseCallback);
3546 std::string adBreakId(reservationId);
3547 std::string adIdStr(adId);
3548 std::string url(adURL);
3549 LOG_WARN(pAAMP,
"pAAMP->_aamp->SetAlternateContents with promiseCallback:%p", callbackObj);
3554 LOG_ERROR(pAAMP,
"Unable to parse the promiseCallback argument");
3557 SAFE_DELETE_ARRAY(reservationId);
3558 SAFE_DELETE_ARRAY(adURL);
3559 SAFE_DELETE_ARRAY(adId);
3561 return JSValueMakeUndefined(context);
3576 static JSValueRef
AAMP_notifyReservationCompletion(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3582 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3583 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.notifyReservationCompletion() on instances of AAMP");
3584 return JSValueMakeUndefined(context);
3587 if (argumentCount != 2)
3589 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 2", argumentCount);
3590 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.notifyReservationCompletion' - 1 argument required");
3595 long time = (long) JSValueToNumber(context, arguments[1], exception);
3598 LOG_WARN(pAAMP,
"Called reservation close for periodId:%s and time:%ld", reservationId, time);
3599 SAFE_DELETE_ARRAY(reservationId);
3601 return JSValueMakeUndefined(context);
3614 static JSValueRef
AAMP_setLinearTrickplayFPS(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3620 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3621 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setAnonymousRequest on instances of AAMP");
3622 return JSValueMakeUndefined(context);
3625 if (argumentCount != 1)
3627 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3628 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setAnonymousRequest' - 1 argument required");
3632 int linearTrickplayFPS = (int)JSValueToNumber(context, arguments[0], exception);
3633 LOG_WARN(pAAMP,
" _aamp->SetLinearTrickplayFPS(%d)", linearTrickplayFPS);
3636 return JSValueMakeUndefined(context);
3652 static JSValueRef
AAMP_setLiveOffset(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3658 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3659 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setLiveOffset on instances of AAMP");
3660 return JSValueMakeUndefined(context);
3663 if (argumentCount != 1)
3665 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3666 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setLiveOffset' - 1 argument required");
3670 double liveOffset = (double)JSValueToNumber(context, arguments[0], exception);
3671 LOG_WARN(pAAMP,
" _aamp->SetLiveOffset(%lf)", liveOffset);
3674 return JSValueMakeUndefined(context);
3689 static JSValueRef
AAMP_setLiveOffset4K(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3695 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3696 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setLiveOffset4K on instances of AAMP");
3697 return JSValueMakeUndefined(context);
3700 if (argumentCount != 1)
3702 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3703 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setLiveOffset4K' - 1 argument required");
3707 double liveOffset = (double)JSValueToNumber(context, arguments[0], exception);
3708 LOG_WARN(pAAMP,
" _aamp->SetLiveOffset4K(%lf)",liveOffset);
3711 return JSValueMakeUndefined(context);
3726 static JSValueRef
AAMP_setDownloadStallTimeout(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3732 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3733 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setDownloadStallTimeout on instances of AAMP");
3734 return JSValueMakeUndefined(context);
3737 if (argumentCount != 1)
3739 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3740 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setDownloadStallTimeout' - 1 argument required");
3744 long stallTimeout = (long)JSValueToNumber(context, arguments[0], exception);
3745 LOG_WARN(pAAMP,
" _aamp->SetDownloadStallTimeout(%ld)",stallTimeout);
3749 return JSValueMakeUndefined(context);
3765 static JSValueRef
AAMP_setDownloadStartTimeout(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3771 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3772 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setDownlodStartTimeout on instances of AAMP");
3773 return JSValueMakeUndefined(context);
3776 if (argumentCount != 1)
3778 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3779 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setDownloadStartTimeout' - 1 argument required");
3783 long startTimeout = (long)JSValueToNumber(context, arguments[0], exception);
3784 LOG_WARN(pAAMP,
"SetDownloadStartTimeout %ld",startTimeout);
3788 return JSValueMakeUndefined(context);
3804 static JSValueRef
AAMP_setNetworkTimeout(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3810 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3811 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setNetworkTimeout on instances of AAMP");
3812 return JSValueMakeUndefined(context);
3815 if (argumentCount != 1)
3818 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3819 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setNetworkTimeout' - 1 argument required");
3823 double networkTimeout = (double)JSValueToNumber(context, arguments[0], exception);
3824 LOG_WARN(pAAMP,
" _aamp->SetNetworkTimeout %lf",networkTimeout);
3828 return JSValueMakeUndefined(context);
3842 static JSValueRef
AAMP_setClosedCaptionStatus(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3848 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3849 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setClosedCaptionStatus on instances of AAMP");
3850 return JSValueMakeUndefined(context);
3853 if (argumentCount != 1)
3855 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3856 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setClosedCaptionStatus' - 1 argument required");
3860 bool enabled = JSValueToBoolean(context, arguments[0]);
3861 LOG_WARN(pAAMP,
"_aamp->SetCCStatus(%d)", enabled);
3864 return JSValueMakeUndefined(context);
3878 static JSValueRef
AAMP_setTextStyleOptions(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3884 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3885 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setTextStyleOptions on instances of AAMP");
3886 return JSValueMakeUndefined(context);
3889 if (argumentCount != 1)
3891 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3892 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setTextStyleOptions' - 1 argument required");
3896 if (JSValueIsString(context, arguments[0]))
3899 LOG_WARN(pAAMP,
"_aamp->SetTextStyle(%s)", options);
3901 SAFE_DELETE_ARRAY(options);
3906 LOG_ERROR(pAAMP,
"InvalidArgument: Argument should be JSON formatted string");
3907 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setTextStyleOptions' - argument should be JSON formatted string");
3910 return JSValueMakeUndefined(context);
3924 static JSValueRef
AAMP_getTextStyleOptions(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3930 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3931 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.getTextStyleOptions on instances of AAMP");
3932 return JSValueMakeUndefined(context);
3935 if (!options.empty())
3937 LOG_INFO(pAAMP,
"_aamp->GetTextStyle() [%s]",options.c_str());
3942 LOG_WARN(pAAMP,
"_aamp->GetTextStyle() options=NULL");
3943 return JSValueMakeUndefined(context);
3958 static JSValueRef
AAMP_setLanguageFormat(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3964 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3965 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setLanguageFormat on instances of AAMP");
3966 return JSValueMakeUndefined(context);
3969 if (argumentCount != 2)
3971 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3972 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setLanguageFormat' - 2 argument required");
3976 int preferredFormat = (int) JSValueToNumber(context, arguments[0], NULL);
3977 bool useRole = JSValueToBoolean(context, arguments[1]);
3978 LOG_WARN(pAAMP,
" aamp->SetLanguageFormat(%d, %d)", preferredFormat, useRole);
3981 return JSValueMakeUndefined(context);
3995 static JSValueRef
AAMP_setLicenseCaching(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
4001 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
4002 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setLicenseCaching on instances of AAMP");
4003 return JSValueMakeUndefined(context);
4006 if (argumentCount != 1)
4009 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
4010 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setLicenseCaching' - 1 argument required");
4014 bool enabled = JSValueToBoolean(context, arguments[0]);
4015 LOG_WARN(pAAMP,
" _aamp->SetLicenseCaching %d)",enabled);
4018 return JSValueMakeUndefined(context);
4031 static JSValueRef
AAMP_setAuxiliaryLanguage(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
4037 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
4038 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setAuxiliaryLanguage on instances of AAMP");
4039 return JSValueMakeUndefined(context);
4042 if (argumentCount != 1)
4044 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
4045 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setAuxiliaryLanguage' - 1 argument required");
4050 LOG_WARN(pAAMP,
" _aamp->SetAuxiliaryLanguage(%s)", lang);
4052 SAFE_DELETE_ARRAY(lang);
4054 return JSValueMakeUndefined(context);
4066 static JSValueRef
AAMP_getPlayeBackStats(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
4070 if(!pAAMP || !pAAMP->_aamp)
4072 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
4073 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.getPlayeBackStats on instances of AAMP");
4074 return JSValueMakeUndefined(context);
4090 static JSValueRef
AAMP_xreSupportedTune(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
4096 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
4097 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.xreSupprotedTune on instances of AAMP");
4098 return JSValueMakeUndefined(context);
4100 if (argumentCount != 1)
4102 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
4103 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.xreSupprotedTune' - 1 argument required");
4107 bool xreSupported = JSValueToBoolean(context, arguments[0]);
4108 LOG_WARN(pAAMP,
" _aamp->XRESupportedTune(%d)",xreSupported);
4111 return JSValueMakeUndefined(context);
4133 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
4134 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setContentProtectionDataUpdateTimeout on instances of AAMP");
4135 return JSValueMakeUndefined(context);
4138 if (argumentCount != 1)
4140 LOG_ERROR(pAAMP,
"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
4141 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setContentProtectionDataUpdateTimeout' - 1 argument required");
4145 int contentProtectionDataUpdateTimeout = (int)JSValueToNumber(context, arguments[0], exception);
4146 LOG_WARN(pAAMP,
" _aamp->SetContentProtectionDataUpdateTimeout %d",contentProtectionDataUpdateTimeout);
4149 return JSValueMakeUndefined(context);
4165 static JSValueRef
AAMP_setContentProtectionDataConfig(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
4171 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
4172 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setContentProtectionDataConfig on instances of AAMP");
4173 return JSValueMakeUndefined(context);
4175 if (argumentCount == 1 && JSValueIsObject(context, arguments[0]))
4178 LOG_WARN(pAAMP,
" Response json call ProcessContentProtection %s",jsonbuffer);
4180 SAFE_DELETE_ARRAY(jsonbuffer);
4184 LOG_ERROR(pAAMP,
"IvalidArgument - argumentCount=%d, expected: 1", argumentCount);
4185 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute setContentProtectionDataConfig() - 1 argument of type IConfig required");
4187 return JSValueMakeUndefined(context);
4202 static JSValueRef
AAMP_setRuntimeDRMConfig(JSContextRef context, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
4208 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
4209 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setDynamicDRMConfig on instances of AAMP");
4210 return JSValueMakeUndefined(context);
4212 if(argumentCount != 1)
4214 LOG_ERROR(pAAMP,
"IvalidArgument - argumentCount=%d, expected: 1", argumentCount);
4215 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setDynamicDRMConfig - 1 argument required");
4219 bool DynamicDRMSupport = (bool)JSValueToBoolean(context, arguments[0]);
4220 LOG_WARN(pAAMP,
" _aamp->SetRuntimeDRMConfigSupport %d",DynamicDRMSupport);
4223 return JSValueMakeUndefined(context);
4232 {
"addEventListener",
AAMP_addEventListener, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4233 {
"removeEventListener",
AAMP_removeEventListener, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4234 {
"setProperties",
AAMP_setProperties, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4235 {
"getProperties",
AAMP_getProperties, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4236 {
"tune",
AAMP_tune, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4237 {
"load",
AAMP_load, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4238 {
"stop",
AAMP_stop, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4239 {
"setRate",
AAMP_setRate, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4240 {
"seek",
AAMP_seek, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4241 {
"seekToLive",
AAMP_seekToLive, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4242 {
"setRect",
AAMP_setRect, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4243 {
"setZoom",
AAMP_setZoom, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4244 {
"setLanguage",
AAMP_setLanguage, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4245 {
"setSubscribeTags",
AAMP_setSubscribeTags, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4246 {
"setAds",
AAMP_setAds, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4247 {
"subscribeTimedMetadata",
AAMP_setSubscribeTags, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4249 {
"setVideoTracks",
AAMP_setVideoTracks, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4251 {
"getAudioTrack",
AAMP_getAudioTrack, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4252 {
"getAudioTrackInfo",
AAMP_getAudioTrackInfo, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4253 {
"getTextTrackInfo",
AAMP_getTextTrackInfo, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4256 {
"setAudioTrack",
AAMP_setAudioTrack, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4258 {
"getTextTrack",
AAMP_getTextTrack, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4259 {
"setTextTrack",
AAMP_setTextTrack, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4260 {
"setVideoMute",
AAMP_setVideoMute, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4261 {
"setAudioVolume",
AAMP_setAudioVolume, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4262 {
"addCustomHTTPHeader",
AAMP_addCustomHTTPHeader, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4264 {
"setLicenseServerURL",
AAMP_setLicenseServerURL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4265 {
"setPreferredDRM",
AAMP_setPreferredDRM, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4266 {
"setAnonymousRequest",
AAMP_setAnonymousRequest, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4268 {
"setVODTrickplayFPS",
AAMP_setVODTrickplayFPS, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4271 {
"setLiveOffset",
AAMP_setLiveOffset, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4272 {
"setLiveOffset4K",
AAMP_setLiveOffset4K, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4275 {
"setNetworkTimeout",
AAMP_setNetworkTimeout, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4276 {
"setAlternateContent",
AAMP_setAlternateContent, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4279 {
"setTextStyleOptions",
AAMP_setTextStyleOptions, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4280 {
"getTextStyleOptions",
AAMP_getTextStyleOptions, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4281 {
"setLanguageFormat",
AAMP_setLanguageFormat, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4282 {
"setLicenseCaching",
AAMP_setLicenseCaching, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4284 {
"xreSupportedTune",
AAMP_xreSupportedTune, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
4285 {
"getPlaybackStatistics",
AAMP_getPlayeBackStats, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4304 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
4307 JSObjectSetPrivate(thisObject, NULL);
4309 while (pAAMP->_listeners != NULL)
4312 JSObjectRef jsCallback = pAAMP->_listeners->_jsCallback;
4317 if (pAAMP->_ctx != NULL) {
4318 JSValueUnprotect(pAAMP->_ctx, pAAMP->_eventType);
4319 if(pAAMP->_subscribedTags) {
4320 JSValueUnprotect(pAAMP->_ctx, pAAMP->_subscribedTags);
4322 if(pAAMP->_promiseCallback) {
4323 JSValueUnprotect(pAAMP->_ctx, pAAMP->_promiseCallback);
4327 pthread_mutex_lock(&mutex);
4328 if (NULL != _allocated_aamp)
4331 LOG_WARN(pAAMP,
" aamp->Stop(false)");
4332 _allocated_aamp->
Stop(
false);
4333 LOG_WARN(pAAMP,
"delete aamp %p",_allocated_aamp);
4334 SAFE_DELETE(_allocated_aamp);
4336 pthread_mutex_unlock(&mutex);
4339 #ifdef AAMP_CC_ENABLED
4341 logprintf(
"[%s] Disabling CC", __FUNCTION__);
4353 kJSClassAttributeNone,
4377 static JSClassRef _classRef = NULL;
4570 { NULL, NULL, NULL, 0 }
4601 kJSClassAttributeNone,
4625 static JSClassRef _classRef = NULL;
4653 LOG_WARN_EX(
"context=%p, aamp=%p", context, playerInstanceAAMP);
4654 JSGlobalContextRef jsContext = (JSGlobalContextRef)context;
4657 pAAMP->_ctx = jsContext;
4658 if (NULL != playerInstanceAAMP)
4664 pthread_mutex_lock(&mutex);
4665 if (NULL == _allocated_aamp )
4675 pAAMP->_aamp = _allocated_aamp;
4676 pthread_mutex_unlock(&mutex);
4679 pAAMP->_listeners = NULL;
4682 pAAMP->iPlayerId = pAAMP->_aamp->
GetId();
4692 JSValueProtect(jsContext, pAAMP->_eventType);
4694 pAAMP->_subscribedTags = NULL;
4695 pAAMP->_promiseCallback = NULL;
4698 JSObjectRef classObj = JSObjectMake(jsContext,
AAMP_class_ref(), pAAMP);
4699 JSObjectRef globalObj = JSContextGetGlobalObject(jsContext);
4700 JSStringRef str = JSStringCreateWithUTF8CString(
"AAMP");
4701 JSObjectSetProperty(jsContext, globalObj, str, classObj, kJSPropertyAttributeReadOnly, NULL);
4702 JSStringRelease(str);
4713 JSGlobalContextRef jsContext = (JSGlobalContextRef)context;
4715 JSObjectRef globalObj = JSContextGetGlobalObject(jsContext);
4716 JSStringRef str = JSStringCreateWithUTF8CString(
"AAMP");
4717 JSValueRef aamp = JSObjectGetProperty(jsContext, globalObj, str, NULL);
4721 JSStringRelease(str);
4725 JSObjectRef aampObj = JSValueToObject(jsContext, aamp, NULL);
4726 if (aampObj == NULL)
4728 JSStringRelease(str);
4737 JSObjectDeleteProperty(jsContext, globalObj, str, NULL);
4738 JSStringRelease(str);
4741 LOG_TRACE(
"JSGarbageCollect() context=%p", context);
4742 JSGarbageCollect(jsContext);
4750 void __attribute__ ((destructor(101))) _aamp_term()
4754 pthread_mutex_lock(&mutex);
4755 if (NULL != _allocated_aamp)
4759 _allocated_aamp->
Stop(
false);
4761 delete _allocated_aamp;
4762 _allocated_aamp = NULL;
4764 pthread_mutex_unlock(&mutex);