RDK Documentation (Open Sourced RDK Components)
fragmentcollector_mpd.cpp File Reference

Fragment collector implementation of MPEG DASH. More...

#include "iso639map.h"
#include "fragmentcollector_mpd.h"
#include "MediaStreamContext.h"
#include "AampFnLogger.h"
#include "priv_aamp.h"
#include "AampDRMSessionManager.h"
#include "AampConstants.h"
#include "SubtecFactory.hpp"
#include <stdlib.h>
#include <string.h>
#include "_base64.h"
#include <pthread.h>
#include <signal.h>
#include <assert.h>
#include <unistd.h>
#include <set>
#include <iomanip>
#include <ctime>
#include <inttypes.h>
#include <libxml/xmlreader.h>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <cctype>
#include <regex>
#include "AampCacheHandler.h"
#include "AampUtils.h"
#include "AampRfc.h"
#include <chrono>
Include dependency graph for fragmentcollector_mpd.cpp:

Go to the source code of this file.

Data Structures

class  PeriodElement
 Consists Adaptation Set and representation-specific parts. More...
 
class  SegmentTemplates
 Handles operation and information on segment template from manifest. More...
 
class  HeaderFetchParams
 Holds information regarding initialization fragment. More...
 
class  FragmentDownloadParams
 Holds data of fragment to be downloaded. More...
 
struct  EarlyAvailablePeriodInfo
 Period Information available at early. More...
 

Macros

#define SEGMENT_COUNT_FOR_ABR_CHECK   5
 
#define DEFAULT_INTERVAL_BETWEEN_MPD_UPDATES_MS   3000
 
#define TIMELINE_START_RESET_DIFF   4000000000
 
#define MAX_DELAY_BETWEEN_MPD_UPDATE_MS   (6000)
 
#define MIN_DELAY_BETWEEN_MPD_UPDATE_MS   (500)
 
#define MIN_TSB_BUFFER_DEPTH   6
 
#define VSS_DASH_EARLY_AVAILABLE_PERIOD_PREFIX   "vss-"
 
#define FOG_INSERTED_PERIOD_ID_PREFIX   "FogPeriod"
 
#define INVALID_VOD_DURATION   (0)
 
#define SUPPLEMENTAL_PROPERTY_TAG   "SupplementalProperty"
 
#define SCHEME_ID_URI_EC3_EXT_CODEC   "tag:dolby.com,2018:dash:EC3_ExtensionType:2018"
 
#define EC3_EXT_VALUE_AUDIO_ATMOS   "JOC"
 
#define MEDIATYPE_VIDEO   "video"
 
#define MEDIATYPE_AUDIO   "audio"
 
#define MEDIATYPE_TEXT   "text"
 
#define MEDIATYPE_AUX_AUDIO   "aux-audio"
 
#define MEDIATYPE_IMAGE   "image"
 
#define AAMP_LANGUAGE_SCORE   1000000000UL
 
#define AAMP_SCHEME_ID_SCORE   100000000L
 
#define AAMP_LABEL_SCORE   10000000L
 
#define AAMP_ROLE_SCORE   1000000L
 
#define AAMP_TYPE_SCORE   100000L
 
#define AAMP_CODEC_SCORE   1000L
 
#define MAX_EVENT_STARTIME   (24*60*60*1000)
 
#define PRESELECTION_PROPERTY_TAG   "Preselection"
 
#define ACCESSIBILITY_PROPERTY_TAG   "Accessibility"
 
#define CHANNEL_PROPERTY_TAG   "AudioChannelConfiguration"
 
#define CHANNEL_SCHEME_ID_TAG   "urn:mpeg:mpegB:cicp:ChannelConfiguration"
 
#define ROLE_PROPERTY_TAG   "Role"
 
#define ROLE_SCHEME_ID_TAG   "urn:mpeg:dash:role:2011"
 

Functions

static double ParseISO8601Duration (const char *ptr)
 Parse duration from ISO8601 string. More...
 
