RDK Documentation (Open Sourced RDK Components)
jsmediaplayer.cpp
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's license file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2018 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 /**
21  * @file jsmediaplayer.cpp
22  * @brief JavaScript bindings for AAMPMediaPlayer
23  */
24 #ifdef USE_CPP_THUNDER_PLUGIN_ACCESS
25  #include "Module.h"
26  #include <core/core.h>
27  #include "ThunderAccess.h"
28  #include "AampUtils.h"
29 #endif
30 
31 
32 #include "jsbindings-version.h"
33 #include "jsbindings.h"
34 #include "jsutils.h"
35 #include "jseventlistener.h"
36 #include <functional>
37 #include <string>
38 #include <unordered_map>
39 #include <vector>
40 
41 #ifdef AAMP_CC_ENABLED
42 #include "AampCCManager.h"
43 #endif
44 
45 
46 extern "C"
47 {
48  JS_EXPORT JSGlobalContextRef JSContextGetGlobalContext(JSContextRef);
50 }
51 
52 /**
53  * @struct AAMPMediaPlayer_JS
54  * @brief Private data structure of AAMPMediaPlayer JS object
55  */
57 {
58  /**
59  * @brief Constructor of AAMPMediaPlayer_JS structure
60  */
61  AAMPMediaPlayer_JS() : _promiseCallbacks(),iPlayerId(-1),bInfoEnabled(0)
62  {
63  }
64  AAMPMediaPlayer_JS(const AAMPMediaPlayer_JS&) = delete;
65  AAMPMediaPlayer_JS& operator=(const AAMPMediaPlayer_JS&) = delete;
66 
67  static std::vector<AAMPMediaPlayer_JS *> _jsMediaPlayerInstances;
68  std::map<std::string, JSObjectRef> _promiseCallbacks;
69  int iPlayerId; /*An int variable iPlayerID to store Playerid */
70  bool bInfoEnabled; /*A bool variable bInfoEnabled for INFO logging check*/
71 
72  /**
73  * @brief Get promise callback for an ad id
74  * @param[in] id ad id
75  */
76  JSObjectRef getCallbackForAdId(std::string id) override
77  {
78  LOG_TRACE("Enter, id: %s",id);
79  std::map<std::string, JSObjectRef>::const_iterator it = _promiseCallbacks.find(id);
80  if (it != _promiseCallbacks.end())
81  {
82  LOG_TRACE("found cbObject");
83  return it->second;
84  }
85  else
86  {
87  LOG_TRACE("didn't find cbObject");
88  return NULL;
89  }
90  }
91 
92 
93  /**
94  * @brief Get promise callback for an ad id
95  * @param[in] id ad id
96  */
97  void removeCallbackForAdId(std::string id) override
98  {
99  LOG_TRACE("Enter");
100  std::map<std::string, JSObjectRef>::const_iterator it = _promiseCallbacks.find(id);
101  if (it != _promiseCallbacks.end())
102  {
103  JSValueUnprotect(_ctx, it->second);
104  _promiseCallbacks.erase(it);
105  }
106  LOG_TRACE("Exit");
107 
108  }
109 
110 
111  /**
112  * @brief Save promise callback for an ad id
113  * @param[in] id ad id
114  * @param[in] cbObject promise callback object
115  */
116  void saveCallbackForAdId(std::string id, JSObjectRef cbObject)
117  {
118  LOG_TRACE("Enter");
119  JSObjectRef savedObject = getCallbackForAdId(id);
120  if (savedObject != NULL)
121  {
122  JSValueUnprotect(_ctx, savedObject); //remove already saved callback
123  }
124 
125  JSValueProtect(_ctx, cbObject);
126  _promiseCallbacks[id] = cbObject;
127  LOG_TRACE("Exit");
128 
129  }
130 
131 
132  /**
133  * @brief Clear all saved promise callbacks
134  */
136  {
137  LOG_TRACE("Enter");
138  if (!_promiseCallbacks.empty())
139  {
140  for (std::map<std::string, JSObjectRef>::iterator it = _promiseCallbacks.begin(); it != _promiseCallbacks.end(); )
141  {
142  JSValueUnprotect(_ctx, it->second);
143  _promiseCallbacks.erase(it);
144  }
145  }
146  LOG_TRACE("Exit");
147  }
148 };
149 
150 /**
151  * @enum ConfigParamType
152  */
153 enum ConfigParamType
154 {
155  ePARAM_RELOCKONTIMEOUT,
156  ePARAM_RELOCKONPROGRAMCHANGE,
157  ePARAM_MAX_COUNT
158 };
159 
160 /**
161  * @struct ConfigParamMap
162  * @brief Data structure to map ConfigParamType and its string equivalent
163  */
165 {
166  ConfigParamType paramType;
167  const char* paramName;
168 };
169 
170 /**
171  * @brief Map relockConditionParamNames and its string equivalent
172  */
174 {
175  { ePARAM_RELOCKONTIMEOUT, "time" },
176  { ePARAM_RELOCKONPROGRAMCHANGE, "programChange" },
177  { ePARAM_MAX_COUNT, "" }
178 };
179 
180 std::vector<AAMPMediaPlayer_JS *> AAMPMediaPlayer_JS::_jsMediaPlayerInstances = std::vector<AAMPMediaPlayer_JS *>();
181 
182 /**
183  * @brief Mutex for global cache of AAMPMediaPlayer_JS instances
184  */
185 static pthread_mutex_t jsMediaPlayerCacheMutex = PTHREAD_MUTEX_INITIALIZER;
186 
187 
188 /**
189  * @brief Helper function to parse a JS property value as number
190  * @param[in] ctx JS execution context
191  * @param[in] jsObject JS object whose property has to be parsed
192  * @param[in] prop property name
193  * @param[out] value to store parsed number
194  * return true if value was parsed sucessfully, false otherwise
195  */
196 bool ParseJSPropAsNumber(JSContextRef ctx, JSObjectRef jsObject, const char *prop, double &value)
197 {
198  bool ret = false;
199  JSStringRef propName = JSStringCreateWithUTF8CString(prop);
200  JSValueRef propValue = JSObjectGetProperty(ctx, jsObject, propName, NULL);
201  if (JSValueIsNumber(ctx, propValue))
202  {
203  value = JSValueToNumber(ctx, propValue, NULL);
204  LOG_WARN_EX("Parsed value for property %s - %f",prop, value);
205  ret = true;
206  }
207  else
208  {
209  LOG_ERROR_EX("Invalid value for property %s passed",prop);
210 
211  }
212 
213  JSStringRelease(propName);
214  return ret;
215 }
216 
217 
218 /**
219  * @brief Helper function to parse a JS property value as string
220  * @param[in] ctx JS execution context
221  * @param[in] jsObject JS object whose property has to be parsed
222  * @param[in] prop property name
223  * @param[out] value to store parsed string
224  * return true if value was parsed sucessfully, false otherwise
225  */
226 bool ParseJSPropAsString(JSContextRef ctx, JSObjectRef jsObject, const char *prop, char * &value)
227 {
228  bool ret = false;
229  JSStringRef propName = JSStringCreateWithUTF8CString(prop);
230  JSValueRef propValue = JSObjectGetProperty(ctx, jsObject, propName, NULL);
231  if (JSValueIsString(ctx, propValue))
232  {
233  value = aamp_JSValueToCString(ctx, propValue, NULL);
234  LOG_WARN_EX("Parsed value for property %s - %f",prop, value);
235  ret = true;
236  }
237  else
238  {
239  LOG_ERROR_EX("Invalid value for property %s passed",prop);
240  }
241 
242  JSStringRelease(propName);
243  return ret;
244 }
245 
246 
247 /**
248  * @brief Helper function to parse a JS property value as object
249  * @param[in] ctx JS execution context
250  * @param[in] jsObject JS object whose property has to be parsed
251  * @param[in] prop property name
252  * @param[out] value to store parsed value
253  * return true if value was parsed sucessfully, false otherwise
254  */
255 bool ParseJSPropAsObject(JSContextRef ctx, JSObjectRef jsObject, const char *prop, JSValueRef &value)
256 {
257  bool ret = false;
258  JSStringRef propName = JSStringCreateWithUTF8CString(prop);
259  JSValueRef propValue = JSObjectGetProperty(ctx, jsObject, propName, NULL);
260  if (JSValueIsObject(ctx, propValue))
261  {
262  value = propValue;
263  LOG_WARN_EX("Parsed object as value for property %s",prop);
264  ret = true;
265  }
266  else
267  {
268  LOG_ERROR_EX("Invalid value for property %s passed",prop);
269 
270  }
271 
272  JSStringRelease(propName);
273  return ret;
274 }
275 
276 /**
277  * @brief Helper function to parse a JS property value as boolean
278  * @param[in] ctx JS execution context
279  * @param[in] jsObject JS object whose property has to be parsed
280  * @param[in] prop property name
281  * @param[out] value to store parsed value
282  * return true if value was parsed sucessfully, false otherwise
283  */
284 bool ParseJSPropAsBoolean(JSContextRef ctx, JSObjectRef jsObject, const char *prop, bool &value)
285 {
286  bool ret = false;
287  JSStringRef propName = JSStringCreateWithUTF8CString(prop);
288  JSValueRef propValue = JSObjectGetProperty(ctx, jsObject, propName, NULL);
289  if (JSValueIsBoolean(ctx, propValue))
290  {
291  value = JSValueToBoolean(ctx, propValue);
292  LOG_WARN_EX("Parsed value for property %s - %d",prop,value);
293  ret = true;
294  }
295  else
296  {
297  LOG_ERROR_EX("Invalid value for property %s passed",prop);
298  }
299 
300  JSStringRelease(propName);
301  return ret;
302 }
303 
304 /**
305  * @brief API to release internal resources of an AAMPMediaPlayerJS object
306  * NOTE that this function does NOT free AAMPMediaPlayer_JS
307  * It is done in AAMPMediaPlayerJS_release ( APP initiated ) or AAMPMediaPlayer_JS_finalize ( GC initiated)
308  * @param[in] object AAMPMediaPlayerJS object being released
309  */
311 {
312  if (privObj != NULL)
313  {
314  LOG_WARN(privObj,"Deleting privObj:%p",privObj);
315  // clean all members of AAMPMediaPlayer_JS(privObj)
316  if (privObj->_aamp != NULL)
317  {
318  //when finalizing JS object, don't generate state change events
319  LOG_WARN(privObj," aamp->Stop(false)");
320  privObj->_aamp->Stop(false);
321  privObj->clearCallbackForAllAdIds();
322  if (privObj->_listeners.size() > 0)
323  {
325  }
326  LOG_WARN(privObj,"Deleting privObj->_aamp :%p",privObj->_aamp);
327 
328  SAFE_DELETE(privObj->_aamp);
329  }
330  }
331 }
332 
333 
334 /**
335  * @brief API to check if AAMPMediaPlayer_JS object present in cache and release it
336  *
337  * @param[in] object AAMPMediaPlayerJS object
338  * @return true if instance was found and native resources released, false otherwise
339  */
341 {
342  bool found = false;
343 
344  if (privObj != NULL)
345  {
346  pthread_mutex_lock(&jsMediaPlayerCacheMutex);
347  for (std::vector<AAMPMediaPlayer_JS *>::iterator iter = AAMPMediaPlayer_JS::_jsMediaPlayerInstances.begin(); iter != AAMPMediaPlayer_JS::_jsMediaPlayerInstances.end(); iter++)
348  {
349  if (privObj == *iter)
350  {
351  //Remove this instance from global cache
352  AAMPMediaPlayer_JS::_jsMediaPlayerInstances.erase(iter);
353  found = true;
354  break;
355  }
356  }
357  pthread_mutex_unlock(&jsMediaPlayerCacheMutex);
358 
359  if (found)
360  {
361  //Release private resources
362  releaseNativeResources(privObj);
363  }
364  }
365 
366  return found;
367 }
368 
369 
370 /**
371  * @brief Helper function to parse DRM config params received from JS
372  * @param[in] ctx JS execution context
373  * @param[in] privObj AAMPMediaPlayer instance to set the drm configuration
374  * @param[in] drmConfigParam parameters received as argument
375  */
376 void parseDRMConfiguration (JSContextRef ctx, AAMPMediaPlayer_JS* privObj, JSValueRef drmConfigParam)
377 {
378  JSValueRef exception = NULL;
379  JSObjectRef drmConfigObj = JSValueToObject(ctx, drmConfigParam, &exception);
380 
381  if (drmConfigObj != NULL && exception == NULL)
382  {
383  char *prLicenseServerURL = NULL;
384  char *wvLicenseServerURL = NULL;
385  char *ckLicenseServerURL = NULL;
386  char *keySystem = NULL;
387  char *customData = NULL;
388  bool ret = false;
389  ret = ParseJSPropAsString(ctx, drmConfigObj, "com.microsoft.playready", prLicenseServerURL);
390  if (ret)
391  {
392  LOG_WARN(privObj,"Playready License Server URL config param received - %s",prLicenseServerURL);
393  privObj->_aamp->SetLicenseServerURL(prLicenseServerURL, eDRM_PlayReady);
394 
395  SAFE_DELETE_ARRAY(prLicenseServerURL);
396  }
397  ret = ParseJSPropAsString(ctx, drmConfigObj, "customData", customData);
398  if (ret)
399  {
400  LOG_WARN(privObj,"CustomData config param received - %s",customData);
401  privObj->_aamp->SetLicenseCustomData(customData);
402  SAFE_DELETE_ARRAY(customData);
403  }
404 
405  ret = ParseJSPropAsString(ctx, drmConfigObj, "com.widevine.alpha", wvLicenseServerURL);
406  if (ret)
407  {
408  LOG_WARN(privObj,"Widevine License Server URL config param received - %s",wvLicenseServerURL);
409  privObj->_aamp->SetLicenseServerURL(wvLicenseServerURL, eDRM_WideVine);
410 
411  SAFE_DELETE_ARRAY(wvLicenseServerURL);
412  }
413 
414  ret = ParseJSPropAsString(ctx, drmConfigObj, "org.w3.clearkey", ckLicenseServerURL);
415  if (ret)
416  {
417  LOG_WARN(privObj,"ClearKey License Server URL config param received - %s",ckLicenseServerURL);
418  privObj->_aamp->SetLicenseServerURL(ckLicenseServerURL, eDRM_ClearKey);
419 
420  SAFE_DELETE_ARRAY(ckLicenseServerURL);
421  }
422 
423  ret = ParseJSPropAsString(ctx, drmConfigObj, "preferredKeysystem", keySystem);
424  if (ret)
425  {
426  if (strncmp(keySystem, "com.microsoft.playready", 23) == 0)
427  {
428  LOG_WARN(privObj,"Preferred key system config received - playready");
429  privObj->_aamp->SetPreferredDRM(eDRM_PlayReady);
430  }
431  else if (strncmp(keySystem, "com.widevine.alpha", 18) == 0)
432  {
433  LOG_WARN(privObj,"Preferred key system config received - widevine");
434  privObj->_aamp->SetPreferredDRM(eDRM_WideVine);
435  }
436  else
437  {
438  LOG_WARN(privObj,"Value passed preferredKeySystem(%s) not supported",keySystem);
439  }
440  SAFE_DELETE_ARRAY(keySystem);
441  }
442  }
443  else
444  {
445  LOG_WARN(privObj,"InvalidProperty - drmConfigParam is NULL");
446  }
447 }
448 
449 
450 /**
451  * @brief API invoked from JS when executing AAMPMediaPlayer.load()
452  * @param[in] ctx JS execution context
453  * @param[in] function JSObject that is the function being called
454  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
455  * @param[in] argumentCount number of args
456  * @param[in] arguments[] JSValue array of args
457  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
458  * @retval JSValue that is the function's return value
459  */
460 JSValueRef AAMPMediaPlayerJS_load (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
461 {
462  LOG_TRACE("Enter");
463 
464 
465  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
466  if (!privObj || !privObj->_aamp)
467  {
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);
471  }
472 
473  bool autoPlay = true;
474  bool bFinalAttempt = false;
475  bool bFirstAttempt = true;
476  char* url = NULL;
477  char* contentType = NULL;
478  char* strTraceId = NULL;
479 
480  switch(argumentCount)
481  {
482  case 3:
483  {
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))
488  {
489  contentType = aamp_JSValueToCString(ctx, paramValue, NULL);
490  }
491  JSStringRelease(paramName);
492 
493  paramName = JSStringCreateWithUTF8CString("traceId");
494  paramValue = JSObjectGetProperty(ctx, argument, paramName, NULL);
495  if (JSValueIsString(ctx, paramValue))
496  {
497  strTraceId = aamp_JSValueToCString(ctx, paramValue, NULL);
498  }
499  JSStringRelease(paramName);
500 
501  paramName = JSStringCreateWithUTF8CString("isInitialAttempt");
502  paramValue = JSObjectGetProperty(ctx, argument, paramName, NULL);
503  if (JSValueIsBoolean(ctx, paramValue))
504  {
505  bFirstAttempt = JSValueToBoolean(ctx, paramValue);
506  }
507  JSStringRelease(paramName);
508 
509  paramName = JSStringCreateWithUTF8CString("isFinalAttempt");
510  paramValue = JSObjectGetProperty(ctx, argument, paramName, NULL);
511  if (JSValueIsBoolean(ctx, paramValue))
512  {
513  bFinalAttempt = JSValueToBoolean(ctx, paramValue);
514  }
515  JSStringRelease(paramName);
516  }
517  case 2:
518  autoPlay = JSValueToBoolean(ctx, arguments[1]);
519  case 1:
520  {
521  url = aamp_JSValueToCString(ctx, arguments[0], exception);
522  aamp_ApplyPageHttpHeaders(privObj->_aamp);
523 
524  {
525  char* url = aamp_JSValueToCString(ctx, arguments[0], exception);
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);
528 
529  }
530 
531 
532  break;
533  }
534 
535  default:
536  LOG_ERROR(privObj,"InvalidArgument - argumentCount=%d, expected atmost 3 arguments",argumentCount);
537 
538  *exception = aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT, "Failed to execute load() <= 3 arguments required");
539  }
540 
541  LOG_TRACE("Exit..");
542  SAFE_DELETE_ARRAY(url);
543  SAFE_DELETE_ARRAY(contentType);
544  SAFE_DELETE_ARRAY(strTraceId);
545 
546  return JSValueMakeUndefined(ctx);
547 }
548 
549 
550 /**
551  * @brief API invoked from JS when executing AAMPMediaPlayer.initConfig()
552  * @param[in] ctx JS execution context
553  * @param[in] function JSObject that is the function being called
554  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
555  * @param[in] argumentCount number of args
556  * @param[in] arguments[] JSValue array of args
557  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
558  * @retval JSValue that is the function's return value
559  */
560 JSValueRef AAMPMediaPlayerJS_initConfig (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
561 {
562 
563  LOG_TRACE("Enter");
564 
565  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
566  if (!privObj || !privObj->_aamp)
567  {
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);
571  }
572 
573 
574  if (argumentCount == 1 && JSValueIsObject(ctx, arguments[0]))
575  {
576  JSValueRef _exception = NULL;
577  bool ret = false;
578  bool valueAsBoolean = false;
579  double valueAsNumber = 0;
580  char *valueAsString = NULL;
581  JSValueRef valueAsObject = NULL;
582  int langCodePreference = -1; // value not passed
583  bool useRole = false; //default value in func arg
584  int enableVideoRectangle = -1; //-1: value not passed, 0: false, 1:true
585 
586  bool jsonparsingdone=false;
587  char *jsonStr = aamp_JSValueToJSONCString(ctx,arguments[0], exception);
588  if (jsonStr != NULL)
589  {
590  LOG_WARN(privObj," aamp->InitAAMPConfig : %s",jsonStr);
591  if(privObj->_aamp->InitAAMPConfig(jsonStr))
592  {
593  jsonparsingdone=true;
594  }
595  SAFE_DELETE_ARRAY(jsonStr);
596  }
597  else
598  {
599  LOG_ERROR(privObj,"Failed to create JSON String");
600  }
601  if(!jsonparsingdone)
602  {
603  LOG_ERROR(privObj,"Failed to parse JSON String");
604 
605  }
606  }
607  else
608  {
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");
611  }
612 
613  LOG_TRACE("Exit");
614  return JSValueMakeUndefined(ctx);
615 }
616 
617 
618 /**
619  * @brief API invoked from JS when executing AAMPMediaPlayer.play()
620  * @param[in] ctx JS execution context
621  * @param[in] function JSObject that is the function being called
622  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
623  * @param[in] argumentCount number of args
624  * @param[in] arguments[] JSValue array of args
625  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
626  * @retval JSValue that is the function's return value
627  */
628 JSValueRef AAMPMediaPlayerJS_play (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
629 {
630  LOG_TRACE("Enter");
631  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
632  if (!privObj || !privObj->_aamp)
633  {
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);
637  }
638  {
639  LOG_WARN(privObj," _aamp->SetRate(%d)",AAMP_NORMAL_PLAY_RATE);
640  privObj->_aamp->SetRate(AAMP_NORMAL_PLAY_RATE);
641  }
642  LOG_TRACE("Exit");
643  return JSValueMakeUndefined(ctx);
644 }
645 
646 /**
647  * @brief API invoked from JS when executing AAMPMediaPlayer.detach()
648  * @param[in] ctx JS execution context
649  * @param[in] function JSObject that is the function being called
650  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
651  * @param[in] argumentCount number of args
652  * @param[in] arguments[] JSValue array of args
653  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
654  * @retval JSValue that is the function's return value
655  */
656 JSValueRef AAMPMediaPlayerJS_detach (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
657 {
658  LOG_TRACE("Enter");
659  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
660  if (!privObj || !privObj->_aamp)
661  {
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);
665  }
666  LOG_WARN(privObj," _aamp->detach");
667  privObj->_aamp->detach();
668 
669  LOG_TRACE("Exit");
670  return JSValueMakeUndefined(ctx);
671 }
672 
673 /**
674  * @brief API invoked from JS when executing AAMPMediaPlayer.pause()
675  * @param[in] ctx JS execution context
676  * @param[in] function JSObject that is the function being called
677  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
678  * @param[in] argumentCount number of args
679  * @param[in] arguments[] JSValue array of args
680  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
681  * @retval JSValue that is the function's return value
682  */
683 JSValueRef AAMPMediaPlayerJS_pause (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
684 {
685  LOG_TRACE("Enter");
686  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
687  if (!privObj || !privObj->_aamp)
688  {
689  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
690  *exception = aamp_GetException(ctx, AAMPJS_MISSING_OBJECT, "Can only call pause() on instances of AAMPPlayer");
691  }
692  else
693  {
694 
695  if (argumentCount == 0)
696  {
697  LOG_WARN(privObj," _aamp->SetRate(0)");
698  privObj->_aamp->SetRate(0);
699  }
700  else if (argumentCount == 1)
701  {
702  double position = (double)JSValueToNumber(ctx, arguments[0], exception);
703  LOG_WARN(privObj," _aamp->PauseAt %lf",position);
704  privObj->_aamp->PauseAt(position);
705  }
706  else
707  {
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");
710  }
711  }
712  LOG_TRACE("Exit");
713  return JSValueMakeUndefined(ctx);
714 }
715 
716 
717 /**
718  * @brief API invoked from JS when executing AAMPMediaPlayer.stop()
719  * @param[in] ctx JS execution context
720  * @param[in] function JSObject that is the function being called
721  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
722  * @param[in] argumentCount number of args
723  * @param[in] arguments[] JSValue array of args
724  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
725  * @retval JSValue that is the function's return value
726  */
727 JSValueRef AAMPMediaPlayerJS_stop (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
728 {
729  LOG_TRACE("Enter");
730  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
731  if (!privObj || (privObj && !privObj->_aamp))
732  {
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);
736  }
737  LOG_WARN(privObj," _aamp->Stop()");
738  privObj->_aamp->Stop();
739  LOG_TRACE("Exit");
740  return JSValueMakeUndefined(ctx);
741 }
742 
743 
744 /**
745  * @brief API invoked from JS when executing AAMPMediaPlayer.seek()
746  * @param[in] ctx JS execution context
747  * @param[in] function JSObject that is the function being called
748  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
749  * @param[in] argumentCount number of args
750  * @param[in] arguments[] JSValue array of args
751  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
752  * @retval JSValue that is the function's return value
753  */
754 JSValueRef AAMPMediaPlayerJS_seek (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
755 {
756  LOG_TRACE("Enter");
757  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
758  if (!privObj)
759  {
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);
763  }
764  if (argumentCount == 1 || argumentCount == 2)
765  {
766  double newSeekPos = JSValueToNumber(ctx, arguments[0], exception);
767  bool keepPaused = (argumentCount == 2)? JSValueToBoolean(ctx, arguments[1]) : false;
768 
769  {
770  LOG_WARN(privObj," _aamp->Seek(%lf, %d)", newSeekPos, keepPaused);
771  privObj->_aamp->Seek(newSeekPos, keepPaused);
772  }
773  }
774  else
775  {
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");
778  }
779  LOG_TRACE("Exit");
780  return JSValueMakeUndefined(ctx);
781 }
782 
783 /**
784  * @brief API invoked from JS when executing AAMPMediaPlayer.GetThumbnails()
785  * @param[in] ctx JS execution context
786  * @param[in] function JSObject that is the function being called
787  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
788  * @param[in] argumentCount number of args
789  * @param[in] arguments[] JSValue array of args
790  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
791  * @retval JSValue that is the function's return value
792  */
793 JSValueRef AAMPMediaPlayerJS_getThumbnails (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
794 {
795  LOG_TRACE("Enter");
796  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
797  if (!privObj || !privObj->_aamp)
798  {
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);
802  }
803  if (argumentCount == 1)
804  {
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);
808  if (!value.empty())
809  {
810  LOG_INFO(privObj,"_aamp->GetThumbnails value [%s]",value.c_str());
811  return aamp_CStringToJSValue(ctx, value.c_str());
812  }
813 
814  }
815  else if (argumentCount == 2)
816  {
817  double startPos = JSValueToNumber(ctx, arguments[0], exception);
818  double endPos = JSValueToNumber(ctx, arguments[1], exception);
819 
820  std::string value = privObj->_aamp->GetThumbnails(startPos, endPos);
821 
822  if (!value.empty())
823  {
824  LOG_INFO(privObj," %d _aamp->GetThumbnails(%d, %d)",value.size(), startPos, endPos);
825  return aamp_CStringToJSValue(ctx, value.c_str());
826  }
827  else
828  {
829  LOG_INFO(privObj," 0 _aamp->GetThumbnails(%d, %d)", startPos, endPos);
830  }
831  }
832  else
833  {
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");
836  }
837  LOG_TRACE("Exit");
838  return JSValueMakeUndefined(ctx);
839 }
840 
841 /**
842  * @brief API invoked from JS when executing AAMPMediaPlayer.getAvailableThumbnailTracks()
843  * @param[in] ctx JS execution context
844  * @param[in] function JSObject that is the function being called
845  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
846  * @param[in] argumentCount number of args
847  * @param[in] arguments[] JSValue array of args
848  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
849  * @retval JSValue that is the function's return value
850  */
851 JSValueRef AAMPMediaPlayerJS_getAvailableThumbnailTracks (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
852 {
853  LOG_TRACE("Enter");
854  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
855  if (!privObj || !privObj->_aamp)
856  {
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);
860  }
861 
862  std::string value = privObj->_aamp->GetAvailableThumbnailTracks();
863  if (!value.empty())
864  {
865 
866  LOG_INFO(privObj,"_aamp->GetAvailableThumbnailTracks() %s",value.c_str());
867  return aamp_CStringToJSValue(ctx, value.c_str());
868  }
869  else
870  {
871  LOG_INFO(privObj,"_aamp->GetAvailableThumbnailTracks value empty");
872  }
873 
874  LOG_TRACE("Exit");
875  return JSValueMakeUndefined(ctx);
876 }
877 
878 /**
879  * @brief API invoked from JS when executing AAMPMediaPlayer.getAudioTrackInfo()
880  * @param[in] ctx JS execution context
881  * @param[in] function JSObject that is the function being called
882  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
883  * @param[in] argumentCount number of args
884  * @param[in] arguments[] JSValue array of args
885  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
886  * @retval JSValue that is the function's return value
887  */
888 JSValueRef AAMPMediaPlayerJS_getAudioTrackInfo (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
889 {
890 
891  LOG_TRACE("Enter");
892  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
893  if (!privObj)
894  {
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);
898  }
899  std::string value = privObj->_aamp->GetAudioTrackInfo();
900  if (!value.empty())
901  {
902  LOG_INFO(privObj," _aamp->GetAudioTrackInfo() value=[%s]",value.c_str());
903  return aamp_CStringToJSValue(ctx, value.c_str());
904  }
905  else
906  {
907  LOG_WARN(privObj,"_aamp->GetAudioTrackInfo() value=NULL");
908  }
909  LOG_TRACE("Exit");
910  return JSValueMakeUndefined(ctx);
911 }
912 
913 /**
914  * @brief API invoked from JS when executing AAMPMediaPlayer.getTextTrackInfo()
915  * @param[in] ctx JS execution context
916  * @param[in] function JSObject that is the function being called
917  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
918  * @param[in] argumentCount number of args
919  * @param[in] arguments[] JSValue array of args
920  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
921  * @retval JSValue that is the function's return value
922  */
923 JSValueRef AAMPMediaPlayerJS_getTextTrackInfo (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
924 {
925  LOG_TRACE("Enter");
926  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
927  if (!privObj)
928  {
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);
932  }
933  std::string value = privObj->_aamp->GetTextTrackInfo();
934  if (!value.empty())
935  {
936  LOG_INFO(privObj,"_aamp->GetTextTrackInfo() value=%s",value.c_str());
937  return aamp_CStringToJSValue(ctx, value.c_str());
938  }
939  else
940  {
941  LOG_WARN(privObj,"_aamp->GetTextTrackInfo() value=NULL");
942  }
943  LOG_TRACE("Exit");
944  return JSValueMakeUndefined(ctx);
945 }
946 
947 /**
948  * @brief API invoked from JS when executing AAMPMediaPlayer.getPreferredAudioProperties()
949  * @param[in] ctx JS execution context
950  * @param[in] function JSObject that is the function being called
951  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
952  * @param[in] argumentCount number of args
953  * @param[in] arguments[] JSValue array of args
954  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
955  * @retval JSValue that is the function's return value
956  */
957 JSValueRef AAMPMediaPlayerJS_getPreferredAudioProperties (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
958 {
959  LOG_TRACE("Enter");
960  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
961  if (!privObj)
962  {
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);
966  }
967  std::string value = privObj->_aamp->GetPreferredAudioProperties();
968  if (!value.empty())
969  {
970  LOG_INFO(privObj,"_aamp->GetPrefferedAudioProperties() value=%s",value.c_str());
971  return aamp_CStringToJSValue(ctx, value.c_str());
972  }
973  else
974  {
975  LOG_WARN(privObj,"_aamp->GetPrefferedAudioProperties() value=NULL");
976  }
977 
978  LOG_TRACE("Exit");
979  return JSValueMakeUndefined(ctx);
980 }
981 
982 /**
983  * @brief API invoked from JS when executing AAMPMediaPlayer.getPreferredTextProperties()
984  * @param[in] ctx JS execution context
985  * @param[in] function JSObject that is the function being called
986  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
987  * @param[in] argumentCount number of args
988  * @param[in] arguments[] JSValue array of args
989  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
990  * @retval JSValue that is the function's return value
991  */
992 JSValueRef AAMPMediaPlayerJS_getPreferredTextProperties (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
993 {
994  LOG_TRACE("Enter");
995  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
996  if (!privObj)
997  {
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);
1001  }
1002  std::string value = privObj->_aamp->GetPreferredTextProperties();
1003  if (!value.empty())
1004  {
1005  LOG_INFO(privObj,"_aamp->GetPreferredTextProperties() value=%s",value.c_str());
1006  return aamp_CStringToJSValue(ctx, value.c_str());
1007  }
1008  else
1009  {
1010  LOG_WARN(privObj,"_aamp->GetPreferredTextProperties() value=NULL");
1011  }
1012  LOG_TRACE("Exit");
1013  return JSValueMakeUndefined(ctx);
1014 }
1015 
1016 /**
1017  * @brief API invoked from JS when executing AAMPMediaPlayer.setThumbnailTrack()
1018  * @param[in] ctx JS execution context
1019  * @param[in] function JSObject that is the function being called
1020  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1021  * @param[in] argumentCount number of args
1022  * @param[in] arguments[] JSValue array of args
1023  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1024  * @retval JSValue that is the function's return value
1025  */
1026 JSValueRef AAMPMediaPlayerJS_setThumbnailTrack (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1027 {
1028  LOG_TRACE("Enter");
1029  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1030  if (!privObj || !privObj->_aamp)
1031  {
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);
1035  }
1036 
1037  if (argumentCount != 1)
1038  {
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");
1041  }
1042  else
1043  {
1044  int thumbnailIndex = (int) JSValueToNumber(ctx, arguments[0], NULL);
1045  if (thumbnailIndex >= 0)
1046  {
1047  LOG_WARN(privObj,"_aamp->SetThumbnailTrack(%d)", thumbnailIndex);
1048  return JSValueMakeBoolean(ctx, privObj->_aamp->SetThumbnailTrack(thumbnailIndex));
1049  }
1050  else
1051  {
1052  LOG_ERROR(privObj,"InvalidArgument - Index should be >= 0!");
1053  *exception = aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT, "Index should be >= 0!");
1054  }
1055  }
1056  LOG_TRACE("Exit");
1057  return JSValueMakeUndefined(ctx);
1058 }
1059 
1060 /**
1061  * @brief API invoked from JS when executing AAMPMediaPlayer.getCurrentState()
1062  * @param[in] ctx JS execution context
1063  * @param[in] function JSObject that is the function being called
1064  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1065  * @param[in] argumentCount number of args
1066  * @param[in] arguments[] JSValue array of args
1067  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1068  * @retval JSValue that is the function's return value
1069  */
1070 JSValueRef AAMPMediaPlayerJS_getCurrentState (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1071 {
1072  LOG_TRACE("Enter");
1073  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1074  if (!privObj || !privObj->_aamp)
1075  {
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);
1079  }
1080  LOG_INFO(privObj,"> _aamp->GetState()");
1081  LOG_TRACE("Exit");
1082  return JSValueMakeNumber(ctx, privObj->_aamp->GetState());
1083 }
1084 
1085 
1086 /**
1087  * @brief API invoked from JS when executing AAMPMediaPlayer.getDurationSec()
1088  * @param[in] ctx JS execution context
1089  * @param[in] function JSObject that is the function being called
1090  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1091  * @param[in] argumentCount number of args
1092  * @param[in] arguments[] JSValue array of args
1093  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1094  * @retval JSValue that is the function's return value
1095  */
1096 JSValueRef AAMPMediaPlayerJS_getDurationSec (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1097 {
1098  LOG_TRACE("Enter");
1099  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1100  double duration = 0;
1101  if (!privObj || !privObj->_aamp)
1102  {
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);
1106  }
1107  duration = privObj->_aamp->GetPlaybackDuration();
1108  if (duration < 0)
1109  {
1110  LOG_INFO(privObj,"Duration returned by GetPlaybackDuration() is less than 0!");
1111  duration = 0;
1112  }
1113 
1114  LOG_TRACE("Exit");
1115  return JSValueMakeNumber(ctx, duration);
1116 }
1117 
1118 
1119 /**
1120  * @brief API invoked from JS when executing AAMPMediaPlayer.getCurrentPosition()
1121  * @param[in] ctx JS execution context
1122  * @param[in] function JSObject that is the function being called
1123  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1124  * @param[in] argumentCount number of args
1125  * @param[in] arguments[] JSValue array of args
1126  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1127  * @retval JSValue that is the function's return value
1128  */
1129 JSValueRef AAMPMediaPlayerJS_getCurrentPosition (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1130 {
1131  LOG_TRACE("Enter");
1132  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1133  double currPosition = 0;
1134  if (!privObj || !privObj->_aamp)
1135  {
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);
1139  }
1140  currPosition = privObj->_aamp->GetPlaybackPosition();
1141  if (currPosition < 0)
1142  {
1143  LOG_INFO(privObj,"Current position returned by GetPlaybackPosition() is less than 0!");
1144  currPosition = 0;
1145  }
1146 
1147  LOG_TRACE("Exit");
1148  return JSValueMakeNumber(ctx, currPosition);
1149 }
1150 
1151 
1152 /**
1153  * @brief API invoked from JS when executing AAMPMediaPlayer.getVideoBitrates()
1154  * @param[in] ctx JS execution context
1155  * @param[in] function JSObject that is the function being called
1156  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1157  * @param[in] argumentCount number of args
1158  * @param[in] arguments[] JSValue array of args
1159  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1160  * @retval JSValue that is the function's return value
1161  */
1162 JSValueRef AAMPMediaPlayerJS_getVideoBitrates (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1163 {
1164  LOG_TRACE("Enter");
1165  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1166  if (!privObj || !privObj->_aamp)
1167  {
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);
1171  }
1172  std::vector<long> bitrates = privObj->_aamp->GetVideoBitrates();
1173  if (!bitrates.empty())
1174  {
1175  unsigned int length = bitrates.size();
1176  JSValueRef* array = new JSValueRef[length];
1177  for (int i = 0; i < length; i++)
1178  {
1179  LOG_INFO(privObj,"_aamp->GetVideoBitrates idx:%d value:%ld",i, bitrates[i]);
1180  array[i] = JSValueMakeNumber(ctx, bitrates[i]);
1181  }
1182 
1183  JSValueRef retVal = JSObjectMakeArray(ctx, length, array, NULL);
1184  SAFE_DELETE_ARRAY(array);
1185  LOG_TRACE("Exit");
1186  return retVal;
1187  }
1188  else
1189  {
1190  LOG_INFO(privObj," _aamp->GetVideoBitrates empty");
1191  }
1192  return JSValueMakeUndefined(ctx);
1193 }
1194 
1195 /**
1196  * @brief API invoked from JS when executing AAMPMediaPlayer.getManifest()
1197  * @param[in] ctx JS execution context
1198  * @param[in] function JSObject that is the function being called
1199  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1200  * @param[in] argumentCount number of args
1201  * @param[in] arguments[] JSValue array of args
1202  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1203  * @retval JSValue that is the function's return value
1204  */
1205 JSValueRef AAMPMediaPlayerJS_getManifest (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1206 {
1207  LOG_TRACE("Enter");
1208  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1209  if (!privObj || !privObj->_aamp)
1210  {
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);
1214  }
1215  std::string manifest = privObj->_aamp->GetManifest();
1216  if (!manifest.empty())
1217  {
1218  LOG_INFO(privObj," _aamp->GetManifest() [%s]",manifest.c_str());
1219  return aamp_CStringToJSValue(ctx, manifest.c_str());
1220  }
1221  else
1222  {
1223  LOG_WARN(privObj,"Manifest empty!");
1224  return JSValueMakeUndefined(ctx);
1225  }
1226 }
1227 
1228 /**
1229  * @brief API invoked from JS when executing AAMPMediaPlayer.getAudioBitrates()
1230  * @param[in] ctx JS execution context
1231  * @param[in] function JSObject that is the function being called
1232  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1233  * @param[in] argumentCount number of args
1234  * @param[in] arguments[] JSValue array of args
1235  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1236  * @retval JSValue that is the function's return value
1237  */
1238 JSValueRef AAMPMediaPlayerJS_getAudioBitrates (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1239 {
1240  LOG_TRACE("Enter");
1241  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1242  if (!privObj || !privObj->_aamp)
1243  {
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);
1247  }
1248  std::vector<long> bitrates = privObj->_aamp->GetAudioBitrates();
1249  if (!bitrates.empty())
1250  {
1251  unsigned int length = bitrates.size();
1252  JSValueRef* array = new JSValueRef[length];
1253  for (int i = 0; i < length; i++)
1254  {
1255  LOG_INFO(privObj,"_aamp->GetAudioBitrates idx:%d value:%ld",i, bitrates[i]);
1256  array[i] = JSValueMakeNumber(ctx, bitrates[i]);
1257  }
1258 
1259  JSValueRef retVal = JSObjectMakeArray(ctx, length, array, NULL);
1260  SAFE_DELETE_ARRAY(array);
1261  LOG_TRACE("Exit");
1262  return retVal;
1263  }
1264  else
1265  {
1266  LOG_INFO(privObj,"_aamp->GetAudioBitrates empty");
1267  }
1268 
1269  return JSValueMakeUndefined(ctx);
1270 }
1271 
1272 
1273 /**
1274  * @brief API invoked from JS when executing AAMPMediaPlayer.getCurrentVideoBitrate()
1275  * @param[in] ctx JS execution context
1276  * @param[in] function JSObject that is the function being called
1277  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1278  * @param[in] argumentCount number of args
1279  * @param[in] arguments[] JSValue array of args
1280  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1281  * @retval JSValue that is the function's return value
1282  */
1283 JSValueRef AAMPMediaPlayerJS_getCurrentVideoBitrate (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1284 {
1285  LOG_TRACE("Enter");
1286  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1287  if (!privObj || !privObj->_aamp)
1288  {
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);
1292  }
1293  LOG_INFO(privObj," aamp->GetVideoBitrate()");
1294  LOG_TRACE("Exit");
1295  return JSValueMakeNumber(ctx, privObj->_aamp->GetVideoBitrate());
1296 }
1297 
1298 
1299 /**
1300  * @brief API invoked from JS when executing AAMPMediaPlayer.setVideoBitrate()
1301  * @param[in] ctx JS execution context
1302  * @param[in] function JSObject that is the function being called
1303  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1304  * @param[in] argumentCount number of args
1305  * @param[in] arguments[] JSValue array of args
1306  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1307  * @retval JSValue that is the function's return value
1308  */
1309 JSValueRef AAMPMediaPlayerJS_setVideoBitrate (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1310 {
1311  LOG_TRACE("Enter");
1312  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1313  if (!privObj || !privObj->_aamp)
1314  {
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);
1318  }
1319 
1320  if (argumentCount != 1)
1321  {
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");
1324  }
1325  else
1326  {
1327  long bitrate = (long) JSValueToNumber(ctx, arguments[0], NULL);
1328  //bitrate 0 is for ABR
1329  if (bitrate >= 0)
1330  {
1331  LOG_WARN(privObj,"_aamp->SetVideoBitrate(%ld)", bitrate);
1332  privObj->_aamp->SetVideoBitrate(bitrate);
1333  }
1334  else
1335  {
1336  LOG_ERROR(privObj,"InvalidArgument - bitrate should be >= 0!");
1337  *exception = aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT, "Bitrate should be >= 0!");
1338  }
1339  }
1340  LOG_TRACE("Exit");
1341  return JSValueMakeUndefined(ctx);
1342 }
1343 
1344 
1345 /**
1346  * @brief API invoked from JS when executing AAMPMediaPlayer.getCurrentAudioBitrate()
1347  * @param[in] ctx JS execution context
1348  * @param[in] function JSObject that is the function being called
1349  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1350  * @param[in] argumentCount number of args
1351  * @param[in] arguments[] JSValue array of args
1352  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1353  * @retval JSValue that is the function's return value
1354  */
1355 JSValueRef AAMPMediaPlayerJS_getCurrentAudioBitrate (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1356 {
1357  LOG_TRACE("Enter");
1358  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1359  if (!privObj || !privObj->_aamp)
1360  {
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);
1364  }
1365  LOG_INFO(privObj,"> _aamp->GetAudioBitrate()");
1366  LOG_TRACE("Exit");
1367  return JSValueMakeNumber(ctx, privObj->_aamp->GetAudioBitrate());
1368 }
1369 
1370 
1371 /**
1372  * @brief API invoked from JS when executing AAMPMediaPlayer.setAudioBitrate()
1373  * @param[in] ctx JS execution context
1374  * @param[in] function JSObject that is the function being called
1375  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1376  * @param[in] argumentCount number of args
1377  * @param[in] arguments[] JSValue array of args
1378  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1379  * @retval JSValue that is the function's return value
1380  */
1381 JSValueRef AAMPMediaPlayerJS_setAudioBitrate (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1382 {
1383  LOG_TRACE("Enter");
1384  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1385  if (!privObj || !privObj->_aamp)
1386  {
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);
1390  }
1391 
1392  if (argumentCount != 1)
1393  {
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");
1396  }
1397  else
1398  {
1399  long bitrate = (long) JSValueToNumber(ctx, arguments[0], NULL);
1400  if (bitrate >= 0)
1401  {
1402  LOG_WARN(privObj," _aamp->SetAudioBitrate(%ld)", bitrate);
1403  privObj->_aamp->SetAudioBitrate(bitrate);
1404  }
1405  else
1406  {
1407  LOG_ERROR(privObj,"InvalidArgument - bitrate should be >= 0!");
1408  *exception = aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT, "Bitrate should be >= 0!");
1409  }
1410  }
1411  LOG_TRACE("Exit");
1412  return JSValueMakeUndefined(ctx);
1413 }
1414 
1415 
1416 /**
1417  * @brief API invoked from JS when executing AAMPMediaPlayer.getAudioTrack()
1418  * @param[in] ctx JS execution context
1419  * @param[in] function JSObject that is the function being called
1420  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1421  * @param[in] argumentCount number of args
1422  * @param[in] arguments[] JSValue array of args
1423  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1424  * @retval JSValue that is the function's return value
1425  */
1426 JSValueRef AAMPMediaPlayerJS_getAudioTrack (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1427 {
1428  LOG_TRACE("Enter");
1429  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1430  if (!privObj || !privObj->_aamp)
1431  {
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);
1435  }
1436  LOG_INFO(privObj,"> _aamp->GetAudioTrack()");
1437  LOG_TRACE("Exit");
1438  return JSValueMakeNumber(ctx, privObj->_aamp->GetAudioTrack());
1439 }
1440 
1441 
1442 /**
1443  * @brief API invoked from JS when executing AAMPMediaPlayer.setAudioTrack()
1444  * @param[in] ctx JS execution context
1445  * @param[in] function JSObject that is the function being called
1446  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1447  * @param[in] argumentCount number of args
1448  * @param[in] arguments[] JSValue array of args
1449  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1450  * @retval JSValue that is the function's return value
1451  */
1452 JSValueRef AAMPMediaPlayerJS_setAudioTrack (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1453 {
1454  LOG_TRACE("Enter");
1455  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1456  if (!privObj || !privObj->_aamp)
1457  {
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);
1461  }
1462 
1463  if (argumentCount != 1)
1464  {
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");
1467  }
1468  else if (JSValueIsObject(ctx, arguments[0]))
1469  {
1470  /*
1471  * Parmater format
1472  * "audioTuple": object {
1473  * "language": "en",
1474  * "rendition": "main"
1475  * "codec": "avc",
1476  * "channel": 6
1477  * "label": "surround"
1478  * }
1479  */
1480  char *language = NULL;
1481  int channel = 0;
1482  char *rendition = NULL;
1483  char *codec = NULL;
1484  char *type = NULL;
1485  char *label = NULL;
1486  //Parse the ad object
1487  JSObjectRef audioProperty = JSValueToObject(ctx, arguments[0], NULL);
1488  if (audioProperty == NULL)
1489  {
1490  LOG_ERROR_EX("Unable to convert argument to JSObject");
1491  return JSValueMakeUndefined(ctx);
1492  }
1493  JSStringRef propName = JSStringCreateWithUTF8CString("language");
1494  JSValueRef propValue = JSObjectGetProperty(ctx, audioProperty, propName, NULL);
1495  if (JSValueIsString(ctx, propValue))
1496  {
1497  language = aamp_JSValueToCString(ctx, propValue, NULL);
1498  }
1499  JSStringRelease(propName);
1500 
1501  propName = JSStringCreateWithUTF8CString("rendition");
1502  propValue = JSObjectGetProperty(ctx, audioProperty, propName, NULL);
1503  if (JSValueIsString(ctx, propValue))
1504  {
1505  rendition = aamp_JSValueToCString(ctx, propValue, NULL);
1506  }
1507  JSStringRelease(propName);
1508 
1509  propName = JSStringCreateWithUTF8CString("codec");
1510  propValue = JSObjectGetProperty(ctx, audioProperty, propName, NULL);
1511  if (JSValueIsString(ctx, propValue))
1512  {
1513  codec = aamp_JSValueToCString(ctx, propValue, NULL);
1514  }
1515  JSStringRelease(propName);
1516 
1517  propName = JSStringCreateWithUTF8CString("type");
1518  propValue = JSObjectGetProperty(ctx, audioProperty, propName, NULL);
1519  if (JSValueIsString(ctx, propValue))
1520  {
1521  type = aamp_JSValueToCString(ctx, propValue, NULL);
1522  }
1523  JSStringRelease(propName);
1524 
1525  propName = JSStringCreateWithUTF8CString("channel");
1526  propValue = JSObjectGetProperty(ctx, audioProperty, propName, NULL);
1527  if (JSValueIsNumber(ctx, propValue))
1528  {
1529  channel = JSValueToNumber(ctx, propValue, NULL);
1530  }
1531  JSStringRelease(propName);
1532 
1533  propName = JSStringCreateWithUTF8CString("label");
1534  propValue = JSObjectGetProperty(ctx, audioProperty, propName, NULL);
1535  if (JSValueIsString(ctx, propValue))
1536  {
1537  label = aamp_JSValueToCString(ctx, propValue, NULL);
1538  }
1539  JSStringRelease(propName);
1540 
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());
1552 
1553  privObj->_aamp->SetAudioTrack(strLanguage, strRendition, strType, strCodec, channel, strLabel);
1554 
1555  }
1556  else
1557  {
1558  int index = (int) JSValueToNumber(ctx, arguments[0], NULL);
1559  if (index >= 0)
1560  {
1561  {
1562  privObj->_aamp->SetAudioTrack(index);
1563  }
1564  }
1565  else
1566  {
1567  LOG_ERROR(privObj,"InvalidArgument - track index should be >= 0!");
1568  *exception = aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT, "Audio track index should be >= 0!");
1569  }
1570  }
1571  LOG_TRACE("Exit");
1572  return JSValueMakeUndefined(ctx);
1573 }
1574 
1575 
1576 /**
1577  * @brief API invoked from JS when executing AAMPMediaPlayer.getTextTrack()
1578  * @param[in] ctx JS execution context
1579  * @param[in] function JSObject that is the function being called
1580  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1581  * @param[in] argumentCount number of args
1582  * @param[in] arguments[] JSValue array of args
1583  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1584  * @retval JSValue that is the function's return value
1585  */
1586 JSValueRef AAMPMediaPlayerJS_getTextTrack (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1587 {
1588  LOG_TRACE("Enter");
1589  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1590  if (!privObj || !privObj->_aamp)
1591  {
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);
1595  }
1596  LOG_INFO(privObj,"> _aamp->GetTextTrack()");
1597  LOG_TRACE("Exit");
1598  return JSValueMakeNumber(ctx, privObj->_aamp->GetTextTrack());
1599 }
1600 
1601 
1602 /**
1603  * @brief API invoked from JS when executing AAMPMediaPlayer.setTextTrack()
1604  * @param[in] ctx JS execution context
1605  * @param[in] function JSObject that is the function being called
1606  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1607  * @param[in] argumentCount number of args
1608  * @param[in] arguments[] JSValue array of args
1609  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1610  * @retval JSValue that is the function's return value
1611  */
1612 JSValueRef AAMPMediaPlayerJS_setTextTrack (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1613 {
1614  LOG_TRACE("Enter");
1615  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1616  if (!privObj || !privObj->_aamp)
1617  {
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);
1621  }
1622 
1623  if (argumentCount != 1)
1624  {
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");
1627  }
1628  else if (!JSValueIsNumber(ctx, arguments[0]))
1629  {
1630  // note, here, first parameter is not used, only the passed WebVTT data
1631  // note: SetTextTrack() will responsibility for releasing data when no longer needed
1632  char *data = aamp_JSValueToCString(ctx, arguments[0], exception);
1633  privObj->_aamp->SetTextTrack(0, data);
1634 
1635  }
1636  else
1637  {
1638  int index = (int) JSValueToNumber(ctx, arguments[0], NULL);
1639  if (index >= MUTE_SUBTITLES_TRACKID) // -1 disable subtitles, >0 subtitle track index
1640  {
1641  LOG_WARN(privObj,"_aamp->SetAudioTrack(%d)", index);
1642  privObj->_aamp->SetTextTrack(index);
1643  }
1644  else
1645  {
1646  LOG_ERROR(privObj,"InvalidArgument - track index should be >= -1!");
1647  *exception = aamp_GetException(ctx, AAMPJS_INVALID_ARGUMENT, "Text track index should be >= -1!");
1648  }
1649  }
1650  LOG_TRACE("Exit");
1651  return JSValueMakeUndefined(ctx);
1652 }
1653 
1654 
1655 /**
1656  * @brief API invoked from JS when executing AAMPMediaPlayer.getVolume()
1657  * @param[in] ctx JS execution context
1658  * @param[in] function JSObject that is the function being called
1659  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1660  * @param[in] argumentCount number of args
1661  * @param[in] arguments[] JSValue array of args
1662  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1663  * @retval JSValue that is the function's return value
1664  */
1665 JSValueRef AAMPMediaPlayerJS_getVolume (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1666 {
1667  LOG_TRACE("Enter");
1668  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1669  if (!privObj || !privObj->_aamp)
1670  {
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);
1674  }
1675 
1676  LOG_INFO(privObj,"_aamp->GetAudioVolume()");
1677  LOG_TRACE("Exit");
1678  return JSValueMakeNumber(ctx, privObj->_aamp->GetAudioVolume());
1679 }
1680 
1681 
1682 /**
1683  * @brief API invoked from JS when executing AAMPMediaPlayer.setVolume()
1684  * @param[in] ctx JS execution context
1685  * @param[in] function JSObject that is the function being called
1686  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1687  * @param[in] argumentCount number of args
1688  * @param[in] arguments[] JSValue array of args
1689  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1690  * @retval JSValue that is the function's return value
1691  */
1692 JSValueRef AAMPMediaPlayerJS_setVolume (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1693 {
1694  LOG_TRACE("Enter");
1695  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1696  if (!privObj || !privObj->_aamp)
1697  {
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);
1701  }
1702 
1703  if(!privObj->_aamp)
1704  {
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);
1708  }
1709 
1710  if (argumentCount == 1)
1711  {
1712  int volume = (int) JSValueToNumber(ctx, arguments[0], exception);
1713  if (volume >= 0)
1714  {
1715  LOG_WARN(privObj," _aamp->SetAudioVolume(%d)", volume);
1716  privObj->_aamp->SetAudioVolume(volume);
1717  }
1718  else
1719  {
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");
1722  }
1723  }
1724  else
1725  {
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");
1728  }
1729  LOG_TRACE("Exit");
1730  return JSValueMakeUndefined(ctx);
1731 }
1732 
1733 /**
1734  * @brief API invoked from JS when executing AAMPMediaPlayer.setAudioLanguage()
1735  * @param[in] ctx JS execution context
1736  * @param[in] function JSObject that is the function being called
1737  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1738  * @param[in] argumentCount number of args
1739  * @param[in] arguments[] JSValue array of args
1740  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1741  * @retval JSValue that is the function's return value
1742  */
1743 JSValueRef AAMPMediaPlayerJS_setAudioLanguage (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1744 {
1745  LOG_TRACE("Enter");
1746  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1747  if (!privObj || !privObj->_aamp)
1748  {
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);
1752  }
1753 
1754  if (argumentCount == 1)
1755  {
1756  const char *lang = aamp_JSValueToCString(ctx, arguments[0], exception);
1757  {
1758  LOG_WARN(privObj," _aamp->SetLanguage(%s)", lang);
1759  privObj->_aamp->SetLanguage(lang);
1760  }
1761  SAFE_DELETE_ARRAY(lang);
1762  }
1763  else
1764  {
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");
1767  }
1768  LOG_TRACE("Exit");
1769  return JSValueMakeUndefined(ctx);
1770 }
1771 
1772 /**
1773  * @brief API invoked from JS when executing AAMPMediaPlayer.getPlaybackRate()
1774  * @param[in] ctx JS execution context
1775  * @param[in] function JSObject that is the function being called
1776  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1777  * @param[in] argumentCount number of args
1778  * @param[in] arguments[] JSValue array of args
1779  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1780  * @retval JSValue that is the function's return value
1781  */
1782 JSValueRef AAMPMediaPlayerJS_getPlaybackRate (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1783 {
1784  LOG_TRACE("Enter");
1785  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1786  if (!privObj || !privObj->_aamp)
1787  {
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);
1791  }
1792  LOG_INFO(privObj,"> aamp->GetPlaybackRate()");
1793  LOG_TRACE("Exit");
1794  return JSValueMakeNumber(ctx, privObj->_aamp->GetPlaybackRate());
1795 }
1796 
1797 
1798 /**
1799  * @brief API invoked from JS when executing AAMPMediaPlayer.setPlaybackRate()
1800  * @param[in] ctx JS execution context
1801  * @param[in] function JSObject that is the function being called
1802  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1803  * @param[in] argumentCount number of args
1804  * @param[in] arguments[] JSValue array of args
1805  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1806  * @retval JSValue that is the function's return value
1807  */
1808 JSValueRef AAMPMediaPlayerJS_setPlaybackRate (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1809 {
1810  LOG_TRACE("Enter");
1811  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1812  if (!privObj || !privObj->_aamp)
1813  {
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);
1817  }
1818 
1819  if (argumentCount == 1 || argumentCount == 2)
1820  {
1821  int overshootCorrection = 0;
1822  float rate = (float) JSValueToNumber(ctx, arguments[0], exception);
1823  if (argumentCount == 2)
1824  {
1825  overshootCorrection = (int) JSValueToNumber(ctx, arguments[1], exception);
1826  }
1827  {
1828  LOG_WARN(privObj,"_aamp->SetRate(%d, %d)", rate, overshootCorrection);
1829  privObj->_aamp->SetRate(rate, overshootCorrection);
1830  }
1831  }
1832  else
1833  {
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");
1836  }
1837  LOG_TRACE("Exit");
1838  return JSValueMakeUndefined(ctx);
1839 }
1840 
1841 
1842 /**
1843  * @brief API invoked from JS when executing AAMPMediaPlayer.getSupportedKeySystems()
1844  * @param[in] ctx JS execution context
1845  * @param[in] function JSObject that is the function being called
1846  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1847  * @param[in] argumentCount number of args
1848  * @param[in] arguments[] JSValue array of args
1849  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1850  * @retval JSValue that is the function's return value
1851  */
1852 JSValueRef AAMPMediaPlayerJS_getSupportedKeySystems (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1853 {
1854  LOG_TRACE("Enter");
1855  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1856  if (!privObj || !privObj->_aamp)
1857  {
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);
1861  }
1862  LOG_INFO(privObj,"Invoked getSupportedKeySystems");
1863  LOG_TRACE("Exit");
1864  return JSValueMakeUndefined(ctx);
1865 }
1866 
1867 
1868 /**
1869  * @brief API invoked from JS when executing AAMPMediaPlayer.setVideoMute()
1870  * @param[in] ctx JS execution context
1871  * @param[in] function JSObject that is the function being called
1872  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1873  * @param[in] argumentCount number of args
1874  * @param[in] arguments[] JSValue array of args
1875  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1876  * @retval JSValue that is the function's return value
1877  */
1878 JSValueRef AAMPMediaPlayerJS_setVideoMute (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1879 {
1880  LOG_TRACE("Enter");
1881  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1882  if (!privObj || !privObj->_aamp)
1883  {
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);
1887  }
1888 
1889  if (argumentCount == 1)
1890  {
1891  bool videoMute = JSValueToBoolean(ctx, arguments[0]);
1892  privObj->_aamp->SetVideoMute(videoMute);
1893  // privObj->_aamp->SetSubtitleMute(videoMute);
1894  LOG_WARN(privObj,"Invoked setVideoMute %d",videoMute);
1895 
1896  }
1897  else
1898  {
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");
1901  }
1902  LOG_TRACE("Exit");
1903  return JSValueMakeUndefined(ctx);
1904 }
1905 
1906 
1907 /**
1908  * @brief API invoked from JS when executing AAMPMediaPlayer.setSubscribedTags()
1909  * @param[in] ctx JS execution context
1910  * @param[in] function JSObject that is the function being called
1911  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1912  * @param[in] argumentCount number of args
1913  * @param[in] arguments[] JSValue array of args
1914  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1915  * @retval JSValue that is the function's return value
1916  */
1917 JSValueRef AAMPMediaPlayerJS_setSubscribedTags (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1918 {
1919  LOG_TRACE("Enter");
1920  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1921  if (!privObj || !privObj->_aamp)
1922  {
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);
1926  }
1927 
1928  if (argumentCount != 1)
1929  {
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");
1932  }
1933  else if (!aamp_JSValueIsArray(ctx, arguments[0]))
1934  {
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");
1937  }
1938  else
1939  {
1940  std::vector<std::string> subscribedTags = aamp_StringArrayToCStringArray(ctx, arguments[0]);
1941  privObj->_aamp->SetSubscribedTags(subscribedTags);
1942  LOG_WARN(privObj,"Invoked setSubscribedTags");
1943  }
1944  LOG_TRACE("Exit");
1945  return JSValueMakeUndefined(ctx);
1946 }
1947 
1948 
1949 /**
1950  * @brief API invoked from JS when executing AAMPMediaPlayer.subscribeResponseHeaders()
1951  * @param[in] ctx JS execution context
1952  * @param[in] function JSObject that is the function being called
1953  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1954  * @param[in] argumentCount number of args
1955  * @param[in] arguments[] JSValue array of args
1956  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1957  * @retval JSValue that is the function's return value
1958  */
1959 JSValueRef AAMPMediaPlayerJS_subscribeResponseHeaders (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1960 {
1961  LOG_TRACE("Enter");
1962  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
1963  if (!privObj || !privObj->_aamp)
1964  {
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);
1968  }
1969 
1970  if (argumentCount != 1)
1971  {
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");
1974  }
1975  else if (!aamp_JSValueIsArray(ctx, arguments[0]))
1976  {
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");
1979  }
1980  else
1981  {
1982  std::vector<std::string> responseHeaders = aamp_StringArrayToCStringArray(ctx, arguments[0]);
1983  privObj->_aamp->SubscribeResponseHeaders(responseHeaders);
1984  LOG_WARN(privObj," Invoked SubscribeResponseHeaders");
1985  }
1986  LOG_TRACE("Exit");
1987  return JSValueMakeUndefined(ctx);
1988 }
1989 
1990 
1991 /**
1992  * @brief API invoked from JS when executing AAMPMediaPlayer.addEventListener()
1993  * @param[in] ctx JS execution context
1994  * @param[in] function JSObject that is the function being called
1995  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1996  * @param[in] argumentCount number of args
1997  * @param[in] arguments[] JSValue array of args
1998  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1999  * @retval JSValue that is the function's return value
2000  */
2001 JSValueRef AAMPMediaPlayerJS_addEventListener (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
2002 {
2003  LOG_TRACE("Enter");
2004  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
2005  if (!privObj || !privObj->_aamp)
2006  {
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);
2010  }
2011 
2012  if (argumentCount >= 2)
2013  {
2014  char* type = aamp_JSValueToCString(ctx, arguments[0], NULL);
2015  JSObjectRef callbackObj = JSValueToObject(ctx, arguments[1], NULL);
2016 
2017  if ((callbackObj != NULL) && JSObjectIsFunction(ctx, callbackObj))
2018  {
2020  LOG_WARN(privObj,"eventType='%s', %d", type, eventType);
2021 
2022  if ((eventType >= 0) && (eventType < AAMP_MAX_NUM_EVENTS))
2023  {
2024  AAMP_JSEventListener::AddEventListener(privObj, eventType, callbackObj);
2025  }
2026  }
2027  else
2028  {
2029  LOG_ERROR(privObj,"callbackObj=%p, JSObjectIsFunction(context, callbackObj) is NULL", callbackObj);
2030  char errMsg[512];
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);
2034  }
2035  SAFE_DELETE_ARRAY(type);
2036  }
2037  else
2038  {
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.");
2041  }
2042  LOG_TRACE("Exit");
2043  return JSValueMakeUndefined(ctx);
2044 }
2045 
2046 
2047 /**
2048  * @brief API invoked from JS when executing AAMPMediaPlayer.removeEventListener()
2049  * @param[in] ctx JS execution context
2050  * @param[in] function JSObject that is the function being called
2051  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2052  * @param[in] argumentCount number of args
2053  * @param[in] arguments[] JSValue array of args
2054  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2055  * @retval JSValue that is the function's return value
2056  */
2057 JSValueRef AAMPMediaPlayerJS_removeEventListener (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
2058 {
2059  LOG_TRACE("Enter");
2060  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
2061  if (!privObj || !privObj->_aamp)
2062  {
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);
2066  }
2067 
2068  if (argumentCount >= 2)
2069  {
2070  char* type = aamp_JSValueToCString(ctx, arguments[0], NULL);
2071  JSObjectRef callbackObj = JSValueToObject(ctx, arguments[1], NULL);
2072 
2073  if ((callbackObj != NULL) && JSObjectIsFunction(ctx, callbackObj))
2074  {
2076  LOG_WARN(privObj,"eventType='%s', %d", type, eventType);
2077 
2078  if ((eventType >= 0) && (eventType < AAMP_MAX_NUM_EVENTS))
2079  {
2080  AAMP_JSEventListener::RemoveEventListener(privObj, eventType, callbackObj);
2081  }
2082  }
2083  else
2084  {
2085  LOG_ERROR(privObj,"InvalidArgument: callbackObj=%p, JSObjectIsFunction(context, callbackObj) is NULL", callbackObj);
2086  char errMsg[512];
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);
2090  }
2091  SAFE_DELETE_ARRAY(type);
2092  }
2093  else
2094  {
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");
2097  }
2098  LOG_TRACE("Exit");
2099  return JSValueMakeUndefined(ctx);
2100 }
2101 
2102 
2103 /**
2104  * @brief API invoked from JS when executing AAMPMediaPlayer.setDRMConfig()
2105  * @param[in] ctx JS execution context
2106  * @param[in] function JSObject that is the function being called
2107  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2108  * @param[in] argumentCount number of args
2109  * @param[in] arguments[] JSValue array of args
2110  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2111  * @retval JSValue that is the function's return value
2112  */
2113 JSValueRef AAMPMediaPlayerJS_setDRMConfig (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
2114 {
2115  LOG_TRACE("Enter");
2116  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
2117  if (!privObj || !privObj->_aamp)
2118  {
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);
2122  }
2123 
2124  if (argumentCount != 1)
2125  {
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");
2128  }
2129  else
2130  {
2131  if (JSValueIsObject(ctx, arguments[0]))
2132  {
2133  parseDRMConfiguration(ctx, privObj, arguments[0]);
2134  }
2135  }
2136  LOG_TRACE("Exit");
2137  return JSValueMakeUndefined(ctx);
2138 }
2139 
2140 
2141 /**
2142  * @brief API invoked from JS when executing AAMPMediaPlayer.addCustomHTTPHeader()
2143  * @param[in] ctx JS execution context
2144  * @param[in] function JSObject that is the function being called
2145  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2146  * @param[in] argumentCount number of args
2147  * @param[in] arguments[] JSValue array of args
2148  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2149  * @retval JSValue that is the function's return value
2150  */
2151 JSValueRef AAMPMediaPlayerJS_addCustomHTTPHeader (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
2152 {
2153  LOG_TRACE("Enter");
2154  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
2155  if (!privObj || !privObj->_aamp)
2156  {
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);
2160  }
2161 
2162  //optional parameter 3 for identifying if the header is for a license request
2163  if (argumentCount == 2 || argumentCount == 3)
2164  {
2165  char *name = aamp_JSValueToCString(ctx, arguments[0], exception);
2166  std::string headerName(name);
2167  std::vector<std::string> headerVal;
2168  bool isLicenseHeader = false;
2169 
2170  SAFE_DELETE_ARRAY(name);
2171 
2172  if (aamp_JSValueIsArray(ctx, arguments[1]))
2173  {
2174  headerVal = aamp_StringArrayToCStringArray(ctx, arguments[1]);
2175  }
2176  else if (JSValueIsString(ctx, arguments[1]))
2177  {
2178  headerVal.reserve(1);
2179  char *value = aamp_JSValueToCString(ctx, arguments[1], exception);
2180  headerVal.push_back(value);
2181  SAFE_DELETE_ARRAY(value);
2182  }
2183 
2184  // Don't support empty values now
2185  if (headerVal.size() == 0)
2186  {
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);
2190  }
2191 
2192  if (argumentCount == 3)
2193  {
2194  isLicenseHeader = JSValueToBoolean(ctx, arguments[2]);
2195  }
2196  LOG_WARN(privObj," _aamp->AddCustomHTTPHeader headerName= %s headerVal= %p",headerName.c_str(), headerVal);
2197  privObj->_aamp->AddCustomHTTPHeader(headerName, headerVal, isLicenseHeader);
2198  }
2199  else
2200  {
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");
2203  }
2204  LOG_TRACE("Exit");
2205  return JSValueMakeUndefined(ctx);
2206 }
2207 
2208 
2209 /**
2210  * @brief API invoked from JS when executing AAMPMediaPlayer.removeCustomHTTPHeader()
2211  * @param[in] ctx JS execution context
2212  * @param[in] function JSObject that is the function being called
2213  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2214  * @param[in] argumentCount number of args
2215  * @param[in] arguments[] JSValue array of args
2216  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2217  * @retval JSValue that is the function's return value
2218  */
2219 JSValueRef AAMPMediaPlayerJS_removeCustomHTTPHeader (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
2220 {
2221  LOG_TRACE("Enter");
2222  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
2223  if (!privObj || !privObj->_aamp)
2224  {
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);
2228  }
2229 
2230  if (argumentCount == 1)
2231  {
2232  char *name = aamp_JSValueToCString(ctx, arguments[0], exception);
2233  std::string headerName(name);
2234  LOG_WARN(privObj,"_aamp->AddCustomHTTPHeader(%s)", headerName.c_str());
2235  privObj->_aamp->AddCustomHTTPHeader(headerName, std::vector<std::string>());
2236  SAFE_DELETE_ARRAY(name);
2237  }
2238  else
2239  {
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");
2242  }
2243  LOG_TRACE("Exit");
2244  return JSValueMakeUndefined(ctx);
2245 }
2246 
2247 
2248 /**
2249  * @brief API invoked from JS when executing AAMPMediaPlayer.setVideoRect()
2250  * @param[in] ctx JS execution context
2251  * @param[in] function JSObject that is the function being called
2252  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2253  * @param[in] argumentCount number of args
2254  * @param[in] arguments[] JSValue array of args
2255  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2256  * @retval JSValue that is the function's return value
2257  */
2258 JSValueRef AAMPMediaPlayerJS_setVideoRect (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
2259 {
2260  LOG_TRACE("Enter");
2261  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
2262  if (!privObj || !privObj->_aamp)
2263  {
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);
2267  }
2268 
2269  if (argumentCount == 4)
2270  {
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);
2275  {
2276  LOG_WARN(privObj,"_aamp->SetVideoRectangle(%d, %d, %d, %d)", x, y, w, h);
2277  privObj->_aamp->SetVideoRectangle(x, y, w, h);
2278  }
2279  }
2280  else
2281  {
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");
2284  }
2285  LOG_TRACE("Exit");
2286  return JSValueMakeUndefined(ctx);
2287 }
2288 
2289 
2290 /**
2291  * @brief API invoked from JS when executing AAMPMediaPlayer.setVideoZoom()
2292  * @param[in] ctx JS execution context
2293  * @param[in] function JSObject that is the function being called
2294  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2295  * @param[in] argumentCount number of args
2296  * @param[in] arguments[] JSValue array of args
2297  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2298  * @retval JSValue that is the function's return value
2299  */
2300 JSValueRef AAMPMediaPlayerJS_setVideoZoom (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
2301 {
2302  LOG_TRACE("Enter");
2303  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
2304  if (!privObj || !privObj->_aamp)
2305  {
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);
2309  }
2310 
2311  if (argumentCount == 1)
2312  {
2313  VideoZoomMode zoom;
2314  char* zoomStr = aamp_JSValueToCString(ctx, arguments[0], exception);
2315  if (0 == strcmp(zoomStr, "none"))
2316  {
2317  zoom = VIDEO_ZOOM_NONE;
2318  }
2319  else
2320  {
2321  zoom = VIDEO_ZOOM_FULL;
2322  }
2323  LOG_WARN(privObj,"_aamp->SetVideoZoom(%d)", static_cast<int>(zoom));
2324  privObj->_aamp->SetVideoZoom(zoom);
2325  SAFE_DELETE_ARRAY(zoomStr);
2326  }
2327  else
2328  {
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");
2331  }
2332  LOG_TRACE("Exit");
2333  return JSValueMakeUndefined(ctx);
2334 }
2335 
2336 
2337 /**
2338  * @brief API invoked from JS when executing AAMPMediaPlayer.release()
2339  * @param[in] ctx JS execution context
2340  * @param[in] function JSObject that is the function being called
2341  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2342  * @param[in] argumentCount number of args
2343  * @param[in] arguments[] JSValue array of args
2344  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2345  * @retval JSValue that is the function's return value
2346  */
2347 JSValueRef AAMPMediaPlayerJS_release (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
2348 {
2349  LOG_TRACE("Enter");
2350 
2351  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
2352  if (!privObj)
2353  {
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);
2357  }
2358 
2359  if (false == findInGlobalCacheAndRelease(privObj))
2360  {
2361  LOG_WARN(privObj,"Invoked release of a PlayerInstanceAAMP object(%p) which was already/being released!!",privObj);
2362  }
2363  else
2364  {
2365  LOG_WARN(privObj,"Cleaned up native object for AAMPMediaPlayer_JS and PlayerInstanceAAMP object(%p)!!" ,privObj);
2366 
2367  }
2368 
2369  // Un-link native object from JS object
2370  JSObjectSetPrivate(thisObject, NULL);
2371 
2372  // Delete native object
2373  SAFE_DELETE(privObj);
2374 
2375 
2376  LOG_TRACE("Exit");
2377  return JSValueMakeUndefined(ctx);
2378 }
2379 
2380 /**
2381  * @brief API invoked from JS when executing AAMPMediaPlayer.getAvailableVideoTracks()
2382  * @param[in] ctx JS execution context
2383  * @param[in] function JSObject that is the function being called
2384  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2385  * @param[in] argumentCount number of args
2386  * @param[in] arguments[] JSValue array of args
2387  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2388  * @retval JSValue that is the function's return value
2389  */
2390 static JSValueRef AAMPMediaPlayerJS_getAvailableVideoTracks(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2391 {
2392  LOG_TRACE("Enter");
2393  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
2394  if(!privObj || !privObj->_aamp)
2395  {
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);
2399  }
2400  std::string tracks = privObj->_aamp->GetAvailableVideoTracks();
2401  if (!tracks.empty())
2402  {
2403  LOG_INFO(privObj,"_aamp->GetAvailableVideoTracks tracks=%s",tracks.c_str());
2404  return aamp_CStringToJSValue(ctx, tracks.c_str());
2405  }
2406  else
2407  {
2408  LOG_WARN(privObj,"_aamp->GetAvailableVideoTracks tracks=NULL");
2409  return JSValueMakeUndefined(ctx);
2410  }
2411 }
2412 
2413 /**
2414  * @brief API invoked from JS when executing AAMPMediaPlayer.setvideoTrack()
2415  * @param[in] ctx JS execution context
2416  * @param[in] function JSObject that is the function being called
2417  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2418  * @param[in] argumentCount number of args
2419  * @param[in] arguments[] JSValue array of args
2420  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2421  * @retval JSValue that is the function's return value
2422  */
2423 JSValueRef AAMPMediaPlayerJS_setVideoTracks (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
2424 {
2425  LOG_TRACE("Enter");
2426  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
2427  std::vector<long> bitrateList;
2428  if (!privObj || !privObj->_aamp)
2429  {
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);
2433  }
2434  for (int i =0; i < argumentCount; i++)
2435  {
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);
2439  }
2440  privObj->_aamp->SetVideoTracks(bitrateList);
2441  LOG_TRACE("Exit");
2442  return JSValueMakeUndefined(ctx);
2443 }
2444 
2445 /**
2446  * @brief API invoked from JS when executing AAMPMediaPlayer.getAvailableAudioTracks()
2447  * @param[in] ctx JS execution context
2448  * @param[in] function JSObject that is the function being called
2449  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2450  * @param[in] argumentCount number of args
2451  * @param[in] arguments[] JSValue array of args
2452  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2453  * @retval JSValue that is the function's return value
2454  */
2455 static JSValueRef AAMPMediaPlayerJS_getAvailableAudioTracks(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2456 {
2457  LOG_TRACE("Enter");
2458  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
2459  if(!privObj || !privObj->_aamp)
2460  {
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);
2464  }
2465  bool allTrack = false;
2466  if (argumentCount == 1)
2467  {
2468  allTrack = JSValueToBoolean(ctx, arguments[0]);
2469  }
2470  std::string tracks = privObj->_aamp->GetAvailableAudioTracks(allTrack);
2471  if (!tracks.empty())
2472  {
2473  LOG_WARN(privObj," _aamp->GetAvailableAudioTracks(%d) tracks=%s", allTrack,tracks.c_str());
2474  return aamp_CStringToJSValue(ctx, tracks.c_str());
2475  }
2476  else
2477  {
2478  LOG_WARN(privObj," _aamp->GetAvailableAudioTracks(%d) tracks=NULL", allTrack);
2479  return JSValueMakeUndefined(ctx);
2480  }
2481 }
2482 
2483 
2484 /**
2485  * @brief API invoked from JS when executing AAMPMediaPlayer.getAvailableTextTracks()
2486  * @param[in] ctx JS execution context
2487  * @param[in] function JSObject that is the function being called
2488  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2489  * @param[in] argumentCount number of args
2490  * @param[in] arguments[] JSValue array of args
2491  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2492  * @retval JSValue that is the function's return value
2493  */
2494 static JSValueRef AAMPMediaPlayerJS_getAvailableTextTracks(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2495 {
2496  LOG_TRACE("Enter");
2497  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
2498  if(!privObj || !privObj->_aamp)
2499  {
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);
2503  }
2504  bool allTrack = false;
2505  if (argumentCount == 1)
2506  {
2507  allTrack = JSValueToBoolean(ctx, arguments[0]);
2508  }
2509  std::string tracks = privObj->_aamp->GetAvailableTextTracks(allTrack);
2510  if (!tracks.empty())
2511  {
2512  LOG_WARN(privObj,"GetAvailableTextTracks(%d) tracks=%s",allTrack,tracks.c_str());
2513  return aamp_CStringToJSValue(ctx, tracks.c_str());
2514  }
2515  else
2516  {
2517  LOG_WARN(privObj,"GetAvailableTextTracks(%d) tracks=NULL",allTrack);
2518  return JSValueMakeUndefined(ctx);
2519  }
2520 }
2521 
2522 
2523 /**
2524  * @brief API invoked from JS when executing AAMPMediaPlayer.getVideoRectangle()
2525  * @param[in] ctx JS execution context
2526  * @param[in] function JSObject that is the function being called
2527  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2528  * @param[in] argumentCount number of args
2529  * @param[in] arguments[] JSValue array of args
2530  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2531  * @retval JSValue that is the function's return value
2532  */
2533 static JSValueRef AAMPMediaPlayerJS_getVideoRectangle(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2534 {
2535  LOG_TRACE("Enter");
2536  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
2537  if(!privObj || !privObj->_aamp)
2538  {
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);
2542  }
2543 
2544  std::string strRect = privObj->_aamp->GetVideoRectangle();
2545  LOG_INFO(privObj," _aamp->GetVideoRectangle() value:%s",(strRect.empty() ? "NULL" : strRect.c_str()));
2546  return aamp_CStringToJSValue(ctx, strRect.c_str());
2547  LOG_TRACE("Exit");
2548 }
2549 
2550 /**
2551  * @brief API invoked from JS when executing AAMPMediaPlayer.setAlternateContent()
2552  * @param[in] ctx JS execution context
2553  * @param[in] function JSObject that is the function being called
2554  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2555  * @param[in] argumentCount number of args
2556  * @param[in] arguments[] JSValue array of args
2557  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2558  * @retval JSValue that is the function's return value
2559  */
2560 static JSValueRef AAMPMediaPlayerJS_setAlternateContent(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2561 {
2562  LOG_TRACE("Enter");
2563  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
2564  if(!privObj || !privObj->_aamp)
2565  {
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);
2569  }
2570 
2571  if (argumentCount == 2)
2572  {
2573  /*
2574  * Parmater format
2575  * "reservationObject": object {
2576  * "reservationId": "773701056",
2577  * "reservationBehavior": number
2578  * "placementRequest": {
2579  * "id": string,
2580  * "pts": number,
2581  * "url": "",
2582  * },
2583  * },
2584  * "promiseCallback": function
2585  */
2586  char *reservationId = NULL;
2587  int reservationBehavior = -1;
2588  char *adId = NULL;
2589  long adPTS = -1;
2590  char *adURL = NULL;
2591  if (JSValueIsObject(ctx, arguments[0]))
2592  {
2593  //Parse the ad object
2594  JSObjectRef reservationObject = JSValueToObject(ctx, arguments[0], NULL);
2595  if (reservationObject == NULL)
2596  {
2597  LOG_ERROR(privObj,"Unable to convert argument to JSObject");
2598  return JSValueMakeUndefined(ctx);
2599  }
2600  JSStringRef propName = JSStringCreateWithUTF8CString("reservationId");
2601  JSValueRef propValue = JSObjectGetProperty(ctx, reservationObject, propName, NULL);
2602  if (JSValueIsString(ctx, propValue))
2603  {
2604  reservationId = aamp_JSValueToCString(ctx, propValue, NULL);
2605  }
2606 
2607  JSStringRelease(propName);
2608  propName = JSStringCreateWithUTF8CString("reservationBehavior");
2609  propValue = JSObjectGetProperty(ctx, reservationObject, propName, NULL);
2610  if (JSValueIsNumber(ctx, propValue))
2611  {
2612  reservationBehavior = JSValueToNumber(ctx, propValue, NULL);
2613  }
2614  JSStringRelease(propName);
2615 
2616  propName = JSStringCreateWithUTF8CString("placementRequest");
2617  propValue = JSObjectGetProperty(ctx, reservationObject, propName, NULL);
2618  if (JSValueIsObject(ctx, propValue))
2619  {
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))
2624  {
2625  adId = aamp_JSValueToCString(ctx, adPropValue, NULL);
2626  }
2627  JSStringRelease(adPropName);
2628  adPropName = JSStringCreateWithUTF8CString("pts");
2629  adPropValue = JSObjectGetProperty(ctx, adObject, adPropName, NULL);
2630  if (JSValueIsNumber(ctx, adPropValue))
2631  {
2632  adPTS = (long) JSValueToNumber(ctx, adPropValue, NULL);
2633  }
2634  JSStringRelease(adPropName);
2635  adPropName = JSStringCreateWithUTF8CString("url");
2636  adPropValue = JSObjectGetProperty(ctx, adObject, adPropName, NULL);
2637  if (JSValueIsString(ctx, adPropValue))
2638  {
2639  adURL = aamp_JSValueToCString(ctx, adPropValue, NULL);
2640  }
2641  JSStringRelease(adPropName);
2642  }
2643  JSStringRelease(propName);
2644  }
2645 
2646  JSObjectRef callbackObj = JSValueToObject(ctx, arguments[1], NULL);
2647  if ((callbackObj) && JSObjectIsFunction(ctx, callbackObj) && adId && reservationId && adURL)
2648  {
2649  std::string adIdStr(adId); //CID:115002 - Resolve Forward null
2650  std::string adBreakId(reservationId); //CID:115001 - Resolve Forward null
2651  std::string url(adURL); //CID:115000 - Resolve Forward null
2652 
2653  privObj->saveCallbackForAdId(adIdStr, callbackObj); //save callback for sending status later, if ad can be played or not
2654  LOG_WARN(privObj,"_aamp->SetAlternateContents(adBreakId=%s,adIdStr=%s,url=%s) with promiseCallback:%p",adBreakId, adIdStr,url,callbackObj);
2655  privObj->_aamp->SetAlternateContents(adBreakId, adIdStr, url);
2656  }
2657  else
2658  {
2659  LOG_ERROR(privObj,"Unable to parse the promiseCallback argument");
2660  }
2661 
2662  SAFE_DELETE_ARRAY(reservationId);
2663  SAFE_DELETE_ARRAY(adURL);
2664  SAFE_DELETE_ARRAY(adId);
2665  }
2666  else
2667  {
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");
2670  }
2671  LOG_TRACE("Exit");
2672  return JSValueMakeUndefined(ctx);
2673 }
2674 
2675 /**
2676  * @brief API invoked from JS when executing AAMPMediaPlayer.setPreferredAudioLanguage()
2677  * @param[in] ctx JS execution context
2678  * @param[in] function JSObject that is the function being called
2679  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2680  * @param[in] argumentCount number of args
2681  * @param[in] arguments[] JSValue array of args
2682  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2683  * @retval JSValue that is the function's return value
2684  */
2685 JSValueRef AAMPMediaPlayerJS_setPreferredAudioLanguage(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
2686 {
2687  LOG_TRACE("Enter");
2688  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
2689  if (!privObj || !privObj->_aamp)
2690  {
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);
2694  }
2695 
2696  if( argumentCount>=1 && argumentCount<=4)
2697  {
2698  char* lanList = aamp_JSValueToCString(ctx,arguments[0], NULL);
2699  char *rendition = NULL;
2700  char *type = NULL;
2701  char *codecList = NULL;
2702  char *labelList=NULL;
2703  if(argumentCount >= 2) {
2704  rendition = aamp_JSValueToCString(ctx,arguments[1], NULL);
2705  }
2706  if(argumentCount >= 3) {
2707  type = aamp_JSValueToCString(ctx,arguments[2], NULL);
2708  }
2709  if(argumentCount >= 4) {
2710  codecList = aamp_JSValueToCString(ctx,arguments[3], NULL);
2711  }
2712  if(argumentCount >= 5) {
2713  labelList = aamp_JSValueToCString(ctx,arguments[4], NULL);
2714  }
2715  LOG_WARN(privObj,"_aamp->SetPrefferedLanguages(%s, %s, %s, %s)", lanList, rendition, type, codecList);
2716  privObj->_aamp->SetPreferredLanguages(lanList, rendition, type, codecList, labelList);
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);
2722  }
2723  else
2724  {
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");
2727  }
2728  LOG_TRACE("Exit");
2729  return JSValueMakeUndefined(ctx);
2730 }
2731 
2732 /**
2733  * @brief API invoked from JS when executing AAMPMediaPlayer.setPreferredAudioLanguage()
2734  * @param[in] ctx JS execution context
2735  * @param[in] function JSObject that is the function being called
2736  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2737  * @param[in] argumentCount number of args
2738  * @param[in] arguments[] JSValue array of args
2739  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2740  * @retval JSValue that is the function's return value
2741  */
2742 JSValueRef AAMPMediaPlayerJS_setPreferredTextLanguage(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
2743 {
2744  LOG_TRACE("Enter");
2745  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
2746  if (!privObj || !privObj->_aamp)
2747  {
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);
2751  }
2752 
2753  if( argumentCount==1)
2754  {
2755  char* parameters = aamp_JSValueToCString(ctx,arguments[0], NULL);
2756  LOG_WARN(privObj," _aamp->SetPreferredTextLanguages %s",parameters);
2757  privObj->_aamp->SetPreferredTextLanguages(parameters);
2758  SAFE_DELETE_ARRAY(parameters);
2759  }
2760  else
2761  {
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");
2764  }
2765  LOG_TRACE("Exit");
2766  return JSValueMakeUndefined(ctx);
2767 }
2768 
2769 /**
2770  * @brief API invoked from JS when executing AAMPMediaPlayer.setPreferredAudioCodec()
2771  * @param[in] ctx JS execution context
2772  * @param[in] function JSObject that is the function being called
2773  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2774  * @param[in] argumentCount number of args
2775  * @param[in] arguments[] JSValue array of args
2776  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2777  * @retval JSValue that is the function's return value
2778  */
2779 JSValueRef AAMPMediaPlayerJS_setPreferredAudioCodec(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
2780 { // placeholder - not ready for use/publishing
2781  LOG_TRACE("Enter");
2782  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
2783  if (!privObj || !privObj->_aamp)
2784  {
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);
2788  }
2789 
2790  if (argumentCount != 1)
2791  {
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");
2794  }
2795  else
2796  {
2797  char *codecList = aamp_JSValueToCString(ctx,arguments[0], NULL);
2798  LOG_WARN(privObj," _aamp->SetPrefferedLanguages(codecList=%s)", codecList);
2799  privObj->_aamp->SetPreferredLanguages(NULL, NULL, NULL, codecList);
2800  SAFE_DELETE_ARRAY(codecList);
2801  }
2802 
2803  LOG_TRACE("Exit");
2804  return JSValueMakeUndefined(ctx);
2805 }
2806 
2807 /**
2808  * @brief API invoked from JS when executing AAMPMediaPlayer.notifyReservationCompletion()
2809  * @param[in] ctx JS execution context
2810  * @param[in] function JSObject that is the function being called
2811  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2812  * @param[in] argumentCount number of args
2813  * @param[in] arguments[] JSValue array of args
2814  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2815  * @retval JSValue that is the function's return value
2816  */
2817 static JSValueRef AAMPMediaPlayerJS_notifyReservationCompletion(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2818 {
2819  LOG_TRACE("Enter");
2820  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
2821  if(!privObj || !privObj->_aamp)
2822  {
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);
2826  }
2827 
2828  if (argumentCount == 2)
2829  {
2830  const char * reservationId = aamp_JSValueToCString(ctx, arguments[0], exception);
2831  long time = (long) JSValueToNumber(ctx, arguments[1], exception);
2832  //Need an API in AAMP to notify that placements for this reservation are over and AAMP might have to trim
2833  //the ads to the period duration or not depending on time param
2834  LOG_WARN(privObj,"Called reservation close for periodId:%s and time:%ld", reservationId, time);
2835  SAFE_DELETE_ARRAY(reservationId);
2836  }
2837  else
2838  {
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");
2841  }
2842  LOG_TRACE("Exit");
2843  return JSValueMakeUndefined(ctx);
2844 }
2845 
2846 
2847 /**
2848  * @brief API invoked from JS when executing AAMPMediaPlayer.setClosedCaptionStatus()
2849  * @param[in] ctx JS execution context
2850  * @param[in] function JSObject that is the function being called
2851  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2852  * @param[in] argumentCount number of args
2853  * @param[in] arguments[] JSValue array of args
2854  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2855  * @retval JSValue that is the function's return value
2856  */
2857 JSValueRef AAMPMediaPlayerJS_setClosedCaptionStatus(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
2858 {
2859  LOG_TRACE("Enter");
2860  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
2861  if (!privObj || !privObj->_aamp)
2862  {
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);
2866  }
2867 
2868  if (argumentCount != 1)
2869  {
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");
2872  }
2873  else
2874  {
2875 
2876  bool enabled = JSValueToBoolean(ctx, arguments[0]);
2877  LOG_WARN(privObj,"_aamp->SetCCStatus(%d)", enabled);
2878  privObj->_aamp->SetCCStatus(enabled);
2879  }
2880  LOG_TRACE("Exit");
2881  return JSValueMakeUndefined(ctx);
2882 }
2883 
2884 
2885 /**
2886  * @brief API invoked from JS when executing AAMPMediaPlayer.setTextStyleOptions()
2887  * @param[in] ctx JS execution context
2888  * @param[in] function JSObject that is the function being called
2889  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2890  * @param[in] argumentCount number of args
2891  * @param[in] arguments[] JSValue array of args
2892  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2893  * @retval JSValue that is the function's return value
2894  */
2895 JSValueRef AAMPMediaPlayerJS_setTextStyleOptions(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
2896 {
2897  LOG_TRACE("Enter");
2898  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
2899  if (!privObj || !privObj->_aamp)
2900  {
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);
2904  }
2905 
2906  if (argumentCount != 1)
2907  {
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");
2910  }
2911  else
2912  {
2913  if (JSValueIsString(ctx, arguments[0]))
2914  {
2915  const char *options = aamp_JSValueToCString(ctx, arguments[0], NULL);
2916  LOG_WARN(privObj," _aamp->SetTextStyle(%s)", options);
2917  privObj->_aamp->SetTextStyle(std::string(options));
2918  SAFE_DELETE_ARRAY(options);
2919  }
2920  else
2921  {
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!");
2924  }
2925  }
2926  LOG_TRACE("Exit");
2927  return JSValueMakeUndefined(ctx);
2928 }
2929 
2930 
2931 /**
2932  * @brief API invoked from JS when executing AAMPMediaPlayer.getTextStyleOptions()
2933  * @param[in] ctx JS execution context
2934  * @param[in] function JSObject that is the function being called
2935  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2936  * @param[in] argumentCount number of args
2937  * @param[in] arguments[] JSValue array of args
2938  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2939  * @retval JSValue that is the function's return value
2940  */
2941 static JSValueRef AAMPMediaPlayerJS_getTextStyleOptions(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2942 {
2943  LOG_TRACE("Enter");
2944  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
2945  if(!privObj || !privObj->_aamp)
2946  {
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);
2950  }
2951  std::string options = privObj->_aamp->GetTextStyle();
2952  if (!options.empty())
2953  {
2954  LOG_INFO(privObj,"_aamp->GetTextStyle() options=%s",options.c_str());
2955  return aamp_CStringToJSValue(ctx, options.c_str());
2956  }
2957  else
2958  {
2959  LOG_WARN(privObj,"_aamp->GetTextStyle() options=NULL");
2960  return JSValueMakeUndefined(ctx);
2961  }
2962 }
2963 
2964 /**
2965  * @brief API invoked from JS when executing AAMPMediaPlayer.disableContentRestrictions()
2966  * @param[in] ctx JS execution context
2967  * @param[in] function JSObject that is the function being called
2968  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2969  * @param[in] argumentCount number of args
2970  * @param[in] arguments[] JSValue array of args
2971  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2972  * @retval JSValue that is the function's return value
2973  */
2974 JSValueRef AAMPMediaPlayerJS_disableContentRestrictions (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
2975 {
2976  LOG_TRACE("Enter");
2977  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
2978  if (!privObj || !privObj->_aamp)
2979  {
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);
2983  }
2984 
2985  long grace = 0;
2986  long time = -1;
2987  bool eventChange=false;
2988  bool updateStatus = false;
2989  if (argumentCount == 1 && JSValueIsObject(ctx, arguments[0]))
2990  {
2991  JSValueRef _exception = NULL;
2992  bool ret = false;
2993  bool valueAsBoolean = false;
2994  double valueAsNumber = 0;
2995 
2996  int numRelockParams = sizeof(relockConditionParamNames)/sizeof(relockConditionParamNames[0]);
2997  JSObjectRef unlockConditionObj = JSValueToObject(ctx, arguments[0], &_exception);
2998  if (unlockConditionObj == NULL || _exception != NULL)
2999  {
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);
3003  }
3004 
3005 
3006  for (int iter = 0; iter < numRelockParams; iter++)
3007  {
3008  ret = false;
3009  switch(relockConditionParamNames[iter].paramType)
3010  {
3011  case ePARAM_RELOCKONTIMEOUT:
3012  ret = ParseJSPropAsNumber(ctx, unlockConditionObj, relockConditionParamNames[iter].paramName, valueAsNumber);
3013  break;
3014  case ePARAM_RELOCKONPROGRAMCHANGE:
3015  ret = ParseJSPropAsBoolean(ctx, unlockConditionObj, relockConditionParamNames[iter].paramName, valueAsBoolean);
3016  break;
3017  default: //ePARAM_MAX_COUNT
3018  ret = false;
3019  break;
3020  }
3021 
3022  if(ret)
3023  {
3024  updateStatus = true;
3025  switch(relockConditionParamNames[iter].paramType)
3026  {
3027  case ePARAM_RELOCKONTIMEOUT:
3028  time = (long) valueAsNumber;
3029  break;
3030  case ePARAM_RELOCKONPROGRAMCHANGE:
3031  eventChange = valueAsBoolean;
3032  break;
3033 
3034  default: //ePARAM_MAX_COUNT
3035  break;
3036  }
3037  }
3038  }
3039  if(updateStatus)
3040  {
3041  privObj->_aamp->DisableContentRestrictions(grace, time, eventChange);
3042  LOG_WARN(privObj,"_aamp->DisableContentRestrictions %ld %ld %d",grace,time,eventChange);
3043  }
3044  }
3045  else if(argumentCount > 1)
3046  {
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");
3049  }
3050  else
3051  {
3052  //No parameter:parental control locking will be disabled until settop reboot, or explicit call to enableContentRestrictions
3053  grace = -1;
3054  LOG_WARN(privObj,"_aamp->DisableContentRestrictions %ld %ld %d",grace,time,eventChange);
3055  privObj->_aamp->DisableContentRestrictions(grace, time, eventChange);
3056  }
3057 
3058  LOG_TRACE("Exit");
3059  return JSValueMakeUndefined(ctx);
3060 }
3061 
3062 
3063 /**
3064  * @brief API invoked from JS when executing AAMPMediaPlayer.enableContentRestrictions()
3065  * @param[in] ctx JS execution context
3066  * @param[in] function JSObject that is the function being called
3067  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3068  * @param[in] argumentCount number of args
3069  * @param[in] arguments[] JSValue array of args
3070  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3071  * @retval JSValue that is the function's return value
3072  */
3073 JSValueRef AAMPMediaPlayerJS_enableContentRestrictions (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
3074 {
3075  LOG_TRACE("Enter");
3076  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
3077  if (!privObj || !privObj->_aamp)
3078  {
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);
3082  }
3083  LOG_WARN(privObj,"_aamp->EnableContentRestrictions()");
3084  privObj->_aamp->EnableContentRestrictions();
3085 
3086  LOG_TRACE("Exit");
3087  return JSValueMakeUndefined(ctx);
3088 }
3089 
3090 /**
3091  * @brief API invoked from JS when executing AAMPMediaPlayer.setAuxiliaryLanguage()
3092  * @param[in] ctx JS execution context
3093  * @param[in] function JSObject that is the function being called
3094  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3095  * @param[in] argumentCount number of args
3096  * @param[in] arguments[] JSValue array of args
3097  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3098  * @retval JSValue that is the function's return value
3099  */
3100 static JSValueRef AAMPMediaPlayerJS_setAuxiliaryLanguage(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3101 {
3102  LOG_TRACE("Enter");
3103  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
3104  if(!privObj || !privObj->_aamp)
3105  {
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);
3109  }
3110 
3111  if (argumentCount == 1)
3112  {
3113  const char *lang = aamp_JSValueToCString(ctx, arguments[0], NULL);
3114  LOG_WARN(privObj,"_aamp->SetAuxiliaryLanguage(%s)",lang);
3115  privObj->_aamp->SetAuxiliaryLanguage(std::string(lang));
3116  SAFE_DELETE_ARRAY(lang);
3117  }
3118  else
3119  {
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");
3122  }
3123  LOG_TRACE("Exit");
3124  return JSValueMakeUndefined(ctx);
3125 }
3126 /**
3127  * @brief API invoked from JS when executing AAMPMediaPlayer.getPlayeBackStats()
3128  * @param[in] ctx JS execution context
3129  * @param[in] function JSObject that is the function being called
3130  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3131  * @param[in] argumentCount number of args
3132  * @param[in] arguments[] JSValue array of args
3133  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3134  * @retval JSValue that is the function's return value
3135  */
3136 static JSValueRef AAMPMediaPlayerJS_getPlayeBackStats(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3137 {
3138  LOG_TRACE("Enter");
3139  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
3140  if(!privObj || !privObj->_aamp)
3141  {
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);
3145  }
3146  LOG_TRACE("Exit");
3147  return aamp_CStringToJSValue(ctx, privObj->_aamp->GetPlaybackStats().c_str());
3148 }
3149 
3150 
3151 /**
3152  * * @brief API invoked from JS when executing AAMPMediaPlayer.xreSupportedTune()
3153  * * @param[in] ctx JS execution context
3154  * * @param[in] function JSObject that is the function being called
3155  * * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3156  * * @param[in] argumentCount number of args
3157  * * @param[in] arguments[] JSValue array of args
3158  * * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3159  * * @retval JSValue that is the function's return value
3160  * */
3161 JSValueRef AAMPMediaPlayerJS_xreSupportedTune(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
3162 {
3163  LOG_TRACE("Enter");
3164  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
3165  if (!privObj)
3166  {
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);
3170  }
3171  if (argumentCount == 1)
3172  {
3173  bool xreSupported = JSValueToBoolean(ctx, arguments[0]);
3174  LOG_WARN(privObj,"_aamp->XRESupportedTune(%d)",xreSupported);
3175  privObj->_aamp->XRESupportedTune(xreSupported);
3176  }
3177  else
3178  {
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");
3181  }
3182  LOG_TRACE("Exit");
3183  return JSValueMakeUndefined(ctx);
3184 }
3185 
3186 /**
3187  * @brief Callback invoked from JS to set update content protection data value on key rotation
3188  *
3189  * @param[in] ctx JS execution context
3190  * @param[in] function JSObject that is the function being called
3191  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3192  * @param[in] argumentCount number of args
3193  * @param[in] arguments[] JSValue array of args
3194  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3195  *
3196  * @retval JSValue that is the function's return value
3197  */
3198 JSValueRef AAMPMediaPlayerJS_setContentProtectionDataConfig(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
3199 {
3200  LOG_TRACE("Enter");
3201  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
3202  if (!privObj)
3203  {
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);
3207  }
3208  if (argumentCount == 1)
3209  {
3210  const char *jsonbuffer = aamp_JSValueToJSONCString(ctx,arguments[0], exception);
3211  LOG_WARN(privObj,"Response json call ProcessContentProtection %s",jsonbuffer);
3212  privObj->_aamp->ProcessContentProtectionDataConfig(jsonbuffer);
3213  SAFE_DELETE_ARRAY(jsonbuffer);
3214  }
3215  else
3216  {
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");
3219  }
3220  LOG_TRACE("Exit");
3221  return JSValueMakeUndefined(ctx);
3222 }
3223 
3224 /**
3225  * @brief Callback invoked from JS to set content protection data update timeout value on key rotation
3226  *
3227  * @param[in] context JS execution context
3228  * @param[in] function JSObject that is the function being called
3229  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3230  * @param[in] argumentCount number of args
3231  * @param[in] arguments[] JSValue array of args
3232  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3233  *
3234  * @retval JSValue that is the function's return value
3235  */
3236 static JSValueRef AAMPMediaPlayerJS_setContentProtectionDataUpdateTimeout(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3237 {
3238  LOG_TRACE("Enter");
3239  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
3240  if (!privObj)
3241  {
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);
3245  }
3246 
3247  if (argumentCount != 1)
3248  {
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");
3251  }
3252  else
3253  {
3254  int contentProtectionDataUpdateTimeout = (int)JSValueToNumber(context, arguments[0], exception);
3255  LOG_WARN(privObj,"aamp->SetContentProtectionDataUpdateTimeout(%d)",contentProtectionDataUpdateTimeout);
3256  privObj->_aamp->SetContentProtectionDataUpdateTimeout(contentProtectionDataUpdateTimeout);
3257  }
3258  LOG_TRACE("Exit");
3259  return JSValueMakeUndefined(context);
3260 }
3261 
3262 /**
3263  * @brief Callback invoked from JS to Enable/Disable Dynamic DRM Config support
3264  *
3265  * @param[in] context JS execution context
3266  * @param[in] function JSObject that is the function being called
3267  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3268  * @param[in] argumentCount number of args
3269  * @param[in] arguments[] JSValue array of args
3270  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3271  *
3272  * @retval JSValue that is the function's return value
3273  */
3274 static JSValueRef AAMPMediaPlayerJS_setRuntimeDRMConfig(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3275 {
3276  LOG_TRACE("Enter");
3277  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
3278  if (!privObj)
3279  {
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);
3283  }
3284  if(argumentCount != 1)
3285  {
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");
3288  }
3289  else
3290  {
3291  bool DynamicDRMSupport = (bool)JSValueToBoolean(context, arguments[0]);
3292  LOG_WARN(privObj,"_aamp->SetRuntimeDRMConfigSupport(%d)",DynamicDRMSupport);
3293  privObj->_aamp->SetRuntimeDRMConfigSupport(DynamicDRMSupport);
3294  }
3295  LOG_TRACE("Exit");
3296  return JSValueMakeUndefined(context);
3297 }
3298 
3299 /**
3300  * @brief Callback invoked from JS to check subtec CC mode is supported or not
3301  *
3302  * @param[in] context JS execution context
3303  * @param[in] function JSObject that is the function being called
3304  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3305  * @param[in] argumentCount number of args
3306  * @param[in] arguments[] JSValue array of args
3307  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3308  *
3309  * @retval JSValue that is the function's return value
3310  */
3311 JSValueRef AAMPMediaPlayerJS_isOOBCCRenderingSupported (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
3312 {
3313  LOG_TRACE("Enter");
3314  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(thisObject);
3315  if(!privObj || !privObj->_aamp)
3316  {
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);
3320  }
3321 
3322  bool bRet = privObj->_aamp->IsOOBCCRenderingSupported();
3323  LOG_INFO(privObj,"<-- returns:%d",bRet);
3324 
3325  LOG_TRACE("Exit");
3326  return JSValueMakeBoolean(ctx, bRet);
3327 }
3328 
3329 /**
3330  * @brief Array containing the AAMPMediaPlayer's statically declared functions
3331  */
3332 static const JSStaticFunction AAMPMediaPlayer_JS_static_functions[] = {
3333  { "load", AAMPMediaPlayerJS_load, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3334  { "initConfig", AAMPMediaPlayerJS_initConfig, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3335  { "play", AAMPMediaPlayerJS_play, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3336  { "detach", AAMPMediaPlayerJS_detach, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3337  { "pause", AAMPMediaPlayerJS_pause, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3338  { "stop", AAMPMediaPlayerJS_stop, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3339  { "seek", AAMPMediaPlayerJS_seek, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3340  { "getCurrentState", AAMPMediaPlayerJS_getCurrentState, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3341  { "getDurationSec", AAMPMediaPlayerJS_getDurationSec, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3342  { "getCurrentPosition", AAMPMediaPlayerJS_getCurrentPosition, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3343  { "getVideoBitrates", AAMPMediaPlayerJS_getVideoBitrates, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3344  { "getAudioBitrates", AAMPMediaPlayerJS_getAudioBitrates, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3345  { "getManifest", AAMPMediaPlayerJS_getManifest, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3346  { "getCurrentVideoBitrate", AAMPMediaPlayerJS_getCurrentVideoBitrate, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3347  { "setVideoBitrate", AAMPMediaPlayerJS_setVideoBitrate, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3348  { "getCurrentAudioBitrate", AAMPMediaPlayerJS_getCurrentAudioBitrate, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3349  { "setAudioBitrate", AAMPMediaPlayerJS_setAudioBitrate, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3350  { "getAudioTrack", AAMPMediaPlayerJS_getAudioTrack, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3351  { "getAudioTrackInfo", AAMPMediaPlayerJS_getAudioTrackInfo, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3352  { "getPreferredAudioProperties", AAMPMediaPlayerJS_getPreferredAudioProperties, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3353  { "getTextTrackInfo", AAMPMediaPlayerJS_getTextTrackInfo, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3354  { "getPreferredTextProperties", AAMPMediaPlayerJS_getPreferredTextProperties, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3355  { "setAudioTrack", AAMPMediaPlayerJS_setAudioTrack, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3356  { "getTextTrack", AAMPMediaPlayerJS_getTextTrack, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3357  { "setTextTrack", AAMPMediaPlayerJS_setTextTrack, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3358  { "getVolume", AAMPMediaPlayerJS_getVolume, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3359  { "setVolume", AAMPMediaPlayerJS_setVolume, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3360  { "setAudioLanguage", AAMPMediaPlayerJS_setAudioLanguage, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3361  { "getPlaybackRate", AAMPMediaPlayerJS_getPlaybackRate, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3362  { "setPlaybackRate", AAMPMediaPlayerJS_setPlaybackRate, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3363  { "getSupportedKeySystems", AAMPMediaPlayerJS_getSupportedKeySystems, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3364  { "setVideoMute", AAMPMediaPlayerJS_setVideoMute, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3365  { "setSubscribedTags", AAMPMediaPlayerJS_setSubscribedTags, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3366  { "subscribeResponseHeaders", AAMPMediaPlayerJS_subscribeResponseHeaders, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3367  { "addEventListener", AAMPMediaPlayerJS_addEventListener, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3368  { "removeEventListener", AAMPMediaPlayerJS_removeEventListener, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3369  { "setDRMConfig", AAMPMediaPlayerJS_setDRMConfig, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3370 
3371  { "addCustomHTTPHeader", AAMPMediaPlayerJS_addCustomHTTPHeader, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
3372  { "removeCustomHTTPHeader", AAMPMediaPlayerJS_removeCustomHTTPHeader, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
3373  { "setVideoRect", AAMPMediaPlayerJS_setVideoRect, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
3374  { "setVideoZoom", AAMPMediaPlayerJS_setVideoZoom, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
3375  { "release", AAMPMediaPlayerJS_release, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
3376  { "getAvailableVideoTracks", AAMPMediaPlayerJS_getAvailableVideoTracks, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3377  { "setVideoTracks", AAMPMediaPlayerJS_setVideoTracks, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3378  { "getAvailableAudioTracks", AAMPMediaPlayerJS_getAvailableAudioTracks, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3379  { "getAvailableTextTracks", AAMPMediaPlayerJS_getAvailableTextTracks, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3380  { "getVideoRectangle", AAMPMediaPlayerJS_getVideoRectangle, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3381  { "setAlternateContent", AAMPMediaPlayerJS_setAlternateContent, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
3382  { "notifyReservationCompletion", AAMPMediaPlayerJS_notifyReservationCompletion, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
3383  { "setClosedCaptionStatus", AAMPMediaPlayerJS_setClosedCaptionStatus, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
3384  { "setTextStyleOptions", AAMPMediaPlayerJS_setTextStyleOptions, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
3385  { "getTextStyleOptions", AAMPMediaPlayerJS_getTextStyleOptions, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
3386  { "disableContentRestrictions", AAMPMediaPlayerJS_disableContentRestrictions, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
3387  { "enableContentRestrictions", AAMPMediaPlayerJS_enableContentRestrictions, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
3388  { "getThumbnail", AAMPMediaPlayerJS_getThumbnails, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
3389  { "getAvailableThumbnailTracks", AAMPMediaPlayerJS_getAvailableThumbnailTracks, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3390  { "setThumbnailTrack", AAMPMediaPlayerJS_setThumbnailTrack, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3391  { "setPreferredAudioLanguage", AAMPMediaPlayerJS_setPreferredAudioLanguage, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3392  { "setPreferredTextLanguage", AAMPMediaPlayerJS_setPreferredTextLanguage, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3393  { "setPreferredAudioCodec", AAMPMediaPlayerJS_setPreferredAudioCodec, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3394  { "setAuxiliaryLanguage", AAMPMediaPlayerJS_setAuxiliaryLanguage, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
3395  { "xreSupportedTune", AAMPMediaPlayerJS_xreSupportedTune, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3396  { "getPlaybackStatistics", AAMPMediaPlayerJS_getPlayeBackStats, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
3397  { "setContentProtectionDataConfig", AAMPMediaPlayerJS_setContentProtectionDataConfig, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
3398  { "setContentProtectionDataUpdateTimeout", AAMPMediaPlayerJS_setContentProtectionDataUpdateTimeout, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
3399  { "configRuntimeDRM", AAMPMediaPlayerJS_setRuntimeDRMConfig, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
3400  { "isOOBCCRenderingSupported", AAMPMediaPlayerJS_isOOBCCRenderingSupported, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
3401  { NULL, NULL, 0 },
3402 };
3403 
3404 
3405 /**
3406  * @brief API invoked from JS when reading value of AAMPMediaPlayer.version
3407  * @param[in] ctx JS execution context
3408  * @param[in] object JSObject to search for the property
3409  * @param[in] propertyName JSString containing the name of the property to get
3410  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3411  * @retval property's value if object has the property, otherwise NULL
3412  */
3413 JSValueRef AAMPMediaPlayerJS_getProperty_Version(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
3414 {
3415  LOG_TRACE("Enter");
3416  AAMPMediaPlayer_JS* privObj = (AAMPMediaPlayer_JS*)JSObjectGetPrivate(object);
3417  if (!privObj || !privObj->_aamp)
3418  {
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);
3422  }
3423  return aamp_CStringToJSValue(ctx, AAMP_UNIFIED_VIDEO_ENGINE_VERSION);
3424 }
3425 
3426 
3427 /**
3428  * @brief Array containing the AAMPMediaPlayer's statically declared value properties
3429  */
3430 static const JSStaticValue AAMPMediaPlayer_JS_static_values[] = {
3431  { "version", AAMPMediaPlayerJS_getProperty_Version, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
3432  { NULL, NULL, NULL, 0 }
3433 };
3434 
3435 
3436 /**
3437  * @brief API invoked from JS when an object of AAMPMediaPlayerJS is destroyed
3438  * @param[in] object JSObject being finalized
3439  */
3440 void AAMPMediaPlayer_JS_finalize(JSObjectRef object)
3441 {
3442  LOG_TRACE("Enter");
3443 
3444  AAMPMediaPlayer_JS *privObj = (AAMPMediaPlayer_JS *) JSObjectGetPrivate(object);
3445  if (privObj != NULL)
3446  {
3447  if (false == findInGlobalCacheAndRelease(privObj))
3448  {
3449  LOG_WARN(privObj,"Invoked finalize of a PlayerInstanceAAMP object(%p) which was already/being released!!", privObj);
3450  }
3451  else
3452  {
3453 
3454  LOG_WARN(privObj,"Cleaned up native object for AAMPMediaPlayer_JS and PlayerInstanceAAMP object(%p)!!",privObj);
3455 
3456  }
3457  //unlink native object from JS object
3458  JSObjectSetPrivate(object, NULL);
3459  // Delete native object
3460  SAFE_DELETE(privObj);
3461  }
3462  else
3463  {
3464  LOG_ERROR(privObj,"Native memory already cleared, since privObj is NULL");
3465 
3466  }
3467 
3468  LOG_TRACE("EXIT");
3469 
3470 }
3471 
3472 
3473 /**
3474  * @brief Object declaration of AAMPMediaPlayer JS object
3475  */
3476 static JSClassDefinition AAMPMediaPlayer_JS_object_def {
3477  0, /* current (and only) version is 0 */
3478  kJSClassAttributeNone,
3479  "__AAMPMediaPlayer",
3480  NULL,
3481 
3484 
3485  NULL,
3487  NULL,
3488  NULL,
3489  NULL,
3490  NULL,
3491  NULL,
3492  NULL,
3493  NULL,
3494  NULL,
3495  NULL
3496 };
3497 
3498 
3499 /**
3500  * @brief Creates a JavaScript class of AAMPMediaPlayer object for use with JSObjectMake
3501  * @retval singleton instance of JavaScript class created
3502  */
3503 static JSClassRef AAMPMediaPlayer_object_ref() {
3504  static JSClassRef _mediaPlayerObjRef = NULL;
3505  if (!_mediaPlayerObjRef) {
3506  _mediaPlayerObjRef = JSClassCreate(&AAMPMediaPlayer_JS_object_def);
3507  }
3508  return _mediaPlayerObjRef;
3509 }
3510 
3511 
3512 /**
3513  * @brief API invoked when AAMPMediaPlayer is used along with 'new'
3514  * @param[in] ctx JS execution context
3515  * @param[in] constructor JSObject that is the constructor being called
3516  * @param[in] argumentCount number of args
3517  * @param[in] arguments[] JSValue array of args
3518  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3519  * @retval JSObject that is the constructor's return value
3520  */
3521 JSObjectRef AAMPMediaPlayer_JS_class_constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
3522 {
3523  LOG_TRACE("Enter");
3524 
3525  std::string appName;
3526  if (argumentCount > 0)
3527  {
3528  if (JSValueIsString(ctx, arguments[0]))
3529  {
3530  char *value = aamp_JSValueToCString(ctx, arguments[0], exception);
3531  appName.assign(value);
3532  LOG_WARN_EX("AAMPMediaPlayer created with app name: %s", appName.c_str());
3533  SAFE_DELETE_ARRAY(value);
3534  }
3535  }
3536 
3537  AAMPMediaPlayer_JS* privObj = new AAMPMediaPlayer_JS();
3538 
3539  privObj->_ctx = JSContextGetGlobalContext(ctx);
3540  privObj->_aamp = new PlayerInstanceAAMP(NULL, NULL);
3541 
3542  if (!appName.empty())
3543  {
3544  LOG_WARN_EX(" _aamp->SetAppName(%s)", appName.c_str());
3545  privObj->_aamp->SetAppName(appName);
3546  }
3547  privObj->_listeners.clear();
3548 
3549  //Get PLAYER ID and store for future use in logging
3550  privObj->iPlayerId = privObj->_aamp->GetId();
3551  //Get jsinfo config for INFO logging
3552  privObj->bInfoEnabled = privObj->_aamp->IsJsInfoLoggingEnabled();
3553 
3554 
3555  // NOTE : Association of JSObject and AAMPMediaPlayer_JS native object will be deleted only in
3556  // AAMPMediaPlayerJS_release ( APP initiated ) or AAMPMediaPlayer_JS_finalize ( GC initiated)
3557  // There is chance that aamp_UnloadJS is called then functions on aamp object is called from JS script.
3558  // In this case AAMPMediaPlayer_JS should be available to access
3559  JSObjectRef newObj = JSObjectMake(ctx, AAMPMediaPlayer_object_ref(), privObj);
3560 
3561  pthread_mutex_lock(&jsMediaPlayerCacheMutex);
3562  AAMPMediaPlayer_JS::_jsMediaPlayerInstances.push_back(privObj);
3563  pthread_mutex_unlock(&jsMediaPlayerCacheMutex);
3564 
3565  // Add a dummy event listener without any function callback.
3566  // Upto JS application to register a common callback function for AAMP to notify ad resolve status
3567  // or individually as part of setAlternateContent call. NULL checks added in eventlistener to avoid undesired behaviour
3569 
3570  // Required for viper-player
3571  JSStringRef fName = JSStringCreateWithUTF8CString("toString");
3572  JSStringRef fString = JSStringCreateWithUTF8CString("return \"[object __AAMPMediaPlayer]\";");
3573  JSObjectRef toStringFunc = JSObjectMakeFunction(ctx, NULL, 0, NULL, fString, NULL, 0, NULL);
3574 
3575  JSObjectSetProperty(ctx, newObj, fName, toStringFunc, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete, NULL);
3576 
3577  JSStringRelease(fName);
3578  JSStringRelease(fString);
3579 
3580  LOG_TRACE("Exit");
3581  return newObj;
3582 }
3583 
3584 
3585 /**
3586  * @brief Class declaration of AAMPMediaPlayer JS object
3587  */
3588 static JSClassDefinition AAMPMediaPlayer_JS_class_def {
3589  0, /* current (and only) version is 0 */
3590  kJSClassAttributeNone,
3591  "__AAMPMediaPlayer__class",
3592  NULL,
3593  NULL,
3594  NULL,
3595  NULL,
3596  NULL,
3597  NULL,
3598  NULL,
3599  NULL,
3600  NULL,
3601  NULL,
3602  NULL,
3604  NULL,
3605  NULL
3606 };
3607 
3608 
3609 /**
3610  * @brief Clear any remaining/active AAMPPlayer instances
3611  */
3613 {
3614  pthread_mutex_lock(&jsMediaPlayerCacheMutex);
3615  LOG_WARN_EX("Number of active jsmediaplayer instances: %d", AAMPMediaPlayer_JS::_jsMediaPlayerInstances.size());
3616  while(AAMPMediaPlayer_JS::_jsMediaPlayerInstances.size() > 0)
3617  {
3618  AAMPMediaPlayer_JS *obj = AAMPMediaPlayer_JS::_jsMediaPlayerInstances.back();
3620  AAMPMediaPlayer_JS::_jsMediaPlayerInstances.pop_back();
3621  }
3622  pthread_mutex_unlock(&jsMediaPlayerCacheMutex);
3623 }
3624 
3625 #ifdef PLATCO
3626 
3627 class XREReceiver_onEventHandler
3628 {
3629 public:
3630  static void handle(JSContextRef ctx, std::string method, size_t argumentCount, const JSValueRef arguments[])
3631  {
3632  if(handlers_map.count(method) != 0)
3633  {
3634  handlers_map.at(method)(ctx, argumentCount, arguments);
3635  }
3636  else
3637  {
3638  LOG_ERROR_EX("[XREReceiver]: no handler for method %s", method.c_str());
3639 
3640  }
3641  }
3642 
3643  static std::string findTextTrackWithLang(JSContextRef ctx, std::string selectedLang)
3644  {
3645  const auto textTracks = AampCCManager::GetInstance()->getLastTextTracks();
3646  LOG_WARN_EX("[XREReceiver]:found %d text tracks", (int)textTracks.size());
3647 
3648  if(!selectedLang.empty() && isdigit(selectedLang[0]))
3649  {
3650  LOG_WARN_EX("[XREReceiver]: trying to parse selected lang as index");
3651 
3652  try
3653  {
3654  //input index starts from 1, not from 0, hence '-1'
3655  int idx = std::stoi(selectedLang)-1;
3656  LOG_WARN_EX("[XREReceiver]:parsed index = %d", idx);
3657 
3658  return textTracks.at(idx).instreamId;
3659  }
3660  catch(const std::exception& e)
3661  {
3662  LOG_WARN_EX("[XREReceiver]:exception during parsing lang selection %s", e.what());
3663 
3664  }
3665  }
3666 
3667  for(const auto& track : textTracks)
3668  {
3669  LOG_WARN_EX("[XREReceiver]:found language '%s', expected '%s'", track.language.c_str(), selectedLang.c_str());
3670 
3671  if(selectedLang == track.language)
3672  {
3673  return track.instreamId;
3674  }
3675  }
3676 
3677  LOG_WARN_EX("[XREReceiver]:cannot find text track matching the selected language, defaulting to 'CC1'");
3678  return "CC1";
3679  }
3680 
3681 private:
3682 
3683  static void handle_onClosedCaptions(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[])
3684  {
3685  LOG_TRACE("[XREReceiver]: Inside Closed Captions");
3686  if(argumentCount != 2)
3687  {
3688  LOG_ERROR_EX("[XREReceiver]: wrong argument count (expected 2) %d", argumentCount);
3689  return;
3690  }
3691 
3692  JSObjectRef argument = JSValueToObject(ctx, arguments[1], NULL);
3693 
3694  JSStringRef param_enable = JSStringCreateWithUTF8CString("enable");
3695  JSStringRef param_setOptions = JSStringCreateWithUTF8CString("setOptions");
3696  JSStringRef param_setTrack = JSStringCreateWithUTF8CString("setTrack");
3697 
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);
3701 
3702  if(JSValueIsBoolean(ctx, param_enable_value))
3703  {
3704  const bool enable_value = JSValueToBoolean(ctx, param_enable_value);
3705  LOG_WARN_EX("[XREReceiver]:received enable boolean %d", enable_value);
3706 
3707 
3708 #ifdef AAMP_CC_ENABLED
3709  AampCCManager::GetInstance()->SetStatus(enable_value);
3710 #endif
3711  if(enable_value)
3712  {
3713  const auto textTracks = AampCCManager::GetInstance()->getLastTextTracks();
3714  std::string defaultTrack;
3715  if(!textTracks.empty())
3716  {
3717  defaultTrack = textTracks.front().instreamId;
3718  }
3719 
3720  if(defaultTrack.empty())
3721  defaultTrack = "CC1";
3722 
3723  LOG_WARN_EX("[XREReceiver]: found %d tracks, selected default textTrack = '%s'", (int)textTracks.size(), defaultTrack.c_str());
3724 
3725 
3726 #ifdef AAMP_CC_ENABLED
3727  AampCCManager::GetInstance()->SetTrack(defaultTrack);
3728 #endif
3729  }
3730  }
3731 
3732  if(JSValueIsObject(ctx, param_setOptions_value))
3733  {
3734  LOG_WARN_EX("[XREReceiver]: received setOptions, ignoring for now");
3735 
3736  }
3737 
3738  if(JSValueIsString(ctx, param_setTrack_value))
3739  {
3740  char* lang = aamp_JSValueToCString(ctx, param_setTrack_value, NULL);
3741  LOG_WARN_EX("[XREReceiver]: received setTrack language: %s", lang);
3742 
3743 
3744  std::string lang_str;
3745  lang_str.assign(lang);
3746  SAFE_DELETE_ARRAY(lang);
3747 
3748  std::string textTrack = findTextTrackWithLang(ctx, lang_str);
3749 
3750  LOG_WARN_EX("[XREReceiver]: selected textTrack = '%s'", textTrack.c_str());
3751 
3752 
3753 #ifdef AAMP_CC_ENABLED
3754  AampCCManager::GetInstance()->SetTrack(textTrack);
3755 #endif
3756 
3757  }
3758 
3759  JSStringRelease(param_enable);
3760  JSStringRelease(param_setOptions);
3761  JSStringRelease(param_setTrack);
3762  }
3763 
3764  using Handler_t = std::function<void(JSContextRef, size_t, const JSValueRef[])>;
3765  static std::unordered_map<std::string, Handler_t> handlers_map;
3766 };
3767 
3768 std::unordered_map<std::string, XREReceiver_onEventHandler::Handler_t> XREReceiver_onEventHandler::handlers_map = {
3769  { std::string{"onClosedCaptions"}, &XREReceiver_onEventHandler::handle_onClosedCaptions}
3770 };
3771 
3772 // temporary patch to avoid JavaScript exception in webapps referencing XREReceiverObject in builds that don't support it
3773 
3774 /**
3775  * @brief API invoked from JS when executing XREReceiver.oneven() method)
3776  * @param[in] ctx JS execution context
3777  * @param[in] function JSObject that is the function being called
3778  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3779  * @param[in] argumentCount number of args
3780  * @param[in] arguments[] JSValue array of args
3781  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3782  * @retval JSValue that is the function's return value
3783  */
3784 JSValueRef XREReceiverJS_onevent (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
3785 {
3786 
3787  LOG_WARN_EX("[XREReceiver]: arg count - %d", argumentCount);
3788 
3789  if (argumentCount > 0)
3790  {
3791  if (JSValueIsString(ctx, arguments[0]))
3792  {
3793  char* value = aamp_JSValueToCString(ctx, arguments[0], exception);
3794  std::string method;
3795  method.assign(value);
3796  XREReceiver_onEventHandler::handle(ctx, method, argumentCount, arguments);
3797 
3798  SAFE_DELETE_ARRAY(value);
3799  }
3800  }
3801  return JSValueMakeUndefined(ctx);
3802 }
3803 
3804 static const JSStaticFunction XREReceiver_JS_static_functions[] =
3805 {
3806  { "onEvent", XREReceiverJS_onevent, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
3807  { NULL, NULL, 0 }
3808 };
3809 
3810 /**
3811  * @brief API invoked when AAMPMediaPlayer is used along with 'new'
3812  * @param[in] ctx JS execution context
3813  * @param[in] constructor JSObject that is the constructor being called
3814  * @param[in] argumentCount number of args
3815  * @param[in] arguments[] JSValue array of args
3816  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3817  * @retval JSObject that is the constructor's return value
3818  */
3819 JSObjectRef XREReceiver_JS_class_constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
3820 {
3821  LOG_TRACE("Enter");
3822  *exception = aamp_GetException(ctx, AAMPJS_GENERIC_ERROR, "Cannot create an object of XREReceiver");
3823  LOG_TRACE("Exit");
3824  return NULL;
3825 }
3826 
3827 static void XREReceiver_JS_finalize(JSObjectRef thisObject)
3828 {
3829 
3830  LOG_TRACE("object=%p", thisObject);
3831 
3832 }
3833 
3834 static JSClassDefinition XREReceiver_JS_class_def {
3835  0, // version
3836  kJSClassAttributeNone, // attributes: JSClassAttributes
3837  "__XREReceiver_class", // className: *const c_char
3838  NULL, // parentClass: JSClassRef
3839  NULL, // staticValues: *const JSStaticValue
3840  XREReceiver_JS_static_functions, // staticFunctions: *const JSStaticFunction
3841  NULL, // initialize: JSObjectInitializeCallback
3842  XREReceiver_JS_finalize, // finalize: JSObjectFinalizeCallback
3843  NULL, // hasProperty: JSObjectHasPropertyCallback
3844  NULL, // getProperty: JSObjectGetPropertyCallback
3845  NULL, // setProperty: JSObjectSetPropertyCallback
3846  NULL, // deleteProperty: JSObjectDeletePropertyCallback
3847  NULL, // getPropertyNames: JSObjectGetPropertyNamesCallback
3848  NULL, // callAsFunction: JSObjectCallAsFunctionCallback
3849  XREReceiver_JS_class_constructor, // callAsConstructor: JSObjectCallAsConstructorCallback,
3850  NULL, // hasInstance: JSObjectHasInstanceCallback
3851  NULL // convertToType: JSObjectConvertToTypeCallback
3852 };
3853 
3854 void LoadXREReceiverStub(void* context)
3855 {
3856 
3857  LOG_TRACE(" context = %p", context);
3858 
3859  JSGlobalContextRef jsContext = (JSGlobalContextRef)context;
3860 
3861  JSClassRef myClass = JSClassCreate(&XREReceiver_JS_class_def);
3862  JSObjectRef classObj = JSObjectMake(jsContext, myClass, NULL);
3863  JSObjectRef globalObj = JSContextGetGlobalObject(jsContext);
3864 
3865  JSStringRef str = JSStringCreateWithUTF8CString("XREReceiver");
3866  JSObjectSetProperty(jsContext, globalObj, str, classObj, kJSPropertyAttributeReadOnly, NULL);
3867 
3868  LOG_TRACE("Exit");
3869 }
3870 #endif // PLATCO
3871 
3872 
3873 /**
3874  * @brief Loads AAMPMediaPlayer JS constructor into JS context
3875  * @param[in] context JS execution context
3876  */
3877 void AAMPPlayer_LoadJS(void* context)
3878 {
3879  LOG_TRACE("Enter");
3880  LOG_WARN_EX("context = %p", context);
3881  JSGlobalContextRef jsContext = (JSGlobalContextRef)context;
3882 
3883  JSObjectRef globalObj = JSContextGetGlobalObject(jsContext);
3884 
3885  JSClassRef mediaPlayerClass = JSClassCreate(&AAMPMediaPlayer_JS_class_def);
3886  JSObjectRef classObj = JSObjectMakeConstructor(jsContext, mediaPlayerClass, AAMPMediaPlayer_JS_class_constructor);
3887  JSValueProtect(jsContext, classObj);
3888 
3889  JSStringRef str = JSStringCreateWithUTF8CString("AAMPMediaPlayer");
3890  JSObjectSetProperty(jsContext, globalObj, str, classObj, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, NULL);
3891 
3892  JSClassRelease(mediaPlayerClass);
3893  JSStringRelease(str);
3894 
3895 #ifdef PLATCO
3896  LoadXREReceiverStub(context);
3897 #endif
3898 
3899  LOG_TRACE("Exit");
3900 }
3901 
3902 /**
3903  * @brief Removes the AAMPMediaPlayer constructor from JS context
3904  * @param[in] context JS execution context
3905  */
3906 void AAMPPlayer_UnloadJS(void* context)
3907 {
3908 
3909  LOG_WARN_EX("context=%p", context);
3910 
3911  JSValueRef exception = NULL;
3912  JSGlobalContextRef jsContext = (JSGlobalContextRef)context;
3913 
3914  //Clear all active js mediaplayer instances and its resources
3916 
3917  JSObjectRef globalObj = JSContextGetGlobalObject(jsContext);
3918  JSStringRef str = JSStringCreateWithUTF8CString("AAMPMediaPlayer");
3919 
3920  JSValueRef playerConstructor = JSObjectGetProperty(jsContext, globalObj, str, &exception);
3921 
3922  if (playerConstructor == NULL || exception != NULL)
3923  {
3924  JSStringRelease(str);
3925  return;
3926  }
3927 
3928  JSObjectRef playerObj = JSValueToObject(jsContext, playerConstructor, &exception);
3929  if (playerObj == NULL || exception != NULL)
3930  {
3931  JSStringRelease(str);
3932  return;
3933  }
3934 
3935  if (!JSObjectIsConstructor(jsContext, playerObj))
3936  {
3937  JSStringRelease(str);
3938  return;
3939  }
3940 
3941  JSValueUnprotect(jsContext, playerConstructor);
3942  JSObjectSetProperty(jsContext, globalObj, str, JSValueMakeUndefined(jsContext), kJSPropertyAttributeReadOnly, NULL);
3943  JSStringRelease(str);
3944 
3945  // Force a garbage collection to clean-up all AAMP objects.
3946  LOG_WARN_EX("JSGarbageCollect() context=%p", context);
3947  JSGarbageCollect(jsContext);
3948  LOG_TRACE("Exit");
3949 }
AAMPMediaPlayer_JS_static_functions
static const JSStaticFunction AAMPMediaPlayer_JS_static_functions[]
Array containing the AAMPMediaPlayer's statically declared functions.
Definition: jsmediaplayer.cpp:3332
ThunderAccess.h
shim for dispatching UVE HDMI input playback
AampCCManagerBase::getLastTextTracks
const std::vector< TextTrackInfo > & getLastTextTracks() const
Get list of text tracks.
Definition: AampCCManager.h:159
ConfigParamMap
Data structure to map ConfigParamType and its string equivalent.
Definition: jsmediaplayer.cpp:164
PlayerInstanceAAMP::GetVideoBitrate
long GetVideoBitrate(void)
To get the bitrate of current video profile.
Definition: main_aamp.cpp:1787
AAMPMediaPlayerJS_getAudioTrackInfo
JSValueRef AAMPMediaPlayerJS_getAudioTrackInfo(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getAudioTrackInfo()
Definition: jsmediaplayer.cpp:888
PlayerInstanceAAMP::GetVideoRectangle
std::string GetVideoRectangle()
Get the video window co-ordinates.
Definition: main_aamp.cpp:2470
AAMPMediaPlayerJS_setVolume
JSValueRef AAMPMediaPlayerJS_setVolume(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.setVolume()
Definition: jsmediaplayer.cpp:1692
eDRM_WideVine
@ eDRM_WideVine
Definition: AampDrmSystems.h:36
AAMPMediaPlayer_JS::getCallbackForAdId
JSObjectRef getCallbackForAdId(std::string id) override
Get promise callback for an ad id.
Definition: jsmediaplayer.cpp:76
AAMPMediaPlayerJS_getPreferredTextProperties
JSValueRef AAMPMediaPlayerJS_getPreferredTextProperties(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getPreferredTextProperties()
Definition: jsmediaplayer.cpp:992
PlayerInstanceAAMP::GetPlaybackPosition
double GetPlaybackPosition(void)
To get the current playback position.
Definition: main_aamp.cpp:1729
AAMPMediaPlayerJS_setSubscribedTags
JSValueRef AAMPMediaPlayerJS_setSubscribedTags(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.setSubscribedTags()
Definition: jsmediaplayer.cpp:1917
AAMPMediaPlayerJS_getPreferredAudioProperties
JSValueRef AAMPMediaPlayerJS_getPreferredAudioProperties(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getPreferredAudioProperties()
Definition: jsmediaplayer.cpp:957
VIDEO_ZOOM_FULL
@ VIDEO_ZOOM_FULL
Definition: main_aamp.h:131
AAMPMediaPlayer_object_ref
static JSClassRef AAMPMediaPlayer_object_ref()
Creates a JavaScript class of AAMPMediaPlayer object for use with JSObjectMake.
Definition: jsmediaplayer.cpp:3503
AAMPMediaPlayerJS_getDurationSec
JSValueRef AAMPMediaPlayerJS_getDurationSec(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getDurationSec()
Definition: jsmediaplayer.cpp:1096
AAMPMediaPlayerJS_disableContentRestrictions
JSValueRef AAMPMediaPlayerJS_disableContentRestrictions(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.disableContentRestrictions()
Definition: jsmediaplayer.cpp:2974
eDRM_PlayReady
@ eDRM_PlayReady
Definition: AampDrmSystems.h:37
aamp_GetException
JSValueRef aamp_GetException(JSContextRef context, ErrorCode error, const char *additionalInfo)
Generate a JSValue object with the exception details.
Definition: jsutils.cpp:278
AampCCManagerBase::SetTrack
int SetTrack(const std::string &track, const CCFormat format=eCLOSEDCAPTION_FORMAT_DEFAULT)
Set CC track.
Definition: AampCCManager.cpp:651
PlayerInstanceAAMP::EnableContentRestrictions
void EnableContentRestrictions()
Enable Content Restrictions - lock.
Definition: main_aamp.cpp:2751
PlayerInstanceAAMP::GetTextTrackInfo
std::string GetTextTrackInfo()
Get current audio track index.
Definition: main_aamp.cpp:2448
aampPlayer_getEventTypeFromName
AAMPEventType aampPlayer_getEventTypeFromName(const char *szName)
Convert JS event name to AAMP event type (AAMPMediaPlayer)
Definition: jsutils.cpp:356
PlayerInstanceAAMP::SetThumbnailTrack
bool SetThumbnailTrack(int thumbIndex)
To set a preferred bitrate for thumbnail profile.
Definition: main_aamp.cpp:2687
eDRM_ClearKey
@ eDRM_ClearKey
Definition: AampDrmSystems.h:41
PlayerInstanceAAMP::SetVideoZoom
void SetVideoZoom(VideoZoomMode zoom)
Set video zoom.
Definition: main_aamp.cpp:1282
AAMPMediaPlayer_JS::removeCallbackForAdId
void removeCallbackForAdId(std::string id) override
Get promise callback for an ad id.
Definition: jsmediaplayer.cpp:97
VIDEO_ZOOM_NONE
@ VIDEO_ZOOM_NONE
Definition: main_aamp.h:132
relockConditionParamNames
static ConfigParamMap relockConditionParamNames[]
Map relockConditionParamNames and its string equivalent.
Definition: jsmediaplayer.cpp:173
AAMPMediaPlayerJS_setDRMConfig
JSValueRef AAMPMediaPlayerJS_setDRMConfig(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.setDRMConfig()
Definition: jsmediaplayer.cpp:2113
AAMPMediaPlayerJS_getPlaybackRate
JSValueRef AAMPMediaPlayerJS_getPlaybackRate(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getPlaybackRate()
Definition: jsmediaplayer.cpp:1782
AAMPMediaPlayerJS_setVideoBitrate
JSValueRef AAMPMediaPlayerJS_setVideoBitrate(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.setVideoBitrate()
Definition: jsmediaplayer.cpp:1309
releaseNativeResources
static void releaseNativeResources(AAMPMediaPlayer_JS *privObj)
API to release internal resources of an AAMPMediaPlayerJS object NOTE that this function does NOT fre...
Definition: jsmediaplayer.cpp:310
AAMPMediaPlayerJS_getThumbnails
JSValueRef AAMPMediaPlayerJS_getThumbnails(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.GetThumbnails()
Definition: jsmediaplayer.cpp:793
PlayerInstanceAAMP::InitAAMPConfig
bool InitAAMPConfig(char *jsonStr)
InitAAMPConfig - Initialize the media player session with json config.
Definition: main_aamp.cpp:2885
ParseJSPropAsNumber
bool ParseJSPropAsNumber(JSContextRef ctx, JSObjectRef jsObject, const char *prop, double &value)
Helper function to parse a JS property value as number.
Definition: jsmediaplayer.cpp:196
PlayerInstanceAAMP::SetContentProtectionDataUpdateTimeout
void SetContentProtectionDataUpdateTimeout(int timeout)
To set default timeout for Dynamic ContentProtectionDataUpdate on Key Rotation.
Definition: main_aamp.cpp:3163
AAMPMediaPlayerJS_setAlternateContent
static JSValueRef AAMPMediaPlayerJS_setAlternateContent(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.setAlternateContent()
Definition: jsmediaplayer.cpp:2560
AAMPMediaPlayerJS_seek
JSValueRef AAMPMediaPlayerJS_seek(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.seek()
Definition: jsmediaplayer.cpp:754
AAMPMediaPlayerJS_getAvailableThumbnailTracks
JSValueRef AAMPMediaPlayerJS_getAvailableThumbnailTracks(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getAvailableThumbnailTracks()
Definition: jsmediaplayer.cpp:851
AAMPMediaPlayerJS_removeCustomHTTPHeader
JSValueRef AAMPMediaPlayerJS_removeCustomHTTPHeader(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.removeCustomHTTPHeader()
Definition: jsmediaplayer.cpp:2219
AAMPMediaPlayerJS_setClosedCaptionStatus
JSValueRef AAMPMediaPlayerJS_setClosedCaptionStatus(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.setClosedCaptionStatus()
Definition: jsmediaplayer.cpp:2857
PlayerInstanceAAMP::GetPlaybackRate
int GetPlaybackRate(void)
To get the current playback rate.
Definition: main_aamp.cpp:1884
AAMPMediaPlayerJS_getProperty_Version
JSValueRef AAMPMediaPlayerJS_getProperty_Version(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception)
API invoked from JS when reading value of AAMPMediaPlayer.version.
Definition: jsmediaplayer.cpp:3413
AampCCManagerBase::SetStatus
int SetStatus(bool enable)
Enable/disable CC rendering.
Definition: AampCCManager.cpp:755
AAMPMediaPlayerJS_subscribeResponseHeaders
JSValueRef AAMPMediaPlayerJS_subscribeResponseHeaders(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.subscribeResponseHeaders()
Definition: jsmediaplayer.cpp:1959
AAMPMediaPlayerJS_stop
JSValueRef AAMPMediaPlayerJS_stop(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.stop()
Definition: jsmediaplayer.cpp:727
AAMPMediaPlayer_JS::AAMPMediaPlayer_JS
AAMPMediaPlayer_JS()
Constructor of AAMPMediaPlayer_JS structure.
Definition: jsmediaplayer.cpp:61
PlayerInstanceAAMP::GetAudioTrack
int GetAudioTrack()
Get current audio track index.
Definition: main_aamp.cpp:2556
PrivAAMPStruct_JS
Private data structure for JS binding object.
Definition: jsbindings.h:35
PlayerInstanceAAMP::SetLicenseCustomData
void SetLicenseCustomData(const char *customData)
Set License Custom Data.
Definition: main_aamp.cpp:3007
PlayerInstanceAAMP::SetVideoRectangle
void SetVideoRectangle(int x, int y, int w, int h)
Set video rectangle.
Definition: main_aamp.cpp:1270
PlayerInstanceAAMP::SubscribeResponseHeaders
void SubscribeResponseHeaders(std::vector< std::string > responseHeaders)
Subscribe array of http response headers.
Definition: main_aamp.cpp:1430
AAMPPlayer_UnloadJS
void AAMPPlayer_UnloadJS(void *context)
Removes the AAMPMediaPlayer constructor from JS context.
Definition: jsmediaplayer.cpp:3906
AAMPMediaPlayerJS_getCurrentState
JSValueRef AAMPMediaPlayerJS_getCurrentState(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getCurrentState()
Definition: jsmediaplayer.cpp:1070
AAMPMediaPlayerJS_getVolume
JSValueRef AAMPMediaPlayerJS_getVolume(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getVolume()
Definition: jsmediaplayer.cpp:1665
AAMPMediaPlayer_JS
Private data structure of AAMPMediaPlayer JS object.
Definition: jsmediaplayer.cpp:56
AAMPMediaPlayerJS_play
JSValueRef AAMPMediaPlayerJS_play(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.play()
Definition: jsmediaplayer.cpp:628
PlayerInstanceAAMP::GetPlaybackStats
std::string GetPlaybackStats()
Get playback statistics formated for partner apps.
Definition: main_aamp.cpp:3016
PlayerInstanceAAMP::XRESupportedTune
void XRESupportedTune(bool xreSupported)
To set whether the JS playback session is from XRE or not.
Definition: main_aamp.cpp:2935
jsutils.h
JavaScript util functions for AAMP.
PlayerInstanceAAMP::GetAvailableVideoTracks
std::string GetAvailableVideoTracks()
Get available video tracks.
Definition: main_aamp.cpp:2410
PlayerInstanceAAMP::SetAlternateContents
void SetAlternateContents(const std::string &adBreakId, const std::string &adId, const std::string &url)
Setting the alternate contents' (Ads/blackouts) URL.
Definition: main_aamp.cpp:2106
AAMPMediaPlayer_JS::saveCallbackForAdId
void saveCallbackForAdId(std::string id, JSObjectRef cbObject)
Save promise callback for an ad id.
Definition: jsmediaplayer.cpp:116
PlayerInstanceAAMP::SetVideoTracks
void SetVideoTracks(std::vector< long > bitrates)
Set video tracks.
Definition: main_aamp.cpp:2420
aamp_ApplyPageHttpHeaders
void aamp_ApplyPageHttpHeaders(PlayerInstanceAAMP *)
applies the parsed custom http headers into the aamp
Definition: jscontroller-jsbindings.cpp:511
PlayerInstanceAAMP::SetTextTrack
void SetTextTrack(int trackId, char *ccData=NULL)
Set text track.
Definition: main_aamp.cpp:2566
AAMPMediaPlayerJS_setPreferredAudioLanguage
JSValueRef AAMPMediaPlayerJS_setPreferredAudioLanguage(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.setPreferredAudioLanguage()
Definition: jsmediaplayer.cpp:2685
PlayerInstanceAAMP::GetAvailableAudioTracks
std::string GetAvailableAudioTracks(bool allTrack=false)
Get available audio tracks.
Definition: main_aamp.cpp:2428
PlayerInstanceAAMP::GetVideoBitrates
std::vector< long > GetVideoBitrates(void)
To get the available video bitrates.
Definition: main_aamp.cpp:1893
PlayerInstanceAAMP::SetLanguage
void SetLanguage(const char *language)
Set Audio language.
Definition: main_aamp.cpp:1389
VideoZoomMode
VideoZoomMode
Video zoom mode.
Definition: main_aamp.h:129
PlayerInstanceAAMP::SetRuntimeDRMConfigSupport
void SetRuntimeDRMConfigSupport(bool DynamicDRMSupported)
To set Dynamic DRM feature by Application.
Definition: main_aamp.cpp:3173
ClearAAMPPlayerInstances
void ClearAAMPPlayerInstances(void)
Clear any remaining/active AAMPPlayer instances.
Definition: jsmediaplayer.cpp:3612
AAMPMediaPlayerJS_getAvailableAudioTracks
static JSValueRef AAMPMediaPlayerJS_getAvailableAudioTracks(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getAvailableAudioTracks()
Definition: jsmediaplayer.cpp:2455
AAMPMediaPlayer_JS::clearCallbackForAllAdIds
void clearCallbackForAllAdIds()
Clear all saved promise callbacks.
Definition: jsmediaplayer.cpp:135
aamp_StringArrayToCStringArray
std::vector< std::string > aamp_StringArrayToCStringArray(JSContextRef context, JSValueRef arrayRef)
Convert an array of JSString to an array of C strings.
Definition: jsutils.cpp:213
AAMPMediaPlayerJS_setAudioLanguage
JSValueRef AAMPMediaPlayerJS_setAudioLanguage(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.setAudioLanguage()
Definition: jsmediaplayer.cpp:1743
AAMPMediaPlayerJS_setRuntimeDRMConfig
static JSValueRef AAMPMediaPlayerJS_setRuntimeDRMConfig(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to Enable/Disable Dynamic DRM Config support.
Definition: jsmediaplayer.cpp:3274
AAMPMediaPlayerJS_getSupportedKeySystems
JSValueRef AAMPMediaPlayerJS_getSupportedKeySystems(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getSupportedKeySystems()
Definition: jsmediaplayer.cpp:1852
ParseJSPropAsBoolean
bool ParseJSPropAsBoolean(JSContextRef ctx, JSObjectRef jsObject, const char *prop, bool &value)
Helper function to parse a JS property value as boolean.
Definition: jsmediaplayer.cpp:284
PlayerInstanceAAMP::Seek
void Seek(double secondsRelativeToTuneTime, bool keepPaused=false)
Seek to a time.
Definition: main_aamp.cpp:971
AAMPMediaPlayerJS_release
JSValueRef AAMPMediaPlayerJS_release(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.release()
Definition: jsmediaplayer.cpp:2347
PlayerInstanceAAMP::SetCCStatus
void SetCCStatus(bool enabled)
Set CC visibility on/off.
Definition: main_aamp.cpp:2620
AAMP_JSEventListener::RemoveEventListener
static void RemoveEventListener(PrivAAMPStruct_JS *obj, AAMPEventType type, JSObjectRef jsCallback)
Removes a JS listener for a particular event.
Definition: jseventlistener.cpp:1688
AAMPMediaPlayer_JS_class_constructor
JSObjectRef AAMPMediaPlayer_JS_class_constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked when AAMPMediaPlayer is used along with 'new'.
Definition: jsmediaplayer.cpp:3521
PlayerInstanceAAMP::SetAuxiliaryLanguage
void SetAuxiliaryLanguage(const std::string &language)
Set auxiliary language.
Definition: main_aamp.cpp:2944
PlayerInstanceAAMP::PauseAt
void PauseAt(double position)
Set PauseAt position.
Definition: main_aamp.cpp:837
AAMPMediaPlayerJS_getManifest
JSValueRef AAMPMediaPlayerJS_getManifest(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getManifest()
Definition: jsmediaplayer.cpp:1205
JSContextGetGlobalContext
JS_EXPORT JSGlobalContextRef JSContextGetGlobalContext(JSContextRef)
Get the global JS execution context.
jsMediaPlayerCacheMutex
static pthread_mutex_t jsMediaPlayerCacheMutex
Mutex for global cache of AAMPMediaPlayer_JS instances.
Definition: jsmediaplayer.cpp:185
PlayerInstanceAAMP::GetPreferredTextProperties
std::string GetPreferredTextProperties()
Get preferred text prioperties.
Definition: main_aamp.cpp:2355
PlayerInstanceAAMP
Player interface class for the JS pluggin.
Definition: main_aamp.h:692
findInGlobalCacheAndRelease
static bool findInGlobalCacheAndRelease(AAMPMediaPlayer_JS *privObj)
API to check if AAMPMediaPlayer_JS object present in cache and release it.
Definition: jsmediaplayer.cpp:340
PlayerInstanceAAMP::GetAudioTrackInfo
std::string GetAudioTrackInfo()
Get current audio track index.
Definition: main_aamp.cpp:2438
AAMPMediaPlayer_JS_object_def
static JSClassDefinition AAMPMediaPlayer_JS_object_def
Object declaration of AAMPMediaPlayer JS object.
Definition: jsmediaplayer.cpp:3476
AAMP_EVENT_AD_RESOLVED
@ AAMP_EVENT_AD_RESOLVED
Definition: AampEvent.h:74
AAMPMediaPlayerJS_getAvailableTextTracks
static JSValueRef AAMPMediaPlayerJS_getAvailableTextTracks(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getAvailableTextTracks()
Definition: jsmediaplayer.cpp:2494
AAMPMediaPlayerJS_setVideoMute
JSValueRef AAMPMediaPlayerJS_setVideoMute(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.setVideoMute()
Definition: jsmediaplayer.cpp:1878
PlayerInstanceAAMP::IsJsInfoLoggingEnabled
bool IsJsInfoLoggingEnabled()
Get jsinfo config value (default false)
Definition: main_aamp.cpp:1514
AAMPMediaPlayer_JS_static_values
static const JSStaticValue AAMPMediaPlayer_JS_static_values[]
Array containing the AAMPMediaPlayer's statically declared value properties.
Definition: jsmediaplayer.cpp:3430
AAMPMediaPlayerJS_setAudioTrack
JSValueRef AAMPMediaPlayerJS_setAudioTrack(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.setAudioTrack()
Definition: jsmediaplayer.cpp:1452
PlayerInstanceAAMP::SetAudioVolume
void SetAudioVolume(int volume)
Set Audio Volume.
Definition: main_aamp.cpp:1361
AAMPMediaPlayerJS_getCurrentPosition
JSValueRef AAMPMediaPlayerJS_getCurrentPosition(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getCurrentPosition()
Definition: jsmediaplayer.cpp:1129
LOG_WARN_EX
#define LOG_WARN_EX(FORMAT,...)
Definition: jsutils.h:44
parseDRMConfiguration
void parseDRMConfiguration(JSContextRef ctx, AAMPMediaPlayer_JS *privObj, JSValueRef drmConfigParam)
Helper function to parse DRM config params received from JS.
Definition: jsmediaplayer.cpp:376
AAMPMediaPlayer_JS_finalize
void AAMPMediaPlayer_JS_finalize(JSObjectRef object)
API invoked from JS when an object of AAMPMediaPlayerJS is destroyed.
Definition: jsmediaplayer.cpp:3440
AAMPMediaPlayerJS_getVideoRectangle
static JSValueRef AAMPMediaPlayerJS_getVideoRectangle(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getVideoRectangle()
Definition: jsmediaplayer.cpp:2533
PlayerInstanceAAMP::detach
void detach()
Soft stop the player instance.
Definition: main_aamp.cpp:385
jseventlistener.h
Event Listner impl for AAMPMediaPlayer_JS object.
PlayerInstanceAAMP::GetPreferredAudioProperties
std::string GetPreferredAudioProperties()
Get preferred audio prioperties.
Definition: main_aamp.cpp:2345
AAMPMediaPlayerJS_setPreferredAudioCodec
JSValueRef AAMPMediaPlayerJS_setPreferredAudioCodec(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.setPreferredAudioCodec()
Definition: jsmediaplayer.cpp:2779
PlayerInstanceAAMP::ProcessContentProtectionDataConfig
void ProcessContentProtectionDataConfig(const char *jsonbuffer)
Definition: main_aamp.cpp:3026
ParseJSPropAsObject
bool ParseJSPropAsObject(JSContextRef ctx, JSObjectRef jsObject, const char *prop, JSValueRef &value)
Helper function to parse a JS property value as object.
Definition: jsmediaplayer.cpp:255
AAMPMediaPlayerJS_getCurrentAudioBitrate
JSValueRef AAMPMediaPlayerJS_getCurrentAudioBitrate(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getCurrentAudioBitrate()
Definition: jsmediaplayer.cpp:1355
AAMP_JSEventListener::RemoveAllEventListener
static void RemoveAllEventListener(PrivAAMPStruct_JS *obj)
Remove all JS listeners registered.
Definition: jseventlistener.cpp:1721
aamp_JSValueToCString
char * aamp_JSValueToCString(JSContextRef context, JSValueRef value, JSValueRef *exception)
Convert JSString to C string.
Definition: jsutils.cpp:164
AAMPMediaPlayerJS_removeEventListener
JSValueRef AAMPMediaPlayerJS_removeEventListener(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.removeEventListener()
Definition: jsmediaplayer.cpp:2057
PlayerInstanceAAMP::GetState
PrivAAMPState GetState(void)
To get the current AAMP state.
Definition: main_aamp.cpp:1765
PlayerInstanceAAMP::SetRate
void SetRate(float rate, int overshootcorrection=0)
Set playback rate.
Definition: main_aamp.cpp:561
PlayerInstanceAAMP::SetPreferredTextLanguages
void SetPreferredTextLanguages(const char *param)
Set optional preferred language list.
Definition: main_aamp.cpp:2371
AAMPMediaPlayerJS_setContentProtectionDataUpdateTimeout
static JSValueRef AAMPMediaPlayerJS_setContentProtectionDataUpdateTimeout(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set content protection data update timeout value on key rotation.
Definition: jsmediaplayer.cpp:3236
AAMPMediaPlayerJS_setTextStyleOptions
JSValueRef AAMPMediaPlayerJS_setTextStyleOptions(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.setTextStyleOptions()
Definition: jsmediaplayer.cpp:2895
PlayerInstanceAAMP::Tune
void Tune(const char *mainManifestUrl, const char *contentType, bool bFirstAttempt, bool bFinalAttempt, const char *traceUUID, bool audioDecoderStreamSync)
Tune to a URL. DEPRECATED! This is included for backwards compatibility with current Sky AS integrati...
Definition: main_aamp.cpp:312
PlayerInstanceAAMP::SetPreferredLanguages
void SetPreferredLanguages(const char *languageList, const char *preferredRendition=NULL, const char *preferredType=NULL, const char *codecList=NULL, const char *labelList=NULL)
Set optional preferred language list.
Definition: main_aamp.cpp:2363
AAMPMediaPlayerJS_setContentProtectionDataConfig
JSValueRef AAMPMediaPlayerJS_setContentProtectionDataConfig(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set update content protection data value on key rotation.
Definition: jsmediaplayer.cpp:3198
PlayerInstanceAAMP::GetThumbnails
std::string GetThumbnails(double sduration, double eduration)
To get preferred thumbnails for the duration.
Definition: main_aamp.cpp:2703
PlayerInstanceAAMP::SetAudioBitrate
void SetAudioBitrate(long bitrate)
To set a preferred bitrate for audio profile.
Definition: main_aamp.cpp:1844
AAMPMediaPlayerJS_setPlaybackRate
JSValueRef AAMPMediaPlayerJS_setPlaybackRate(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.setPlaybackRate()
Definition: jsmediaplayer.cpp:1808
AAMPMediaPlayer_JS_class_def
static JSClassDefinition AAMPMediaPlayer_JS_class_def
Class declaration of AAMPMediaPlayer JS object.
Definition: jsmediaplayer.cpp:3588
AAMPMediaPlayerJS_notifyReservationCompletion
static JSValueRef AAMPMediaPlayerJS_notifyReservationCompletion(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.notifyReservationCompletion()
Definition: jsmediaplayer.cpp:2817
PlayerInstanceAAMP::GetPlaybackDuration
double GetPlaybackDuration(void)
To get the current asset's duration.
Definition: main_aamp.cpp:1738
PlayerInstanceAAMP::GetTextTrack
int GetTextTrack()
Get current text track index.
Definition: main_aamp.cpp:2610
PlayerInstanceAAMP::SetPreferredDRM
void SetPreferredDRM(DRMSystems drmType)
Set Preferred DRM.
Definition: main_aamp.cpp:2027
PlayerInstanceAAMP::GetAudioBitrate
long GetAudioBitrate(void)
To get the bitrate of current audio profile.
Definition: main_aamp.cpp:1826
AAMPMediaPlayerJS_getCurrentVideoBitrate
JSValueRef AAMPMediaPlayerJS_getCurrentVideoBitrate(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getCurrentVideoBitrate()
Definition: jsmediaplayer.cpp:1283
PlayerInstanceAAMP::GetAvailableTextTracks
std::string GetAvailableTextTracks(bool allTrack=false)
Get available text tracks.
Definition: main_aamp.cpp:2460
AAMPMediaPlayerJS_getTextStyleOptions
static JSValueRef AAMPMediaPlayerJS_getTextStyleOptions(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getTextStyleOptions()
Definition: jsmediaplayer.cpp:2941
PlayerInstanceAAMP::GetAudioBitrates
std::vector< long > GetAudioBitrates(void)
To get the available audio bitrates.
Definition: main_aamp.cpp:1935
AAMPMediaPlayerJS_xreSupportedTune
JSValueRef AAMPMediaPlayerJS_xreSupportedTune(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.xreSupportedTune()
Definition: jsmediaplayer.cpp:3161
AAMPPlayer_LoadJS
void AAMPPlayer_LoadJS(void *context)
Loads AAMPMediaPlayer JS constructor into JS context.
Definition: jsmediaplayer.cpp:3877
AAMPMediaPlayerJS_load
JSValueRef AAMPMediaPlayerJS_load(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.load()
Definition: jsmediaplayer.cpp:460
AAMPMediaPlayerJS_getVideoBitrates
JSValueRef AAMPMediaPlayerJS_getVideoBitrates(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getVideoBitrates()
Definition: jsmediaplayer.cpp:1162
LOG_INFO
#define LOG_INFO(AAMP_JS_OBJECT, FORMAT,...)
Definition: jsutils.h:39
AAMPMediaPlayerJS_setTextTrack
JSValueRef AAMPMediaPlayerJS_setTextTrack(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.setTextTrack()
Definition: jsmediaplayer.cpp:1612
AAMPMediaPlayerJS_setThumbnailTrack
JSValueRef AAMPMediaPlayerJS_setThumbnailTrack(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.setThumbnailTrack()
Definition: jsmediaplayer.cpp:1026
AAMPEventType
AAMPEventType
Type of the events sending to the JSPP player.
Definition: AampEvent.h:44
AAMPMediaPlayerJS_setPreferredTextLanguage
JSValueRef AAMPMediaPlayerJS_setPreferredTextLanguage(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.setPreferredAudioLanguage()
Definition: jsmediaplayer.cpp:2742
AAMPMediaPlayerJS_initConfig
JSValueRef AAMPMediaPlayerJS_initConfig(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.initConfig()
Definition: jsmediaplayer.cpp:560
PlayerInstanceAAMP::GetManifest
std::string GetManifest(void)
To get the available manifest.
Definition: main_aamp.cpp:1911
AampCCManager::GetInstance
static AampCCManagerBase * GetInstance()
Get the singleton instance.
Definition: AampCCManager.cpp:799
PlayerInstanceAAMP::SetAudioTrack
void SetAudioTrack(std::string language="", std::string rendition="", std::string type="", std::string codec="", unsigned int channel=0, std::string label="")
Set audio track.
Definition: main_aamp.cpp:2282
aamp_CStringToJSValue
JSValueRef aamp_CStringToJSValue(JSContextRef context, const char *sz)
Convert C string to JSString.
Definition: jsutils.cpp:152
AAMP_JSEventListener::AddEventListener
static void AddEventListener(PrivAAMPStruct_JS *obj, AAMPEventType type, JSObjectRef jsCallback)
Adds a JS function as listener for a particular event.
Definition: jseventlistener.cpp:1571
PlayerInstanceAAMP::GetAvailableThumbnailTracks
std::string GetAvailableThumbnailTracks(void)
To get the available bitrates for thumbnails.
Definition: main_aamp.cpp:2678
PlayerInstanceAAMP::SetAppName
void SetAppName(std::string name)
Set the application name which has created PlayerInstanceAAMP, for logging purposes.
Definition: main_aamp.cpp:2480
PlayerInstanceAAMP::SetLicenseServerURL
void SetLicenseServerURL(const char *url, DRMSystems type=eDRM_MAX_DRMSystems)
Set License Server URL.
Definition: main_aamp.cpp:1590
PlayerInstanceAAMP::DisableContentRestrictions
void DisableContentRestrictions(long grace, long time, bool eventChange)
Disable Content Restrictions - unlock.
Definition: main_aamp.cpp:2742
PlayerInstanceAAMP::Stop
void Stop(bool sendStateChangeEvent=true)
Stop playback and release resources.
Definition: main_aamp.cpp:282
PlayerInstanceAAMP::IsOOBCCRenderingSupported
bool IsOOBCCRenderingSupported()
Definition: main_aamp.cpp:3183
AAMPMediaPlayerJS_setVideoTracks
JSValueRef AAMPMediaPlayerJS_setVideoTracks(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.setvideoTrack()
Definition: jsmediaplayer.cpp:2423
AAMPMediaPlayerJS_setAuxiliaryLanguage
static JSValueRef AAMPMediaPlayerJS_setAuxiliaryLanguage(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.setAuxiliaryLanguage()
Definition: jsmediaplayer.cpp:3100
AAMPMediaPlayerJS_addCustomHTTPHeader
JSValueRef AAMPMediaPlayerJS_addCustomHTTPHeader(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.addCustomHTTPHeader()
Definition: jsmediaplayer.cpp:2151
PlayerInstanceAAMP::GetId
int GetId(void)
Definition: main_aamp.cpp:1750
AAMPMediaPlayerJS_getAvailableVideoTracks
static JSValueRef AAMPMediaPlayerJS_getAvailableVideoTracks(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getAvailableVideoTracks()
Definition: jsmediaplayer.cpp:2390
PlayerInstanceAAMP::SetVideoBitrate
void SetVideoBitrate(long bitrate)
To set a preferred bitrate for video profile.
Definition: main_aamp.cpp:1805
AAMPMediaPlayerJS_getPlayeBackStats
static JSValueRef AAMPMediaPlayerJS_getPlayeBackStats(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getPlayeBackStats()
Definition: jsmediaplayer.cpp:3136
ParseJSPropAsString
bool ParseJSPropAsString(JSContextRef ctx, JSObjectRef jsObject, const char *prop, char *&value)
Helper function to parse a JS property value as string.
Definition: jsmediaplayer.cpp:226
PlayerInstanceAAMP::SetTextStyle
void SetTextStyle(const std::string &options)
Set style options for text track rendering.
Definition: main_aamp.cpp:2638
AAMPMediaPlayerJS_setVideoZoom
JSValueRef AAMPMediaPlayerJS_setVideoZoom(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.setVideoZoom()
Definition: jsmediaplayer.cpp:2300
Module.h
Declaration of module name aamp.
AAMPMediaPlayerJS_getTextTrackInfo
JSValueRef AAMPMediaPlayerJS_getTextTrackInfo(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getTextTrackInfo()
Definition: jsmediaplayer.cpp:923
aamp_JSValueToJSONCString
char * aamp_JSValueToJSONCString(JSContextRef context, JSValueRef value, JSValueRef *exception)
Convert JSString to JSON C string.
Definition: jsutils.cpp:177
PlayerInstanceAAMP::GetTextStyle
std::string GetTextStyle()
Get style options for text track rendering.
Definition: main_aamp.cpp:2648
PlayerInstanceAAMP::GetAudioVolume
int GetAudioVolume(void)
To get the current audio volume.
Definition: main_aamp.cpp:1870
PlayerInstanceAAMP::SetSubscribedTags
void SetSubscribedTags(std::vector< std::string > subscribedTags)
Set array of subscribed tags.
Definition: main_aamp.cpp:1415
PlayerInstanceAAMP::AddCustomHTTPHeader
void AddCustomHTTPHeader(std::string headerName, std::vector< std::string > headerValue, bool isLicenseHeader=false)
Add/Remove a custom HTTP header and value.
Definition: main_aamp.cpp:1579
AAMPMediaPlayerJS_getAudioBitrates
JSValueRef AAMPMediaPlayerJS_getAudioBitrates(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getAudioBitrates()
Definition: jsmediaplayer.cpp:1238
AampCCManager.h
Integration layer of ClosedCaption in AAMP.
PlayerInstanceAAMP::SetVideoMute
void SetVideoMute(bool muted)
Enable/ Disable Video.
Definition: main_aamp.cpp:1303
aamp_JSValueIsArray
bool aamp_JSValueIsArray(JSContextRef context, JSValueRef value)
Check if a JSValue object is array or not.
Definition: jsutils.cpp:190
AAMPMediaPlayerJS_isOOBCCRenderingSupported
JSValueRef AAMPMediaPlayerJS_isOOBCCRenderingSupported(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to check subtec CC mode is supported or not.
Definition: jsmediaplayer.cpp:3311
AAMPMediaPlayerJS_getTextTrack
JSValueRef AAMPMediaPlayerJS_getTextTrack(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getTextTrack()
Definition: jsmediaplayer.cpp:1586
AAMPMediaPlayerJS_enableContentRestrictions
JSValueRef AAMPMediaPlayerJS_enableContentRestrictions(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.enableContentRestrictions()
Definition: jsmediaplayer.cpp:3073
AAMPMediaPlayerJS_setAudioBitrate
JSValueRef AAMPMediaPlayerJS_setAudioBitrate(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.setAudioBitrate()
Definition: jsmediaplayer.cpp:1381
AAMPMediaPlayerJS_pause
JSValueRef AAMPMediaPlayerJS_pause(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.pause()
Definition: jsmediaplayer.cpp:683
LOG_TRACE
#define LOG_TRACE
Definition: rdk_debug_priv.c:83
AAMPMediaPlayerJS_getAudioTrack
JSValueRef AAMPMediaPlayerJS_getAudioTrack(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.getAudioTrack()
Definition: jsmediaplayer.cpp:1426
AAMPMediaPlayerJS_setVideoRect
JSValueRef AAMPMediaPlayerJS_setVideoRect(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.setVideoRect()
Definition: jsmediaplayer.cpp:2258
AAMPMediaPlayerJS_detach
JSValueRef AAMPMediaPlayerJS_detach(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.detach()
Definition: jsmediaplayer.cpp:656
AAMPMediaPlayerJS_addEventListener
JSValueRef AAMPMediaPlayerJS_addEventListener(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
API invoked from JS when executing AAMPMediaPlayer.addEventListener()
Definition: jsmediaplayer.cpp:2001