2 * BaseRepresentation.cpp
3 *****************************************************************************
4 * Copyright (C) 2010 - 2011 Klagenfurt University
6 * Created on: Aug 10, 2010
7 * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
8 * Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published
12 * by the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
30 #include "BaseRepresentation.h"
31 #include "BaseAdaptationSet.h"
32 #include "BasePlaylist.hpp"
33 #include "SegmentTemplate.h"
34 #include "SegmentTimeline.h"
35 #include "SegmentList.h"
36 #include "SegmentBase.h"
38 #include "../tools/Helper.h"
42 using namespace adaptive
;
43 using namespace adaptive::playlist
;
45 BaseRepresentation::BaseRepresentation( BaseAdaptationSet
*set
) :
46 SegmentInformation( set
),
47 adaptationSet ( set
),
53 BaseRepresentation::~BaseRepresentation ()
57 StreamFormat
BaseRepresentation::getStreamFormat() const
59 return StreamFormat();
62 BaseAdaptationSet
* BaseRepresentation::getAdaptationSet()
67 uint64_t BaseRepresentation::getBandwidth () const
72 void BaseRepresentation::setBandwidth( uint64_t bandwidth
)
74 this->bandwidth
= bandwidth
;
77 const std::list
<std::string
> & BaseRepresentation::getCodecs() const
82 void BaseRepresentation::addCodecs(const std::string
&s
)
84 std::list
<std::string
> list
= Helper::tokenize(s
, ',');
85 std::list
<std::string
>::const_iterator it
;
86 for(it
=list
.begin(); it
!=list
.end(); ++it
)
87 codecs
.push_back(*it
);
90 void BaseRepresentation::getCodecsDesc(CodecDescriptionList
*desc
) const
92 std::list
<std::string
> codecs
= getCodecs();
95 const StreamFormat format
= getStreamFormat();
98 case StreamFormat::TTML
:
99 codecs
.push_front("stpp");
101 case StreamFormat::WEBVTT
:
102 codecs
.push_front("wvtt");
109 for(auto it
= codecs
.cbegin(); it
!= codecs
.cend(); ++it
)
111 CodecDescription
*dsc
= makeCodecDescription(*it
);
112 dsc
->setDescription(adaptationSet
->description
.Get());
113 dsc
->setLanguage(adaptationSet
->getLang());
114 desc
->push_back(dsc
);
118 CodecDescription
* BaseRepresentation::makeCodecDescription(const std::string
&codec
) const
120 return new CodecDescription(codec
);
123 bool BaseRepresentation::needsUpdate(uint64_t) const
128 bool BaseRepresentation::needsIndex() const
130 SegmentBase
*base
= inheritSegmentBase();
131 return base
&& base
->subSegments().empty();
134 bool BaseRepresentation::runLocalUpdates(SharedResources
*)
139 void BaseRepresentation::scheduleNextUpdate(uint64_t, bool)
144 bool BaseRepresentation::consistentSegmentNumber() const
149 void BaseRepresentation::pruneByPlaybackTime(vlc_tick_t time
)
152 if(getSegmentNumberByTime(time
, &num
))
153 pruneBySegmentNumber(num
);
156 vlc_tick_t
BaseRepresentation::getMinAheadTime(uint64_t curnum
) const
158 AbstractSegmentBaseType
*profile
= inheritSegmentTemplate();
160 profile
= inheritSegmentList();
162 profile
= inheritSegmentBase();
164 return profile
? profile
->getMinAheadTime(curnum
) : 0;
167 void BaseRepresentation::debug(vlc_object_t
*obj
, int indent
) const
169 std::string
text(indent
, ' ');
170 text
.append("Representation ");
171 text
.append(id
.str());
174 std::list
<std::string
>::const_iterator c
= codecs
.begin();
175 text
.append(" [" + *c
++);
176 while(c
!= codecs
.end())
177 text
.append("," + *c
++);
180 msg_Dbg(obj
, "%s", text
.c_str());
181 const AbstractSegmentBaseType
*profile
= getProfile();
183 profile
->debug(obj
, indent
+ 1);
186 std::string
BaseRepresentation::contextualize(size_t, const std::string
&component
,
187 const SegmentTemplate
*) const
192 bool BaseRepresentation::bwCompare(const BaseRepresentation
*a
,
193 const BaseRepresentation
*b
)
195 return a
->getBandwidth() < b
->getBandwidth();
198 bool BaseRepresentation::validateCodec(const std::string
&) const
203 uint64_t BaseRepresentation::translateSegmentNumber(uint64_t num
, const BaseRepresentation
*from
) const
205 vlc_tick_t time
, duration
;
206 if( from
->getPlaybackTimeDurationBySegmentNumber(num
, &time
, &duration
) )
207 getSegmentNumberByTime(time
, &num
);
211 bool BaseRepresentation::getSegmentNumberByTime(vlc_tick_t time
, uint64_t *ret
) const
213 const AbstractSegmentBaseType
*profile
= inheritSegmentProfile();
214 return profile
&& profile
->getSegmentNumberByTime(time
, ret
);
217 bool BaseRepresentation::getPlaybackTimeDurationBySegmentNumber(uint64_t number
,
218 vlc_tick_t
*time
, vlc_tick_t
*duration
) const
220 if(number
== std::numeric_limits
<uint64_t>::max())
223 const AbstractSegmentBaseType
*profile
= inheritSegmentProfile();
224 return profile
&& profile
->getPlaybackTimeDurationBySegmentNumber(number
, time
, duration
);
227 bool BaseRepresentation::getMediaPlaybackRange(vlc_tick_t
*rangeBegin
,
228 vlc_tick_t
*rangeEnd
,
229 vlc_tick_t
*rangeLength
) const
231 SegmentTemplate
*mediaSegmentTemplate
= inheritSegmentTemplate();
232 if( mediaSegmentTemplate
)
234 const Timescale timescale
= mediaSegmentTemplate
->inheritTimescale();
235 const SegmentTimeline
*timeline
= mediaSegmentTemplate
->inheritSegmentTimeline();
238 stime_t startTime
, endTime
, duration
;
239 if(!timeline
->getScaledPlaybackTimeDurationBySegmentNumber(timeline
->minElementNumber(),
240 &startTime
, &duration
) ||
241 !timeline
->getScaledPlaybackTimeDurationBySegmentNumber(timeline
->maxElementNumber(),
242 &endTime
, &duration
))
245 *rangeBegin
= timescale
.ToTime(startTime
);
246 *rangeEnd
= timescale
.ToTime(endTime
+duration
);
247 *rangeLength
= timescale
.ToTime(timeline
->getTotalLength());
250 /* Else compute, current time and timeshiftdepth based */
251 else if( mediaSegmentTemplate
->inheritDuration() )
254 *rangeBegin
= -1 * getPlaylist()->timeShiftBufferDepth
.Get();
255 *rangeLength
= getPlaylist()->timeShiftBufferDepth
.Get();
260 SegmentList
*segmentList
= inheritSegmentList();
261 if ( segmentList
&& !segmentList
->getSegments().empty() )
263 const Timescale timescale
= segmentList
->inheritTimescale();
264 const std::vector
<Segment
*> &list
= segmentList
->getSegments();
265 const ISegment
*back
= list
.back();
266 const stime_t startTime
= list
.front()->startTime
.Get();
267 const stime_t endTime
= back
->startTime
.Get() + back
->duration
.Get();
268 *rangeBegin
= timescale
.ToTime(startTime
);
269 *rangeEnd
= timescale
.ToTime(endTime
);
270 *rangeLength
= timescale
.ToTime(segmentList
->getTotalLength());
274 SegmentBase
*segmentBase
= inheritSegmentBase();
277 const std::vector
<Segment
*> &list
= segmentBase
->subSegments();
281 const Timescale timescale
= inheritTimescale();
282 const Segment
*back
= list
.back();
283 const stime_t startTime
= list
.front()->startTime
.Get();
284 const stime_t endTime
= back
->startTime
.Get() + back
->duration
.Get();
285 *rangeBegin
= timescale
.ToTime(startTime
);
286 *rangeEnd
= timescale
.ToTime(endTime
);