static double ComputeFragmentDuration (uint32_t duration, uint32_t timeScale)
 
static bool IsIframeTrack (IAdaptationSet *adaptationSet)
 Check if adaptation set is iframe track. More...
 
static void GetBitrateInfoFromCustomMpd (const IAdaptationSet *adaptationSet, std::vector< Representation * > &representations)
 Extract bitrate info from custom mpd. More...
 
static bool IsCompatibleMimeType (const std::string &mimeType, MediaType mediaType)
 Check if mime type is compatible with media type. More...
 
static bool IsAtmosAudio (const IMPDElement *nodePtr)
 Get Additional tag property value from any child node of MPD. More...
 
static AudioType getCodecType (string &codecValue, const IMPDElement *rep)
 Get codec value from representation level. More...
 
static int GetDesiredCodecIndex (IAdaptationSet *adaptationSet, AudioType &selectedCodecType, uint32_t &selectedRepBandwidth, bool disableEC3, bool disableATMOS, bool disableAC4, bool disableAC3, bool &disabled)
 
static int GetDesiredVideoCodecIndex (IAdaptationSet *adaptationSet)
 Get representation index of desired video codec. More...
 
static const char * getMediaTypeName (MediaType mediaType)
 Return the name corresponding to the Media Type. More...
 
static bool IsContentType (const IAdaptationSet *adaptationSet, MediaType mediaType)
 Check if adaptation set is of a given media type. More...
 
static unsigned int Read32 (const char **pptr)
 read unsigned 32 bit value and update buffer pointer More...
 
static bool ParseSegmentIndexBox (const char *start, size_t size, int segmentIndex, unsigned int *referenced_size, float *referenced_duration, unsigned int *firstOffset)
 Parse segment index box. More...
 
static int replace (std::string &str, const std::string &from, uint64_t toNumber)
 Replace matching token with given number. More...
 
static int replace (std::string &str, const std::string &from, const std::string &toString)
 Replace matching token with given string. More...
 
static AampCurlInstance getCurlInstanceByMediaType (MediaType type)
 Gets a curlInstance index for a given MediaType. More...
 
static void deIndexTileInfo (std::vector< TileInfo > &indexedTileInfo)
 
static void AddAttributesToNode (xmlTextReaderPtr *reader, Node *node)
 Add attriblutes to xml node. More...
 
Node * aamp_ProcessNode (xmlTextReaderPtr *reader, std::string url, bool isAd)
 Get xml node form reader. More...
 
double safeMultiply (const unsigned int first, const unsigned int second)
 
static void ParseXmlNS (const std::string &fullName, std::string &ns, std::string &name)
 Parse XML NS. More...
 
uint64_t GetFirstSegmentStartTime (IPeriod *period)
 GetFirstSegment start time from period. More...
 
uint32_t GetPeriodSegmentTimeScale (IPeriod *period)
 GetPeriod Segment timescale from period. More...
 
double aamp_GetPeriodNewContentDuration (dash::mpd::IMPD *mpd, IPeriod *period, uint64_t &curEndNumber)
 
double aamp_GetPeriodStartTimeDeltaRelativeToPTSOffset (IPeriod *period)
 Get difference between first segment start time and presentation offset from period. More...
 
void ParseCCStreamIDAndLang (std::string input, std::string &id, std::string &lang)
 Parse CC streamID and language from value. More...
 
double aamp_GetPeriodDuration (dash::mpd::IMPD *mpd, int periodIndex, uint64_t mpdDownloadTime)
 Get Period Duration. More...
 
uint64_t aamp_GetDurationFromRepresentation (dash::mpd::IMPD *mpd)
 Get duration though representation iteration. More...
 
static void * TrackDownloader (void *arg)
 Fragment downloader thread. More...
 
static void * FragmentDownloader (void *arg)
 Fragment downloader thread. More...
 
StreamOutputFormat GetSubtitleFormat (std::string mimeType)
 
