RDK Documentation (Open Sourced RDK Components)
MediaStreamContext.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 2021 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 #ifndef MEDIASTREAMCONTEXT_H
21 #define MEDIASTREAMCONTEXT_H
22 
23 /**
24  * @file MediaStreamContext.h
25  * @brief Handles operations for Media stream context
26  */
27 
28 #include "StreamAbstractionAAMP.h"
29 #include "fragmentcollector_mpd.h"
30 
31 /**
32  * @class MediaStreamContext
33  * @brief MPD media track
34  */
36 {
37 public:
38  /**
39  * @brief MediaStreamContext Constructor
40  * @param type Type of track
41  * @param ctx context MPD collector context
42  * @param aamp Pointer to associated aamp instance
43  * @param name Name of the track
44  */
46  MediaTrack(logObj, type, aamp, name),
47  mediaType((MediaType)type), adaptationSet(NULL), representation(NULL),
48  fragmentIndex(0), timeLineIndex(0), fragmentRepeatCount(0), fragmentOffset(0),
49  eos(false), fragmentTime(0), periodStartOffset(0), timeStampOffset(0), index_ptr(NULL), index_len(0),
50  lastSegmentTime(0), lastSegmentNumber(0), lastSegmentDuration(0), adaptationSetIdx(0), representationIndex(0), profileChanged(true),
51  adaptationSetId(0), fragmentDescriptor(), context(ctx), initialization(""),
52  mDownloadedFragment(), discontinuity(false), mSkipSegmentOnError(true),
53  downloadedDuration(0)//,mCMCDNetworkMetrics{-1,-1,-1}
54  , scaledPTO(0),pCMCDMetrics(NULL)
55  , failAdjacentSegment(false),httpErrorCode(0)
56  {
57  memset(&mDownloadedFragment, 0, sizeof(GrowableBuffer));
58  fragmentDescriptor.bUseMatchingBaseUrl = ISCONFIGSET(eAAMPConfig_MatchBaseUrl);
60  {
61  if(mediaType == eMEDIATYPE_VIDEO)
62  pCMCDMetrics = new VideoCMCDHeaders();
63  else if(mediaType == eMEDIATYPE_AUDIO)
64  pCMCDMetrics = new AudioCMCDHeaders();
65  else if(mediaType == eMEDIATYPE_SUBTITLE)
66  pCMCDMetrics = new SubtitleCMCDHeaders();
67  }
68  }
69 
70  /**
71  * @brief MediaStreamContext Destructor
72  */
74  {
75  aamp_Free(&mDownloadedFragment);
76  delete pCMCDMetrics;
77  }
78 
79  /**
80  * @brief MediaStreamContext Copy Constructor
81  */
82  MediaStreamContext(const MediaStreamContext&) = delete;
83 
84  /**
85  * @brief MediaStreamContext Assignment operator overloading
86  */
88 
89 
90  /**
91  * @brief Get the context of media track. To be implemented by subclasses
92  * @retval Context of track.
93  */
95  {
96  return context;
97  }
98 
99  /**
100  * @fn InjectFragmentInternal
101  *
102  * @param[in] cachedFragment - contains fragment to be processed and injected
103  * @param[out] fragmentDiscarded - true if fragment is discarded.
104  */
105  void InjectFragmentInternal(CachedFragment* cachedFragment, bool &fragmentDiscarded);
106 
107  /**
108  * @fn CacheFragment
109  * @param fragmentUrl url of fragment
110  * @param curlInstance curl instance to be used to fetch
111  * @param position position of fragment in seconds
112  * @param duration duration of fragment in seconds
113  * @param range byte range
114  * @param initSegment true if fragment is init fragment
115  * @param discontinuity true if fragment is discontinuous
116  * @param playingAd flag if playing Ad
117  * @param pto unscaled pto value from mpd
118  * @param scale timeScale value from mpd
119  * @param overWriteTrackId flag to overwrite the trackID of the init fragment with the current one if those are different
120  * @retval true on success
121  */
122  bool CacheFragment(std::string fragmentUrl, unsigned int curlInstance, double position, double duration, const char *range = NULL, bool initSegment = false, bool discontinuity = false, bool playingAd = false, double pto = 0, uint32_t scale = 0, bool overWriteTrackId = false);
123 
124  /**
125  * @fn CacheFragmentChunk
126  * @param actualType MediaType type of cached media
127  * @param ptr CURL provided chunk data
128  * @param size CURL provided chunk data size
129  * @param remoteUrl url of fragment
130  * @param dnldStartTime of the download
131  */
132  bool CacheFragmentChunk(MediaType actualType, char *ptr, size_t size, std::string remoteUrl,long long dnldStartTime);
133 
134  /**
135  * @fn ABRProfileChanged
136  */
137  void ABRProfileChanged(void);
138  /**
139  * @fn GetBufferedDuration
140  */
141  double GetBufferedDuration();
142 
143  /**
144  * @fn SignalTrickModeDiscontinuity
145  * @return void
146  */
148 
149  /**
150  * @fn IsAtEndOfTrack
151  * @return true - If yes
152  */
153  bool IsAtEndOfTrack();
154 
155  MediaType mediaType;
156  CMCDHeaders *pCMCDMetrics;/**<pointer object to class CMCDHeaders*/
157  struct FragmentDescriptor fragmentDescriptor;
158  const IAdaptationSet *adaptationSet;
159  const IRepresentation *representation;
160  int fragmentIndex;
161  int timeLineIndex;
162  int fragmentRepeatCount;
163  uint64_t fragmentOffset;
164  bool eos;
165  bool profileChanged;
166  bool discontinuity;
167  GrowableBuffer mDownloadedFragment;
168 
169  double fragmentTime;
170  double downloadedDuration;
171  double periodStartOffset;
172  uint64_t timeStampOffset;
173  char *index_ptr;
174  size_t index_len;
175  uint64_t lastSegmentTime;
176  uint64_t lastSegmentNumber;
177  uint64_t lastSegmentDuration;
178  int adaptationSetIdx;
179  int representationIndex;
180  StreamAbstractionAAMP_MPD* context;
181  std::string initialization;
182  uint32_t adaptationSetId;
183  bool mSkipSegmentOnError;
184  double scaledPTO;
185  bool failAdjacentSegment;
186  long httpErrorCode;
187 }; // MediaStreamContext
188 
189 #endif /* MEDIASTREAMCONTEXT_H */
190 
aamp_Free
void aamp_Free(void *ptr)
wrapper for g_free, used for segment allocation
Definition: AampMemoryUtils.cpp:56
fragmentcollector_mpd.h
Fragment collector MPEG DASH declarations.
eMEDIATYPE_VIDEO
@ eMEDIATYPE_VIDEO
Definition: AampMediaType.h:39
MediaTrack::cachedFragment
CachedFragment * cachedFragment
Definition: StreamAbstractionAAMP.h:535
StreamAbstractionAAMP.h
Base classes of HLS/MPD collectors. Implements common caching/injection logic.
MediaStreamContext::CacheFragment
bool CacheFragment(std::string fragmentUrl, unsigned int curlInstance, double position, double duration, const char *range=NULL, bool initSegment=false, bool discontinuity=false, bool playingAd=false, double pto=0, uint32_t scale=0, bool overWriteTrackId=false)
Fetch and cache a fragment.
Definition: MediaStreamContext.cpp:55
MediaStreamContext::operator=
MediaStreamContext & operator=(const MediaStreamContext &)=delete
MediaStreamContext Assignment operator overloading.
eAAMPConfig_EnableCMCD
@ eAAMPConfig_EnableCMCD
Definition: AampConfig.h:203
MediaStreamContext::MediaStreamContext
MediaStreamContext(AampLogManager *logObj, TrackType type, StreamAbstractionAAMP_MPD *ctx, PrivateInstanceAAMP *aamp, const char *name)
MediaStreamContext Constructor.
Definition: MediaStreamContext.h:45
MediaTrack::type
TrackType type
Definition: StreamAbstractionAAMP.h:523
ISCONFIGSET
#define ISCONFIGSET(x)
Definition: AampConfig.h:84
MediaStreamContext::CacheFragmentChunk
bool CacheFragmentChunk(MediaType actualType, char *ptr, size_t size, std::string remoteUrl, long long dnldStartTime)
Cache Fragment Chunk.
Definition: MediaStreamContext.cpp:309
AampLogManager
AampLogManager Class.
Definition: AampLogManager.h:150
MediaStreamContext::ABRProfileChanged
void ABRProfileChanged(void)
Listener to ABR profile change.
Definition: MediaStreamContext.cpp:343
MediaStreamContext::GetContext
StreamAbstractionAAMP * GetContext()
Get the context of media track. To be implemented by subclasses.
Definition: MediaStreamContext.h:94
MediaTrack
Base Class for Media Track.
Definition: StreamAbstractionAAMP.h:159
eMEDIATYPE_AUDIO
@ eMEDIATYPE_AUDIO
Definition: AampMediaType.h:40
StreamAbstractionAAMP
StreamAbstraction class of AAMP.
Definition: StreamAbstractionAAMP.h:577
MediaStreamContext::~MediaStreamContext
~MediaStreamContext()
MediaStreamContext Destructor.
Definition: MediaStreamContext.h:73
TrackType
TrackType
Media Track Types.
Definition: StreamAbstractionAAMP.h:48
MediaStreamContext::SignalTrickModeDiscontinuity
void SignalTrickModeDiscontinuity()
Notify discontinuity during trick-mode as PTS re-stamping is done in sink.
Definition: MediaStreamContext.cpp:413
MediaType
MediaType
Media types.
Definition: AampMediaType.h:37
MediaTrack::name
const char * name
Definition: StreamAbstractionAAMP.h:518
MediaStreamContext::pCMCDMetrics
CMCDHeaders * pCMCDMetrics
Definition: MediaStreamContext.h:156
StreamAbstractionAAMP_MPD
Fragment collector for MPEG DASH.
Definition: fragmentcollector_mpd.h:175
MediaStreamContext
MPD media track.
Definition: MediaStreamContext.h:35
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
MediaStreamContext::InjectFragmentInternal
void InjectFragmentInternal(CachedFragment *cachedFragment, bool &fragmentDiscarded)
Receives cached fragment and injects to sink.
Definition: MediaStreamContext.cpp:33
MediaStreamContext::IsAtEndOfTrack
bool IsAtEndOfTrack()
Returns if the end of track reached.
Definition: MediaStreamContext.cpp:422
MediaTrack::aamp
PrivateInstanceAAMP * aamp
Definition: StreamAbstractionAAMP.h:534
CachedFragment
Structure of cached fragment data Holds information about a cached fragment.
Definition: StreamAbstractionAAMP.h:99
eMEDIATYPE_SUBTITLE
@ eMEDIATYPE_SUBTITLE
Definition: AampMediaType.h:41
eAAMPConfig_MatchBaseUrl
@ eAAMPConfig_MatchBaseUrl
Definition: AampConfig.h:157
MediaStreamContext::GetBufferedDuration
double GetBufferedDuration()
Get duration of buffer.
Definition: MediaStreamContext.cpp:392