25 #ifndef FRAGMENTCOLLECTOR_MPD_H_
26 #define FRAGMENTCOLLECTOR_MPD_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>
45 using namespace dash::mpd;
46 using namespace dash::xml;
47 using namespace dash::helpers;
48 #define MAX_MANIFEST_DOWNLOAD_RETRY_MPD 2
51 double aamp_GetPeriodNewContentDuration(dash::mpd::IMPD *mpd, IPeriod * period, uint64_t &curEndNumber);
68 Node*
aamp_ProcessNode(xmlTextReaderPtr *reader, std::string url,
bool isAd =
false);
81 int adaptationSetIndex;
82 int representationIndex;
92 std::string matchingBaseURL;
94 std::string manifestUrl;
96 std::string RepresentationID;
99 bool bUseMatchingBaseUrl;
101 FragmentDescriptor() : manifestUrl(
""), Bandwidth(0), Number(0), Time(0), RepresentationID(
""),matchingBaseURL(
""),bUseMatchingBaseUrl(
false)
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)
111 manifestUrl = p.manifestUrl;
112 RepresentationID.assign(p.RepresentationID);
113 Bandwidth = p.Bandwidth;
116 matchingBaseURL = p.matchingBaseURL;
119 std::string GetMatchingBaseUrl()
const
121 return matchingBaseURL;
124 void ClearMatchingBaseUrl()
126 matchingBaseURL.clear();
128 void AppendMatchingBaseUrl(
const std::vector<IBaseUrl *>*baseUrls )
130 if( baseUrls && baseUrls->size()>0 )
132 const std::string &url = baseUrls->at(0)->GetUrl();
138 if(bUseMatchingBaseUrl)
141 for (
auto & item : *baseUrls) {
142 std::string itemUrl = item->GetUrl();
144 if(0 == prefHost.compare(host))
146 matchingBaseURL = item->GetUrl();
151 matchingBaseURL = url;
153 else if( url.rfind(
"/",0)==0 )
156 matchingBaseURL += url;
157 AAMPLOG_WARN(
"baseURL with leading /" );
161 if( !matchingBaseURL.empty() && matchingBaseURL.back() !=
'/' )
163 matchingBaseURL +=
"/";
165 matchingBaseURL += url;
202 void DumpProfiles(
void)
override;
207 void Start()
override;
212 void Stop(
bool clearChannelData)
override;
229 double GetStreamPosition()
override;
238 double GetFirstPTS()
override;
242 double GetStartTimeOfFirstPTS()
override;
247 int GetBWIndex(
long bitrate)
override;
251 std::vector<long> GetVideoBitrates(
void)
override;
255 std::vector<long> GetAudioBitrates(
void)
override;
259 long GetMaxBitrate(
void)
override;
264 void StopInjection(
void)
override;
269 void StartInjection(
void)
override;
270 double GetBufferedDuration();
271 void SeekPosUpdate(
double secondsRelativeToTuneTime) {seekPosition = secondsRelativeToTuneTime; }
272 virtual void SetCDAIObject(
CDAIObject *cdaiObj)
override;
278 virtual std::vector<AudioTrackInfo> & GetAvailableAudioTracks(
bool allTrack=
false)
override;
283 virtual std::vector<TextTrackInfo>& GetAvailableTextTracks(
bool allTrack=
false)
override;
292 virtual bool Is4KStream(
int &height,
long &bandwidth)
override;
299 int GetProfileCount();
304 int GetProfileIndexForBandwidth(
long mTsbBandwidth);
308 std::vector<StreamInfo*> GetAvailableThumbnailTracks(
void)
override;
312 std::vector<StreamInfo*> GetAvailableVideoTracks(
void)
override;
317 bool SetThumbnailTrack(
int)
override;
328 std::vector<ThumbnailData> GetThumbnailRangeData(
double,
double, std::string*,
int*,
int*,
int*,
int*)
override;
335 const IAdaptationSet* GetAdaptationSetAtIndex(
int idx);
340 struct ProfileInfo GetAdaptationSetAndRepresetationIndicesForProfile(int profileIndex);
341 int64_t GetMinUpdateDuration() {
return mMinUpdateDurationMs;}
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);
359 bool PushNextFragment(
class MediaStreamContext *pMediaStreamContext,
unsigned int curlInstance);
363 double GetFirstPeriodStartTime(
void);
364 void MonitorLatency();
365 void StartSubtitleParser()
override;
366 void PauseSubtitleParser(
bool pause)
override;
370 uint32_t GetCurrPeriodTimeScale();
371 dash::mpd::IMPD *GetMPD(
void );
372 IPeriod *GetPeriod(
void );
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);
386 bool GetBestTextTrackByLanguage(
TextTrackInfo &selectedTextTrack);
394 void ParseTrackInformation(IAdaptationSet *adaptationSet, uint32_t iAdaptationIndex,
MediaType media, std::vector<AudioTrackInfo> &aTracks, std::vector<TextTrackInfo> &tTracks);
403 void InitSubtitleParser(
char *data)
override;
409 void ResetSubtitle()
override;
415 void MuteSubtitleOnPause()
override;
423 void ResumeSubtitleOnPlay(
bool mute,
char *data)
override;
430 void MuteSidecarSubtitles(
bool mute)
override;
438 void ResumeSubtitleAfterSeek(
bool mute,
char *data)
override;
445 bool SetTextStyle(
const std::string &options)
override;
452 void printSelectedTrack(
const std::string &trackIndex,
MediaType media);
457 void AdvanceTrack(
int trackIdx,
bool trickPlay,
double delta,
bool *waitForFreeFrag,
bool *exitFetchLoop,
bool *bCacheFullState);
472 bool CheckLLProfileAvailable(IMPD *mpd);
478 AAMPStatusType EnableAndSetLiveOffsetForLLDashPlayback(
const MPD* mpd);
505 bool FindServerUTCTime(Node* root);
513 void FindTimedMetadata(MPD* mpd, Node* root,
bool init =
false,
bool reportBulkMet =
false);
523 void ProcessPeriodSupplementalProperty(Node* node, std::string& AdID, uint64_t startMS, uint64_t durationMS,
bool isInit,
bool reportBulkMeta=
false);
534 void ProcessPeriodAssetIdentifier(Node* node, uint64_t startMS, uint64_t durationMS, std::string& assetID, std::string& providerID,
bool isInit,
bool reportBulkMeta=
false);
542 bool ProcessEventStream(uint64_t startMS, int64_t startOffsetMS, IPeriod * period,
bool reportBulkMeta);
551 void ProcessStreamRestrictionList(Node* node,
const std::string& AdID, uint64_t startMS,
bool isInit,
bool reportBulkMeta);
560 void ProcessStreamRestriction(Node* node,
const std::string& AdID, uint64_t startMS,
bool isInit,
bool reportBulkMeta);
569 void ProcessStreamRestrictionExt(Node* node,
const std::string& AdID, uint64_t startMS,
bool isInit,
bool reportBulkMeta);
578 void ProcessTrickModeRestriction(Node* node,
const std::string& AdID, uint64_t startMS,
bool isInit,
bool reportBulkMeta);
583 void FetchAndInjectInitFragments(
bool discontinuity =
false);
588 void FetchAndInjectInitialization(
int trackIdx,
bool discontinuity =
false);
593 void StreamSelection(
bool newTune =
false,
bool forceSpeedsChangedEvent =
false);
597 bool CheckForInitalClearPeriod();
602 bool PushEncryptedHeaders();
607 int GetProfileIdxForBandwidthNotification(uint32_t bandwidth);
613 std::string GetCurrentMimeType(
MediaType mediaType);
617 AAMPStatusType UpdateTrackInfo(
bool modifyDefaultBW,
bool periodChanged,
bool resetTimeLineIndex=
false);
624 double SkipFragments(
class MediaStreamContext *pMediaStreamContext,
double skipTime,
bool updateFirstPTS =
false,
bool skipToEnd =
false);
635 void ProcessContentProtection(IAdaptationSet * adaptationSet,
MediaType mediaType, std::shared_ptr<AampDrmHelper> drmHelper =
nullptr);
640 void SeekInPeriod(
double seekPositionSeconds,
bool skipToEnd =
false);
645 void ApplyLiveOffsetWorkaroundForSAP(
double seekPositionSeconds);
649 double GetCulledSeconds();
653 void UpdateCulledAndDurationFromPeriodInfo();
658 void UpdateLanguageList();
666 int GetBestAudioTrackByLanguage(
int &desiredRepIdx,
AudioType &selectedCodecType, std::vector<AudioTrackInfo> &ac4Tracks, std::string &audioTrackIndex);
667 int GetPreferredAudioTrackByLanguage();
672 bool CheckProducerReferenceTimeUTCTimeMatch(IProducerReferenceTime *pRT);
677 void PrintProducerReferenceTimeAtrributes(IProducerReferenceTime *pRT);
682 IProducerReferenceTime *GetProducerReferenceTimeForAdaptationSet(IAdaptationSet *adaptationSet);
688 std::string GetLanguageForAdaptationSet( IAdaptationSet *adaptationSet );
701 int GetDrmPrefs(
const std::string& uuid);
705 std::string GetPreferredDrmUUID();
712 bool IsEmptyPeriod(IPeriod *period,
bool isFogPeriod =
false);
718 bool IsEmptyAdaptation(IAdaptationSet *adaptationSet,
bool isFogPeriod);
723 void GetAvailableVSSPeriods(std::vector<IPeriod*>& PeriodIds);
727 bool CheckForVssTags();
731 std::string GetVssVirtualStreamID();
739 bool IsMatchingLanguageAndMimeType(
MediaType type, std::string lang, IAdaptationSet *adaptationSet,
int &representationIndex);
746 void GetFragmentUrl( std::string& fragmentUrl,
const FragmentDescriptor *fragmentDescriptor, std::string media);
747 double GetEncoderDisplayLatency();
752 void StartLatencyMonitorThread();
758 vector<IDescriptor*> GetContentProtection(
const IAdaptationSet *adaptationSet,
MediaType mediaType);
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);
776 void PopulateAudioTracks(
void);
783 void ParseAvailablePreselections(IMPDElement *period, std::vector<AudioTrackInfo> & audioAC4Tracks);
791 void PopulateTrackInfo(
MediaType media,
bool reset=
false);
799 bool IsPeriodEncrypted(IPeriod *period);
801 std::mutex mStreamLock;
803 bool fragmentCollectorThreadStarted;
804 std::set<std::string> mLangList;
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;
816 int mCurrentPeriodIdx;
822 double mPrevStartTimeSeconds;
823 std::string mPrevLastSegurlMedia;
825 double mPeriodEndTime;
826 double mPeriodStartTime;
827 double mPeriodDuration;
828 uint64_t mMinUpdateDurationMs;
830 double mPresentationOffsetDelay;
831 uint64_t mLastPlaylistDownloadTimeMs;
833 double mStartTimeOfFirstPTS;
834 double mVideoPosRemainder;
837 int mPrevAdaptationSetCount;
838 std::vector<long> mBitrateIndexVector;
843 std::map<int, struct ProfileInfo> mProfileMaps;
846 IPeriod *mCurrentPeriod;
847 std::string mBasePeriodId;
848 double mBasePeriodOffset;
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;
859 long mMaxTSBBandwidth;
861 double mLiveEndPosition;
862 double mCulledSeconds;
863 bool mAdPlayingFromCDN;
864 double mAvailabilityStartTime;
865 std::map<std::string, int> mDrmPrefs;
867 double mServerUtcTime;
869 double mHasServerUtcTime;
875 double GetPeriodStartTime(IMPD *mpd,
int periodIndex);
881 double GetPeriodDuration(IMPD *mpd,
int periodIndex);
888 double GetPeriodEndTime(IMPD *mpd,
int periodIndex, uint64_t mpdRefreshTime);
895 bool isAdbreakStart(IPeriod *period, uint64_t &startMS, std::vector<EventBreakInfo> &eventBreakVec);
900 bool onAdEvent(
AdEvent evt,
double &adOffset);
906 void SetAudioTrackInfo(
const std::vector<AudioTrackInfo> &tracks,
const std::string &trackIndex);
907 void SetTextTrackInfo(
const std::vector<TextTrackInfo> &tracks,
const std::string &trackIndex);
911 void FindPeriodGapsAndReport();
917 void ProcessEAPLicenseRequest(
void);
922 void StartDeferredDRMRequestThread(
MediaType mediaType);
928 void ProcessVssContentProtection(std::shared_ptr<AampDrmHelper> drmHelper,
MediaType mediaType);
934 std::shared_ptr<AampDrmHelper> CreateDrmHelper(IAdaptationSet * adaptationSet,
MediaType mediaType);
936 std::vector<StreamInfo*> thumbnailtrack;
937 std::vector<TileInfo> indexedTileInfo;
938 double mFirstPeriodStartTime;
948 #endif //FRAGMENTCOLLECTOR_MPD_H_