Commit bba54210 authored by Francois Cartegnie's avatar Francois Cartegnie

demux: dash: add Timeline pruning

parent f46a168a
...@@ -31,6 +31,7 @@ using namespace dash::mpd; ...@@ -31,6 +31,7 @@ using namespace dash::mpd;
SegmentTimeline::SegmentTimeline() SegmentTimeline::SegmentTimeline()
{ {
pruned = 0;
} }
SegmentTimeline::~SegmentTimeline() SegmentTimeline::~SegmentTimeline()
...@@ -70,6 +71,7 @@ uint64_t SegmentTimeline::getElementNumberByScaledPlaybackTime(time_t scaled) co ...@@ -70,6 +71,7 @@ uint64_t SegmentTimeline::getElementNumberByScaledPlaybackTime(time_t scaled) co
count++; count++;
} }
} }
count += pruned;
return count; return count;
} }
...@@ -77,6 +79,11 @@ mtime_t SegmentTimeline::getScaledPlaybackTimeByElementNumber(uint64_t number) c ...@@ -77,6 +79,11 @@ mtime_t SegmentTimeline::getScaledPlaybackTimeByElementNumber(uint64_t number) c
{ {
mtime_t totalscaledtime = 0; mtime_t totalscaledtime = 0;
if(number < pruned)
return 0;
number -= pruned;
std::list<Element *>::const_iterator it; std::list<Element *>::const_iterator it;
for(it = elements.begin(); it != elements.end(); it++) for(it = elements.begin(); it != elements.end(); it++)
{ {
...@@ -101,6 +108,26 @@ mtime_t SegmentTimeline::getScaledPlaybackTimeByElementNumber(uint64_t number) c ...@@ -101,6 +108,26 @@ mtime_t SegmentTimeline::getScaledPlaybackTimeByElementNumber(uint64_t number) c
return totalscaledtime; return totalscaledtime;
} }
size_t SegmentTimeline::prune(mtime_t scaled)
{
size_t prunednow = 0;
while(elements.size())
{
Element *el = elements.front();
if(el->t + (el->d * (mtime_t)(el->r + 1)) < scaled)
{
prunednow += el->r + 1;
delete el;
elements.pop_front();
}
else
break;
}
pruned += prunednow;
return prunednow;
}
SegmentTimeline::Element::Element(mtime_t d_, uint64_t r_, mtime_t t_) SegmentTimeline::Element::Element(mtime_t d_, uint64_t r_, mtime_t t_)
{ {
d = d_; d = d_;
......
...@@ -41,9 +41,11 @@ namespace dash ...@@ -41,9 +41,11 @@ namespace dash
void addElement(mtime_t d, uint64_t r = 0, mtime_t t = 0); void addElement(mtime_t d, uint64_t r = 0, mtime_t t = 0);
uint64_t getElementNumberByScaledPlaybackTime(time_t) const; uint64_t getElementNumberByScaledPlaybackTime(time_t) const;
mtime_t getScaledPlaybackTimeByElementNumber(uint64_t) const; mtime_t getScaledPlaybackTimeByElementNumber(uint64_t) const;
size_t prune(mtime_t);
private: private:
std::list<Element *> elements; std::list<Element *> elements;
size_t pruned;
class Element class Element
{ {
......
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