-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathpriv_aamp.h
More file actions
4364 lines (3840 loc) · 124 KB
/
Copy pathpriv_aamp.h
File metadata and controls
4364 lines (3840 loc) · 124 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 priv_aamp.h
* @brief Private functions and types used internally by AAMP
*/
#ifndef PRIVAAMP_H
#define PRIVAAMP_H
#include "Accessibility.hpp"
#include "VideoZoomMode.h"
#include "AampScheduler.h"
#include "StreamSink.h"
#include "TimedMetadata.h"
#include "AampSpeedCache.h"
#include "AampProfiler.h"
#include "DrmHelper.h"
#include "DrmMediaFormat.h"
#include "DrmCallbacks.h"
#include <IPVideoStat.h>
#include "CCTrackInfo.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 <condition_variable>
#include <queue>
#include <algorithm>
#include <glib.h>
#include <cjson/cJSON.h>
#include <future>
#include "AampConfig.h"
#include <atomic>
#include <memory>
#include <inttypes.h>
#include <type_traits>
#include <chrono>
#include "AampEventManager.h"
#include "abr.h"
#include "AampCMCDCollector.h"
#include "AampDefine.h"
#include "AampCurlDefine.h"
#include "AampLLDASHData.h"
#include "AampMPDPeriodInfo.h"
#include "TsbApi.h"
#include "AampTrackWorkerManager.hpp"
#include "AudioTrackInfo.h"
#include "TextTrackInfo.h"
#include "AAMPAnomalyMessageType.h"
#include "AampDemuxDataTypes.h"
#define FAKE_TUNE_URL "file:///etc/manifest.mpd" /**< Fake tune URL for testing purposes */
// forward declaration to avoid circular dependency
class AampMPDDownloader;
class AampLatencyMonitor;
struct LatencyConfig;
// forward declaration
struct CurlCallbackContext;
typedef struct _manifestDownloadConfig ManifestDownloadConfig;
/**
* @struct PreCacheUrlData
* @brief Pre cache the data information
*/
typedef struct PreCacheUrlData
{
std::string url;
AampMediaType type;
PreCacheUrlData():url(""),type(eMEDIATYPE_VIDEO)
{
}
} PreCacheUrlStruct;
typedef std::vector < PreCacheUrlStruct> PreCacheUrlList;
class AampTSBSessionManager;
namespace aamp
{
// Other declarations
class AampTrackWorkerManager; // Forward declaration
}
#include "ID3Metadata.hpp"
#define AAMP_SEEK_TO_LIVE_POSITION (-1)
#define MANIFEST_TEMP_DATA_LENGTH 100 /**< Manifest temp data length */
#define AAMP_LOW_BUFFER_BEFORE_RAMPDOWN_FOR_LLD 3 /**< 3sec buffer before rampdown for lld */
#define AAMP_HIGH_BUFFER_BEFORE_RAMPUP_FOR_LLD 4 /**< 4sec buffer before rampup for lld */
#define TIMEOUT_FOR_LLD 3 /**< 3sec network timeout for lld */
#define MANIFEST_TIMEOUT_FOR_LLD 3 /**< 3 sec timeout for manifest refresh in case of LLD*/
#define ABR_BUFFER_COUNTER_FOR_LLD 3 /** Counter for steady state rampup/rampdown for lld */
#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
/**
* @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 CONVERT_MS_TO_SEC(_x_) (_x_ / 1000)
#define DEFAULT_PRECACHE_WINDOW (10) /**< 10 mins for full precaching */
// 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)
#define LOW_BW_TIMEOUT_FACTOR 0.4
#define DEFAULT_LOW_BW_TIMEOUT 4
/**
* @brief Structure of X-Start HLS Tag
*/
struct HLSXStart
{
double offset; /**< Time offset from XStart */
bool precise; /**< Precise input */
};
/*
* @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 Type
*/
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 Http Header Type
*/
/**
* @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,
eAUDIO_VORBIS,
eAUDIO_OPUS
};
/**
* @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<class PrivateInstanceAAMP> aamp;
};
/**
* @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;
bool isDAIEvent; // true if the SCTE35 event is PA START or PPO START
EventBreakInfo() : payload(), name(), duration(0), presentationTime(0), isDAIEvent(false)
{}
EventBreakInfo(std::string _data, std::string _name, uint64_t _presentationTime, uint32_t _dur, bool _isDAIEvent) : payload(std::move(_data)), name(std::move(_name)), presentationTime(_presentationTime), duration(_dur), isDAIEvent(_isDAIEvent)
{}
};
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 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(std::move(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 TileLayout
{
int numRows; /**< Number of Rows from Tile Inf */
int numCols; /**< Number of Cols from Tile Inf */
double posterDuration; /**< Duration of each Tile in Spritesheet */
double tileSetDuration; /**< Duration of whole tile set */
long long progStartDateTime; /**< Program start date time from manifest */
TileLayout(): numRows(0), numCols(0), posterDuration(0.0f), tileSetDuration(0.0f), progStartDateTime(0)
{
}
};
/**
* \struct TileInfo
* \brief TileInfo structure for Thumbnail data
*/
class TileInfo
{
public:
TileInfo(): layout(), startTime(), url()
{
}
~TileInfo()
{
}
TileLayout layout;
double startTime;
std::string url;
};
/**
* @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 */
};
/**
* @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;
BitsPerSecond 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 = std::move(language);
this->rendition = std::move(rendition);
this->codec = std::move(codec);
this->channel = channel;
this->bitrate = 0;
}
void clear(void)
{
this->language = "";
this->rendition = "";
this->codec = "";
this->bitrate = 0;
this->channel = 0;
}
};
/**
* \Class attrNameData
* \brief local class to hold DRM information
*/
class attrNameData
{
public:
std::string attrName;
bool isProcessed;
attrNameData() : attrName(""),isProcessed(false)
{
}
attrNameData(std::string argument) : attrName(std::move(argument)), isProcessed(false)
{
}
bool operator==(const attrNameData& rhs) const { return (this->attrName == rhs.attrName); }
};
/**
* @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;
typedef enum
{
PROFILE_BLACKLIST_DRM_FAILURE,
PROFILE_BLACKLIST_INIT_FAILURE
} eBlacklistProfileReason;
typedef struct BlacklistProfileInfo_t
{
// Extend for HLS and other stream formats
std::string mPeriodId;
uint32_t mAdaptationSetIdx;
eBlacklistProfileReason mReason;
} StreamBlacklistProfileInfo;
/**
* @}
*/
class AampCacheHandler;
class AampDRMLicenseManager;
/**
* @brief
*
*/
class SegmentInfo_t;
/**
* @brief Class representing the AAMP player's private instance, which is not exposed to outside world.
*/
class PrivateInstanceAAMP : public DrmCallbacks, 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 MonitorProgress() (i.e. the position really sent, using SendEvent())
double mReportProgressPosn;
long long mLastTelemetryTimeMS;
// The time when buffering started (steady clock ms), used to calculate buffering duration
// for telemetry. -1 means no episode is in progress. Declared atomic because
// SendBufferChangeEvent() is reached concurrently from the underflow monitor thread and
// from GStreamer error callbacks (via ScheduleRetune), with no common lock held at the
// call site. The compound check-and-set operations in SendBufferChangeEvent use
// compare_exchange_strong / exchange to keep the read-modify-write sequences race-free.
std::atomic<long long> mBufferingStartTimeMS;
std::chrono::system_clock::time_point m_lastSubClockSyncTime;
std::shared_ptr<TSB::Store> mTSBStore; /**< Local TSB Store object */
void SanitizeLanguageList(std::vector<std::string>& languages) const;
/**
* @fn Process json object or language string and save the preferred selection to AampConfig
* @param[in] param - language string or json object
* @param[out] isSelectionChange - flag to indicate if accessibility has changed
*/
void SavePreferredTextLanguages(const char *param, bool &isSelectionChange);
/**
* @brief Set closed caption track with appropriate format from passed text track
* @param[in] track - Text track information
*/
void SetClosedCaptionsFromTextTrack(TextTrackInfo &track);
/**
* @brief Find closed caption track index in list of text tracks
* @param[in] trackInfo - Text track information vector
* @return index of closed caption track otherwise -1 if not found
*/
int FindClosedCaptionTrackIndex(const std::vector<TextTrackInfo> &trackInfo) const;
/**
* @fn CheckPreferredTextLanguages
* @param[in] trackInfo - Text track information
* @param[out] isSelectionChange true if preferences now select a different track to the current selection
* @param[out] isAvailableInManifest true if new selection is available in the manifest
* @param[out] closedCaptionTrackIdx - closed caption track index
*/
void CheckPreferredTextLanguages(const std::vector<TextTrackInfo> &trackInfo,bool &isInManifest, bool &isPresent, int &closedCaptionTrackIdx);
/**
* @brief Find the index of a text track in a vector
* @param[in] tracks - Vector of text tracks to search
* @param[in] target - Track to find
* @return Index of track (0-based), or -1 if not found
*/
int FindTextTrackIndex(const std::vector<TextTrackInfo>& tracks,
const TextTrackInfo& target) const;
public:
/* @fn RecalculatePTS
* @param[in] mediaType stream type
* @param[in] ptr buffer pointer
* @param[in] len length of buffer
*/
double RecalculatePTS(AampMediaType mediaType, const void *ptr, size_t len);
/**
* @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(AampMediaType 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
*
* @param[in] refreshManifestUrl -
* @param[in] mpdStitchingMode -
* @param[in] sid - Session ID defined by the player
* @param[in] manifestData - preprocessed manifest provided by application
* @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,
const char *refreshManifestUrl = NULL,
int mpdStitchingMode = 0,
std::string sid = {},
const char *manifestData = NULL
);
/**
* @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
* @param[in] newTune - true if downloads need to be disabled
* @return void
*/
void TeardownStream( bool newTune, bool disableDownloads = false );
/**
* @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() const;
/**
* @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 buffer-in-progress
* @return true on success
*/
bool PausePipeline(bool pause, bool forceStopGstreamerPreBuffering);
/**
* @fn SetBufferingState
* @brief Convenience API to toggle buffering state and handle pipeline pause/resume and events.
* When buffering is true, sends buffer start event and pauses pipeline if not already paused.
* When buffering is false, resumes pipeline if paused, updates subtitle timestamp, and sends buffer end event.
* @param[in] buffering - true to indicate buffering (underflow start), false to indicate buffering ended.
* @return void
*/
void SetBufferingState(bool buffering);
/**
* @fn mediaType2Bucket
*
* @param[in] mediaType - Media filetype
* @return Profiler bucket type
*/
ProfilerBucketType mediaType2Bucket(AampMediaType mediaType);
/**
* @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 EnableMediaDownloads
*
* @param[in] AampMediaType - playlist type
* @return void
*/
void EnableMediaDownloads(AampMediaType type);
/**
* @fn DisableMediaDownloads
*
* @param[in] AampMediaType - playlist type
* @return void
*/
void DisableMediaDownloads(AampMediaType type);
/**
* @fn EnableAllMediaDownloads
*
* @return void
*/
void EnableAllMediaDownloads();
/**
* @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);
/**
* @fn UpdateBufferBasedOnLiveOffset - to modify Min/Max buffer based on liveoffset value
*
* @return void
*/
void UpdateBufferBasedOnLiveOffset();
/**
* @fn GetCustomHeaders - get CUrl headers for a media type request
*
* Free the returned list of CUrl headers using curl_slist_free_all.
*
* @param[in] mediaType Media type
* @return list of CUrl headers
*/
struct curl_slist* GetCustomHeaders(AampMediaType mediaType);
/**
* @fn SetDiscontinuityParam - to mark the discontinuity and save the details
* @return void
*/
void SetDiscontinuityParam();
/**
* @fn SetLatencyParam - to mark the latency details
* @param latency - latency value
* @param buffer - buffer
* @param playbackRate - playback Rate
* @param bw - bandwidth
* @return void
*/
void SetLatencyParam(double latency, double buffer, double playbackRate, double bw);
/**
* @fn SetLLDLowBufferParam - to mark the lld low buff details
* @param latency - latency value
* @param buff - buffer
* @param rate - playback rate
* @param bw - bandwidth
* @param buffLowCount - Low buffer hit count
* @return void
*/
void SetLLDLowBufferParam(double latency, double buff, double rate, double bw, double buffLowCount);
/**
* @fn GetTSBStore - Get the TSB Store Object
* @param config - TSB config
* @param logger - Logger function
* @param level - Log Level
* @return TSB::Store pointer
*/
std::shared_ptr<TSB::Store> GetTSBStore(const TSB::Store::Config& config, TSB::LogFunction logger, TSB::LogLevel level);
/**
* @brief Get if pipeline reconfigure required for elementary stream type change status (from stream abstraction)
* @return true if audio codec has changed
*/
bool ReconfigureForElementaryStreamUpdate();
/**
* @brief Function pointer passed as argument to AampMPDDownloader class. This function is invoked to read the preprocessed manifest provided by application.
* Also it generate error event if preprocessed manifest is not available.
*
* @return modified manifest data
*/
std::string SendManifestPreProcessEvent();
/**
* @brief This function is invoked by application with the available preprocessed manifest information
* This function is invoked continuously when ever there is an update in manifest
*/
void updateManifest(const char *manifestData);
bool mDiscontinuityFound;
int mTelemetryInterval;
std::recursive_mutex mLock;
std::recursive_mutex mParallelPlaylistFetchLock; /**< mutex lock for parallel fetch */
std::thread mRateCorrectionThread; /**< Rate correction thread Id **/
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 mSubtitleFormat{FORMAT_UNKNOWN};
std::condition_variable_any mDownloadsDisabled;
bool mDownloadsEnabled;
std::map<AampMediaType, bool> mMediaDownloadsEnabled; /* Used to enable/Disable individual mediaType downloads */
ABRManager 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 mSchemeIdUriDai;
std::string mMPDStichRefreshUrl;
std::string mProvidedManifestFile; // provided manifest data
MPDStichOptions mMPDStichOption;
AampURLInfoStruct mOrigManifestUrl; /**< Original Manifest URl */
bool isPreferredDRMConfigured;
bool mIsWVKIDWorkaround; /**< Widevine KID workaround flag */
int mPreCacheDnldTimeWindow; /**< Stores PreCaching timewindow */
bool mbDownloadsBlocked;
bool streamerIsActive;
bool mFogTSBEnabled;
bool mIscDVR;
double mLiveOffset;
double mLiveOffsetDrift; /**< allowed drift value from live offset configured **/
int mNetworkTimeoutMs;
int mManifestTimeoutMs;
int mPlaylistTimeoutMs;
bool mAsyncTuneEnabled;
std::string mTsbType;
int mTsbDepthMs;
int mDownloadDelay;
long long mThumbnailLastProgramDateTime;
std::vector<TileInfo> mLastSleThumbnailInfo;
/**
* @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 default)
*/
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
*/
int getTimeSinceUpdateMs() const
{
return (int)(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