static void indexThumbnails (dash::mpd::IMPD *mpd, int thumbIndexValue, std::vector< TileInfo > &indexedTileInfo, std::vector< StreamInfo * > &thumbnailtrack)
 
static int getChannel (INode *nodePtr)
 Get the cannel number from preselection node. More...
 
static std::string getRole (INode *nodePtr)
 
static void * LatencyMonitor (void *arg)
 Latency monitor thread. More...
 

yes

Fragment collector implementation of MPEG DASH.

Definition in file fragmentcollector_mpd.cpp.


Data Structure Documentation

◆ FragmentDownloadParams

class FragmentDownloadParams

Holds data of fragment to be downloaded.

Definition at line 262 of file fragmentcollector_mpd.cpp.

Collaboration diagram for FragmentDownloadParams:
Collaboration graph
Data Fields
class StreamAbstractionAAMP_MPD * context
class MediaStreamContext * pMediaStreamContext
bool playingLastPeriod
long long lastPlaylistUpdateMS

Macro Definition Documentation

◆ SUPPLEMENTAL_PROPERTY_TAG

#define SUPPLEMENTAL_PROPERTY_TAG   "SupplementalProperty"

Macros for extended audio codec check as per ETSI-TS-103-420-V1.2.1

Definition at line 76 of file fragmentcollector_mpd.cpp.

◆ AAMP_LANGUAGE_SCORE

#define AAMP_LANGUAGE_SCORE   1000000000UL

Top priority: matching language

Definition at line 87 of file fragmentcollector_mpd.cpp.

◆ AAMP_SCHEME_ID_SCORE

#define AAMP_SCHEME_ID_SCORE   100000000L

2nd priority to scheme id matching

Definition at line 88 of file fragmentcollector_mpd.cpp.

◆ AAMP_LABEL_SCORE

#define AAMP_LABEL_SCORE   10000000L

3rd priority to label matching

Definition at line 89 of file fragmentcollector_mpd.cpp.

◆ AAMP_ROLE_SCORE

#define AAMP_ROLE_SCORE   1000000L

4th priority to role/rendition matching

Definition at line 90 of file fragmentcollector_mpd.cpp.

◆ AAMP_TYPE_SCORE

#define AAMP_TYPE_SCORE   100000L

5th priority to type matching

Definition at line 91 of file fragmentcollector_mpd.cpp.

◆ AAMP_CODEC_SCORE

#define AAMP_CODEC_SCORE   1000L

Lowest priority: matchng codec

Definition at line 92 of file fragmentcollector_mpd.cpp.

◆ PRESELECTION_PROPERTY_TAG

#define PRESELECTION_PROPERTY_TAG   "Preselection"

TBD : Move to Dash Utils

Definition at line 11265 of file fragmentcollector_mpd.cpp.

Function Documentation

◆ ParseISO8601Duration()

static double ParseISO8601Duration ( const char *  ptr)
static

Parse duration from ISO8601 string.

Parameters
ptrISO8601 string
Returns
durationMs duration in milliseconds

Definition at line 3012 of file fragmentcollector_mpd.cpp.

◆ IsIframeTrack()

static bool IsIframeTrack ( IAdaptationSet *  adaptationSet)
static

Check if adaptation set is iframe track.

Parameters
adaptationSetPointer to adaptainSet
Return values
trueif iframe track

Definition at line 6141 of file fragmentcollector_mpd.cpp.

◆ GetBitrateInfoFromCustomMpd()

static void GetBitrateInfoFromCustomMpd ( const IAdaptationSet *  adaptationSet,
std::vector< Representation * > &  representations 
)
static

Extract bitrate info from custom mpd.

Note
Caller function should delete the vector elements after use.
Parameters
adaptationSet: AdaptaionSet from which bitrate info is to be extracted
[out]representations: Representation vector gets updated with Available bit rates.

Definition at line 7364 of file fragmentcollector_mpd.cpp.

