[vlc-commits] demux: dash: add Timeline pruning

Francois Cartegnie git at videolan.org
Mon Jan 12 20:22:07 CET 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sun Jan 11 23:58:56 2015 +0100| [bba5421011d886c3082a7a1d9dd85b8c55e6553d] | committer: Francois Cartegnie

demux: dash: add Timeline pruning

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=bba5421011d886c3082a7a1d9dd85b8c55e6553d
---

 modules/demux/dash/mpd/SegmentTimeline.cpp |   27 +++++++++++++++++++++++++++
 modules/demux/dash/mpd/SegmentTimeline.h   |    2 ++
 2 files changed, 29 insertions(+)

diff --git a/modules/demux/dash/mpd/SegmentTimeline.cpp b/modules/demux/dash/mpd/SegmentTimeline.cpp
index 540dd9c..64bdb0a 100644
--- a/modules/demux/dash/mpd/SegmentTimeline.cpp
+++ b/modules/demux/dash/mpd/SegmentTimeline.cpp
@@ -31,6 +31,7 @@ using namespace dash::mpd;
 
 SegmentTimeline::SegmentTimeline()
 {
+    pruned = 0;
 }
 
 SegmentTimeline::~SegmentTimeline()
@@ -70,6 +71,7 @@ uint64_t SegmentTimeline::getElementNumberByScaledPlaybackTime(time_t scaled) co
             count++;
         }
     }
+    count += pruned;
     return count;
 }
 
@@ -77,6 +79,11 @@ mtime_t SegmentTimeline::getScaledPlaybackTimeByElementNumber(uint64_t number) c
 {
     mtime_t totalscaledtime = 0;
 
+    if(number < pruned)
+        return 0;
+
+    number -= pruned;
+
     std::list<Element *>::const_iterator it;
     for(it = elements.begin(); it != elements.end(); it++)
     {
@@ -101,6 +108,26 @@ mtime_t SegmentTimeline::getScaledPlaybackTimeByElementNumber(uint64_t number) c
     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_)
 {
     d = d_;
diff --git a/modules/demux/dash/mpd/SegmentTimeline.h b/modules/demux/dash/mpd/SegmentTimeline.h
index f387372..46f87a7 100644
--- a/modules/demux/dash/mpd/SegmentTimeline.h
+++ b/modules/demux/dash/mpd/SegmentTimeline.h
@@ -41,9 +41,11 @@ namespace dash
                 void addElement(mtime_t d, uint64_t r = 0, mtime_t t = 0);
                 uint64_t getElementNumberByScaledPlaybackTime(time_t) const;
                 mtime_t getScaledPlaybackTimeByElementNumber(uint64_t) const;
+                size_t prune(mtime_t);
 
             private:
                 std::list<Element *> elements;
+                size_t pruned;
 
                 class Element
                 {



More information about the vlc-commits mailing list