[vlc-commits] demux: adaptive: simplify segment methods and avoid temp lists
Francois Cartegnie
git at videolan.org
Fri Nov 27 11:23:18 CET 2020
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Oct 14 21:52:41 2020 +0200| [844f58a8abee1196ff9c3bcc7af6d511edb1a377] | committer: Francois Cartegnie
demux: adaptive: simplify segment methods and avoid temp lists
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=844f58a8abee1196ff9c3bcc7af6d511edb1a377
---
modules/demux/adaptive/SegmentTracker.cpp | 7 +-
modules/demux/adaptive/logic/BufferingLogic.cpp | 6 +-
.../demux/adaptive/playlist/BaseRepresentation.cpp | 29 ++--
modules/demux/adaptive/playlist/Segment.cpp | 10 +-
modules/demux/adaptive/playlist/Segment.h | 8 +-
modules/demux/adaptive/playlist/SegmentBase.h | 4 +-
.../demux/adaptive/playlist/SegmentInfoCommon.cpp | 6 +-
.../demux/adaptive/playlist/SegmentInfoCommon.h | 6 +-
.../demux/adaptive/playlist/SegmentInformation.cpp | 191 ++++++++++-----------
.../demux/adaptive/playlist/SegmentInformation.hpp | 16 +-
modules/demux/adaptive/playlist/SegmentList.cpp | 28 +--
modules/demux/adaptive/playlist/SegmentList.h | 8 +-
.../demux/adaptive/playlist/SegmentTemplate.cpp | 16 +-
modules/demux/adaptive/playlist/SegmentTemplate.h | 9 +-
modules/demux/dash/mpd/IsoffMainParser.cpp | 10 +-
modules/demux/dash/mpd/IsoffMainParser.h | 2 +-
modules/demux/hls/playlist/Representation.cpp | 8 +-
modules/demux/smooth/playlist/Representation.cpp | 12 +-
modules/demux/smooth/playlist/Representation.hpp | 4 +-
19 files changed, 188 insertions(+), 192 deletions(-)
diff --git a/modules/demux/adaptive/SegmentTracker.cpp b/modules/demux/adaptive/SegmentTracker.cpp
index 7f987abec8..ac05c6e62c 100644
--- a/modules/demux/adaptive/SegmentTracker.cpp
+++ b/modules/demux/adaptive/SegmentTracker.cpp
@@ -296,7 +296,7 @@ SegmentChunk * SegmentTracker::getNextChunk(bool switch_allowed,
if(!current.init_sent)
{
++next;
- segment = current.rep->getSegment(BaseRepresentation::INFOTYPE_INIT);
+ segment = current.rep->getInitSegment();
if(segment)
return segment->toChunk(resources, connManager, current.number, current.rep);
current = next;
@@ -307,7 +307,7 @@ SegmentChunk * SegmentTracker::getNextChunk(bool switch_allowed,
++next;
if(current.rep->needsIndex())
{
- segment = current.rep->getSegment(BaseRepresentation::INFOTYPE_INDEX);
+ segment = current.rep->getIndexSegment();
if(segment)
return segment->toChunk(resources, connManager, current.number, current.rep);
}
@@ -315,8 +315,7 @@ SegmentChunk * SegmentTracker::getNextChunk(bool switch_allowed,
}
bool b_gap = false;
- segment = current.rep->getNextSegment(BaseRepresentation::INFOTYPE_MEDIA,
- current.number, ¤t.number, &b_gap);
+ segment = current.rep->getNextMediaSegment(current.number, ¤t.number, &b_gap);
if(!segment)
return NULL;
if(b_gap)
diff --git a/modules/demux/adaptive/logic/BufferingLogic.cpp b/modules/demux/adaptive/logic/BufferingLogic.cpp
index f11fac2377..d4073dd976 100644
--- a/modules/demux/adaptive/logic/BufferingLogic.cpp
+++ b/modules/demux/adaptive/logic/BufferingLogic.cpp
@@ -269,7 +269,7 @@ uint64_t DefaultBufferingLogic::getLiveStartSegmentNumber(BaseRepresentation *re
else if (segmentList && !segmentList->getSegments().empty())
{
const Timescale timescale = segmentList->inheritTimescale();
- const std::vector<ISegment *> list = segmentList->getSegments();
+ const std::vector<Segment *> &list = segmentList->getSegments();
const ISegment *back = list.back();
/* working around HLS discontinuities by using durations */
@@ -338,12 +338,12 @@ uint64_t DefaultBufferingLogic::getLiveStartSegmentNumber(BaseRepresentation *re
}
else if(segmentBase)
{
- const std::vector<ISegment *> list = segmentBase->subSegments();
+ const std::vector<Segment *> &list = segmentBase->subSegments();
if(!list.empty())
return segmentBase->getSequenceNumber();
const Timescale timescale = rep->inheritTimescale();
- const ISegment *back = list.back();
+ const Segment *back = list.back();
const stime_t bufferingstart = back->startTime.Get() + back->duration.Get() -
timescale.ToScaled(i_buffering);
diff --git a/modules/demux/adaptive/playlist/BaseRepresentation.cpp b/modules/demux/adaptive/playlist/BaseRepresentation.cpp
index 6afc11fef1..c0c353b2f6 100644
--- a/modules/demux/adaptive/playlist/BaseRepresentation.cpp
+++ b/modules/demux/adaptive/playlist/BaseRepresentation.cpp
@@ -122,8 +122,8 @@ void BaseRepresentation::pruneByPlaybackTime(vlc_tick_t time)
vlc_tick_t BaseRepresentation::getMinAheadTime(uint64_t curnum) const
{
- std::vector<ISegment *> seglist;
- getSegments(INFOTYPE_MEDIA, seglist);
+ std::vector<Segment *> seglist;
+ getMediaSegments(seglist);
if(seglist.size() == 1 && seglist.front()->isTemplate())
{
@@ -141,10 +141,10 @@ vlc_tick_t BaseRepresentation::getMinAheadTime(uint64_t curnum) const
vlc_tick_t minTime = 0;
const Timescale timescale = inheritTimescale();
- std::vector<ISegment *>::const_iterator it;
+ std::vector<Segment *>::const_iterator it;
for(it = seglist.begin(); it != seglist.end(); ++it)
{
- const ISegment *seg = *it;
+ const Segment *seg = *it;
if(seg->getSequenceNumber() > curnum)
minTime += timescale.ToTime(seg->duration.Get());
}
@@ -166,9 +166,14 @@ void BaseRepresentation::debug(vlc_object_t *obj, int indent) const
text.append("]");
}
msg_Dbg(obj, "%s", text.c_str());
- std::vector<ISegment *> list;
- getAllSegments(list);
- std::vector<ISegment *>::const_iterator l;
+ const ISegment *seg;
+ if((seg = getInitSegment()))
+ seg->debug(obj, indent + 1);
+ if((seg = getIndexSegment()))
+ seg->debug(obj, indent + 1);
+ std::vector<Segment *> list;
+ getMediaSegments(list);
+ std::vector<Segment *>::const_iterator l;
for(l = list.begin(); l != list.end(); ++l)
(*l)->debug(obj, indent + 1);
}
@@ -253,7 +258,7 @@ bool BaseRepresentation::getSegmentNumberByTime(vlc_tick_t time, uint64_t *ret)
const Timescale timescale = inheritTimescale();
stime_t st = timescale.ToScaled(time);
*ret = 0;
- const std::vector<ISegment *> list = segmentBase->subSegments();
+ const std::vector<Segment *> &list = segmentBase->subSegments();
return SegmentInfoCommon::getSegmentNumberByScaledTime(list, st, ret);
}
@@ -299,7 +304,7 @@ bool BaseRepresentation::getPlaybackTimeDurationBySegmentNumber(uint64_t number,
else
{
const Timescale timescale = inheritTimescale();
- const ISegment *segment = getSegment(INFOTYPE_MEDIA, number);
+ const ISegment *segment = getMediaSegment(number);
if( segment )
{
*time = timescale.ToTime(segment->startTime.Get());
@@ -348,7 +353,7 @@ bool BaseRepresentation::getMediaPlaybackRange(vlc_tick_t *rangeBegin,
if ( segmentList && !segmentList->getSegments().empty() )
{
const Timescale timescale = segmentList->inheritTimescale();
- const std::vector<ISegment *> list = segmentList->getSegments();
+ const std::vector<Segment *> &list = segmentList->getSegments();
const ISegment *back = list.back();
const stime_t startTime = list.front()->startTime.Get();
@@ -362,12 +367,12 @@ bool BaseRepresentation::getMediaPlaybackRange(vlc_tick_t *rangeBegin,
SegmentBase *segmentBase = inheritSegmentBase();
if( segmentBase )
{
- const std::vector<ISegment *> list = segmentBase->subSegments();
+ const std::vector<Segment *> &list = segmentBase->subSegments();
if(list.empty())
return false;
const Timescale timescale = inheritTimescale();
- const ISegment *back = list.back();
+ const Segment *back = list.back();
const stime_t startTime = list.front()->startTime.Get();
const stime_t endTime = back->startTime.Get() + back->duration.Get();
*rangeBegin = timescale.ToTime(startTime);
diff --git a/modules/demux/adaptive/playlist/Segment.cpp b/modules/demux/adaptive/playlist/Segment.cpp
index fbe171e6a5..0bbe7c101b 100644
--- a/modules/demux/adaptive/playlist/Segment.cpp
+++ b/modules/demux/adaptive/playlist/Segment.cpp
@@ -213,7 +213,7 @@ void Segment::addSubSegment(SubSegment *subsegment)
Segment::~Segment()
{
- std::vector<ISegment*>::iterator it;
+ std::vector<Segment*>::iterator it;
for(it=subsegments.begin();it!=subsegments.end();++it)
delete *it;
}
@@ -235,7 +235,7 @@ void Segment::debug(vlc_object_t *obj, int indent) const
std::string text(indent, ' ');
text.append("Segment");
msg_Dbg(obj, "%s", text.c_str());
- std::vector<ISegment *>::const_iterator l;
+ std::vector<Segment *>::const_iterator l;
for(l = subsegments.begin(); l != subsegments.end(); ++l)
(*l)->debug(obj, indent + 1);
}
@@ -256,7 +256,7 @@ Url Segment::getUrlSegment() const
}
}
-std::vector<ISegment*> & Segment::subSegments()
+const std::vector<Segment*> & Segment::subSegments() const
{
return subsegments;
}
@@ -275,8 +275,8 @@ IndexSegment::IndexSegment(ICanonicalUrl *parent) :
classId = CLASSID_INDEXSEGMENT;
}
-SubSegment::SubSegment(ISegment *main, size_t start, size_t end) :
- ISegment(main)
+SubSegment::SubSegment(Segment *main, size_t start, size_t end) :
+ Segment(main)
{
setByteRange(start, end);
debugName = "SubSegment";
diff --git a/modules/demux/adaptive/playlist/Segment.h b/modules/demux/adaptive/playlist/Segment.h
index 595dcd9592..11a1e8652c 100644
--- a/modules/demux/adaptive/playlist/Segment.h
+++ b/modules/demux/adaptive/playlist/Segment.h
@@ -102,13 +102,13 @@ namespace adaptive
virtual SegmentChunk* createChunk(AbstractChunkSource *, BaseRepresentation *); /* impl */
virtual void setSourceUrl( const std::string &url );
virtual Url getUrlSegment() const; /* impl */
- virtual std::vector<ISegment*> & subSegments();
+ virtual const std::vector<Segment*> & subSegments() const;
virtual void debug(vlc_object_t *,int = 0) const;
virtual void addSubSegment(SubSegment *);
static const int CLASSID_SEGMENT = 1;
protected:
- std::vector<ISegment *> subsegments;
+ std::vector<Segment *> subsegments;
Url sourceUrl;
int size;
};
@@ -127,10 +127,10 @@ namespace adaptive
static const int CLASSID_INDEXSEGMENT = 3;
};
- class SubSegment : public ISegment
+ class SubSegment : public Segment
{
public:
- SubSegment(ISegment *, size_t start, size_t end);
+ SubSegment(Segment *, size_t start, size_t end);
virtual SegmentChunk* createChunk(AbstractChunkSource *, BaseRepresentation *); /* impl */
virtual Url getUrlSegment() const; /* impl */
static const int CLASSID_SUBSEGMENT = 4;
diff --git a/modules/demux/adaptive/playlist/SegmentBase.h b/modules/demux/adaptive/playlist/SegmentBase.h
index 3144e2cff1..4297b28be6 100644
--- a/modules/demux/adaptive/playlist/SegmentBase.h
+++ b/modules/demux/adaptive/playlist/SegmentBase.h
@@ -35,8 +35,8 @@ namespace adaptive
{
/* SegmentBase can contain only one segment */
class SegmentBase : public Segment,
- public Initializable<Segment>,
- public Indexable<Segment>
+ public Initializable<InitSegment>,
+ public Indexable<IndexSegment>
{
public:
SegmentBase (ICanonicalUrl *);
diff --git a/modules/demux/adaptive/playlist/SegmentInfoCommon.cpp b/modules/demux/adaptive/playlist/SegmentInfoCommon.cpp
index 5dfb3d6790..f8c0070803 100644
--- a/modules/demux/adaptive/playlist/SegmentInfoCommon.cpp
+++ b/modules/demux/adaptive/playlist/SegmentInfoCommon.cpp
@@ -64,7 +64,7 @@ Url SegmentInfoCommon::getUrlSegment() const
return ret;
}
-bool SegmentInfoCommon::getSegmentNumberByScaledTime(const std::vector<ISegment *> &segments,
+bool SegmentInfoCommon::getSegmentNumberByScaledTime(const std::vector<Segment *> &segments,
stime_t time, uint64_t *ret)
{
if(segments.empty() || (segments.size() > 1 && segments[1]->startTime.Get() == 0) )
@@ -72,10 +72,10 @@ bool SegmentInfoCommon::getSegmentNumberByScaledTime(const std::vector<ISegment
*ret = 0;
- std::vector<ISegment *>::const_iterator it = segments.begin();
+ std::vector<Segment *>::const_iterator it = segments.begin();
while(it != segments.end())
{
- const ISegment *seg = *it;
+ const Segment *seg = *it;
if(seg->startTime.Get() > time)
{
if(it == segments.begin())
diff --git a/modules/demux/adaptive/playlist/SegmentInfoCommon.h b/modules/demux/adaptive/playlist/SegmentInfoCommon.h
index a0d9265cce..0498a4b75f 100644
--- a/modules/demux/adaptive/playlist/SegmentInfoCommon.h
+++ b/modules/demux/adaptive/playlist/SegmentInfoCommon.h
@@ -39,8 +39,8 @@ namespace adaptive
class Segment;
class SegmentInfoCommon : public ICanonicalUrl,
- public Initializable<Segment>,
- public Indexable<Segment>
+ public Initializable<InitSegment>,
+ public Indexable<IndexSegment>
{
public:
SegmentInfoCommon( ICanonicalUrl *parent = NULL );
@@ -50,7 +50,7 @@ namespace adaptive
void appendBaseURL( const std::string& url );
virtual Url getUrlSegment() const; /* impl */
Property<stime_t> duration;
- static bool getSegmentNumberByScaledTime(const std::vector<ISegment *> &,
+ static bool getSegmentNumberByScaledTime(const std::vector<Segment *> &,
stime_t, uint64_t *);
private:
diff --git a/modules/demux/adaptive/playlist/SegmentInformation.cpp b/modules/demux/adaptive/playlist/SegmentInformation.cpp
index 6a71601645..6867529924 100644
--- a/modules/demux/adaptive/playlist/SegmentInformation.cpp
+++ b/modules/demux/adaptive/playlist/SegmentInformation.cpp
@@ -77,103 +77,44 @@ AbstractPlaylist * SegmentInformation::getPlaylist() const
return NULL;
}
-std::size_t SegmentInformation::getSegments(SegmentInfoType type, std::vector<ISegment *> &retSegments) const
+std::size_t SegmentInformation::getMediaSegments(std::vector<Segment *> &retSegments) const
{
- switch (type)
+ if( mediaSegmentTemplate )
{
- case INFOTYPE_INIT:
- {
- /* init segments are always single segment */
- if( segmentBase && segmentBase->initialisationSegment.Get() )
- {
- retSegments.push_back( segmentBase->initialisationSegment.Get() );
- }
- else if( segmentList && segmentList->initialisationSegment.Get() )
- {
- retSegments.push_back( segmentList->initialisationSegment.Get() );
- }
- else if( mediaSegmentTemplate && mediaSegmentTemplate->initialisationSegment.Get() )
- {
- retSegments.push_back( mediaSegmentTemplate->initialisationSegment.Get() );
- }
- }
- break;
-
- case INFOTYPE_MEDIA:
- {
- if( mediaSegmentTemplate )
- {
- retSegments.push_back( mediaSegmentTemplate );
- }
- else if ( segmentList && !segmentList->getSegments().empty() )
- {
- std::vector<ISegment *> list = segmentList->getSegments();
- retSegments.insert( retSegments.end(), list.begin(), list.end() );
- }
- else if( segmentBase )
- {
- std::vector<ISegment *> list = segmentBase->subSegments();
- retSegments.insert( retSegments.end(), list.begin(), list.end() );
- }
- }
- break;
-
- case INFOTYPE_INDEX:
- {
- /* index segments are always single segment */
- if( segmentBase && segmentBase->indexSegment.Get() )
- {
- retSegments.push_back( segmentBase->indexSegment.Get() );
- }
- else if( segmentList && segmentList->indexSegment.Get() )
- {
- retSegments.push_back( segmentList->indexSegment.Get() );
- }
- // templated index ?
- }
-
- default:
- break;
+ retSegments.push_back( mediaSegmentTemplate );
}
-
- if( retSegments.empty() && parent )
+ else if ( segmentList && !segmentList->getSegments().empty() )
{
- return parent->getSegments( type, retSegments );
+ std::vector<Segment *> list = segmentList->getSegments();
+ retSegments.insert( retSegments.end(), list.begin(), list.end() );
}
- else
+ else if( segmentBase )
{
- return retSegments.size();
+ const std::vector<Segment *> &list = segmentBase->subSegments();
+ retSegments.insert( retSegments.end(), list.begin(), list.end() );
}
-}
-
-std::size_t SegmentInformation::getAllSegments(std::vector<ISegment *> &retSegments) const
-{
- for(int i=0; i<InfoTypeCount; i++)
+ else if( parent )
{
- std::vector<ISegment *> segs;
- if( getSegments(static_cast<SegmentInfoType>(i), segs) )
- retSegments.insert( retSegments.end(), segs.begin(), segs.end() );
+ return parent->getMediaSegments(retSegments);
}
return retSegments.size();
}
/* Returns wanted segment, or next in sequence if not found */
-ISegment * SegmentInformation::getNextSegment(SegmentInfoType type, uint64_t i_pos,
- uint64_t *pi_newpos, bool *pb_gap) const
+Segment * SegmentInformation::getNextMediaSegment(uint64_t i_pos,uint64_t *pi_newpos,
+ bool *pb_gap) const
{
*pb_gap = false;
*pi_newpos = i_pos;
- if( type != INFOTYPE_MEDIA )
- return NULL;
- std::vector<ISegment *> retSegments;
- const size_t size = getSegments( type, retSegments );
+ std::vector<Segment *> retSegments;
+ const size_t size = getMediaSegments( retSegments );
if( size )
{
- std::vector<ISegment *>::const_iterator it;
+ std::vector<Segment *>::const_iterator it;
for(it = retSegments.begin(); it != retSegments.end(); ++it)
{
- ISegment *seg = *it;
+ Segment *seg = *it;
if(seg->isTemplate()) /* we don't care about seq number */
{
/* Check if we don't exceed timeline */
@@ -224,36 +165,78 @@ ISegment * SegmentInformation::getNextSegment(SegmentInfoType type, uint64_t i_p
return NULL;
}
-ISegment * SegmentInformation::getSegment(SegmentInfoType type, uint64_t pos) const
+InitSegment * SegmentInformation::getInitSegment() const
{
- std::vector<ISegment *> retSegments;
- const size_t size = getSegments( type, retSegments );
- if( size )
+ if( segmentBase && segmentBase->initialisationSegment.Get() )
{
- if(size == 1 && retSegments[0]->isTemplate())
- {
- MediaSegmentTemplate *templ = dynamic_cast<MediaSegmentTemplate*>(retSegments[0]);
- const SegmentTimeline *tl = templ->inheritSegmentTimeline();
- if(!templ || tl == NULL || tl->maxElementNumber() > pos)
- return templ;
- }
- else
+ return segmentBase->initialisationSegment.Get();
+ }
+ else if( segmentList && segmentList->initialisationSegment.Get() )
+ {
+ return segmentList->initialisationSegment.Get();
+ }
+ else if( mediaSegmentTemplate && mediaSegmentTemplate->initialisationSegment.Get() )
+ {
+ return mediaSegmentTemplate->initialisationSegment.Get();
+ }
+ else if( parent )
+ {
+ return parent->getInitSegment();
+ }
+ else return NULL;
+}
+
+IndexSegment *SegmentInformation::getIndexSegment() const
+{
+ if( segmentBase && segmentBase->indexSegment.Get() )
+ {
+ return segmentBase->indexSegment.Get();
+ }
+ else if( segmentList && segmentList->indexSegment.Get() )
+ {
+ return segmentList->indexSegment.Get();
+ }
+ else if( parent )
+ {
+ return parent->getIndexSegment();
+ }
+ else return NULL;
+}
+
+Segment * SegmentInformation::getMediaSegment(uint64_t pos) const
+{
+ if( mediaSegmentTemplate )
+ {
+ const SegmentTimeline *tl = mediaSegmentTemplate->inheritSegmentTimeline();
+ if(tl == NULL || tl->maxElementNumber() > pos)
+ return mediaSegmentTemplate;
+ }
+ else if( segmentList )
+ {
+ return segmentList->getSegmentByNumber( pos );
+ }
+ else if( segmentBase )
+ {
+ /* FIXME add getSegmentByNumber */
+ const std::vector<Segment *> &retSegments = segmentBase->subSegments();
+ std::vector<Segment *>::const_iterator it;
+ for(it = retSegments.begin(); it != retSegments.end(); ++it)
{
- std::vector<ISegment *>::const_iterator it;
- for(it = retSegments.begin(); it != retSegments.end(); ++it)
+ Segment *seg = *it;
+ if(seg->getSequenceNumber() >= pos)
{
- ISegment *seg = *it;
- if(seg->getSequenceNumber() >= pos)
- {
- if(seg->getSequenceNumber() == pos)
- return seg;
- else
- return NULL;
- }
+ if(seg->getSequenceNumber() == pos)
+ return seg;
+ else
+ return NULL;
}
}
+ return NULL;
+ }
+ else if( parent )
+ {
+ return parent->getMediaSegment(pos);
}
-
return NULL;
}
@@ -383,20 +366,20 @@ void SegmentInformation::setSegmentTemplate(MediaSegmentTemplate *templ)
mediaSegmentTemplate = templ;
}
-static void insertIntoSegment(std::vector<ISegment *> &seglist, size_t start,
+static void insertIntoSegment(std::vector<Segment *> &seglist, size_t start,
size_t end, stime_t time, stime_t duration)
{
- std::vector<ISegment *>::iterator segIt;
+ std::vector<Segment *>::iterator segIt;
for(segIt = seglist.begin(); segIt < seglist.end(); ++segIt)
{
- ISegment *segment = *segIt;
+ Segment *segment = *segIt;
if(segment->getClassId() == Segment::CLASSID_SEGMENT &&
(end == 0 || segment->contains(end)))
{
SubSegment *subsegment = new SubSegment(segment, start, (end != 0) ? end : 0);
subsegment->startTime.Set(time);
subsegment->duration.Set(duration);
- static_cast<Segment *>(segment)->addSubSegment(subsegment);
+ segment->addSubSegment(subsegment);
break;
}
}
@@ -408,7 +391,7 @@ void SegmentInformation::SplitUsingIndex(std::vector<SplitPoint> &splitlist)
if(!segmentBase)
return;
- std::vector<ISegment *> seglist;
+ std::vector<Segment *> seglist;
seglist.push_back( segmentBase );
size_t prevstart = 0;
diff --git a/modules/demux/adaptive/playlist/SegmentInformation.hpp b/modules/demux/adaptive/playlist/SegmentInformation.hpp
index 396239c7c4..3d3ac27046 100644
--- a/modules/demux/adaptive/playlist/SegmentInformation.hpp
+++ b/modules/demux/adaptive/playlist/SegmentInformation.hpp
@@ -64,16 +64,11 @@ namespace adaptive
};
void SplitUsingIndex(std::vector<SplitPoint>&);
- enum SegmentInfoType
- {
- INFOTYPE_INIT = 0,
- INFOTYPE_MEDIA,
- INFOTYPE_INDEX
- };
- static const int InfoTypeCount = INFOTYPE_INDEX + 1;
+ virtual InitSegment * getInitSegment() const;
+ virtual IndexSegment *getIndexSegment() const;
+ virtual Segment * getMediaSegment(uint64_t = 0) const;
+ virtual Segment * getNextMediaSegment(uint64_t, uint64_t *, bool *) const;
- ISegment * getSegment(SegmentInfoType, uint64_t = 0) const;
- ISegment * getNextSegment(SegmentInfoType, uint64_t, uint64_t *, bool *) const;
virtual void updateWith(SegmentInformation *);
virtual void mergeWithTimeline(SegmentTimeline *); /* ! don't use with global merge */
virtual void pruneBySegmentNumber(uint64_t);
@@ -82,8 +77,7 @@ namespace adaptive
const CommonEncryption & intheritEncryption() const;
protected:
- std::size_t getAllSegments(std::vector<ISegment *> &) const;
- virtual std::size_t getSegments(SegmentInfoType, std::vector<ISegment *>&) const;
+ std::size_t getMediaSegments(std::vector<Segment *>&) const;
std::vector<SegmentInformation *> childs;
SegmentInformation * getChildByID( const ID & );
SegmentInformation *parent;
diff --git a/modules/demux/adaptive/playlist/SegmentList.cpp b/modules/demux/adaptive/playlist/SegmentList.cpp
index 3b47867e5f..16efe98c8e 100644
--- a/modules/demux/adaptive/playlist/SegmentList.cpp
+++ b/modules/demux/adaptive/playlist/SegmentList.cpp
@@ -38,22 +38,22 @@ SegmentList::SegmentList( SegmentInformation *parent ):
}
SegmentList::~SegmentList()
{
- std::vector<ISegment *>::iterator it;
+ std::vector<Segment *>::iterator it;
for(it = segments.begin(); it != segments.end(); ++it)
delete(*it);
}
-const std::vector<ISegment*>& SegmentList::getSegments() const
+const std::vector<Segment*>& SegmentList::getSegments() const
{
return segments;
}
-ISegment * SegmentList::getSegmentByNumber(uint64_t number)
+Segment * SegmentList::getSegmentByNumber(uint64_t number)
{
- std::vector<ISegment *>::const_iterator it = segments.begin();
+ std::vector<Segment *>::const_iterator it = segments.begin();
for(it = segments.begin(); it != segments.end(); ++it)
{
- ISegment *seg = *it;
+ Segment *seg = *it;
if(seg->getSequenceNumber() == number)
{
return seg;
@@ -66,7 +66,7 @@ ISegment * SegmentList::getSegmentByNumber(uint64_t number)
return NULL;
}
-void SegmentList::addSegment(ISegment *seg)
+void SegmentList::addSegment(Segment *seg)
{
seg->setParent(this);
segments.push_back(seg);
@@ -75,18 +75,18 @@ void SegmentList::addSegment(ISegment *seg)
void SegmentList::updateWith(SegmentList *updated, bool b_restamp)
{
- const ISegment * lastSegment = (segments.empty()) ? NULL : segments.back();
- const ISegment * prevSegment = lastSegment;
+ const Segment * lastSegment = (segments.empty()) ? NULL : segments.back();
+ const Segment * prevSegment = lastSegment;
if(updated->segments.empty())
return;
uint64_t firstnumber = updated->segments.front()->getSequenceNumber();
- std::vector<ISegment *>::iterator it;
+ std::vector<Segment *>::iterator it;
for(it = updated->segments.begin(); it != updated->segments.end(); ++it)
{
- ISegment *cur = *it;
+ Segment *cur = *it;
if(!lastSegment || lastSegment->compare(cur) < 0)
{
if(b_restamp && prevSegment)
@@ -119,10 +119,10 @@ void SegmentList::pruneByPlaybackTime(vlc_tick_t time)
void SegmentList::pruneBySegmentNumber(uint64_t tobelownum)
{
- std::vector<ISegment *>::iterator it = segments.begin();
+ std::vector<Segment *>::iterator it = segments.begin();
while(it != segments.end())
{
- ISegment *seg = *it;
+ Segment *seg = *it;
if(seg->getSequenceNumber() >= tobelownum)
break;
@@ -154,10 +154,10 @@ bool SegmentList::getPlaybackTimeDurationBySegmentNumber(uint64_t number,
bool found = false;
stime_t seg_start = first->startTime.Get();
stime_t seg_dura = 0;
- std::vector<ISegment *>::const_iterator it = segments.begin();
+ std::vector<Segment *>::const_iterator it = segments.begin();
for(it = segments.begin(); it != segments.end(); ++it)
{
- const ISegment *seg = *it;
+ const Segment *seg = *it;
if(seg->duration.Get())
seg_dura = seg->duration.Get();
diff --git a/modules/demux/adaptive/playlist/SegmentList.h b/modules/demux/adaptive/playlist/SegmentList.h
index 8bad67f6b6..6fd1a00836 100644
--- a/modules/demux/adaptive/playlist/SegmentList.h
+++ b/modules/demux/adaptive/playlist/SegmentList.h
@@ -41,9 +41,9 @@ namespace adaptive
SegmentList ( SegmentInformation * = NULL );
virtual ~SegmentList ();
- const std::vector<ISegment *>& getSegments() const;
- ISegment * getSegmentByNumber(uint64_t);
- void addSegment(ISegment *seg);
+ const std::vector<Segment *>& getSegments() const;
+ Segment * getSegmentByNumber(uint64_t);
+ void addSegment(Segment *seg);
void updateWith(SegmentList *, bool = false);
void pruneBySegmentNumber(uint64_t);
void pruneByPlaybackTime(vlc_tick_t);
@@ -52,7 +52,7 @@ namespace adaptive
stime_t getTotalLength() const;
private:
- std::vector<ISegment *> segments;
+ std::vector<Segment *> segments;
stime_t totalLength;
};
}
diff --git a/modules/demux/adaptive/playlist/SegmentTemplate.cpp b/modules/demux/adaptive/playlist/SegmentTemplate.cpp
index 5fdf38cd5e..04b70557c2 100644
--- a/modules/demux/adaptive/playlist/SegmentTemplate.cpp
+++ b/modules/demux/adaptive/playlist/SegmentTemplate.cpp
@@ -208,9 +208,21 @@ void MediaSegmentTemplate::debug(vlc_object_t *obj, int indent) const
segmentTimeline->debug(obj, indent + 1);
}
-InitSegmentTemplate::InitSegmentTemplate( ICanonicalUrl *parent ) :
- BaseSegmentTemplate(parent)
+InitSegmentTemplate::InitSegmentTemplate( ICanonicalUrl *parent,
+ MediaSegmentTemplate *templ ) :
+ InitSegment(parent)
{
debugName = "InitSegmentTemplate";
classId = InitSegment::CLASSID_INITSEGMENT;
+ maintempl = templ;
+}
+
+InitSegmentTemplate::~InitSegmentTemplate()
+{
+
+}
+
+void InitSegmentTemplate::setSourceUrl(const std::string &url)
+{
+ sourceUrl = Url(Url::Component(url, maintempl));
}
diff --git a/modules/demux/adaptive/playlist/SegmentTemplate.h b/modules/demux/adaptive/playlist/SegmentTemplate.h
index 12d3e1f7c7..cac4dbf3b3 100644
--- a/modules/demux/adaptive/playlist/SegmentTemplate.h
+++ b/modules/demux/adaptive/playlist/SegmentTemplate.h
@@ -71,10 +71,15 @@ namespace adaptive
SegmentInformation *parentSegmentInformation;
};
- class InitSegmentTemplate : public BaseSegmentTemplate
+ class InitSegmentTemplate : public InitSegment
{
public:
- InitSegmentTemplate( ICanonicalUrl * = NULL );
+ InitSegmentTemplate( ICanonicalUrl * = NULL, MediaSegmentTemplate * = NULL );
+ virtual ~InitSegmentTemplate();
+ virtual void setSourceUrl( const std::string &url ); /* reimpl */
+
+ protected:
+ const MediaSegmentTemplate *maintempl;
};
}
}
diff --git a/modules/demux/dash/mpd/IsoffMainParser.cpp b/modules/demux/dash/mpd/IsoffMainParser.cpp
index 3e8eee2049..3188fba343 100644
--- a/modules/demux/dash/mpd/IsoffMainParser.cpp
+++ b/modules/demux/dash/mpd/IsoffMainParser.cpp
@@ -213,7 +213,7 @@ size_t IsoffMainParser::parseSegmentTemplate(MPD *mpd, Node *templateNode, Segme
if(templateNode->hasAttribute("initialization"))
{
std::string initurl = templateNode->getAttributeValue("initialization");
- if(!initurl.empty() && (initTemplate = new (std::nothrow) InitSegmentTemplate(info)))
+ if(!initurl.empty() && (initTemplate = new (std::nothrow) InitSegmentTemplate(info, mediaTemplate)))
initTemplate->setSourceUrl(initurl);
}
mediaTemplate->initialisationSegment.Set(initTemplate);
@@ -354,7 +354,7 @@ void IsoffMainParser::parseRepresentations (MPD *mpd, Node *adaptationSetNode
/* Empty Representation with just baseurl (ex: subtitles) */
if(i_total == 0 &&
(currentRepresentation->baseUrl.Get() && !currentRepresentation->baseUrl.Get()->empty()) &&
- adaptationSet->getSegment(SegmentInformation::INFOTYPE_MEDIA, 0) == NULL)
+ adaptationSet->getMediaSegment(0) == NULL)
{
SegmentBase *base = new (std::nothrow) SegmentBase(currentRepresentation);
if(base)
@@ -392,7 +392,7 @@ size_t IsoffMainParser::parseSegmentBase(MPD *mpd, Node * segmentBaseNode, Segme
if(!base->initialisationSegment.Get() && base->indexSegment.Get() && base->indexSegment.Get()->getOffset())
{
- Segment *initSeg = new InitSegment( info );
+ InitSegment *initSeg = new InitSegment( info );
initSeg->setSourceUrl(base->getUrlSegment().toString());
initSeg->setByteRange(0, base->indexSegment.Get()->getOffset() - 1);
base->initialisationSegment.Set(initSeg);
@@ -462,12 +462,12 @@ size_t IsoffMainParser::parseSegmentList(MPD *mpd, Node * segListNode, SegmentIn
return total;
}
-void IsoffMainParser::parseInitSegment(Node *initNode, Initializable<Segment> *init, SegmentInformation *parent)
+void IsoffMainParser::parseInitSegment(Node *initNode, Initializable<InitSegment> *init, SegmentInformation *parent)
{
if(!initNode)
return;
- Segment *seg = new InitSegment( parent );
+ InitSegment *seg = new InitSegment( parent );
seg->setSourceUrl(initNode->getAttributeValue("sourceURL"));
if(initNode->hasAttribute("range"))
diff --git a/modules/demux/dash/mpd/IsoffMainParser.h b/modules/demux/dash/mpd/IsoffMainParser.h
index 0bd0f59ae5..0856bfb132 100644
--- a/modules/demux/dash/mpd/IsoffMainParser.h
+++ b/modules/demux/dash/mpd/IsoffMainParser.h
@@ -74,7 +74,7 @@ namespace dash
void parseMPDAttributes (MPD *, xml::Node *);
void parseAdaptationSets (MPD *, xml::Node *periodNode, Period *period);
void parseRepresentations(MPD *, xml::Node *adaptationSetNode, AdaptationSet *adaptationSet);
- void parseInitSegment (xml::Node *, Initializable<Segment> *, SegmentInformation *);
+ void parseInitSegment (xml::Node *, Initializable<InitSegment> *, SegmentInformation *);
void parseTimeline (xml::Node *, MediaSegmentTemplate *);
void parsePeriods (MPD *, xml::Node *);
size_t parseSegmentInformation(MPD *, xml::Node *, SegmentInformation *, uint64_t *);
diff --git a/modules/demux/hls/playlist/Representation.cpp b/modules/demux/hls/playlist/Representation.cpp
index 4bcdd7beae..97ce41883b 100644
--- a/modules/demux/hls/playlist/Representation.cpp
+++ b/modules/demux/hls/playlist/Representation.cpp
@@ -165,16 +165,16 @@ uint64_t Representation::translateSegmentNumber(uint64_t num, const BaseRepresen
{
if(consistentSegmentNumber())
return num;
- ISegment *fromSeg = from->getSegment(INFOTYPE_MEDIA, num);
+ ISegment *fromSeg = from->getMediaSegment(num);
HLSSegment *fromHlsSeg = dynamic_cast<HLSSegment *>(fromSeg);
if(!fromHlsSeg)
return 1;
const vlc_tick_t utcTime = fromHlsSeg->getUTCTime() +
getTimescale().ToTime(fromHlsSeg->duration.Get()) / 2;
- std::vector<ISegment *> list;
- std::vector<ISegment *>::const_iterator it;
- getSegments(INFOTYPE_MEDIA, list);
+ std::vector<Segment *> list;
+ std::vector<Segment *>::const_iterator it;
+ getMediaSegments(list);
for(it=list.begin(); it != list.end(); ++it)
{
const HLSSegment *hlsSeg = dynamic_cast<HLSSegment *>(*it);
diff --git a/modules/demux/smooth/playlist/Representation.cpp b/modules/demux/smooth/playlist/Representation.cpp
index d919ade29e..eae39dded9 100644
--- a/modules/demux/smooth/playlist/Representation.cpp
+++ b/modules/demux/smooth/playlist/Representation.cpp
@@ -43,14 +43,12 @@ StreamFormat Representation::getStreamFormat() const
return StreamFormat(StreamFormat::MP4);
}
-std::size_t Representation::getSegments(SegmentInfoType type, std::vector<ISegment *> &retSegments) const
+InitSegment * Representation::getInitSegment() const
{
- if(type == INFOTYPE_INIT && initialisationSegment.Get())
- {
- retSegments.push_back(initialisationSegment.Get());
- return retSegments.size();
- }
- return BaseRepresentation::getSegments(type, retSegments);
+ if(initialisationSegment.Get())
+ return initialisationSegment.Get();
+ else
+ return BaseRepresentation::getInitSegment();
}
std::string Representation::contextualize(size_t number, const std::string &component,
diff --git a/modules/demux/smooth/playlist/Representation.hpp b/modules/demux/smooth/playlist/Representation.hpp
index 2100fe2505..09eb6927f8 100644
--- a/modules/demux/smooth/playlist/Representation.hpp
+++ b/modules/demux/smooth/playlist/Representation.hpp
@@ -39,13 +39,13 @@ namespace smooth
using namespace adaptive::playlist;
class Representation : public BaseRepresentation,
- public Initializable<Segment>
+ public Initializable<InitSegment>
{
public:
Representation(BaseAdaptationSet *);
virtual ~Representation ();
- virtual std::size_t getSegments(SegmentInfoType, std::vector<ISegment *>&) const; /* reimpl */
+ virtual InitSegment * getInitSegment() const; /* reimpl */
virtual StreamFormat getStreamFormat() const; /* reimpl */
/* for segment templates */
More information about the vlc-commits
mailing list