Commit 2bf7935f authored by Francois Cartegnie's avatar Francois Cartegnie

demux: adaptative: add pruning by position

parent 425d321a
...@@ -131,3 +131,9 @@ mtime_t SegmentTracker::getSegmentStart() const ...@@ -131,3 +131,9 @@ mtime_t SegmentTracker::getSegmentStart() const
else else
return 0; return 0;
} }
void SegmentTracker::pruneFromCurrent()
{
if(playlist->isLive())
playlist->pruneBySegmentNumber(count);
}
...@@ -61,6 +61,7 @@ namespace adaptative ...@@ -61,6 +61,7 @@ namespace adaptative
Chunk* getNextChunk(StreamType); Chunk* getNextChunk(StreamType);
bool setPosition(mtime_t, bool, bool); bool setPosition(mtime_t, bool, bool);
mtime_t getSegmentStart() const; mtime_t getSegmentStart() const;
void pruneFromCurrent();
private: private:
bool initializing; bool initializing;
......
...@@ -249,6 +249,11 @@ mtime_t Stream::getPosition() const ...@@ -249,6 +249,11 @@ mtime_t Stream::getPosition() const
return segmentTracker->getSegmentStart(); return segmentTracker->getSegmentStart();
} }
void Stream::prune()
{
segmentTracker->pruneFromCurrent();
}
AbstractStreamOutput::AbstractStreamOutput(demux_t *demux) AbstractStreamOutput::AbstractStreamOutput(demux_t *demux)
{ {
realdemux = demux; realdemux = demux;
......
...@@ -71,6 +71,7 @@ namespace adaptative ...@@ -71,6 +71,7 @@ namespace adaptative
status demux(HTTPConnectionManager *, mtime_t); status demux(HTTPConnectionManager *, mtime_t);
bool setPosition(mtime_t, bool); bool setPosition(mtime_t, bool);
mtime_t getPosition() const; mtime_t getPosition() const;
void prune();
private: private:
Chunk *getChunk(); Chunk *getChunk();
......
...@@ -145,3 +145,9 @@ void AbstractPlaylist::mergeWith(AbstractPlaylist *updatedAbstractPlaylist, mtim ...@@ -145,3 +145,9 @@ void AbstractPlaylist::mergeWith(AbstractPlaylist *updatedAbstractPlaylist, mtim
periods.at(i)->mergeWith(updatedAbstractPlaylist->periods.at(i), prunebarrier); periods.at(i)->mergeWith(updatedAbstractPlaylist->periods.at(i), prunebarrier);
} }
void AbstractPlaylist::pruneBySegmentNumber(uint64_t num)
{
for(size_t i = 0; i < periods.size(); i++)
periods.at(i)->pruneBySegmentNumber(num);
}
...@@ -54,6 +54,7 @@ namespace adaptative ...@@ -54,6 +54,7 @@ namespace adaptative
virtual BasePeriod* getNextPeriod(BasePeriod *period); virtual BasePeriod* getNextPeriod(BasePeriod *period);
void mergeWith(AbstractPlaylist *, mtime_t = 0); void mergeWith(AbstractPlaylist *, mtime_t = 0);
void pruneBySegmentNumber(uint64_t);
void getTimeLinesBoundaries(mtime_t *, mtime_t *) const; void getTimeLinesBoundaries(mtime_t *, mtime_t *) const;
void getPlaylistDurationsRange(mtime_t *, mtime_t *) const; void getPlaylistDurationsRange(mtime_t *, mtime_t *) const;
......
...@@ -69,8 +69,10 @@ AbstractPlaylist * SegmentInformation::getPlaylist() const ...@@ -69,8 +69,10 @@ AbstractPlaylist * SegmentInformation::getPlaylist() const
return NULL; return NULL;
} }
std::size_t SegmentInformation::getSegments(SegmentInfoType type, vector<ISegment *> &retSegments) const std::size_t SegmentInformation::getSegments(SegmentInfoType type, vector<ISegment *> &retSegments,
std::size_t *offset) const
{ {
std::size_t off = 0;
switch (type) switch (type)
{ {
case INFOTYPE_INIT: case INFOTYPE_INIT:
...@@ -106,6 +108,7 @@ std::size_t SegmentInformation::getSegments(SegmentInfoType type, vector<ISegmen ...@@ -106,6 +108,7 @@ std::size_t SegmentInformation::getSegments(SegmentInfoType type, vector<ISegmen
std::vector<ISegment *> list = (*it)->subSegments(); std::vector<ISegment *> list = (*it)->subSegments();
retSegments.insert( retSegments.end(), list.begin(), list.end() ); retSegments.insert( retSegments.end(), list.begin(), list.end() );
} }
off = segmentList->getOffset();
} }
else if( segmentBase ) else if( segmentBase )
{ {
...@@ -134,9 +137,15 @@ std::size_t SegmentInformation::getSegments(SegmentInfoType type, vector<ISegmen ...@@ -134,9 +137,15 @@ std::size_t SegmentInformation::getSegments(SegmentInfoType type, vector<ISegmen
} }
if( retSegments.empty() && parent ) if( retSegments.empty() && parent )
return parent->getSegments( type, retSegments ); {
return parent->getSegments( type, retSegments, offset );
}
else else
{
if( offset )
*offset = off;
return retSegments.size(); return retSegments.size();
}
} }
std::size_t SegmentInformation::getAllSegments(vector<ISegment *> &retSegments) const std::size_t SegmentInformation::getAllSegments(vector<ISegment *> &retSegments) const
...@@ -155,7 +164,8 @@ ISegment * SegmentInformation::getSegment(SegmentInfoType type, uint64_t pos) co ...@@ -155,7 +164,8 @@ ISegment * SegmentInformation::getSegment(SegmentInfoType type, uint64_t pos) co
ISegment *segment = NULL; ISegment *segment = NULL;
vector<ISegment *> retSegments; vector<ISegment *> retSegments;
const size_t size = getSegments( type, retSegments ); std::size_t offset = 0;
const size_t size = getSegments( type, retSegments, &offset );
if( size ) if( size )
{ {
/* check if that's a template (fixme: find a better way) */ /* check if that's a template (fixme: find a better way) */
...@@ -166,9 +176,9 @@ ISegment * SegmentInformation::getSegment(SegmentInfoType type, uint64_t pos) co ...@@ -166,9 +176,9 @@ ISegment * SegmentInformation::getSegment(SegmentInfoType type, uint64_t pos) co
templ->segmentTimeline.Get()->maxElementNumber() > pos) templ->segmentTimeline.Get()->maxElementNumber() > pos)
return templ; return templ;
} }
else if( pos < size ) else if( pos < size + offset && pos >= offset )
{ {
segment = retSegments[pos]; segment = retSegments[pos - offset];
} }
} }
...@@ -291,6 +301,15 @@ void SegmentInformation::mergeWith(SegmentInformation *updated, mtime_t prunetim ...@@ -291,6 +301,15 @@ void SegmentInformation::mergeWith(SegmentInformation *updated, mtime_t prunetim
} }
} }
void SegmentInformation::pruneBySegmentNumber(uint64_t num)
{
if(segmentList)
segmentList->pruneBySegmentNumber(num);
for(size_t i=0; i<childs.size(); i++)
childs.at(i)->pruneBySegmentNumber(num);
}
bool SegmentInformation::canBitswitch() const bool SegmentInformation::canBitswitch() const
{ {
if(bitswitch_policy == BITSWITCH_INHERIT) if(bitswitch_policy == BITSWITCH_INHERIT)
......
...@@ -80,10 +80,11 @@ namespace adaptative ...@@ -80,10 +80,11 @@ namespace adaptative
void collectTimelines(std::vector<SegmentTimeline *> *) const; void collectTimelines(std::vector<SegmentTimeline *> *) const;
void getDurationsRange(mtime_t *, mtime_t *) const; void getDurationsRange(mtime_t *, mtime_t *) const;
virtual void mergeWith(SegmentInformation *, mtime_t); virtual void mergeWith(SegmentInformation *, mtime_t);
virtual void pruneBySegmentNumber(uint64_t);
protected: protected:
std::size_t getAllSegments(std::vector<ISegment *> &) const; std::size_t getAllSegments(std::vector<ISegment *> &) const;
std::size_t getSegments(SegmentInfoType, std::vector<ISegment *>&) const; std::size_t getSegments(SegmentInfoType, std::vector<ISegment *>&, std::size_t * = NULL) const;
std::vector<SegmentInformation *> childs; std::vector<SegmentInformation *> childs;
SegmentInformation *parent; SegmentInformation *parent;
......
...@@ -31,6 +31,7 @@ using namespace adaptative::playlist; ...@@ -31,6 +31,7 @@ using namespace adaptative::playlist;
SegmentList::SegmentList( SegmentInformation *parent ): SegmentList::SegmentList( SegmentInformation *parent ):
SegmentInfoCommon( parent ), TimescaleAble( parent ) SegmentInfoCommon( parent ), TimescaleAble( parent )
{ {
pruned = 0;
} }
SegmentList::~SegmentList() SegmentList::~SegmentList()
{ {
...@@ -64,3 +65,28 @@ void SegmentList::mergeWith(SegmentList *updated) ...@@ -64,3 +65,28 @@ void SegmentList::mergeWith(SegmentList *updated)
} }
updated->segments.clear(); updated->segments.clear();
} }
void SegmentList::pruneBySegmentNumber(uint64_t tobelownum)
{
if(tobelownum < pruned)
return;
uint64_t current = pruned;
std::vector<Segment *>::iterator it = segments.begin();
while(it != segments.end() && current < tobelownum)
{
Segment *seg = *it;
if(seg->chunksuse.Get()) /* can't prune from here, still in use */
break;
delete *it;
it = segments.erase(it);
current++;
pruned++;
}
}
std::size_t SegmentList::getOffset() const
{
return pruned;
}
...@@ -48,9 +48,12 @@ namespace adaptative ...@@ -48,9 +48,12 @@ namespace adaptative
const std::vector<Segment *>& getSegments() const; const std::vector<Segment *>& getSegments() const;
void addSegment(Segment *seg); void addSegment(Segment *seg);
void mergeWith(SegmentList *); void mergeWith(SegmentList *);
void pruneBySegmentNumber(uint64_t);
std::size_t getOffset() const;
private: private:
std::vector<Segment *> segments; std::vector<Segment *> segments;
std::size_t pruned;
}; };
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment