Repository navigation
Expand file tree
/
Copy pathmain_aamp.cpp
More file actions
1910 lines (1732 loc) · 49.5 KB
/
Copy pathmain_aamp.cpp
File metadata and controls
1910 lines (1732 loc) · 49.5 KB
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 main_aamp.cpp
* @brief Advanced Adaptive Media Player (AAMP)
*/
#include "main_aamp.h"
#include "GlobalConfigAAMP.h"
#include "AampCacheHandler.h"
#include "AampUtils.h"
#ifdef AAMP_RDK_CC_ENABLED
#include "AampRDKCCManager.h"
#endif
#include "helper/AampDrmHelper.h"
#include "StreamAbstractionAAMP.h"
#include "aampgstplayer.h"
#include <dlfcn.h>
#ifdef WIN32
#include "conio.h"
#else
#include <termios.h>
#include <errno.h>
#include <regex>
#endif //WIN32
#define ERROR_STATE_CHECK_VOID() \
PrivAAMPState state; \
aamp->GetState(state); \
if( state == eSTATE_ERROR){ \
logprintf("%s() operation is not allowed when player in eSTATE_ERROR state !", __FUNCTION__ );\
return; \
}
#define ERROR_STATE_CHECK_VAL(val) \
PrivAAMPState state; \
aamp->GetState(state); \
if( state == eSTATE_ERROR){ \
logprintf("%s() operation is not allowed when player in eSTATE_ERROR state !", __FUNCTION__ );\
return val; \
}
#define ERROR_OR_IDLE_STATE_CHECK_VOID() \
PrivAAMPState state; \
aamp->GetState(state); \
if( state == eSTATE_ERROR || state == eSTATE_IDLE){ \
logprintf("%s() operation is not allowed when player in %s state !", __FUNCTION__ ,\
(state == eSTATE_ERROR) ? "eSTATE_ERROR" : "eSTATE_IDLE" );\
return; \
}
#define NOT_IDLE_AND_NOT_RELEASED_STATE_CHECK_VOID() \
PrivAAMPState state; \
aamp->GetState(state); \
if( state != eSTATE_IDLE && state != eSTATE_RELEASED){ \
logprintf("%s() operation is not allowed when player not in eSTATE_IDLE or eSTATE_RELEASED state !", __FUNCTION__ );\
return; \
}
#define ERROR_OR_IDLE_STATE_CHECK_VAL(val) \
PrivAAMPState state; \
aamp->GetState(state); \
if( state == eSTATE_ERROR || state == eSTATE_IDLE){ \
logprintf("%s() operation is not allowed in %s state !", __FUNCTION__ ,\
(state == eSTATE_ERROR) ? "eSTATE_ERROR" : "eSTATE_IDLE" );\
return val; \
}
/**
* @brief Constructor.
*
* @param[in] streamSink - custom stream sink, NULL for default.
*/
PlayerInstanceAAMP::PlayerInstanceAAMP(StreamSink* streamSink
, std::function< void(uint8_t *, int, int, int) > exportFrames
) : aamp(NULL), mInternalStreamSink(NULL), mJSBinding_DL()
{
#ifdef SUPPORT_JS_EVENTS
#ifdef AAMP_WPEWEBKIT_JSBINDINGS //aamp_LoadJS defined in libaampjsbindings.so
const char* szJSLib = "libaampjsbindings.so";
#else
const char* szJSLib = "libaamp.so";
#endif
mJSBinding_DL = dlopen(szJSLib, RTLD_GLOBAL | RTLD_LAZY);
logprintf("[AAMP_JS] dlopen(\"%s\")=%p", szJSLib, mJSBinding_DL);
#endif
aamp = new PrivateInstanceAAMP();
if (NULL == streamSink)
{
mInternalStreamSink = new AAMPGstPlayer(aamp);
streamSink = mInternalStreamSink;
}
aamp->SetStreamSink(streamSink);
}
/**
* @brief PlayerInstanceAAMP Destructor
*/
PlayerInstanceAAMP::~PlayerInstanceAAMP()
{
if (aamp)
{
PrivAAMPState state;
aamp->GetState(state);
if (state != eSTATE_IDLE && state != eSTATE_RELEASED)
{
//Avoid stop call since already stopped
aamp->Stop();
}
delete aamp;
aamp = NULL;
}
if (mInternalStreamSink)
{
delete mInternalStreamSink;
}
bool isLastPlayerInstance = !PrivateInstanceAAMP::IsActiveInstancePresent();
#ifdef AAMP_RDK_CC_ENABLED
if (isLastPlayerInstance)
{
AampRDKCCManager::DestroyInstance();
}
#endif
#ifdef SUPPORT_JS_EVENTS
if (mJSBinding_DL && isLastPlayerInstance)
{
logprintf("[AAMP_JS] dlclose(%p)", mJSBinding_DL);
dlclose(mJSBinding_DL);
}
#endif
if (isLastPlayerInstance && gpGlobalConfig)
{
logprintf("[%s] Release GlobalConfig(%p)", __FUNCTION__,gpGlobalConfig);
delete gpGlobalConfig;
gpGlobalConfig = NULL;
}
}
/**
* @brief Stop playback and release resources.
*
* @param[in] sendStateChangeEvent - true if state change events need to be sent for Stop operation, default value true
*/
void PlayerInstanceAAMP::Stop(bool sendStateChangeEvent)
{
if (aamp)
{
PrivAAMPState state;
aamp->GetState(state);
//state will be eSTATE_IDLE or eSTATE_RELEASED, right after an init or post-processing of a Stop call
if (state == eSTATE_IDLE || state == eSTATE_RELEASED)
{
return;
}
logprintf("PLAYER[%d] aamp_stop PlayerState=%d", aamp->mPlayerId, state);
if(gpGlobalConfig->enableMicroEvents && (eSTATE_ERROR == state) && !(aamp->IsTuneCompleted()))
{
/*Sending metrics on tune Error; excluding mid-stream failure cases & aborted tunes*/
aamp->sendTuneMetrics(false);
}
if (sendStateChangeEvent)
{
aamp->SetState(eSTATE_IDLE);
}
AAMPLOG_WARN("%s PLAYER[%d] Stopping Playback at Position '%lld'.\n",(aamp->mbPlayEnabled?STRFGPLAYER:STRBGPLAYER), aamp->mPlayerId, aamp->GetPositionMilliseconds());
aamp->Stop();
}
}
/**
* @brief Tune to a URL.
* This extra Tune function is included for backwards compatibility
* @param[in] url - HTTP/HTTPS url to be played.
* @param[in] contentType - Content type of the asset
* @param[in] audioDecoderStreamSync - Enable or disable audio decoder stream sync,
* set to 'false' if audio fragments come with additional padding at the end (BCOM-4203)
* @return void
*/
void PlayerInstanceAAMP::Tune(const char *mainManifestUrl, const char *contentType, bool bFirstAttempt, bool bFinalAttempt,const char *traceUUID,bool audioDecoderStreamSync)
{
Tune(mainManifestUrl, /*autoPlay*/ true, contentType,bFirstAttempt,bFinalAttempt,traceUUID,audioDecoderStreamSync);
}
/**
* @brief Tune to a URL.
*
* @param mainManifestUrl - HTTP/HTTPS url to be played.
* @param[in] autoPlay - Start playback immediately or not
* @param contentType - content Type.
*/
void PlayerInstanceAAMP::Tune(const char *mainManifestUrl, bool autoPlay, const char *contentType, bool bFirstAttempt, bool bFinalAttempt,const char *traceUUID,bool audioDecoderStreamSync)
{
PrivAAMPState state;
aamp->GetState(state);
if ((state != eSTATE_IDLE) && (state != eSTATE_RELEASED)){
//Calling tune without closing previous tune
Stop(false);
}
aamp->getAampCacheHandler()->StartPlaylistCache();
aamp->Tune(mainManifestUrl, autoPlay, contentType, bFirstAttempt, bFinalAttempt,traceUUID,audioDecoderStreamSync);
}
/**
* @brief Soft-realease player.
*
*/
void PlayerInstanceAAMP::detach()
{
aamp->detach();
}
/**
* @brief Register event handler.
*
* @param eventListener - pointer to implementation of EventListener to receive events.
*/
void PlayerInstanceAAMP::RegisterEvents(EventListener* eventListener)
{
aamp->RegisterEvents(eventListener);
}
/**
* @brief Set retry limit on Segment injection failure.
*
*/
void PlayerInstanceAAMP::SetSegmentInjectFailCount(int value)
{
if(gpGlobalConfig->segInjectFailCount > 0)
{
aamp->mSegInjectFailCount = gpGlobalConfig->segInjectFailCount;
AAMPLOG_INFO("%s:%d Setting limit from configuration file: %d", __FUNCTION__, __LINE__, aamp->mSegInjectFailCount);
}
else
{
if ((value > 0) && (value <= MAX_SEG_INJECT_FAIL_COUNT))
{
aamp->mSegInjectFailCount = value;
AAMPLOG_INFO("%s:%d Setting Segment Inject fail count : %d", __FUNCTION__, __LINE__, aamp->mSegInjectFailCount);
}
else
{
AAMPLOG_WARN("%s:%d Invalid value %d, will continue with %d", __FUNCTION__,__LINE__, value, MAX_SEG_INJECT_FAIL_COUNT);
}
}
}
/**
* @brief Set retry limit on Segment drm decryption failure.
*
*/
void PlayerInstanceAAMP::SetSegmentDecryptFailCount(int value)
{
if (gpGlobalConfig->drmDecryptFailCount > 0)
{
aamp->mDrmDecryptFailCount = gpGlobalConfig->drmDecryptFailCount;
AAMPLOG_INFO("%s:%d Setting limit from configuration file: %d", __FUNCTION__, __LINE__, aamp->mDrmDecryptFailCount);
}
else
{
if ((value > 0) && (value <= MAX_SEG_DRM_DECRYPT_FAIL_COUNT))
{
aamp->mDrmDecryptFailCount = value;
AAMPLOG_INFO("%s:%d Setting Segment DRM decrypt fail count : %d", __FUNCTION__, __LINE__, aamp->mDrmDecryptFailCount);
}
else
{
AAMPLOG_WARN("%s:%d Invalid value %d, will continue with %d", __FUNCTION__,__LINE__, value, MAX_SEG_DRM_DECRYPT_FAIL_COUNT);
}
}
}
/**
* @brief Set initial buffer duration in seconds
*
*/
void PlayerInstanceAAMP::SetInitialBufferDuration(int durationSec)
{
NOT_IDLE_AND_NOT_RELEASED_STATE_CHECK_VOID();
if(gpGlobalConfig->minInitialCacheSeconds == MINIMUM_INIT_CACHE_NOT_OVERRIDDEN)
{
aamp->SetInitialBufferDuration(durationSec);
}
}
/**
* @brief Set Maximum Cache Size for playlist store
*
*/
void PlayerInstanceAAMP::SetMaxPlaylistCacheSize(int cacheSize)
{
if(gpGlobalConfig->gMaxPlaylistCacheSize == 0)
{
aamp->SetMaxPlaylistCacheSize(cacheSize);
}
}
/**
* @brief Set profile ramp down limit.
*
*/
void PlayerInstanceAAMP::SetRampDownLimit(int limit)
{
aamp->SetRampDownLimit(limit);
}
/**
* @brief Set Language Format
* @param[in] preferredFormat - one of \ref LangCodePreference
* @param[in] useRole - if enabled, the language in format <lang>-<role>
* if <role> attribute available in stream
*
* @return void
*/
void PlayerInstanceAAMP::SetLanguageFormat(LangCodePreference preferredFormat, bool useRole)
{
NOT_IDLE_AND_NOT_RELEASED_STATE_CHECK_VOID();
gpGlobalConfig->langCodePreference = preferredFormat;
gpGlobalConfig->bDescriptiveAudioTrack = useRole;
}
/**
* @brief Set minimum bitrate value.
* @param url - stream url with vss service zone info as query string
*/
void PlayerInstanceAAMP::SetMinimumBitrate(long bitrate)
{
if (gpGlobalConfig->minBitrate > 0)
{
aamp->SetMinimumBitrate(gpGlobalConfig->minBitrate);
AAMPLOG_INFO("%s:%d Setting minBitrate from configuration file: %ld", __FUNCTION__, __LINE__, gpGlobalConfig->minBitrate);
}
else
{
if (bitrate > 0)
{
AAMPLOG_INFO("%s:%d Setting minimum bitrate: %ld", __FUNCTION__, __LINE__, bitrate);
aamp->SetMinimumBitrate(bitrate);
}
else
{
AAMPLOG_WARN("%s:%d Invalid bitrate value %ld", __FUNCTION__,__LINE__, bitrate);
}
}
}
/**
* @brief Set maximum bitrate value.
*
*/
void PlayerInstanceAAMP::SetMaximumBitrate(long bitrate)
{
if (gpGlobalConfig->maxBitrate > 0)
{
aamp->SetMinimumBitrate(gpGlobalConfig->maxBitrate);
AAMPLOG_INFO("%s:%d Setting maxBitrate from configuration file: %ld", __FUNCTION__, __LINE__, gpGlobalConfig->maxBitrate);
}
else
{
if (bitrate > 0)
{
AAMPLOG_INFO("%s:%d Setting maximum bitrate : %ld", __FUNCTION__,__LINE__, bitrate);
aamp->SetMaximumBitrate(bitrate);
}
else
{
AAMPLOG_WARN("%s:%d Invalid bitrate value %d", __FUNCTION__,__LINE__, bitrate);
}
}
}
/**
* @brief Check given rate is valid.
*
* @param[in] rate - Rate of playback.
* @retval return true if the given rate is valid.
*/
bool PlayerInstanceAAMP::IsValidRate(int rate)
{
bool retValue = false;
switch(rate)
{
case AAMP_RATE_REW_1X:
case AAMP_RATE_REW_2X:
case AAMP_RATE_REW_3X:
case AAMP_RATE_REW_4X:
case AAMP_RATE_PAUSE:
case AAMP_NORMAL_PLAY_RATE:
case AAMP_RATE_FWD_1X:
case AAMP_RATE_FWD_2X:
case AAMP_RATE_FWD_3X:
case AAMP_RATE_FWD_4X:
{
retValue = true;
break;
}
}
return retValue;
}
/**
* @brief Set playback rate.
*
* @param rate - Rate of playback.
* @param overshootcorrection - overshoot correction in milliseconds.
*/
void PlayerInstanceAAMP::SetRate(int rate,int overshootcorrection)
{
AAMPLOG_INFO("%s:%d PLAYER[%d] rate=%d.", __FUNCTION__, __LINE__, aamp->mPlayerId, rate);
ERROR_STATE_CHECK_VOID();
if (!IsValidRate(rate))
{
AAMPLOG_WARN("%s:%d SetRate ignored!! Invalid rate (%d)", __FUNCTION__, __LINE__, rate);
return;
}
if (aamp->mpStreamAbstractionAAMP)
{
if (!aamp->mIsIframeTrackPresent && rate != AAMP_NORMAL_PLAY_RATE && rate != 0)
{
AAMPLOG_WARN("%s:%d Ignoring trickplay. No iframe tracks in stream", __FUNCTION__, __LINE__);
aamp->NotifySpeedChanged(AAMP_NORMAL_PLAY_RATE); // Send speed change event to XRE to reset the speed to normal play since the trickplay ignored at player level.
return;
}
if(!(aamp->mbPlayEnabled) && aamp->pipeline_paused && (AAMP_NORMAL_PLAY_RATE == rate))
{
AAMPLOG_WARN("%s:%d PLAYER[%d] Player %s=>%s.", __FUNCTION__, __LINE__, aamp->mPlayerId, STRBGPLAYER, STRFGPLAYER );
aamp->mbPlayEnabled = true;
aamp->LogPlayerPreBuffered();
aamp->mStreamSink->Configure(aamp->mVideoFormat, aamp->mAudioFormat, aamp->mpStreamAbstractionAAMP->GetESChangeStatus());
aamp->mpStreamAbstractionAAMP->StartInjection();
aamp->mStreamSink->Stream();
aamp->pipeline_paused = false;
return;
}
bool retValue = true;
if (rate > 0 && aamp->IsLive() && aamp->mpStreamAbstractionAAMP->IsStreamerAtLivePoint() && aamp->rate >= AAMP_NORMAL_PLAY_RATE)
{
AAMPLOG_WARN("%s(): Already at logical live point, hence skipping operation", __FUNCTION__);
aamp->NotifyOnEnteringLive();
return;
}
// DELIA-39691 If input rate is same as current playback rate, skip duplicate operation
// Additional check for pipeline_paused is because of 0(PAUSED) -> 1(PLAYING), where aamp->rate == 1.0 in PAUSED state
if ((!aamp->pipeline_paused && rate == aamp->rate) || (rate == 0 && aamp->pipeline_paused))
{
AAMPLOG_WARN("%s(): Already running at playback rate(%d) pipeline_paused(%d), hence skipping set rate for (%d)", __FUNCTION__, aamp->rate, aamp->pipeline_paused, rate);
return;
}
//DELIA-30274 -- Get the trick play to a closer position
//Logic adapted
// XRE gives fixed overshoot position , not suited for aamp . So ignoring overshoot correction value
// instead use last reported posn vs the time player get play command
// a. During trickplay , last XRE reported position is stored in aamp->mReportProgressPosn
/// and last reported time is stored in aamp->mReportProgressTime
// b. Calculate the time delta from last reported time
// c. Using this diff , calculate the best/nearest match position (works out 70-80%)
// d. If time delta is < 100ms ,still last video fragment rendering is not removed ,but position updated very recently
// So switch last displayed position - NewPosn -= Posn - ((aamp->rate/4)*1000)
// e. If time delta is > 950ms , possibility of next frame to come by the time play event is processed.
//So go to next fragment which might get displayed
// f. If none of above ,maintain the last displayed position .
//
// h. TODO (again trial n error) - for 3x/4x , within 1sec there might multiple frame displayed . Can use timedelta to calculate some more near,to be tried
int timeDeltaFromProgReport = (aamp_GetCurrentTimeMS() - aamp->mReportProgressTime);
//Skip this logic for either going to paused to coming out of paused scenarios with HLS
//What we would like to avoid here is the update of seek_pos_seconds because gstreamer position will report proper position
//Check for 1.0 -> 0.0 and 0.0 -> 1.0 usecase and avoid below logic
if (!((aamp->rate == AAMP_NORMAL_PLAY_RATE && rate == 0) || (aamp->pipeline_paused && rate == AAMP_NORMAL_PLAY_RATE)))
{
double newSeekPosInSec = -1;
// when switching from trick to play mode only
if(aamp->rate && rate == AAMP_NORMAL_PLAY_RATE && !aamp->pipeline_paused)
{
if(timeDeltaFromProgReport > 950) // diff > 950 mSec
{
// increment by 1x trickplay frame , next possible displayed frame
newSeekPosInSec = (aamp->mReportProgressPosn+(aamp->rate*1000))/1000;
}
else if(timeDeltaFromProgReport > 100) // diff > 100 mSec
{
// Get the last shown frame itself
newSeekPosInSec = aamp->mReportProgressPosn/1000;
}
else
{
// Go little back to last shown frame
newSeekPosInSec = (aamp->mReportProgressPosn-(aamp->rate*1000))/1000;
}
if (newSeekPosInSec >= 0)
{
aamp->seek_pos_seconds = newSeekPosInSec;
}
else
{
AAMPLOG_WARN("%s:%d new seek_pos_seconds calculated is invalid(%f), discarding it!", __FUNCTION__, __LINE__, newSeekPosInSec);
}
}
else
{
// Coming out of pause mode(aamp->rate=0) or when going into pause mode (rate=0)
// Show the last position
aamp->seek_pos_seconds = aamp->GetPositionMilliseconds()/1000;
}
aamp->trickStartUTCMS = -1;
}
else
{
// DELIA-39530 - For 1.0->0.0 and 0.0->1.0 if bPositionQueryEnabled is enabled, GStreamer position query will give proper value
// Fallback case added for when bPositionQueryEnabled is disabled, since we will be using elapsedTime to calculate position and
// trickStartUTCMS has to be reset
if (!gpGlobalConfig->bPositionQueryEnabled)
{
aamp->seek_pos_seconds = aamp->GetPositionMilliseconds()/1000;
aamp->trickStartUTCMS = -1;
}
}
logprintf("aamp_SetRate(%d)overshoot(%d) ProgressReportDelta:(%d) ", rate,overshootcorrection,timeDeltaFromProgReport);
logprintf("aamp_SetRate Adj position: %f", aamp->seek_pos_seconds); // current position relative to tune time
logprintf("aamp_SetRate rate(%d)->(%d)", aamp->rate,rate);
logprintf("aamp_SetRate cur pipeline: %s", aamp->pipeline_paused ? "paused" : "playing");
if (rate == aamp->rate)
{ // no change in desired play rate
if (aamp->pipeline_paused && rate != 0)
{ // but need to unpause pipeline
AAMPLOG_INFO("Resuming Playback at Position '%lld'.", aamp->GetPositionMilliseconds());
// check if unpausing in the middle of fragments caching
if(!aamp->SetStateBufferingIfRequired())
{
aamp->mpStreamAbstractionAAMP->NotifyPlaybackPaused(false);
retValue = aamp->mStreamSink->Pause(false, false);
aamp->NotifyFirstBufferProcessed(); //required since buffers are already cached in paused state
}
aamp->pipeline_paused = false;
aamp->ResumeDownloads();
}
}
else if (rate == 0)
{
if (!aamp->pipeline_paused)
{
AAMPLOG_INFO("Pausing Playback at Position '%lld'.", aamp->GetPositionMilliseconds());
aamp->mpStreamAbstractionAAMP->NotifyPlaybackPaused(true);
aamp->StopDownloads();
retValue = aamp->mStreamSink->Pause(true, false);
aamp->pipeline_paused = true;
}
}
else
{
aamp->rate = rate;
aamp->pipeline_paused = false;
aamp->ResumeDownloads();
aamp->TuneHelper(eTUNETYPE_SEEK); // this unpauses pipeline as side effect
}
if(retValue)
{
// Do not update state if fragments caching is ongoing and pipeline not paused,
// target state will be updated once caching completed
aamp->NotifySpeedChanged(aamp->pipeline_paused ? 0 : aamp->rate,
(!aamp->IsFragmentCachingRequired() || aamp->pipeline_paused));
}
}
else
{
AAMPLOG_WARN("%s:%d aamp_SetRate not changed, remains in same rate[%d] - mpStreamAbstractionAAMP[%p] state[%d]", __FUNCTION__, __LINE__, aamp->rate, aamp->mpStreamAbstractionAAMP, state);
}
}
/**
* @brief Seek to a time.
*
* @param ptr - Aamp instance,
* Return true on success
*/
static gboolean SeekAfterPrepared(gpointer ptr)
{
PrivateInstanceAAMP* aamp = (PrivateInstanceAAMP*) ptr;
bool sentSpeedChangedEv = false;
bool isSeekToLive = false;
TuneType tuneType = eTUNETYPE_SEEK;
PrivAAMPState state;
aamp->GetState(state);
if( state == eSTATE_ERROR){
logprintf("%s() operation is not allowed when player in eSTATE_ERROR state !", __FUNCTION__ );\
return false;
}
if (AAMP_SEEK_TO_LIVE_POSITION == aamp->seek_pos_seconds )
{
isSeekToLive = true;
tuneType = eTUNETYPE_SEEKTOLIVE;
}
logprintf("aamp_Seek(%f) and seekToLive(%d)", aamp->seek_pos_seconds, isSeekToLive);
if (isSeekToLive && !aamp->IsLive())
{
logprintf("%s:%d - Not live, skipping seekToLive",__FUNCTION__,__LINE__);
return false;
}
if (aamp->IsLive() && aamp->mpStreamAbstractionAAMP && aamp->mpStreamAbstractionAAMP->IsStreamerAtLivePoint())
{
double currPositionSecs = aamp->GetPositionMilliseconds() / 1000.00;
if (isSeekToLive || aamp->seek_pos_seconds >= currPositionSecs)
{
logprintf("%s():Already at live point, skipping operation since requested position(%f) >= currPosition(%f) or seekToLive(%d)", __FUNCTION__, aamp->seek_pos_seconds, currPositionSecs, isSeekToLive);
aamp->NotifyOnEnteringLive();
return false;
}
}
if (aamp->pipeline_paused)
{
// resume downloads and clear paused flag. state change will be done
// on streamSink configuration.
logprintf("%s(): paused state, so resume downloads", __FUNCTION__);
aamp->pipeline_paused = false;
aamp->ResumeDownloads();
sentSpeedChangedEv = true;
}
if (tuneType == eTUNETYPE_SEEK)
{
logprintf("%s(): tune type is SEEK", __FUNCTION__);
}
if (aamp->rate != AAMP_NORMAL_PLAY_RATE)
{
aamp->rate = AAMP_NORMAL_PLAY_RATE;
sentSpeedChangedEv = true;
}
if (aamp->mpStreamAbstractionAAMP)
{ // for seek while streaming
aamp->SetState(eSTATE_SEEKING);
aamp->TuneHelper(tuneType);
if (sentSpeedChangedEv)
{
aamp->NotifySpeedChanged(aamp->rate, false);
}
}
return true;
}
/**
* @brief Seek to a time.
*
* @param secondsRelativeToTuneTime - Seek position for VOD,
* relative position from first tune command.
* @param keepPaused - set true if want to keep paused state after seek
*/
void PlayerInstanceAAMP::Seek(double secondsRelativeToTuneTime, bool keepPaused)
{
bool sentSpeedChangedEv = false;
bool isSeekToLive = false;
TuneType tuneType = eTUNETYPE_SEEK;
ERROR_STATE_CHECK_VOID();
if ((aamp->mMediaFormat == eMEDIAFORMAT_HLS || aamp->mMediaFormat == eMEDIAFORMAT_HLS_MP4) && (eSTATE_INITIALIZING == state) && aamp->mpStreamAbstractionAAMP)
{
logprintf("Seeking to %lf at the middle of tune, no fragments downloaded yet.", secondsRelativeToTuneTime);
aamp->mpStreamAbstractionAAMP->SeekPosUpdate(secondsRelativeToTuneTime);
}
else if (eSTATE_INITIALIZED == state || eSTATE_PREPARING == state)
{
logprintf("Seek will be called after preparing the content.");
aamp->seek_pos_seconds = secondsRelativeToTuneTime ;
g_idle_add(SeekAfterPrepared, (gpointer)aamp);
}
else
{
if (secondsRelativeToTuneTime == AAMP_SEEK_TO_LIVE_POSITION)
{
isSeekToLive = true;
tuneType = eTUNETYPE_SEEKTOLIVE;
}
logprintf("aamp_Seek(%f) and seekToLive(%d)", secondsRelativeToTuneTime, isSeekToLive);
if (isSeekToLive && !aamp->IsLive())
{
logprintf("%s:%d - Not live, skipping seekToLive",__FUNCTION__,__LINE__);
return;
}
if (aamp->IsLive() && aamp->mpStreamAbstractionAAMP && aamp->mpStreamAbstractionAAMP->IsStreamerAtLivePoint())
{
double currPositionSecs = aamp->GetPositionMilliseconds() / 1000.00;
if (isSeekToLive || secondsRelativeToTuneTime >= currPositionSecs)
{
logprintf("%s():Already at live point, skipping operation since requested position(%f) >= currPosition(%f) or seekToLive(%d)", __FUNCTION__, secondsRelativeToTuneTime, currPositionSecs, isSeekToLive);
aamp->NotifyOnEnteringLive();
return;
}
}
bool seekWhilePause = false;
if (aamp->pipeline_paused)
{
// resume downloads and clear paused flag. state change will be done
// on streamSink configuration.
logprintf("%s(): paused state, so resume downloads", __FUNCTION__);
aamp->pipeline_paused = false;
aamp->ResumeDownloads();
sentSpeedChangedEv = true;
if(keepPaused && aamp->mMediaFormat != eMEDIAFORMAT_PROGRESSIVE)
{
// Enable seek while paused if not Progressive stream
seekWhilePause = true;
}
}
if (tuneType == eTUNETYPE_SEEK)
{
aamp->seek_pos_seconds = secondsRelativeToTuneTime;
}
if (aamp->rate != AAMP_NORMAL_PLAY_RATE)
{
aamp->rate = AAMP_NORMAL_PLAY_RATE;
sentSpeedChangedEv = true;
}
if (aamp->mpStreamAbstractionAAMP)
{ // for seek while streaming
aamp->SetState(eSTATE_SEEKING);
aamp->TuneHelper(tuneType, seekWhilePause);
if (sentSpeedChangedEv && (!seekWhilePause) )
{
aamp->NotifySpeedChanged(aamp->rate, false);
}
}
}
}
/**
* @brief Seek to live point.
*
* @param[in] keepPaused - set true if want to keep paused state after seek
*/
void PlayerInstanceAAMP::SeekToLive(bool keepPaused)
{
Seek(AAMP_SEEK_TO_LIVE_POSITION, keepPaused);
}
/**
* @brief Seek to a time and playback with a new rate.
*
* @param rate - Rate of playback.
* @param secondsRelativeToTuneTime - Seek position for VOD,
* relative position from first tune command.
*/
void PlayerInstanceAAMP::SetRateAndSeek(int rate, double secondsRelativeToTuneTime)
{
ERROR_OR_IDLE_STATE_CHECK_VOID();
logprintf("aamp_SetRateAndSeek(%d)(%f)", rate, secondsRelativeToTuneTime);
aamp->TeardownStream(false);
aamp->seek_pos_seconds = secondsRelativeToTuneTime;
aamp->rate = rate;
aamp->TuneHelper(eTUNETYPE_SEEK);
}
/**
* @brief Set video rectangle.
*
* @param x - horizontal start position.
* @param y - vertical start position.
* @param w - width.
* @param h - height.
*/
void PlayerInstanceAAMP::SetVideoRectangle(int x, int y, int w, int h)
{
ERROR_STATE_CHECK_VOID();
aamp->SetVideoRectangle(x, y, w, h);
}
/**
* @brief Set video zoom.
*
* @param zoom - zoom mode.
*/
void PlayerInstanceAAMP::SetVideoZoom(VideoZoomMode zoom)
{
ERROR_STATE_CHECK_VOID();
aamp->zoom_mode = zoom;
if (aamp->mpStreamAbstractionAAMP ){
aamp->SetVideoZoom(zoom);
}else{
AAMPLOG_WARN("%s:%d Player is in state (%s) , value has been cached",
__FUNCTION__, __LINE__, "eSTATE_IDLE");
}
}
/**
* @brief Enable/ Disable Video.
*
* @param muted - true to disable video, false to enable video.
*/
void PlayerInstanceAAMP::SetVideoMute(bool muted)
{
ERROR_STATE_CHECK_VOID();
aamp->video_muted = muted;
if (aamp->mpStreamAbstractionAAMP)
{
aamp->SetVideoMute(muted);
}
else
{
AAMPLOG_WARN("%s:%d Player is in state eSTATE_IDLE, value has been cached", __FUNCTION__, __LINE__);
}
}
/**
* @brief Set Audio Volume.
*
* @param volume - Minimum 0, maximum 100.
*/
void PlayerInstanceAAMP::SetAudioVolume(int volume)
{
ERROR_STATE_CHECK_VOID();
if (volume < AAMP_MINIMUM_AUDIO_LEVEL || volume > AAMP_MAXIMUM_AUDIO_LEVEL)
{
AAMPLOG_WARN("%s:%d Audio level (%d) is outside the range supported.. discarding it..",
__FUNCTION__, __LINE__, volume);
}else{
aamp->audio_volume = volume;
if (aamp->mpStreamAbstractionAAMP)
{
aamp->SetAudioVolume(volume);
}
else
{
AAMPLOG_WARN("%s:%d Player is in state eSTATE_IDLE, value has been cached", __FUNCTION__, __LINE__);
}
}
}
/**
* @brief Set Audio language.
*
* @param language - Language of audio track.
*/
void PlayerInstanceAAMP::SetLanguage(const char* language)
{
ERROR_STATE_CHECK_VOID();
logprintf("aamp_SetLanguage(%s)->(%s)",aamp->language, language);
if(strncmp(language, aamp->language, MAX_LANGUAGE_TAG_LENGTH) == 0)
{
aamp->noExplicitUserLanguageSelection = false;
aamp->languageSetByUser = true;
return;
}
// There is no active playback session, save the language for later
if (state == eSTATE_IDLE || state == eSTATE_RELEASED)
{
aamp->languageSetByUser = true;
aamp->UpdateAudioLanguageSelection(language);
}
// check if language is supported in manifest languagelist
else if((aamp->IsAudioLanguageSupported(language)) || (!aamp->mMaxLanguageCount))
{
aamp->languageSetByUser = true;
aamp->UpdateAudioLanguageSelection(language);
if (aamp->mpStreamAbstractionAAMP)
{
logprintf("aamp_SetLanguage(%s) retuning", language);
if(aamp->mMediaFormat == eMEDIAFORMAT_OTA)
{
aamp->mpStreamAbstractionAAMP->SetAudioTrackByLanguage(language);
}
else
{
aamp->discardEnteringLiveEvt = true;
aamp->seek_pos_seconds = aamp->GetPositionMilliseconds()/1000.0;
aamp->TeardownStream(false);
aamp->TuneHelper(eTUNETYPE_SEEK);
aamp->discardEnteringLiveEvt = false;
}
}
}
else
{
logprintf("aamp_SetLanguage(%s) not supported in manifest", language);
}
}
/**
* @brief Set array of subscribed tags.
*
* @param subscribedTags - Array of subscribed tags.
*/
void PlayerInstanceAAMP::SetSubscribedTags(std::vector<std::string> subscribedTags)
{
ERROR_STATE_CHECK_VOID();
aamp->subscribedTags = subscribedTags;
for (int i=0; i < aamp->subscribedTags.size(); i++) {
logprintf(" subscribedTags[%d] = '%s'", i, subscribedTags.at(i).data());
}
}
#ifdef SUPPORT_JS_EVENTS
/**
* @brief Load AAMP JS object in the specified JS context.
*
* @param context - JS context.
*/
void PlayerInstanceAAMP::LoadJS(void* context)
{
logprintf("[AAMP_JS] %s(%p)", __FUNCTION__, context);
if (mJSBinding_DL) {
void(*loadJS)(void*, void*);
const char* szLoadJS = "aamp_LoadJS";
loadJS = (void(*)(void*, void*))dlsym(mJSBinding_DL, szLoadJS);
if (loadJS) {
logprintf("[AAMP_JS] %s() dlsym(%p, \"%s\")=%p", __FUNCTION__, mJSBinding_DL, szLoadJS, loadJS);
loadJS(context, this);
}
}
}
/**
* @brief Unoad AAMP JS object in the specified JS context.
*
* @param context - JS context.
*/
void PlayerInstanceAAMP::UnloadJS(void* context)
{
logprintf("[AAMP_JS] %s(%p)", __FUNCTION__, context);
if (mJSBinding_DL) {
void(*unloadJS)(void*);
const char* szUnloadJS = "aamp_UnloadJS";
unloadJS = (void(*)(void*))dlsym(mJSBinding_DL, szUnloadJS);
if (unloadJS) {
logprintf("[AAMP_JS] %s() dlsym(%p, \"%s\")=%p", __FUNCTION__, mJSBinding_DL, szUnloadJS, unloadJS);
unloadJS(context);
}
}
}
#endif
/**
* @brief Support multiple listeners for multiple event type
*
* @param eventType - type of event.
* @param eventListener - listener for the eventType.
*/
void PlayerInstanceAAMP::AddEventListener(AAMPEventType eventType, EventListener* eventListener)
{
aamp->AddEventListener(eventType, eventListener);
}
/**
* @brief Remove event listener for eventType.
*