◆ IsCompatibleMimeType()

static bool IsCompatibleMimeType ( const std::string &  mimeType,
MediaType  mediaType 
)
static

Check if mime type is compatible with media type.

Parameters
mimeTypemime type
mediaTypemedia type
Return values
trueif compatible

Definition at line 401 of file fragmentcollector_mpd.cpp.

◆ IsAtmosAudio()

static bool IsAtmosAudio ( const IMPDElement *  nodePtr)
static

Get Additional tag property value from any child node of MPD.

Parameters
nodePtrPointer to MPD child node, Tage Name , Property Name, SchemeIdUri (if the propery mapped against scheme Id , default value is empty)
Return values
returnthe property name if found, if not found return empty string

Definition at line 440 of file fragmentcollector_mpd.cpp.

◆ getCodecType()

static AudioType getCodecType ( string &  codecValue,
const IMPDElement *  rep 
)
static

Get codec value from representation level.

Parameters
[out]codecValue- string value of codec as per manifest
[in]rep- representation node for atmos audio check
Return values
audiotype as per aamp code from string value

Definition at line 485 of file fragmentcollector_mpd.cpp.

◆ GetDesiredVideoCodecIndex()

static int GetDesiredVideoCodecIndex ( IAdaptationSet *  adaptationSet)
static

Get representation index of desired video codec.

Parameters
adaptationSetAdaptation set object
[out]selectedRepIdxindex of desired representation
Return values
indexof desired representation

Definition at line 710 of file fragmentcollector_mpd.cpp.

◆ getMediaTypeName()

static const char* getMediaTypeName ( MediaType  mediaType)
static

Return the name corresponding to the Media Type.

Parameters
mediaTypemedia type
Return values
thename of the mediaType

Definition at line 739 of file fragmentcollector_mpd.cpp.

◆ IsContentType()

static bool IsContentType ( const IAdaptationSet *  adaptationSet,
MediaType  mediaType 
)
static

Check if adaptation set is of a given media type.

Parameters
adaptationSetadaptation set
mediaTypemedia type
Return values
trueif adaptation set is of the given media type

Definition at line 765 of file fragmentcollector_mpd.cpp.

◆ Read32()

static unsigned int Read32 ( const char **  pptr)
static

read unsigned 32 bit value and update buffer pointer

Parameters
[in]pptrbuffer
Return values
32bit value

Definition at line 819 of file fragmentcollector_mpd.cpp.

◆ ParseSegmentIndexBox()

static bool ParseSegmentIndexBox ( const char *  start,
size_t  size,
int  segmentIndex,
unsigned int *  referenced_size,
float *  referenced_duration,
unsigned int *  firstOffset 
)
static

Parse segment index box.

Note
The SegmentBase indexRange attribute points to Segment Index Box location with segments and random access points.
Parameters
startstart of box
sizesize of box
segmentIndexsegment index
[out]referenced_sizereferenced size
[out]referenced_durationreferenced duration
Return values
trueon success

Definition at line 843 of file fragmentcollector_mpd.cpp.

◆ replace() [1/2]

static int replace ( std::string &  str,
const std::string &  from,
uint64_t  toNumber 
)
static

Replace matching token with given number.

Parameters
strString in which operation to be performed
fromtoken
toNumbernumber to replace token
Return values
position

Definition at line 906 of file fragmentcollector_mpd.cpp.

◆ replace() [2/2]

static int replace ( std::string &  str,
const std::string &  from,
const std::string &  toString 
)
static

Replace matching token with given string.

Parameters
strString in which operation to be performed
fromtoken
toStringstring to replace token
Return values
position

Definition at line 985 of file fragmentcollector_mpd.cpp.

◆ getCurlInstanceByMediaType()

static AampCurlInstance getCurlInstanceByMediaType ( MediaType  type)
static

Gets a curlInstance index for a given MediaType.

Parameters
typethe stream MediaType
Return values
AampCurlInstanceindex to curl_easy_perform session

