This repository has been archived by the owner on Jan 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
ota_shim.cpp
1161 lines (1020 loc) · 35.5 KB
/
ota_shim.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* If not stated otherwise in this file or this component's license file the
* following copyright and licenses apply:
*
* Copyright 2018 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file ota_shim.cpp
* @brief shim for dispatching UVE OTA ATSC playback
*/
#include "AampUtils.h"
#include "ota_shim.h"
#include "priv_aamp.h"
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <signal.h>
#include <assert.h>
#ifdef USE_CPP_THUNDER_PLUGIN_ACCESS
#include <core/core.h>
#include <websocket/websocket.h>
using namespace std;
using namespace WPEFramework;
#endif
#ifdef USE_CPP_THUNDER_PLUGIN_ACCESS
#define MEDIAPLAYER_CALLSIGN "org.rdk.MediaPlayer.1"
#define MEDIASETTINGS_CALLSIGN "org.rdk.MediaSettings.1"
#define APP_ID "MainPlayer"
#define RDKSHELL_CALLSIGN "org.rdk.RDKShell.1"
ATSCGlobalSettings gATSCSettings;
void StreamAbstractionAAMP_OTA::onPlayerStatusHandler(const JsonObject& parameters) {
std::string message;
parameters.ToString(message);
JsonObject playerData = parameters[APP_ID].Object();
AAMPLOG_TRACE( "[OTA_SHIM]Received event : message : %s ", message.c_str());
/* For detailed event data, we can print or use details like
playerData["locator"].String(), playerData["length"].String(), playerData["position"].String() */
std::string currState = playerData["playerStatus"].String();
bool blockedReasonChanged = false;
std::string reason("");
if(0 == currState.compare("BLOCKED"))
{
reason = playerData["blockedReason"].String();
if(0 != reason.compare(prevBlockedReason))
{
blockedReasonChanged = true;
}
}
if(0 != prevState.compare(currState) || blockedReasonChanged)
{
PrivAAMPState state = eSTATE_IDLE;
prevBlockedReason.clear();
AAMPLOG_WARN( "[OTA_SHIM] State changed from %s to %s ", prevState.c_str(), currState.c_str());
prevState = currState;
if(0 == currState.compare("PENDING"))
{
state = eSTATE_PREPARING;
}else if((0 == currState.compare("BLOCKED")) && (0 != reason.compare("NOT_BLOCKED")))
{
std::string ratingString;
JsonObject ratingObj = playerData["rating"].Object();
ratingObj.ToString(ratingString);
AAMPLOG_WARN( "[OTA_SHIM] Received BLOCKED event from player with REASON: %s Current Ratings: %s", reason.c_str(), ratingString.c_str());
aamp->SendAnomalyEvent(ANOMALY_WARNING,"BLOCKED REASON:%s", reason.c_str());
aamp->SendBlockedEvent(reason);
state = eSTATE_BLOCKED;
prevBlockedReason = reason;
}else if(0 == currState.compare("PLAYING"))
{
if(!tuned){
aamp->SendTunedEvent(false);
/* For consistency, during first tune, first move to
PREPARED state to match normal IPTV flow sequence */
aamp->SetState(eSTATE_PREPARED);
tuned = true;
aamp->LogFirstFrame();
aamp->LogTuneComplete();
}
std::string ratingString;
JsonObject ratingObj = playerData["rating"].Object();
ratingObj.ToString(ratingString);
AAMPLOG_WARN( "[OTA_SHIM] PLAYING STATE Current Ratings : %s", ratingString.c_str());
state = eSTATE_PLAYING;
}else if(0 == currState.compare("DONE"))
{
if(tuned){
tuned = false;
}
state = eSTATE_COMPLETE;
}else
{
if(0 == currState.compare("IDLE"))
{
aamp->SendAnomalyEvent(ANOMALY_WARNING, "ATSC Tuner Idle");
}else{
/* Currently plugin lists only "IDLE","ERROR","PROCESSING","PLAYING"&"DONE" */
AAMPLOG_INFO( "[OTA_SHIM] Unsupported state change!");
}
/* Need not set a new state hence returning */
return;
}
aamp->SetState(state);
}
if((0 == currState.compare("PLAYING")) || (0 == currState.compare("BLOCKED")) && 0 == reason.compare("SERVICE_PIN_LOCKED"))
{
if(PopulateMetaData(playerData))
{
SendMediaMetadataEvent();
// genereate Notify bitrate event if video w/h is changed
// this is lagacy event used by factory test app to get video info
if( (miPrevmiVideoWidth != miVideoWidth) || (miPrevmiVideoHeight != miVideoHeight) )
{
miPrevmiVideoWidth = miVideoWidth;
miPrevmiVideoHeight = miVideoHeight;
aamp->NotifyBitRateChangeEvent(mVideoBitrate, eAAMP_BITRATE_CHANGE_BY_OTA, miVideoWidth, miVideoHeight, mFrameRate, 0, false, mVideoScanType, mAspectRatioWidth, mAspectRatioHeight);
}
}
}
}
/**
* @brief reads metadata properties from player status object and return true if any of data is changed
*/
bool StreamAbstractionAAMP_OTA::PopulateMetaData(const JsonObject& playerData)
{
bool isDataChanged = false;
std::string ratingString;
JsonObject ratingObj = playerData["rating"].Object();
ratingObj.ToString(ratingString);
if( mPCRating != ratingString )
{
AAMPLOG_INFO( "[OTA_SHIM]ratings changed : old:%s new:%s ", mPCRating.c_str(), ratingString.c_str());
mPCRating = ratingString;
isDataChanged = true;
}
int tempSSI = playerData["ssi"].Number();
if(tempSSI != mSsi)
{
AAMPLOG_INFO( "[OTA_SHIM]SSI changed : old:%d new:%d ", mSsi, tempSSI);
mSsi = tempSSI;
isDataChanged = true;
}
/* Video info */
JsonObject videoInfoObj = playerData["videoInfo"].Object();
VideoScanType tempScanType = (videoInfoObj["progressive"].Boolean() ? eVIDEOSCAN_PROGRESSIVE : eVIDEOSCAN_INTERLACED);
if(mVideoScanType != tempScanType)
{
AAMPLOG_INFO( "[OTA_SHIM]Scan type changed : old:%d new:%d ", mVideoScanType, tempScanType);
isDataChanged = true;
mVideoScanType = tempScanType;
}
float tempframeRate = 0.0;
float frameRateN = static_cast<float> (videoInfoObj["frameRateN"].Number());
float frameRateD = static_cast<float> (videoInfoObj["frameRateD"].Number());
if((0 != frameRateN) && (0 != frameRateD))
{
tempframeRate = frameRateN / frameRateD;
if( mFrameRate != tempframeRate)
{
AAMPLOG_INFO( "[OTA_SHIM] mFrameRate changed : old:%f new:%f ", mFrameRate, tempframeRate);
isDataChanged = true;
mFrameRate = tempframeRate;
}
}
int tempAspectRatioWidth = videoInfoObj["aspectRatioWidth"].Number();
if( tempAspectRatioWidth != mAspectRatioWidth)
{
isDataChanged = true;
AAMPLOG_INFO( "[OTA_SHIM] mAspectRatioWidth changed : old:%d new:%d ", mAspectRatioWidth, tempAspectRatioWidth);
mAspectRatioWidth = tempAspectRatioWidth;
}
int tempAspectRatioHeight = videoInfoObj["aspectRatioHeight"].Number();
if( mAspectRatioHeight != tempAspectRatioHeight)
{
AAMPLOG_INFO( "[OTA_SHIM] tempAspectRatioHeight : old:%d new:%d ", mAspectRatioHeight, tempAspectRatioHeight);
isDataChanged = true;
mAspectRatioHeight = tempAspectRatioHeight;
}
int tempVideoWidth = videoInfoObj["width"].Number();
if( miVideoWidth != tempVideoWidth)
{
AAMPLOG_INFO( "[OTA_SHIM] miVideoWidth : old:%d new:%d ", miVideoWidth, tempVideoWidth);
miVideoWidth = tempVideoWidth;
isDataChanged = true;
}
int tempVideoHeight = videoInfoObj["height"].Number();
if( miVideoHeight != tempVideoHeight)
{
AAMPLOG_INFO( "[OTA_SHIM] miVideoHeight : old:%d new:%d ", miVideoHeight, tempVideoHeight);
miVideoHeight = tempVideoHeight;
isDataChanged = true;
}
std::string tempVideoCodec = videoInfoObj["codec"].String();
if(0 != mVideoCodec.compare(tempVideoCodec))
{
AAMPLOG_INFO( "[OTA_SHIM] mVideoCodec : old:%s new:%s ", mVideoCodec.c_str(), tempVideoCodec.c_str());
mVideoCodec = tempVideoCodec;
isDataChanged = true;
}
mHdrType = videoInfoObj["hdrType"].String();
/* Audio Info */
JsonObject audioInfoObj = playerData["audioInfo"].Object();
std::string tempAudioCodec = audioInfoObj["codec"].String();
if(0 != mAudioCodec.compare(tempAudioCodec))
{
AAMPLOG_INFO( "[OTA_SHIM] tempAudioCodec : old:%s new:%s ", mAudioCodec.c_str(), mAudioCodec.c_str());
mAudioCodec = tempAudioCodec;
isDataChanged = true;
}
std::string tempAudioMixType = audioInfoObj["mixType"].String();
if(0 != mAudioMixType.compare(tempAudioMixType))
{
AAMPLOG_INFO( "[OTA_SHIM] tempAudioMixType : old:%s new:%s ", mAudioMixType.c_str(), tempAudioMixType.c_str());
mAudioMixType = tempAudioMixType;
isDataChanged = true;
}
bool tempIsAtmos = audioInfoObj["isAtmos"].Boolean();
if( mIsAtmos != tempIsAtmos)
{
AAMPLOG_INFO( "[OTA_SHIM] -- mIsAtmos : old:%d new:%d ", mIsAtmos, tempIsAtmos);
mIsAtmos = tempIsAtmos;
isDataChanged = true;
}
if( isDataChanged )
{
mVideoBitrate = videoInfoObj["bitrate"].Number();
mAudioBitrate = audioInfoObj["bitrate"].Number();
}
return isDataChanged;
}
void StreamAbstractionAAMP_OTA::SendMediaMetadataEvent()
{
if(aamp->IsEventListenerAvailable(AAMP_EVENT_MEDIA_METADATA))
{
MediaMetadataEventPtr event = std::make_shared<MediaMetadataEvent>(-1/*duration*/, miVideoWidth, miVideoHeight, false/*hasDrm*/,true/*isLive*/, ""/*drmtype*/, -1/*programStartTime*/);
// This is video bitrate
event->addBitrate(mVideoBitrate);
event->addSupportedSpeed(1);
event->SetVideoMetaData(mFrameRate,mVideoScanType,mAspectRatioWidth,mAspectRatioHeight, mVideoCodec, mHdrType, mPCRating,mSsi);
event->SetAudioMetaData(mAudioCodec,mAudioMixType,mIsAtmos);
event->addAudioBitrate(mAudioBitrate);
aamp->SendEvent(event,AAMP_EVENT_ASYNC_MODE);
}
}
#endif
/**
* @brief Initialize a newly created object.
*/
AAMPStatusType StreamAbstractionAAMP_OTA::Init(TuneType tuneType)
{
#ifndef USE_CPP_THUNDER_PLUGIN_ACCESS
AAMPLOG_WARN( "[OTA_SHIM]Inside CURL ACCESS" );
AAMPStatusType retval = eAAMPSTATUS_OK;
#else
AAMPLOG_INFO("[OTA_SHIM]Inside" );
prevState = "IDLE";
//initialize few veriables, it will invalidate mediametadata/Notifybitrate events
miVideoWidth = 0;
miVideoHeight = 0;
miPrevmiVideoWidth = 0;
miPrevmiVideoHeight = 0;
prevBlockedReason = "";
tuned = false;
aamp->SetContentType("OTA");
thunderAccessObj.ActivatePlugin();
mediaSettingsObj.ActivatePlugin();
std::function<void(const WPEFramework::Core::JSON::VariantContainer&)> actualMethod = std::bind(&StreamAbstractionAAMP_OTA::onPlayerStatusHandler, this, std::placeholders::_1);
//mEventSubscribed flag updated for tracking event subscribtion
mEventSubscribed = thunderAccessObj.SubscribeEvent(_T("onPlayerStatus"), actualMethod);
AAMPStatusType retval = eAAMPSTATUS_OK;
//activate RDK Shell - not required as this plugin is already activated
// thunderRDKShellObj.ActivatePlugin();
#endif
return retval;
}
/**
* @brief StreamAbstractionAAMP_OTA Constructor
*/
StreamAbstractionAAMP_OTA::StreamAbstractionAAMP_OTA(AampLogManager *logObj, class PrivateInstanceAAMP *aamp,double seek_pos, float rate)
: StreamAbstractionAAMP(logObj, aamp)
#ifdef USE_CPP_THUNDER_PLUGIN_ACCESS
, tuned(false),mEventSubscribed(false),
thunderAccessObj(MEDIAPLAYER_CALLSIGN, logObj),
mediaSettingsObj(MEDIASETTINGS_CALLSIGN, logObj),
thunderRDKShellObj(RDKSHELL_CALLSIGN,logObj),
mPCRating(),mSsi(-1),mFrameRate(0),mVideoScanType(eVIDEOSCAN_UNKNOWN),mAspectRatioWidth(0),mAspectRatioHeight(0),
mVideoCodec(),mHdrType(),mAudioBitrate(0),mAudioCodec(),mAudioMixType(),mIsAtmos(false),
miVideoWidth(0),miVideoHeight(0),miPrevmiVideoWidth(0),miPrevmiVideoHeight(0)
#endif
{ // STUB
}
/**
* @brief StreamAbstractionAAMP_OTA Distructor
*/
StreamAbstractionAAMP_OTA::~StreamAbstractionAAMP_OTA()
{
#ifndef USE_CPP_THUNDER_PLUGIN_ACCESS
/*
Request : {"jsonrpc":"2.0", "id":3, "method": "org.rdk.MediaPlayer.1.release", "params":{ "id":"MainPlayer", "tag" : "MyApp"} }
Response: { "jsonrpc":"2.0", "id":3, "result": { "success": true } }
*/
std::string id = "3";
std:: string response = aamp_PostJsonRPC(id, "org.rdk.MediaPlayer.1.release", "{\"id\":\"MainPlayer\",\"tag\" : \"MyApp\"}");
AAMPLOG_WARN( "StreamAbstractionAAMP_OTA: response '%s'", response.c_str());
#else
JsonObject param;
JsonObject result;
param["id"] = APP_ID;
param["tag"] = "MyApp";
thunderAccessObj.InvokeJSONRPC("release", param, result);
// unsubscribing only if subscribed
if (mEventSubscribed)
{
thunderAccessObj.UnSubscribeEvent(_T("onPlayerStatus"));
mEventSubscribed = false;
}
else
{
AAMPLOG_WARN("[OTA_SHIM]OTA Destructor finds Player Status Event not Subscribed !! ");
}
AAMPLOG_INFO("[OTA_SHIM]StreamAbstractionAAMP_OTA Destructor called !! ");
#endif
}
/**
* @brief Starts streaming.
*/
void StreamAbstractionAAMP_OTA::Start(void)
{
std::string id = "3";
std::string response;
const char *display = getenv("WAYLAND_DISPLAY");
std::string waylandDisplay;
if( display )
{
waylandDisplay = display;
AAMPLOG_WARN( "WAYLAND_DISPLAY: '%s'", display );
}
else
{
AAMPLOG_WARN( "WAYLAND_DISPLAY: NULL!" );
}
std::string url = aamp->GetManifestUrl();
#ifndef USE_CPP_THUNDER_PLUGIN_ACCESS
AAMPLOG_WARN( "[OTA_SHIM]Inside CURL ACCESS");
/*
Request : {"jsonrpc": "2.0","id": 4,"method": "Controller.1.activate", "params": { "callsign": "org.rdk.MediaPlayer" }}
Response : {"jsonrpc": "2.0","id": 4,"result": null}
*/
response = aamp_PostJsonRPC(id, "Controller.1.activate", "{\"callsign\":\"org.rdk.MediaPlayer\"}" );
AAMPLOG_WARN( "StreamAbstractionAAMP_OTA: response '%s'", response.c_str());
response.clear();
/*
Request : {"jsonrpc":"2.0", "id":3, "method":"org.rdk.MediaPlayer.1.create", "params":{ "id" : "MainPlayer", "tag" : "MyApp"} }
Response: { "jsonrpc":"2.0", "id":3, "result": { "success": true } }
*/
response = aamp_PostJsonRPC(id, "org.rdk.MediaPlayer.1.create", "{\"id\":\"MainPlayer\",\"tag\":\"MyApp\"}");
AAMPLOG_WARN( "StreamAbstractionAAMP_OTA: response '%s'", response.c_str());
response.clear();
// inform (MediaRite) player instance on which wayland display it should draw the video. This MUST be set before load/play is called.
/*
Request : {"jsonrpc":"2.0", "id":3, "method":"org.rdk.MediaPlayer.1.setWaylandDisplay", "params":{"id" : "MainPlayer","display" : "westeros-123"} }
Response: { "jsonrpc":"2.0", "id":3, "result": { "success": true} }
*/
response = aamp_PostJsonRPC( id, "org.rdk.MediaPlayer.1.setWaylandDisplay", "{\"id\":\"MainPlayer\",\"display\":\"" + waylandDisplay + "\"}" );
AAMPLOG_WARN( "StreamAbstractionAAMP_OTA: response '%s'", response.c_str());
response.clear();
/*
Request : {"jsonrpc":"2.0", "id":3, "method": "org.rdk.MediaPlayer.1.load", "params":{ "id":"MainPlayer", "url":"live://...", "autoplay": true} }
Response: { "jsonrpc":"2.0", "id":3, "result": { "success": true } }
*/
response = aamp_PostJsonRPC(id, "org.rdk.MediaPlayer.1.load","{\"id\":\"MainPlayer\",\"url\":\""+url+"\",\"autoplay\":true}" );
AAMPLOG_WARN( "StreamAbstractionAAMP_OTA: response '%s'", response.c_str());
response.clear();
/*
Request : {"jsonrpc":"2.0", "id":3, "method": "org.rdk.MediaPlayer.1.play", "params":{ "id":"MainPlayer"} }
Response: { "jsonrpc":"2.0", "id":3, "result": { "success": true } }
*/
// below play request harmless, but not needed, given use of autoplay above
// response = aamp_PostJsonRPC(id, "org.rdk.MediaPlayer.1.play", "{\"id\":\"MainPlayer\"}");
// AAMPLOG_WARN( "StreamAbstractionAAMP_OTA: response '%s'", response.c_str());
#else
AAMPLOG_INFO( "[OTA_SHIM] url : %s ", url.c_str());
JsonObject result;
SetPreferredAudioLanguages();
JsonObject createParam;
createParam["id"] = APP_ID;
createParam["tag"] = "MyApp";
thunderAccessObj.InvokeJSONRPC("create", createParam, result);
JsonObject displayParam;
displayParam["id"] = APP_ID;
displayParam["display"] = waylandDisplay;
thunderAccessObj.InvokeJSONRPC("setWaylandDisplay", displayParam, result);
JsonObject loadParam;
loadParam["id"] = APP_ID;
loadParam["url"] = url;
loadParam["autoplay"] = true;
thunderAccessObj.InvokeJSONRPC("load", loadParam, result);
// below play request harmless, but not needed, given use of autoplay above
//JsonObject playParam;
//playParam["id"] = APP_ID;
//thunderAccessObj.InvokeJSONRPC("play", playParam, result);
#endif
}
/**
* @brief Stops streaming.
*/
void StreamAbstractionAAMP_OTA::Stop(bool clearChannelData)
{
/*StreamAbstractionAAMP::Stop is being called twice
PrivateInstanceAAMP::Stop calls Stop with clearChannelData set to true
PrivateInstanceAAMP::TeardownStream calls Stop with clearChannelData set to false
Hence avoiding the Stop with clearChannelData set to false*/
if(!clearChannelData)
return;
#ifndef USE_CPP_THUNDER_PLUGIN_ACCESS
/*
Request : {"jsonrpc":"2.0", "id":3, "method": "org.rdk.MediaPlayer.1.stop", "params":{ "id":"MainPlayer"} }
Response: { "jsonrpc":"2.0", "id":3, "result": { "success": true } }
*/
std::string id = "3";
std::string response = aamp_PostJsonRPC(id, "org.rdk.MediaPlayer.1.stop", "{\"id\":\"MainPlayer\"}");
AAMPLOG_WARN( "StreamAbstractionAAMP_OTA: response '%s'", response.c_str());
#else
JsonObject param;
JsonObject result;
param["id"] = APP_ID;
thunderAccessObj.InvokeJSONRPC("stop", param, result);
#endif
}
#ifdef USE_CPP_THUNDER_PLUGIN_ACCESS
bool StreamAbstractionAAMP_OTA::GetScreenResolution(int & screenWidth, int & screenHeight)
{
JsonObject param;
JsonObject result;
bool bRetVal = false;
if( thunderRDKShellObj.InvokeJSONRPC("getScreenResolution", param, result) )
{
screenWidth = result["w"].Number();
screenHeight = result["h"].Number();
AAMPLOG_INFO( "StreamAbstractionAAMP_OTA: screenWidth:%d screenHeight:%d ",screenWidth, screenHeight);
bRetVal = true;
}
return bRetVal;
}
#endif
/**
* @brief SetVideoRectangle sets the position coordinates (x,y) & size (w,h)
*/
void StreamAbstractionAAMP_OTA::SetVideoRectangle(int x, int y, int w, int h)
{
#ifndef USE_CPP_THUNDER_PLUGIN_ACCESS
/*
Request : {"jsonrpc":"2.0", "id":3, "method": "org.rdk.MediaPlayer.1.setVideoRectangle", "params":{ "id":"MainPlayer", "x":0, "y":0, "w":1280, "h":720} }
Response: { "jsonrpc":"2.0", "id":3, "result": { "success": true } }
*/
std::string id = "3";
std::string response = aamp_PostJsonRPC(id, "org.rdk.MediaPlayer.1.setVideoRectangle", "{\"id\":\"MainPlayer\", \"x\":" + to_string(x) + ", \"y\":" + to_string(y) + ", \"w\":" + to_string(w) + ", \"h\":" + std::to_string(h) + "}");
AAMPLOG_WARN( "StreamAbstractionAAMP_OTA: response '%s'", response.c_str());
#else
JsonObject param;
JsonObject result;
param["id"] = APP_ID;
param["x"] = x;
param["y"] = y;
param["w"] = w;
param["h"] = h;
int screenWidth = 0;
int screenHeight = 0;
if(GetScreenResolution(screenWidth,screenHeight))
{
JsonObject meta;
meta["resWidth"] = screenWidth;
meta["resHeight"] = screenHeight;
param["meta"] = meta;
}
thunderAccessObj.InvokeJSONRPC("setVideoRectangle", param, result);
#endif
}
/**
* @brief NotifyAudioTrackChange To notify audio track change.Currently not used
* as mediaplayer does not have support yet.
*/
void StreamAbstractionAAMP_OTA::NotifyAudioTrackChange(const std::vector<AudioTrackInfo> &tracks)
{
if ((0 != mAudioTracks.size()) && (tracks.size() != mAudioTracks.size()))
{
aamp->NotifyAudioTracksChanged();
}
return;
}
/**
* @brief Get the list of available audio tracks
*/
std::vector<AudioTrackInfo> & StreamAbstractionAAMP_OTA::GetAvailableAudioTracks(bool allTrack)
{
if (mAudioTrackIndex.empty())
GetAudioTracks();
return mAudioTracks;
}
/**
* @brief Get current audio track
*/
int StreamAbstractionAAMP_OTA::GetAudioTrack()
{
int index = -1;
if (mAudioTrackIndex.empty())
GetAudioTracks();
if (!mAudioTrackIndex.empty())
{
for (auto it = mAudioTracks.begin(); it != mAudioTracks.end(); it++)
{
if (it->index == mAudioTrackIndex)
{
index = std::distance(mAudioTracks.begin(), it);
}
}
}
return index;
}
/**
* @brief Get current audio track
*/
bool StreamAbstractionAAMP_OTA::GetCurrentAudioTrack(AudioTrackInfo &audioTrack)
{
int index = -1;
bool bFound = false;
if (mAudioTrackIndex.empty())
GetAudioTracks();
if (!mAudioTrackIndex.empty())
{
for (auto it = mAudioTracks.begin(); it != mAudioTracks.end(); it++)
{
if (it->index == mAudioTrackIndex)
{
audioTrack = *it;
bFound = true;
}
}
}
return bFound;
}
/**
* @brief SetPreferredAudioLanguages set the preferred audio language list
*/
void StreamAbstractionAAMP_OTA::SetPreferredAudioLanguages()
{
#ifndef USE_CPP_THUNDER_PLUGIN_ACCESS
#else
JsonObject properties;
bool modifiedLang = false;
bool modifiedRend = false;
//AAMPLOG_WARN( "[OTA_SHIM]aamp->preferredLanguagesString : %s, gATSCSettings.preferredLanguages : %s aamp->preferredRenditionString : %s gATSCSettings.preferredRendition : %s", aamp->preferredLanguagesString.c_str(),gATSCSettings.preferredLanguages.c_str(), aamp->preferredRenditionString.c_str(), gATSCSettings.preferredRendition.c_str());fflush(stdout);
if((0 != aamp->preferredLanguagesString.length()) && (aamp->preferredLanguagesString != gATSCSettings.preferredLanguages)){
properties["preferredAudioLanguage"] = aamp->preferredLanguagesString.c_str();
modifiedLang = true;
}
if((0 != aamp->preferredRenditionString.length()) && (aamp->preferredRenditionString != gATSCSettings.preferredRendition)){
if(0 == aamp->preferredRenditionString.compare("VISUALLY_IMPAIRED")){
properties["visuallyImpaired"] = true;
modifiedRend = true;
}else if(0 == aamp->preferredRenditionString.compare("NORMAL")){
properties["visuallyImpaired"] = false;
modifiedRend = true;
}else{
/*No rendition settings to MediaSettings*/
}
}
if(modifiedLang || modifiedRend)
{
bool rpcResult = false;
JsonObject result;
JsonObject param;
param["properties"] = properties;
rpcResult = mediaSettingsObj.InvokeJSONRPC("setProperties", param, result);
if (rpcResult){
if (!result["success"].Boolean()){
std::string responseStr;
result.ToString(responseStr);
AAMPLOG_WARN( "[OTA_SHIM] setProperties API failed result:%s", responseStr.c_str());
}else{
std::string paramStr;
param.ToString(paramStr);
AAMPLOG_WARN( "[OTA_SHIM] setProperties success with param:%s", paramStr.c_str());
/*Thunder call success save global settings*/
if(modifiedLang){
gATSCSettings.preferredLanguages = aamp->preferredLanguagesString;
}
if(modifiedRend){
gATSCSettings.preferredRendition = aamp->preferredRenditionString;
}
}
}
}
#endif
}
/**
* @brief SetAudioTrackByLanguage set the audio language
*/
void StreamAbstractionAAMP_OTA::SetAudioTrackByLanguage(const char* lang)
{
#ifndef USE_CPP_THUNDER_PLUGIN_ACCESS
#else
JsonObject param;
JsonObject result;
JsonObject properties;
int index = -1;
if(NULL != lang)
{
if(mAudioTrackIndex.empty())
GetAudioTracks();
std::vector<AudioTrackInfo>::iterator itr;
for(itr = mAudioTracks.begin(); itr != mAudioTracks.end(); itr++)
{
if(0 == strcmp(lang, itr->language.c_str()))
{
index = std::distance(mAudioTracks.begin(), itr);
break;
}
}
}
if(-1 != index)
{
SetAudioTrack(index);
}
return;
#endif
}
/**
* @brief GetAudioTracks get the available audio tracks for the selected service / media
*/
void StreamAbstractionAAMP_OTA::GetAudioTracks()
{
#ifndef USE_CPP_THUNDER_PLUGIN_ACCESS
#else
JsonObject param;
JsonObject result;
JsonArray attributesArray;
std::vector<AudioTrackInfo> aTracks;
std::string aTrackIdx = "";
std::string index;
std::string output;
JsonArray outputArray;
JsonObject audioData;
int i = 0,arrayCount = 0;
long bandwidth = -1;
int currentTrackPk = 0;
currentTrackPk = GetAudioTrackInternal();
attributesArray.Add("pk"); // int - Unique primary key dynamically allocated. Used for track selection.
attributesArray.Add("name"); // Name to display in the UI when doing track selection
attributesArray.Add("type"); // e,g "MPEG4_AAC" "MPEG2" etc
attributesArray.Add("description"); //Track description supplied by the content provider
attributesArray.Add("language"); //ISO 639-2 three character text language (terminology variant per DVB standard, i.e. "deu" instead of "ger")
attributesArray.Add("contentType"); // e.g "DIALOGUE" , "EMERGENCY" , "MUSIC_AND_EFFECTS" etc
attributesArray.Add("mixType"); // Signaled audio mix type - orthogonal to AudioTrackType; For example, ac3 could be either surround or stereo.e.g "STEREO" , "SURROUND_SOUND"
attributesArray.Add("isSelected"); // Is Currently selected track
param["id"] = APP_ID;
param["attributes"] = attributesArray;
thunderAccessObj.InvokeJSONRPC("getAudioTracks", param, result);
result.ToString(output);
AAMPLOG_TRACE( "[OTA_SHIM]:audio track output : %s ", output.c_str());
outputArray = result["table"].Array();
arrayCount = outputArray.Length();
for(i = 0; i < arrayCount; i++)
{
index = to_string(i);
audioData = outputArray[i].Object();
if(currentTrackPk == audioData["pk"].Number()){
aTrackIdx = to_string(i);
}
std::string languageCode;
languageCode = Getiso639map_NormalizeLanguageCode(audioData["language"].String(),aamp->GetLangCodePreference());
aTracks.push_back(AudioTrackInfo(index, /*idx*/ languageCode, /*lang*/ audioData["contentType"].String(), /*rend*/ audioData["name"].String(), /*name*/ audioData["type"].String(), /*codecStr*/ (int)audioData["pk"].Number(), /*primaryKey*/ audioData["contentType"].String(), /*contentType*/ audioData["mixType"].String() /*mixType*/));
}
mAudioTracks = aTracks;
mAudioTrackIndex = aTrackIdx;
return;
#endif
}
/**
* @brief GetAudioTrackInternal get the primary key for the selected audio
*/
int StreamAbstractionAAMP_OTA::GetAudioTrackInternal()
{
#ifndef USE_CPP_THUNDER_PLUGIN_ACCESS
return 0;
#else
int pk = 0;
JsonObject param;
JsonObject result;
AAMPLOG_TRACE("[OTA_SHIM]Entered ");
param["id"] = APP_ID;
thunderAccessObj.InvokeJSONRPC("getAudioTrack", param, result);
pk = result["pk"].Number();
return pk;
#endif
}
/**
* @brief SetAudioTrack sets a specific audio track
*/
void StreamAbstractionAAMP_OTA::SetAudioTrack(int trackId)
{
#ifndef USE_CPP_THUNDER_PLUGIN_ACCESS
#else
JsonObject param;
JsonObject result;
param["id"] = APP_ID;
param["trackPk"] = mAudioTracks[trackId].primaryKey;
thunderAccessObj.InvokeJSONRPC("setAudioTrack", param, result);
if (result["success"].Boolean()) {
mAudioTrackIndex = to_string(trackId);
}
return;
#endif
}
/**
* @brief Get the list of available text tracks
*/
std::vector<TextTrackInfo> & StreamAbstractionAAMP_OTA::GetAvailableTextTracks(bool all)
{
AAMPLOG_TRACE("[OTA_SHIM]");
if (mTextTracks.empty())
GetTextTracks();
return mTextTracks;
}
/**
* @brief GetTextTracks get the available text tracks for the selected service / media
*/
void StreamAbstractionAAMP_OTA::GetTextTracks()
{
AAMPLOG_TRACE("[OTA_SHIM]");
#ifndef USE_CPP_THUNDER_PLUGIN_ACCESS
#else
JsonObject param;
JsonObject result;
JsonArray attributesArray;
std::vector<TextTrackInfo> txtTracks;
std::string output;
JsonArray outputArray;
JsonObject textData;
int arrayCount = 0;
attributesArray.Add("pk"); // int - Unique primary key dynamically allocated. Used for track selection.
attributesArray.Add("name"); // Name to display in the UI when doing track selection
attributesArray.Add("type"); // Specific track type for the track - "CC" for ATSC Closed caption
attributesArray.Add("description"); //Track description supplied by the content provider
attributesArray.Add("language"); //ISO 639-2 three character text language
attributesArray.Add("contentType"); // Track content type e.g "HEARING_IMPAIRED", "EASY_READER"
attributesArray.Add("ccServiceNumber"); // Set to 1-63 for 708 CC Subtitles and 0 for 608
attributesArray.Add("isSelected"); // Is Currently selected track
attributesArray.Add("ccTypeIs708"); // Is 708 cc track
attributesArray.Add("ccType"); // Actual cc track type
param["id"] = APP_ID;
param["attributes"] = attributesArray;
thunderAccessObj.InvokeJSONRPC("getSubtitleTracks", param, result);
result.ToString(output);
AAMPLOG_TRACE( "[OTA_SHIM]:text track output : %s ", output.c_str());
outputArray = result["table"].Array();
arrayCount = outputArray.Length();
std::string txtTrackIdx = "";
std::string instreamId;
int ccIndex = 0;
for(int i = 0; i < arrayCount; i++)
{
std::string trackType;
textData = outputArray[i].Object();
trackType = textData["type"].String();
if(0 == trackType.compare("CC"))
{
std::string empty;
std::string index = std::to_string(ccIndex++);
std::string serviceNo;
int ccServiceNumber = -1;
std::string languageCode = Getiso639map_NormalizeLanguageCode(textData["language"].String(),aamp->GetLangCodePreference());
ccServiceNumber = textData["ccServiceNumber"].Number();
/*Plugin info : ccServiceNumber int Set to 1-63 for 708 CC Subtitles and 1-4 for 608/TEXT*/
if(textData["ccType"].String() == std::string{"CC708"})
{
if((ccServiceNumber >= 1) && (ccServiceNumber <= 63))
{
/*708 CC*/
serviceNo = "SERVICE";
serviceNo.append(std::to_string(ccServiceNumber));
}
else
{
AAMPLOG_WARN( "[OTA_SHIM]:unexpected text track for 708 CC");
}
}
else if(textData["ccType"].String() == std::string{"CC608"})
{
if((ccServiceNumber >= 1) && (ccServiceNumber <= 4))
{
/*608 CC*/
serviceNo = "CC";
serviceNo.append(std::to_string(ccServiceNumber));
}
else
{
AAMPLOG_WARN( "[OTA_SHIM]:unexpected text track for 608 CC");
}
}
else if(textData["ccType"].String() == std::string{"TEXT"})
{
if((ccServiceNumber >= 1) && (ccServiceNumber <= 4))
{
/*TEXT CC*/
serviceNo = "TXT";
serviceNo.append(std::to_string(ccServiceNumber));
}
else
{
AAMPLOG_WARN( "[OTA_SHIM]:unexpected text track for TEXT CC");
}
}
else
{
AAMPLOG_WARN( "[OTA_SHIM]:unexpected ccType: '%s'", textData["ccType"].String().c_str());
}
txtTracks.push_back(TextTrackInfo(index, languageCode, true, empty, textData["name"].String(), serviceNo, empty, (int)textData["pk"].Number()));
//values shared: index, language, isCC, rendition-empty, name, instreamId, characteristics-empty, primarykey
AAMPLOG_WARN("[OTA_SHIM]:: Text Track - index:%s lang:%s, isCC:true, rendition:empty, name:%s, instreamID:%s, characteristics:empty, primarykey:%d", index.c_str(), languageCode.c_str(), textData["name"].String().c_str(), serviceNo.c_str(), (int)textData["pk"].Number());
}
}
if (txtTracks.empty())
{
std::string empty;
// Push dummy track , when not published,
// it is obseved that even if track is not published
// CC1 is present
txtTracks.push_back(TextTrackInfo("0", "und", true, empty, "Undetermined", "CC1", empty, 0 ));
}
mTextTracks = txtTracks;
return;
#endif
}
/**
* @brief Disable Restrictions (unlock) till seconds mentioned
*/
void StreamAbstractionAAMP_OTA::DisableContentRestrictions(long grace, long time, bool eventChange)
{
#ifndef USE_CPP_THUNDER_PLUGIN_ACCESS
#else
JsonObject param;
JsonObject result;
param["id"] = APP_ID;
if(-1 == grace){
param["grace"] = -1;
param["time"] = -1;
param["eventChange"] = false;
AAMPLOG_WARN( "[OTA_SHIM] unlocked till next reboot or explicit enable" );
}else{
param["grace"] = 0;
param["time"] = time;
param["eventChange"] = eventChange;
if(-1 != time)
AAMPLOG_WARN( "[OTA_SHIM] unlocked for %ld sec ", time);
if(eventChange)
AAMPLOG_WARN( "[OTA_SHIM] unlocked till next program ");
}
thunderAccessObj.InvokeJSONRPC("disableContentRestrictionsUntil", param, result);
#endif
}
/**
* @brief Enable Content Restriction (lock)
*/
void StreamAbstractionAAMP_OTA::EnableContentRestrictions()
{
#ifndef USE_CPP_THUNDER_PLUGIN_ACCESS
#else