24 #ifdef USE_CPP_THUNDER_PLUGIN_ACCESS
26 #include <core/core.h>
28 #include "AampUtils.h"
32 #include "jsbindings-version.h"
33 #include "jsbindings.h"
38 #include <unordered_map>
41 #ifdef AAMP_CC_ENABLED
67 static std::vector<AAMPMediaPlayer_JS *> _jsMediaPlayerInstances;
68 std::map<std::string, JSObjectRef> _promiseCallbacks;
79 std::map<std::string, JSObjectRef>::const_iterator it = _promiseCallbacks.find(
id);
80 if (it != _promiseCallbacks.end())
100 std::map<std::string, JSObjectRef>::const_iterator it = _promiseCallbacks.find(
id);
101 if (it != _promiseCallbacks.end())
103 JSValueUnprotect(_ctx, it->second);
104 _promiseCallbacks.erase(it);
120 if (savedObject != NULL)
122 JSValueUnprotect(_ctx, savedObject);
125 JSValueProtect(_ctx, cbObject);
126 _promiseCallbacks[id] = cbObject;
138 if (!_promiseCallbacks.empty())
140 for (std::map<std::string, JSObjectRef>::iterator it = _promiseCallbacks.begin(); it != _promiseCallbacks.end(); )
142 JSValueUnprotect(_ctx, it->second);
143 _promiseCallbacks.erase(it);
155 ePARAM_RELOCKONTIMEOUT,
156 ePARAM_RELOCKONPROGRAMCHANGE,
166 ConfigParamType paramType;
167 const char* paramName;
175 { ePARAM_RELOCKONTIMEOUT,
"time" },
176 { ePARAM_RELOCKONPROGRAMCHANGE,
"programChange" },
177 { ePARAM_MAX_COUNT,
"" }
180 std::vector<AAMPMediaPlayer_JS *> AAMPMediaPlayer_JS::_jsMediaPlayerInstances = std::vector<AAMPMediaPlayer_JS *>();
199 JSStringRef propName = JSStringCreateWithUTF8CString(prop);
200 JSValueRef propValue = JSObjectGetProperty(ctx, jsObject, propName, NULL);
201 if (JSValueIsNumber(ctx, propValue))
203 value = JSValueToNumber(ctx, propValue, NULL);
204 LOG_WARN_EX(
"Parsed value for property %s - %f",prop, value);
209 LOG_ERROR_EX(
"Invalid value for property %s passed",prop);
213 JSStringRelease(propName);
229 JSStringRef propName = JSStringCreateWithUTF8CString(prop);
230 JSValueRef propValue = JSObjectGetProperty(ctx, jsObject, propName, NULL);
231 if (JSValueIsString(ctx, propValue))
234 LOG_WARN_EX(
"Parsed value for property %s - %f",prop, value);
239 LOG_ERROR_EX(
"Invalid value for property %s passed",prop);
242 JSStringRelease(propName);
258 JSStringRef propName = JSStringCreateWithUTF8CString(prop);
259 JSValueRef propValue = JSObjectGetProperty(ctx, jsObject, propName, NULL);
260 if (JSValueIsObject(ctx, propValue))
263 LOG_WARN_EX(
"Parsed object as value for property %s",prop);
268 LOG_ERROR_EX(
"Invalid value for property %s passed",prop);
272 JSStringRelease(propName);
287 JSStringRef propName = JSStringCreateWithUTF8CString(prop);
288 JSValueRef propValue = JSObjectGetProperty(ctx, jsObject, propName, NULL);
289 if (JSValueIsBoolean(ctx, propValue))
291 value = JSValueToBoolean(ctx, propValue);
292 LOG_WARN_EX(
"Parsed value for property %s - %d",prop,value);
297 LOG_ERROR_EX(
"Invalid value for property %s passed",prop);
300 JSStringRelease(propName);
314 LOG_WARN(privObj,
"Deleting privObj:%p",privObj);
316 if (privObj->_aamp != NULL)
319 LOG_WARN(privObj,
" aamp->Stop(false)");
320 privObj->_aamp->
Stop(
false);
322 if (privObj->_listeners.size() > 0)
326 LOG_WARN(privObj,
"Deleting privObj->_aamp :%p",privObj->_aamp);
328 SAFE_DELETE(privObj->_aamp);
347 for (std::vector<AAMPMediaPlayer_JS *>::iterator iter = AAMPMediaPlayer_JS::_jsMediaPlayerInstances.begin(); iter != AAMPMediaPlayer_JS::_jsMediaPlayerInstances.end(); iter++)
349 if (privObj == *iter)
352 AAMPMediaPlayer_JS::_jsMediaPlayerInstances.erase(iter);
378 JSValueRef exception = NULL;
379 JSObjectRef drmConfigObj = JSValueToObject(ctx, drmConfigParam, &exception);
381 if (drmConfigObj != NULL && exception == NULL)
383 char *prLicenseServerURL = NULL;
384 char *wvLicenseServerURL = NULL;
385 char *ckLicenseServerURL = NULL;
386 char *keySystem = NULL;
387 char *customData = NULL;
389 ret =
ParseJSPropAsString(ctx, drmConfigObj,
"com.microsoft.playready", prLicenseServerURL);
392 LOG_WARN(privObj,
"Playready License Server URL config param received - %s",prLicenseServerURL);
395 SAFE_DELETE_ARRAY(prLicenseServerURL);
400 LOG_WARN(privObj,
"CustomData config param received - %s",customData);
402 SAFE_DELETE_ARRAY(customData);
408 LOG_WARN(privObj,
"Widevine License Server URL config param received - %s",wvLicenseServerURL);
411 SAFE_DELETE_ARRAY(wvLicenseServerURL);
417 LOG_WARN(privObj,
"ClearKey License Server URL config param received - %s",ckLicenseServerURL);
420 SAFE_DELETE_ARRAY(ckLicenseServerURL);
426 if (strncmp(keySystem,
"com.microsoft.playready", 23) == 0)
428 LOG_WARN(privObj,
"Preferred key system config received - playready");
431 else if (strncmp(keySystem,
"com.widevine.alpha", 18) == 0)
433 LOG_WARN(privObj,
"Preferred key system config received - widevine");
438 LOG_WARN(privObj,
"Value passed preferredKeySystem(%s) not supported",keySystem);
440 SAFE_DELETE_ARRAY(keySystem);
445 LOG_WARN(privObj,
"InvalidProperty - drmConfigParam is NULL");
460 JSValueRef
AAMPMediaPlayerJS_load (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
466 if (!privObj || !privObj->_aamp)
468 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
469 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call load() on instances of AAMPPlayer");
470 return JSValueMakeUndefined(ctx);
473 bool autoPlay =
true;
474 bool bFinalAttempt =
false;
475 bool bFirstAttempt =
true;
477 char* contentType = NULL;
478 char* strTraceId = NULL;
480 switch(argumentCount)
484 JSObjectRef argument = JSValueToObject(ctx, arguments[2], NULL);
485 JSStringRef paramName = JSStringCreateWithUTF8CString(
"contentType");
486 JSValueRef paramValue = JSObjectGetProperty(ctx, argument, paramName, NULL);
487 if (JSValueIsString(ctx, paramValue))
491 JSStringRelease(paramName);
493 paramName = JSStringCreateWithUTF8CString(
"traceId");
494 paramValue = JSObjectGetProperty(ctx, argument, paramName, NULL);
495 if (JSValueIsString(ctx, paramValue))
499 JSStringRelease(paramName);
501 paramName = JSStringCreateWithUTF8CString(
"isInitialAttempt");
502 paramValue = JSObjectGetProperty(ctx, argument, paramName, NULL);
503 if (JSValueIsBoolean(ctx, paramValue))
505 bFirstAttempt = JSValueToBoolean(ctx, paramValue);
507 JSStringRelease(paramName);
509 paramName = JSStringCreateWithUTF8CString(
"isFinalAttempt");
510 paramValue = JSObjectGetProperty(ctx, argument, paramName, NULL);
511 if (JSValueIsBoolean(ctx, paramValue))
513 bFinalAttempt = JSValueToBoolean(ctx, paramValue);
515 JSStringRelease(paramName);
518 autoPlay = JSValueToBoolean(ctx, arguments[1]);
526 LOG_WARN(privObj,
"_aamp->Tune(%d, %s, %d, %d, %s)", autoPlay, contentType, bFirstAttempt, bFinalAttempt,strTraceId);
527 privObj->_aamp->
Tune(url, autoPlay, contentType, bFirstAttempt, bFinalAttempt,strTraceId);
536 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected atmost 3 arguments",argumentCount);
538 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute load() <= 3 arguments required");
542 SAFE_DELETE_ARRAY(url);
543 SAFE_DELETE_ARRAY(contentType);
544 SAFE_DELETE_ARRAY(strTraceId);
546 return JSValueMakeUndefined(ctx);
560 JSValueRef
AAMPMediaPlayerJS_initConfig (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
566 if (!privObj || !privObj->_aamp)
568 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
569 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call initConfig() on instances of AAMPPlayer");
570 return JSValueMakeUndefined(ctx);
574 if (argumentCount == 1 && JSValueIsObject(ctx, arguments[0]))
576 JSValueRef _exception = NULL;
578 bool valueAsBoolean =
false;
579 double valueAsNumber = 0;
580 char *valueAsString = NULL;
581 JSValueRef valueAsObject = NULL;
582 int langCodePreference = -1;
583 bool useRole =
false;
584 int enableVideoRectangle = -1;
586 bool jsonparsingdone=
false;
590 LOG_WARN(privObj,
" aamp->InitAAMPConfig : %s",jsonStr);
593 jsonparsingdone=
true;
595 SAFE_DELETE_ARRAY(jsonStr);
599 LOG_ERROR(privObj,
"Failed to create JSON String");
603 LOG_ERROR(privObj,
"Failed to parse JSON String");
609 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
610 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute initConfig() - 1 argument of type IConfig required");
614 return JSValueMakeUndefined(ctx);
628 JSValueRef
AAMPMediaPlayerJS_play (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
632 if (!privObj || !privObj->_aamp)
634 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
635 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call play() on instances of AAMPPlayer");
636 return JSValueMakeUndefined(ctx);
639 LOG_WARN(privObj,
" _aamp->SetRate(%d)",AAMP_NORMAL_PLAY_RATE);
640 privObj->_aamp->
SetRate(AAMP_NORMAL_PLAY_RATE);
643 return JSValueMakeUndefined(ctx);
656 JSValueRef
AAMPMediaPlayerJS_detach (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
660 if (!privObj || !privObj->_aamp)
662 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
663 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call play() on instances of AAMPPlayer");
664 return JSValueMakeUndefined(ctx);
666 LOG_WARN(privObj,
" _aamp->detach");
670 return JSValueMakeUndefined(ctx);
683 JSValueRef
AAMPMediaPlayerJS_pause (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
687 if (!privObj || !privObj->_aamp)
689 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
690 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call pause() on instances of AAMPPlayer");
695 if (argumentCount == 0)
697 LOG_WARN(privObj,
" _aamp->SetRate(0)");
700 else if (argumentCount == 1)
702 double position = (double)JSValueToNumber(ctx, arguments[0], exception);
703 LOG_WARN(privObj,
" _aamp->PauseAt %lf",position);
704 privObj->_aamp->
PauseAt(position);
708 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 0 or 1", argumentCount);
709 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute pause() - 0 or 1 argument required");
713 return JSValueMakeUndefined(ctx);
727 JSValueRef
AAMPMediaPlayerJS_stop (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
731 if (!privObj || (privObj && !privObj->_aamp))
733 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
734 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call stop() on instances of AAMPPlayer");
735 return JSValueMakeUndefined(ctx);
737 LOG_WARN(privObj,
" _aamp->Stop()");
738 privObj->_aamp->
Stop();
740 return JSValueMakeUndefined(ctx);
754 JSValueRef
AAMPMediaPlayerJS_seek (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
760 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
761 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call seek() on instances of AAMPPlayer");
762 return JSValueMakeUndefined(ctx);
764 if (argumentCount == 1 || argumentCount == 2)
766 double newSeekPos = JSValueToNumber(ctx, arguments[0], exception);
767 bool keepPaused = (argumentCount == 2)? JSValueToBoolean(ctx, arguments[1]) :
false;
770 LOG_WARN(privObj,
" _aamp->Seek(%lf, %d)", newSeekPos, keepPaused);
771 privObj->_aamp->
Seek(newSeekPos, keepPaused);
776 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1 or 2", argumentCount);
777 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute seek() - 1 or 2 arguments required");
780 return JSValueMakeUndefined(ctx);
793 JSValueRef
AAMPMediaPlayerJS_getThumbnails (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
797 if (!privObj || !privObj->_aamp)
799 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
800 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call seek() on instances of AAMPPlayer");
801 return JSValueMakeUndefined(ctx);
803 if (argumentCount == 1)
805 double thumbnailPosition = JSValueToNumber(ctx, arguments[0], exception);
806 LOG_INFO(privObj,
" _aamp->GetThumbnails(%lf,0)", thumbnailPosition);
807 std::string value = privObj->_aamp->
GetThumbnails(thumbnailPosition, 0);
810 LOG_INFO(privObj,
"_aamp->GetThumbnails value [%s]",value.c_str());
815 else if (argumentCount == 2)
817 double startPos = JSValueToNumber(ctx, arguments[0], exception);
818 double endPos = JSValueToNumber(ctx, arguments[1], exception);
820 std::string value = privObj->_aamp->
GetThumbnails(startPos, endPos);
824 LOG_INFO(privObj,
" %d _aamp->GetThumbnails(%d, %d)",value.size(), startPos, endPos);
829 LOG_INFO(privObj,
" 0 _aamp->GetThumbnails(%d, %d)", startPos, endPos);
834 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1 or 2", argumentCount);
835 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute seek() - 1 or 2 arguments required");
838 return JSValueMakeUndefined(ctx);
855 if (!privObj || !privObj->_aamp)
857 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
858 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getVideoBitrates() on instances of AAMPPlayer");
859 return JSValueMakeUndefined(ctx);
866 LOG_INFO(privObj,
"_aamp->GetAvailableThumbnailTracks() %s",value.c_str());
871 LOG_INFO(privObj,
"_aamp->GetAvailableThumbnailTracks value empty");
875 return JSValueMakeUndefined(ctx);
888 JSValueRef
AAMPMediaPlayerJS_getAudioTrackInfo (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
895 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
896 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getAudioTrackInfo() on instances of AAMPPlayer");
897 return JSValueMakeUndefined(ctx);
902 LOG_INFO(privObj,
" _aamp->GetAudioTrackInfo() value=[%s]",value.c_str());
907 LOG_WARN(privObj,
"_aamp->GetAudioTrackInfo() value=NULL");
910 return JSValueMakeUndefined(ctx);
923 JSValueRef
AAMPMediaPlayerJS_getTextTrackInfo (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
929 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
930 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getTextTrackInfo() on instances of AAMPPlayer");
931 return JSValueMakeUndefined(ctx);
936 LOG_INFO(privObj,
"_aamp->GetTextTrackInfo() value=%s",value.c_str());
941 LOG_WARN(privObj,
"_aamp->GetTextTrackInfo() value=NULL");
944 return JSValueMakeUndefined(ctx);
963 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
964 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getPreferredAudioProperties() on instances of AAMPPlayer");
965 return JSValueMakeUndefined(ctx);
970 LOG_INFO(privObj,
"_aamp->GetPrefferedAudioProperties() value=%s",value.c_str());
975 LOG_WARN(privObj,
"_aamp->GetPrefferedAudioProperties() value=NULL");
979 return JSValueMakeUndefined(ctx);
998 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
999 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getPreferredTextProperties() on instances of AAMPPlayer");
1000 return JSValueMakeUndefined(ctx);
1005 LOG_INFO(privObj,
"_aamp->GetPreferredTextProperties() value=%s",value.c_str());
1010 LOG_WARN(privObj,
"_aamp->GetPreferredTextProperties() value=NULL");
1013 return JSValueMakeUndefined(ctx);
1030 if (!privObj || !privObj->_aamp)
1032 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1033 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call SetThumbnailTrack() on instances of AAMPPlayer");
1034 return JSValueMakeUndefined(ctx);
1037 if (argumentCount != 1)
1039 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
1040 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute SetThumbnailTrack() - 1 argument required");
1044 int thumbnailIndex = (int) JSValueToNumber(ctx, arguments[0], NULL);
1045 if (thumbnailIndex >= 0)
1047 LOG_WARN(privObj,
"_aamp->SetThumbnailTrack(%d)", thumbnailIndex);
1048 return JSValueMakeBoolean(ctx, privObj->_aamp->
SetThumbnailTrack(thumbnailIndex));
1052 LOG_ERROR(privObj,
"InvalidArgument - Index should be >= 0!");
1053 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Index should be >= 0!");
1057 return JSValueMakeUndefined(ctx);
1070 JSValueRef
AAMPMediaPlayerJS_getCurrentState (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
1074 if (!privObj || !privObj->_aamp)
1076 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1077 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getCurrentState() on instances of AAMPPlayer");
1078 return JSValueMakeUndefined(ctx);
1080 LOG_INFO(privObj,
"> _aamp->GetState()");
1082 return JSValueMakeNumber(ctx, privObj->_aamp->
GetState());
1096 JSValueRef
AAMPMediaPlayerJS_getDurationSec (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
1100 double duration = 0;
1101 if (!privObj || !privObj->_aamp)
1103 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1104 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getDurationSec() on instances of AAMPPlayer");
1105 return JSValueMakeUndefined(ctx);
1110 LOG_INFO(privObj,
"Duration returned by GetPlaybackDuration() is less than 0!");
1115 return JSValueMakeNumber(ctx, duration);
1133 double currPosition = 0;
1134 if (!privObj || !privObj->_aamp)
1136 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1137 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getCurrentPosition() on instances of AAMPPlayer");
1138 return JSValueMakeUndefined(ctx);
1141 if (currPosition < 0)
1143 LOG_INFO(privObj,
"Current position returned by GetPlaybackPosition() is less than 0!");
1148 return JSValueMakeNumber(ctx, currPosition);
1162 JSValueRef
AAMPMediaPlayerJS_getVideoBitrates (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
1166 if (!privObj || !privObj->_aamp)
1168 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1169 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getVideoBitrates() on instances of AAMPPlayer");
1170 return JSValueMakeUndefined(ctx);
1173 if (!bitrates.empty())
1175 unsigned int length = bitrates.size();
1176 JSValueRef* array =
new JSValueRef[length];
1177 for (
int i = 0; i < length; i++)
1179 LOG_INFO(privObj,
"_aamp->GetVideoBitrates idx:%d value:%ld",i, bitrates[i]);
1180 array[i] = JSValueMakeNumber(ctx, bitrates[i]);
1183 JSValueRef retVal = JSObjectMakeArray(ctx, length, array, NULL);
1184 SAFE_DELETE_ARRAY(array);
1190 LOG_INFO(privObj,
" _aamp->GetVideoBitrates empty");
1192 return JSValueMakeUndefined(ctx);
1205 JSValueRef
AAMPMediaPlayerJS_getManifest (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
1209 if (!privObj || !privObj->_aamp)
1211 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1212 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getManifest() on instances of AAMPPlayer");
1213 return JSValueMakeUndefined(ctx);
1215 std::string manifest = privObj->_aamp->
GetManifest();
1216 if (!manifest.empty())
1218 LOG_INFO(privObj,
" _aamp->GetManifest() [%s]",manifest.c_str());
1223 LOG_WARN(privObj,
"Manifest empty!");
1224 return JSValueMakeUndefined(ctx);
1238 JSValueRef
AAMPMediaPlayerJS_getAudioBitrates (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
1242 if (!privObj || !privObj->_aamp)
1244 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1245 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getAudioBitrates() on instances of AAMPPlayer");
1246 return JSValueMakeUndefined(ctx);
1249 if (!bitrates.empty())
1251 unsigned int length = bitrates.size();
1252 JSValueRef* array =
new JSValueRef[length];
1253 for (
int i = 0; i < length; i++)
1255 LOG_INFO(privObj,
"_aamp->GetAudioBitrates idx:%d value:%ld",i, bitrates[i]);
1256 array[i] = JSValueMakeNumber(ctx, bitrates[i]);
1259 JSValueRef retVal = JSObjectMakeArray(ctx, length, array, NULL);
1260 SAFE_DELETE_ARRAY(array);
1266 LOG_INFO(privObj,
"_aamp->GetAudioBitrates empty");
1269 return JSValueMakeUndefined(ctx);
1287 if (!privObj || !privObj->_aamp)
1289 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1290 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getCurrentVideoBitrate() on instances of AAMPPlayer");
1291 return JSValueMakeUndefined(ctx);
1293 LOG_INFO(privObj,
" aamp->GetVideoBitrate()");
1309 JSValueRef
AAMPMediaPlayerJS_setVideoBitrate (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
1313 if (!privObj || !privObj->_aamp)
1315 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1316 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call setVideoBitrate() on instances of AAMPPlayer");
1317 return JSValueMakeUndefined(ctx);
1320 if (argumentCount != 1)
1322 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
1323 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute setVideoBitrate() - 1 argument required");
1327 long bitrate = (long) JSValueToNumber(ctx, arguments[0], NULL);
1331 LOG_WARN(privObj,
"_aamp->SetVideoBitrate(%ld)", bitrate);
1336 LOG_ERROR(privObj,
"InvalidArgument - bitrate should be >= 0!");
1337 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Bitrate should be >= 0!");
1341 return JSValueMakeUndefined(ctx);
1359 if (!privObj || !privObj->_aamp)
1361 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1362 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getCurrentAudioBitrate() on instances of AAMPPlayer");
1363 return JSValueMakeUndefined(ctx);
1365 LOG_INFO(privObj,
"> _aamp->GetAudioBitrate()");
1381 JSValueRef
AAMPMediaPlayerJS_setAudioBitrate (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
1385 if (!privObj || !privObj->_aamp)
1387 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1388 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call setAudioBitrate() on instances of AAMPPlayer");
1389 return JSValueMakeUndefined(ctx);
1392 if (argumentCount != 1)
1394 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
1395 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute setAudioBitrate() - 1 argument required");
1399 long bitrate = (long) JSValueToNumber(ctx, arguments[0], NULL);
1402 LOG_WARN(privObj,
" _aamp->SetAudioBitrate(%ld)", bitrate);
1407 LOG_ERROR(privObj,
"InvalidArgument - bitrate should be >= 0!");
1408 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Bitrate should be >= 0!");
1412 return JSValueMakeUndefined(ctx);
1426 JSValueRef
AAMPMediaPlayerJS_getAudioTrack (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
1430 if (!privObj || !privObj->_aamp)
1432 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1433 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getAudioTrack() on instances of AAMPPlayer");
1434 return JSValueMakeUndefined(ctx);
1436 LOG_INFO(privObj,
"> _aamp->GetAudioTrack()");
1438 return JSValueMakeNumber(ctx, privObj->_aamp->
GetAudioTrack());
1452 JSValueRef
AAMPMediaPlayerJS_setAudioTrack (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
1456 if (!privObj || !privObj->_aamp)
1458 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1459 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call setAudioTrack() on instances of AAMPPlayer");
1460 return JSValueMakeUndefined(ctx);
1463 if (argumentCount != 1)
1465 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
1466 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute setAudioTrack() - 1 argument required");
1468 else if (JSValueIsObject(ctx, arguments[0]))
1480 char *language = NULL;
1482 char *rendition = NULL;
1487 JSObjectRef audioProperty = JSValueToObject(ctx, arguments[0], NULL);
1488 if (audioProperty == NULL)
1490 LOG_ERROR_EX(
"Unable to convert argument to JSObject");
1491 return JSValueMakeUndefined(ctx);
1493 JSStringRef propName = JSStringCreateWithUTF8CString(
"language");
1494 JSValueRef propValue = JSObjectGetProperty(ctx, audioProperty, propName, NULL);
1495 if (JSValueIsString(ctx, propValue))
1499 JSStringRelease(propName);
1501 propName = JSStringCreateWithUTF8CString(
"rendition");
1502 propValue = JSObjectGetProperty(ctx, audioProperty, propName, NULL);
1503 if (JSValueIsString(ctx, propValue))
1507 JSStringRelease(propName);
1509 propName = JSStringCreateWithUTF8CString(
"codec");
1510 propValue = JSObjectGetProperty(ctx, audioProperty, propName, NULL);
1511 if (JSValueIsString(ctx, propValue))
1515 JSStringRelease(propName);
1517 propName = JSStringCreateWithUTF8CString(
"type");
1518 propValue = JSObjectGetProperty(ctx, audioProperty, propName, NULL);
1519 if (JSValueIsString(ctx, propValue))
1523 JSStringRelease(propName);
1525 propName = JSStringCreateWithUTF8CString(
"channel");
1526 propValue = JSObjectGetProperty(ctx, audioProperty, propName, NULL);
1527 if (JSValueIsNumber(ctx, propValue))
1529 channel = JSValueToNumber(ctx, propValue, NULL);
1531 JSStringRelease(propName);
1533 propName = JSStringCreateWithUTF8CString(
"label");
1534 propValue = JSObjectGetProperty(ctx, audioProperty, propName, NULL);
1535 if (JSValueIsString(ctx, propValue))
1539 JSStringRelease(propName);
1541 std::string strLanguage = language?std::string(language):
"";
1542 SAFE_DELETE_ARRAY(language);
1543 std::string strRendition = rendition?std::string(rendition):
"";
1544 SAFE_DELETE_ARRAY(rendition);
1545 std::string strCodec = codec?std::string(codec):
"";
1546 SAFE_DELETE_ARRAY(codec);
1547 std::string strType = type?std::string(type):
"";
1548 SAFE_DELETE_ARRAY(type);
1549 std::string strLabel = label?std::string(label):
"";
1550 SAFE_DELETE_ARRAY(label);
1551 LOG_WARN(privObj,
" SetAudioTrack language=%s renditio=%s type=%s codec=%s channel=%d label=%s", strLanguage.c_str(), strRendition.c_str(), strType.c_str(), strCodec.c_str(), channel,strLabel.c_str());
1553 privObj->_aamp->
SetAudioTrack(strLanguage, strRendition, strType, strCodec, channel, strLabel);
1558 int index = (int) JSValueToNumber(ctx, arguments[0], NULL);
1567 LOG_ERROR(privObj,
"InvalidArgument - track index should be >= 0!");
1568 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Audio track index should be >= 0!");
1572 return JSValueMakeUndefined(ctx);
1586 JSValueRef
AAMPMediaPlayerJS_getTextTrack (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
1590 if (!privObj || !privObj->_aamp)
1592 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1593 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getTextTrack() on instances of AAMPPlayer");
1594 return JSValueMakeUndefined(ctx);
1596 LOG_INFO(privObj,
"> _aamp->GetTextTrack()");
1598 return JSValueMakeNumber(ctx, privObj->_aamp->
GetTextTrack());
1612 JSValueRef
AAMPMediaPlayerJS_setTextTrack (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
1616 if (!privObj || !privObj->_aamp)
1618 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1619 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call setTextTrack() on instances of AAMPPlayer");
1620 return JSValueMakeUndefined(ctx);
1623 if (argumentCount != 1)
1625 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
1626 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute setTextTrack() - atleast 1 argument required");
1628 else if (!JSValueIsNumber(ctx, arguments[0]))
1638 int index = (int) JSValueToNumber(ctx, arguments[0], NULL);
1639 if (index >= MUTE_SUBTITLES_TRACKID)
1641 LOG_WARN(privObj,
"_aamp->SetAudioTrack(%d)", index);
1646 LOG_ERROR(privObj,
"InvalidArgument - track index should be >= -1!");
1647 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Text track index should be >= -1!");
1651 return JSValueMakeUndefined(ctx);
1665 JSValueRef
AAMPMediaPlayerJS_getVolume (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
1669 if (!privObj || !privObj->_aamp)
1671 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1672 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getVolume() on instances of AAMPPlayer");
1673 return JSValueMakeUndefined(ctx);
1676 LOG_INFO(privObj,
"_aamp->GetAudioVolume()");
1692 JSValueRef
AAMPMediaPlayerJS_setVolume (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
1696 if (!privObj || !privObj->_aamp)
1698 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1699 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call setVolume() on instances of AAMPPlayer");
1700 return JSValueMakeUndefined(ctx);
1705 LOG_ERROR_EX(
"Error - PlayerInstanceAAMP returned NULL!");
1706 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call setVolume() on valid instance of PlayerInstanceAAMP");
1707 return JSValueMakeUndefined(ctx);
1710 if (argumentCount == 1)
1712 int volume = (int) JSValueToNumber(ctx, arguments[0], exception);
1715 LOG_WARN(privObj,
" _aamp->SetAudioVolume(%d)", volume);
1720 LOG_ERROR(privObj,
"InvalidArgument - volume should not be a negative number");
1721 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Volume should not be a negative number");
1726 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
1727 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute setVolume() - 1 argument required");
1730 return JSValueMakeUndefined(ctx);
1743 JSValueRef
AAMPMediaPlayerJS_setAudioLanguage (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
1747 if (!privObj || !privObj->_aamp)
1749 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1750 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call setAudioLanguage() on instances of AAMPPlayer");
1751 return JSValueMakeUndefined(ctx);
1754 if (argumentCount == 1)
1758 LOG_WARN(privObj,
" _aamp->SetLanguage(%s)", lang);
1761 SAFE_DELETE_ARRAY(lang);
1765 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
1766 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute setAudioLanguage() - 1 argument required");
1769 return JSValueMakeUndefined(ctx);
1782 JSValueRef
AAMPMediaPlayerJS_getPlaybackRate (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
1786 if (!privObj || !privObj->_aamp)
1788 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1789 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getPlaybackRate() on instances of AAMPPlayer");
1790 return JSValueMakeUndefined(ctx);
1792 LOG_INFO(privObj,
"> aamp->GetPlaybackRate()");
1808 JSValueRef
AAMPMediaPlayerJS_setPlaybackRate (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
1812 if (!privObj || !privObj->_aamp)
1814 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1815 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call setPlaybackRate() on instances of AAMPPlayer");
1816 return JSValueMakeUndefined(ctx);
1819 if (argumentCount == 1 || argumentCount == 2)
1821 int overshootCorrection = 0;
1822 float rate = (float) JSValueToNumber(ctx, arguments[0], exception);
1823 if (argumentCount == 2)
1825 overshootCorrection = (int) JSValueToNumber(ctx, arguments[1], exception);
1828 LOG_WARN(privObj,
"_aamp->SetRate(%d, %d)", rate, overshootCorrection);
1829 privObj->_aamp->
SetRate(rate, overshootCorrection);
1834 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
1835 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute setPlaybackRate() - atleast 1 argument required");
1838 return JSValueMakeUndefined(ctx);
1856 if (!privObj || !privObj->_aamp)
1858 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1859 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getSupportedKeySystems() on instances of AAMPPlayer");
1860 return JSValueMakeUndefined(ctx);
1862 LOG_INFO(privObj,
"Invoked getSupportedKeySystems");
1864 return JSValueMakeUndefined(ctx);
1878 JSValueRef
AAMPMediaPlayerJS_setVideoMute (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
1882 if (!privObj || !privObj->_aamp)
1884 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1885 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call setVideoMute() on instances of AAMPPlayer");
1886 return JSValueMakeUndefined(ctx);
1889 if (argumentCount == 1)
1891 bool videoMute = JSValueToBoolean(ctx, arguments[0]);
1894 LOG_WARN(privObj,
"Invoked setVideoMute %d",videoMute);
1899 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
1900 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute setVideoMute() - 1 argument required");
1903 return JSValueMakeUndefined(ctx);
1921 if (!privObj || !privObj->_aamp)
1923 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1924 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call setSubscribedTags() on instances of AAMPPlayer");
1925 return JSValueMakeUndefined(ctx);
1928 if (argumentCount != 1)
1930 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
1931 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute setSubscribedTags() - 1 argument required");
1935 LOG_ERROR(privObj,
"InvalidArgument: aamp_JSValueIsArray=%d",
aamp_JSValueIsArray(ctx, arguments[0]));
1936 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute setSubscribeTags() - parameter 1 is not an array");
1942 LOG_WARN(privObj,
"Invoked setSubscribedTags");
1945 return JSValueMakeUndefined(ctx);
1963 if (!privObj || !privObj->_aamp)
1965 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
1966 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call subscribeResponseHeaders() on instances of AAMPPlayer");
1967 return JSValueMakeUndefined(ctx);
1970 if (argumentCount != 1)
1972 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
1973 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute subscribeResponseHeaders() - 1 argument required");
1977 LOG_ERROR(privObj,
"InvalidArgument: aamp_JSValueIsArray=%d",
aamp_JSValueIsArray(ctx, arguments[0]));
1978 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute subscribeResponseHeaders() - parameter 1 is not an array");
1984 LOG_WARN(privObj,
" Invoked SubscribeResponseHeaders");
1987 return JSValueMakeUndefined(ctx);
2001 JSValueRef
AAMPMediaPlayerJS_addEventListener (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
2005 if (!privObj || !privObj->_aamp)
2007 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2008 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call addEventListener() on instances of AAMPPlayer");
2009 return JSValueMakeUndefined(ctx);
2012 if (argumentCount >= 2)
2015 JSObjectRef callbackObj = JSValueToObject(ctx, arguments[1], NULL);
2017 if ((callbackObj != NULL) && JSObjectIsFunction(ctx, callbackObj))
2020 LOG_WARN(privObj,
"eventType='%s', %d", type, eventType);
2022 if ((eventType >= 0) && (eventType < AAMP_MAX_NUM_EVENTS))
2029 LOG_ERROR(privObj,
"callbackObj=%p, JSObjectIsFunction(context, callbackObj) is NULL", callbackObj);
2031 memset(errMsg,
'\0', 512);
2032 snprintf(errMsg, 511,
"Failed to execute addEventListener() for event %s - parameter 2 is not a function", type);
2033 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT, (
const char*)errMsg);
2035 SAFE_DELETE_ARRAY(type);
2039 LOG_ERROR(privObj,
"InvalidArgument: argumentCount=%d, expected: 2", argumentCount);
2040 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute addEventListener() - 2 arguments required.");
2043 return JSValueMakeUndefined(ctx);
2061 if (!privObj || !privObj->_aamp)
2063 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2064 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call removeEventListener() on instances of AAMPPlayer");
2065 return JSValueMakeUndefined(ctx);
2068 if (argumentCount >= 2)
2071 JSObjectRef callbackObj = JSValueToObject(ctx, arguments[1], NULL);
2073 if ((callbackObj != NULL) && JSObjectIsFunction(ctx, callbackObj))
2076 LOG_WARN(privObj,
"eventType='%s', %d", type, eventType);
2078 if ((eventType >= 0) && (eventType < AAMP_MAX_NUM_EVENTS))
2085 LOG_ERROR(privObj,
"InvalidArgument: callbackObj=%p, JSObjectIsFunction(context, callbackObj) is NULL", callbackObj);
2087 memset(errMsg,
'\0', 512);
2088 snprintf(errMsg, 511,
"Failed to execute removeEventListener() for event %s - parameter 2 is not a function", type);
2089 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT, (
const char*)errMsg);
2091 SAFE_DELETE_ARRAY(type);
2095 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
2096 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute removeEventListener() - 1 argument required");
2099 return JSValueMakeUndefined(ctx);
2113 JSValueRef
AAMPMediaPlayerJS_setDRMConfig (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
2117 if (!privObj || !privObj->_aamp)
2119 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2120 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call setDrmConfig() on instances of AAMPPlayer");
2121 return JSValueMakeUndefined(ctx);
2124 if (argumentCount != 1)
2126 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
2127 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute setDrmConfig() - 1 argument required");
2131 if (JSValueIsObject(ctx, arguments[0]))
2137 return JSValueMakeUndefined(ctx);
2155 if (!privObj || !privObj->_aamp)
2157 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2158 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call addCustomHTTPHeader() on instances of AAMPPlayer");
2159 return JSValueMakeUndefined(ctx);
2163 if (argumentCount == 2 || argumentCount == 3)
2166 std::string headerName(name);
2167 std::vector<std::string> headerVal;
2168 bool isLicenseHeader =
false;
2170 SAFE_DELETE_ARRAY(name);
2176 else if (JSValueIsString(ctx, arguments[1]))
2178 headerVal.reserve(1);
2180 headerVal.push_back(value);
2181 SAFE_DELETE_ARRAY(value);
2185 if (headerVal.size() == 0)
2187 LOG_ERROR(privObj,
"InvalidArgument: Custom header's value is empty");
2188 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute addCustomHTTPHeader() - 2nd argument should be a string or array of strings");
2189 return JSValueMakeUndefined(ctx);
2192 if (argumentCount == 3)
2194 isLicenseHeader = JSValueToBoolean(ctx, arguments[2]);
2196 LOG_WARN(privObj,
" _aamp->AddCustomHTTPHeader headerName= %s headerVal= %p",headerName.c_str(), headerVal);
2201 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
2202 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute addCustomHTTPHeader() - 2 arguments required");
2205 return JSValueMakeUndefined(ctx);
2223 if (!privObj || !privObj->_aamp)
2225 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2226 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call removeCustomHTTPHeader() on instances of AAMPPlayer");
2227 return JSValueMakeUndefined(ctx);
2230 if (argumentCount == 1)
2233 std::string headerName(name);
2234 LOG_WARN(privObj,
"_aamp->AddCustomHTTPHeader(%s)", headerName.c_str());
2236 SAFE_DELETE_ARRAY(name);
2240 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
2241 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute removeCustomHTTPHeader() - 1 argument required");
2244 return JSValueMakeUndefined(ctx);
2258 JSValueRef
AAMPMediaPlayerJS_setVideoRect (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
2262 if (!privObj || !privObj->_aamp)
2264 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2265 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call setVideoRect() on instances of AAMPPlayer");
2266 return JSValueMakeUndefined(ctx);
2269 if (argumentCount == 4)
2271 int x = (int) JSValueToNumber(ctx, arguments[0], exception);
2272 int y = (int) JSValueToNumber(ctx, arguments[1], exception);
2273 int w = (int) JSValueToNumber(ctx, arguments[2], exception);
2274 int h = (int) JSValueToNumber(ctx, arguments[3], exception);
2276 LOG_WARN(privObj,
"_aamp->SetVideoRectangle(%d, %d, %d, %d)", x, y, w, h);
2282 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
2283 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute setVideoRect() - 1 argument required");
2286 return JSValueMakeUndefined(ctx);
2300 JSValueRef
AAMPMediaPlayerJS_setVideoZoom (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
2304 if (!privObj || !privObj->_aamp)
2306 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2307 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call setVideoZoom() on instances of AAMPPlayer");
2308 return JSValueMakeUndefined(ctx);
2311 if (argumentCount == 1)
2315 if (0 == strcmp(zoomStr,
"none"))
2323 LOG_WARN(privObj,
"_aamp->SetVideoZoom(%d)",
static_cast<int>(zoom));
2325 SAFE_DELETE_ARRAY(zoomStr);
2329 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
2330 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute setVideoZoom() - 1 argument required");
2333 return JSValueMakeUndefined(ctx);
2347 JSValueRef
AAMPMediaPlayerJS_release (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
2354 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2355 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call release() on instances of AAMPPlayer");
2356 return JSValueMakeUndefined(ctx);
2361 LOG_WARN(privObj,
"Invoked release of a PlayerInstanceAAMP object(%p) which was already/being released!!",privObj);
2365 LOG_WARN(privObj,
"Cleaned up native object for AAMPMediaPlayer_JS and PlayerInstanceAAMP object(%p)!!" ,privObj);
2370 JSObjectSetPrivate(thisObject, NULL);
2373 SAFE_DELETE(privObj);
2377 return JSValueMakeUndefined(ctx);
2394 if(!privObj || !privObj->_aamp)
2396 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2397 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getAvailableVideoTracks() on instances of AAMPPlayer");
2398 return JSValueMakeUndefined(ctx);
2401 if (!tracks.empty())
2403 LOG_INFO(privObj,
"_aamp->GetAvailableVideoTracks tracks=%s",tracks.c_str());
2408 LOG_WARN(privObj,
"_aamp->GetAvailableVideoTracks tracks=NULL");
2409 return JSValueMakeUndefined(ctx);
2423 JSValueRef
AAMPMediaPlayerJS_setVideoTracks (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
2427 std::vector<long> bitrateList;
2428 if (!privObj || !privObj->_aamp)
2430 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2431 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call setVideoTrack() on instances of AAMPPlayer");
2432 return JSValueMakeUndefined(ctx);
2434 for (
int i =0; i < argumentCount; i++)
2436 long bitrate = JSValueToNumber(ctx, arguments[i], exception) ;
2437 LOG_WARN(privObj,
"_aamp->SetVideoTracks argCount:%d value:%ld",i, bitrate);
2438 bitrateList.push_back(bitrate);
2442 return JSValueMakeUndefined(ctx);
2459 if(!privObj || !privObj->_aamp)
2461 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2462 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getAvailableAudioTracks() on instances of AAMPPlayer");
2463 return JSValueMakeUndefined(ctx);
2465 bool allTrack =
false;
2466 if (argumentCount == 1)
2468 allTrack = JSValueToBoolean(ctx, arguments[0]);
2471 if (!tracks.empty())
2473 LOG_WARN(privObj,
" _aamp->GetAvailableAudioTracks(%d) tracks=%s", allTrack,tracks.c_str());
2478 LOG_WARN(privObj,
" _aamp->GetAvailableAudioTracks(%d) tracks=NULL", allTrack);
2479 return JSValueMakeUndefined(ctx);
2498 if(!privObj || !privObj->_aamp)
2500 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2501 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getAvailableTextTracks() on instances of AAMPPlayer");
2502 return JSValueMakeUndefined(ctx);
2504 bool allTrack =
false;
2505 if (argumentCount == 1)
2507 allTrack = JSValueToBoolean(ctx, arguments[0]);
2510 if (!tracks.empty())
2512 LOG_WARN(privObj,
"GetAvailableTextTracks(%d) tracks=%s",allTrack,tracks.c_str());
2517 LOG_WARN(privObj,
"GetAvailableTextTracks(%d) tracks=NULL",allTrack);
2518 return JSValueMakeUndefined(ctx);
2533 static JSValueRef
AAMPMediaPlayerJS_getVideoRectangle(JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
2537 if(!privObj || !privObj->_aamp)
2539 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2540 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getVideoRectangle() on instances of AAMPPlayer");
2541 return JSValueMakeUndefined(ctx);
2545 LOG_INFO(privObj,
" _aamp->GetVideoRectangle() value:%s",(strRect.empty() ?
"NULL" : strRect.c_str()));
2564 if(!privObj || !privObj->_aamp)
2566 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2567 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call setAlternateContent() on instances of AAMPPlayer");
2568 return JSValueMakeUndefined(ctx);
2571 if (argumentCount == 2)
2586 char *reservationId = NULL;
2587 int reservationBehavior = -1;
2591 if (JSValueIsObject(ctx, arguments[0]))
2594 JSObjectRef reservationObject = JSValueToObject(ctx, arguments[0], NULL);
2595 if (reservationObject == NULL)
2597 LOG_ERROR(privObj,
"Unable to convert argument to JSObject");
2598 return JSValueMakeUndefined(ctx);
2600 JSStringRef propName = JSStringCreateWithUTF8CString(
"reservationId");
2601 JSValueRef propValue = JSObjectGetProperty(ctx, reservationObject, propName, NULL);
2602 if (JSValueIsString(ctx, propValue))
2607 JSStringRelease(propName);
2608 propName = JSStringCreateWithUTF8CString(
"reservationBehavior");
2609 propValue = JSObjectGetProperty(ctx, reservationObject, propName, NULL);
2610 if (JSValueIsNumber(ctx, propValue))
2612 reservationBehavior = JSValueToNumber(ctx, propValue, NULL);
2614 JSStringRelease(propName);
2616 propName = JSStringCreateWithUTF8CString(
"placementRequest");
2617 propValue = JSObjectGetProperty(ctx, reservationObject, propName, NULL);
2618 if (JSValueIsObject(ctx, propValue))
2620 JSObjectRef adObject = JSValueToObject(ctx, propValue, NULL);
2621 JSStringRef adPropName = JSStringCreateWithUTF8CString(
"id");
2622 JSValueRef adPropValue = JSObjectGetProperty(ctx, adObject, adPropName, NULL);
2623 if (JSValueIsString(ctx, adPropValue))
2627 JSStringRelease(adPropName);
2628 adPropName = JSStringCreateWithUTF8CString(
"pts");
2629 adPropValue = JSObjectGetProperty(ctx, adObject, adPropName, NULL);
2630 if (JSValueIsNumber(ctx, adPropValue))
2632 adPTS = (long) JSValueToNumber(ctx, adPropValue, NULL);
2634 JSStringRelease(adPropName);
2635 adPropName = JSStringCreateWithUTF8CString(
"url");
2636 adPropValue = JSObjectGetProperty(ctx, adObject, adPropName, NULL);
2637 if (JSValueIsString(ctx, adPropValue))
2641 JSStringRelease(adPropName);
2643 JSStringRelease(propName);
2646 JSObjectRef callbackObj = JSValueToObject(ctx, arguments[1], NULL);
2647 if ((callbackObj) && JSObjectIsFunction(ctx, callbackObj) && adId && reservationId && adURL)
2649 std::string adIdStr(adId);
2650 std::string adBreakId(reservationId);
2651 std::string url(adURL);
2654 LOG_WARN(privObj,
"_aamp->SetAlternateContents(adBreakId=%s,adIdStr=%s,url=%s) with promiseCallback:%p",adBreakId, adIdStr,url,callbackObj);
2659 LOG_ERROR(privObj,
"Unable to parse the promiseCallback argument");
2662 SAFE_DELETE_ARRAY(reservationId);
2663 SAFE_DELETE_ARRAY(adURL);
2664 SAFE_DELETE_ARRAY(adId);
2668 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 2", argumentCount);
2669 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute setAlternateContent() - 2 argument required");
2672 return JSValueMakeUndefined(ctx);
2689 if (!privObj || !privObj->_aamp)
2691 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2692 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call setPreferredAudioLanguage() on instances of AAMPPlayer");
2693 return JSValueMakeUndefined(ctx);
2696 if( argumentCount>=1 && argumentCount<=4)
2699 char *rendition = NULL;
2701 char *codecList = NULL;
2702 char *labelList=NULL;
2703 if(argumentCount >= 2) {
2706 if(argumentCount >= 3) {
2709 if(argumentCount >= 4) {
2712 if(argumentCount >= 5) {
2715 LOG_WARN(privObj,
"_aamp->SetPrefferedLanguages(%s, %s, %s, %s)", lanList, rendition, type, codecList);
2717 SAFE_DELETE_ARRAY(type);
2718 SAFE_DELETE_ARRAY(rendition);
2719 SAFE_DELETE_ARRAY(lanList);
2720 SAFE_DELETE_ARRAY(codecList);
2721 SAFE_DELETE_ARRAY(labelList);
2725 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1, 2 , 3 or 4", argumentCount);
2726 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute setPreferredAudioLanguage() - 1, 2 or 3 arguments required");
2729 return JSValueMakeUndefined(ctx);
2746 if (!privObj || !privObj->_aamp)
2748 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2749 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call setPreferredAudioLanguage() on instances of AAMPPlayer");
2750 return JSValueMakeUndefined(ctx);
2753 if( argumentCount==1)
2756 LOG_WARN(privObj,
" _aamp->SetPreferredTextLanguages %s",parameters);
2758 SAFE_DELETE_ARRAY(parameters);
2762 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
2763 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute setPreferredAudioLanguage() - 1 argument required");
2766 return JSValueMakeUndefined(ctx);
2783 if (!privObj || !privObj->_aamp)
2785 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2786 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call setPreferredAudioCodec() on instances of AAMPPlayer");
2787 return JSValueMakeUndefined(ctx);
2790 if (argumentCount != 1)
2792 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
2793 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute setPreferredAudioCodec() - 1 argument required");
2798 LOG_WARN(privObj,
" _aamp->SetPrefferedLanguages(codecList=%s)", codecList);
2800 SAFE_DELETE_ARRAY(codecList);
2804 return JSValueMakeUndefined(ctx);
2821 if(!privObj || !privObj->_aamp)
2823 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2824 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call notifyReservationCompletion() on instances of AAMPPlayer");
2825 return JSValueMakeUndefined(ctx);
2828 if (argumentCount == 2)
2831 long time = (long) JSValueToNumber(ctx, arguments[1], exception);
2834 LOG_WARN(privObj,
"Called reservation close for periodId:%s and time:%ld", reservationId, time);
2835 SAFE_DELETE_ARRAY(reservationId);
2839 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 2", argumentCount);
2840 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute notifyReservationCompletion() - 2 argument required");
2843 return JSValueMakeUndefined(ctx);
2861 if (!privObj || !privObj->_aamp)
2863 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2864 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call setClosedCaptionStatus() on instances of AAMPPlayer");
2865 return JSValueMakeUndefined(ctx);
2868 if (argumentCount != 1)
2870 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
2871 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute setClosedCaptionStatus() - 1 argument required");
2876 bool enabled = JSValueToBoolean(ctx, arguments[0]);
2877 LOG_WARN(privObj,
"_aamp->SetCCStatus(%d)", enabled);
2881 return JSValueMakeUndefined(ctx);
2899 if (!privObj || !privObj->_aamp)
2901 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2902 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call setTextStyleOptions() on instances of AAMPPlayer");
2903 return JSValueMakeUndefined(ctx);
2906 if (argumentCount != 1)
2908 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
2909 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute setTextStyleOptions() - 1 argument required");
2913 if (JSValueIsString(ctx, arguments[0]))
2916 LOG_WARN(privObj,
" _aamp->SetTextStyle(%s)", options);
2918 SAFE_DELETE_ARRAY(options);
2922 LOG_ERROR(privObj,
"InvalidArgument - Argument should be a JSON formatted string!");
2923 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Argument should be a JSON formatted string!");
2927 return JSValueMakeUndefined(ctx);
2945 if(!privObj || !privObj->_aamp)
2947 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2948 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getTextStyleOptions() on instances of AAMPPlayer");
2949 return JSValueMakeUndefined(ctx);
2952 if (!options.empty())
2954 LOG_INFO(privObj,
"_aamp->GetTextStyle() options=%s",options.c_str());
2959 LOG_WARN(privObj,
"_aamp->GetTextStyle() options=NULL");
2960 return JSValueMakeUndefined(ctx);
2978 if (!privObj || !privObj->_aamp)
2980 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
2981 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call disableContentRestrictions() on instances of AAMPPlayer");
2982 return JSValueMakeUndefined(ctx);
2987 bool eventChange=
false;
2988 bool updateStatus =
false;
2989 if (argumentCount == 1 && JSValueIsObject(ctx, arguments[0]))
2991 JSValueRef _exception = NULL;
2993 bool valueAsBoolean =
false;
2994 double valueAsNumber = 0;
2997 JSObjectRef unlockConditionObj = JSValueToObject(ctx, arguments[0], &_exception);
2998 if (unlockConditionObj == NULL || _exception != NULL)
3000 LOG_ERROR(privObj,
"InvalidArgument - argument passed is NULL/not a valid object");
3001 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute disableContentRestrictions() - object of unlockConditions required");
3002 return JSValueMakeUndefined(ctx);
3006 for (
int iter = 0; iter < numRelockParams; iter++)
3011 case ePARAM_RELOCKONTIMEOUT:
3014 case ePARAM_RELOCKONPROGRAMCHANGE:
3024 updateStatus =
true;
3027 case ePARAM_RELOCKONTIMEOUT:
3028 time = (long) valueAsNumber;
3030 case ePARAM_RELOCKONPROGRAMCHANGE:
3031 eventChange = valueAsBoolean;
3042 LOG_WARN(privObj,
"_aamp->DisableContentRestrictions %ld %ld %d",grace,time,eventChange);
3045 else if(argumentCount > 1)
3047 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1 or no argument", argumentCount);
3048 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute disableContentRestrictions() - 1 argument of type IConfig required");
3054 LOG_WARN(privObj,
"_aamp->DisableContentRestrictions %ld %ld %d",grace,time,eventChange);
3059 return JSValueMakeUndefined(ctx);
3077 if (!privObj || !privObj->_aamp)
3079 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3080 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call enableContentRestrictions() on instances of AAMPPlayer");
3081 return JSValueMakeUndefined(ctx);
3083 LOG_WARN(privObj,
"_aamp->EnableContentRestrictions()");
3087 return JSValueMakeUndefined(ctx);
3104 if(!privObj || !privObj->_aamp)
3106 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3107 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call setAuxiliaryLanguage() on instances of AAMPPlayer");
3108 return JSValueMakeUndefined(ctx);
3111 if (argumentCount == 1)
3114 LOG_WARN(privObj,
"_aamp->SetAuxiliaryLanguage(%s)",lang);
3116 SAFE_DELETE_ARRAY(lang);
3120 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
3121 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute setAuxiliaryLanguage() - 1 argument required");
3124 return JSValueMakeUndefined(ctx);
3136 static JSValueRef
AAMPMediaPlayerJS_getPlayeBackStats(JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef *exception)
3140 if(!privObj || !privObj->_aamp)
3142 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3143 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call getVideoRectangle() on instances of AAMPPlayer");
3144 return JSValueMakeUndefined(ctx);
3167 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3168 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call xreSupportedTune() on instances of AAMPPlayer");
3169 return JSValueMakeUndefined(ctx);
3171 if (argumentCount == 1)
3173 bool xreSupported = JSValueToBoolean(ctx, arguments[0]);
3174 LOG_WARN(privObj,
"_aamp->XRESupportedTune(%d)",xreSupported);
3179 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
3180 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute xreSupportedTune() - 1 argument required");
3183 return JSValueMakeUndefined(ctx);
3204 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3205 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call setContentProtectionDataConfig() on instances of AAMPPlayer");
3206 return JSValueMakeUndefined(ctx);
3208 if (argumentCount == 1)
3211 LOG_WARN(privObj,
"Response json call ProcessContentProtection %s",jsonbuffer);
3213 SAFE_DELETE_ARRAY(jsonbuffer);
3217 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
3218 *exception =
aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT,
"Failed to execute setContentProtectionDataConfig() - 1 argument required");
3221 return JSValueMakeUndefined(ctx);
3242 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3243 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setContentProtectionDataUpdateTimeout on instances of AAMP");
3244 return JSValueMakeUndefined(context);
3247 if (argumentCount != 1)
3249 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
3250 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setContentProtectionDataUpdateTimeout' - 1 argument required");
3254 int contentProtectionDataUpdateTimeout = (int)JSValueToNumber(context, arguments[0], exception);
3255 LOG_WARN(privObj,
"aamp->SetContentProtectionDataUpdateTimeout(%d)",contentProtectionDataUpdateTimeout);
3259 return JSValueMakeUndefined(context);
3280 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3281 *exception =
aamp_GetException(context, AAMPJS_MISSING_OBJECT,
"Can only call AAMP.setDynamicDRMConfig on instances of AAMP");
3282 return JSValueMakeUndefined(context);
3284 if(argumentCount != 1)
3286 LOG_ERROR(privObj,
"InvalidArgument - argumentCount=%d, expected: 1", argumentCount);
3287 *exception =
aamp_GetException(context, AAMPJS_INVALID_ARGUMENT,
"Failed to execute 'AAMP.setDynamicDRMConfig - 1 argument required");
3291 bool DynamicDRMSupport = (bool)JSValueToBoolean(context, arguments[0]);
3292 LOG_WARN(privObj,
"_aamp->SetRuntimeDRMConfigSupport(%d)",DynamicDRMSupport);
3296 return JSValueMakeUndefined(context);
3315 if(!privObj || !privObj->_aamp)
3317 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3318 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Can only call IsOOBCCRenderingSupported() on instances of AAMPPlayer");
3319 return JSValueMakeUndefined(ctx);
3323 LOG_INFO(privObj,
"<-- returns:%d",bRet);
3326 return JSValueMakeBoolean(ctx, bRet);
3417 if (!privObj || !privObj->_aamp)
3419 LOG_ERROR_EX(
"JSObjectGetPrivate returned NULL!");
3420 *exception =
aamp_GetException(ctx, AAMPJS_MISSING_OBJECT,
"Get property version on instances of AAMPPlayer");
3421 return JSValueMakeUndefined(ctx);
3432 { NULL, NULL, NULL, 0 }
3445 if (privObj != NULL)
3449 LOG_WARN(privObj,
"Invoked finalize of a PlayerInstanceAAMP object(%p) which was already/being released!!", privObj);
3454 LOG_WARN(privObj,
"Cleaned up native object for AAMPMediaPlayer_JS and PlayerInstanceAAMP object(%p)!!",privObj);
3458 JSObjectSetPrivate(
object, NULL);
3460 SAFE_DELETE(privObj);
3464 LOG_ERROR(privObj,
"Native memory already cleared, since privObj is NULL");
3478 kJSClassAttributeNone,
3479 "__AAMPMediaPlayer",
3504 static JSClassRef _mediaPlayerObjRef = NULL;
3505 if (!_mediaPlayerObjRef) {
3508 return _mediaPlayerObjRef;
3525 std::string appName;
3526 if (argumentCount > 0)
3528 if (JSValueIsString(ctx, arguments[0]))
3531 appName.assign(value);
3532 LOG_WARN_EX(
"AAMPMediaPlayer created with app name: %s", appName.c_str());
3533 SAFE_DELETE_ARRAY(value);
3542 if (!appName.empty())
3544 LOG_WARN_EX(
" _aamp->SetAppName(%s)", appName.c_str());
3547 privObj->_listeners.clear();
3550 privObj->iPlayerId = privObj->_aamp->
GetId();
3562 AAMPMediaPlayer_JS::_jsMediaPlayerInstances.push_back(privObj);
3571 JSStringRef fName = JSStringCreateWithUTF8CString(
"toString");
3572 JSStringRef fString = JSStringCreateWithUTF8CString(
"return \"[object __AAMPMediaPlayer]\";");
3573 JSObjectRef toStringFunc = JSObjectMakeFunction(ctx, NULL, 0, NULL, fString, NULL, 0, NULL);
3575 JSObjectSetProperty(ctx, newObj, fName, toStringFunc, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete, NULL);
3577 JSStringRelease(fName);
3578 JSStringRelease(fString);
3590 kJSClassAttributeNone,
3591 "__AAMPMediaPlayer__class",
3615 LOG_WARN_EX(
"Number of active jsmediaplayer instances: %d", AAMPMediaPlayer_JS::_jsMediaPlayerInstances.size());
3616 while(AAMPMediaPlayer_JS::_jsMediaPlayerInstances.size() > 0)
3620 AAMPMediaPlayer_JS::_jsMediaPlayerInstances.pop_back();
3627 class XREReceiver_onEventHandler
3630 static void handle(JSContextRef ctx, std::string method,
size_t argumentCount,
const JSValueRef arguments[])
3632 if(handlers_map.count(method) != 0)
3634 handlers_map.at(method)(ctx, argumentCount, arguments);
3638 LOG_ERROR_EX(
"[XREReceiver]: no handler for method %s", method.c_str());
3643 static std::string findTextTrackWithLang(JSContextRef ctx, std::string selectedLang)
3646 LOG_WARN_EX(
"[XREReceiver]:found %d text tracks", (
int)textTracks.size());
3648 if(!selectedLang.empty() && isdigit(selectedLang[0]))
3650 LOG_WARN_EX(
"[XREReceiver]: trying to parse selected lang as index");
3655 int idx = std::stoi(selectedLang)-1;
3656 LOG_WARN_EX(
"[XREReceiver]:parsed index = %d", idx);
3658 return textTracks.at(idx).instreamId;
3660 catch(
const std::exception& e)
3662 LOG_WARN_EX(
"[XREReceiver]:exception during parsing lang selection %s", e.what());
3667 for(
const auto& track : textTracks)
3669 LOG_WARN_EX(
"[XREReceiver]:found language '%s', expected '%s'", track.language.c_str(), selectedLang.c_str());
3671 if(selectedLang == track.language)
3673 return track.instreamId;
3677 LOG_WARN_EX(
"[XREReceiver]:cannot find text track matching the selected language, defaulting to 'CC1'");
3683 static void handle_onClosedCaptions(JSContextRef ctx,
size_t argumentCount,
const JSValueRef arguments[])
3685 LOG_TRACE(
"[XREReceiver]: Inside Closed Captions");
3686 if(argumentCount != 2)
3688 LOG_ERROR_EX(
"[XREReceiver]: wrong argument count (expected 2) %d", argumentCount);
3692 JSObjectRef argument = JSValueToObject(ctx, arguments[1], NULL);
3694 JSStringRef param_enable = JSStringCreateWithUTF8CString(
"enable");
3695 JSStringRef param_setOptions = JSStringCreateWithUTF8CString(
"setOptions");
3696 JSStringRef param_setTrack = JSStringCreateWithUTF8CString(
"setTrack");
3698 JSValueRef param_enable_value = JSObjectGetProperty(ctx, argument, param_enable, NULL);
3699 JSValueRef param_setOptions_value = JSObjectGetProperty(ctx, argument, param_setOptions, NULL);
3700 JSValueRef param_setTrack_value = JSObjectGetProperty(ctx, argument, param_setTrack, NULL);
3702 if(JSValueIsBoolean(ctx, param_enable_value))
3704 const bool enable_value = JSValueToBoolean(ctx, param_enable_value);
3705 LOG_WARN_EX(
"[XREReceiver]:received enable boolean %d", enable_value);
3708 #ifdef AAMP_CC_ENABLED
3714 std::string defaultTrack;
3715 if(!textTracks.empty())
3717 defaultTrack = textTracks.front().instreamId;
3720 if(defaultTrack.empty())
3721 defaultTrack =
"CC1";
3723 LOG_WARN_EX(
"[XREReceiver]: found %d tracks, selected default textTrack = '%s'", (
int)textTracks.size(), defaultTrack.c_str());
3726 #ifdef AAMP_CC_ENABLED
3732 if(JSValueIsObject(ctx, param_setOptions_value))
3734 LOG_WARN_EX(
"[XREReceiver]: received setOptions, ignoring for now");
3738 if(JSValueIsString(ctx, param_setTrack_value))
3741 LOG_WARN_EX(
"[XREReceiver]: received setTrack language: %s", lang);
3744 std::string lang_str;
3745 lang_str.assign(lang);
3746 SAFE_DELETE_ARRAY(lang);
3748 std::string textTrack = findTextTrackWithLang(ctx, lang_str);
3750 LOG_WARN_EX(
"[XREReceiver]: selected textTrack = '%s'", textTrack.c_str());
3753 #ifdef AAMP_CC_ENABLED
3759 JSStringRelease(param_enable);
3760 JSStringRelease(param_setOptions);
3761 JSStringRelease(param_setTrack);
3764 using Handler_t = std::function<void(JSContextRef,
size_t,
const JSValueRef[])>;
3765 static std::unordered_map<std::string, Handler_t> handlers_map;
3768 std::unordered_map<std::string, XREReceiver_onEventHandler::Handler_t> XREReceiver_onEventHandler::handlers_map = {
3769 { std::string{
"onClosedCaptions"}, &XREReceiver_onEventHandler::handle_onClosedCaptions}
3784 JSValueRef XREReceiverJS_onevent (JSContextRef ctx, JSObjectRef
function, JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
3787 LOG_WARN_EX(
"[XREReceiver]: arg count - %d", argumentCount);
3789 if (argumentCount > 0)
3791 if (JSValueIsString(ctx, arguments[0]))
3795 method.assign(value);
3796 XREReceiver_onEventHandler::handle(ctx, method, argumentCount, arguments);
3798 SAFE_DELETE_ARRAY(value);
3801 return JSValueMakeUndefined(ctx);
3804 static const JSStaticFunction XREReceiver_JS_static_functions[] =
3806 {
"onEvent", XREReceiverJS_onevent, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3819 JSObjectRef XREReceiver_JS_class_constructor(JSContextRef ctx, JSObjectRef constructor,
size_t argumentCount,
const JSValueRef arguments[], JSValueRef* exception)
3822 *exception =
aamp_GetException(ctx, AAMPJS_GENERIC_ERROR,
"Cannot create an object of XREReceiver");
3827 static void XREReceiver_JS_finalize(JSObjectRef thisObject)
3834 static JSClassDefinition XREReceiver_JS_class_def {
3836 kJSClassAttributeNone,
3837 "__XREReceiver_class",
3840 XREReceiver_JS_static_functions,
3842 XREReceiver_JS_finalize,
3849 XREReceiver_JS_class_constructor,
3854 void LoadXREReceiverStub(
void* context)
3859 JSGlobalContextRef jsContext = (JSGlobalContextRef)context;
3861 JSClassRef myClass = JSClassCreate(&XREReceiver_JS_class_def);
3862 JSObjectRef classObj = JSObjectMake(jsContext, myClass, NULL);
3863 JSObjectRef globalObj = JSContextGetGlobalObject(jsContext);
3865 JSStringRef str = JSStringCreateWithUTF8CString(
"XREReceiver");
3866 JSObjectSetProperty(jsContext, globalObj, str, classObj, kJSPropertyAttributeReadOnly, NULL);
3881 JSGlobalContextRef jsContext = (JSGlobalContextRef)context;
3883 JSObjectRef globalObj = JSContextGetGlobalObject(jsContext);
3887 JSValueProtect(jsContext, classObj);
3889 JSStringRef str = JSStringCreateWithUTF8CString(
"AAMPMediaPlayer");
3890 JSObjectSetProperty(jsContext, globalObj, str, classObj, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, NULL);
3892 JSClassRelease(mediaPlayerClass);
3893 JSStringRelease(str);
3896 LoadXREReceiverStub(context);
3911 JSValueRef exception = NULL;
3912 JSGlobalContextRef jsContext = (JSGlobalContextRef)context;
3917 JSObjectRef globalObj = JSContextGetGlobalObject(jsContext);
3918 JSStringRef str = JSStringCreateWithUTF8CString(
"AAMPMediaPlayer");
3920 JSValueRef playerConstructor = JSObjectGetProperty(jsContext, globalObj, str, &exception);
3922 if (playerConstructor == NULL || exception != NULL)
3924 JSStringRelease(str);
3928 JSObjectRef playerObj = JSValueToObject(jsContext, playerConstructor, &exception);
3929 if (playerObj == NULL || exception != NULL)
3931 JSStringRelease(str);
3935 if (!JSObjectIsConstructor(jsContext, playerObj))
3937 JSStringRelease(str);
3941 JSValueUnprotect(jsContext, playerConstructor);
3942 JSObjectSetProperty(jsContext, globalObj, str, JSValueMakeUndefined(jsContext), kJSPropertyAttributeReadOnly, NULL);
3943 JSStringRelease(str);
3946 LOG_WARN_EX(
"JSGarbageCollect() context=%p", context);
3947 JSGarbageCollect(jsContext);