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
/
priv_aamp.h
4129 lines (3627 loc) · 110 KB
/
priv_aamp.h
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 priv_aamp.h
* @brief Private functions and types used internally by AAMP
*/
#ifndef PRIVAAMP_H
#define PRIVAAMP_H
#include "AampMemoryUtils.h"
#include "AampProfiler.h"
#include "AampDrmHelper.h"
#include "AampDrmMediaFormat.h"
#include "AampDrmCallbacks.h"
#include "main_aamp.h"
#include <IPVideoStat.h>
#include <pthread.h>
#include <signal.h>
#include <semaphore.h>
#include <curl/curl.h>
#include <string.h>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <list>
#include <sstream>
#include <mutex>
#include <queue>
#include <algorithm>
#include <glib.h>
#include <cjson/cJSON.h>
#include "AampConfig.h"
#include <atomic>
#include <memory>
#include <inttypes.h>
#include <type_traits>
#include "AampRfc.h"
#include "AampEventManager.h"
#include <HybridABRManager.h>
#ifdef __APPLE__
#define aamp_pthread_setname(tid,name) pthread_setname_np(name)
#else
#define aamp_pthread_setname(tid,name) pthread_setname_np(tid,name)
#endif
#define AAMP_TRACK_COUNT 4 /**< internal use - audio+video+sub+aux track */
#define DEFAULT_CURL_INSTANCE_COUNT (AAMP_TRACK_COUNT + 1) /**< One for Manifest/Playlist + Number of tracks */
#define AAMP_DRM_CURL_COUNT 4 /**< audio+video+sub+aux track DRMs */
//#define CURL_FRAGMENT_DL_TIMEOUT 10L /**< Curl timeout for fragment download */
#define DEFAULT_PLAYLIST_DL_TIMEOUT 10L /**< Curl timeout for playlist download */
#define DEFAULT_CURL_TIMEOUT 5L /**< Default timeout for Curl downloads */
#define DEFAULT_CURL_CONNECTTIMEOUT 3L /**< Curl socket connection timeout */
#define EAS_CURL_TIMEOUT 3L /**< Curl timeout for EAS manifest downloads */
#define EAS_CURL_CONNECTTIMEOUT 2L /**< Curl timeout for EAS connection */
#define DEFAULT_INTERVAL_BETWEEN_PLAYLIST_UPDATES_MS (6*1000) /**< Interval between playlist refreshes */
#define AAMP_SEEK_TO_LIVE_POSITION (-1)
#define MAX_SESSION_ID_LENGTH 128 /**<session id string length */
#define MANIFEST_TEMP_DATA_LENGTH 100 /**< Manifest temp data length */
#define AAMP_LOW_BUFFER_BEFORE_RAMPDOWN 10 /**< 10sec buffer before rampdown */
#define AAMP_HIGH_BUFFER_BEFORE_RAMPUP 15 /**< 15sec buffer before rampup */
#define AAMP_USER_AGENT_MAX_CONFIG_LEN 512 /**< Max Chars allowed in aamp.cfg for user-agent */
#define SERVER_UTCTIME_DIRECT "urn:mpeg:dash:utc:direct:2014"
#define SERVER_UTCTIME_HTTP "urn:mpeg:dash:utc:http-xsdate:2014"
// MSO-specific VSS Service Zone identifier in URL
#define VSS_MARKER "?sz="
#define VSS_MARKER_LEN 4
#define VSS_MARKER_FOG "%3Fsz%3D" /**< URI-encoded ?sz= */
#define VSS_VIRTUAL_STREAM_ID_KEY_STR "content:xcal:virtualStreamId"
#define VSS_VIRTUAL_STREAM_ID_PREFIX "urn:merlin:linear:stream:"
#define VSS_SERVICE_ZONE_KEY_STR "device:xcal:serviceZone"
//Low Latency DASH SERVICE PROFILE URL
#define LL_DASH_SERVICE_PROFILE "http://www.dashif.org/guidelines/low-latency-live-v5"
#define URN_UTC_HTTP_XSDATE "urn:mpeg:dash:utc:http-xsdate:2014"
#define URN_UTC_HTTP_ISO "urn:mpeg:dash:utc:http-iso:2014"
#define URN_UTC_HTTP_NTP "urn:mpeg:dash:utc:http-ntp:2014"
#define URN_UTC_HTTP_HEAD "urn:mpeg:dash:utc:http-head:2014"
#define MAX_LOW_LATENCY_DASH_CORRECTION_ALLOWED 100
#define MAX_LOW_LATENCY_DASH_RETUNE_ALLOWED 2
#define MAX_LOW_LATENCY_DASH_ABR_SPEEDSTORE_SIZE 10
/*1 for debugging video track, 2 for audio track, 4 for subtitle track and 7 for all*/
/*#define AAMP_DEBUG_FETCH_INJECT 0x001 */
/**
* @brief Max debug log buffer size
*/
#define MAX_DEBUG_LOG_BUFF_SIZE 1024
/**
* @brief Max URL log size
*/
#define MAX_URL_LOG_SIZE 960 /**< Considering "aamp_tune" and [AAMP-PLAYER] pretext */
#define CONVERT_SEC_TO_MS(_x_) (_x_ * 1000) /**< Convert value to sec to ms */
#define DEFAULT_PREBUFFER_COUNT (2)
#define DEFAULT_PRECACHE_WINDOW (10) /**< 10 mins for full precaching */
#define DEFAULT_DOWNLOAD_RETRY_COUNT (1) /**< max download failure retry attempt count */
// These error codes are used internally to identify the cause of error from GetFile
#define PARTIAL_FILE_CONNECTIVITY_AAMP (130)
#define PARTIAL_FILE_DOWNLOAD_TIME_EXPIRED_AAMP (131)
#define OPERATION_TIMEOUT_CONNECTIVITY_AAMP (132)
#define PARTIAL_FILE_START_STALL_TIMEOUT_AAMP (133)
#define AAMP_MINIMUM_AUDIO_LEVEL (0) /**< minimum value for audio level supported */
#define AAMP_MAXIMUM_AUDIO_LEVEL (100) /**< maximum value for audio level supported */
#define STRBGPLAYER "BACKGROUND"
#define STRFGPLAYER "FOREGROUND"
#define MUTE_SUBTITLES_TRACKID (-1)
/**
* @brief Structure of X-Start HLS Tag
*/
struct HLSXStart
{
double offset; /**< Time offset from XStart */
bool precise; /**< Precise input */
};
/**
* @addtogroup AAMP_COMMON_TYPES
* @{
*/
/**
* @brief Enumeration for Curl Instances
*/
enum AampCurlInstance
{
eCURLINSTANCE_VIDEO, /**< Curl Instance for Video */
eCURLINSTANCE_AUDIO, /**< Curl Instance for Audio */
eCURLINSTANCE_SUBTITLE, /**< Curl Instance for Subtitle */
eCURLINSTANCE_AUX_AUDIO, /**< Curl Instance for Aux Audio */
eCURLINSTANCE_MANIFEST_PLAYLIST, /**< Curl Instance for Manifest file */
eCURLINSTANCE_DAI, /**< Curl Instance for DAI */
eCURLINSTANCE_AES, /**< Curl Instance for AES */
eCURLINSTANCE_PLAYLISTPRECACHE, /**< Curl Instance for Precache */
eCURLINSTANCE_MAX /**< Curl Max Instance */
};
/*
* @brief Playback Error Type
*/
enum PlaybackErrorType
{
eGST_ERROR_PTS, /**< PTS error from gstreamer */
eGST_ERROR_UNDERFLOW, /**< Underflow error from gstreamer */
eGST_ERROR_VIDEO_BUFFERING, /**< Video buffering error */
eGST_ERROR_OUTPUT_PROTECTION_ERROR, /**< Output Protection error */
eDASH_ERROR_STARTTIME_RESET, /**< Start time reset of DASH */
eSTALL_AFTER_DISCONTINUITY, /**< Playback stall after notifying discontinuity */
eGST_ERROR_GST_PIPELINE_INTERNAL, /**< GstPipeline Internal Error */
eDASH_LOW_LATENCY_MAX_CORRECTION_REACHED, /**< Low Latency Dash Max Correction Reached**/
eDASH_LOW_LATENCY_INPUT_PROTECTION_ERROR, /**< Low Latency Dash Input Protection error **/
eDASH_RECONFIGURE_FOR_ENC_PERIOD /**< Retune to reconfigure pipeline for encrypted period **/
};
/**
* @brief Tune Typea
*/
enum TuneType
{
eTUNETYPE_NEW_NORMAL, /**< Play from live point for live streams, from start for VOD*/
eTUNETYPE_NEW_SEEK, /**< A new tune with valid seek position*/
eTUNETYPE_SEEK, /**< Seek to a position. Not a new channel, so resources can be reused*/
eTUNETYPE_SEEKTOLIVE, /**< Seek to live point. Not a new channel, so resources can be reused*/
eTUNETYPE_RETUNE, /**< Internal retune for error handling.*/
eTUNETYPE_LAST, /**< Use the tune mode used in last tune*/
eTUNETYPE_NEW_END, /**< Start playback from the end of the asset*/
eTUNETYPE_SEEKTOEND /**< Seek to live point. Not a new channel, so resources can be reused*/
};
/**
* @brief AAMP Function return values
*/
enum AAMPStatusType
{
eAAMPSTATUS_OK, /**< Aamp Status ok */
eAAMPSTATUS_FAKE_TUNE_COMPLETE, /**< Fake tune completed */
eAAMPSTATUS_GENERIC_ERROR, /**< Aamp General Error */
eAAMPSTATUS_MANIFEST_DOWNLOAD_ERROR, /**< Manifest download failed */
eAAMPSTATUS_PLAYLIST_VIDEO_DOWNLOAD_ERROR, /**< Video download failed */
eAAMPSTATUS_PLAYLIST_AUDIO_DOWNLOAD_ERROR, /**< Audio dowload failed */
eAAMPSTATUS_MANIFEST_PARSE_ERROR, /**< Manifest parse failed */
eAAMPSTATUS_MANIFEST_CONTENT_ERROR, /**< Manifest content is unknown or Error */
eAAMPSTATUS_MANIFEST_INVALID_TYPE, /**< Invalid manifest type */
eAAMPSTATUS_PLAYLIST_PLAYBACK, /**< Playlist play back happening */
eAAMPSTATUS_SEEK_RANGE_ERROR, /**< Seek position range invalid */
eAAMPSTATUS_TRACKS_SYNCHRONISATION_ERROR, /**< Audio video track synchronisation Error */
eAAMPSTATUS_INVALID_PLAYLIST_ERROR, /**< Playlist discontinuity mismatch*/
eAAMPSTATUS_UNSUPPORTED_DRM_ERROR /**< Unsupported DRM */
};
/**
* @brief Http Header Type
*/
enum HttpHeaderType
{
eHTTPHEADERTYPE_COOKIE, /**< Cookie Header */
eHTTPHEADERTYPE_XREASON, /**< X-Reason Header */
eHTTPHEADERTYPE_FOG_REASON, /**< X-Reason Header */
eHTTPHEADERTYPE_EFF_LOCATION, /**< Effective URL location returned */
eHTTPHEADERTYPE_UNKNOWN=-1 /**< Unkown Header */
};
/**
* @brief Http Header Type
*/
enum CurlAbortReason
{
eCURL_ABORT_REASON_NONE = 0,
eCURL_ABORT_REASON_STALL_TIMEDOUT,
eCURL_ABORT_REASON_START_TIMEDOUT,
eCURL_ABORT_REASON_LOW_BANDWIDTH_TIMEDOUT
};
/**
* @brief Different reasons for bitrate change
*/
typedef enum
{
eAAMP_BITRATE_CHANGE_BY_ABR = 0,
eAAMP_BITRATE_CHANGE_BY_RAMPDOWN = 1,
eAAMP_BITRATE_CHANGE_BY_TUNE = 2,
eAAMP_BITRATE_CHANGE_BY_SEEK = 3,
eAAMP_BITRATE_CHANGE_BY_TRICKPLAY = 4,
eAAMP_BITRATE_CHANGE_BY_BUFFER_FULL = 5,
eAAMP_BITRATE_CHANGE_BY_BUFFER_EMPTY = 6,
eAAMP_BITRATE_CHANGE_BY_FOG_ABR = 7,
eAAMP_BITRATE_CHANGE_BY_OTA = 8,
eAAMP_BITRATE_CHANGE_BY_HDMIIN = 9,
eAAMP_BITRATE_CHANGE_MAX = 10
} BitrateChangeReason;
/**
* @enum AudioType
*
* @brief Type of audio ES for MPD
*/
enum AudioType
{
eAUDIO_UNSUPPORTED,
eAUDIO_UNKNOWN,
eAUDIO_AAC,
eAUDIO_DDPLUS,
eAUDIO_ATMOS,
eAUDIO_DOLBYAC3,
eAUDIO_DOLBYAC4
};
/**
*
* @enum Curl Request
*
*/
enum CurlRequest
{
eCURL_GET,
eCURL_POST,
eCURL_DELETE
};
/**
*
* @enum UTC TIMING
*
*/
enum UtcTiming
{
eUTC_HTTP_INVALID,
eUTC_HTTP_XSDATE,
eUTC_HTTP_ISO,
eUTC_HTTP_NTP
};
/**
* @struct AsyncEventDescriptor
* @brief Used in asynchronous event notification logic
*/
struct AsyncEventDescriptor
{
/**
* @brief AsyncEventDescriptor constructor
*/
AsyncEventDescriptor() : event(nullptr), aamp(nullptr)
{
}
/**
* @brief AsyncEventDescriptor destructor
*/
virtual ~AsyncEventDescriptor()
{
}
AsyncEventDescriptor(const AsyncEventDescriptor &other) = delete;
AsyncEventDescriptor& operator=(const AsyncEventDescriptor& other) = delete;
AAMPEventPtr event;
std::shared_ptr<PrivateInstanceAAMP> aamp;
};
/**
* @struct PeriodInfo
* @brief Stores details about available periods in mpd
*/
struct PeriodInfo {
std::string periodId;
uint64_t startTime;
uint32_t timeScale;
double duration;
PeriodInfo() : periodId(""), startTime(0), duration(0.0), timeScale(0)
{
}
};
/**
* @struct EventBreakInfo
* @brief Stores the detail about the Event break info
*/
struct EventBreakInfo
{
std::string payload;
std::string name;
uint32_t duration;
uint64_t presentationTime;
EventBreakInfo() : payload(), name(), duration(0), presentationTime(0)
{}
EventBreakInfo(std::string _data, std::string _name, uint64_t _presentationTime, uint32_t _dur) : payload(_data), name(_name), presentationTime(_presentationTime), duration(_dur)
{}
};
struct DynamicDrmInfo {
std::vector<uint8_t> keyID;
std::map<std::string, std::string> licenseEndPoint;
std::string customData;
std::string authToken;
std::string licenseResponse;
DynamicDrmInfo() : keyID(), licenseEndPoint{}, customData(""), authToken(""), licenseResponse()
{
}
};
class Id3CallbackData;
/**
* @brief Class for Timed Metadata
*/
class TimedMetadata
{
public:
/**
* @brief TimedMetadata Constructor
*/
TimedMetadata() : _timeMS(0), _name(""), _content(""), _id(""), _durationMS(0) {}
/**
* @brief TimedMetadata Constructor
*
* @param[in] timeMS - Time in milliseconds
* @param[in] name - Metadata name
* @param[in] content - Metadata content
*/
TimedMetadata(long long timeMS, std::string name, std::string content, std::string id, double durMS) : _timeMS(timeMS), _name(name), _content(content), _id(id), _durationMS(durMS) {}
public:
long long _timeMS; /**< Time in milliseconds */
std::string _name; /**< Metadata name */
std::string _content; /**< Metadata content */
std::string _id; /**< Id of the timedMetadata. If not available an Id will bre created */
double _durationMS; /**< Duration in milliseconds */
};
/**
* @brief Class for Content gap information
*/
class ContentGapInfo
{
public:
/**
* @brief ContentGapInfo Constructor
*/
ContentGapInfo() : _timeMS(0), _id(""), _durationMS(-1), _complete(false) {}
/**
* @brief ContentGapInfo Constructor
*
* @param[in] timeMS - Time in milliseconds
* @param[in] id - Content gap ID
* @param[in] durMS - Total duration of gap identified
*/
ContentGapInfo(long long timeMS, std::string id, double durMS) : _timeMS(timeMS), _id(id), _complete(false), _durationMS(durMS)
{
if(durMS > 0)
{
_complete = true;
}
}
public:
long long _timeMS; /**< Time in milliseconds */
std::string _id; /**< Id of the content gap information. (period ID of new dash period after gap) */
double _durationMS; /**< Duration in milliseconds */
bool _complete; /**< Flag to indicate whether gap info is complete or not */
};
/**
* @brief Function pointer for the idle task
* @param[in] arg - Arguments
* @return Idle task status
*/
typedef int(*IdleTask)(void* arg);
/**
* @brief Function pointer for the destroy task
*
* @param[in] arg - Arguments
*
*/
typedef void(*DestroyTask)(void * arg);
/**
* @brief To store Set Cookie: headers and X-Reason headers in HTTP Response
*/
struct httpRespHeaderData {
httpRespHeaderData() : type(0), data("")
{
}
int type; /**< Header type */
std::string data; /**< Header value */
};
/**
* @struct ThumbnailData
* @brief Holds the Thumbnail information
*/
struct ThumbnailData {
ThumbnailData() : url(""), x(0), y(0), t(0.0), d(0.0)
{
}
std::string url; /**< url of tile image (may be relative or absolute path) */
double t; /**< presentation time for this thumbnail */
double d; /**< time duration of this tile */
int x; /**< x coordinate of thumbnail within tile */
int y; /**< y coordinate of Thumbnail within tile */
};
/**
* @struct SpeedCache
* @brief Stroes the information for cache speed
*/
struct SpeedCache
{
long last_sample_time_val;
long prev_dlnow;
long prevSampleTotalDownloaded;
long totalDownloaded;
long speed_now;
long start_val;
bool bStart;
double totalWeight;
double weightedBitsPerSecond;
std::vector< std::pair<double,long> > mChunkSpeedData;
SpeedCache() : last_sample_time_val(0), prev_dlnow(0), prevSampleTotalDownloaded(0), totalDownloaded(0), speed_now(0), start_val(0), bStart(false) , totalWeight(0), weightedBitsPerSecond(0), mChunkSpeedData()
{
}
};
/**
* @brief To store Low Latency Service configurtions
*/
struct AampLLDashServiceData {
bool lowLatencyMode; /**< LL Playback mode enabled */
bool strictSpecConformance; /**< Check for Strict LL Dash spec conformace*/
double availabilityTimeOffset; /**< LL Availability Time Offset */
bool availabilityTimeComplete; /**< LL Availability Time Complete */
int targetLatency; /**< Target Latency of playback */
int minLatency; /**< Minimum Latency of playback */
int maxLatency; /**< Maximum Latency of playback */
int latencyThreshold; /**< Latency when play rate correction kicks-in */
double minPlaybackRate; /**< Minimum playback rate for playback */
double maxPlaybackRate; /**< Maximum playback rate for playback */
bool isSegTimeLineBased; /**< Indicates is stream is segmenttimeline based */
double fragmentDuration; /**< Maximum Fragment Duartion */
UtcTiming utcTiming; /**< Server UTC timings */
};
/**
* @brief To store video rectangle properties
*/
struct videoRect {
int horizontalPos;
int verticalPos;
int width;
int height;
};
/**
* @class AudioTrackTuple
* @brief Class to hold audio information like lang, codec, bitrate,etc
*/
class AudioTrackTuple
{
public:
std::string language;
std::string rendition;
std::string codec;
unsigned int bitrate;
unsigned int channel;
public:
AudioTrackTuple(): language(""),rendition(""),codec(""),bitrate(0), channel(0){}
void setAudioTrackTuple(std::string language="", std::string rendition="", std::string codec="", unsigned int channel=0)
{
this->language = language;
this->rendition = rendition;
this->codec = codec;
this->channel = channel;
this->bitrate = 0;
}
void clear(void)
{
this->language = "";
this->rendition = "";
this->codec = "";
this->bitrate = 0;
this->channel = 0;
}
};
#ifdef AAMP_HLS_DRM
/**
* \Class attrNameData
* \brief local calss to hold DRM information
*/
class attrNameData
{
public:
std::string attrName;
bool isProcessed;
attrNameData() : attrName(""),isProcessed(false)
{
}
attrNameData(std::string argument) : attrName(argument), isProcessed(false)
{
}
bool operator==(const attrNameData& rhs) const { return (this->attrName == rhs.attrName); }
};
#endif
/**
* @brief To have hostname mapped curl handles
*/
typedef struct eCurlHostMap
{
CURL *curl;
std::string hostname;
bool isRemotehost;
bool redirect;
eCurlHostMap():curl(NULL),hostname(""),isRemotehost(true),redirect(true)
{}
//Disabled
eCurlHostMap(const eCurlHostMap&) = delete;
eCurlHostMap& operator=(const eCurlHostMap&) = delete;
}eCurlHostMapStruct;
/**
* @brief Struct to store parsed url hostname & its type
*/
typedef struct AampUrlInfo
{
std::string hostname;
bool isRemotehost;
AampUrlInfo():hostname(""),isRemotehost(true)
{}
//Disabled
AampUrlInfo(const AampUrlInfo&) = delete;
AampUrlInfo& operator=(const AampUrlInfo&) = delete;
}AampURLInfoStruct;
/**
* @}
*/
class AampCacheHandler;
class AampDRMSessionManager;
/**
* @brief Class representing the AAMP player's private instance, which is not exposed to outside world.
*/
class PrivateInstanceAAMP : public AampDrmCallbacks, public std::enable_shared_from_this<PrivateInstanceAAMP>
{
enum AAMP2ReceiverMsgType
{
E_AAMP2Receiver_TUNETIME, /**< Tune time Message */
E_AAMP2Receiver_EVENTS, /**< Aamp Events to receiver */
E_AAMP2Receiver_MsgMAX /**< Max message to receiver */
};
// needed to ensure matching structure alignment in receiver
typedef struct __attribute__((__packed__)) _AAMP2ReceiverMsg
{
unsigned int type;
unsigned int length;
char data[1];
}AAMP2ReceiverMsg;
#define AAMP2ReceiverMsgHdrSz (sizeof(AAMP2ReceiverMsg)-1)
//The position previously reported by ReportProgress() (i.e. the position really sent, using SendEvent())
double mReportProgressPosn;
public:
/**
* @brief Get profiler bucket type
*
* @param[in] mediaType - Media type. eg: Video, Audio, etc
* @param[in] isInitializationSegment - Initialization segment or not
* @return Bucket type
*/
ProfilerBucketType GetProfilerBucketForMedia(MediaType mediaType, bool isInitializationSegment)
{
switch (mediaType)
{
case eMEDIATYPE_SUBTITLE:
return isInitializationSegment ? PROFILE_BUCKET_INIT_SUBTITLE : PROFILE_BUCKET_FRAGMENT_SUBTITLE;
case eMEDIATYPE_VIDEO:
return isInitializationSegment ? PROFILE_BUCKET_INIT_VIDEO : PROFILE_BUCKET_FRAGMENT_VIDEO;
case eMEDIATYPE_AUDIO:
default:
return isInitializationSegment ? PROFILE_BUCKET_INIT_AUDIO : PROFILE_BUCKET_FRAGMENT_AUDIO;
}
}
/**
* @fn Tune
*
* @param[in] url - Asset URL
* @param[in] autoPlay - Start playback immediately or not
* @param[in] contentType - Content Type
* @param[in] bFirstAttempt - External initiated tune
* @param[in] bFinalAttempt - Final retry/attempt.
* @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 Tune(const char *url, bool autoPlay, const char *contentType = NULL, bool bFirstAttempt = true, bool bFinalAttempt = false, const char *sessionUUID = NULL,bool audioDecoderStreamSync = true);
/**
* @brief API Used to reload TSB with new session
*
* @return void
*/
void ReloadTSB();
/**
* @fn TuneHelper
* @param[in] tuneType - Type of tuning. eg: Normal, trick, seek to live, etc
* @param[in] seekWhilePaused - Set true if want to keep in Paused state after
* seek for tuneType = eTUNETYPE_SEEK or eTUNETYPE_SEEKTOLIVE
* @return void
*/
void TuneHelper(TuneType tuneType, bool seekWhilePaused = false);
/**
* @fn TeardownStream
*
* @param[in] newTune - true if operation is a new tune
* @return void
*/
void TeardownStream(bool newTune);
/**
* @fn SendMessageOverPipe
*
* @param[in] str - Pointer to the message
* @param[in] nToWrite - Number of bytes in the message
* @return void
*/
void SendMessageOverPipe(const char *str,int nToWrite);
/**
* @fn GetLangCodePreference
* @return enum type
*/
LangCodePreference GetLangCodePreference();
/**
* @fn SetupPipeSession
*
* @return Success/Failure
*/
bool SetupPipeSession();
/**
* @fn ClosePipeSession
*
* @return void
*/
void ClosePipeSession();
/**
* @fn SendMessage2Receiver
*
* @param[in] type - Message type
* @param[in] data - Message data
* @return void
*/
void SendMessage2Receiver(AAMP2ReceiverMsgType type, const char *data);
/**
* @fn PausePipeline
*
* @param[in] pause - true for pause and false for play
* @param[in] forceStopGstreamerPreBuffering - true for disabling bufferinprogress
* @return true on success
*/
bool PausePipeline(bool pause, bool forceStopGstreamerPreBuffering);
/**
* @fn mediaType2Bucket
*
* @param[in] fileType - Media filetype
* @return Profiler bucket type
*/
ProfilerBucketType mediaType2Bucket(MediaType fileType);
/**
* @brief to set the vod-tune-event according to the player
*
* @param[in] tuneEventType
* @return void
*/
void SetTuneEventConfig( TunedEventConfig tuneEventType);
TunedEventConfig GetTuneEventConfig(bool isLive);
/**
* @fn UpdatePreferredAudioList
*
* @return void
*/
void UpdatePreferredAudioList();
/**
* @fn ReplaceKeyIDPsshData
* @param initialization data input
* @param initialization data input size
* @param [out] output data size
* @retval Output data pointer
*/
unsigned char* ReplaceKeyIDPsshData(const unsigned char *InputData, const size_t InputDataLength, size_t & OutputDataLength);
std::vector< std::pair<long long,long> > mAbrBitrateData;
pthread_mutex_t mLock; /**< = PTHREAD_MUTEX_INITIALIZER; */
pthread_mutexattr_t mMutexAttr;
pthread_mutex_t mParallelPlaylistFetchLock; /**< mutex lock for parallel fetch */
class StreamAbstractionAAMP *mpStreamAbstractionAAMP; /**< HLS or MPD collector */
class CDAIObject *mCdaiObject; /**< Client Side DAI Object */
std::queue<AAMPEventPtr> mAdEventsQ; /**< A Queue of Ad events */
std::mutex mAdEventQMtx; /**< Add events' queue protector */
bool mInitSuccess; /**< TODO: Need to replace with player state */
StreamOutputFormat mVideoFormat;
StreamOutputFormat mAudioFormat;
StreamOutputFormat mPreviousAudioType; /**< Used to maintain previous audio type of HLS playback */
StreamOutputFormat mAuxFormat;
StreamOutputFormat mSubtitleFormat{FORMAT_UNKNOWN};
pthread_cond_t mDownloadsDisabled;
bool mDownloadsEnabled;
StreamSink* mStreamSink;
HybridABRManager mhAbrManager; /**< Pointer to Hybrid abr manager*/
ProfileEventAAMP profiler;
bool licenceFromManifest;
AudioType previousAudioType; /**< Used to maintain previous audio type */
CURL *curl[eCURLINSTANCE_MAX];
eCurlHostMapStruct *curlhost[eCURLINSTANCE_MAX];
CURLSH* mCurlShared;
// To store Set Cookie: headers and X-Reason headers in HTTP Response
httpRespHeaderData httpRespHeaders[eCURLINSTANCE_MAX];
//std::string cookieHeaders[MAX_CURL_INSTANCE_COUNT]; //To store Set-Cookie: headers in HTTP response
std::string mManifestUrl;
std::string mTunedManifestUrl;
std::string mTsbSessionRequestUrl;
std::string schemeIdUriDai;
AampURLInfoStruct mOrigManifestUrl; /**< Original Manifest URl */
bool isPreferredDRMConfigured;
bool mIsWVKIDWorkaround; /**< Widevine KID workaround flag */
int mPreCacheDnldTimeWindow; /**< Stores PreCaching timewindow */
bool mbDownloadsBlocked;
bool streamerIsActive;
bool mTSBEnabled;
bool mIscDVR;
double mLiveOffset;
long mNetworkTimeoutMs;
std::string mCMCDNextObjectRequest; /**<store the next next fragment url */
long mCMCDBandwidth; /**<store the audio bandwidth */
long mManifestTimeoutMs;
long mPlaylistTimeoutMs;
bool mAsyncTuneEnabled;
/**
* @brief A readonly, validatable position value.
*/
template<typename TPOSITION> class PositionInfo
{
private:
TPOSITION mPosition;
long long mUpdateTime;
double mSeekPosSeconds; //copy of seek_pos_seconds
bool mIsPopulated; //true if data is real, false if default values
public:
PositionInfo():mPosition(-1.0), mUpdateTime(0), mSeekPosSeconds(-1), mIsPopulated(false){}
PositionInfo(TPOSITION Pos, double SeekPosSeconds):mPosition(Pos), mUpdateTime(aamp_GetCurrentTimeMS()), mSeekPosSeconds(SeekPosSeconds), mIsPopulated(true){}
/**
* @brief The stored position value, may be invalid, check using isPositionValid()
*/
TPOSITION getPosition() const {return mPosition;}
/**
* @brief The timestamp at which the position in this object was updated (0 by deault)
*/
long long getUpdateTime() const {return mUpdateTime;};
/**
* @brief For objects containing real data (check using isPopulated()) this
* returns the number of milliseconds since the object was created
*/
long long getTimeSinceUpdateMs() const
{
return (aamp_GetCurrentTimeMS() - getUpdateTime());
}
/**
* @brief seek_pos_seconds value supplied when this object was created (-1 default)
*/
double getSeekPositionSec() const {return mSeekPosSeconds;}
/**
* @brief false if the object contains default data
*/
bool isPopulated() const {return mIsPopulated;}
/**
* @brief Returns true if the value returned by Position() is valid
*/
bool isPositionValid(const double LatestSeekPosSeconds) const
{
constexpr double SEEK_POS_SECONDS_TOLERANCE = 0.01;
return (
isPopulated() &&
((std::abs(getSeekPositionSec() - LatestSeekPosSeconds)<SEEK_POS_SECONDS_TOLERANCE)) &&
(0.0<=getPosition())
);
}
};
/**
* @brief A standard way of storing positions with associated data for validation purposes
*/
template<typename TPOSITIONCACHE> class PositionCache
{
PositionInfo<TPOSITIONCACHE> mInfo;
std::mutex mMutex;
public:
PositionCache():mInfo(), mMutex(){}
/**
* @brief Update the stored position information
*/
void Update(TPOSITIONCACHE Pos, double SeekPosSeconds)
{
std::lock_guard<std::mutex>lock(mMutex);
mInfo = PositionInfo<TPOSITIONCACHE>{Pos, SeekPosSeconds};
}
/**
* @brief Retrieve the stored position information
*/
PositionInfo<TPOSITIONCACHE> GetInfo()
{
std::lock_guard<std::mutex>lock(mMutex);
return mInfo;
}
/**
* @brief Explicitly set the cache to an invalid state
*/
void Invalidate()
{
std::lock_guard<std::mutex>lock(mMutex);
mInfo = PositionInfo<TPOSITIONCACHE>{};
}
};
PositionCache<long long> mPrevPositionMilliseconds;
std::mutex mGetPositionMillisecondsMutexHard; //limit (with lock()) access to GetPositionMilliseconds(), & mGetPositionMillisecondsMutexSoft
std::mutex mGetPositionMillisecondsMutexSoft; //detect (with trylock()) where mGetPositionMillisecondsMutexHard would have deadlocked if it was the sole mutex
volatile std::atomic <long long> mPausePositionMilliseconds; /**< Requested pause position, can be 0 or more, or AAMP_PAUSE_POSITION_INVALID_POSITION */
MediaFormat mMediaFormat;
double seek_pos_seconds; /**< indicates the playback position at which most recent playback activity began */
float rate; /**< most recent (non-zero) play rate for non-paused content */
float playerrate;
bool mSetPlayerRateAfterFirstframe;
bool pipeline_paused; /**< true if pipeline is paused */
bool mbNewSegmentEvtSent[AAMP_TRACK_COUNT];
char mLanguageList[MAX_LANGUAGE_COUNT][MAX_LANGUAGE_TAG_LENGTH]; /**< list of languages in stream */
int mCurrentLanguageIndex; /**< Index of current selected lang in mLanguageList, this is used for VideoStat event data collection */
int mMaxLanguageCount;
std::string preferredLanguagesString; /**< unparsed string with preferred languages in format "lang1,lang2,.." */
std::vector<std::string> preferredLanguagesList; /**< list of preferred languages from most-preferred to the least */
std::string preferredRenditionString; /**< unparsed string with preferred renditions in format "rendition1,rendition2,.." */
std::vector<std::string> preferredRenditionList; /**< list of preferred rendition from most-preferred to the least */
std::string preferredLabelsString; /**< unparsed string with preferred labels in format "lang1,lang2,.." */
std::vector<std::string> preferredLabelList; /**< list of preferred labels from most-preferred to the least */
std::string preferredTypeString; /**< unparsed string with preferred accessibility type */
std::string preferredCodecString; /**< unparsed string with preferred codecs in format "codec1,codec2,.." */
std::vector<std::string> preferredCodecList; /**<String array to store codec preference */
std::string preferredTextLanguagesString; /**< unparsed string with preferred languages in format "lang1,lang2,.." */
std::vector<std::string> preferredTextLanguagesList; /**< list of preferred text languages from most-preferred to the least*/
std::string preferredTextRenditionString; /**< String value for rendition */
std::string preferredTextTypeString; /**< String value for text type */
std::string preferredTextLabelString; /**< String value for text type */
std::vector<struct DynamicDrmInfo> vDynamicDrmData;
Accessibility preferredTextAccessibilityNode; /**< Preferred Accessibility Node for Text */
Accessibility preferredAudioAccessibilityNode; /**< Preferred Accessibility Node for Audio */
AudioTrackTuple mAudioTuple; /**< Depricated **/
VideoZoomMode zoom_mode;
bool video_muted;
bool subtitles_muted;
int audio_volume;
std::vector<std::string> subscribedTags;
std::vector<TimedMetadata> timedMetadata;
std::vector<TimedMetadata> timedMetadataNew;
std::vector<ContentGapInfo> contentGaps;
std::vector<std::string> responseHeaders;
std::vector<long>bitrateList;
std::map<std::string, std::string> httpHeaderResponses;
bool mIsIframeTrackPresent; /**< flag to check iframe track availability*/
/* START: Added As Part of DELIA-28363 and DELIA-28247 */
bool IsTuneTypeNew; /**< Flag for the eTUNETYPE_NEW_NORMAL */
/* END: Added As Part of DELIA-28363 and DELIA-28247 */
bool mLogTimetoTopProfile; /**< Flag for logging time to top profile ,only one time after tune .*/
pthread_cond_t waitforplaystart; /**< Signaled after playback starts */
pthread_mutex_t mMutexPlaystart; /**< Mutex associated with playstart */