Definition at line 1095 of file fragmentcollector_mpd.cpp.

◆ AddAttributesToNode()

static void AddAttributesToNode ( xmlTextReaderPtr *  reader,
Node *  node 
)
static

Add attriblutes to xml node.

Parameters
readerxmlTextReaderPtr
nodexml Node

Definition at line 2814 of file fragmentcollector_mpd.cpp.

◆ aamp_ProcessNode()

Node* aamp_ProcessNode ( xmlTextReaderPtr *  reader,
std::string  url,
bool  isAd 
)

Get xml node form reader.

Return values
xmlnode

Definition at line 2914 of file fragmentcollector_mpd.cpp.

◆ ParseXmlNS()

static void ParseXmlNS ( const std::string &  fullName,
std::string &  ns,
std::string &  name 
)
static

Parse XML NS.

Parameters
fullNamefull name of node
[out]nsnamespace
[out]namename after :

Definition at line 3115 of file fragmentcollector_mpd.cpp.

◆ GetFirstSegmentStartTime()

uint64_t GetFirstSegmentStartTime ( IPeriod *  period)

GetFirstSegment start time from period.

Parameters
period
Return values
starttime

Definition at line 3498 of file fragmentcollector_mpd.cpp.

◆ GetPeriodSegmentTimeScale()

uint32_t GetPeriodSegmentTimeScale ( IPeriod *  period)

GetPeriod Segment timescale from period.

Parameters
periodSegment period
Return values
timescale

Definition at line 3541 of file fragmentcollector_mpd.cpp.

◆ aamp_GetPeriodStartTimeDeltaRelativeToPTSOffset()

double aamp_GetPeriodStartTimeDeltaRelativeToPTSOffset ( IPeriod *  period)

Get difference between first segment start time and presentation offset from period.

Return values
starttime delta in seconds

Definition at line 3661 of file fragmentcollector_mpd.cpp.

◆ ParseCCStreamIDAndLang()

void ParseCCStreamIDAndLang ( std::string  input,
std::string &  id,
std::string &  lang 
)

Parse CC streamID and language from value.

Parameters
[in]input- input value
[out]id- stream ID value
[out]lang- language value
Returns
void

Definition at line 3725 of file fragmentcollector_mpd.cpp.

◆ aamp_GetPeriodDuration()

double aamp_GetPeriodDuration ( dash::mpd::IMPD *  mpd,
int  periodIndex,
uint64_t  mpdDownloadTime 
)

Get Period Duration.

Return values
periodduration in milli seconds

Definition at line 3966 of file fragmentcollector_mpd.cpp.

◆ aamp_GetDurationFromRepresentation()

uint64_t aamp_GetDurationFromRepresentation ( dash::mpd::IMPD *  mpd)

Get duration though representation iteration.

Return values
durationin milliseconds

Definition at line 4874 of file fragmentcollector_mpd.cpp.

◆ TrackDownloader()

static void* TrackDownloader ( void *  arg)
static

Fragment downloader thread.

Parameters
argHeaderFetchParams pointer

Definition at line 6066 of file fragmentcollector_mpd.cpp.

◆ FragmentDownloader()

static void* FragmentDownloader ( void *  arg)
static

Fragment downloader thread.

Parameters
argPointer to FragmentDownloadParams object
Return values
NULL

Definition at line 6095 of file fragmentcollector_mpd.cpp.

◆ getChannel()

static int getChannel ( INode *  nodePtr)
static

Get the cannel number from preselection node.

TBD : Move to Dash Utils

Parameters
preselectionndoe as nodePtr
Returns
channel number

Definition at line 11280 of file fragmentcollector_mpd.cpp.

◆ LatencyMonitor()

static void* LatencyMonitor ( void *  arg)
static

Latency monitor thread.

Parameters
argPointer to FragmentCollector
Return values
NULL

Definition at line 11785 of file fragmentcollector_mpd.cpp.