Commit 2bf7935f authored by François Cartegnie's avatar François Cartegnie 🤞

demux: adaptative: add pruning by position

parent 425d321a
......@@ -131,3 +131,9 @@ mtime_t SegmentTracker::getSegmentStart() const
else
return 0;
}
void SegmentTracker::pruneFromCurrent()
{
if(playlist->isLive())
playlist->pruneBySegmentNumber(count);
}
......@@ -61,6 +61,7 @@ namespace adaptative
Chunk* getNextChunk(StreamType);
bool setPosition(mtime_t, bool, bool);
mtime_t getSegmentStart() const;
void pruneFromCurrent();
private:
bool initializing;
......
......@@ -249,6 +249,11 @@ mtime_t Stream::getPosition() const
return segmentTracker->getSegmentStart();
}
void Stream::prune()
{
segmentTracker->pruneFromCurrent();
}
AbstractStreamOutput::AbstractStreamOutput(demux_t *demux)
{
realdemux = demux;
......
......@@ -71,6 +71,7 @@ namespace adaptative
status demux(HTTPConnectionManager *, mtime_t);
bool setPosition(mtime_t, bool);
mtime_t getPosition() const;
void prune();
private:
Chunk *getChunk();
......
......@@ -145,3 +145,9 @@ void AbstractPlaylist::mergeWith(AbstractPlaylist *updatedAbstractPlaylist, mtim
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
virtual BasePeriod* getNextPeriod(BasePeriod *period);
void mergeWith(AbstractPlaylist *, mtime_t = 0);
void pruneBySegmentNumber(uint64_t);
void getTimeLinesBoundaries(mtime_t *, mtime_t *) const;
void getPlaylistDurationsRange(mtime_t *, mtime_t *) const;
......
......@@ -69,8 +69,10 @@ AbstractPlaylist * SegmentInformation::getPlaylist() const
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)
{
case INFOTYPE_INIT:
......@@ -106,6 +108,7 @@ std::size_t SegmentInformation::getSegments(SegmentInfoType type, vector<ISegmen
std::vector<ISegment *> list = (*it)->subSegments();
retSegments.insert( retSegments.end(), list.begin(), list.end() );
}
off = segmentList->getOffset();
}
else if( segmentBase )
{
......@@ -134,9 +137,15 @@ std::size_t SegmentInformation::getSegments(SegmentInfoType type, vector<ISegmen
}
if( retSegments.empty() && parent )
return parent->getSegments( type, retSegments );
{
return parent->getSegments( type, retSegments, offset );
}
else
{
if( offset )
*offset = off;
return retSegments.size();
}
}
std::size_t SegmentInformation::getAllSegments(vector<ISegment *> &retSegments) const
......@@ -155,7 +164,8 @@ ISegment * SegmentInformation::getSegment(SegmentInfoType type, uint64_t pos) co
ISegment *segment = NULL;
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 )
{
/* check if that's a template (fixme: find a better way) */
......@@ -166,9 +176,9 @@ ISegment * SegmentInformation::getSegment(SegmentInfoType type, uint64_t pos) co
templ->segmentTimeline.Get()->maxElementNumber() > pos)
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
}
}
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
{
if(bitswitch_policy == BITSWITCH_INHERIT)
......
......@@ -80,10 +80,11 @@ namespace adaptative
void collectTimelines(std::vector<SegmentTimeline *> *) const;
void getDurationsRange(mtime_t *, mtime_t *) const;
virtual void mergeWith(SegmentInformation *, mtime_t);
virtual void pruneBySegmentNumber(uint64_t);
protected:
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;
SegmentInformation *parent;
......
......@@ -31,6 +31,7 @@ using namespace adaptative::playlist;
SegmentList::SegmentList( SegmentInformation *parent ):
SegmentInfoCommon( parent ), TimescaleAble( parent )
{
pruned = 0;
}
SegmentList::~SegmentList()
{
......@@ -64,3 +65,28 @@ void SegmentList::mergeWith(SegmentList *updated)
}
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
const std::vector<Segment *>& getSegments() const;
void addSegment(Segment *seg);
void mergeWith(SegmentList *);
void pruneBySegmentNumber(uint64_t);
std::size_t getOffset() const;
private:
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