RDK Documentation (Open Sourced RDK Components)
fragmentcollector_mpd.h
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's license file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2018 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 /**
21  * @file fragmentcollector_mpd.h
22  * @brief Fragment collector MPEG DASH declarations
23  */
24 
25 #ifndef FRAGMENTCOLLECTOR_MPD_H_
26 #define FRAGMENTCOLLECTOR_MPD_H_
27 
28 #include "StreamAbstractionAAMP.h"
29 #include "AampJsonObject.h" /**< For JSON parsing */
30 #include <string>
31 #include <stdint.h>
32 #include "libdash/IMPD.h"
33 #include "libdash/INode.h"
34 #include "libdash/IDASHManager.h"
35 #include "libdash/IProducerReferenceTime.h"
36 #include "libdash/xml/Node.h"
37 #include "libdash/helpers/Time.h"
38 #include "libdash/xml/DOMParser.h"
39 #include <libxml/xmlreader.h>
40 #include <thread>
41 #include "admanager_mpd.h"
42 
43 using namespace dash;
44 using namespace std;
45 using namespace dash::mpd;
46 using namespace dash::xml;
47 using namespace dash::helpers;
48 #define MAX_MANIFEST_DOWNLOAD_RETRY_MPD 2
49 
50 /*Common MPD util functions (admanager_mpd.cpp and fragmentcollector_mpd.cpp */
51 double aamp_GetPeriodNewContentDuration(dash::mpd::IMPD *mpd, IPeriod * period, uint64_t &curEndNumber);
52 /**
53  * @fn aamp_GetPeriodStartTimeDeltaRelativeToPTSOffset
54  * @param period period of segment
55  */
57 /**
58  * @fn aamp_GetPeriodDuration
59  * @param mpd manifest ptr
60  * @param periodIndex Index of the current period
61  */
62 double aamp_GetPeriodDuration(dash::mpd::IMPD *mpd, int periodIndex, uint64_t mpdDownloadTime = 0);
63 /**
64  * @fn aamp_ProcessNode
65  * @param[in] reader Pointer to reader object
66  * @param[in] url manifest url
67  */
68 Node* aamp_ProcessNode(xmlTextReaderPtr *reader, std::string url, bool isAd = false);
69 /**
70  * @fn aamp_GetDurationFromRepresentation
71  * @param mpd manifest ptr
72  */
73 uint64_t aamp_GetDurationFromRepresentation(dash::mpd::IMPD *mpd);
74 
75 /**
76  * @struct ProfileInfo
77  * @brief Manifest file adaptation and representation info
78  */
80 {
81  int adaptationSetIndex;
82  int representationIndex;
83 };
84 
85 /**
86  * @struct FragmentDescriptor
87  * @brief Stores information of dash fragment
88  */
90 {
91 private :
92  std::string matchingBaseURL;
93 public :
94  std::string manifestUrl;
95  uint32_t Bandwidth;
96  std::string RepresentationID;
97  uint64_t Number;
98  double Time;
99  bool bUseMatchingBaseUrl;
100 
101  FragmentDescriptor() : manifestUrl(""), Bandwidth(0), Number(0), Time(0), RepresentationID(""),matchingBaseURL(""),bUseMatchingBaseUrl(false)
102  {
103  }
104 
105  FragmentDescriptor(const FragmentDescriptor& p) : manifestUrl(p.manifestUrl), Bandwidth(p.Bandwidth), RepresentationID(p.RepresentationID), Number(p.Number), Time(p.Time),matchingBaseURL(p.matchingBaseURL),bUseMatchingBaseUrl(p.bUseMatchingBaseUrl)
106  {
107  }
108 
109  FragmentDescriptor& operator=(const FragmentDescriptor &p)
110  {
111  manifestUrl = p.manifestUrl;
112  RepresentationID.assign(p.RepresentationID);
113  Bandwidth = p.Bandwidth;
114  Number = p.Number;
115  Time = p.Time;
116  matchingBaseURL = p.matchingBaseURL;
117  return *this;
118  }
119  std::string GetMatchingBaseUrl() const
120  {
121  return matchingBaseURL;
122  }
123 
124  void ClearMatchingBaseUrl()
125  {
126  matchingBaseURL.clear();
127  }
128  void AppendMatchingBaseUrl( const std::vector<IBaseUrl *>*baseUrls )
129  {
130  if( baseUrls && baseUrls->size()>0 )
131  {
132  const std::string &url = baseUrls->at(0)->GetUrl();
133  if( url.empty() )
134  {
135  }
136  else if( aamp_IsAbsoluteURL(url) )
137  {
138  if(bUseMatchingBaseUrl)
139  {
140  std::string prefHost = aamp_getHostFromURL(manifestUrl);
141  for (auto & item : *baseUrls) {
142  std::string itemUrl = item->GetUrl();
143  std::string host = aamp_getHostFromURL(itemUrl);
144  if(0 == prefHost.compare(host))
145  {
146  matchingBaseURL = item->GetUrl();
147  return;
148  }
149  }
150  }
151  matchingBaseURL = url;
152  }
153  else if( url.rfind("/",0)==0 )
154  {
155  matchingBaseURL = aamp_getHostFromURL(matchingBaseURL);
156  matchingBaseURL += url;
157  AAMPLOG_WARN( "baseURL with leading /" );
158  }
159  else
160  {
161  if( !matchingBaseURL.empty() && matchingBaseURL.back() != '/' )
162  { // add '/' delimiter only if parent baseUrl doesn't already end with one
163  matchingBaseURL += "/";
164  }
165  matchingBaseURL += url;
166  }
167  }
168  }
169 };
170 
171 /**
172  * @class StreamAbstractionAAMP_MPD
173  * @brief Fragment collector for MPEG DASH
174  */
176 {
177 public:
178  /**
179  * @fn StreamAbstractionAAMP_MPD
180  * @param aamp pointer to PrivateInstanceAAMP object associated with player
181  * @param seek_pos Seek position
182  * @param rate playback rate
183  */
184  StreamAbstractionAAMP_MPD(AampLogManager *logObj, class PrivateInstanceAAMP *aamp,double seekpos, float rate);
185  /**
186  * @fn ~StreamAbstractionAAMP_MPD
187  */
189  /**
190  * @fn StreamAbstractionAAMP_MPD Copy constructor disabled
191  *
192  */
194  /**
195  * @fn StreamAbstractionAAMP_MPD assignment operator disabled
196  *
197  */
198  StreamAbstractionAAMP_MPD& operator=(const StreamAbstractionAAMP_MPD&) = delete;
199  /**
200  * @fn DumpProfiles
201  */
202  void DumpProfiles(void) override;
203  /**
204  * @fn Start
205  * @return void
206  */
207  void Start() override;
208  /**
209  * @fn Stop
210  * @param clearChannelData - ignored.
211  */
212  void Stop(bool clearChannelData) override;
213  /**
214  * @fn Init
215  * @param tuneType to set type of object.
216  */
217  AAMPStatusType Init(TuneType tuneType) override;
218  /**
219  * @fn GetStreamFormat
220  * @param[out] primaryOutputFormat - format of primary track
221  * @param[out] audioOutputFormat - format of audio track
222  * @param[out] auxOutputFormat - format of aux audio track
223  * @param[out] subtitleOutputFormat - format of sutbtile track
224  */
225  void GetStreamFormat(StreamOutputFormat &primaryOutputFormat, StreamOutputFormat &audioOutputFormat, StreamOutputFormat &auxOutputFormat, StreamOutputFormat &subtitleOutputFormat) override;
226  /**
227  * @fn GetStreamPosition
228  */
229  double GetStreamPosition() override;
230  /**
231  * @fn GetMediaTrack
232  * @param[in] type - track type
233  */
234  MediaTrack* GetMediaTrack(TrackType type) override;
235  /**
236  * @fn GetFirstPTS
237  */
238  double GetFirstPTS() override;
239  /**
240  * @fn GetStartTimeOfFirstPTS
241  */
242  double GetStartTimeOfFirstPTS() override;
243  /**
244  * @fn GetBWIndex
245  * @param[in] bitrate Bitrate to lookup profile
246  */
247  int GetBWIndex(long bitrate) override;
248  /**
249  * @fn GetVideoBitrates
250  */
251  std::vector<long> GetVideoBitrates(void) override;
252  /**
253  * @fn GetAudioBitrates
254  */
255  std::vector<long> GetAudioBitrates(void) override;
256  /**
257  * @fn GetMaxBitrate
258  */
259  long GetMaxBitrate(void) override;
260  /**
261  * @fn StopInjection
262  * @return void
263  */
264  void StopInjection(void) override;
265  /**
266  * @fn StartInjection
267  * @return void
268  */
269  void StartInjection(void) override;
270  double GetBufferedDuration();
271  void SeekPosUpdate(double secondsRelativeToTuneTime) {seekPosition = secondsRelativeToTuneTime; }
272  virtual void SetCDAIObject(CDAIObject *cdaiObj) override;
273  /**
274  * @fn GetAvailableAudioTracks
275  * @param[in] tracks - available audio tracks in period
276  * @param[in] trackIndex - index of current audio track
277  */
278  virtual std::vector<AudioTrackInfo> & GetAvailableAudioTracks(bool allTrack=false) override;
279  /**
280  * @brief Gets all/current available text tracks
281  * @retval vector of tracks
282  */
283  virtual std::vector<TextTrackInfo>& GetAvailableTextTracks(bool allTrack=false) override;
284 
285  /**
286  * @fn Is4KStream
287  * @brief check if current stream have 4K content
288  * @param height - resolution of 4K stream if found
289  * @param bandwidth - bandwidth of 4K stream if foudd
290  * @return true on success
291  */
292  virtual bool Is4KStream(int &height, long &bandwidth) override;
293 
294 
295  /**
296  * @fn GetProfileCount
297  *
298  */
299  int GetProfileCount();
300  /**
301  * @fn GetProfileIndexForBandwidth
302  * @param mTsbBandwidth - bandwidth to identify profile index from list
303  */
304  int GetProfileIndexForBandwidth(long mTsbBandwidth);
305  /**
306  * @fn GetAvailableThumbnailTracks
307  */
308  std::vector<StreamInfo*> GetAvailableThumbnailTracks(void) override;
309  /**
310  * @fn GetAvailableVideoTracks
311  */
312  std::vector<StreamInfo*> GetAvailableVideoTracks(void) override;
313  /**
314  * @fn SetThumbnailTrack
315  * @param thumbnail index value indicating the track to select
316  */
317  bool SetThumbnailTrack(int) override;
318  /**
319  * @fn GetThumbnailRangeData
320  * @param tStart start duration of thumbnail data.
321  * @param tEnd end duration of thumbnail data.
322  * @param *baseurl base url of thumbnail images.
323  * @param *raw_w absolute width of the thumbnail spritesheet.
324  * @param *raw_h absolute height of the thumbnail spritesheet.
325  * @param *width width of each thumbnail tile.
326  * @param *height height of each thumbnail tile.
327  */
328  std::vector<ThumbnailData> GetThumbnailRangeData(double,double, std::string*, int*, int*, int*, int*) override;
329 
330  // ideally below would be private, but called from MediaStreamContext
331  /**
332  * @fn GetAdaptationSetAtIndex
333  * @param[in] idx - Adaptation Set Index
334  */
335  const IAdaptationSet* GetAdaptationSetAtIndex(int idx);
336  /**
337  * @fn GetAdaptationSetAndRepresetationIndicesForProfile
338  * @param[in] idx - Profile Index
339  */
340  struct ProfileInfo GetAdaptationSetAndRepresetationIndicesForProfile(int profileIndex);
341  int64_t GetMinUpdateDuration() { return mMinUpdateDurationMs;}
342  /**
343  * @fn FetchFragment
344  * @param pMediaStreamContext Track object pointer
345  * @param media media descriptor string
346  * @param fragmentDuration duration of fragment in seconds
347  * @param isInitializationSegment true if fragment is init fragment
348  * @param curlInstance curl instance to be used to fetch
349  * @param discontinuity true if fragment is discontinuous
350  * @param pto unscaled pto value from mpd
351  * @param scale timeScale value from mpd
352  */
353  bool FetchFragment( class MediaStreamContext *pMediaStreamContext, std::string media, double fragmentDuration, bool isInitializationSegment, unsigned int curlInstance, bool discontinuity = false, double pto = 0 , uint32_t scale = 0);
354  /**
355  * @fn PushNextFragment
356  * @param pMediaStreamContext Track object
357  * @param curlInstance instance of curl to be used to fetch
358  */
359  bool PushNextFragment( class MediaStreamContext *pMediaStreamContext, unsigned int curlInstance);
360  /**
361  * @fn GetFirstPeriodStartTime
362  */
363  double GetFirstPeriodStartTime(void);
364  void MonitorLatency();
365  void StartSubtitleParser() override;
366  void PauseSubtitleParser(bool pause) override;
367  /**
368  * @fn GetCurrPeriodTimeScale
369  */
370  uint32_t GetCurrPeriodTimeScale();
371  dash::mpd::IMPD *GetMPD( void );
372  IPeriod *GetPeriod( void );
373  /**
374  * @fn GetPreferredTextRepresentation
375  * @param[in] adaptationSet Adaptation set object
376  * @param[out] selectedRepIdx - Selected representation index
377  * @param[out] selectedRepBandwidth - selected audio track bandwidth
378  */
379  void GetPreferredTextRepresentation(IAdaptationSet *adaptationSet, int &selectedRepIdx, uint32_t &selectedRepBandwidth, unsigned long long &score, std::string &name, std::string &codec);
380  static Accessibility getAccessibilityNode(void *adaptationSet);
381  static Accessibility getAccessibilityNode(AampJsonObject &accessNode);
382  /**
383  * @fn GetBestTextTrackByLanguage
384  * @param[out] selectedTextTrack selected representation Index
385  */
386  bool GetBestTextTrackByLanguage( TextTrackInfo &selectedTextTrack);
387  /**
388  * @fn ParseTrackInformation
389  * @param adaptationSet Adaptation Node
390  * @param MediaType type of media
391  * @param[out] aTracks audio tracks
392  * @param[out] tTracks text tracks
393  */
394  void ParseTrackInformation(IAdaptationSet *adaptationSet, uint32_t iAdaptationIndex, MediaType media, std::vector<AudioTrackInfo> &aTracks, std::vector<TextTrackInfo> &tTracks);
395 
396  //Apis for sidecar caption support
397 
398  /**
399  * @fn InitSubtitleParser
400  * @param[in] data - subtitle data from application
401  * @return void
402  */
403  void InitSubtitleParser(char *data) override;
404 
405  /**
406  * @fn ResetSubtitle
407  * @return void
408  */
409  void ResetSubtitle() override;
410 
411  /**
412  * @fn MuteSubtitleOnPause
413  * @return void
414  */
415  void MuteSubtitleOnPause() override;
416 
417  /**
418  * @fn ResumeSubtitleOnPlay
419  * @param[in] mute - mute status
420  * @param[in] data - subtitle data from application
421  * @return void
422  */
423  void ResumeSubtitleOnPlay(bool mute, char *data) override;
424 
425  /**
426  * @fn MuteSidecarSubtitles
427  * @param[in] mute - mute/unmute
428  * @return void
429  */
430  void MuteSidecarSubtitles(bool mute) override;
431 
432  /**
433  * @fn ResumeSubtitleAfterSeek
434  * @param[in] mute - mute status
435  * @param[in] data - subtitle data from application
436  * @return void
437  */
438  void ResumeSubtitleAfterSeek(bool mute, char *data) override;
439  /**
440  * @fn SetTextStyle
441  * @brief Set the text style of the subtitle to the options passed
442  * @param[in] options - reference to the Json string that contains the information
443  * @return - true indicating successful operation in passing options to the parser
444  */
445  bool SetTextStyle(const std::string &options) override;
446 private:
447  /**
448  * @fn printSelectedTrack
449  * @param[in] trackIndex - selected track index
450  * @param[in] media - Media type
451  */
452  void printSelectedTrack(const std::string &trackIndex, MediaType media);
453  /**
454  * @fn AdvanceTrack
455  * @return void
456  */
457  void AdvanceTrack(int trackIdx, bool trickPlay, double delta, bool *waitForFreeFrag, bool *exitFetchLoop, bool *bCacheFullState);
458  /**
459  * @fn FetcherLoop
460  * @return void
461  */
462  void FetcherLoop();
463  /**
464  * @fn GetStreamInfo
465  * @param[in] idx - profile index.
466  */
467  StreamInfo* GetStreamInfo(int idx) override;
468  /**
469  * @fn CheckLLProfileAvailable
470  * @param mpd Pointer to manifest
471  */
472  bool CheckLLProfileAvailable(IMPD *mpd);
473  /**
474  * @fn EnableAndSetLiveOffsetForLLDashPlayback
475  * @param[In] const mpd Pointer to FragmentCollector
476  * @retval AAMPStatusType
477  */
478  AAMPStatusType EnableAndSetLiveOffsetForLLDashPlayback(const MPD* mpd);
479 
480  /**
481  * @fn GetLowLatencyParams
482  * @param[In] const mpd Pointer to FragmentCollector
483  * @param[Out] LLDashData Reference to LowLatency element parsed data
484  * @retval bool true if successfully Parsed Low Latency elements. Else false
485  */
486  bool GetLowLatencyParams(const MPD* mpd,AampLLDashServiceData &LLDashData);
487 
488  /**
489  * @fn ParseMPDLLData
490  * @param[In] mpd Pointer to FragmentCollector
491  * @param[Out] stAampLLDashServiceData Reference to LowLatency element parsed data
492  * @retval bool true if successfully Parsed Low Latency elements. Else false
493  */
494  bool ParseMPDLLData(MPD* mpd, AampLLDashServiceData &stAampLLDashServiceData);
495  /**
496  * @fn UpdateMPD
497  * @param init retrievePlaylistFromCache true to try to get from cache
498  */
499  AAMPStatusType UpdateMPD(bool init = false);
500  /**
501  * @fn FindServerUTCTime
502  * @param mpd: MPD top level element
503  * @param root: XML root node
504  */
505  bool FindServerUTCTime(Node* root);
506  /**
507  * @fn FindTimedMetadata
508  * @param mpd MPD top level element
509  * @param root XML root node
510  * @param init true if this is the first playlist download for a tune/seek/trickplay
511  * @param reportBulkMeta true if bulkTimedMetadata feature is enabled
512  */
513  void FindTimedMetadata(MPD* mpd, Node* root, bool init = false, bool reportBulkMet = false);
514  /**
515  * @fn ProcessPeriodSupplementalProperty
516  * @param node SupplementalProperty node
517  * @param[out] AdID AD Id
518  * @param startMS start time in MS
519  * @param durationMS duration in MS
520  * @param isInit true if its the first playlist download
521  * @param reportBulkMeta true if bulk metadata is enabled
522  */
523  void ProcessPeriodSupplementalProperty(Node* node, std::string& AdID, uint64_t startMS, uint64_t durationMS, bool isInit, bool reportBulkMeta=false);
524  /**
525  * @fn ProcessPeriodAssetIdentifier
526  * @param node AssetIdentifier node
527  * @param startMS start time MS
528  * @param durationMS duration MS
529  * @param AssetID Asset Id
530  * @param ProviderID Provider Id
531  * @param isInit true if its the first playlist download
532  * @param reportBulkMeta true if bulk metadata is enabled
533  */
534  void ProcessPeriodAssetIdentifier(Node* node, uint64_t startMS, uint64_t durationMS, std::string& assetID, std::string& providerID,bool isInit, bool reportBulkMeta=false);
535  /**
536  * @fn ProcessEventStream
537  * @param startMS the start time of the event derived from the (previous) period info (ms)
538  * @param startOffsetMS the start time of the stream derived from the first segment
539  * @param[in] period instance.
540  * @param reportBulkMeta true if bulk metadata is enabled
541  */
542  bool ProcessEventStream(uint64_t startMS, int64_t startOffsetMS, IPeriod * period, bool reportBulkMeta);
543  /**
544  * @fn ProcessStreamRestrictionList
545  * @param node StreamRestrictionListType node
546  * @param AdID Ad Id
547  * @param startMS start time MS
548  * @param isInit true if its the first playlist download
549  * @param reportBulkMeta true if bulk metadata is enabled
550  */
551  void ProcessStreamRestrictionList(Node* node, const std::string& AdID, uint64_t startMS, bool isInit, bool reportBulkMeta);
552  /**
553  * @fn ProcessStreamRestriction
554  * @param node StreamRestriction xml node
555  * @param AdID Ad ID
556  * @param startMS Start time in MS
557  * @param isInit true if its the first playlist download
558  * @param reportBulkMeta true if bulk metadata is enabled
559  */
560  void ProcessStreamRestriction(Node* node, const std::string& AdID, uint64_t startMS, bool isInit, bool reportBulkMeta);
561  /**
562  * @fn ProcessStreamRestrictionExt
563  * @param node Ext child of StreamRestriction xml node
564  * @param AdID Ad ID
565  * @param startMS start time in ms
566  * @param isInit true if its the first playlist download
567  * @param reportBulkMeta true if bulk metadata is enabled
568  */
569  void ProcessStreamRestrictionExt(Node* node, const std::string& AdID, uint64_t startMS, bool isInit, bool reportBulkMeta);
570  /**
571  * @fn ProcessTrickModeRestriction
572  * @param node TrickModeRestriction xml node
573  * @param AdID Ad ID
574  * @param startMS start time in ms
575  * @param isInit true if its the first playlist download
576  * @param reportBulkMeta true if bulk metadata is enabled
577  */
578  void ProcessTrickModeRestriction(Node* node, const std::string& AdID, uint64_t startMS, bool isInit, bool reportBulkMeta);
579  /**
580  * @fn FetchAndInjectInitFragments
581  * @param discontinuity number of tracks and discontinuity true if discontinuous fragment
582  */
583  void FetchAndInjectInitFragments(bool discontinuity = false);
584  /**
585  * @fn FetchAndInjectInitialization
586  * @param trackIdx,discontinuity number of tracks and discontinuity true if discontinuous fragment
587  */
588  void FetchAndInjectInitialization(int trackIdx, bool discontinuity = false);
589  /**
590  * @fn StreamSelection
591  * @param newTune true if this is a new tune
592  */
593  void StreamSelection(bool newTune = false, bool forceSpeedsChangedEvent = false);
594  /**
595  * @fn CheckForInitalClearPeriod
596  */
597  bool CheckForInitalClearPeriod();
598  /**
599  * @fn PushEncryptedHeaders
600  * @return bool
601  */
602  bool PushEncryptedHeaders();
603  /**
604  * @fn GetProfileIdxForBandwidthNotification
605  * @param bandwidth - bandwidth to identify profile index from list
606  */
607  int GetProfileIdxForBandwidthNotification(uint32_t bandwidth);
608  /**
609  * @fn GetCurrentMimeType
610  * @param MediaType type of media
611  * @retval mimeType
612  */
613  std::string GetCurrentMimeType(MediaType mediaType);
614  /**
615  * @fn UpdateTrackInfo
616  */
617  AAMPStatusType UpdateTrackInfo(bool modifyDefaultBW, bool periodChanged, bool resetTimeLineIndex=false);
618  /**
619  * @fn SkipFragments
620  * @param pMediaStreamContext Media track object
621  * @param skipTime time to skip in seconds
622  * @param updateFirstPTS true to update first pts state variable
623  */
624  double SkipFragments( class MediaStreamContext *pMediaStreamContext, double skipTime, bool updateFirstPTS = false, bool skipToEnd = false);
625  /**
626  * @fn SkipToEnd
627  * @param pMediaStreamContext Track object pointer
628  */
629  void SkipToEnd( class MediaStreamContext *pMediaStreamContext); //Added to support rewind in multiperiod assets
630  /**
631  * @fn ProcessContentProtection
632  * @param adaptationSet Adaptation set object
633  * @param mediaType type of track
634  */
635  void ProcessContentProtection(IAdaptationSet * adaptationSet,MediaType mediaType, std::shared_ptr<AampDrmHelper> drmHelper = nullptr);
636  /**
637  * @fn SeekInPeriod
638  * @param seekPositionSeconds seek positon in seconds
639  */
640  void SeekInPeriod( double seekPositionSeconds, bool skipToEnd = false);
641  /**
642  * @fn ApplyLiveOffsetWorkaroundForSAP
643  * @param seekPositionSeconds seek positon in seconds.
644  */
645  void ApplyLiveOffsetWorkaroundForSAP(double seekPositionSeconds);
646  /**
647  * @fn GetCulledSeconds
648  */
649  double GetCulledSeconds();
650  /**
651  * @fn UpdateCulledAndDurationFromPeriodInfo
652  */
653  void UpdateCulledAndDurationFromPeriodInfo();
654  /**
655  * @fn UpdateLanguageList
656  * @return void
657  */
658  void UpdateLanguageList();
659  /**
660  * @fn GetBestAudioTrackByLanguage
661  * @param desiredRepIdx [out] selected representation Index
662  * @param CodecType [out] selected codec type
663  * @param ac4Tracks parsed track from preselection node
664  * @param audioTrackIndex selected audio track index
665  */
666  int GetBestAudioTrackByLanguage(int &desiredRepIdx,AudioType &selectedCodecType, std::vector<AudioTrackInfo> &ac4Tracks, std::string &audioTrackIndex);
667  int GetPreferredAudioTrackByLanguage();
668  /**
669  * @fn CheckProducerReferenceTimeUTCTimeMatch
670  * @param pRT Pointer to ProducerReferenceTime
671  */
672  bool CheckProducerReferenceTimeUTCTimeMatch(IProducerReferenceTime *pRT);
673  /**
674  * @fn PrintProducerReferenceTimeAtrributes
675  * @param pRT Pointer to ProducerReferenceTime
676  */
677  void PrintProducerReferenceTimeAtrributes(IProducerReferenceTime *pRT);
678  /**
679  * @fn GetProducerReferenceTimeForAdaptationSet
680  * @param adaptationSet Pointer to AdaptationSet
681  */
682  IProducerReferenceTime *GetProducerReferenceTimeForAdaptationSet(IAdaptationSet *adaptationSet);
683  /**
684  * @fn GetLanguageForAdaptationSet
685  * @param adaptationSet Pointer to adaptation set
686  * @retval language of adaptation set
687  */
688  std::string GetLanguageForAdaptationSet( IAdaptationSet *adaptationSet );
689  /**
690  * @fn GetMpdFromManfiest
691  * @param manifest buffer pointer
692  * @param mpd MPD object of manifest
693  * @param manifestUrl manifest url
694  * @param init true if this is the first playlist download for a tune/seek/trickplay
695  */
696  AAMPStatusType GetMpdFromManfiest(const GrowableBuffer &manifest, MPD * &mpd, std::string manifestUrl, bool init = false);
697  /**
698  * @fn GetDrmPrefs
699  * @param The UUID for the DRM type
700  */
701  int GetDrmPrefs(const std::string& uuid);
702  /**
703  * @fn GetPreferredDrmUUID
704  */
705  std::string GetPreferredDrmUUID();
706  /**
707  * @fn IsEmptyPeriod
708  * @param period period to check whether it is empty
709  * @param isFogPeriod true if it is fog period
710  * @retval Return true on empty Period
711  */
712  bool IsEmptyPeriod(IPeriod *period, bool isFogPeriod = false);
713  /**
714  * @fn IsEmptyAdaptation
715  * @param Adaptation Adaptationto check whether it is empty
716  * @param isFogPeriod true if it is fog period
717  */
718  bool IsEmptyAdaptation(IAdaptationSet *adaptationSet, bool isFogPeriod);
719  /**
720  * @fn GetAvailableVSSPeriods
721  * @param PeriodIds vector of new Early Available Periods
722  */
723  void GetAvailableVSSPeriods(std::vector<IPeriod*>& PeriodIds);
724  /**
725  * @fn CheckForVssTags
726  */
727  bool CheckForVssTags();
728  /**
729  * @fn GetVssVirtualStreamID
730  */
731  std::string GetVssVirtualStreamID();
732  /**
733  * @fn IsMatchingLanguageAndMimeType
734  * @param[in] type - media type
735  * @param[in] lang - language to be matched
736  * @param[in] adaptationSet - adaptation to be checked for
737  * @param[out] representionIndex - represention within adaptation with matching params
738  */
739  bool IsMatchingLanguageAndMimeType(MediaType type, std::string lang, IAdaptationSet *adaptationSet, int &representationIndex);
740  /**
741  * @fn GetFragmentUrl
742  * @param[out] fragmentUrl fragment url
743  * @param fragmentDescriptor descriptor
744  * @param media media information string
745  */
746  void GetFragmentUrl( std::string& fragmentUrl, const FragmentDescriptor *fragmentDescriptor, std::string media);
747  double GetEncoderDisplayLatency();
748  /**
749  * @fn StartLatencyMonitorThread
750  * @return void
751  */
752  void StartLatencyMonitorThread();
753  LatencyStatus GetLatencyStatus() { return latencyStatus; }
754  /**
755  * @fn GetContentProtection
756  * @param[In] adaptation set and media type
757  */
758  vector<IDescriptor*> GetContentProtection(const IAdaptationSet *adaptationSet, MediaType mediaType);
759  /**
760  * @fn GetPreferredCodecIndex
761  * @param adaptationSet Adaptation set object
762  * @param[out] selectedRepIdx - Selected representation index
763  * @param[out] selectedCodecType type of desired representation
764  * @param[out] selectedRepBandwidth - selected audio track bandwidth
765  * @param disableEC3 whether EC3 deabled by config
766  * @param disableATMOS whether ATMOS audio deabled by config
767  */
768  bool GetPreferredCodecIndex(IAdaptationSet *adaptationSet, int &selectedRepIdx, AudioType &selectedCodecType,
769  uint32_t &selectedRepBandwidth, uint32_t &bestScore, bool disableEC3, bool disableATMOS, bool disableAC4, bool disableAC3, bool &disabled);
770 
771  /**
772  * @brief Get the audio track information from all period
773  * updated member variable mAudioTracksAll
774  * @return void
775  */
776  void PopulateAudioTracks(void);
777 
778  /**
779  * @brief Get the audio track information from all preselection node of the period
780  * @param period Node ans IMPDElement
781  * @return void
782  */
783  void ParseAvailablePreselections(IMPDElement *period, std::vector<AudioTrackInfo> & audioAC4Tracks);
784 
785  /**
786  * @fn PopulateTrackInfo
787  * @param media - Media type
788  * @param - Do need to reset vector?
789  * @retun none
790  */
791  void PopulateTrackInfo(MediaType media, bool reset=false);
792 
793  /**
794  * @fn IsPeriodEncrypted
795  * @param[in] period - current period
796  * @brief check if current period is encrypted
797  * @retval true on success
798  */
799  bool IsPeriodEncrypted(IPeriod *period);
800 
801  std::mutex mStreamLock;
802  CMCDHeaders *pCMCDMetrics;/**<pointer object to class CMCDHeaders*/
803  bool fragmentCollectorThreadStarted;
804  std::set<std::string> mLangList;
805  double seekPosition;
806  float rate;
807  std::thread *fragmentCollectorThreadID;
808  pthread_t createDRMSessionThreadID;
809  std::thread *deferredDRMRequestThread;
810  bool deferredDRMRequestThreadStarted;
811  bool mAbortDeferredLicenseLoop;
812  bool drmSessionThreadStarted;
813  dash::mpd::IMPD *mpd;
814  class MediaStreamContext *mMediaStreamContext[AAMP_TRACK_COUNT];
815  int mNumberOfTracks;
816  int mCurrentPeriodIdx;
817  double mEndPosition;
818  bool mIsLiveStream; /**< Stream is live or not; won't change during runtime. */
819  bool mIsLiveManifest; /**< Current manifest is dynamic or static; may change during runtime. eg: Hot DVR. */
820  StreamInfo* mStreamInfo;
821  bool mUpdateStreamInfo; /**< Indicates mStreamInfo needs to be updated */
822  double mPrevStartTimeSeconds;
823  std::string mPrevLastSegurlMedia;
824  long mPrevLastSegurlOffset; /**< duration offset from beginning of TSB */
825  double mPeriodEndTime;
826  double mPeriodStartTime;
827  double mPeriodDuration;
828  uint64_t mMinUpdateDurationMs;
829  double mTSBDepth;
830  double mPresentationOffsetDelay;
831  uint64_t mLastPlaylistDownloadTimeMs;
832  double mFirstPTS;
833  double mStartTimeOfFirstPTS;
834  double mVideoPosRemainder;
835  double mFirstFragPTS[AAMP_TRACK_COUNT];
836  AudioType mAudioType;
837  int mPrevAdaptationSetCount;
838  std::vector<long> mBitrateIndexVector;
839  // In case of streams with multiple video Adaptation Sets, A profile
840  // is a combination of an Adaptation Set and Representation within
841  // that Adaptation Set. Hence we need a mapping from a profile to
842  // corresponding Adaptation Set and Representation Index
843  std::map<int, struct ProfileInfo> mProfileMaps;
844 
845  bool mIsFogTSB;
846  IPeriod *mCurrentPeriod;
847  std::string mBasePeriodId;
848  double mBasePeriodOffset;
849  class PrivateCDAIObjectMPD *mCdaiObject;
850  std::shared_ptr<AampDrmHelper> mLastDrmHelper;
851  std::vector<std::string> mEarlyAvailablePeriodIds;
852  std::map<std::string, struct EarlyAvailablePeriodInfo> mEarlyAvailableKeyIDMap;
853  std::queue<std::string> mPendingKeyIDs;
854  int mCommonKeyDuration;
855 
856  // DASH does not use abr manager to store the supported bandwidth values,
857  // hence storing max TSB bandwith in this variable which will be used for VideoEnd Metric data via
858  // StreamAbstractionAAMP::GetMaxBitrate function,
859  long mMaxTSBBandwidth;
860 
861  double mLiveEndPosition;
862  double mCulledSeconds;
863  bool mAdPlayingFromCDN; /*Note: TRUE: Ad playing currently & from CDN. FALSE: Ad "maybe playing", but not from CDN.*/
864  double mAvailabilityStartTime;
865  std::map<std::string, int> mDrmPrefs;
866  int mMaxTracks; /* Max number of tracks for this session */
867  double mServerUtcTime;
868  double mDeltaTime;
869  double mHasServerUtcTime;
870  /**
871  * @fn GetPeriodStartTime
872  * @param mpd : pointer manifest
873  * @param periodIndex
874  */
875  double GetPeriodStartTime(IMPD *mpd, int periodIndex);
876  /**
877  * @fn GetPeriodDuration
878  * @param mpd : pointer manifest
879  * @param periodIndex Index of the current period
880  */
881  double GetPeriodDuration(IMPD *mpd, int periodIndex);
882  /**
883  * @fn GetPeriodEndTime
884  * @param mpd : pointer manifest
885  * @param periodIndex Index of the current period
886  * @param mpdRefreshTime : time when manifest was downloade
887  */
888  double GetPeriodEndTime(IMPD *mpd, int periodIndex, uint64_t mpdRefreshTime);
889  /**
890  * @fn isAdbreakStart
891  * @param[in] period instance.
892  * @param[in] startMS start time in milli seconds.
893  * @param[in] eventBreakVec vector of EventBreakInfo structure.
894  */
895  bool isAdbreakStart(IPeriod *period, uint64_t &startMS, std::vector<EventBreakInfo> &eventBreakVec);
896  /**
897  * @fn onAdEvent
898  */
899  bool onAdEvent(AdEvent evt);
900  bool onAdEvent(AdEvent evt, double &adOffset);
901  /**
902  * @fn SetAudioTrackInfo
903  * @param[in] tracks - available audio tracks in period
904  * @param[in] trackIndex - index of current audio track
905  */
906  void SetAudioTrackInfo(const std::vector<AudioTrackInfo> &tracks, const std::string &trackIndex);
907  void SetTextTrackInfo(const std::vector<TextTrackInfo> &tracks, const std::string &trackIndex);
908  /**
909  * @fn FindPeriodGapsAndReport
910  */
911  void FindPeriodGapsAndReport();
912 
913 #ifdef AAMP_MPD_DRM
914  /**
915  * @fn ProcessEAPLicenseRequest
916  */
917  void ProcessEAPLicenseRequest(void);
918  /**
919  * @fn StartDeferredDRMRequestThread
920  * @param mediaType type of track
921  */
922  void StartDeferredDRMRequestThread(MediaType mediaType);
923  /**
924  * @fn ProcessVssContentProtection
925  * @param drmHelper created
926  * @param mediaType type of track
927  */
928  void ProcessVssContentProtection(std::shared_ptr<AampDrmHelper> drmHelper, MediaType mediaType);
929  /**
930  * @fn CreateDrmHelper
931  * @param adaptationSet Adaptation set object
932  * @param mediaType type of track
933  */
934  std::shared_ptr<AampDrmHelper> CreateDrmHelper(IAdaptationSet * adaptationSet,MediaType mediaType);
935 #endif
936  std::vector<StreamInfo*> thumbnailtrack;
937  std::vector<TileInfo> indexedTileInfo;
938  double mFirstPeriodStartTime; /*< First period start time for progress report*/
939 
940  LatencyStatus latencyStatus; /**< Latency status of the playback*/
941  LatencyStatus prevLatencyStatus; /**< Previous latency status of the playback*/
942  bool latencyMonitorThreadStarted; /**< Monitor latency thread status*/
943  pthread_t latencyMonitorThreadID; /**< Fragment injector thread id*/
944  int mProfileCount; /**< Total video profile count*/
945  std::unique_ptr<SubtitleParser> mSubtitleParser; /**< Parser for subtitle data*/
946 };
947 
948 #endif //FRAGMENTCOLLECTOR_MPD_H_
949 /**
950  * @}
951  */
StreamOutputFormat
StreamOutputFormat
Media output format.
Definition: main_aamp.h:106
PrivateCDAIObjectMPD
Private Client Side DAI object for DASH.
Definition: admanager_mpd.h:278
StreamInfo
Structure holding the information of a stream.
Definition: StreamAbstractionAAMP.h:69
aamp_ProcessNode
Node * aamp_ProcessNode(xmlTextReaderPtr *reader, std::string url, bool isAd=false)
Get xml node form reader.
Definition: fragmentcollector_mpd.cpp:2914
ProfileInfo
Manifest file adaptation and representation info.
Definition: fragmentcollector_mpd.h:79
StreamAbstractionAAMP_MPD::latencyMonitorThreadID
pthread_t latencyMonitorThreadID
Definition: fragmentcollector_mpd.h:943
StreamAbstractionAAMP_MPD::mProfileCount
int mProfileCount
Definition: fragmentcollector_mpd.h:944
TuneType
TuneType
Tune Typea.
Definition: priv_aamp.h:190
StreamAbstractionAAMP.h
Base classes of HLS/MPD collectors. Implements common caching/injection logic.
StreamAbstractionAAMP_MPD::pCMCDMetrics
CMCDHeaders * pCMCDMetrics
Definition: fragmentcollector_mpd.h:802
StreamAbstractionAAMP_MPD::mPrevLastSegurlOffset
long mPrevLastSegurlOffset
Definition: fragmentcollector_mpd.h:824
StreamAbstractionAAMP_MPD::latencyStatus
LatencyStatus latencyStatus
Definition: fragmentcollector_mpd.h:940
AdEvent
AdEvent
Events to the Ad manager's state machine.
Definition: admanager_mpd.h:97
admanager_mpd.h
Client side DAI manger for MPEG DASH.
AampLogManager
AampLogManager Class.
Definition: AampLogManager.h:150
MediaTrack
Base Class for Media Track.
Definition: StreamAbstractionAAMP.h:159
StreamAbstractionAAMP
StreamAbstraction class of AAMP.
Definition: StreamAbstractionAAMP.h:577
AampLLDashServiceData
To store Low Latency Service configurtions.
Definition: priv_aamp.h:511
StreamAbstractionAAMP_MPD::mUpdateStreamInfo
bool mUpdateStreamInfo
Definition: fragmentcollector_mpd.h:821
StreamAbstractionAAMP_MPD::prevLatencyStatus
LatencyStatus prevLatencyStatus
Definition: fragmentcollector_mpd.h:941
aamp_GetPeriodStartTimeDeltaRelativeToPTSOffset
double aamp_GetPeriodStartTimeDeltaRelativeToPTSOffset(IPeriod *period)
Get difference between first segment start time and presentation offset from period.
Definition: fragmentcollector_mpd.cpp:3661
LatencyStatus
LatencyStatus
Latency status.
Definition: AampDefine.h:223
StreamAbstractionAAMP_MPD::mIsLiveStream
bool mIsLiveStream
Definition: fragmentcollector_mpd.h:818
TrackType
TrackType
Media Track Types.
Definition: StreamAbstractionAAMP.h:48
MediaType
MediaType
Media types.
Definition: AampMediaType.h:37
StreamAbstractionAAMP_MPD::mIsLiveManifest
bool mIsLiveManifest
Definition: fragmentcollector_mpd.h:819
AampJsonObject.h
File to handle Json format.
AAMP_TRACK_COUNT
#define AAMP_TRACK_COUNT
Definition: priv_aamp.h:67
aamp_getHostFromURL
std::string aamp_getHostFromURL(std::string url)
Extract host string from url.
Definition: AampUtils.cpp:232
StreamAbstractionAAMP_MPD
Fragment collector for MPEG DASH.
Definition: fragmentcollector_mpd.h:175
aamp_GetDurationFromRepresentation
uint64_t aamp_GetDurationFromRepresentation(dash::mpd::IMPD *mpd)
Get duration though representation iteration.
Definition: fragmentcollector_mpd.cpp:4874
MediaStreamContext
MPD media track.
Definition: MediaStreamContext.h:35
AudioType
AudioType
Type of audio ES for MPD.
Definition: priv_aamp.h:271
GrowableBuffer
Structure of GrowableBuffer.
Definition: AampMemoryUtils.h:39
PrivateInstanceAAMP
Class representing the AAMP player's private instance, which is not exposed to outside world.
Definition: priv_aamp.h:640
FragmentDescriptor
Stores information of dash fragment.
Definition: fragmentcollector_mpd.h:89
aamp_GetPeriodDuration
double aamp_GetPeriodDuration(dash::mpd::IMPD *mpd, int periodIndex, uint64_t mpdDownloadTime=0)
Get Period Duration.
Definition: fragmentcollector_mpd.cpp:3966
StreamAbstractionAAMP_MPD::mSubtitleParser
std::unique_ptr< SubtitleParser > mSubtitleParser
Definition: fragmentcollector_mpd.h:945
StreamAbstractionAAMP_MPD::latencyMonitorThreadStarted
bool latencyMonitorThreadStarted
Definition: fragmentcollector_mpd.h:942
AAMPStatusType
AAMPStatusType
AAMP Function return values.
Definition: priv_aamp.h:205
TextTrackInfo
Structure for text track information Holds information about a text track in playlist.
Definition: main_aamp.h:282
CDAIObject
Base class for the client side DAI object.
Definition: AdManagerBase.h:57
Accessibility
Data type to store Accessibility Node data.
Definition: Accessibility.hpp:29
StreamAbstractionAAMP_MPD::SeekPosUpdate
void SeekPosUpdate(double secondsRelativeToTuneTime)
Update seek position when player is initialized.
Definition: fragmentcollector_mpd.h:271
AampJsonObject
Utility class to construct a JSON string.
Definition: AampJsonObject.h:37
aamp_IsAbsoluteURL
bool aamp_IsAbsoluteURL(const std::string &url)
distinguish between absolute and relative urls
Definition: AampUtils.cpp:221