This repository has been archived by the owner on Jan 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
MediaStreamContext.h
190 lines (171 loc) · 6.28 KB
/
MediaStreamContext.h
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
/*
* If not stated otherwise in this file or this component's license file the
* following copyright and licenses apply:
*
* Copyright 2021 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.
*/
#ifndef MEDIASTREAMCONTEXT_H
#define MEDIASTREAMCONTEXT_H
/**
* @file MediaStreamContext.h
* @brief Handles operations for Media stream context
*/
#include "StreamAbstractionAAMP.h"
#include "fragmentcollector_mpd.h"
/**
* @class MediaStreamContext
* @brief MPD media track
*/
class MediaStreamContext : public MediaTrack
{
public:
/**
* @brief MediaStreamContext Constructor
* @param type Type of track
* @param ctx context MPD collector context
* @param aamp Pointer to associated aamp instance
* @param name Name of the track
*/
MediaStreamContext(AampLogManager *logObj, TrackType type, StreamAbstractionAAMP_MPD* ctx, PrivateInstanceAAMP* aamp, const char* name) :
MediaTrack(logObj, type, aamp, name),
mediaType((MediaType)type), adaptationSet(NULL), representation(NULL),
fragmentIndex(0), timeLineIndex(0), fragmentRepeatCount(0), fragmentOffset(0),
eos(false), fragmentTime(0), periodStartOffset(0), timeStampOffset(0), index_ptr(NULL), index_len(0),
lastSegmentTime(0), lastSegmentNumber(0), lastSegmentDuration(0), adaptationSetIdx(0), representationIndex(0), profileChanged(true),
adaptationSetId(0), fragmentDescriptor(), context(ctx), initialization(""),
mDownloadedFragment(), discontinuity(false), mSkipSegmentOnError(true),
downloadedDuration(0)//,mCMCDNetworkMetrics{-1,-1,-1}
, scaledPTO(0),pCMCDMetrics(NULL)
, failAdjacentSegment(false),httpErrorCode(0)
{
memset(&mDownloadedFragment, 0, sizeof(GrowableBuffer));
fragmentDescriptor.bUseMatchingBaseUrl = ISCONFIGSET(eAAMPConfig_MatchBaseUrl);
if(ISCONFIGSET(eAAMPConfig_EnableCMCD))
{
if(mediaType == eMEDIATYPE_VIDEO)
pCMCDMetrics = new VideoCMCDHeaders();
else if(mediaType == eMEDIATYPE_AUDIO)
pCMCDMetrics = new AudioCMCDHeaders();
else if(mediaType == eMEDIATYPE_SUBTITLE)
pCMCDMetrics = new SubtitleCMCDHeaders();
}
}
/**
* @brief MediaStreamContext Destructor
*/
~MediaStreamContext()
{
aamp_Free(&mDownloadedFragment);
delete pCMCDMetrics;
}
/**
* @brief MediaStreamContext Copy Constructor
*/
MediaStreamContext(const MediaStreamContext&) = delete;
/**
* @brief MediaStreamContext Assignment operator overloading
*/
MediaStreamContext& operator=(const MediaStreamContext&) = delete;
/**
* @brief Get the context of media track. To be implemented by subclasses
* @retval Context of track.
*/
StreamAbstractionAAMP* GetContext()
{
return context;
}
/**
* @fn InjectFragmentInternal
*
* @param[in] cachedFragment - contains fragment to be processed and injected
* @param[out] fragmentDiscarded - true if fragment is discarded.
*/
void InjectFragmentInternal(CachedFragment* cachedFragment, bool &fragmentDiscarded);
/**
* @fn CacheFragment
* @param fragmentUrl url of fragment
* @param curlInstance curl instance to be used to fetch
* @param position position of fragment in seconds
* @param duration duration of fragment in seconds
* @param range byte range
* @param initSegment true if fragment is init fragment
* @param discontinuity true if fragment is discontinuous
* @param playingAd flag if playing Ad
* @param pto unscaled pto value from mpd
* @param scale timeScale value from mpd
* @param overWriteTrackId flag to overwrite the trackID of the init fragment with the current one if those are different
* @retval true on success
*/
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);
/**
* @fn CacheFragmentChunk
* @param actualType MediaType type of cached media
* @param ptr CURL provided chunk data
* @param size CURL provided chunk data size
* @param remoteUrl url of fragment
* @param dnldStartTime of the download
*/
bool CacheFragmentChunk(MediaType actualType, char *ptr, size_t size, std::string remoteUrl,long long dnldStartTime);
/**
* @fn ABRProfileChanged
*/
void ABRProfileChanged(void);
/**
* @fn GetBufferedDuration
*/
double GetBufferedDuration();
/**
* @fn SignalTrickModeDiscontinuity
* @return void
*/
void SignalTrickModeDiscontinuity();
/**
* @fn IsAtEndOfTrack
* @return true - If yes
*/
bool IsAtEndOfTrack();
MediaType mediaType;
CMCDHeaders *pCMCDMetrics;/**<pointer object to class CMCDHeaders*/
struct FragmentDescriptor fragmentDescriptor;
const IAdaptationSet *adaptationSet;
const IRepresentation *representation;
int fragmentIndex;
int timeLineIndex;
int fragmentRepeatCount;
uint64_t fragmentOffset;
bool eos;
bool profileChanged;
bool discontinuity;
GrowableBuffer mDownloadedFragment;
double fragmentTime;
double downloadedDuration;
double periodStartOffset;
uint64_t timeStampOffset;
char *index_ptr;
size_t index_len;
uint64_t lastSegmentTime;
uint64_t lastSegmentNumber;
uint64_t lastSegmentDuration;
int adaptationSetIdx;
int representationIndex;
StreamAbstractionAAMP_MPD* context;
std::string initialization;
uint32_t adaptationSetId;
bool mSkipSegmentOnError;
double scaledPTO;
bool failAdjacentSegment;
long httpErrorCode;
}; // MediaStreamContext
#endif /* MEDIASTREAMCONTEXT_H */