RDK Documentation (Open Sourced RDK Components)
jsbindings.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 jsbindings.cpp
22  * @brief JavaScript bindings for AAMP
23  */
24 
25 
26 #include <JavaScriptCore/JavaScript.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include <pthread.h>
31 
32 #include "jsbindings-version.h"
33 #include "jsutils.h"
34 #include "main_aamp.h"
35 #include "priv_aamp.h"
36 
37 #ifdef AAMP_CC_ENABLED
38 #include "AampCCManager.h"
39 #endif
40 
41 static class PlayerInstanceAAMP* _allocated_aamp = NULL;
42 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
43 
44 extern void ClearAAMPPlayerInstances();
45 
46 extern "C"
47 {
48 
49  /**
50  * @brief Get the global JS execution context
51  * @param[in] JSContextRef JS execution context
52  * @retval global execution context
53  */
54  JS_EXPORT JSGlobalContextRef JSContextGetGlobalContext(JSContextRef);
55 
56  JSObjectRef AAMP_JS_AddEventTypeClass(JSGlobalContextRef context);
58 }
59 
60 /**
61  * @struct AAMP_JS
62  * @brief Data structure of AAMP object
63  */
64 struct AAMP_JS
65 {
66  JSGlobalContextRef _ctx;
67  class PlayerInstanceAAMP* _aamp;
68  class AAMP_JSListener* _listeners;
69  int iPlayerId; /*An int variable iPlayerID to store Playerid */
70  bool bInfoEnabled; /*A bool variable bInfoEnabled for INFO logging check*/
71  JSObjectRef _eventType;
72  JSObjectRef _subscribedTags;
73  JSObjectRef _promiseCallback; /* Callback function for JS promise resolve/reject.*/
74 };
75 
76 
77 /**
78  * @brief callback invoked when AAMP is used along with 'new'
79  * @param[in] context JS execution context
80  * @param[in] constructor JSObject that is the constructor being called
81  * @param[in] argumentCount number of args
82  * @param[in] arguments[] JSValue array of args
83  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
84  * @retval JSObject that is the constructor's return value
85  */
86 static JSObjectRef AAMP_class_constructor(JSContextRef context, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
87 {
88  *exception = aamp_GetException(context, AAMPJS_GENERIC_ERROR, "Cannot create an object of AAMP");
89  return NULL;
90 }
91 
92 
93 /**
94  * @brief Callback invoked from JS to get the closedCaptionEnabled property value
95  * @param[in] context JS execution context
96  * @param[in] thisObject JSObject to search for the property
97  * @param[in] propertyName JSString containing the name of the property to get
98  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
99  * @retval property's value if object has the property, otherwise NULL
100  */
101 static JSValueRef AAMP_getProperty_closedCaptionEnabled(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
102 {
103 
104  LOG_TRACE("Enter");
105  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
106  if (pAAMP == NULL)
107  {
108  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
109  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.closedCaptionEnabled on instances of AAMP");
110  return JSValueMakeUndefined(context);
111  }
112  return JSValueMakeUndefined(context);
113 }
114 
115 
116 /**
117  * @brief Callback invoked from JS to set the closedCaptionEnabled property value
118  * @param[in] context JS exception context
119  * @param[in] thisObject JSObject on which to set the property's value
120  * @param[in] propertyName JSString containing the name of the property to set
121  * @param[in] value JSValue to use as the property's value
122  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
123  * @retval true if the property was set, otherwise false
124  */
125 static bool AAMP_setProperty_closedCaptionEnabled(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
126 {
127  LOG_TRACE("Enter");
128  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
129  if (pAAMP == NULL)
130  {
131  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
132  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.closedCaptionEnabled on instances of AAMP");
133  return false;
134  }
135  return true;
136 }
137 
138 
139 /**
140  * @brief Callback invoked from JS to get the initialBufferTime property value
141  * @param[in] context JS execution context
142  * @param[in] thisObject JSObject to search for the property
143  * @param[in] propertyName JSString containing the name of the property to get
144  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
145  * @retval property's value if object has the property, otherwise NULL
146  */
147 static JSValueRef AAMP_getProperty_initialBufferTime(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
148 {
149 
150  LOG_TRACE("Enter");
151  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
152  if (pAAMP == NULL)
153  {
154  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
155  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.initialBufferTime on instances of AAMP");
156  return JSValueMakeUndefined(context);
157  }
158  return JSValueMakeUndefined(context);
159 }
160 
161 
162 /**
163  * @brief Callback invoked from JS to set the initialBufferTime property value
164  * @param[in] context JS exception context
165  * @param[in] thisObject JSObject on which to set the property's value
166  * @param[in] propertyName JSString containing the name of the property to set
167  * @param[in] value JSValue to use as the property's value
168  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
169  * @retval true if the property was set, otherwise false
170  */
171 static bool AAMP_setProperty_initialBufferTime(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
172 {
173  LOG_TRACE("Enter");
174  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
175  if (pAAMP == NULL)
176  {
177  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
178  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.initialBufferTime on instances of AAMP");
179  return false;
180  }
181  return true;
182 }
183 
184 
185 /**
186  * @brief Callback invoked from JS to get the trickPlayEnabled property value
187  * @param[in] context JS execution context
188  * @param[in] thisObject JSObject to search for the property
189  * @param[in] propertyName JSString containing the name of the property to get
190  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
191  * @retval property's value if object has the property, otherwise NULL
192  */
193 static JSValueRef AAMP_getProperty_trickPlayEnabled(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
194 {
195  LOG_TRACE("Enter");
196  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
197  if (pAAMP == NULL)
198  {
199  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
200  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.trickPlayEnabled on instances of AAMP");
201  return JSValueMakeUndefined(context);
202  }
203  return JSValueMakeUndefined(context);
204 }
205 
206 
207 /**
208  * @brief Callback invoked from JS to set the trickPlayEnabled property value
209  * @param[in] context JS exception context
210  * @param[in] thisObject JSObject on which to set the property's value
211  * @param[in] propertyName JSString containing the name of the property to set
212  * @param[in] value JSValue to use as the property's value
213  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
214  * @retval true if the property was set, otherwise false
215  */
216 static bool AAMP_setProperty_trickPlayEnabled(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
217 {
218 
219  LOG_TRACE("Enter");
220  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
221  if (pAAMP == NULL)
222  {
223  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
224  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.trickPlayEnabled on instances of AAMP");
225  return false;
226  }
227  return true;
228 }
229 
230 
231 /**
232  * @brief Callback invoked from JS to get the EventType property value
233  * @param[in] context JS execution context
234  * @param[in] thisObject JSObject to search for the property
235  * @param[in] propertyName JSString containing the name of the property to get
236  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
237  * @retval property's value if object has the property, otherwise NULL
238  */
239 static JSValueRef AAMP_getProperty_EventType(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
240 {
241  LOG_TRACE("Enter");
242  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
243  if (pAAMP == NULL)
244  {
245  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
246  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.EventType on instances of AAMP");
247  return JSValueMakeUndefined(context);
248  }
249  return pAAMP->_eventType;
250 }
251 
252 
253 /**
254  * @brief Callback invoked from JS to get the mediaType property value
255  * @param[in] context JS execution context
256  * @param[in] thisObject JSObject to search for the property
257  * @param[in] propertyName JSString containing the name of the property to get
258  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
259  * @retval property's value if object has the property, otherwise NULL
260  */
261 static JSValueRef AAMP_getProperty_MediaType(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
262 {
263  LOG_TRACE("Enter");
264  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
265  if (pAAMP == NULL)
266  {
267  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
268  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.mediaType on instances of AAMP");
269  return JSValueMakeUndefined(context);
270  }
271 
272  if (pAAMP->_aamp->IsLive())
273  {
274  return aamp_CStringToJSValue(context, "live");
275  }
276  else
277  {
278  return aamp_CStringToJSValue(context, "vod");
279  }
280 }
281 
282 
283 /**
284  * @brief Callback invoked from JS to get the version property value
285  * @param[in] context JS execution context
286  * @param[in] thisObject JSObject to search for the property
287  * @param[in] propertyName JSString containing the name of the property to get
288  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
289  * @retval property's value if object has the property, otherwise NULL
290  */
291 static JSValueRef AAMP_getProperty_Version(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
292 {
293  LOG_TRACE("Enter");
294  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
295  if (pAAMP == NULL)
296  {
297  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
298  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.version on instances of AAMP");
299  return JSValueMakeUndefined(context);
300  }
301 
302  return aamp_CStringToJSValue(context, AAMP_UNIFIED_VIDEO_ENGINE_VERSION);
303 }
304 
305 
306 /**
307  * @brief Callback invoked from JS to get the audioLanguage property value
308  * @param[in] context JS execution context
309  * @param[in] thisObject JSObject to search for the property
310  * @param[in] propertyName JSString containing the name of the property to get
311  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
312  * @retval property's value if object has the property, otherwise NULL
313  */
314 static JSValueRef AAMP_getProperty_AudioLanguage(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
315 {
316  LOG_TRACE("Enter");
317  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
318  if (pAAMP == NULL)
319  {
320  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
321  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.audioLanguage on instances of AAMP");
322  return JSValueMakeUndefined(context);
323  }
324 
325  const char* language = pAAMP->_aamp->GetCurrentAudioLanguage();
326  LOG_INFO(pAAMP,"_aamp->GetCurrentAudioLanguage() %s",language);
327  return aamp_CStringToJSValue(context, language);
328 }
329 
330 /**
331  * @brief Callback invoked from JS to get the currentDRM property value
332  * @param[in] context JS execution context
333  * @param[in] thisObject JSObject to search for the property
334  * @param[in] propertyName JSString containing the name of the property to get
335  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
336  * @retval property's value if object has the property, otherwise NULL
337  */
338 static JSValueRef AAMP_getProperty_CurrentDRM(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
339 {
340  LOG_TRACE("Enter");
341  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
342  if (pAAMP == NULL)
343  {
344  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
345  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.currentDRM on instances of AAMP");
346  return JSValueMakeUndefined(context);
347  }
348 
349  const char* drm = pAAMP->_aamp->GetCurrentDRM();
350  LOG_INFO(pAAMP,"_aamp->GetCurrentDRM() %s",drm);
351  return aamp_CStringToJSValue(context, drm);
352 }
353 
354 
355 /**
356  * @brief Callback invoked from JS to get the timedMetadata property value
357  * @param[in] context JS execution context
358  * @param[in] thisObject JSObject to search for the property
359  * @param[in] propertyName JSString containing the name of the property to get
360  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
361  * @retval property's value if object has the property, otherwise NULL
362  */
363 static JSValueRef AAMP_getProperty_timedMetadata(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
364 {
365  LOG_TRACE("Enter");
366  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
367  if (pAAMP == NULL)
368  {
369  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
370  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.timedMetadata on instances of AAMP");
371  return JSValueMakeUndefined(context);
372  }
373 
374  PrivateInstanceAAMP* privAAMP = (pAAMP->_aamp != NULL) ? pAAMP->_aamp->aamp : NULL;
375  if (privAAMP == NULL)
376  {
377  LOG_ERROR_EX("privAAMP not initialized");
378  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "AAMP.timedMetadata - initialization error");
379  return JSValueMakeUndefined(context);
380  }
381 
382  int32_t length = privAAMP->timedMetadata.size();
383 
384  JSValueRef* array = new JSValueRef[length];
385  for (int32_t i = 0; i < length; i++)
386  {
387  TimedMetadata item = privAAMP->timedMetadata.at(i);
388  JSObjectRef ref = aamp_CreateTimedMetadataJSObject(context, item._timeMS, item._name.c_str(), item._content.c_str(), item._id.c_str(), item._durationMS);
389  array[i] = ref;
390  }
391 
392  JSValueRef prop = JSObjectMakeArray(context, length, array, NULL);
393  SAFE_DELETE_ARRAY(array);
394 
395  return prop;
396 }
397 
398 
399 /**
400  * @brief Callback invoked from JS to set the stallErrorCode property value
401  * @param[in] context JS exception context
402  * @param[in] thisObject JSObject on which to set the property's value
403  * @param[in] propertyName JSString containing the name of the property to set
404  * @param[in] value JSValue to use as the property's value
405  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
406  * @retval true if the property was set, otherwise false
407  */
408 static bool AAMP_setProperty_stallErrorCode(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
409 {
410  LOG_TRACE("Enter");
411  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
412  if (pAAMP == NULL)
413  {
414  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
415  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.stallErrorCode on instances of AAMP");
416  return false;
417  }
418  LOG_WARN(pAAMP,"_aamp->SetStallErrorCode context=%p value=%d exception=%p ",context, value, exception);
419  pAAMP->_aamp->SetStallErrorCode(JSValueToNumber(context, value, exception));
420  return true;
421 }
422 
423 
424 /**
425  * @brief Callback invoked from JS to set the stallTimeout property value
426  * @param[in] context JS exception context
427  * @param[in] thisObject JSObject on which to set the property's value
428  * @param[in] propertyName JSString containing the name of the property to set
429  * @param[in] value JSValue to use as the property's value
430  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
431  * @retval true if the property was set, otherwise false
432  */
433 static bool AAMP_setProperty_stallTimeout(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
434 {
435  LOG_TRACE("Enter");
436  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
437  if (pAAMP == NULL)
438  {
439  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
440  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.stallTimeout on instances of AAMP");
441  return false;
442  }
443  LOG_WARN(pAAMP,"_aamp->SetStallTimeout context=%p value=%d exception=%p",context, value, exception);
444  pAAMP->_aamp->SetStallTimeout(JSValueToNumber(context, value, exception));
445  return true;
446 }
447 
448 
449 /**
450  * @brief Callback invoked from JS to set the reportInterval property value
451  * @param[in] context JS exception context
452  * @param[in] thisObject JSObject on which to set the property's value
453  * @param[in] propertyName JSString containing the name of the property to set
454  * @param[in] value JSValue to use as the property's value
455  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
456  * @retval true if the property was set, otherwise false
457  */
458 static bool AAMP_setProperty_reportInterval(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
459 {
460  LOG_TRACE("Enter");
461  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
462  if (pAAMP == NULL)
463  {
464  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
465  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.reportInterval on instances of AAMP");
466  return false;
467  }
468  LOG_WARN(pAAMP,"_aamp->SetReportInterval context=%p value=%d exception=%p ",context, value, exception);
469  pAAMP->_aamp->SetReportInterval(JSValueToNumber(context, value, exception));
470  return true;
471 }
472 
473 /**
474  * @brief Callback invoked from JS to set the enableNativeCC property value
475  * @param[in] context JS exception context
476  * @param[in] thisObject JSObject on which to set the property's value
477  * @param[in] propertyName JSString containing the name of the property to set
478  * @param[in] value JSValue to use as the property's value
479  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
480  * @retval true if the property was set, otherwise false
481  */
482 static bool AAMP_setProperty_enableNativeCC(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
483 {
484  LOG_TRACE("Enter");
485  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
486  if (pAAMP == NULL)
487  {
488  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
489  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.reportInterval on instances of AAMP");
490  return false;
491  }
492  LOG_WARN(pAAMP,"_aamp->SetNativeCCRendering context=%p value=%d ",context, value);
493  pAAMP->_aamp->SetNativeCCRendering(JSValueToBoolean(context, value));
494  return true;
495 }
496 
497 /**
498  * @brief Callback invoked from JS to set the preferred CEA format property value
499  * @param[in] context JS exception context
500  * @param[in] thisObject JSObject on which to set the property's value
501  * @param[in] propertyName JSString containing the name of the property to set
502  * @param[in] value JSValue to use as the property's value
503  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
504  * @retval true if the property was set, otherwise false
505  */
506 static bool AAMP_setProperty_preferredCEAFormat(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
507 {
508  LOG_TRACE("Enter");
509  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
510  if (pAAMP == NULL)
511  {
512  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
513  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.reportInterval on instances of AAMP");
514  return false;
515  }
516  LOG_WARN(pAAMP,"_aamp->SetCEAFormat context=%p value=%d exception=%p ",context, value, exception);
517  pAAMP->_aamp->SetCEAFormat((int)JSValueToNumber(context, value, exception));
518  return true;
519 }
520 
521 /**
522  * @brief Array containing the AAMP's statically declared value properties
523  */
524 static const JSStaticValue AAMP_static_values[] =
525 {
526  {"closedCaptionEnabled", AAMP_getProperty_closedCaptionEnabled, AAMP_setProperty_closedCaptionEnabled, kJSPropertyAttributeDontDelete },
527  {"initialBufferTime", AAMP_getProperty_initialBufferTime, AAMP_setProperty_initialBufferTime, kJSPropertyAttributeDontDelete },
528  {"trickPlayEnabled", AAMP_getProperty_trickPlayEnabled, AAMP_setProperty_trickPlayEnabled, kJSPropertyAttributeDontDelete },
529  {"EventType", AAMP_getProperty_EventType, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
530  {"mediaType", AAMP_getProperty_MediaType, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
531  {"version", AAMP_getProperty_Version, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
532  {"audioLanguage", AAMP_getProperty_AudioLanguage, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
533  {"currentDRM", AAMP_getProperty_CurrentDRM, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
534  {"timedMetadata", AAMP_getProperty_timedMetadata, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
535  {"stallErrorCode", NULL, AAMP_setProperty_stallErrorCode, kJSPropertyAttributeDontDelete },
536  {"stallTimeout", NULL, AAMP_setProperty_stallTimeout, kJSPropertyAttributeDontDelete },
537  {"reportInterval", NULL, AAMP_setProperty_reportInterval, kJSPropertyAttributeDontDelete },
538  {"enableNativeCC", NULL, AAMP_setProperty_enableNativeCC, kJSPropertyAttributeDontDelete },
539  {"preferredCEAFormat", NULL, AAMP_setProperty_preferredCEAFormat, kJSPropertyAttributeDontDelete },
540  {NULL, NULL, NULL, 0}
541 };
542 
543 /**
544  * @brief Array containing the Event's statically declared functions
545  */
546 static const JSStaticFunction Event_staticfunctions[] =
547 {
548  { NULL, NULL, 0 }
549 };
550 
551 
552 /**
553  * @brief Callback invoked from JS when an object of Event is first created
554  * @param[in] ctx JS execution context
555  * @param[in] thisObject JSObject being created
556  */
557 static void Event_init(JSContextRef ctx, JSObjectRef thisObject)
558 {
559  //LOG_TRACE("Enter");
560 }
561 
562 
563 /**
564  * @brief Callback invoked when an object of Event is finalized
565  * @param[in] thisObject JSObject being finalized
566  */
567 static void Event_finalize(JSObjectRef thisObject)
568 {
569  //noisy - large (>400) burst of logging seen during garbage collection
570  //LOG_TRACE("Enter");
571 
572  const AAMPEvent* pEvent = (const AAMPEvent*)JSObjectGetPrivate(thisObject);
573  JSObjectSetPrivate(thisObject, NULL);
574 }
575 
576 
577 static JSClassRef Event_class_ref();
578 
579 
580 /**
581  * @brief callback invoked when Event is used along with 'new'
582  * @param[in] ctx JS execution context
583  * @param[in] constructor JSObject that is the constructor being called
584  * @param[in] argumentCount number of args
585  * @param[in] arguments[] JSValue array of args
586  * @param[out] execption pointer to a JSValueRef in which to return an exception, if any
587  * @retval JSObject that is the constructor's return value
588  */
589 static JSObjectRef Event_constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* execption)
590 {
591  //LOG_TRACE("Enter");
592  return JSObjectMake(ctx, Event_class_ref(), NULL);
593 }
594 
595 
596 /**
597  * @brief Structure contains properties and callbacks of Event object
598  */
599 static const JSClassDefinition Event_object_def =
600 {
601  0,
602  kJSClassAttributeNone,
603  "__Event__AAMP",
604  NULL,
605  NULL,
607  Event_init,
609  NULL,
610  NULL,
611  NULL,
612  NULL,
613  NULL,
614  NULL,
616  NULL,
617  NULL
618 };
619 
620 
621 /**
622  * @brief Creates a JavaScript class of Event for use with JSObjectMake
623  * @retval singleton instance of JavaScript class created
624  */
625 static JSClassRef Event_class_ref() {
626  static JSClassRef _classRef = NULL;
627  if (!_classRef) {
628  _classRef = JSClassCreate(&Event_object_def);
629  }
630  return _classRef;
631 }
632 
633 /**
634  * @class AAMP_JSListener
635  * @brief Event listener impl for AAMP events
636  */
638 {
639 public:
640 
641  static void AddEventListener(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback);
642 
643  static void RemoveEventListener(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback);
644 
645  /**
646  * @brief AAMP_JSListener Constructor
647  * @param[in] aamp instance of AAMP_JS
648  * @param[in] type event type
649  * @param[in] jsCallback callback to be registered as listener
650  */
651  AAMP_JSListener(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback)
652  : _aamp(aamp)
653  , _type(type)
654  , _jsCallback(jsCallback)
655  , _pNext(NULL)
656  {
657  LOG_TRACE("ctx=%p, type=%d, jsCallback=%p", _aamp->_ctx, _type, _jsCallback);
658  JSValueProtect(_aamp->_ctx, _jsCallback);
659  }
660 
661 
662  /**
663  * @brief AAMP_JSListener Destructor
664  */
666  {
667  LOG_TRACE("ctx=%p, type=%d, jsCallback=%p", _aamp->_ctx, _type, _jsCallback);
668  JSValueUnprotect(_aamp->_ctx, _jsCallback);
669  }
670 
671  /**
672  * @brief AAMP_JSListener Copy Constructor
673  */
674  AAMP_JSListener(const AAMP_JSListener&) = delete;
675 
676  /**
677  * @brief AAMP_JSListener Assignment operator overloading
678  */
679  AAMP_JSListener& operator=(const AAMP_JSListener&) = delete;
680 
681  /**
682  * @brief Dispatch JS event for the corresponding AAMP event
683  * @param[in] e AAMP event object
684  */
685  void Event(const AAMPEventPtr &e)
686  {
687  AAMPEventType evtType = e->getType();
688  if(evtType != AAMP_EVENT_PROGRESS && evtType != AAMP_EVENT_AD_PLACEMENT_PROGRESS) {//log all events except progress which spams
689  LOG_WARN( _aamp,"ctx=%p, type=%d, jsCallback=%p", _aamp->_ctx,evtType, _jsCallback);
690  }
691 
692  JSObjectRef eventObj = JSObjectMake(_aamp->_ctx, Event_class_ref(), NULL);
693  if (eventObj) {
694  JSValueProtect(_aamp->_ctx, eventObj);
695  JSStringRef name = JSStringCreateWithUTF8CString("type");
696  JSObjectSetProperty(_aamp->_ctx, eventObj, name, JSValueMakeNumber(_aamp->_ctx, evtType), kJSPropertyAttributeReadOnly, NULL);
697  JSStringRelease(name);
698  setEventProperties(e, _aamp->_ctx, eventObj);
699  JSValueRef args[1] = { eventObj };
700  if (evtType == AAMP_EVENT_AD_RESOLVED)
701  {
702  if (_aamp->_promiseCallback != NULL)
703  {
704  JSObjectCallAsFunction(_aamp->_ctx, _aamp->_promiseCallback, NULL, 1, args, NULL);
705  }
706  else
707  {
708  LOG_WARN( _aamp,"No promise callback registered ctx=%p, jsCallback=%p", _aamp->_ctx, _aamp->_promiseCallback);
709 
710  }
711  }
712  else
713  {
714  JSObjectCallAsFunction(_aamp->_ctx, _jsCallback, NULL, 1, args, NULL);
715  }
716  JSValueUnprotect(_aamp->_ctx, eventObj);
717  }
718  }
719 
720  /**
721  * @brief Set JS event properties
722  * @param[in] e AAMP event object
723  * @param[in] context JS execution context
724  * @param[out] eventObj JS event object
725  */
726  virtual void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
727  {
728  }
729 
730 public:
731  AAMP_JS* _aamp;
732  AAMPEventType _type;
733  JSObjectRef _jsCallback;
734  AAMP_JSListener* _pNext;
735 };
736 
737 /**
738  * @class AAMP_JSListener_Progress
739  * @brief Event listener impl for REPORT_PROGRESS AAMP event
740  */
742 {
743 public:
744 
745  /**
746  * @brief AAMP_JSListener_Progress Constructor
747  * @param[in] aamp instance of AAMP_JS
748  * @param[in] type event type
749  * @param[in] jsCallback callback to be registered as listener
750  */
751  AAMP_JSListener_Progress(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
752  {
753  }
754 
755  /**
756  * @brief Set JS event properties
757  * @param[in] e AAMP event object
758  * @param[in] context JS execution context
759  * @param[out] eventObj JS event object
760  */
761  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
762  {
763  ProgressEventPtr evt = std::dynamic_pointer_cast<ProgressEvent>(e);
764 
765  JSStringRef name;
766 
767  name = JSStringCreateWithUTF8CString("durationMiliseconds");
768  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getDuration()), kJSPropertyAttributeReadOnly, NULL);
769  JSStringRelease(name);
770 
771  name = JSStringCreateWithUTF8CString("positionMiliseconds");
772  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getPosition()), kJSPropertyAttributeReadOnly, NULL);
773  JSStringRelease(name);
774 
775  name = JSStringCreateWithUTF8CString("playbackSpeed");
776  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getSpeed()), kJSPropertyAttributeReadOnly, NULL);
777  JSStringRelease(name);
778 
779  name = JSStringCreateWithUTF8CString("startMiliseconds");
780  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getStart()), kJSPropertyAttributeReadOnly, NULL);
781  JSStringRelease(name);
782 
783  name = JSStringCreateWithUTF8CString("endMiliseconds");
784  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getEnd()), kJSPropertyAttributeReadOnly, NULL);
785  JSStringRelease(name);
786 
787  name = JSStringCreateWithUTF8CString("currentPTS");
788  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getPTS()), kJSPropertyAttributeReadOnly, NULL);
789  JSStringRelease(name);
790 
791  name = JSStringCreateWithUTF8CString("videoBufferedMiliseconds");
792  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getBufferedDuration()), kJSPropertyAttributeReadOnly, NULL);
793  JSStringRelease(name);
794 
795  name = JSStringCreateWithUTF8CString("timecode");
796  JSObjectSetProperty(context, eventObj, name, aamp_CStringToJSValue(context, evt->getSEITimeCode()), kJSPropertyAttributeReadOnly, NULL);
797  JSStringRelease(name);
798  }
799 };
800 
801 /**
802  * @class AAMP_JSListener_BitRateChanged
803  * @brief Event listener impl for BITRATE_CHANGED AAMP event
804  */
806 {
807 public:
808 
809  /**
810  * @brief AAMP_JSListener_BitRateChanged Constructor
811  * @param[in] aamp instance of AAMP_JS
812  * @param[in] type event type
813  * @param[in] jsCallback callback to be registered as listener
814  */
815  AAMP_JSListener_BitRateChanged(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
816  {
817  }
818 
819  /**
820  * @brief Set JS event properties
821  * @param[in] e AAMP event object
822  * @param[in] context JS execution context
823  * @param[out] eventObj JS event object
824  */
825  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
826  {
827  BitrateChangeEventPtr evt = std::dynamic_pointer_cast<BitrateChangeEvent>(e);
828 
829  JSStringRef name;
830  name = JSStringCreateWithUTF8CString("time");
831  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getTime()), kJSPropertyAttributeReadOnly, NULL);
832  JSStringRelease(name);
833 
834  name = JSStringCreateWithUTF8CString("bitRate");
835  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getBitrate()), kJSPropertyAttributeReadOnly, NULL);
836  JSStringRelease(name);
837 
838  name = JSStringCreateWithUTF8CString("description");
839  JSObjectSetProperty(context, eventObj, name, aamp_CStringToJSValue(context, evt->getDescription().c_str()), kJSPropertyAttributeReadOnly, NULL);
840  JSStringRelease(name);
841 
842  name = JSStringCreateWithUTF8CString("width");
843  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getWidth()), kJSPropertyAttributeReadOnly, NULL);
844  JSStringRelease(name);
845 
846  name = JSStringCreateWithUTF8CString("height");
847  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getHeight()), kJSPropertyAttributeReadOnly, NULL);
848  JSStringRelease(name);
849 
850  name = JSStringCreateWithUTF8CString("framerate");
851  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getFrameRate()), kJSPropertyAttributeReadOnly, NULL);
852  JSStringRelease(name);
853 
854  name = JSStringCreateWithUTF8CString("position");
855  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getPosition()), kJSPropertyAttributeReadOnly, NULL);
856  name = JSStringCreateWithUTF8CString("cappedProfile");
857  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getCappedProfileStatus()), kJSPropertyAttributeReadOnly, NULL);
858 
859  JSStringRelease(name);
860 
861  name = JSStringCreateWithUTF8CString("displayWidth");
862  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getDisplayWidth()), kJSPropertyAttributeReadOnly, NULL);
863 
864  JSStringRelease(name);
865 
866  name = JSStringCreateWithUTF8CString("displayHeight");
867  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getDisplayHeight()), kJSPropertyAttributeReadOnly, NULL);
868 
869  JSStringRelease(name);
870  }
871 };
872 
873 /**
874  * @class AAMP_JSListener_SpeedChanged
875  * @brief Event listener impl for SPEED_CHANGED AAMP event
876  */
878 {
879 public:
880 
881  /**
882  * @brief AAMP_JSListener_SpeedChanged Constructor
883  * @param[in] aamp instance of AAMP_JS
884  * @param[in] type event type
885  * @param[in] jsCallback callback to be registered as listener
886  */
887  AAMP_JSListener_SpeedChanged(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
888  {
889  }
890 
891  /**
892  * @brief Set JS event properties
893  * @param[in] e AAMP event object
894  * @param[in] context JS execution context
895  * @param[out] eventObj JS event object
896  */
897  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
898  {
899  SpeedChangedEventPtr evt = std::dynamic_pointer_cast<SpeedChangedEvent>(e);
900 
901  JSStringRef name;
902 
903  name = JSStringCreateWithUTF8CString("speed");
904  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getRate()), kJSPropertyAttributeReadOnly, NULL);
905  JSStringRelease(name);
906 
907  name = JSStringCreateWithUTF8CString("reason");
908  JSObjectSetProperty(context, eventObj, name, aamp_CStringToJSValue(context, "unknown"), kJSPropertyAttributeReadOnly, NULL);
909  JSStringRelease(name);
910  }
911 };
912 
913 /**
914  * @class AAMP_JSListener_TuneFailed
915  * @brief Event listener impl for TUNE_FAILED AAMP event
916  */
918 {
919 public:
920 
921  /**
922  * @brief AAMP_JSListener_TuneFailed Constructor
923  * @param[in] aamp instance of AAMP_JS
924  * @param[in] type event type
925  * @param[in] jsCallback callback to be registered as listener
926  */
927  AAMP_JSListener_TuneFailed(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
928  {
929  }
930 
931  /**
932  * @brief Set JS event properties
933  * @param[in] e AAMP event object
934  * @param[in] context JS execution context
935  * @param[out] eventObj JS event object
936  */
937  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
938  {
939  MediaErrorEventPtr evt = std::dynamic_pointer_cast<MediaErrorEvent>(e);
940 
941  int code = evt->getCode();
942  const char* description = evt->getDescription().c_str();
943 
944  JSStringRef name = JSStringCreateWithUTF8CString("code");
945  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, code), kJSPropertyAttributeReadOnly, NULL);
946  JSStringRelease(name);
947 
948  name = JSStringCreateWithUTF8CString("description");
949  JSObjectSetProperty(context, eventObj, name, aamp_CStringToJSValue(context, description), kJSPropertyAttributeReadOnly, NULL);
950  JSStringRelease(name);
951 
952  name = JSStringCreateWithUTF8CString("shouldRetry");
953  JSObjectSetProperty(context, eventObj, name, JSValueMakeBoolean(context, evt->shouldRetry()), kJSPropertyAttributeReadOnly, NULL);
954  JSStringRelease(name);
955 
956  if(-1 != evt->getClass()) //Only send verbose error for secclient/secmanager DRM failures
957  {
958  name = JSStringCreateWithUTF8CString("class");
959  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getClass()), kJSPropertyAttributeReadOnly, NULL);
960  JSStringRelease(name);
961 
962  name = JSStringCreateWithUTF8CString("reason");
963  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getReason()), kJSPropertyAttributeReadOnly, NULL);
964  JSStringRelease(name);
965 
966  name = JSStringCreateWithUTF8CString("businessStatus");
967  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getBusinessStatus()), kJSPropertyAttributeReadOnly, NULL);
968  JSStringRelease(name);
969  }
970  }
971 };
972 
973 
974 
975 /**
976  * @class AAMP_JSListener_DRMMetadata
977  * @brief Class handles JS Listener for DRM meta data operation
978  */
980 {
981 public:
982 
983  /**
984  * @brief AAMP_JSListener_DRMMetadata Constructor
985  * @param aamp instance of Aamp_JS
986  * @param type AampEvent type
987  * @param jsCallback callback to be registered as listener
988  */
989  AAMP_JSListener_DRMMetadata(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
990  {
991  }
992 
993  /**
994  * @brief set the aamp event properties
995  * @param e Aamp Event pointer
996  * @param context JS execution context
997  * @param eventObj JS object reference
998  * @retval None
999  */
1000  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
1001  {
1002  DrmMetaDataEventPtr evt = std::dynamic_pointer_cast<DrmMetaDataEvent>(e);
1003  JSStringRef name;
1004 
1005  int code = evt->getAccessStatusValue();
1006  const char* description = evt->getAccessStatus().c_str();
1007 
1008  LOG_WARN_EX("AAMP_JSListener_DRMMetadata code %d Description %s", code, description);
1009  name = JSStringCreateWithUTF8CString("code");
1010  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, code), kJSPropertyAttributeReadOnly, NULL);
1011  JSStringRelease(name);
1012 
1013  name = JSStringCreateWithUTF8CString("description");
1014  JSObjectSetProperty(context, eventObj, name, aamp_CStringToJSValue(context, description), kJSPropertyAttributeReadOnly, NULL);
1015  JSStringRelease(name);
1016  }
1017 };
1018 
1019 /**
1020  * @class AAMP_JSListener_AnomalyReport
1021  * @brief AAMP_JSListener_AnomalyReport to receive anomalyreport
1022  */
1024 {
1025 public:
1026 
1027  /**
1028  * @brief AAMP_JSListener_DRMMetadata Constructor
1029  * @param aamp Aamp_JS
1030  * @param type AampEvent type
1031  * @param jsCallback callback to be registered as listener
1032  */
1033  AAMP_JSListener_AnomalyReport(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
1034  {
1035  }
1036 
1037  /**
1038  * @brief
1039  * @param e Aamp Event pointer
1040  * @param context JS execution context
1041  * @param eventObj JS object reference
1042  * @retval void
1043  */
1044  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
1045  {
1046  AnomalyReportEventPtr evt = std::dynamic_pointer_cast<AnomalyReportEvent>(e);
1047  JSStringRef name;
1048 
1049  int severity = evt->getSeverity();
1050  const char* description = evt->getMessage().c_str();
1051 
1052  LOG_WARN_EX("AAMP_JSListener_AnomalyReport severity %d Description %s",severity,description);
1053  name = JSStringCreateWithUTF8CString("severity");
1054  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, severity), kJSPropertyAttributeReadOnly, NULL);
1055  JSStringRelease(name);
1056 
1057  name = JSStringCreateWithUTF8CString("description");
1058  JSObjectSetProperty(context, eventObj, name, aamp_CStringToJSValue(context, description), kJSPropertyAttributeReadOnly, NULL);
1059  JSStringRelease(name);
1060  }
1061 };
1062 
1063 /**
1064  * @class AAMP_JSListener_MetricsData
1065  * @brief AAMP_JSListener_MetricsData to receive aamp metrics
1066  */
1068 {
1069 public:
1070 
1071  /**
1072  * @brief AAMP_JSListener_DRMMetadata Constructor
1073  * @param aamp instance of AAMP_JS
1074  * @param type AampEvent type
1075  * @param jsCallback callback to be registered as listener
1076  */
1077  AAMP_JSListener_MetricsData(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
1078  {
1079  }
1080 
1081  /**
1082  * @brief Set the Aamp Event properties
1083  * @param e Aamp Event pointer
1084  * @param context JS execution context
1085  * @param eventObj JS event object
1086  * @retval None
1087  */
1088  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
1089  {
1090  MetricsDataEventPtr evt = std::dynamic_pointer_cast<MetricsDataEvent>(e);
1091  JSStringRef strJSObj;
1092 
1093  strJSObj = JSStringCreateWithUTF8CString("metricType");
1094  JSObjectSetProperty(context, eventObj, strJSObj, JSValueMakeNumber(context, evt->getMetricsDataType()), kJSPropertyAttributeReadOnly, NULL);
1095  JSStringRelease(strJSObj);
1096 
1097  strJSObj = JSStringCreateWithUTF8CString("traceID");
1098  JSObjectSetProperty(context, eventObj, strJSObj, aamp_CStringToJSValue(context, evt->getMetricUUID().c_str()), kJSPropertyAttributeReadOnly, NULL);
1099  JSStringRelease(strJSObj);
1100 
1101  strJSObj = JSStringCreateWithUTF8CString("metricData");
1102  JSObjectSetProperty(context, eventObj, strJSObj, aamp_CStringToJSValue(context, evt->getMetricsData().c_str()), kJSPropertyAttributeReadOnly, NULL);
1103  JSStringRelease(strJSObj);
1104  }
1105 };
1106 
1107 
1108 /**
1109  * @class AAMP_JSListener_CCHandleReceived
1110  * @brief Event listener impl for CC_HANDLE_RECEIVED AAMP event
1111  */
1113 {
1114 public:
1115  /**
1116  * @brief AAMP_JSListener_CCHandleReceived Constructor
1117  * @param[in] aamp instance of AAMP_JS
1118  * @param[in] type event type
1119  * @param[in] jsCallback callback to be registered as listener
1120  */
1121  AAMP_JSListener_CCHandleReceived(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
1122  {
1123  }
1124 
1125  /**
1126  * @brief Set JS event properties
1127  * @param[in] e AAMP event object
1128  * @param[in] context JS execution context
1129  * @param[out] eventObj JS event object
1130  */
1131  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
1132  {
1133  CCHandleEventPtr evt = std::dynamic_pointer_cast<CCHandleEvent>(e);
1134  JSStringRef name;
1135 
1136  name = JSStringCreateWithUTF8CString("decoderHandle");
1137  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getCCHandle()), kJSPropertyAttributeReadOnly, NULL);
1138  JSStringRelease(name);
1139  }
1140 };
1141 
1142 /**
1143  * @class AAMP_JSListener_VideoMetadata
1144  * @brief Event listener impl for VIDEO_METADATA AAMP event
1145  */
1147 {
1148 public:
1149 
1150  /**
1151  * @brief AAMP_JSListener_VideoMetadata Constructor
1152  * @param[in] aamp instance of AAMP_JS
1153  * @param[in] type event type
1154  * @param[in] jsCallback callback to be registered as listener
1155  */
1156  AAMP_JSListener_VideoMetadata(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
1157  {
1158  }
1159 
1160  /**
1161  * @brief Set JS event properties
1162  * @param[in] e AAMP event object
1163  * @param[in] context JS execution context
1164  * @param[out] eventObj JS event object
1165  */
1166  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
1167  {
1168  MediaMetadataEventPtr evt = std::dynamic_pointer_cast<MediaMetadataEvent>(e);
1169 
1170  JSStringRef name;
1171  name = JSStringCreateWithUTF8CString("durationMiliseconds");
1172  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getDuration()), kJSPropertyAttributeReadOnly, NULL);
1173  JSStringRelease(name);
1174 
1175  int count = evt->getLanguagesCount();
1176  const std::vector<std::string> &langVect = evt->getLanguages();
1177  JSValueRef* array = new JSValueRef[count];
1178  for (int32_t i = 0; i < count; i++)
1179  {
1180  JSValueRef lang = aamp_CStringToJSValue(context, langVect[i].c_str());
1181  array[i] = lang;
1182  //JSValueRelease(lang);
1183  }
1184  JSValueRef prop = JSObjectMakeArray(context, count, array, NULL);
1185  SAFE_DELETE_ARRAY(array);
1186 
1187  name = JSStringCreateWithUTF8CString("languages");
1188  JSObjectSetProperty(context, eventObj, name, prop, kJSPropertyAttributeReadOnly, NULL);
1189  JSStringRelease(name);
1190 
1191  count = evt->getBitratesCount();
1192  const std::vector<long> &bitrateVect = evt->getBitrates();
1193  array = new JSValueRef[count];
1194  for (int32_t i = 0; i < count; i++)
1195  {
1196  array[i] = JSValueMakeNumber(context, bitrateVect[i]);
1197  }
1198  prop = JSObjectMakeArray(context, count, array, NULL);
1199  SAFE_DELETE_ARRAY(array);
1200 
1201  name = JSStringCreateWithUTF8CString("bitrates");
1202  JSObjectSetProperty(context, eventObj, name, prop, kJSPropertyAttributeReadOnly, NULL);
1203  JSStringRelease(name);
1204 
1205  count = evt->getSupportedSpeedCount();
1206  const std::vector<float> &speedVect = evt->getSupportedSpeeds();
1207  array = new JSValueRef[count];
1208  for (int32_t i = 0; i < count; i++)
1209  {
1210  array[i] = JSValueMakeNumber(context, speedVect[i]);
1211  }
1212  prop = JSObjectMakeArray(context, count, array, NULL);
1213  SAFE_DELETE_ARRAY(array);
1214 
1215  name = JSStringCreateWithUTF8CString("playbackSpeeds");
1216  JSObjectSetProperty(context, eventObj, name, prop, kJSPropertyAttributeReadOnly, NULL);
1217  JSStringRelease(name);
1218 
1219  name = JSStringCreateWithUTF8CString("width");
1220  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getWidth()), kJSPropertyAttributeReadOnly, NULL);
1221  JSStringRelease(name);
1222 
1223  name = JSStringCreateWithUTF8CString("height");
1224  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, evt->getHeight()), kJSPropertyAttributeReadOnly, NULL);
1225  JSStringRelease(name);
1226 
1227  name = JSStringCreateWithUTF8CString("hasDrm");
1228  JSObjectSetProperty(context, eventObj, name, JSValueMakeBoolean(context, evt->hasDrm()), kJSPropertyAttributeReadOnly, NULL);
1229  JSStringRelease(name);
1230  }
1231 };
1232 
1233 /**
1234  * @class AAMP_JSListener_BulkTimedMetadata
1235  * @brief Event listener impl for BULK_TIMED_METADATA AAMP event
1236  */
1238 {
1239 public:
1240 
1241  /**
1242  * @brief AAMP_JSListener_TimedMetadata Constructor
1243  * @param[in] aamp instance of AAMP_JS
1244  * @param[in] type event type
1245  * @param[in] jsCallback callback to be registered as listener
1246  */
1247  AAMP_JSListener_BulkTimedMetadata(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
1248  {
1249  }
1250 
1251  /**
1252  * @brief Set JS event properties
1253  * @param[in] e AAMP event object
1254  * @param[in] context JS execution context
1255  * @param[out] eventObj JS event object
1256  */
1257  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
1258  {
1259  BulkTimedMetadataEventPtr evt = std::dynamic_pointer_cast<BulkTimedMetadataEvent>(e);
1260  JSStringRef name = JSStringCreateWithUTF8CString("timedMetadatas");
1261  JSObjectSetProperty(context, eventObj, name, aamp_CStringToJSValue(context, evt->getContent().c_str()), kJSPropertyAttributeReadOnly, NULL);
1262  JSStringRelease(name);
1263  }
1264 };
1265 
1266 
1267 /**
1268  * @class AAMP_JSListener_TimedMetadata
1269  * @brief Event listener impl for TIMED_METADATA AAMP event
1270  */
1272 {
1273 public:
1274 
1275  /**
1276  * @brief AAMP_JSListener_TimedMetadata Constructor
1277  * @param[in] aamp instance of AAMP_JS
1278  * @param[in] type event type
1279  * @param[in] jsCallback callback to be registered as listener
1280  */
1281  AAMP_JSListener_TimedMetadata(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
1282  {
1283  }
1284 
1285  /**
1286  * @brief Set JS event properties
1287  * @param[in] e AAMP event object
1288  * @param[in] context JS execution context
1289  * @param[out] eventObj JS event object
1290  */
1291  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
1292  {
1293  TimedMetadataEventPtr evt = std::dynamic_pointer_cast<TimedMetadataEvent>(e);
1294 
1295  JSObjectRef timedMetadata = aamp_CreateTimedMetadataJSObject(context, evt->getTime(), evt->getName().c_str(), evt->getContent().c_str(), evt->getId().c_str(), evt->getDuration());
1296  if (timedMetadata) {
1297  JSValueProtect(context, timedMetadata);
1298  JSStringRef name = JSStringCreateWithUTF8CString("timedMetadata");
1299  JSObjectSetProperty(context, eventObj, name, timedMetadata, kJSPropertyAttributeReadOnly, NULL);
1300  JSStringRelease(name);
1301  JSValueUnprotect(context, timedMetadata);
1302  }
1303  }
1304 };
1305 
1306 /**
1307  * @class AAMP_JSListener_ContentGap
1308  * @brief Event listener impl for AAMP_EVENT_CONTENT_GAP event.
1309  */
1311 {
1312 public:
1313  /**
1314  * @brief AAMP_JSListener_ContentGap Constructor
1315  * @param[in] aamp instance of AAMP_JS
1316  * @param[in] type event type
1317  * @param[in] jsCallback callback to be registered as listener
1318  */
1319  AAMP_JSListener_ContentGap(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
1320  {
1321  }
1322 
1323  /**
1324  * @brief Set JS event properties
1325  * @param[in] e AAMP event object
1326  * @param[in] context JS execution context
1327  * @param[out] eventObj JS event object
1328  */
1329  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
1330  {
1331  ContentGapEventPtr evt = std::dynamic_pointer_cast<ContentGapEvent>(e);
1332  JSStringRef name;
1333 
1334  double time = evt->getTime();
1335  double durationMs = evt->getDuration();
1336 
1337  name = JSStringCreateWithUTF8CString("time");
1338  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, std::round(time)), kJSPropertyAttributeReadOnly, NULL);
1339  JSStringRelease(name);
1340 
1341  if (durationMs >= 0)
1342  {
1343  name = JSStringCreateWithUTF8CString("duration");
1344  JSObjectSetProperty(context, eventObj, name, JSValueMakeNumber(context, (int)durationMs), kJSPropertyAttributeReadOnly, NULL);
1345  JSStringRelease(name);
1346  }
1347  }
1348 };
1349 
1350 /**
1351  * @class AAMP_JSListener_StatusChanged
1352  * @brief Event listener for STATUS_CHANGED AAMP event
1353  */
1355 {
1356 public:
1357 
1358  /**
1359  * @brief AAMP_JSListener_StatusChanged Constructor
1360  * @param[in] aamp instance of AAMP_JS
1361  * @param[in] type event type
1362  * @param[in] jsCallback callback to be registered as listener
1363  */
1364  AAMP_JSListener_StatusChanged(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
1365  {
1366  }
1367 
1368  /**
1369  * @brief Set JS event properties
1370  * @param[in] e AAMP event object
1371  * @param[in] context JS execution context
1372  * @param[out] eventObj JS event object
1373  */
1374  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
1375  {
1376  StateChangedEventPtr evt = std::dynamic_pointer_cast<StateChangedEvent>(e);
1377 
1378  JSStringRef prop;
1379 
1380  prop = JSStringCreateWithUTF8CString("state");
1381  JSObjectSetProperty(context, eventObj, prop, JSValueMakeNumber(context, evt->getState()), kJSPropertyAttributeReadOnly, NULL);
1382  JSStringRelease(prop);
1383 
1384  }
1385 };
1386 
1387 
1388 /**
1389  * @class AAMP_JSListener_SpeedsChanged
1390  * @brief Event listener impl for SPEEDS_CHANGED AAMP event
1391  */
1393 {
1394 public:
1395 
1396  /**
1397  * @brief AAMP_JSListener_SpeedsChanged Constructor
1398  * @param[in] aamp instance of AAMP_JS
1399  * @param[in] type event type
1400  * @param[in] jsCallback callback to be registered as listener
1401  */
1402  AAMP_JSListener_SpeedsChanged(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
1403  {
1404  }
1405 
1406  /**
1407  * @brief Set JS event properties
1408  * @param[in] e AAMP event object
1409  * @param[in] context JS execution context
1410  * @param[out] eventObj JS event object
1411  */
1412  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
1413  {
1414  SupportedSpeedsChangedEventPtr evt = std::dynamic_pointer_cast<SupportedSpeedsChangedEvent>(e);
1415 
1416  int count = evt->getSupportedSpeedCount();
1417  const std::vector<float> &speedVect = evt->getSupportedSpeeds();
1418  JSValueRef* array = new JSValueRef[count];
1419  for (int32_t i = 0; i < count; i++)
1420  {
1421  array[i] = JSValueMakeNumber(context, speedVect[i]);
1422  }
1423  JSValueRef prop = JSObjectMakeArray(context, count, array, NULL);
1424  SAFE_DELETE_ARRAY(array);
1425 
1426  JSStringRef name = JSStringCreateWithUTF8CString("playbackSpeeds");
1427  JSObjectSetProperty(context, eventObj, name, prop, kJSPropertyAttributeReadOnly, NULL);
1428  JSStringRelease(name);
1429  }
1430 };
1431 
1432 
1433 /**
1434  * @class AAMP_JSListener_AdResolved
1435  * @brief Event listener impl for AD_RESOLVED AAMP event
1436  */
1438 {
1439 public:
1440 
1441  /**
1442  * @brief AAMP_JSListener_AdResolved Constructor
1443  * @param[in] aamp instance of AAMP_JS
1444  * @param[in] type event type
1445  * @param[in] jsCallback callback to be registered as listener
1446  */
1447  AAMP_JSListener_AdResolved(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
1448  {
1449  }
1450 
1451  /**
1452  * @brief Set JS event properties
1453  * @param[in] e AAMP event object
1454  * @param[in] context JS execution context
1455  * @param[out] eventObj JS event object
1456  */
1457  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
1458  {
1459  AdResolvedEventPtr evt = std::dynamic_pointer_cast<AdResolvedEvent>(e);
1460 
1461  JSStringRef prop;
1462 
1463  prop = JSStringCreateWithUTF8CString("resolvedStatus");
1464  JSObjectSetProperty(context, eventObj, prop, JSValueMakeBoolean(context, evt->getResolveStatus()), kJSPropertyAttributeReadOnly, NULL);
1465  JSStringRelease(prop);
1466 
1467  prop = JSStringCreateWithUTF8CString("placementId");
1468  JSObjectSetProperty(context, eventObj, prop, aamp_CStringToJSValue(context, evt->getAdId().c_str()), kJSPropertyAttributeReadOnly, NULL);
1469  JSStringRelease(prop);
1470 
1471  prop = JSStringCreateWithUTF8CString("placementStartTime");
1472  JSObjectSetProperty(context, eventObj, prop, JSValueMakeNumber(context, evt->getStart()), kJSPropertyAttributeReadOnly, NULL);
1473  JSStringRelease(prop);
1474 
1475  prop = JSStringCreateWithUTF8CString("placementDuration");
1476  JSObjectSetProperty(context, eventObj, prop, JSValueMakeNumber(context, evt->getDuration()), kJSPropertyAttributeReadOnly, NULL);
1477  JSStringRelease(prop);
1478  }
1479 };
1480 
1481 /**
1482  * @class AAMP_JSListener_AdReservationStart
1483  * @brief Event listener impl for AD_RESOLVED AAMP event
1484  */
1486 {
1487 public:
1488 
1489  /**
1490  * @brief AAMP_JSListener_AdReservationStart Constructor
1491  * @param[in] aamp instance of AAMP_JS
1492  * @param[in] type event type
1493  * @param[in] jsCallback callback to be registered as listener
1494  */
1495  AAMP_JSListener_AdReservationStart(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
1496  {
1497  }
1498 
1499  /**
1500  * @brief Set JS event properties
1501  * @param[in] e AAMP event object
1502  * @param[in] context JS execution context
1503  * @param[out] eventObj JS event object
1504  */
1505  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
1506  {
1507  AdReservationEventPtr evt = std::dynamic_pointer_cast<AdReservationEvent>(e);
1508 
1509  JSStringRef prop;
1510 
1511  prop = JSStringCreateWithUTF8CString("adbreakId");
1512  JSObjectSetProperty(context, eventObj, prop, aamp_CStringToJSValue(context, evt->getAdBreakId().c_str()), kJSPropertyAttributeReadOnly, NULL);
1513  JSStringRelease(prop);
1514 
1515  prop = JSStringCreateWithUTF8CString("time");
1516  JSObjectSetProperty(context, eventObj, prop, JSValueMakeNumber(context, evt->getPosition()), kJSPropertyAttributeReadOnly, NULL);
1517  JSStringRelease(prop);
1518  }
1519 };
1520 
1521 /**
1522  * @class AAMP_JSListener_AdReservationEnd
1523  * @brief Event listener impl for AD_RESOLVED AAMP event
1524  */
1526 {
1527 public:
1528 
1529  /**
1530  * @brief AAMP_JSListener_AdReservationEnd Constructor
1531  * @param[in] aamp instance of AAMP_JS
1532  * @param[in] type event type
1533  * @param[in] jsCallback callback to be registered as listener
1534  */
1535  AAMP_JSListener_AdReservationEnd(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
1536  {
1537  }
1538 
1539  /**
1540  * @brief Set JS event properties
1541  * @param[in] e AAMP event object
1542  * @param[in] context JS execution context
1543  * @param[out] eventObj JS event object
1544  */
1545  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
1546  {
1547  AdReservationEventPtr evt = std::dynamic_pointer_cast<AdReservationEvent>(e);
1548 
1549  JSStringRef prop;
1550 
1551  prop = JSStringCreateWithUTF8CString("adbreakId");
1552  JSObjectSetProperty(context, eventObj, prop, aamp_CStringToJSValue(context, evt->getAdBreakId().c_str()), kJSPropertyAttributeReadOnly, NULL);
1553  JSStringRelease(prop);
1554 
1555  prop = JSStringCreateWithUTF8CString("time");
1556  JSObjectSetProperty(context, eventObj, prop, JSValueMakeNumber(context, evt->getPosition()), kJSPropertyAttributeReadOnly, NULL);
1557  JSStringRelease(prop);
1558  }
1559 };
1560 
1561 /**
1562  * @class AAMP_JSListener_AdPlacementStart
1563  * @brief Event listener impl for AD_RESOLVED AAMP event
1564  */
1566 {
1567 public:
1568 
1569  /**
1570  * @brief AAMP_JSListener_AdPlacementStart Constructor
1571  * @param[in] aamp instance of AAMP_JS
1572  * @param[in] type event type
1573  * @param[in] jsCallback callback to be registered as listener
1574  */
1575  AAMP_JSListener_AdPlacementStart(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
1576  {
1577  }
1578 
1579  /**
1580  * @brief Set JS event properties
1581  * @param[in] e AAMP event object
1582  * @param[in] context JS execution context
1583  * @param[out] eventObj JS event object
1584  */
1585  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
1586  {
1587  AdPlacementEventPtr evt = std::dynamic_pointer_cast<AdPlacementEvent>(e);
1588 
1589  JSStringRef prop;
1590 
1591  prop = JSStringCreateWithUTF8CString("adId");
1592  JSObjectSetProperty(context, eventObj, prop, aamp_CStringToJSValue(context, evt->getAdId().c_str()), kJSPropertyAttributeReadOnly, NULL);
1593  JSStringRelease(prop);
1594 
1595  prop = JSStringCreateWithUTF8CString("time");
1596  JSObjectSetProperty(context, eventObj, prop, JSValueMakeNumber(context, evt->getPosition()), kJSPropertyAttributeReadOnly, NULL);
1597  JSStringRelease(prop);
1598  }
1599 };
1600 
1601 /**
1602  * @class AAMP_JSListener_AdPlacementEnd
1603  * @brief Event listener impl for AD_RESOLVED AAMP event
1604  */
1606 {
1607 public:
1608 
1609  /**
1610  * @brief AAMP_JSListener_AdPlacementEnd Constructor
1611  * @param[in] aamp instance of AAMP_JS
1612  * @param[in] type event type
1613  * @param[in] jsCallback callback to be registered as listener
1614  */
1615  AAMP_JSListener_AdPlacementEnd(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
1616  {
1617  }
1618 
1619  /**
1620  * @brief Set JS event properties
1621  * @param[in] e AAMP event object
1622  * @param[in] context JS execution context
1623  * @param[out] eventObj JS event object
1624  */
1625  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
1626  {
1627  AdPlacementEventPtr evt = std::dynamic_pointer_cast<AdPlacementEvent>(e);
1628 
1629  JSStringRef prop;
1630 
1631  prop = JSStringCreateWithUTF8CString("adId");
1632  JSObjectSetProperty(context, eventObj, prop, aamp_CStringToJSValue(context, evt->getAdId().c_str()), kJSPropertyAttributeReadOnly, NULL);
1633  JSStringRelease(prop);
1634 
1635  prop = JSStringCreateWithUTF8CString("time");
1636  JSObjectSetProperty(context, eventObj, prop, JSValueMakeNumber(context, evt->getPosition()), kJSPropertyAttributeReadOnly, NULL);
1637  JSStringRelease(prop);
1638  }
1639 };
1640 
1641 /**
1642  * @class AAMP_JSListener_AdProgress
1643  * @brief Event listener impl for REPORT_AD_PROGRESS AAMP event
1644  */
1646 {
1647 public:
1648 
1649  /**
1650  * @brief AAMP_JSListener_AdProgress Constructor
1651  * @param[in] aamp instance of AAMP_JS
1652  * @param[in] type event type
1653  * @param[in] jsCallback callback to be registered as listener
1654  */
1655  AAMP_JSListener_AdProgress(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
1656  {
1657  }
1658 
1659  /**
1660  * @brief Set JS event properties
1661  *
1662  * @param[in] e AAMP event object
1663  * @param[in] context JS execution context
1664  * @param[out] eventObj JS event object
1665  */
1666  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
1667  {
1668  AdPlacementEventPtr evt = std::dynamic_pointer_cast<AdPlacementEvent>(e);
1669 
1670  JSStringRef prop;
1671 
1672  prop = JSStringCreateWithUTF8CString("adId");
1673  JSObjectSetProperty(context, eventObj, prop, aamp_CStringToJSValue(context, evt->getAdId().c_str()), kJSPropertyAttributeReadOnly, NULL);
1674  JSStringRelease(prop);
1675 
1676  prop = JSStringCreateWithUTF8CString("time");
1677  JSObjectSetProperty(context, eventObj, prop, JSValueMakeNumber(context, evt->getPosition()), kJSPropertyAttributeReadOnly, NULL);
1678  JSStringRelease(prop);
1679  }
1680 };
1681 
1682 /**
1683  * @class AAMP_JSListener_AdPlacementEror
1684  * @brief Event listener impl for AD_RESOLVED AAMP event
1685  */
1687 {
1688 public:
1689 
1690  /**
1691  * @brief AAMP_JSListener_AdPlacementEror Constructor
1692  * @param[in] aamp instance of AAMP_JS
1693  * @param[in] type event type
1694  * @param[in] jsCallback callback to be registered as listener
1695  */
1696  AAMP_JSListener_AdPlacementEror(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
1697  {
1698  }
1699 
1700  /**
1701  * @brief Set JS event properties
1702  * @param[in] e AAMP event object
1703  * @param[in] context JS execution context
1704  * @param[out] eventObj JS event object
1705  */
1706  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
1707  {
1708  AdPlacementEventPtr evt = std::dynamic_pointer_cast<AdPlacementEvent>(e);
1709 
1710  JSStringRef prop;
1711 
1712  prop = JSStringCreateWithUTF8CString("adId");
1713  JSObjectSetProperty(context, eventObj, prop, aamp_CStringToJSValue(context, evt->getAdId().c_str()), kJSPropertyAttributeReadOnly, NULL);
1714  JSStringRelease(prop);
1715 
1716  prop = JSStringCreateWithUTF8CString("time");
1717  JSObjectSetProperty(context, eventObj, prop, JSValueMakeNumber(context, evt->getPosition()), kJSPropertyAttributeReadOnly, NULL);
1718  JSStringRelease(prop);
1719 
1720  prop = JSStringCreateWithUTF8CString("error");
1721  JSObjectSetProperty(context, eventObj, prop, JSValueMakeNumber(context, evt->getErrorCode()), kJSPropertyAttributeReadOnly, NULL);
1722  JSStringRelease(prop);
1723  }
1724 };
1725 
1726 /**
1727  * @class AAMP_JSListener_BufferingChanged
1728  * @brief Event listener impl for (AAMP_EVENT_BUFFER_UNDERFLOW) AAMP event
1729  */
1731 {
1732 public:
1733 
1734  /**
1735  * @brief AAMP_JSListener_BufferingChanged Constructor
1736  * @param[in] aamp instance of AAMP_JS
1737  * @param[in] type event type
1738  * @param[in] jsCallback callback to be registered as listener
1739  */
1740  AAMP_JSListener_BufferingChanged(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
1741  {
1742  }
1743 
1744  /**
1745  * @brief Set JS event properties
1746  * @param[in] e AAMP event object
1747  * @param[in] context JS execution context
1748  * @param[out] eventObj JS event object
1749  */
1750  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
1751  {
1752  BufferingChangedEventPtr evt = std::dynamic_pointer_cast<BufferingChangedEvent>(e);
1753  JSStringRef prop;
1754 
1755  /* e.data.bufferingChanged.buffering buffering started(underflow ended) = true, buffering end(underflow started) = false*/
1756  prop = JSStringCreateWithUTF8CString("status");
1757  JSObjectSetProperty(context, eventObj, prop, JSValueMakeBoolean(context, evt->buffering()), kJSPropertyAttributeReadOnly, NULL);
1758  JSStringRelease(prop);
1759  }
1760 };
1761 
1762 
1763 /**
1764  * @class AAMP_JSListener_Id3Metadata
1765  * @brief Event listener impl for (AAMP_JSListener_Id3Metadata) AAMP event
1766  */
1768 {
1769 public:
1770 
1771  /**
1772  * @brief AAMP_JSListener_Id3Metadata Constructor
1773  * @param[in] aamp instance of AAMP_JS
1774  * @param[in] type event type
1775  * @param[in] jsCallback callback to be registered as listener
1776  */
1777  AAMP_JSListener_Id3Metadata(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
1778  {
1779  }
1780 
1781  /**
1782  * @brief Set JS event properties
1783  * @param[in] e AAMP event object
1784  * @param[in] context JS execution context
1785  * @param[out] eventObj JS event object
1786  */
1787  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
1788  {
1789  ID3MetadataEventPtr evt = std::dynamic_pointer_cast<ID3MetadataEvent>(e);
1790  std::vector<uint8_t> data = evt->getMetadata();
1791  int len = evt->getMetadataSize();
1792  JSStringRef prop;
1793 
1794  JSValueRef* array = new JSValueRef[len];
1795  for (int32_t i = 0; i < len; i++)
1796  {
1797  array[i] = JSValueMakeNumber(context, data[i]);
1798  }
1799 
1800  prop = JSStringCreateWithUTF8CString("data");
1801  JSObjectSetProperty(context, eventObj, prop, JSObjectMakeArray(context, len, array, NULL), kJSPropertyAttributeReadOnly, NULL);
1802  JSStringRelease(prop);
1803  SAFE_DELETE_ARRAY(array);
1804 
1805  prop = JSStringCreateWithUTF8CString("length");
1806  JSObjectSetProperty(context, eventObj, prop, JSValueMakeNumber(context, len), kJSPropertyAttributeReadOnly, NULL);
1807  JSStringRelease(prop);
1808  }
1809 };
1810 
1811 /**
1812  * @class AAMP_JSListener_DrmMessage
1813  * @brief Event listener impl for (AAMP_EVENT_DRM_MESSAGE) AAMP event
1814  */
1816 {
1817 public:
1818 
1819  /**
1820  * @brief AAMP_JSListener_DrmMessage Constructor
1821  * @param[in] aamp instance of AAMP_JS
1822  * @param[in] type event type
1823  * @param[in] jsCallback callback to be registered as listener
1824  */
1825  AAMP_JSListener_DrmMessage(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
1826  {
1827  }
1828 
1829  /**
1830  * @brief Set JS event properties
1831  * @param[in] e AAMP event object
1832  * @param[in] context JS execution context
1833  * @param[out] eventObj JS event object
1834  */
1835  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
1836  {
1837  DrmMessageEventPtr evt = std::dynamic_pointer_cast<DrmMessageEvent>(e);
1838  JSStringRef prop;
1839  prop = JSStringCreateWithUTF8CString("data");
1840  JSObjectSetProperty(context, eventObj, prop, aamp_CStringToJSValue(context, evt->getMessage().c_str()), kJSPropertyAttributeReadOnly, NULL);
1841  JSStringRelease(prop);
1842  }
1843 };
1844 
1845 /**
1846  * @class AAMP_JSListener_ContentProtectionData
1847  * @brief Event listener impl for (AAMP_EVENT_CONTENT_PROTECTION_DATA_UPDATE) AAMP event
1848  */
1850 {
1851 public:
1852 
1853  /**
1854  * @brief AAMP_JSListener_ContentProtectionData Constructor
1855  * @param[in] aamp instance of AAMP_JS
1856  * @param[in] type event type
1857  * @param[in] jsCallback callback to be registered as listener
1858  */
1859  AAMP_JSListener_ContentProtectionData(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback) : AAMP_JSListener(aamp, type, jsCallback)
1860  {
1861  }
1862 
1863  /**
1864  * @brief Set JS event properties
1865  * @param[in] e AAMP event object
1866  * @param[in] context JS execution context
1867  * @param[out] eventObj JS event object
1868  */
1869  void setEventProperties(const AAMPEventPtr& e, JSContextRef context, JSObjectRef eventObj)
1870  {
1871  ContentProtectionDataEventPtr evt = std::dynamic_pointer_cast<ContentProtectionDataEvent>(e);
1872  std::vector<uint8_t> keyId = evt->getKeyID();
1873  int len = keyId.size();
1874  JSStringRef prop;
1875  JSValueRef* array = new JSValueRef[len];
1876  for (int32_t i = 0; i < len; i++)
1877  {
1878  array[i] = JSValueMakeNumber(context, keyId[i]);
1879  }
1880 
1881  prop = JSStringCreateWithUTF8CString("keyID");
1882  JSObjectSetProperty(context, eventObj, prop, JSObjectMakeArray(context, len, array, NULL), kJSPropertyAttributeReadOnly, NULL);
1883  JSStringRelease(prop);
1884  SAFE_DELETE_ARRAY(array);
1885 
1886  prop = JSStringCreateWithUTF8CString("streamType");
1887  JSObjectSetProperty(context, eventObj, prop, aamp_CStringToJSValue(context, evt->getStreamType().c_str()), kJSPropertyAttributeReadOnly, NULL);
1888  JSStringRelease(prop);
1889 
1890  }
1891 };
1892 
1893 
1894 /**
1895  * @brief Callback invoked from JS to add an event listener for a particular event
1896  * @param[in] context JS execution context
1897  * @param[in] function JSObject that is the function being called
1898  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
1899  * @param[in] argumentCount number of args
1900  * @param[in] arguments[] JSValue array of args
1901  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
1902  * @retval JSValue that is the function's return value
1903  */
1904 static JSValueRef AAMP_addEventListener(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
1905 {
1906  LOG_TRACE("Enter");
1907  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
1908  if (pAAMP == NULL)
1909  {
1910  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
1911  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.addEventListener on instances of AAMP");
1912  return JSValueMakeUndefined(context);
1913  }
1914 
1915  if (argumentCount >= 2)
1916  {
1917  JSObjectRef callbackObj = JSValueToObject(context, arguments[1], NULL);
1918 
1919  if (callbackObj != NULL && JSObjectIsFunction(context, callbackObj))
1920  {
1921  char* type = aamp_JSValueToCString(context, arguments[0], NULL);
1922  AAMPEventType eventType = aamp_getEventTypeFromName(type);
1923  LOG_TRACE("eventType='%s', %d", type, eventType);
1924 
1925  if ((eventType >= 0) && (eventType < AAMP_MAX_NUM_EVENTS))
1926  {
1927  AAMP_JSListener::AddEventListener(pAAMP, eventType, callbackObj);
1928  }
1929  SAFE_DELETE_ARRAY(type);
1930  }
1931  else
1932  {
1933  LOG_ERROR_EX("callbackObj=%p, JSObjectIsFunction(context, callbackObj) is NULL", callbackObj);
1934  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.addEventListener' - parameter 2 is not a function");
1935  }
1936  }
1937  else
1938  {
1939  LOG_ERROR_EX("InvalidArgument: argumentCount=%d, expected: 2", argumentCount);
1940  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.addEventListener' - 2 arguments required.");
1941  }
1942 
1943  return JSValueMakeUndefined(context);
1944 }
1945 
1946 
1947 /**
1948  * @brief Adds a JS function as listener for a particular event
1949  * @param[in] aamp jsObj instance of AAMP_JS
1950  * @param[in] type event type
1951  * @param[in] jsCallback callback to be registered as listener
1952  */
1953 void AAMP_JSListener::AddEventListener(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback)
1954 {
1955  LOG_TRACE("(%p, %d, %p)", aamp, type, jsCallback);
1956 
1957  AAMP_JSListener* pListener = 0;
1958 
1959  if(type == AAMP_EVENT_PROGRESS)
1960  {
1961  pListener = new AAMP_JSListener_Progress(aamp, type, jsCallback);
1962  }
1963  else if(type == AAMP_EVENT_SPEED_CHANGED)
1964  {
1965  pListener = new AAMP_JSListener_SpeedChanged(aamp, type, jsCallback);
1966  }
1967  else if(type == AAMP_EVENT_CC_HANDLE_RECEIVED)
1968  {
1969  pListener = new AAMP_JSListener_CCHandleReceived(aamp, type, jsCallback);
1970  }
1971  else if(type == AAMP_EVENT_MEDIA_METADATA)
1972  {
1973  pListener = new AAMP_JSListener_VideoMetadata(aamp, type, jsCallback);
1974  }
1975  else if(type == AAMP_EVENT_TUNE_FAILED)
1976  {
1977  pListener = new AAMP_JSListener_TuneFailed(aamp, type, jsCallback);
1978  }
1979  else if(type == AAMP_EVENT_BITRATE_CHANGED)
1980  {
1981  pListener = new AAMP_JSListener_BitRateChanged(aamp, type, jsCallback);
1982  }
1983  else if(type == AAMP_EVENT_BULK_TIMED_METADATA)
1984  {
1985  pListener = new AAMP_JSListener_BulkTimedMetadata(aamp, type, jsCallback);
1986  }
1987  else if(type == AAMP_EVENT_TIMED_METADATA)
1988  {
1989  pListener = new AAMP_JSListener_TimedMetadata(aamp, type, jsCallback);
1990  }
1991  else if(type == AAMP_EVENT_CONTENT_GAP)
1992  {
1993  pListener = new AAMP_JSListener_ContentGap(aamp, type, jsCallback);
1994  }
1995  else if(type == AAMP_EVENT_STATE_CHANGED)
1996  {
1997  pListener = new AAMP_JSListener_StatusChanged(aamp, type, jsCallback);
1998  }
1999  else if(type == AAMP_EVENT_SPEEDS_CHANGED)
2000  {
2001  pListener = new AAMP_JSListener_SpeedsChanged(aamp, type, jsCallback);
2002  }
2003  else if (type == AAMP_EVENT_REPORT_ANOMALY)
2004  {
2005  pListener = new AAMP_JSListener_AnomalyReport(aamp, type, jsCallback);
2006  }
2007  else if (type == AAMP_EVENT_REPORT_METRICS_DATA)
2008  {
2009  pListener = new AAMP_JSListener_MetricsData(aamp, type, jsCallback);
2010  }
2011  else if (type == AAMP_EVENT_DRM_METADATA)
2012  {
2013  pListener = new AAMP_JSListener_DRMMetadata(aamp, type, jsCallback);
2014  }
2015  else if(type == AAMP_EVENT_AD_RESOLVED)
2016  {
2017  pListener = new AAMP_JSListener_AdResolved(aamp, type, jsCallback);
2018  }
2019  else if(type == AAMP_EVENT_AD_RESERVATION_START)
2020  {
2021  pListener = new AAMP_JSListener_AdReservationStart(aamp, type, jsCallback);
2022  }
2023  else if(type == AAMP_EVENT_AD_RESERVATION_END)
2024  {
2025  pListener = new AAMP_JSListener_AdReservationEnd(aamp, type, jsCallback);
2026  }
2027  else if(type == AAMP_EVENT_AD_PLACEMENT_START)
2028  {
2029  pListener = new AAMP_JSListener_AdPlacementStart(aamp, type, jsCallback);
2030  }
2031  else if(type == AAMP_EVENT_AD_PLACEMENT_END)
2032  {
2033  pListener = new AAMP_JSListener_AdPlacementEnd(aamp, type, jsCallback);
2034  }
2035  else if(type == AAMP_EVENT_AD_PLACEMENT_PROGRESS)
2036  {
2037  pListener = new AAMP_JSListener_AdProgress(aamp, type, jsCallback);
2038  }
2039  else if(type == AAMP_EVENT_AD_PLACEMENT_ERROR)
2040  {
2041  pListener = new AAMP_JSListener_AdPlacementEror(aamp, type, jsCallback);
2042  }
2043  else if(type == AAMP_EVENT_BUFFERING_CHANGED)
2044  {
2045  pListener = new AAMP_JSListener_BufferingChanged(aamp, type, jsCallback);
2046  }
2047  else if(type == AAMP_EVENT_ID3_METADATA)
2048  {
2049  pListener = new AAMP_JSListener_Id3Metadata(aamp, type, jsCallback);
2050  }
2051  else if(type == AAMP_EVENT_DRM_MESSAGE)
2052  {
2053  pListener = new AAMP_JSListener_DrmMessage(aamp, type, jsCallback);
2054  }
2056  {
2057  pListener = new AAMP_JSListener_ContentProtectionData(aamp, type, jsCallback);
2058  }
2059  else
2060  {
2061  pListener = new AAMP_JSListener(aamp, type, jsCallback);
2062  }
2063 
2064  pListener->_pNext = aamp->_listeners;
2065  aamp->_listeners = pListener;
2066  aamp->_aamp->AddEventListener(type, pListener);
2067 }
2068 
2069 
2070 /**
2071  * @brief Callback invoked from JS to remove an event listener
2072  * @param[in] context JS execution context
2073  * @param[in] function JSObject that is the function being called
2074  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2075  * @param[in] argumentCount number of args
2076  * @param[in] arguments[] JSValue array of args
2077  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2078  * @retval JSValue that is the function's return value
2079  */
2080 static JSValueRef AAMP_removeEventListener(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2081 {
2082  LOG_TRACE("Enter");
2083  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
2084  if (pAAMP == NULL)
2085  {
2086  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
2087  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.removeEventListener on instances of AAMP");
2088  return JSValueMakeUndefined(context);
2089  }
2090 
2091  if (argumentCount >= 2)
2092  {
2093  JSObjectRef callbackObj = JSValueToObject(context, arguments[1], NULL);
2094 
2095  if ((callbackObj != NULL) && (JSObjectIsFunction(context, callbackObj)))
2096  {
2097  char* type = aamp_JSValueToCString(context, arguments[0], NULL);
2098  AAMPEventType eventType = aamp_getEventTypeFromName(type);
2099  LOG_TRACE("eventType='%s', %d", type, eventType);
2100 
2101  if ((eventType >= 0) && (eventType < AAMP_MAX_NUM_EVENTS))
2102  {
2103 
2104  AAMP_JSListener::RemoveEventListener(pAAMP, eventType, callbackObj);
2105  }
2106  SAFE_DELETE_ARRAY(type);
2107  }
2108  else
2109  {
2110  LOG_ERROR_EX("InvalidArgument: callbackObj=%p, JSObjectIsFunction(context, callbackObj) is NULL", callbackObj);
2111  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.removeEventListener' - parameter 2 is not a function");
2112  }
2113  }
2114  else
2115  {
2116  LOG_ERROR_EX("InvalidArgument: argumentCount=%d, expected: 2", argumentCount);
2117  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.removeEventListener' - 2 arguments required.");
2118  }
2119 
2120  return JSValueMakeUndefined(context);
2121 }
2122 
2123 
2124 /**
2125  * @brief Removes a JS listener for a particular event
2126  * @param[in] aamp instance of AAMP_JS
2127  * @param[in] type event type
2128  * @param[in] jsCallback callback to be removed as listener
2129  */
2130 void AAMP_JSListener::RemoveEventListener(AAMP_JS* aamp, AAMPEventType type, JSObjectRef jsCallback)
2131 {
2132  LOG_TRACE("(%p, %d, %p)", aamp, type, jsCallback);
2133  AAMP_JSListener** ppListener = &aamp->_listeners;
2134  while (*ppListener != NULL)
2135  {
2136  AAMP_JSListener* pListener = *ppListener;
2137  if ((pListener->_type == type) && (pListener->_jsCallback == jsCallback))
2138  {
2139  *ppListener = pListener->_pNext;
2140  LOG_WARN_EX(" type=%d,pListener= %p", type, pListener);
2141  aamp->_aamp->RemoveEventListener(type, pListener);
2142  SAFE_DELETE(pListener);
2143  return;
2144  }
2145  ppListener = &pListener->_pNext;
2146  }
2147 }
2148 
2149 
2150 /**
2151  * @brief Callback invoked from JS to set AAMP object's properties
2152  * @param[in] context JS execution context
2153  * @param[in] function JSObject that is the function being called
2154  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2155  * @param[in] argumentCount number of args
2156  * @param[in] arguments[] JSValue array of args
2157  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2158  * @retval JSValue that is the function's return value
2159  */
2160 static JSValueRef AAMP_setProperties(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2161 {
2162  LOG_TRACE("Enter");
2163  return JSValueMakeUndefined(context);
2164 }
2165 
2166 
2167 /**
2168  * @brief Callback invoked from JS to get AAMP object's properties
2169  * @param[in] context JS execution context
2170  * @param[in] function JSObject that is the function being called
2171  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2172  * @param[in] argumentCount number of args
2173  * @param[in] arguments[] JSValue array of args
2174  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2175  * @retval JSValue that is the function's return value
2176  */
2177 static JSValueRef AAMP_getProperties(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2178 {
2179  LOG_TRACE("Enter");
2180  return JSValueMakeUndefined(context);
2181 }
2182 
2183 
2184 /**
2185  * @brief Callback invoked from JS to start playback for requested URL
2186  * @param[in] context JS execution context
2187  * @param[in] function JSObject that is the function being called
2188  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2189  * @param[in] argumentCount number of args
2190  * @param[in] arguments[] JSValue array of args
2191  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2192  * @retval JSValue that is the function's return value
2193  */
2194 static JSValueRef AAMP_tune(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2195 {
2196  LOG_TRACE("Enter");
2197  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
2198  if(!pAAMP)
2199  {
2200  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
2201  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.tune on instances of AAMP");
2202  return JSValueMakeUndefined(context);
2203  }
2204 
2205  char* contentType = NULL;
2206  bool bFinalAttempt = false;
2207  bool bFirstAttempt = true;
2208  switch(argumentCount)
2209  {
2210  case 4:
2211  {
2212  bFinalAttempt = JSValueToBoolean(context, arguments[3]);
2213  }
2214  case 3:
2215  {
2216  bFirstAttempt = JSValueToBoolean(context, arguments[2]);
2217  }
2218  case 2:
2219  {
2220  contentType = aamp_JSValueToCString(context, arguments[1], exception);
2221  }
2222  case 1:
2223  {
2224  char* url = aamp_JSValueToCString(context, arguments[0], exception);
2225  aamp_ApplyPageHttpHeaders(pAAMP->_aamp);
2226  {
2227  LOG_WARN(pAAMP," _aamp->Tune(%d, %s, %d, %d)", true, contentType, bFirstAttempt, bFinalAttempt);
2228  pAAMP->_aamp->Tune(url, true, contentType, bFirstAttempt, bFinalAttempt);
2229  }
2230  SAFE_DELETE_ARRAY(url);
2231  }
2232  SAFE_DELETE_ARRAY(contentType);
2233  break;
2234  default:
2235  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1 to 4", argumentCount);
2236  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.tune' - 1 argument required");
2237  break;
2238  }
2239  return JSValueMakeUndefined(context);
2240 }
2241 
2242 
2243 /**
2244  * @brief Callback invoked from JS to start playback for requested URL
2245  * @param[in] context JS execution context
2246  * @param[in] function JSObject that is the function being called
2247  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2248  * @param[in] argumentCount number of args
2249  * @param[in] arguments[] JSValue array of args
2250  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2251  * @retval JSValue that is the function's return value
2252  */
2253 static JSValueRef AAMP_load(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2254 {
2255  LOG_TRACE("Enter");
2256  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
2257  if(!pAAMP)
2258  {
2259  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
2260  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.load on instances of AAMP");
2261  return JSValueMakeUndefined(context);
2262  }
2263 
2264  if (argumentCount == 1 || argumentCount == 2)
2265  {
2266  char* contentType = NULL;
2267  char* strTraceId = NULL;
2268  char* strAuthToken = NULL;
2269  bool bFinalAttempt = false;
2270  bool bFirstAttempt = true;
2271  if (argumentCount == 2 && JSValueIsObject(context, arguments[1]))
2272  {
2273  JSObjectRef argument = JSValueToObject(context, arguments[1], NULL);
2274  JSStringRef paramName = JSStringCreateWithUTF8CString("contentType");
2275  JSValueRef paramValue = JSObjectGetProperty(context, argument, paramName, NULL);
2276  if (JSValueIsString(context, paramValue))
2277  {
2278  contentType = aamp_JSValueToCString(context, paramValue, NULL);
2279  }
2280  JSStringRelease(paramName);
2281 
2282  paramName = JSStringCreateWithUTF8CString("traceId");
2283  paramValue = JSObjectGetProperty(context, argument, paramName, NULL);
2284  if (JSValueIsString(context, paramValue))
2285  {
2286  strTraceId = aamp_JSValueToCString(context, paramValue, NULL);
2287  }
2288  JSStringRelease(paramName);
2289 
2290  paramName = JSStringCreateWithUTF8CString("isInitialAttempt");
2291  paramValue = JSObjectGetProperty(context, argument, paramName, NULL);
2292  if (JSValueIsBoolean(context, paramValue))
2293  {
2294  bFirstAttempt = JSValueToBoolean(context, paramValue);
2295  }
2296  JSStringRelease(paramName);
2297 
2298  paramName = JSStringCreateWithUTF8CString("isFinalAttempt");
2299  paramValue = JSObjectGetProperty(context, argument, paramName, NULL);
2300  if (JSValueIsBoolean(context, paramValue))
2301  {
2302  bFinalAttempt = JSValueToBoolean(context, paramValue);
2303  }
2304  JSStringRelease(paramName);
2305 
2306  paramName = JSStringCreateWithUTF8CString("authToken");
2307  paramValue = JSObjectGetProperty(context, argument, paramName, NULL);
2308  if (JSValueIsString(context, paramValue))
2309  {
2310  strAuthToken = aamp_JSValueToCString(context, paramValue, NULL);
2311  }
2312  JSStringRelease(paramName);
2313  }
2314 
2315  char* url = aamp_JSValueToCString(context, arguments[0], exception);
2316  aamp_ApplyPageHttpHeaders(pAAMP->_aamp);
2317  if (strAuthToken != NULL){
2318  LOG_WARN(pAAMP,"authToken provided by the App");
2319  pAAMP->_aamp->SetSessionToken(strAuthToken);
2320  }
2321  {
2322  LOG_WARN(pAAMP," _aamp->Tune(%d, %d, %d, %d, %d)", true, contentType, bFirstAttempt, bFinalAttempt, strTraceId);
2323  pAAMP->_aamp->Tune(url, true, contentType, bFirstAttempt, bFinalAttempt, strTraceId);
2324  }
2325 
2326  SAFE_DELETE_ARRAY(url);
2327  SAFE_DELETE_ARRAY(contentType);
2328  SAFE_DELETE_ARRAY(strTraceId);
2329  SAFE_DELETE_ARRAY(strAuthToken);
2330  }
2331  else
2332  {
2333  LOG_ERROR_EX("InvalidArgument: argumentCount=%d, expected: 1 or 2", argumentCount);
2334  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.load' - 1 or 2 argument required");
2335  }
2336  return JSValueMakeUndefined(context);
2337 }
2338 
2339 
2340 /**
2341  * @brief Callback invoked from JS to stop active playback
2342  * @param[in] context JS execution context
2343  * @param[in] function JSObject that is the function being called
2344  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2345  * @param[in] argumentCount number of args
2346  * @param[in] arguments[] JSValue array of args
2347  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2348  * @retval JSValue that is the function's return value
2349  */
2350 static JSValueRef AAMP_stop(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2351 {
2352 
2353  LOG_TRACE("Enter");
2354  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
2355  if(!pAAMP)
2356  {
2357  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
2358  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.stop on instances of AAMP");
2359  return JSValueMakeUndefined(context);
2360  }
2361  LOG_WARN(pAAMP," aamp->stop()");
2362  pAAMP->_aamp->Stop();
2363  return JSValueMakeUndefined(context);
2364 }
2365 
2366 
2367 /**
2368  * @brief Callback invoked from JS to set playback rate
2369  * @param[in] context JS execution context
2370  * @param[in] function JSObject that is the function being called
2371  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2372  * @param[in] argumentCount number of args
2373  * @param[in] arguments[] JSValue array of args
2374  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2375  * @retval JSValue that is the function's return value
2376  */
2377 static JSValueRef AAMP_setRate(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2378 {
2379  LOG_TRACE("Enter");
2380  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
2381  if(!pAAMP)
2382  {
2383  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
2384  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setRate on instances of AAMP");
2385  return JSValueMakeUndefined(context);
2386  }
2387 
2388  if (argumentCount < 1)
2389  {
2390  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 2", argumentCount);
2391  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setRate' - 2 arguments required");
2392  }
2393  else
2394  {
2395  int overshoot = 0;
2396  float rate = (float)JSValueToNumber(context, arguments[0], exception);
2397  // present JS doesnt support overshoot , check for arguement count and store.
2398  if(argumentCount > 1)
2399  {
2400  overshoot = (int)JSValueToNumber(context, arguments[1], exception);
2401  }
2402 
2403  LOG_WARN(pAAMP,"rate=%f, overshoot=%d", rate, overshoot);
2404  {
2405  LOG_WARN(pAAMP," _aamp->SetRate(%d, %d)", rate, overshoot);
2406  pAAMP->_aamp->SetRate(rate, overshoot);
2407  }
2408  }
2409  return JSValueMakeUndefined(context);
2410 }
2411 
2412 
2413 /**
2414  * @brief Callback invoked from JS to perform seek to a particular playback position
2415  * @param[in] context 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 static JSValueRef AAMP_seek(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2424 {
2425 
2426  LOG_TRACE("Enter");
2427  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
2428  if(!pAAMP)
2429  {
2430  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
2431  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.seek on instances of AAMP");
2432  return JSValueMakeUndefined(context);
2433  }
2434 
2435  if (argumentCount != 1)
2436  {
2437  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1",argumentCount);
2438  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.seek' - 1 argument required");
2439  }
2440  else
2441  {
2442  double position = JSValueToNumber(context, arguments[0], exception);
2443  {
2444 
2445  LOG_WARN(pAAMP,"_aamp->Seek(%g)",position);
2446  pAAMP->_aamp->Seek(position);
2447  }
2448  }
2449  return JSValueMakeUndefined(context);
2450 }
2451 
2452 
2453 
2454 /**
2455  * @brief Callback invoked from JS to perform seek to live point
2456  * @param[in] context JS execution context
2457  * @param[in] function JSObject that is the function being called
2458  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2459  * @param[in] argumentCount number of args
2460  * @param[in] arguments[] JSValue array of args
2461  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2462  * @retval JSValue that is the function's return value
2463  */
2464 static JSValueRef AAMP_seekToLive(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2465 {
2466  LOG_TRACE("Enter");
2467  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
2468  if(!pAAMP)
2469  {
2470  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
2471  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.seekToLive on instances of AAMP");
2472  return JSValueMakeUndefined(context);
2473  }
2474  {
2475  LOG_WARN(pAAMP," _aamp->SeekToLive()");
2476  pAAMP->_aamp->SeekToLive();
2477  }
2478  return JSValueMakeUndefined(context);
2479 }
2480 
2481 
2482 /**
2483  * @brief Callback invoked from JS to set video rectangle co-ordinates
2484  * @param[in] context JS execution context
2485  * @param[in] function JSObject that is the function being called
2486  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2487  * @param[in] argumentCount number of args
2488  * @param[in] arguments[] JSValue array of args
2489  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2490  * @retval JSValue that is the function's return value
2491  */
2492 static JSValueRef AAMP_setRect(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2493 {
2494  LOG_TRACE("Enter");
2495  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
2496  if(!pAAMP)
2497  {
2498  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
2499  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setRect on instances of AAMP");
2500  return JSValueMakeUndefined(context);
2501  }
2502 
2503  if (argumentCount != 4)
2504  {
2505  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 4", argumentCount);
2506  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setRect' - 4 arguments required");
2507  }
2508  else
2509  {
2510  int x = JSValueToNumber(context, arguments[0], exception);
2511  int y = JSValueToNumber(context, arguments[1], exception);
2512  int w = JSValueToNumber(context, arguments[2], exception);
2513  int h = JSValueToNumber(context, arguments[3], exception);
2514  {
2515  LOG_WARN(pAAMP," _aamp->SetVideoRectangle(%d, %d, %d, %d)", x,y,w,h);
2516  pAAMP->_aamp->SetVideoRectangle(x, y, w, h);
2517  }
2518  }
2519  return JSValueMakeUndefined(context);
2520 }
2521 
2522 
2523 /**
2524  * @brief Callback invoked from JS to set video mute status
2525  * @param[in] context 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 AAMP_setVideoMute(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2534 {
2535  LOG_TRACE("Enter");
2536  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
2537  if(!pAAMP)
2538  {
2539  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
2540  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setVideoMute on instances of AAMP");
2541  return JSValueMakeUndefined(context);
2542  }
2543 
2544  if (argumentCount != 1)
2545  {
2546 
2547  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
2548  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setVideoMute' - 1 argument required");
2549  }
2550  else
2551  {
2552  bool muted = JSValueToBoolean(context, arguments[0]);
2553  LOG_WARN(pAAMP," _aamp->SetVideoMute(%d)", muted);
2554  pAAMP->_aamp->SetVideoMute(muted);
2555  // pAAMP->_aamp->SetSubtitleMute(muted);
2556  }
2557  return JSValueMakeUndefined(context);
2558 }
2559 
2560 
2561 /**
2562  * @brief Callback invoked from JS to set audio volume
2563  * @param[in] context JS execution context
2564  * @param[in] function JSObject that is the function being called
2565  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2566  * @param[in] argumentCount number of args
2567  * @param[in] arguments[] JSValue array of args
2568  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2569  * @retval JSValue that is the function's return value
2570  */
2571 static JSValueRef AAMP_setAudioVolume(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2572 {
2573 
2574  LOG_TRACE("Enter");
2575  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
2576  if(!pAAMP)
2577  {
2578  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
2579  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setAudioVolume on instances of AAMP");
2580  return JSValueMakeUndefined(context);
2581  }
2582 
2583  if (argumentCount != 1)
2584  {
2585  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
2586  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setAudioVolume' - 1 argument required");
2587  }
2588  else
2589  {
2590  unsigned int volume = JSValueToNumber(context, arguments[0], exception);
2591  LOG_WARN(pAAMP," aamp->SetAudioVolume(%d)", volume);
2592  pAAMP->_aamp->SetAudioVolume(volume);
2593  }
2594  return JSValueMakeUndefined(context);
2595 }
2596 
2597 
2598 /**
2599  * @brief Callback invoked from JS to set preferred zoom setting
2600  * @param[in] context JS execution context
2601  * @param[in] function JSObject that is the function being called
2602  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2603  * @param[in] argumentCount number of args
2604  * @param[in] arguments[] JSValue array of args
2605  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2606  * @retval JSValue that is the function's return value
2607  */
2608 static JSValueRef AAMP_setZoom(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2609 {
2610  LOG_TRACE("Enter");
2611  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
2612  if(!pAAMP)
2613  {
2614 
2615  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
2616  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setZoom on instances of AAMP");
2617  return JSValueMakeUndefined(context);
2618  }
2619 
2620  if (argumentCount != 1)
2621  {
2622  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
2623  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setZoom' - 1 argument required");
2624  }
2625  else
2626  {
2627  VideoZoomMode zoom;
2628  char* zoomStr = aamp_JSValueToCString(context, arguments[0], exception);
2629  LOG_WARN(pAAMP,"zoomStr %s", zoomStr);
2630  if (0 == strcmp(zoomStr, "none"))
2631  {
2632  zoom = VIDEO_ZOOM_NONE;
2633  }
2634  else
2635  {
2636  zoom = VIDEO_ZOOM_FULL;
2637  }
2638  pAAMP->_aamp->SetVideoZoom(zoom);
2639  SAFE_DELETE_ARRAY(zoomStr);
2640  }
2641  return JSValueMakeUndefined(context);
2642 }
2643 
2644 
2645 /**
2646  * @brief Callback invoked from JS to set preferred audio language
2647  * @param[in] context JS execution context
2648  * @param[in] function JSObject that is the function being called
2649  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2650  * @param[in] argumentCount number of args
2651  * @param[in] arguments[] JSValue array of args
2652  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2653  * @retval JSValue that is the function's return value
2654  */
2655 static JSValueRef AAMP_setLanguage(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2656 {
2657 
2658  LOG_TRACE("Enter");
2659  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
2660  if(!pAAMP)
2661  {
2662  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
2663  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setLanguage on instances of AAMP");
2664  return JSValueMakeUndefined(context);
2665  }
2666 
2667  if (argumentCount != 1)
2668  {
2669  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
2670  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setLanguage' - 1 argument required");
2671  }
2672  else
2673  {
2674  char* lang = aamp_JSValueToCString(context, arguments[0], exception);
2675  {
2676  LOG_WARN(pAAMP," _aamp->SetLKanguage(%s)", lang);
2677  pAAMP->_aamp->SetLanguage(lang);
2678  }
2679  SAFE_DELETE_ARRAY(lang);
2680  }
2681  return JSValueMakeUndefined(context);
2682 }
2683 
2684 /**
2685  * @brief Callback invoked from JS to set list of subscribed tags
2686  * @param[in] context JS execution context
2687  * @param[in] function JSObject that is the function being called
2688  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2689  * @param[in] argumentCount number of args
2690  * @param[in] arguments[] JSValue array of args
2691  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2692  * @retval JSValue that is the function's return value
2693  */
2694 static JSValueRef AAMP_setSubscribeTags(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2695 {
2696 
2697  LOG_TRACE("Enter");
2698  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
2699  if(!pAAMP)
2700  {
2701  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
2702  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.subscribedTags on instances of AAMP");
2703  return JSValueMakeUndefined(context);
2704  }
2705 
2706  if (argumentCount != 1)
2707  {
2708  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
2709  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setSubscribeTags' - 1 argument required");
2710  }
2711  else if (!aamp_JSValueIsArray(context, arguments[0]))
2712  {
2713  LOG_ERROR(pAAMP,"InvalidArgument: aamp_JSValueIsArray=%d", aamp_JSValueIsArray(context, arguments[0]));
2714  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setSubscribeTags' - parameter 1 is not an array");
2715  }
2716  else
2717  {
2718  if(pAAMP->_subscribedTags)
2719  {
2720  JSValueUnprotect(pAAMP->_ctx, pAAMP->_subscribedTags);
2721  }
2722  pAAMP->_subscribedTags = JSValueToObject(context, arguments[0], NULL);
2723  if(pAAMP->_subscribedTags)
2724  {
2725  JSValueProtect(pAAMP->_ctx, pAAMP->_subscribedTags);
2726  std::vector<std::string> subscribedTags = aamp_StringArrayToCStringArray(context, arguments[0]);
2727  LOG_WARN(pAAMP," _aamp->SetSubscribedTags");
2728  pAAMP->_aamp->SetSubscribedTags(subscribedTags);
2729  }
2730  }
2731  return JSValueMakeUndefined(context);
2732 }
2733 
2734 
2735 /**
2736  * @brief Callback invoked from JS to add a custom HTTP header/s
2737  * @param[in] context JS execution context
2738  * @param[in] function JSObject that is the function being called
2739  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2740  * @param[in] argumentCount number of args
2741  * @param[in] arguments[] JSValue array of args
2742  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2743  * @retval JSValue that is the function's return value
2744  */
2745 static JSValueRef AAMP_addCustomHTTPHeader(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2746 {
2747 
2748  LOG_TRACE("Enter");
2749  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
2750  if(!pAAMP)
2751  {
2752 
2753  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
2754  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.addCustomHTTPHeader on instances of AAMP");
2755  return JSValueMakeUndefined(context);
2756  }
2757 
2758  if (argumentCount != 2)
2759  {
2760 
2761  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 2", argumentCount);
2762  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.addCustomHTTPHeader' - 2 argument required");
2763  }
2764  else
2765  {
2766  char *name = aamp_JSValueToCString(context, arguments[0], exception);
2767  std::string headerName(name);
2768  std::vector<std::string> headerVal;
2769 
2770  SAFE_DELETE_ARRAY(name);
2771 
2772  if (aamp_JSValueIsArray(context, arguments[1]))
2773  {
2774  headerVal = aamp_StringArrayToCStringArray(context, arguments[1]);
2775  }
2776  else if (JSValueIsString(context, arguments[1]))
2777  {
2778  headerVal.reserve(1);
2779  char *value = aamp_JSValueToCString(context, arguments[1], exception);
2780  headerVal.push_back(value);
2781  SAFE_DELETE_ARRAY(value);
2782  }
2783 
2784  // Don't support empty values now
2785  if (headerVal.size() == 0)
2786  {
2787 
2788  LOG_ERROR(pAAMP,"InvalidArgument: Custom header's value is empty");
2789  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.addCustomHTTPHeader' - 2nd argument should be a string or array of strings");
2790  return JSValueMakeUndefined(context);
2791  }
2792  LOG_WARN(pAAMP," _aamp->AddCustomHTTPHeader headerName= %s headerVal= %p",headerName.c_str(), headerVal);
2793  pAAMP->_aamp->AddCustomHTTPHeader(headerName, headerVal);
2794  }
2795  return JSValueMakeUndefined(context);
2796 }
2797 
2798 
2799 /**
2800  * @brief Callback invoked from JS to remove custom HTTP headers
2801  * @param[in] context JS execution context
2802  * @param[in] function JSObject that is the function being called
2803  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2804  * @param[in] argumentCount number of args
2805  * @param[in] arguments[] JSValue array of args
2806  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2807  * @retval JSValue that is the function's return value
2808  */
2809 static JSValueRef AAMP_removeCustomHTTPHeader(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2810 {
2811 
2812  LOG_TRACE("Enter");
2813  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
2814  if(!pAAMP)
2815  {
2816 
2817  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
2818  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.removeCustomHTTPHeader on instances of AAMP");
2819  return JSValueMakeUndefined(context);
2820  }
2821 
2822  if (argumentCount != 1)
2823  {
2824  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
2825  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.removeCustomHTTPHeader' - 1 argument required");
2826  }
2827  else
2828  {
2829  char *name = aamp_JSValueToCString(context, arguments[0], exception);
2830  std::string headerName(name);
2831  LOG_WARN(pAAMP," AAMP_removeCustomHTTPHeader headerName= %s",headerName.c_str());
2832  pAAMP->_aamp->AddCustomHTTPHeader(headerName, std::vector<std::string>());
2833  SAFE_DELETE_ARRAY(name);
2834 
2835  }
2836  return JSValueMakeUndefined(context);
2837 }
2838 
2839 
2840 /**
2841  * @brief Callback invoked from JS to set an ad
2842  * @param[in] context JS execution context
2843  * @param[in] function JSObject that is the function being called
2844  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2845  * @param[in] argumentCount number of args
2846  * @param[in] arguments[] JSValue array of args
2847  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2848  * @retval JSValue that is the function's return value
2849  */
2850 static JSValueRef AAMP_setAds(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2851 {
2852 
2853  LOG_TRACE("Enter");
2854  return JSValueMakeUndefined(context);
2855 }
2856 
2857 
2858 /**
2859  * @brief Callback invoked from JS to get list of audio tracks
2860  * @param[in] context JS execution context
2861  * @param[in] function JSObject that is the function being called
2862  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2863  * @param[in] argumentCount number of args
2864  * @param[in] arguments[] JSValue array of args
2865  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2866  * @retval JSValue that is the function's return value
2867  */
2868 static JSValueRef AAMP_getAvailableAudioTracks(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2869 {
2870 
2871  LOG_TRACE("Enter");
2872  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
2873  if(!pAAMP)
2874  {
2875 
2876  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
2877  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.getAvailableAudioTracks on instances of AAMP");
2878  return JSValueMakeUndefined(context);
2879  }
2880  bool allTrack = false;
2881  if (argumentCount == 1)
2882  {
2883  allTrack = JSValueToBoolean(context, arguments[0]);
2884  }
2885  std::string tracks = pAAMP->_aamp->GetAvailableAudioTracks(allTrack);
2886  if (!tracks.empty())
2887  {
2888  LOG_WARN(pAAMP,"Exit _aamp->GetAvailableAudioTracks(%d) tracks [%s]",allTrack,tracks.c_str());
2889  return aamp_CStringToJSValue(context, tracks.c_str());
2890  }
2891  else
2892  {
2893  LOG_WARN(pAAMP," _aamp->GetAvailableAudioTracks(%d) tracks=NULL", allTrack);
2894  return JSValueMakeUndefined(context);
2895  }
2896 }
2897 
2898 /**
2899  * @brief Callback invoked from JS to get current audio track
2900  * @param[in] context JS execution context
2901  * @param[in] function JSObject that is the function being called
2902  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2903  * @param[in] argumentCount number of args
2904  * @param[in] arguments[] JSValue array of args
2905  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2906  * @retval JSValue that is the function's return value
2907  */
2908 static JSValueRef AAMP_getAudioTrack(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2909 {
2910 
2911  LOG_TRACE("Enter");
2912  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
2913  if(!pAAMP)
2914  {
2915  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
2916  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.getAudioTrack on instances of AAMP");
2917  return JSValueMakeUndefined(context);
2918  }
2919  return JSValueMakeNumber(context, pAAMP->_aamp->GetAudioTrack());
2920 }
2921 
2922 /**
2923  * @brief Callback invoked from JS to get current audio track
2924  * @param[in] context JS execution context
2925  * @param[in] function JSObject that is the function being called
2926  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2927  * @param[in] argumentCount number of args
2928  * @param[in] arguments[] JSValue array of args
2929  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2930  * @retval JSValue that is the function's return value
2931  */
2932 static JSValueRef AAMP_getAudioTrackInfo(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2933 {
2934 
2935  LOG_TRACE("Enter");
2936  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
2937  if(!pAAMP)
2938  {
2939  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
2940  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.getAudioTrackInfo on instances of AAMP");
2941  return JSValueMakeUndefined(context);
2942  }
2943  LOG_INFO(pAAMP," _aamp->GetAudioTrackInfo()");
2944  std::string track = pAAMP->_aamp->GetAudioTrackInfo();
2945  if (!track.empty())
2946  {
2947  LOG_INFO(pAAMP," _aamp->GetAudioTrackInfo() [%s]",track.c_str());
2948  return aamp_CStringToJSValue(context, track.c_str());
2949  }
2950  else
2951  {
2952  LOG_WARN(pAAMP," _aamp->GetAudioTrackInfo() track=NULL");
2953  return JSValueMakeUndefined(context);
2954  }
2955 }
2956 
2957 /**
2958  * @brief Callback invoked from JS to get current text track info
2959  * @param[in] context JS execution context
2960  * @param[in] function JSObject that is the function being called
2961  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2962  * @param[in] argumentCount number of args
2963  * @param[in] arguments[] JSValue array of args
2964  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2965  * @retval JSValue that is the function's return value
2966  */
2967 static JSValueRef AAMP_getTextTrackInfo(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
2968 {
2969  LOG_TRACE("Enter");
2970  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
2971  if(!pAAMP)
2972  {
2973  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
2974  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.getTextTrackInfo on instances of AAMP");
2975  return JSValueMakeUndefined(context);
2976  }
2977  std::string track = pAAMP->_aamp->GetTextTrackInfo();
2978  if (!track.empty())
2979  {
2980  LOG_INFO(pAAMP,"_aamp->GetTextTrackInfo [%s]",track.c_str());
2981  return aamp_CStringToJSValue(context, track.c_str());
2982  }
2983  else
2984  { LOG_WARN(pAAMP,"_aamp->GetTextTrackInfo track=NULL");
2985  return JSValueMakeUndefined(context);
2986  }
2987 }
2988 
2989 /**
2990  * @brief Callback invoked from JS to get current audio track
2991  * @param[in] context JS execution context
2992  * @param[in] function JSObject that is the function being called
2993  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
2994  * @param[in] argumentCount number of args
2995  * @param[in] arguments[] JSValue array of args
2996  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
2997  * @retval JSValue that is the function's return value
2998  */
2999 static JSValueRef AAMP_getPreferredAudioProperties(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3000 {
3001 
3002  LOG_TRACE("Enter");
3003  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3004  if(!pAAMP)
3005  {
3006  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3007  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.getPreferredAudioProperties on instances of AAMP");
3008  return JSValueMakeUndefined(context);
3009  }
3010  std::string audioPreference = pAAMP->_aamp->GetPreferredAudioProperties();
3011  if (!audioPreference.empty())
3012  {
3013  LOG_INFO(pAAMP," _aamp->GetPreferredAudioProperties() [%s]",audioPreference.c_str());
3014  return aamp_CStringToJSValue(context, audioPreference.c_str());
3015  }
3016  else
3017  {
3018  LOG_WARN(pAAMP,"_aamp->GetPreferredAudioProperties() audioPreference=NULL");
3019  return JSValueMakeUndefined(context);
3020  }
3021 }
3022 
3023 /**
3024  * @brief Callback invoked from JS to set audio track
3025  * @param[in] context JS execution context
3026  * @param[in] function JSObject that is the function being called
3027  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3028  * @param[in] argumentCount number of args
3029  * @param[in] arguments[] JSValue array of args
3030  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3031  * @retval JSValue that is the function's return value
3032  */
3033 static JSValueRef AAMP_setAudioTrack(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3034 {
3035  LOG_TRACE("Enter");
3036  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3037  if(!pAAMP)
3038  {
3039  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3040  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setAudioTrack on instances of AAMP");
3041  return JSValueMakeUndefined(context);
3042  }
3043 
3044  if (argumentCount != 1)
3045  {
3046  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3047  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setAudioTrack' - 1 argument required");
3048  }
3049  else
3050  {
3051  int index = (int) JSValueToNumber(context, arguments[0], NULL);
3052  if (index >= 0)
3053  {
3054  {
3055  LOG_WARN(pAAMP," _aamp->SetAudioTrack(%d)", index);
3056  pAAMP->_aamp->SetAudioTrack(index);
3057  }
3058  }
3059  else
3060  {
3061  LOG_ERROR(pAAMP,"InvalidArgument: Track index should be >= 0!");
3062  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setAudioTrack' - argument should be >= 0");
3063  }
3064  }
3065  return JSValueMakeUndefined(context);
3066 }
3067 
3068 /**
3069  * @brief Callback invoked from JS to get preferred text properties
3070  * @param[in] context JS execution context
3071  * @param[in] function JSObject that is the function being called
3072  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3073  * @param[in] argumentCount number of args
3074  * @param[in] arguments[] JSValue array of args
3075  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3076  * @retval JSValue that is the function's return value
3077  */
3078 static JSValueRef AAMP_getPreferredTextProperties(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3079 {
3080 
3081  LOG_TRACE("Enter");
3082  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3083  if(!pAAMP)
3084  {
3085 
3086  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3087  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.getPreferredTextProperties on instances of AAMP");
3088  return JSValueMakeUndefined(context);
3089  }
3090  std::string textPreference = pAAMP->_aamp->GetPreferredTextProperties();
3091  if (!textPreference.empty())
3092  {
3093  LOG_INFO(pAAMP," _aamp->GetPreferredTextProperties() [%s]",textPreference.c_str());
3094  return aamp_CStringToJSValue(context, textPreference.c_str());
3095  }
3096  else
3097  {
3098  LOG_WARN(pAAMP," _aamp->GetPreferredTextProperties() textPreference=NULL");
3099  return JSValueMakeUndefined(context);
3100  }
3101 }
3102 
3103 /**
3104  * @brief Callback invoked from JS to get list of text tracks
3105  * @param[in] context JS execution context
3106  * @param[in] function JSObject that is the function being called
3107  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3108  * @param[in] argumentCount number of args
3109  * @param[in] arguments[] JSValue array of args
3110  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3111  * @retval JSValue that is the function's return value
3112  */
3113 static JSValueRef AAMP_getAvailableTextTracks(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3114 {
3115 
3116  LOG_TRACE("Enter");
3117  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3118  if(!pAAMP)
3119  {
3120  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3121  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.getAvailableTextTracks on instances of AAMP");
3122  return JSValueMakeUndefined(context);
3123  }
3124  bool allTrack = false;
3125  if (argumentCount == 1)
3126  {
3127  allTrack = JSValueToBoolean(context, arguments[0]);
3128  }
3129  std::string tracks = pAAMP->_aamp->GetAvailableTextTracks(allTrack);
3130  if (!tracks.empty())
3131  {
3132  LOG_WARN(pAAMP,"_aamp->GetAvailableTextTracks(%d) [%s]",allTrack,tracks.c_str());
3133  return aamp_CStringToJSValue(context, tracks.c_str());
3134  }
3135  else
3136  {
3137  LOG_WARN(pAAMP,"_aamp->GetAvailableTextTracks(%d) tracks=NULL",allTrack);
3138  return JSValueMakeUndefined(context);
3139  }
3140 }
3141 
3142 
3143 /**
3144  * @brief Callback invoked from JS to get current text track index
3145  * @param[in] context JS execution context
3146  * @param[in] function JSObject that is the function being called
3147  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3148  * @param[in] argumentCount number of args
3149  * @param[in] arguments[] JSValue array of args
3150  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3151  * @retval JSValue that is the function's return value
3152  */
3153 static JSValueRef AAMP_getTextTrack(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3154 {
3155  LOG_TRACE("Enter");
3156  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3157  if(!pAAMP)
3158  {
3159  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3160  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.getTextTrack on instances of AAMP");
3161  return JSValueMakeUndefined(context);
3162  }
3163  LOG_INFO(pAAMP," _aamp->GetTextTrack()");
3164  return JSValueMakeNumber(context, pAAMP->_aamp->GetTextTrack());
3165 }
3166 
3167 
3168 /**
3169  * @brief Callback invoked from JS to set text track
3170  * @param[in] context JS execution context
3171  * @param[in] function JSObject that is the function being called
3172  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3173  * @param[in] argumentCount number of args
3174  * @param[in] arguments[] JSValue array of args
3175  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3176  * @retval JSValue that is the function's return value
3177  */
3178 static JSValueRef AAMP_setTextTrack(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3179 {
3180  LOG_TRACE("Enter");
3181  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3182  if(!pAAMP)
3183  {
3184  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3185  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setTextTrack on instances of AAMP");
3186  return JSValueMakeUndefined(context);
3187  }
3188 
3189  if (argumentCount != 1)
3190  {
3191  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1 or 2", argumentCount);
3192  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setTextTrack' - atleast 1 argument required");
3193  }
3194  else
3195  {
3196  int index = (int) JSValueToNumber(context, arguments[0], NULL);
3197  if (index >= MUTE_SUBTITLES_TRACKID) // -1 disable subtitles, >= 0 subtitle track index
3198  {
3199  LOG_WARN(pAAMP," _aamp->SetTextTrack(%d)", index);
3200  pAAMP->_aamp->SetTextTrack(index);
3201  }
3202  else
3203  {
3204  LOG_ERROR(pAAMP,"InvalidArgument - track index should be >= 0!");
3205  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Text track index should be >= -1 !");
3206  }
3207  }
3208  return JSValueMakeUndefined(context);
3209 }
3210 
3211 /**
3212  * @brief Callback invoked from JS to get list of video tracks
3213  * @param[in] context JS execution context
3214  * @param[in] function JSObject that is the function being called
3215  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3216  * @param[in] argumentCount number of args
3217  * @param[in] arguments[] JSValue array of args
3218  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3219  * @retval JSValue that is the function's return value
3220  */
3221 static JSValueRef AAMP_getAvailableVideoTracks(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3222 {
3223  LOG_TRACE("Enter");
3224  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3225  if(!pAAMP)
3226  {
3227  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3228  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.getAvailableAudioTracks on instances of AAMP");
3229  return JSValueMakeUndefined(context);
3230  }
3231  std::string tracks = pAAMP->_aamp->GetAvailableVideoTracks();
3232  if (!tracks.empty())
3233  {
3234  LOG_INFO(pAAMP," _aamp->GetAvailableVideoTracks()[%s]",tracks.c_str());
3235  return aamp_CStringToJSValue(context, tracks.c_str());
3236  }
3237  else
3238  {
3239  LOG_INFO(pAAMP," _aamp->GetAvailableVideoTracks() tracks=NULL");
3240  return JSValueMakeUndefined(context);
3241  }
3242 }
3243 
3244 /**
3245  * @brief Callback invoked from JS to set video track
3246  * @param[in] context JS execution context
3247  * @param[in] function JSObject that is the function being called
3248  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3249  * @param[in] argumentCount number of args
3250  * @param[in] arguments[] JSValue array of args
3251  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3252  * @retval JSValue that is the function's return value
3253  */
3254 static JSValueRef AAMP_setVideoTracks(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3255 {
3256  LOG_TRACE("Enter");
3257  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3258  if(!pAAMP)
3259  {
3260  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3261  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setVideoTrack on instances of AAMP");
3262  return JSValueMakeUndefined(context);
3263  }
3264 
3265  std::vector<long> bitrateList;
3266  for (int i = 0; i < argumentCount; i++)
3267  {
3268  long bitrate = JSValueToNumber(context, arguments[i], exception) ;
3269  LOG_WARN(pAAMP,"_aamp->SetVideoTracks argCount:%d value:%ld",i, bitrate);
3270  bitrateList.push_back(bitrate);
3271  }
3272  pAAMP->_aamp->SetVideoTracks(bitrateList);
3273 
3274  return JSValueMakeUndefined(context);
3275 }
3276 
3277 /**
3278  * @brief Callback invoked from JS to set license server URL
3279  * @param[in] context JS execution context
3280  * @param[in] function JSObject that is the function being called
3281  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3282  * @param[in] argumentCount number of args
3283  * @param[in] arguments[] JSValue array of args
3284  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3285  * @retval JSValue that is the function's return value
3286  */
3287 static JSValueRef AAMP_setLicenseServerURL(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3288 {
3289  LOG_TRACE("Enter");
3290  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3291  if (!pAAMP)
3292  {
3293  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3294  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setLicenseServerURL on instances of AAMP");
3295  return JSValueMakeUndefined(context);
3296  }
3297 
3298  if (argumentCount != 1)
3299  {
3300  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1",argumentCount);
3301  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setLicenseServerURL' - 1 argument required");
3302  }
3303  else
3304  {
3305  const char *url = aamp_JSValueToCString(context, arguments[0], exception);
3306  LOG_WARN(pAAMP," _aamp->SetLicenseServerURL(%s)", url);
3307  pAAMP->_aamp->SetLicenseServerURL(url);
3308  SAFE_DELETE_ARRAY(url);
3309  }
3310  return JSValueMakeUndefined(context);
3311 }
3312 
3313 
3314 /**
3315  * @brief Callback invoked from JS to set the preferred DRM
3316  * @param[in] context JS execution context
3317  * @param[in] function JSObject that is the function being called
3318  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3319  * @param[in] argumentCount number of args
3320  * @param[in] arguments[] JSValue array of args
3321  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3322  * @retval JSValue that is the function's return value
3323  */
3324 static JSValueRef AAMP_setPreferredDRM(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3325 {
3326  LOG_TRACE("Enter");
3327  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3328  if (!pAAMP)
3329  {
3330  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3331  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setPreferredDRM on instances of AAMP");
3332  return JSValueMakeUndefined(context);
3333  }
3334 
3335  if (argumentCount != 1)
3336  {
3337  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1",argumentCount);
3338  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setPreferredDRM' - 1 argument required");
3339  }
3340  else
3341  {
3342  const char *drm = aamp_JSValueToCString(context, arguments[0], exception);
3343  if (strncasecmp(drm, "widevine", 8) == 0)
3344  {
3345  LOG_WARN(pAAMP,"_aamp->SetPreferredDRM WideWine");
3346  pAAMP->_aamp->SetPreferredDRM(eDRM_WideVine);
3347  }
3348  if (strncasecmp(drm, "playready", 9) == 0)
3349  {
3350  LOG_WARN(pAAMP,"_aamp->SetPreferredDRM PlayReady");
3351  pAAMP->_aamp->SetPreferredDRM(eDRM_PlayReady);
3352  }
3353  SAFE_DELETE_ARRAY(drm);
3354  }
3355  return JSValueMakeUndefined(context);
3356 }
3357 
3358 /**
3359  * @brief Callback invoked from JS to en/disable anonymous request
3360  * @param[in] context JS execution context
3361  * @param[in] function JSObject that is the function being called
3362  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3363  * @param[in] argumentCount number of args
3364  * @param[in] arguments[] JSValue array of args
3365  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3366  * @retval JSValue that is the function's return value
3367  */
3368 static JSValueRef AAMP_setAnonymousRequest(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3369 {
3370  LOG_TRACE("Enter");
3371  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3372  if (!pAAMP)
3373  {
3374  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3375  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setAnonymousRequest on instances of AAMP");
3376  return JSValueMakeUndefined(context);
3377  }
3378 
3379  if (argumentCount != 1)
3380  {
3381  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3382  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setAnonymousRequest' - 1 argument required");
3383  }
3384  else
3385  {
3386  bool isAnonymousReq = JSValueToBoolean(context, arguments[0]);
3387  LOG_WARN(pAAMP," _aamp->SetAnonymousRequest(%d)", isAnonymousReq);
3388  pAAMP->_aamp->SetAnonymousRequest(isAnonymousReq);
3389  }
3390  return JSValueMakeUndefined(context);
3391 }
3392 
3393 
3394 /**
3395  * @brief Callback invoked from JS to set vod trickplay FPS
3396  * @param[in] context JS execution context
3397  * @param[in] function JSObject that is the function being called
3398  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3399  * @param[in] argumentCount number of args
3400  * @param[in] arguments[] JSValue array of args
3401  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3402  * @retval JSValue that is the function's return value
3403  */
3404 static JSValueRef AAMP_setVODTrickplayFPS(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3405 {
3406  LOG_TRACE("Enter");
3407  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3408  if (!pAAMP)
3409  {
3410  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3411  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setAnonymousRequest on instances of AAMP");
3412  return JSValueMakeUndefined(context);
3413  }
3414 
3415  if (argumentCount != 1)
3416  {
3417  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3418  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setAnonymousRequest' - 1 argument required");
3419  }
3420  else
3421  {
3422  int vodTrickplayFPS = (int)JSValueToNumber(context, arguments[0], exception);
3423  LOG_WARN(pAAMP," _aamp->SetVODTrickplayFPS(%d)", vodTrickplayFPS);
3424  pAAMP->_aamp->SetVODTrickplayFPS(vodTrickplayFPS);
3425  }
3426  return JSValueMakeUndefined(context);
3427 }
3428 
3429 /**
3430  * @brief Callback invoked from JS to set alternate playback content URLs
3431  *
3432  * @param[in] context JS execution context
3433  * @param[in] function JSObject that is the function being called
3434  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3435  * @param[in] argumentCount number of args
3436  * @param[in] arguments[] JSValue array of args
3437  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3438  *
3439  * @retval JSValue that is the function's return value
3440  */
3441 static JSValueRef AAMP_setAlternateContent(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3442 {
3443 
3444  LOG_TRACE("Enter");
3445  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3446  if(!pAAMP)
3447  {
3448  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3449  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.SetAlternateContents() on instances of AAMP");
3450  return JSValueMakeUndefined(context);
3451  }
3452 
3453  if (argumentCount != 2)
3454  {
3455  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 2", argumentCount);
3456  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.SetAlternateContent' - 1 argument required");
3457  }
3458  else
3459  {
3460  /*
3461  * Parmater format
3462  "reservationObject": object {
3463  "reservationId": "773701056",
3464  "reservationBehavior": number
3465  "placementRequest": {
3466  "id": string,
3467  "pts": number,
3468  "url": "",
3469  },
3470  },
3471  "promiseCallback": function
3472  */
3473  char *reservationId = NULL;
3474  int reservationBehavior = -1;
3475  char *adId = NULL;
3476  long adPTS = -1;
3477  char *adURL = NULL;
3478  if (JSValueIsObject(context, arguments[0]))
3479  {
3480  //Parse the ad object
3481  JSObjectRef reservationObject = JSValueToObject(context, arguments[0], NULL);
3482  if (reservationObject == NULL)
3483  {
3484  LOG_ERROR(pAAMP,"Unable to convert argument to JSObject");
3485  return JSValueMakeUndefined(context);
3486  }
3487  JSStringRef propName = JSStringCreateWithUTF8CString("reservationId");
3488  JSValueRef propValue = JSObjectGetProperty(context, reservationObject, propName, NULL);
3489  if (JSValueIsString(context, propValue))
3490  {
3491  reservationId = aamp_JSValueToCString(context, propValue, NULL);
3492  }
3493  JSStringRelease(propName);
3494 
3495  propName = JSStringCreateWithUTF8CString("reservationBehavior");
3496  propValue = JSObjectGetProperty(context, reservationObject, propName, NULL);
3497  if (JSValueIsNumber(context, propValue))
3498  {
3499  reservationBehavior = JSValueToNumber(context, propValue, NULL);
3500  }
3501  JSStringRelease(propName);
3502 
3503  propName = JSStringCreateWithUTF8CString("placementRequest");
3504  propValue = JSObjectGetProperty(context, reservationObject, propName, NULL);
3505  if (JSValueIsObject(context, propValue))
3506  {
3507  JSObjectRef adObject = JSValueToObject(context, propValue, NULL);
3508 
3509  JSStringRef adPropName = JSStringCreateWithUTF8CString("id");
3510  JSValueRef adPropValue = JSObjectGetProperty(context, adObject, adPropName, NULL);
3511  if (JSValueIsString(context, adPropValue))
3512  {
3513  adId = aamp_JSValueToCString(context, adPropValue, NULL);
3514  }
3515  JSStringRelease(adPropName);
3516 
3517  adPropName = JSStringCreateWithUTF8CString("pts");
3518  adPropValue = JSObjectGetProperty(context, adObject, adPropName, NULL);
3519  if (JSValueIsNumber(context, adPropValue))
3520  {
3521  adPTS = (long) JSValueToNumber(context, adPropValue, NULL);
3522  }
3523  JSStringRelease(adPropName);
3524 
3525  adPropName = JSStringCreateWithUTF8CString("url");
3526  adPropValue = JSObjectGetProperty(context, adObject, adPropName, NULL);
3527  if (JSValueIsString(context, adPropValue))
3528  {
3529  adURL = aamp_JSValueToCString(context, adPropValue, NULL);
3530  }
3531  JSStringRelease(adPropName);
3532  }
3533  JSStringRelease(propName);
3534  }
3535 
3536  JSObjectRef callbackObj = JSValueToObject(context, arguments[1], NULL);
3537 
3538  if (callbackObj != NULL && JSObjectIsFunction(context, callbackObj) && reservationId && adId && adURL)
3539  {
3540  if (pAAMP->_promiseCallback)
3541  {
3542  JSValueUnprotect(context, pAAMP->_promiseCallback);
3543  }
3544  pAAMP->_promiseCallback = callbackObj;
3545  JSValueProtect(context, pAAMP->_promiseCallback);
3546  std::string adBreakId(reservationId); //CID:89434 - Resolve Forward null
3547  std::string adIdStr(adId); //CID:89725 - Resolve Forward null
3548  std::string url(adURL); //CID:86272 - Resolve Forward null
3549  LOG_WARN(pAAMP,"pAAMP->_aamp->SetAlternateContents with promiseCallback:%p", callbackObj);
3550  pAAMP->_aamp->SetAlternateContents(adBreakId, adIdStr, url);
3551  }
3552  else
3553  {
3554  LOG_ERROR(pAAMP,"Unable to parse the promiseCallback argument");
3555 
3556  }
3557  SAFE_DELETE_ARRAY(reservationId);
3558  SAFE_DELETE_ARRAY(adURL);
3559  SAFE_DELETE_ARRAY(adId);
3560  }
3561  return JSValueMakeUndefined(context);
3562 }
3563 
3564 /**
3565  * @brief Notify AAMP that the reservation is complete
3566  *
3567  * @param[in] context JS execution context
3568  * @param[in] function JSObject that is the function being called
3569  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3570  * @param[in] argumentCount number of args
3571  * @param[in] arguments[] JSValue array of args
3572  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3573  *
3574  * @retval JSValue that is the function's return value
3575  */
3576 static JSValueRef AAMP_notifyReservationCompletion(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3577 {
3578  LOG_TRACE("Enter");
3579  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3580  if(!pAAMP)
3581  {
3582  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3583  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.notifyReservationCompletion() on instances of AAMP");
3584  return JSValueMakeUndefined(context);
3585  }
3586 
3587  if (argumentCount != 2)
3588  {
3589  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 2", argumentCount);
3590  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.notifyReservationCompletion' - 1 argument required");
3591  }
3592  else
3593  {
3594  const char * reservationId = aamp_JSValueToCString(context, arguments[0], exception);
3595  long time = (long) JSValueToNumber(context, arguments[1], exception);
3596  //Need an API in AAMP to notify that placements for this reservation are over and AAMP might have to trim
3597  //the ads to the period duration or not depending on time param
3598  LOG_WARN(pAAMP,"Called reservation close for periodId:%s and time:%ld", reservationId, time);
3599  SAFE_DELETE_ARRAY(reservationId);
3600  }
3601  return JSValueMakeUndefined(context);
3602 }
3603 
3604 /**
3605  * @brief Callback invoked from JS to set linear trickplay FPS
3606  * @param[in] context JS execution context
3607  * @param[in] function JSObject that is the function being called
3608  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3609  * @param[in] argumentCount number of args
3610  * @param[in] arguments[] JSValue array of args
3611  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3612  * @retval JSValue that is the function's return value
3613  */
3614 static JSValueRef AAMP_setLinearTrickplayFPS(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3615 {
3616  LOG_TRACE("Enter");
3617  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3618  if (!pAAMP)
3619  {
3620  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3621  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setAnonymousRequest on instances of AAMP");
3622  return JSValueMakeUndefined(context);
3623  }
3624 
3625  if (argumentCount != 1)
3626  {
3627  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3628  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setAnonymousRequest' - 1 argument required");
3629  }
3630  else
3631  {
3632  int linearTrickplayFPS = (int)JSValueToNumber(context, arguments[0], exception);
3633  LOG_WARN(pAAMP," _aamp->SetLinearTrickplayFPS(%d)", linearTrickplayFPS);
3634  pAAMP->_aamp->SetLinearTrickplayFPS(linearTrickplayFPS);
3635  }
3636  return JSValueMakeUndefined(context);
3637 }
3638 
3639 
3640 /**
3641  * @brief Callback invoked from JS to set live offset
3642  *
3643  * @param[in] context JS execution context
3644  * @param[in] function JSObject that is the function being called
3645  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3646  * @param[in] argumentCount number of args
3647  * @param[in] arguments[] JSValue array of args
3648  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3649  *
3650  * @retval JSValue that is the function's return value
3651  */
3652 static JSValueRef AAMP_setLiveOffset(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3653 {
3654  LOG_TRACE("Enter");
3655  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3656  if (!pAAMP)
3657  {
3658  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3659  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setLiveOffset on instances of AAMP");
3660  return JSValueMakeUndefined(context);
3661  }
3662 
3663  if (argumentCount != 1)
3664  {
3665  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3666  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setLiveOffset' - 1 argument required");
3667  }
3668  else
3669  {
3670  double liveOffset = (double)JSValueToNumber(context, arguments[0], exception);
3671  LOG_WARN(pAAMP," _aamp->SetLiveOffset(%lf)", liveOffset);
3672  pAAMP->_aamp->SetLiveOffset(liveOffset);
3673  }
3674  return JSValueMakeUndefined(context);
3675 }
3676 
3677 /**
3678  * @brief Callback invoked from JS to set live offset for 4K
3679  *
3680  * @param[in] context JS execution context
3681  * @param[in] function JSObject that is the function being called
3682  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3683  * @param[in] argumentCount number of args
3684  * @param[in] arguments[] JSValue array of args
3685  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3686  *
3687  * @retval JSValue that is the function's return value
3688  */
3689 static JSValueRef AAMP_setLiveOffset4K(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3690 {
3691  LOG_TRACE("Enter");
3692  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3693  if (!pAAMP)
3694  {
3695  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3696  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setLiveOffset4K on instances of AAMP");
3697  return JSValueMakeUndefined(context);
3698  }
3699 
3700  if (argumentCount != 1)
3701  {
3702  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3703  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setLiveOffset4K' - 1 argument required");
3704  }
3705  else
3706  {
3707  double liveOffset = (double)JSValueToNumber(context, arguments[0], exception);
3708  LOG_WARN(pAAMP," _aamp->SetLiveOffset4K(%lf)",liveOffset);
3709  pAAMP->_aamp->SetLiveOffset4K(liveOffset);
3710  }
3711  return JSValueMakeUndefined(context);
3712 }
3713 
3714 /**
3715  * @brief Callback invoked from JS to set download stall timeout value
3716  *
3717  * @param[in] context JS execution context
3718  * @param[in] function JSObject that is the function being called
3719  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3720  * @param[in] argumentCount number of args
3721  * @param[in] arguments[] JSValue array of args
3722  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3723  *
3724  * @retval JSValue that is the function's return value
3725  */
3726 static JSValueRef AAMP_setDownloadStallTimeout(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3727 {
3728  LOG_TRACE("Enter");
3729  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3730  if (!pAAMP)
3731  {
3732  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3733  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setDownloadStallTimeout on instances of AAMP");
3734  return JSValueMakeUndefined(context);
3735  }
3736 
3737  if (argumentCount != 1)
3738  {
3739  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3740  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setDownloadStallTimeout' - 1 argument required");
3741  }
3742  else
3743  {
3744  long stallTimeout = (long)JSValueToNumber(context, arguments[0], exception);
3745  LOG_WARN(pAAMP," _aamp->SetDownloadStallTimeout(%ld)",stallTimeout);
3746  pAAMP->_aamp->SetDownloadStallTimeout(stallTimeout);
3747  }
3748 
3749  return JSValueMakeUndefined(context);
3750 }
3751 
3752 
3753 /**
3754  * @brief Callback invoked from JS to set download start timeout value
3755  *
3756  * @param[in] context JS execution context
3757  * @param[in] function JSObject that is the function being called
3758  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3759  * @param[in] argumentCount number of args
3760  * @param[in] arguments[] JSValue array of args
3761  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3762  *
3763  * @retval JSValue that is the function's return value
3764  */
3765 static JSValueRef AAMP_setDownloadStartTimeout(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3766 {
3767  LOG_TRACE("Enter");
3768  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3769  if (!pAAMP)
3770  {
3771  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3772  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setDownlodStartTimeout on instances of AAMP");
3773  return JSValueMakeUndefined(context);
3774  }
3775 
3776  if (argumentCount != 1)
3777  {
3778  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3779  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setDownloadStartTimeout' - 1 argument required");
3780  }
3781  else
3782  {
3783  long startTimeout = (long)JSValueToNumber(context, arguments[0], exception);
3784  LOG_WARN(pAAMP,"SetDownloadStartTimeout %ld",startTimeout);
3785  pAAMP->_aamp->SetDownloadStartTimeout(startTimeout);
3786  }
3787 
3788  return JSValueMakeUndefined(context);
3789 }
3790 
3791 
3792 /**
3793  * @brief Callback invoked from JS to set network timeout value
3794  *
3795  * @param[in] context JS execution context
3796  * @param[in] function JSObject that is the function being called
3797  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3798  * @param[in] argumentCount number of args
3799  * @param[in] arguments[] JSValue array of args
3800  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3801  *
3802  * @retval JSValue that is the function's return value
3803  */
3804 static JSValueRef AAMP_setNetworkTimeout(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3805 {
3806  LOG_TRACE("Enter");
3807  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3808  if (!pAAMP)
3809  {
3810  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3811  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setNetworkTimeout on instances of AAMP");
3812  return JSValueMakeUndefined(context);
3813  }
3814 
3815  if (argumentCount != 1)
3816  {
3817 
3818  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3819  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setNetworkTimeout' - 1 argument required");
3820  }
3821  else
3822  {
3823  double networkTimeout = (double)JSValueToNumber(context, arguments[0], exception);
3824  LOG_WARN(pAAMP," _aamp->SetNetworkTimeout %lf",networkTimeout);
3825  pAAMP->_aamp->SetNetworkTimeout(networkTimeout);
3826  }
3827 
3828  return JSValueMakeUndefined(context);
3829 }
3830 
3831 
3832 /**
3833  * @brief Callback invoked from JS to enable/disable CC rendering
3834  * @param[in] context JS execution context
3835  * @param[in] function JSObject that is the function being called
3836  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3837  * @param[in] argumentCount number of args
3838  * @param[in] arguments[] JSValue array of args
3839  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3840  * @retval JSValue that is the function's return value
3841  */
3842 static JSValueRef AAMP_setClosedCaptionStatus(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3843 {
3844  LOG_TRACE("Enter");
3845  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3846  if(!pAAMP)
3847  {
3848  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3849  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setClosedCaptionStatus on instances of AAMP");
3850  return JSValueMakeUndefined(context);
3851  }
3852 
3853  if (argumentCount != 1)
3854  {
3855  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3856  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setClosedCaptionStatus' - 1 argument required");
3857  }
3858  else
3859  {
3860  bool enabled = JSValueToBoolean(context, arguments[0]);
3861  LOG_WARN(pAAMP,"_aamp->SetCCStatus(%d)", enabled);
3862  pAAMP->_aamp->SetCCStatus(enabled);
3863  }
3864  return JSValueMakeUndefined(context);
3865 }
3866 
3867 
3868 /**
3869  * @brief Callback invoked from JS to set text style
3870  * @param[in] context JS execution context
3871  * @param[in] function JSObject that is the function being called
3872  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3873  * @param[in] argumentCount number of args
3874  * @param[in] arguments[] JSValue array of args
3875  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3876  * @retval JSValue that is the function's return value
3877  */
3878 static JSValueRef AAMP_setTextStyleOptions(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3879 {
3880  LOG_TRACE("Enter");
3881  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3882  if(!pAAMP)
3883  {
3884  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3885  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setTextStyleOptions on instances of AAMP");
3886  return JSValueMakeUndefined(context);
3887  }
3888 
3889  if (argumentCount != 1)
3890  {
3891  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3892  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setTextStyleOptions' - 1 argument required");
3893  }
3894  else
3895  {
3896  if (JSValueIsString(context, arguments[0]))
3897  {
3898  const char *options = aamp_JSValueToCString(context, arguments[0], NULL);
3899  LOG_WARN(pAAMP,"_aamp->SetTextStyle(%s)", options);
3900  pAAMP->_aamp->SetTextStyle(std::string(options));
3901  SAFE_DELETE_ARRAY(options);
3902 
3903  }
3904  else
3905  {
3906  LOG_ERROR(pAAMP,"InvalidArgument: Argument should be JSON formatted string");
3907  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setTextStyleOptions' - argument should be JSON formatted string");
3908  }
3909  }
3910  return JSValueMakeUndefined(context);
3911 }
3912 
3913 
3914 /**
3915  * @brief Callback invoked from JS to get text style
3916  * @param[in] context JS execution context
3917  * @param[in] function JSObject that is the function being called
3918  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3919  * @param[in] argumentCount number of args
3920  * @param[in] arguments[] JSValue array of args
3921  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3922  * @retval JSValue that is the function's return value
3923  */
3924 static JSValueRef AAMP_getTextStyleOptions(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3925 {
3926  LOG_TRACE("Enter");
3927  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3928  if(!pAAMP)
3929  {
3930  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3931  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.getTextStyleOptions on instances of AAMP");
3932  return JSValueMakeUndefined(context);
3933  }
3934  std::string options = pAAMP->_aamp->GetTextStyle();
3935  if (!options.empty())
3936  {
3937  LOG_INFO(pAAMP,"_aamp->GetTextStyle() [%s]",options.c_str());
3938  return aamp_CStringToJSValue(context, options.c_str());
3939  }
3940  else
3941  {
3942  LOG_WARN(pAAMP,"_aamp->GetTextStyle() options=NULL");
3943  return JSValueMakeUndefined(context);
3944  }
3945 }
3946 
3947 
3948 /**
3949  * @brief Callback invoked from JS to set the preferred language format
3950  * @param[in] context JS execution context
3951  * @param[in] function JSObject that is the function being called
3952  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3953  * @param[in] argumentCount number of args
3954  * @param[in] arguments[] JSValue array of args
3955  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3956  * @retval JSValue that is the function's return value
3957  */
3958 static JSValueRef AAMP_setLanguageFormat(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3959 {
3960  LOG_TRACE("Enter");
3961  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3962  if(!pAAMP)
3963  {
3964  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
3965  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setLanguageFormat on instances of AAMP");
3966  return JSValueMakeUndefined(context);
3967  }
3968 
3969  if (argumentCount != 2)
3970  {
3971  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
3972  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setLanguageFormat' - 2 argument required");
3973  }
3974  else
3975  {
3976  int preferredFormat = (int) JSValueToNumber(context, arguments[0], NULL);
3977  bool useRole = JSValueToBoolean(context, arguments[1]);
3978  LOG_WARN(pAAMP," aamp->SetLanguageFormat(%d, %d)", preferredFormat, useRole);
3979  pAAMP->_aamp->SetLanguageFormat((LangCodePreference) preferredFormat, useRole);
3980  }
3981  return JSValueMakeUndefined(context);
3982 }
3983 
3984 
3985 /**
3986  * @brief Callback invoked from JS to set the license caching config
3987  * @param[in] context JS execution context
3988  * @param[in] function JSObject that is the function being called
3989  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
3990  * @param[in] argumentCount number of args
3991  * @param[in] arguments[] JSValue array of args
3992  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
3993  * @retval JSValue that is the function's return value
3994  */
3995 static JSValueRef AAMP_setLicenseCaching(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
3996 {
3997  LOG_TRACE("Enter");
3998  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
3999  if(!pAAMP)
4000  {
4001  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
4002  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setLicenseCaching on instances of AAMP");
4003  return JSValueMakeUndefined(context);
4004  }
4005 
4006  if (argumentCount != 1)
4007  {
4008 
4009  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
4010  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setLicenseCaching' - 1 argument required");
4011  }
4012  else
4013  {
4014  bool enabled = JSValueToBoolean(context, arguments[0]);
4015  LOG_WARN(pAAMP," _aamp->SetLicenseCaching %d)",enabled);
4016  pAAMP->_aamp->SetLicenseCaching(enabled);
4017  }
4018  return JSValueMakeUndefined(context);
4019 }
4020 
4021 /**
4022  * @brief Callback invoked from JS to set auxiliary audio language
4023  * @param[in] context JS execution context
4024  * @param[in] function JSObject that is the function being called
4025  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
4026  * @param[in] argumentCount number of args
4027  * @param[in] arguments[] JSValue array of args
4028  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
4029  * @retval JSValue that is the function's return value
4030  */
4031 static JSValueRef AAMP_setAuxiliaryLanguage(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
4032 {
4033  LOG_TRACE("Enter");
4034  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
4035  if(!pAAMP)
4036  {
4037  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
4038  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setAuxiliaryLanguage on instances of AAMP");
4039  return JSValueMakeUndefined(context);
4040  }
4041 
4042  if (argumentCount != 1)
4043  {
4044  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
4045  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setAuxiliaryLanguage' - 1 argument required");
4046  }
4047  else
4048  {
4049  char* lang = aamp_JSValueToCString(context, arguments[0], exception);
4050  LOG_WARN(pAAMP," _aamp->SetAuxiliaryLanguage(%s)", lang);
4051  pAAMP->_aamp->SetAuxiliaryLanguage(lang);
4052  SAFE_DELETE_ARRAY(lang);
4053  }
4054  return JSValueMakeUndefined(context);
4055 }
4056 /**
4057  * @brief Callback invoked from JS to get playback stats
4058  * @param[in] context JS execution context
4059  * @param[in] function JSObject that is the function being called
4060  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
4061  * @param[in] argumentCount number of args
4062  * @param[in] arguments[] JSValue array of args
4063  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
4064  * @retval JSValue that is the function's return value
4065  */
4066 static JSValueRef AAMP_getPlayeBackStats(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
4067 {
4068  LOG_TRACE("Enter");
4069  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
4070  if(!pAAMP || !pAAMP->_aamp)
4071  {
4072  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
4073  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.getPlayeBackStats on instances of AAMP");
4074  return JSValueMakeUndefined(context);
4075  }
4076  return aamp_CStringToJSValue(context, pAAMP->_aamp->GetPlaybackStats().c_str());
4077 }
4078 
4079 
4080 /**
4081  * * @brief Callback invoked from JS to set xre supported tune
4082  * * @param[in] context JS execution context
4083  * * @param[in] function JSObject that is the function being called
4084  * * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
4085  * * @param[in] argumentCount number of args
4086  * * @param[in] arguments[] JSValue array of args
4087  * * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
4088  * * @retval JSValue that is the function's return value
4089  * */
4090 static JSValueRef AAMP_xreSupportedTune(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
4091 {
4092  LOG_TRACE("Enter");
4093  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
4094  if(!pAAMP)
4095  {
4096  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
4097  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.xreSupprotedTune on instances of AAMP");
4098  return JSValueMakeUndefined(context);
4099  }
4100  if (argumentCount != 1)
4101  {
4102  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
4103  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.xreSupprotedTune' - 1 argument required");
4104  }
4105  else
4106  {
4107  bool xreSupported = JSValueToBoolean(context, arguments[0]);
4108  LOG_WARN(pAAMP," _aamp->XRESupportedTune(%d)",xreSupported);
4109  pAAMP->_aamp->XRESupportedTune(xreSupported);
4110  }
4111  return JSValueMakeUndefined(context);
4112 }
4113 
4114 
4115 /**
4116  * @brief Callback invoked from JS to set content protection data update timeout value on key rotation
4117  *
4118  * @param[in] context JS execution context
4119  * @param[in] function JSObject that is the function being called
4120  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
4121  * @param[in] argumentCount number of args
4122  * @param[in] arguments[] JSValue array of args
4123  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
4124  *
4125  * @retval JSValue that is the function's return value
4126  */
4127 static JSValueRef AAMP_setContentProtectionDataUpdateTimeout(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
4128 {
4129  LOG_TRACE("Enter");
4130  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
4131  if (!pAAMP)
4132  {
4133  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
4134  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setContentProtectionDataUpdateTimeout on instances of AAMP");
4135  return JSValueMakeUndefined(context);
4136  }
4137 
4138  if (argumentCount != 1)
4139  {
4140  LOG_ERROR(pAAMP,"InvalidArgument: argumentCount=%d, expected: 1", argumentCount);
4141  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setContentProtectionDataUpdateTimeout' - 1 argument required");
4142  }
4143  else
4144  {
4145  int contentProtectionDataUpdateTimeout = (int)JSValueToNumber(context, arguments[0], exception);
4146  LOG_WARN(pAAMP," _aamp->SetContentProtectionDataUpdateTimeout %d",contentProtectionDataUpdateTimeout);
4147  pAAMP->_aamp->SetContentProtectionDataUpdateTimeout(contentProtectionDataUpdateTimeout);
4148  }
4149  return JSValueMakeUndefined(context);
4150 }
4151 
4152 /**
4153  * @brief Callback invoked from JS to update content protection data value on key rotation
4154  *
4155  * @param[in] ctx JS execution context
4156  * @param[in] function JSObject that is the function being called
4157  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
4158  * @param[in] argumentCount number of args
4159  * @param[in] arguments[] JSValue array of args
4160  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
4161  *
4162  * @retval JSValue that is the function's return value
4163  */
4164 
4165 static JSValueRef AAMP_setContentProtectionDataConfig(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
4166 {
4167  LOG_TRACE("Enter");
4168  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
4169  if(!pAAMP)
4170  {
4171  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
4172  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setContentProtectionDataConfig on instances of AAMP");
4173  return JSValueMakeUndefined(context);
4174  }
4175  if (argumentCount == 1 && JSValueIsObject(context, arguments[0]))
4176  {
4177  const char *jsonbuffer = aamp_JSValueToJSONCString(context,arguments[0], exception);
4178  LOG_WARN(pAAMP," Response json call ProcessContentProtection %s",jsonbuffer);
4179  pAAMP->_aamp->ProcessContentProtectionDataConfig(jsonbuffer);
4180  SAFE_DELETE_ARRAY(jsonbuffer);
4181  }
4182  else
4183  {
4184  LOG_ERROR(pAAMP,"IvalidArgument - argumentCount=%d, expected: 1", argumentCount);
4185  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute setContentProtectionDataConfig() - 1 argument of type IConfig required");
4186  }
4187  return JSValueMakeUndefined(context);
4188 }
4189 
4190 /**
4191  * @brief Callback invoked from JS to Enable/Disable Dynamic DRM Config support
4192  *
4193  * @param[in] context JS execution context
4194  * @param[in] function JSObject that is the function being called
4195  * @param[in] thisObject JSObject that is the 'this' variable in the function's scope
4196  * @param[in] argumentCount number of args
4197  * @param[in] arguments[] JSValue array of args
4198  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
4199  *
4200  * @retval JSValue that is the function's return value
4201  */
4202 static JSValueRef AAMP_setRuntimeDRMConfig(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
4203 {
4204  LOG_TRACE("Enter");
4205  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
4206  if (!pAAMP)
4207  {
4208  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
4209  *exception = aamp_GetException(context, AAMPJS_MISSING_OBJECT, "Can only call AAMP.setDynamicDRMConfig on instances of AAMP");
4210  return JSValueMakeUndefined(context);
4211  }
4212  if(argumentCount != 1)
4213  {
4214  LOG_ERROR(pAAMP,"IvalidArgument - argumentCount=%d, expected: 1", argumentCount);
4215  *exception = aamp_GetException(context, AAMPJS_INVALID_ARGUMENT, "Failed to execute 'AAMP.setDynamicDRMConfig - 1 argument required");
4216  }
4217  else
4218  {
4219  bool DynamicDRMSupport = (bool)JSValueToBoolean(context, arguments[0]);
4220  LOG_WARN(pAAMP," _aamp->SetRuntimeDRMConfigSupport %d",DynamicDRMSupport);
4221  pAAMP->_aamp->SetRuntimeDRMConfigSupport(DynamicDRMSupport);
4222  }
4223  return JSValueMakeUndefined(context);
4224 }
4225 
4226 
4227 /**
4228  * @brief Array containing the AAMP's statically declared functions
4229  */
4230 static const JSStaticFunction AAMP_staticfunctions[] =
4231 {
4232  { "addEventListener", AAMP_addEventListener, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4233  { "removeEventListener", AAMP_removeEventListener, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4234  { "setProperties", AAMP_setProperties, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4235  { "getProperties", AAMP_getProperties, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4236  { "tune", AAMP_tune, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4237  { "load", AAMP_load, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4238  { "stop", AAMP_stop, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4239  { "setRate", AAMP_setRate, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4240  { "seek", AAMP_seek, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4241  { "seekToLive", AAMP_seekToLive, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4242  { "setRect", AAMP_setRect, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4243  { "setZoom", AAMP_setZoom, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4244  { "setLanguage", AAMP_setLanguage, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4245  { "setSubscribeTags", AAMP_setSubscribeTags, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4246  { "setAds", AAMP_setAds, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4247  { "subscribeTimedMetadata", AAMP_setSubscribeTags, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4248  { "getAvailableVideoTracks", AAMP_getAvailableVideoTracks, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4249  { "setVideoTracks", AAMP_setVideoTracks, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4250  { "getAvailableAudioTracks", AAMP_getAvailableAudioTracks, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4251  { "getAudioTrack", AAMP_getAudioTrack, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4252  { "getAudioTrackInfo", AAMP_getAudioTrackInfo, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4253  { "getTextTrackInfo", AAMP_getTextTrackInfo, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4254  { "getPreferredAudioProperties", AAMP_getPreferredAudioProperties, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4255  { "getPreferredTextProperties", AAMP_getPreferredTextProperties, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4256  { "setAudioTrack", AAMP_setAudioTrack, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4257  { "getAvailableTextTracks", AAMP_getAvailableTextTracks, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4258  { "getTextTrack", AAMP_getTextTrack, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4259  { "setTextTrack", AAMP_setTextTrack, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4260  { "setVideoMute", AAMP_setVideoMute, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4261  { "setAudioVolume", AAMP_setAudioVolume, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4262  { "addCustomHTTPHeader", AAMP_addCustomHTTPHeader, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4263  { "removeCustomHTTPHeader", AAMP_removeCustomHTTPHeader, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4264  { "setLicenseServerURL", AAMP_setLicenseServerURL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4265  { "setPreferredDRM", AAMP_setPreferredDRM, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4266  { "setAnonymousRequest", AAMP_setAnonymousRequest, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4267 
4268  { "setVODTrickplayFPS", AAMP_setVODTrickplayFPS, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4269 
4270  { "setLinearTrickplayFPS", AAMP_setLinearTrickplayFPS, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4271  { "setLiveOffset", AAMP_setLiveOffset, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4272  { "setLiveOffset4K", AAMP_setLiveOffset4K, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4273  { "setDownloadStallTimeout", AAMP_setDownloadStallTimeout, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4274  { "setDownloadStartTimeout", AAMP_setDownloadStartTimeout, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4275  { "setNetworkTimeout", AAMP_setNetworkTimeout, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4276  { "setAlternateContent", AAMP_setAlternateContent, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4277  { "notifyReservationCompletion", AAMP_notifyReservationCompletion, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4278  { "setClosedCaptionStatus", AAMP_setClosedCaptionStatus, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4279  { "setTextStyleOptions", AAMP_setTextStyleOptions, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4280  { "getTextStyleOptions", AAMP_getTextStyleOptions, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4281  { "setLanguageFormat", AAMP_setLanguageFormat, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4282  { "setLicenseCaching", AAMP_setLicenseCaching, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4283  { "setAuxiliaryLanguage", AAMP_setAuxiliaryLanguage, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4284  { "xreSupportedTune", AAMP_xreSupportedTune, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly},
4285  { "getPlaybackStatistics", AAMP_getPlayeBackStats, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4286  { "setContentProtectionDataConfig", AAMP_setContentProtectionDataConfig, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4287  { "setContentProtectionDataUpdateTimeout", AAMP_setContentProtectionDataUpdateTimeout, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4288  { "configRuntimeDRM", AAMP_setRuntimeDRMConfig, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4289  { NULL, NULL, 0 }
4290 };
4291 
4292 
4293 /**
4294  * @brief Callback invoked when an object of AAMP is finalized
4295  * @param[in] thisObject JSObject being finalized
4296  */
4297 static void AAMP_finalize(JSObjectRef thisObject)
4298 {
4299 
4300  AAMP_JS* pAAMP = (AAMP_JS*)JSObjectGetPrivate(thisObject);
4301  LOG_WARN_EX("object=%p", thisObject);
4302  if (pAAMP == NULL)
4303  {
4304  LOG_ERROR_EX("JSObjectGetPrivate returned NULL!");
4305  return;
4306  }
4307  JSObjectSetPrivate(thisObject, NULL);
4308 
4309  while (pAAMP->_listeners != NULL)
4310  {
4311  AAMPEventType eventType = pAAMP->_listeners->_type;
4312  JSObjectRef jsCallback = pAAMP->_listeners->_jsCallback;
4313 
4314  AAMP_JSListener::RemoveEventListener(pAAMP, eventType, jsCallback);
4315  }
4316 
4317  if (pAAMP->_ctx != NULL) {
4318  JSValueUnprotect(pAAMP->_ctx, pAAMP->_eventType);
4319  if(pAAMP->_subscribedTags) {
4320  JSValueUnprotect(pAAMP->_ctx, pAAMP->_subscribedTags);
4321  }
4322  if(pAAMP->_promiseCallback) {
4323  JSValueUnprotect(pAAMP->_ctx, pAAMP->_promiseCallback);
4324  }
4325  }
4326 
4327  pthread_mutex_lock(&mutex);
4328  if (NULL != _allocated_aamp)
4329  {
4330  //when finalizing JS object, don't generate state change events
4331  LOG_WARN(pAAMP," aamp->Stop(false)");
4332  _allocated_aamp->Stop(false);
4333  LOG_WARN(pAAMP,"delete aamp %p",_allocated_aamp);
4334  SAFE_DELETE(_allocated_aamp);
4335  }
4336  pthread_mutex_unlock(&mutex);
4337  SAFE_DELETE(pAAMP);
4338 
4339 #ifdef AAMP_CC_ENABLED
4340  //disable CC rendering so that state will not be persisted between two different sessions.
4341  logprintf("[%s] Disabling CC", __FUNCTION__);
4343 #endif
4344 }
4345 
4346 
4347 /**
4348  * @brief Structure contains properties and callbacks of AAMP object
4349  */
4350 static const JSClassDefinition AAMP_class_def =
4351 {
4352  0,
4353  kJSClassAttributeNone,
4354  "__AAMP__class",
4355  NULL,
4358  NULL,
4359  NULL, // _allocated_aamp is reused, so don't clean when one object goes out of scope
4360  NULL,
4361  NULL,
4362  NULL,
4363  NULL,
4364  NULL,
4365  NULL,
4367  NULL,
4368  NULL
4369 };
4370 
4371 
4372 /**
4373  * @brief Creates a JavaScript class of AAMP for use with JSObjectMake
4374  * @retval singleton instance of JavaScript class created
4375  */
4376 static JSClassRef AAMP_class_ref() {
4377  static JSClassRef _classRef = NULL;
4378  if (!_classRef) {
4379  _classRef = JSClassCreate(&AAMP_class_def);
4380  }
4381  return _classRef;
4382 }
4383 
4384 
4385 /**
4386  * @brief Callback invoked from JS to get the AD_PLAYBACK_STARTED property value
4387  * @param[in] context JS execution context
4388  * @param[in] thisObject JSObject to search for the property
4389  * @param[in] propertyName JSString containing the name of the property to get
4390  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
4391  * @retval property's value if object has the property, otherwise NULL
4392  */
4393 static JSValueRef EventType_getproperty_AD_PLAYBACK_STARTED(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
4394 {
4395  LOG_TRACE("Enter");
4396  return aamp_CStringToJSValue(context, "adPlaybackStarted");
4397 }
4398 
4399 
4400 /**
4401  * @brief Callback invoked from JS to get the AD_PLAYBACK_COMPLETED property value
4402  * @param[in] context JS execution context
4403  * @param[in] thisObject JSObject to search for the property
4404  * @param[in] propertyName JSString containing the name of the property to get
4405  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
4406  * @retval property's value if object has the property, otherwise NULL
4407  */
4408 static JSValueRef EventType_getproperty_AD_PLAYBACK_COMPLETED(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
4409 {
4410  LOG_TRACE("Enter");
4411  return aamp_CStringToJSValue(context, "adPlaybackCompleted");
4412 }
4413 
4414 
4415 /**
4416  * @brief Callback invoked from JS to get the AD_PLAYBACK_INTERRUPTED property value
4417  * @param[in] context JS execution context
4418  * @param[in] thisObject JSObject to search for the property
4419  * @param[in] propertyName JSString containing the name of the property to get
4420  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
4421  * @retval property's value if object has the property, otherwise NULL
4422  */
4423 static JSValueRef EventType_getproperty_AD_PLAYBACK_INTERRUPTED(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
4424 {
4425  LOG_TRACE("Enter");
4426  return aamp_CStringToJSValue(context, "adPlaybackInterrupted");
4427 }
4428 
4429 
4430 /**
4431  * @brief Callback invoked from JS to get the BUFFERING_BEGIN property value
4432  * @param[in] context JS execution context
4433  * @param[in] thisObject JSObject to search for the property
4434  * @param[in] propertyName JSString containing the name of the property to get
4435  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
4436  * @retval property's value if object has the property, otherwise NULL
4437  */
4438 static JSValueRef EventType_getproperty_BUFFERING_BEGIN(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
4439 {
4440  LOG_TRACE("Enter");
4441  return aamp_CStringToJSValue(context, "bufferingBegin");
4442 }
4443 
4444 
4445 /**
4446  * @brief Callback invoked from JS to get the BUFFERING_END property value
4447  * @param[in] context JS execution context
4448  * @param[in] thisObject JSObject to search for the property
4449  * @param[in] propertyName JSString containing the name of the property to get
4450  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
4451  * @retval property's value if object has the property, otherwise NULL
4452  */
4453 static JSValueRef EventType_getproperty_BUFFERING_END(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
4454 {
4455  LOG_TRACE("Enter");
4456  return aamp_CStringToJSValue(context, "bufferingEnd");
4457 }
4458 
4459 
4460 /**
4461  * @brief Callback invoked from JS to get the DECODER_AVAILABLE property value
4462  * @param[in] context JS execution context
4463  * @param[in] thisObject JSObject to search for the property
4464  * @param[in] propertyName JSString containing the name of the property to get
4465  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
4466  * @retval property's value if object has the property, otherwise NULL
4467  */
4468 static JSValueRef EventType_getproperty_DECODER_AVAILABLE(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
4469 {
4470  LOG_TRACE("Enter");
4471  return aamp_CStringToJSValue(context, "decoderAvailable");
4472 }
4473 
4474 
4475 /**
4476  * @brief Callback invoked from JS to get the DRM_METADATA_INFO_AVAILABLE property value
4477  * @param[in] context JS execution context
4478  * @param[in] thisObject JSObject to search for the property
4479  * @param[in] propertyName JSString containing the name of the property to get
4480  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
4481  * @retval property's value if object has the property, otherwise NULL
4482  */
4483 static JSValueRef EventType_getproperty_DRM_METADATA_INFO_AVAILABLE(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
4484 {
4485  LOG_TRACE("Enter");
4486  return aamp_CStringToJSValue(context, "drmMetadataInfoAvailable");
4487 }
4488 
4489 
4490 
4491 
4492 
4493 /**
4494  * @brief Callback invoked from JS to get the DRM_METADATA property value
4495  * @param[in] context JS execution context
4496  * @param[in] thisObject JSObject to search for the property
4497  * @param[in] propertyName JSString containing the name of the property to get
4498  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
4499  * @retval property's value if object has the property, otherwise NULL
4500  */
4501 static JSValueRef EventType_getproperty_DRM_METADATA(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
4502 {
4503  LOG_TRACE("Enter");
4504  return aamp_CStringToJSValue(context, "drmMetadata");
4505 }
4506 
4507 
4508 
4509 
4510 /**
4511  * @brief Callback invoked from JS to get the ENTERING_LIVE property value
4512  * @param[in] context JS execution context
4513  * @param[in] thisObject JSObject to search for the property
4514  * @param[in] propertyName JSString containing the name of the property to get
4515  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
4516  * @retval property's value if object has the property, otherwise NULL
4517  */
4518 static JSValueRef EventType_getproperty_ENTERING_LIVE(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
4519 {
4520  LOG_TRACE("Enter");
4521  return aamp_CStringToJSValue(context, "enteringLive");
4522 }
4523 
4524 
4525 /**
4526  * @brief Callback invoked from JS to get the MEDIA_OPENED property value
4527  * @param[in] context JS execution context
4528  * @param[in] thisObject JSObject to search for the property
4529  * @param[in] propertyName JSString containing the name of the property to get
4530  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
4531  * @retval property's value if object has the property, otherwise NULL
4532  */
4533 static JSValueRef EventType_getproperty_MEDIA_OPENED(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
4534 {
4535  LOG_TRACE("Enter");
4536  return aamp_CStringToJSValue(context, "mediaOpened");
4537 }
4538 
4539 
4540 /**
4541  * @brief Callback invoked from JS to get the MEDIA_STOPPED property value
4542  * @param[in] context JS execution context
4543  * @param[in] thisObject JSObject to search for the property
4544  * @param[in] propertyName JSString containing the name of the property to get
4545  * @param[out] exception pointer to a JSValueRef in which to return an exception, if any
4546  * @retval property's value if object has the property, otherwise NULL
4547  */
4548 static JSValueRef EventType_getproperty_MEDIA_STOPPED(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
4549 {
4550  LOG_TRACE("Enter");
4551  return aamp_CStringToJSValue(context, "mediaStopped");
4552 }
4553 
4554 
4555 /**
4556  * @brief Array containing the EventType's statically declared value properties
4557  */
4558 static const JSStaticValue EventType_staticprops[] =
4559 {
4560  { "AD_PLAYBACK_STARTED", EventType_getproperty_AD_PLAYBACK_STARTED, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4561  { "AD_PLAYBACK_COMPLETED", EventType_getproperty_AD_PLAYBACK_COMPLETED, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4562  { "AD_PLAYBACK_INTERRUPTED", EventType_getproperty_AD_PLAYBACK_INTERRUPTED, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4563  { "BUFFERING_BEGIN", EventType_getproperty_BUFFERING_BEGIN, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4564  { "BUFFERING_END", EventType_getproperty_BUFFERING_END, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4565  { "DECODER_AVAILABLE", EventType_getproperty_DECODER_AVAILABLE, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4566  { "DRM_METADATA_INFO_AVAILABLE", EventType_getproperty_DRM_METADATA_INFO_AVAILABLE, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4567  { "ENTERING_LIVE", EventType_getproperty_ENTERING_LIVE, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4568  { "MEDIA_OPENED", EventType_getproperty_MEDIA_OPENED, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4569  { "MEDIA_STOPPED", EventType_getproperty_MEDIA_STOPPED, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
4570  { NULL, NULL, NULL, 0 }
4571 };
4572 
4573 
4574 /**
4575  * @brief Callback invoked from JS when an object of EventType is first created
4576  * @param[in] ctx JS execution context
4577  * @param[in] thisObject JSObject being created
4578  */
4579 static void EventType_init(JSContextRef ctx, JSObjectRef thisObject)
4580 {
4581  LOG_TRACE("Enter");
4582 }
4583 
4584 
4585 /**
4586  * @brief Callback invoked when an object of EventType is finalized
4587  * @param[in] thisObject JSObject being finalized
4588  */
4589 static void EventType_finalize(JSObjectRef thisObject)
4590 {
4591  LOG_TRACE("Enter");
4592 }
4593 
4594 
4595 /**
4596  * @brief Structure contains properties and callbacks of EventType object
4597  */
4598 static const JSClassDefinition EventType_object_def =
4599 {
4600  0,
4601  kJSClassAttributeNone,
4602  "__EventType",
4603  NULL,
4605  NULL,
4608  NULL,
4609  NULL,
4610  NULL,
4611  NULL,
4612  NULL,
4613  NULL,
4614  NULL,
4615  NULL,
4616  NULL
4617 };
4618 
4619 
4620 /**
4621  * @brief Creates a JavaScript class of EventType for use with JSObjectMake
4622  * @retval singleton instance of JavaScript class created
4623  */
4624 static JSClassRef EventType_class_ref() {
4625  static JSClassRef _classRef = NULL;
4626  if (!_classRef) {
4627  _classRef = JSClassCreate(&EventType_object_def);
4628  }
4629  return _classRef;
4630 }
4631 
4632 
4633 /**
4634  * @brief Create a EventType JS object
4635  * @param[in] context JS execute context
4636  * @retval JSObject of EventType
4637  */
4638 JSObjectRef AAMP_JS_AddEventTypeClass(JSGlobalContextRef context)
4639 {
4640  LOG_TRACE("context=%p", context);
4641 
4642  JSObjectRef obj = JSObjectMake(context, EventType_class_ref(), context);
4643 
4644  return obj;
4645 }
4646 
4647 
4648 /**
4649  * @brief Load aamp JS bindings.
4650  */
4651 void aamp_LoadJS(void* context, void* playerInstanceAAMP)
4652 {
4653  LOG_WARN_EX("context=%p, aamp=%p", context, playerInstanceAAMP);
4654  JSGlobalContextRef jsContext = (JSGlobalContextRef)context;
4655 
4656  AAMP_JS* pAAMP = new AAMP_JS();
4657  pAAMP->_ctx = jsContext;
4658  if (NULL != playerInstanceAAMP)
4659  {
4660  pAAMP->_aamp = (PlayerInstanceAAMP*)playerInstanceAAMP;
4661  }
4662  else
4663  {
4664  pthread_mutex_lock(&mutex);
4665  if (NULL == _allocated_aamp )
4666  {
4667  _allocated_aamp = new PlayerInstanceAAMP(NULL, NULL);
4668  LOG_WARN_EX("create aamp %p", _allocated_aamp);
4669  }
4670  else
4671  {
4672  LOG_WARN_EX("reuse aamp %p", _allocated_aamp);
4673 
4674  }
4675  pAAMP->_aamp = _allocated_aamp;
4676  pthread_mutex_unlock(&mutex);
4677  }
4678 
4679  pAAMP->_listeners = NULL;
4680 
4681  //Get PLAYER ID and store for future use in logging
4682  pAAMP->iPlayerId = pAAMP->_aamp->GetId();
4683  //Get jsinfo config for INFO logging
4684  pAAMP->bInfoEnabled = pAAMP->_aamp->IsJsInfoLoggingEnabled();
4685 
4686  // DELIA-48250 Set tuned event configuration to playlist indexed
4688  // DELIA-48278 Set EnableVideoRectangle to false, this is tied to westeros config
4689  pAAMP->_aamp->EnableVideoRectangle(false);
4690 
4691  pAAMP->_eventType = AAMP_JS_AddEventTypeClass(jsContext);
4692  JSValueProtect(jsContext, pAAMP->_eventType);
4693 
4694  pAAMP->_subscribedTags = NULL;
4695  pAAMP->_promiseCallback = NULL;
4697 
4698  JSObjectRef classObj = JSObjectMake(jsContext, AAMP_class_ref(), pAAMP);
4699  JSObjectRef globalObj = JSContextGetGlobalObject(jsContext);
4700  JSStringRef str = JSStringCreateWithUTF8CString("AAMP");
4701  JSObjectSetProperty(jsContext, globalObj, str, classObj, kJSPropertyAttributeReadOnly, NULL);
4702  JSStringRelease(str);
4703 }
4704 
4705 /**
4706  * @brief Unload aamp JS bindings.
4707  *
4708  */
4709 void aamp_UnloadJS(void* context)
4710 {
4711 
4712  LOG_WARN_EX("context=%p", context);
4713  JSGlobalContextRef jsContext = (JSGlobalContextRef)context;
4714 
4715  JSObjectRef globalObj = JSContextGetGlobalObject(jsContext);
4716  JSStringRef str = JSStringCreateWithUTF8CString("AAMP");
4717  JSValueRef aamp = JSObjectGetProperty(jsContext, globalObj, str, NULL);
4718 
4719  if (aamp == NULL)
4720  {
4721  JSStringRelease(str);
4722  return;
4723  }
4724 
4725  JSObjectRef aampObj = JSValueToObject(jsContext, aamp, NULL);
4726  if (aampObj == NULL)
4727  {
4728  JSStringRelease(str);
4729  return;
4730  }
4731 
4732  // Only a single AAMP object is available in this JS context which is added at the time of webpage load
4733  // So it makes sense to remove the object when webpage is unloaded.
4734  AAMP_finalize(aampObj);
4735 
4736  // Per comments in DELIA-48964, use JSObjectDeleteProperty instead of JSObjectSetProperty when trying to invalidate a read-only property
4737  JSObjectDeleteProperty(jsContext, globalObj, str, NULL);
4738  JSStringRelease(str);
4739 
4740  // Force a garbage collection to clean-up all AAMP objects.
4741  LOG_TRACE("JSGarbageCollect() context=%p", context);
4742  JSGarbageCollect(jsContext);
4743 }
4744 
4745 #ifdef __GNUC__
4746 
4747 /**
4748  * @brief Stops any prevailing AAMP instances before exit of program
4749  */
4750 void __attribute__ ((destructor(101))) _aamp_term()
4751 {
4752 
4753  LOG_TRACE("Enter");
4754  pthread_mutex_lock(&mutex);
4755  if (NULL != _allocated_aamp)
4756  {
4757  LOG_WARN_EX("stopping aamp");
4758  //when finalizing JS object, don't generate state change events
4759  _allocated_aamp->Stop(false);
4760  LOG_WARN_EX("stopped aamp");
4761  delete _allocated_aamp;
4762  _allocated_aamp = NULL;
4763  }
4764  pthread_mutex_unlock(&mutex);
4765 
4766  //Clear any active js mediaplayer instances on term
4768 }
4769 #endif
EventType_getproperty_DRM_METADATA_INFO_AVAILABLE
static JSValueRef EventType_getproperty_DRM_METADATA_INFO_AVAILABLE(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception)
Callback invoked from JS to get the DRM_METADATA_INFO_AVAILABLE property value.
Definition: jsbindings.cpp:4483
EventType_getproperty_MEDIA_OPENED
static JSValueRef EventType_getproperty_MEDIA_OPENED(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception)
Callback invoked from JS to get the MEDIA_OPENED property value.
Definition: jsbindings.cpp:4533
EventType_getproperty_BUFFERING_BEGIN
static JSValueRef EventType_getproperty_BUFFERING_BEGIN(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception)
Callback invoked from JS to get the BUFFERING_BEGIN property value.
Definition: jsbindings.cpp:4438
AAMP_getProperty_EventType
static JSValueRef AAMP_getProperty_EventType(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception)
Callback invoked from JS to get the EventType property value.
Definition: jsbindings.cpp:239
AAMP_JSListener_TimedMetadata::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:1291
AAMP_setSubscribeTags
static JSValueRef AAMP_setSubscribeTags(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set list of subscribed tags.
Definition: jsbindings.cpp:2694
AAMP_setProperty_reportInterval
static bool AAMP_setProperty_reportInterval(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef *exception)
Callback invoked from JS to set the reportInterval property value.
Definition: jsbindings.cpp:458
AAMP_JSListener_DrmMessage
Event listener impl for (AAMP_EVENT_DRM_MESSAGE) AAMP event.
Definition: jsbindings.cpp:1815
AAMP_JSListener_AdPlacementEror::AAMP_JSListener_AdPlacementEror
AAMP_JSListener_AdPlacementEror(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_AdPlacementEror Constructor.
Definition: jsbindings.cpp:1696
AAMP_getTextTrackInfo
static JSValueRef AAMP_getTextTrackInfo(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to get current text track info.
Definition: jsbindings.cpp:2967
eDRM_WideVine
@ eDRM_WideVine
Definition: AampDrmSystems.h:36
AAMP_EVENT_DRM_METADATA
@ AAMP_EVENT_DRM_METADATA
Definition: AampEvent.h:71
AAMP_EVENT_BULK_TIMED_METADATA
@ AAMP_EVENT_BULK_TIMED_METADATA
Definition: AampEvent.h:59
AAMP_finalize
static void AAMP_finalize(JSObjectRef thisObject)
Callback invoked when an object of AAMP is finalized.
Definition: jsbindings.cpp:4297
AAMP_setClosedCaptionStatus
static JSValueRef AAMP_setClosedCaptionStatus(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to enable/disable CC rendering.
Definition: jsbindings.cpp:3842
PlayerInstanceAAMP::aamp
class PrivateInstanceAAMP * aamp
Definition: main_aamp.h:1943
AAMP_JSListener_AdReservationEnd::AAMP_JSListener_AdReservationEnd
AAMP_JSListener_AdReservationEnd(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_AdReservationEnd Constructor.
Definition: jsbindings.cpp:1535
VIDEO_ZOOM_FULL
@ VIDEO_ZOOM_FULL
Definition: main_aamp.h:131
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
AAMP_getProperty_timedMetadata
static JSValueRef AAMP_getProperty_timedMetadata(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception)
Callback invoked from JS to get the timedMetadata property value.
Definition: jsbindings.cpp:363
AAMP_setVODTrickplayFPS
static JSValueRef AAMP_setVODTrickplayFPS(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set vod trickplay FPS.
Definition: jsbindings.cpp:3404
AAMP_JSListener_CCHandleReceived::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:1131
PlayerInstanceAAMP::GetTextTrackInfo
std::string GetTextTrackInfo()
Get current audio track index.
Definition: main_aamp.cpp:2448
AAMP_removeEventListener
static JSValueRef AAMP_removeEventListener(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to remove an event listener.
Definition: jsbindings.cpp:2080
AAMP_xreSupportedTune
static JSValueRef AAMP_xreSupportedTune(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set xre supported tune.
Definition: jsbindings.cpp:4090
AAMP_EVENT_CONTENT_GAP
@ AAMP_EVENT_CONTENT_GAP
Definition: AampEvent.h:85
AAMP_setTextStyleOptions
static JSValueRef AAMP_setTextStyleOptions(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set text style.
Definition: jsbindings.cpp:3878
PlayerInstanceAAMP::SetVideoZoom
void SetVideoZoom(VideoZoomMode zoom)
Set video zoom.
Definition: main_aamp.cpp:1282
AAMP_JSListener_TimedMetadata::AAMP_JSListener_TimedMetadata
AAMP_JSListener_TimedMetadata(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_TimedMetadata Constructor.
Definition: jsbindings.cpp:1281
EventType_getproperty_AD_PLAYBACK_INTERRUPTED
static JSValueRef EventType_getproperty_AD_PLAYBACK_INTERRUPTED(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception)
Callback invoked from JS to get the AD_PLAYBACK_INTERRUPTED property value.
Definition: jsbindings.cpp:4423
VIDEO_ZOOM_NONE
@ VIDEO_ZOOM_NONE
Definition: main_aamp.h:132
AAMP_EVENT_AD_PLACEMENT_END
@ AAMP_EVENT_AD_PLACEMENT_END
Definition: AampEvent.h:78
EventType_getproperty_AD_PLAYBACK_COMPLETED
static JSValueRef EventType_getproperty_AD_PLAYBACK_COMPLETED(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception)
Callback invoked from JS to get the AD_PLAYBACK_COMPLETED property value.
Definition: jsbindings.cpp:4408
AAMP_setRate
static JSValueRef AAMP_setRate(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set playback rate.
Definition: jsbindings.cpp:2377
AAMP_EVENT_BUFFERING_CHANGED
@ AAMP_EVENT_BUFFERING_CHANGED
Definition: AampEvent.h:64
AAMP_notifyReservationCompletion
static JSValueRef AAMP_notifyReservationCompletion(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Notify AAMP that the reservation is complete.
Definition: jsbindings.cpp:3576
AAMP_getProperty_initialBufferTime
static JSValueRef AAMP_getProperty_initialBufferTime(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception)
Callback invoked from JS to get the initialBufferTime property value.
Definition: jsbindings.cpp:147
Event_staticfunctions
static const JSStaticFunction Event_staticfunctions[]
Array containing the Event's statically declared functions.
Definition: jsbindings.cpp:546
AAMP_JSListener::RemoveEventListener
static void RemoveEventListener(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
Removes a JS listener for a particular event.
Definition: jsbindings.cpp:2130
PlayerInstanceAAMP::SetLicenseCaching
void SetLicenseCaching(bool bValue)
Set license caching.
Definition: main_aamp.cpp:2218
AAMP_JSListener_SpeedChanged
Event listener impl for SPEED_CHANGED AAMP event.
Definition: jsbindings.cpp:877
AAMP_EVENT_REPORT_ANOMALY
@ AAMP_EVENT_REPORT_ANOMALY
Definition: AampEvent.h:72
AAMP_EVENT_TUNE_FAILED
@ AAMP_EVENT_TUNE_FAILED
Definition: AampEvent.h:48
PlayerInstanceAAMP::SetContentProtectionDataUpdateTimeout
void SetContentProtectionDataUpdateTimeout(int timeout)
To set default timeout for Dynamic ContentProtectionDataUpdate on Key Rotation.
Definition: main_aamp.cpp:3163
logprintf
void logprintf(const char *format,...)
Print logs to console / log fil.
Definition: aamplogging.cpp:432
AAMP_class_constructor
static JSObjectRef AAMP_class_constructor(JSContextRef context, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
callback invoked when AAMP is used along with 'new'
Definition: jsbindings.cpp:86
AAMP_JSListener::setEventProperties
virtual void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:726
AAMP_JSListener_BufferingChanged::AAMP_JSListener_BufferingChanged
AAMP_JSListener_BufferingChanged(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_BufferingChanged Constructor.
Definition: jsbindings.cpp:1740
AAMP_EVENT_DRM_MESSAGE
@ AAMP_EVENT_DRM_MESSAGE
Definition: AampEvent.h:83
AAMP_setAudioVolume
static JSValueRef AAMP_setAudioVolume(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set audio volume.
Definition: jsbindings.cpp:2571
PlayerInstanceAAMP::IsLive
bool IsLive()
To check whether the asset is live or not.
Definition: main_aamp.cpp:1503
main_aamp.h
Types and APIs exposed by the AAMP player.
AAMP_JSListener_AdReservationEnd
Event listener impl for AD_RESOLVED AAMP event.
Definition: jsbindings.cpp:1525
PlayerInstanceAAMP::SetStallTimeout
void SetStallTimeout(int timeoutMS)
To set the timeout value to be used for playback stall detection.
Definition: main_aamp.cpp:1693
AAMP_seek
static JSValueRef AAMP_seek(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to perform seek to a particular playback position.
Definition: jsbindings.cpp:2423
AAMP_EVENT_AD_RESERVATION_END
@ AAMP_EVENT_AD_RESERVATION_END
Definition: AampEvent.h:76
Event_object_def
static const JSClassDefinition Event_object_def
Structure contains properties and callbacks of Event object.
Definition: jsbindings.cpp:599
AAMP_setAnonymousRequest
static JSValueRef AAMP_setAnonymousRequest(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to en/disable anonymous request.
Definition: jsbindings.cpp:3368
AAMP_JSListener_AdResolved::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:1457
AAMP_getProperties
static JSValueRef AAMP_getProperties(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to get AAMP object's properties.
Definition: jsbindings.cpp:2177
AAMP_setDownloadStartTimeout
static JSValueRef AAMP_setDownloadStartTimeout(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set download start timeout value.
Definition: jsbindings.cpp:3765
PlayerInstanceAAMP::SetDownloadStartTimeout
void SetDownloadStartTimeout(long startTimeout)
To set the curl download start timeout.
Definition: main_aamp.cpp:2145
aamp_UnloadJS
void aamp_UnloadJS(void *context)
Unload aamp JS bindings.
Definition: jsbindings.cpp:4709
AAMP_getPlayeBackStats
static JSValueRef AAMP_getPlayeBackStats(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to get playback stats.
Definition: jsbindings.cpp:4066
AampCCManagerBase::SetStatus
int SetStatus(bool enable)
Enable/disable CC rendering.
Definition: AampCCManager.cpp:755
AAMP_JSListener_Id3Metadata::AAMP_JSListener_Id3Metadata
AAMP_JSListener_Id3Metadata(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_Id3Metadata Constructor.
Definition: jsbindings.cpp:1777
AAMP_getProperty_AudioLanguage
static JSValueRef AAMP_getProperty_AudioLanguage(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception)
Callback invoked from JS to get the audioLanguage property value.
Definition: jsbindings.cpp:314
AAMP_JSListener_CCHandleReceived
Event listener impl for CC_HANDLE_RECEIVED AAMP event.
Definition: jsbindings.cpp:1112
AAMP_JSListener_AdPlacementEror
Event listener impl for AD_RESOLVED AAMP event.
Definition: jsbindings.cpp:1686
PlayerInstanceAAMP::GetAudioTrack
int GetAudioTrack()
Get current audio track index.
Definition: main_aamp.cpp:2556
AAMP_JSListener_AdResolved
Event listener impl for AD_RESOLVED AAMP event.
Definition: jsbindings.cpp:1437
aamp_ApplyPageHttpHeaders
void aamp_ApplyPageHttpHeaders(PlayerInstanceAAMP *)
applies the parsed custom http headers into the aamp
Definition: jscontroller-jsbindings.cpp:511
AAMP_JSListener_SpeedsChanged::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:1412
PlayerInstanceAAMP::RemoveEventListener
void RemoveEventListener(AAMPEventType eventType, EventListener *eventListener)
Remove event listener for eventType.
Definition: main_aamp.cpp:1493
PlayerInstanceAAMP::SetVideoRectangle
void SetVideoRectangle(int x, int y, int w, int h)
Set video rectangle.
Definition: main_aamp.cpp:1270
AAMP_setLiveOffset4K
static JSValueRef AAMP_setLiveOffset4K(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set live offset for 4K.
Definition: jsbindings.cpp:3689
AAMP_setLiveOffset
static JSValueRef AAMP_setLiveOffset(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set live offset.
Definition: jsbindings.cpp:3652
AAMP_getProperty_closedCaptionEnabled
static JSValueRef AAMP_getProperty_closedCaptionEnabled(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception)
Callback invoked from JS to get the closedCaptionEnabled property value.
Definition: jsbindings.cpp:101
AAMP_JSListener_VideoMetadata::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:1166
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
AAMP_JSListener_AdPlacementEnd::AAMP_JSListener_AdPlacementEnd
AAMP_JSListener_AdPlacementEnd(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_AdPlacementEnd Constructor.
Definition: jsbindings.cpp:1615
PlayerInstanceAAMP::SetAnonymousRequest
void SetAnonymousRequest(bool isAnonymous)
Indicates if session token has to be used with license request or not.
Definition: main_aamp.cpp:1620
AAMP_JSListener_TimedMetadata
Event listener impl for TIMED_METADATA AAMP event.
Definition: jsbindings.cpp:1271
jsutils.h
JavaScript util functions for AAMP.
AAMP_JSListener_SpeedChanged::AAMP_JSListener_SpeedChanged
AAMP_JSListener_SpeedChanged(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_SpeedChanged Constructor.
Definition: jsbindings.cpp:887
AAMP_getProperty_trickPlayEnabled
static JSValueRef AAMP_getProperty_trickPlayEnabled(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception)
Callback invoked from JS to get the trickPlayEnabled property value.
Definition: jsbindings.cpp:193
EventType_getproperty_AD_PLAYBACK_STARTED
static JSValueRef EventType_getproperty_AD_PLAYBACK_STARTED(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception)
Callback invoked from JS to get the AD_PLAYBACK_STARTED property value.
Definition: jsbindings.cpp:4393
AAMP_JSListener_CCHandleReceived::AAMP_JSListener_CCHandleReceived
AAMP_JSListener_CCHandleReceived(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_CCHandleReceived Constructor.
Definition: jsbindings.cpp:1121
AAMPEventObjectListener
Class for AAMP event listening Uses shared_ptr for event objects for better memory management New AAM...
Definition: AampEventListener.h:87
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
AAMP_JSListener::AddEventListener
static void AddEventListener(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
Adds a JS function as listener for a particular event.
Definition: jsbindings.cpp:1953
PlayerInstanceAAMP::SetVideoTracks
void SetVideoTracks(std::vector< long > bitrates)
Set video tracks.
Definition: main_aamp.cpp:2420
AAMP_setLanguageFormat
static JSValueRef AAMP_setLanguageFormat(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set the preferred language format.
Definition: jsbindings.cpp:3958
PlayerInstanceAAMP::AddEventListener
void AddEventListener(AAMPEventType eventType, EventListener *eventListener)
Support multiple listeners for multiple event type.
Definition: main_aamp.cpp:1483
PlayerInstanceAAMP::SetLanguageFormat
void SetLanguageFormat(LangCodePreference preferredFormat, bool useRole=false)
Set Language preferred Format.
Definition: main_aamp.cpp:480
AAMP_setProperties
static JSValueRef AAMP_setProperties(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set AAMP object's properties.
Definition: jsbindings.cpp:2160
AAMP_setRuntimeDRMConfig
static JSValueRef AAMP_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: jsbindings.cpp:4202
PlayerInstanceAAMP::SetLinearTrickplayFPS
void SetLinearTrickplayFPS(int linearTrickplayFPS)
Set Linear Trickplay FPS.
Definition: main_aamp.cpp:1655
PlayerInstanceAAMP::SetTextTrack
void SetTextTrack(int trackId, char *ccData=NULL)
Set text track.
Definition: main_aamp.cpp:2566
AAMP_JSListener::AAMP_JSListener
AAMP_JSListener(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
Definition: jsbindings.cpp:651
PlayerInstanceAAMP::GetAvailableAudioTracks
std::string GetAvailableAudioTracks(bool allTrack=false)
Get available audio tracks.
Definition: main_aamp.cpp:2428
AAMP_JSListener_AdPlacementStart::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:1585
ClearAAMPPlayerInstances
void ClearAAMPPlayerInstances()
Clear any remaining/active AAMPPlayer instances.
Definition: jsmediaplayer.cpp:3612
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
AAMP_JSListener_TuneFailed::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:937
aamp_LoadJS
void aamp_LoadJS(void *context, void *playerInstanceAAMP)
Load aamp JS bindings.
Definition: jsbindings.cpp:4651
PlayerInstanceAAMP::SetRuntimeDRMConfigSupport
void SetRuntimeDRMConfigSupport(bool DynamicDRMSupported)
To set Dynamic DRM feature by Application.
Definition: main_aamp.cpp:3173
AAMP_JSListener_BitRateChanged::AAMP_JSListener_BitRateChanged
AAMP_JSListener_BitRateChanged(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_BitRateChanged Constructor.
Definition: jsbindings.cpp:815
PlayerInstanceAAMP::SetLiveOffset4K
void SetLiveOffset4K(double liveoffset)
Set Live Offset.
Definition: main_aamp.cpp:1674
AAMP_getAvailableAudioTracks
static JSValueRef AAMP_getAvailableAudioTracks(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to get list of audio tracks.
Definition: jsbindings.cpp:2868
AAMP_JSListener_AdReservationStart::AAMP_JSListener_AdReservationStart
AAMP_JSListener_AdReservationStart(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_AdReservationStart Constructor.
Definition: jsbindings.cpp:1495
TimedMetadata
Class for Timed Metadata.
Definition: priv_aamp.h:382
PlayerInstanceAAMP::GetCurrentDRM
const char * GetCurrentDRM()
Get current drm.
Definition: main_aamp.cpp:1547
AAMP_JSListener_SpeedChanged::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:897
PlayerInstanceAAMP::SetLiveOffset
void SetLiveOffset(double liveoffset)
Set Live Offset.
Definition: main_aamp.cpp:1664
AAMP_setDownloadStallTimeout
static JSValueRef AAMP_setDownloadStallTimeout(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set download stall timeout value.
Definition: jsbindings.cpp:3726
AAMP_JSListener_BulkTimedMetadata
Event listener impl for BULK_TIMED_METADATA AAMP event.
Definition: jsbindings.cpp:1237
AAMP_static_values
static const JSStaticValue AAMP_static_values[]
Array containing the AAMP's statically declared value properties.
Definition: jsbindings.cpp:524
AAMP_setAuxiliaryLanguage
static JSValueRef AAMP_setAuxiliaryLanguage(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set auxiliary audio language.
Definition: jsbindings.cpp:4031
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
Event_class_ref
static JSClassRef Event_class_ref()
Creates a JavaScript class of Event for use with JSObjectMake.
Definition: jsbindings.cpp:625
PlayerInstanceAAMP::SetVODTrickplayFPS
void SetVODTrickplayFPS(int vodTrickplayFPS)
Set VOD Trickplay FPS.
Definition: main_aamp.cpp:1646
AAMP_class_def
static const JSClassDefinition AAMP_class_def
Structure contains properties and callbacks of AAMP object.
Definition: jsbindings.cpp:4350
AAMP_class_ref
static JSClassRef AAMP_class_ref()
Creates a JavaScript class of AAMP for use with JSObjectMake.
Definition: jsbindings.cpp:4376
AAMP_JSListener_AdReservationStart
Event listener impl for AD_RESOLVED AAMP event.
Definition: jsbindings.cpp:1485
AAMP_JSListener_MetricsData
AAMP_JSListener_MetricsData to receive aamp metrics.
Definition: jsbindings.cpp:1067
AAMP_setAlternateContent
static JSValueRef AAMP_setAlternateContent(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set alternate playback content URLs.
Definition: jsbindings.cpp:3441
AAMP_setContentProtectionDataConfig
static JSValueRef AAMP_setContentProtectionDataConfig(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to update content protection data value on key rotation.
Definition: jsbindings.cpp:4165
PlayerInstanceAAMP::Seek
void Seek(double secondsRelativeToTuneTime, bool keepPaused=false)
Seek to a time.
Definition: main_aamp.cpp:971
AAMP_setProperty_initialBufferTime
static bool AAMP_setProperty_initialBufferTime(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef *exception)
Callback invoked from JS to set the initialBufferTime property value.
Definition: jsbindings.cpp:171
AAMP_JSListener_DrmMessage::AAMP_JSListener_DrmMessage
AAMP_JSListener_DrmMessage(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_DrmMessage Constructor.
Definition: jsbindings.cpp:1825
PlayerInstanceAAMP::SetCCStatus
void SetCCStatus(bool enabled)
Set CC visibility on/off.
Definition: main_aamp.cpp:2620
AAMP_setRect
static JSValueRef AAMP_setRect(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set video rectangle co-ordinates.
Definition: jsbindings.cpp:2492
AAMP_EVENT_STATE_CHANGED
@ AAMP_EVENT_STATE_CHANGED
Definition: AampEvent.h:60
PlayerInstanceAAMP::SetCEAFormat
void SetCEAFormat(int format)
Set the CEA format for force setting.
Definition: main_aamp.cpp:2667
AAMP_getAudioTrackInfo
static JSValueRef AAMP_getAudioTrackInfo(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to get current audio track.
Definition: jsbindings.cpp:2932
PlayerInstanceAAMP::SetAuxiliaryLanguage
void SetAuxiliaryLanguage(const std::string &language)
Set auxiliary language.
Definition: main_aamp.cpp:2944
AAMP_getAudioTrack
static JSValueRef AAMP_getAudioTrack(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to get current audio track.
Definition: jsbindings.cpp:2908
AAMP_setProperty_preferredCEAFormat
static bool AAMP_setProperty_preferredCEAFormat(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef *exception)
Callback invoked from JS to set the preferred CEA format property value.
Definition: jsbindings.cpp:506
AAMP_JSListener_ContentProtectionData::AAMP_JSListener_ContentProtectionData
AAMP_JSListener_ContentProtectionData(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_ContentProtectionData Constructor.
Definition: jsbindings.cpp:1859
AAMP_JSListener_ContentGap::AAMP_JSListener_ContentGap
AAMP_JSListener_ContentGap(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_ContentGap Constructor.
Definition: jsbindings.cpp:1319
AAMP_JSListener_StatusChanged
Event listener for STATUS_CHANGED AAMP event.
Definition: jsbindings.cpp:1354
AAMP_JSListener_ContentGap::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:1329
AAMP_EVENT_SPEEDS_CHANGED
@ AAMP_EVENT_SPEEDS_CHANGED
Definition: AampEvent.h:61
EventType_class_ref
static JSClassRef EventType_class_ref()
Creates a JavaScript class of EventType for use with JSObjectMake.
Definition: jsbindings.cpp:4624
AAMP_JSListener_ContentProtectionData
Event listener impl for (AAMP_EVENT_CONTENT_PROTECTION_DATA_UPDATE) AAMP event.
Definition: jsbindings.cpp:1849
AAMP_JSListener_AdPlacementStart
Event listener impl for AD_RESOLVED AAMP event.
Definition: jsbindings.cpp:1565
JSContextGetGlobalContext
JS_EXPORT JSGlobalContextRef JSContextGetGlobalContext(JSContextRef)
Get the global JS execution context.
AAMP_EVENT_AD_PLACEMENT_PROGRESS
@ AAMP_EVENT_AD_PLACEMENT_PROGRESS
Definition: AampEvent.h:80
AAMP_setPreferredDRM
static JSValueRef AAMP_setPreferredDRM(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set the preferred DRM.
Definition: jsbindings.cpp:3324
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
AAMP_EVENT_SPEED_CHANGED
@ AAMP_EVENT_SPEED_CHANGED
Definition: AampEvent.h:49
EventType_getproperty_DECODER_AVAILABLE
static JSValueRef EventType_getproperty_DECODER_AVAILABLE(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception)
Callback invoked from JS to get the DECODER_AVAILABLE property value.
Definition: jsbindings.cpp:4468
aamp_getEventTypeFromName
AAMPEventType aamp_getEventTypeFromName(const char *szName)
Convert JS event name to AAMP event type.
Definition: jsutils.cpp:324
PlayerInstanceAAMP::GetAudioTrackInfo
std::string GetAudioTrackInfo()
Get current audio track index.
Definition: main_aamp.cpp:2438
AAMP_addCustomHTTPHeader
static JSValueRef AAMP_addCustomHTTPHeader(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to add a custom HTTP header/s.
Definition: jsbindings.cpp:2745
aamp_CreateTimedMetadataJSObject
JSObjectRef aamp_CreateTimedMetadataJSObject(JSContextRef context, long long timeMS, const char *szName, const char *szContent, const char *id, double durationMS)
Create a TimedMetadata JS object with args passed. Sample input "#EXT-X-CUE:ID=eae90713-db8e,...
Definition: jsutils.cpp:396
AAMP_JSListener_SpeedsChanged
Event listener impl for SPEEDS_CHANGED AAMP event.
Definition: jsbindings.cpp:1392
PlayerInstanceAAMP::SetStallErrorCode
void SetStallErrorCode(int errorCode)
To set the error code to be used for playback stalled error.
Definition: main_aamp.cpp:1684
AAMP_EVENT_AD_RESOLVED
@ AAMP_EVENT_AD_RESOLVED
Definition: AampEvent.h:74
EventType_getproperty_MEDIA_STOPPED
static JSValueRef EventType_getproperty_MEDIA_STOPPED(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception)
Callback invoked from JS to get the MEDIA_STOPPED property value.
Definition: jsbindings.cpp:4548
AAMP_JSListener_MetricsData::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set the Aamp Event properties.
Definition: jsbindings.cpp:1088
AAMP_JSListener_AdResolved::AAMP_JSListener_AdResolved
AAMP_JSListener_AdResolved(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_AdResolved Constructor.
Definition: jsbindings.cpp:1447
AAMP_setTextTrack
static JSValueRef AAMP_setTextTrack(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set text track.
Definition: jsbindings.cpp:3178
AAMP_EVENT_CONTENT_PROTECTION_DATA_UPDATE
@ AAMP_EVENT_CONTENT_PROTECTION_DATA_UPDATE
Definition: AampEvent.h:88
PlayerInstanceAAMP::IsJsInfoLoggingEnabled
bool IsJsInfoLoggingEnabled()
Get jsinfo config value (default false)
Definition: main_aamp.cpp:1514
AAMPEvent
Structure of the AAMP events. Recommend new AAMP integration layers to use AAMPEventObject based list...
Definition: AampEvent.h:204
AAMP_removeCustomHTTPHeader
static JSValueRef AAMP_removeCustomHTTPHeader(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to remove custom HTTP headers.
Definition: jsbindings.cpp:2809
AAMP_getProperty_Version
static JSValueRef AAMP_getProperty_Version(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception)
Callback invoked from JS to get the version property value.
Definition: jsbindings.cpp:291
PlayerInstanceAAMP::SetAudioVolume
void SetAudioVolume(int volume)
Set Audio Volume.
Definition: main_aamp.cpp:1361
AAMP_JSListener::Event
void Event(const AAMPEventPtr &e)
Dispatch JS event for the corresponding AAMP event.
Definition: jsbindings.cpp:685
LOG_WARN_EX
#define LOG_WARN_EX(FORMAT,...)
Definition: jsutils.h:44
AAMP_JSListener_VideoMetadata::AAMP_JSListener_VideoMetadata
AAMP_JSListener_VideoMetadata(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_VideoMetadata Constructor.
Definition: jsbindings.cpp:1156
AAMP_setLanguage
static JSValueRef AAMP_setLanguage(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set preferred audio language.
Definition: jsbindings.cpp:2655
Event_constructor
static JSObjectRef Event_constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef *execption)
callback invoked when Event is used along with 'new'
Definition: jsbindings.cpp:589
AAMP_getPreferredTextProperties
static JSValueRef AAMP_getPreferredTextProperties(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to get preferred text properties.
Definition: jsbindings.cpp:3078
AAMP_staticfunctions
static const JSStaticFunction AAMP_staticfunctions[]
Array containing the AAMP's statically declared functions.
Definition: jsbindings.cpp:4230
AAMP_JSListener_BufferingChanged::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:1750
AAMP_JSListener_AdPlacementEnd
Event listener impl for AD_RESOLVED AAMP event.
Definition: jsbindings.cpp:1605
PlayerInstanceAAMP::GetPreferredAudioProperties
std::string GetPreferredAudioProperties()
Get preferred audio prioperties.
Definition: main_aamp.cpp:2345
AAMP_getTextTrack
static JSValueRef AAMP_getTextTrack(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to get current text track index.
Definition: jsbindings.cpp:3153
PlayerInstanceAAMP::ProcessContentProtectionDataConfig
void ProcessContentProtectionDataConfig(const char *jsonbuffer)
Definition: main_aamp.cpp:3026
Event_finalize
static void Event_finalize(JSObjectRef thisObject)
Callback invoked when an object of Event is finalized.
Definition: jsbindings.cpp:567
AAMP_getProperty_CurrentDRM
static JSValueRef AAMP_getProperty_CurrentDRM(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception)
Callback invoked from JS to get the currentDRM property value.
Definition: jsbindings.cpp:338
AAMP_JSListener
Event listener impl for AAMP events.
Definition: jsbindings.cpp:637
AAMP_tune
static JSValueRef AAMP_tune(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to start playback for requested URL.
Definition: jsbindings.cpp:2194
EventType_staticprops
static const JSStaticValue EventType_staticprops[]
Array containing the EventType's statically declared value properties.
Definition: jsbindings.cpp:4558
AAMP_JSListener_DRMMetadata::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
set the aamp event properties
Definition: jsbindings.cpp:1000
aamp_JSValueToCString
char * aamp_JSValueToCString(JSContextRef context, JSValueRef value, JSValueRef *exception)
Convert JSString to C string.
Definition: jsutils.cpp:164
AAMP_JSListener::operator=
AAMP_JSListener & operator=(const AAMP_JSListener &)=delete
AAMP_JSListener Assignment operator overloading.
AAMP_EVENT_ID3_METADATA
@ AAMP_EVENT_ID3_METADATA
Definition: AampEvent.h:82
AAMP_JS_AddEventTypeClass
JSObjectRef AAMP_JS_AddEventTypeClass(JSGlobalContextRef context)
Create a EventType JS object.
Definition: jsbindings.cpp:4638
AAMP_JSListener_AdReservationEnd::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:1545
AAMP_JSListener_AdProgress::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:1666
priv_aamp.h
Private functions and types used internally by AAMP.
AAMP_JSListener_BitRateChanged
Event listener impl for BITRATE_CHANGED AAMP event.
Definition: jsbindings.cpp:805
PlayerInstanceAAMP::SetRate
void SetRate(float rate, int overshootcorrection=0)
Set playback rate.
Definition: main_aamp.cpp:561
AAMP_setNetworkTimeout
static JSValueRef AAMP_setNetworkTimeout(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set network timeout value.
Definition: jsbindings.cpp:3804
AAMP_JSListener::~AAMP_JSListener
virtual ~AAMP_JSListener()
AAMP_JSListener Destructor.
Definition: jsbindings.cpp:665
AAMP_EVENT_REPORT_METRICS_DATA
@ AAMP_EVENT_REPORT_METRICS_DATA
Definition: AampEvent.h:81
PlayerInstanceAAMP::GetCurrentAudioLanguage
const char * GetCurrentAudioLanguage()
Get current audio language.
Definition: main_aamp.cpp:1523
AAMP_JSListener_VideoMetadata
Event listener impl for VIDEO_METADATA AAMP event.
Definition: jsbindings.cpp:1146
PlayerInstanceAAMP::SetSessionToken
void SetSessionToken(std::string sessionToken)
Set the session token for player.
Definition: main_aamp.cpp:2712
EventType_getproperty_ENTERING_LIVE
static JSValueRef EventType_getproperty_ENTERING_LIVE(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception)
Callback invoked from JS to get the ENTERING_LIVE property value.
Definition: jsbindings.cpp:4518
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
AAMP_JSListener_Progress
Event listener impl for REPORT_PROGRESS AAMP event.
Definition: jsbindings.cpp:741
EventType_getproperty_DRM_METADATA
static JSValueRef EventType_getproperty_DRM_METADATA(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception)
Callback invoked from JS to get the DRM_METADATA property value.
Definition: jsbindings.cpp:4501
AAMP_JSListener_Progress::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:761
AAMP_EVENT_AD_RESERVATION_START
@ AAMP_EVENT_AD_RESERVATION_START
Definition: AampEvent.h:75
AAMP_JSListener_StatusChanged::AAMP_JSListener_StatusChanged
AAMP_JSListener_StatusChanged(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_StatusChanged Constructor.
Definition: jsbindings.cpp:1364
PrivateInstanceAAMP
Class representing the AAMP player's private instance, which is not exposed to outside world.
Definition: priv_aamp.h:640
PlayerInstanceAAMP::SetNetworkTimeout
void SetNetworkTimeout(double timeout)
To override default curl timeout for playlist/fragment downloads.
Definition: main_aamp.cpp:1991
PlayerInstanceAAMP::GetTextTrack
int GetTextTrack()
Get current text track index.
Definition: main_aamp.cpp:2610
AAMP_EVENT_CC_HANDLE_RECEIVED
@ AAMP_EVENT_CC_HANDLE_RECEIVED
Definition: AampEvent.h:53
PlayerInstanceAAMP::SetPreferredDRM
void SetPreferredDRM(DRMSystems drmType)
Set Preferred DRM.
Definition: main_aamp.cpp:2027
AAMP_JSListener_BitRateChanged::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:825
AAMP_JSListener_AdPlacementEror::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:1706
AAMP_setProperty_trickPlayEnabled
static bool AAMP_setProperty_trickPlayEnabled(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef *exception)
Callback invoked from JS to set the trickPlayEnabled property value.
Definition: jsbindings.cpp:216
PlayerInstanceAAMP::SetNativeCCRendering
void SetNativeCCRendering(bool enable)
Enable/disable the native CC rendering feature.
Definition: main_aamp.cpp:2488
PlayerInstanceAAMP::GetAvailableTextTracks
std::string GetAvailableTextTracks(bool allTrack=false)
Get available text tracks.
Definition: main_aamp.cpp:2460
AAMP_JSListener_BulkTimedMetadata::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:1257
AAMP_setContentProtectionDataUpdateTimeout
static JSValueRef AAMP_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: jsbindings.cpp:4127
AAMP_EVENT_MEDIA_METADATA
@ AAMP_EVENT_MEDIA_METADATA
Definition: AampEvent.h:55
AAMP_setProperty_stallErrorCode
static bool AAMP_setProperty_stallErrorCode(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef *exception)
Callback invoked from JS to set the stallErrorCode property value.
Definition: jsbindings.cpp:408
PlayerInstanceAAMP::EnableVideoRectangle
void EnableVideoRectangle(bool rectProperty)
Set video rectangle property.
Definition: main_aamp.cpp:2506
EventType_init
static void EventType_init(JSContextRef ctx, JSObjectRef thisObject)
Callback invoked from JS when an object of EventType is first created.
Definition: jsbindings.cpp:4579
AAMP_setLicenseCaching
static JSValueRef AAMP_setLicenseCaching(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set the license caching config.
Definition: jsbindings.cpp:3995
EventType_finalize
static void EventType_finalize(JSObjectRef thisObject)
Callback invoked when an object of EventType is finalized.
Definition: jsbindings.cpp:4589
AAMP_getProperty_MediaType
static JSValueRef AAMP_getProperty_MediaType(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception)
Callback invoked from JS to get the mediaType property value.
Definition: jsbindings.cpp:261
PlayerInstanceAAMP::SetDownloadStallTimeout
void SetDownloadStallTimeout(long stallTimeout)
To set the curl stall timeout value.
Definition: main_aamp.cpp:2133
AAMP_JSListener_BufferingChanged
Event listener impl for (AAMP_EVENT_BUFFER_UNDERFLOW) AAMP event.
Definition: jsbindings.cpp:1730
AAMP_JSListener_AdPlacementStart::AAMP_JSListener_AdPlacementStart
AAMP_JSListener_AdPlacementStart(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_AdPlacementStart Constructor.
Definition: jsbindings.cpp:1575
AAMP_JSListener_AnomalyReport::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Definition: jsbindings.cpp:1044
LOG_INFO
#define LOG_INFO(AAMP_JS_OBJECT, FORMAT,...)
Definition: jsutils.h:39
AAMP_getAvailableTextTracks
static JSValueRef AAMP_getAvailableTextTracks(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to get list of text tracks.
Definition: jsbindings.cpp:3113
AAMPEventType
AAMPEventType
Type of the events sending to the JSPP player.
Definition: AampEvent.h:44
EventType_object_def
static const JSClassDefinition EventType_object_def
Structure contains properties and callbacks of EventType object.
Definition: jsbindings.cpp:4598
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
PlayerInstanceAAMP::SetLicenseServerURL
void SetLicenseServerURL(const char *url, DRMSystems type=eDRM_MAX_DRMSystems)
Set License Server URL.
Definition: main_aamp.cpp:1590
PlayerInstanceAAMP::Stop
void Stop(bool sendStateChangeEvent=true)
Stop playback and release resources.
Definition: main_aamp.cpp:282
eTUNED_EVENT_ON_PLAYLIST_INDEXED
@ eTUNED_EVENT_ON_PLAYLIST_INDEXED
Definition: AampDefine.h:186
AAMP_EVENT_AD_PLACEMENT_START
@ AAMP_EVENT_AD_PLACEMENT_START
Definition: AampEvent.h:77
AAMP_JSListener_DRMMetadata::AAMP_JSListener_DRMMetadata
AAMP_JSListener_DRMMetadata(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_DRMMetadata Constructor.
Definition: jsbindings.cpp:989
AAMP_JSListener_AdReservationStart::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:1505
AAMP_EVENT_TIMED_METADATA
@ AAMP_EVENT_TIMED_METADATA
Definition: AampEvent.h:58
AAMP_setProperty_stallTimeout
static bool AAMP_setProperty_stallTimeout(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef *exception)
Callback invoked from JS to set the stallTimeout property value.
Definition: jsbindings.cpp:433
PlayerInstanceAAMP::GetId
int GetId(void)
Definition: main_aamp.cpp:1750
AAMP_JSListener_SpeedsChanged::AAMP_JSListener_SpeedsChanged
AAMP_JSListener_SpeedsChanged(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_SpeedsChanged Constructor.
Definition: jsbindings.cpp:1402
AAMP_setProperty_enableNativeCC
static bool AAMP_setProperty_enableNativeCC(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef *exception)
Callback invoked from JS to set the enableNativeCC property value.
Definition: jsbindings.cpp:482
AAMP_seekToLive
static JSValueRef AAMP_seekToLive(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to perform seek to live point.
Definition: jsbindings.cpp:2464
AAMP_JSListener_AdProgress
Event listener impl for REPORT_AD_PROGRESS AAMP event.
Definition: jsbindings.cpp:1645
AAMP_JSListener_MetricsData::AAMP_JSListener_MetricsData
AAMP_JSListener_MetricsData(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_DRMMetadata Constructor.
Definition: jsbindings.cpp:1077
PlayerInstanceAAMP::SetTextStyle
void SetTextStyle(const std::string &options)
Set style options for text track rendering.
Definition: main_aamp.cpp:2638
AAMP_setLicenseServerURL
static JSValueRef AAMP_setLicenseServerURL(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set license server URL.
Definition: jsbindings.cpp:3287
AAMP_setVideoMute
static JSValueRef AAMP_setVideoMute(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set video mute status.
Definition: jsbindings.cpp:2533
AAMP_JSListener_AnomalyReport::AAMP_JSListener_AnomalyReport
AAMP_JSListener_AnomalyReport(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_DRMMetadata Constructor.
Definition: jsbindings.cpp:1033
AAMP_setZoom
static JSValueRef AAMP_setZoom(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set preferred zoom setting.
Definition: jsbindings.cpp:2608
AAMP_JSListener_Id3Metadata
Event listener impl for (AAMP_JSListener_Id3Metadata) AAMP event.
Definition: jsbindings.cpp:1767
AAMP_EVENT_PROGRESS
@ AAMP_EVENT_PROGRESS
Definition: AampEvent.h:52
AAMP_setProperty_closedCaptionEnabled
static bool AAMP_setProperty_closedCaptionEnabled(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef *exception)
Callback invoked from JS to set the closedCaptionEnabled property value.
Definition: jsbindings.cpp:125
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
AAMP_setVideoTracks
static JSValueRef AAMP_setVideoTracks(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set video track.
Definition: jsbindings.cpp:3254
PlayerInstanceAAMP::SeekToLive
void SeekToLive(bool keepPaused=false)
Seek to live point.
Definition: main_aamp.cpp:1144
AAMP_JS
Data structure of AAMP object.
Definition: jsbindings.cpp:64
AAMP_setAds
static JSValueRef AAMP_setAds(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set an ad.
Definition: jsbindings.cpp:2850
AAMP_setLinearTrickplayFPS
static JSValueRef AAMP_setLinearTrickplayFPS(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set linear trickplay FPS.
Definition: jsbindings.cpp:3614
PlayerInstanceAAMP::SetSubscribedTags
void SetSubscribedTags(std::vector< std::string > subscribedTags)
Set array of subscribed tags.
Definition: main_aamp.cpp:1415
AAMP_getAvailableVideoTracks
static JSValueRef AAMP_getAvailableVideoTracks(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to get list of video tracks.
Definition: jsbindings.cpp:3221
AAMP_JSListener_Id3Metadata::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:1787
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
AAMP_JSListener_AdPlacementEnd::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:1625
AampCCManager.h
Integration layer of ClosedCaption in AAMP.
PlayerInstanceAAMP::SetVideoMute
void SetVideoMute(bool muted)
Enable/ Disable Video.
Definition: main_aamp.cpp:1303
AAMP_JSListener_ContentProtectionData::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:1869
AAMP_setAudioTrack
static JSValueRef AAMP_setAudioTrack(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to set audio track.
Definition: jsbindings.cpp:3033
aamp_JSValueIsArray
bool aamp_JSValueIsArray(JSContextRef context, JSValueRef value)
Check if a JSValue object is array or not.
Definition: jsutils.cpp:190
AAMP_JSListener_BulkTimedMetadata::AAMP_JSListener_BulkTimedMetadata
AAMP_JSListener_BulkTimedMetadata(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_TimedMetadata Constructor.
Definition: jsbindings.cpp:1247
LangCodePreference
LangCodePreference
Language Code Preference types.
Definition: main_aamp.h:165
PlayerInstanceAAMP::SetTuneEventConfig
void SetTuneEventConfig(int tuneEventType)
To set the vod-tune-event according to the player.
Definition: main_aamp.cpp:2498
EventType_getproperty_BUFFERING_END
static JSValueRef EventType_getproperty_BUFFERING_END(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef *exception)
Callback invoked from JS to get the BUFFERING_END property value.
Definition: jsbindings.cpp:4453
AAMP_JSListener_AnomalyReport
AAMP_JSListener_AnomalyReport to receive anomalyreport.
Definition: jsbindings.cpp:1023
AAMP_EVENT_BITRATE_CHANGED
@ AAMP_EVENT_BITRATE_CHANGED
Definition: AampEvent.h:57
Event_init
static void Event_init(JSContextRef ctx, JSObjectRef thisObject)
Callback invoked from JS when an object of Event is first created.
Definition: jsbindings.cpp:557
AAMP_getTextStyleOptions
static JSValueRef AAMP_getTextStyleOptions(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to get text style.
Definition: jsbindings.cpp:3924
AAMP_getPreferredAudioProperties
static JSValueRef AAMP_getPreferredAudioProperties(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to get current audio track.
Definition: jsbindings.cpp:2999
AAMP_EVENT_AD_PLACEMENT_ERROR
@ AAMP_EVENT_AD_PLACEMENT_ERROR
Definition: AampEvent.h:79
AAMP_JSListener_DrmMessage::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:1835
AAMP_JSListener_Progress::AAMP_JSListener_Progress
AAMP_JSListener_Progress(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_Progress Constructor.
Definition: jsbindings.cpp:751
AAMP_JSListener_TuneFailed::AAMP_JSListener_TuneFailed
AAMP_JSListener_TuneFailed(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_TuneFailed Constructor.
Definition: jsbindings.cpp:927
LOG_TRACE
#define LOG_TRACE
Definition: rdk_debug_priv.c:83
AAMP_JSListener_DRMMetadata
Class handles JS Listener for DRM meta data operation.
Definition: jsbindings.cpp:979
PlayerInstanceAAMP::SetReportInterval
void SetReportInterval(int reportInterval)
To set the Playback Position reporting interval.
Definition: main_aamp.cpp:1702
AAMP_load
static JSValueRef AAMP_load(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to start playback for requested URL.
Definition: jsbindings.cpp:2253
AAMP_JSListener_StatusChanged::setEventProperties
void setEventProperties(const AAMPEventPtr &e, JSContextRef context, JSObjectRef eventObj)
Set JS event properties.
Definition: jsbindings.cpp:1374
AAMP_JSListener_TuneFailed
Event listener impl for TUNE_FAILED AAMP event.
Definition: jsbindings.cpp:917
AAMP_stop
static JSValueRef AAMP_stop(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to stop active playback.
Definition: jsbindings.cpp:2350
AAMP_JSListener_AdProgress::AAMP_JSListener_AdProgress
AAMP_JSListener_AdProgress(AAMP_JS *aamp, AAMPEventType type, JSObjectRef jsCallback)
AAMP_JSListener_AdProgress Constructor.
Definition: jsbindings.cpp:1655
AAMP_JSListener_ContentGap
Event listener impl for AAMP_EVENT_CONTENT_GAP event.
Definition: jsbindings.cpp:1310
AAMP_addEventListener
static JSValueRef AAMP_addEventListener(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Callback invoked from JS to add an event listener for a particular event.
Definition: jsbindings.cpp:1904