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

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


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Jan  8 20:00:12 2015 +0100| [b67040057d85180408bbe0a1d9e53796fcf84cfc] | committer: Francois Cartegnie

demux: dash: add Timeline merging

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

 modules/demux/dash/mpd/SegmentTimeline.cpp |   48 ++++++++++++++++++++++++++++
 modules/demux/dash/mpd/SegmentTimeline.h   |    1 +
 2 files changed, 49 insertions(+)

diff --git a/modules/demux/dash/mpd/SegmentTimeline.cpp b/modules/demux/dash/mpd/SegmentTimeline.cpp
index 64bdb0a..d7140c0 100644
--- a/modules/demux/dash/mpd/SegmentTimeline.cpp
+++ b/modules/demux/dash/mpd/SegmentTimeline.cpp
@@ -128,6 +128,54 @@ size_t SegmentTimeline::prune(mtime_t scaled)
     return prunednow;
 }
 
+void SegmentTimeline::mergeWith(SegmentTimeline &other)
+{
+    if(elements.empty())
+    {
+        while(other.elements.size())
+        {
+            elements.push_back(other.elements.front());
+            other.elements.pop_front();
+        }
+        return;
+    }
+
+    Element *last = elements.back();
+    while(other.elements.size())
+    {
+        Element *el = other.elements.front();
+        other.elements.pop_front();
+        if(el->t == last->t) /* Same element, but prev could have been middle of repeat */
+        {
+            last->r = std::max(last->r, el->r);
+            delete el;
+        }
+        else if(el->t > last->t) /* Did not exist in previous list */
+        {
+            if( el->t - last->t >= last->d * (mtime_t)(last->r + 1) )
+            {
+                elements.push_back(el);
+                last = el;
+            }
+            else if(last->d == el->d) /* should always be in that case */
+            {
+                last->r = ((el->t - last->t) / last->d) - 1;
+                elements.push_back(el);
+                last = el;
+            }
+            else
+            {
+                /* borked: skip */
+                delete el;
+            }
+        }
+        else
+        {
+            delete el;
+        }
+    }
+}
+
 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 46f87a7..fec2771 100644
--- a/modules/demux/dash/mpd/SegmentTimeline.h
+++ b/modules/demux/dash/mpd/SegmentTimeline.h
@@ -42,6 +42,7 @@ namespace dash
                 uint64_t getElementNumberByScaledPlaybackTime(time_t) const;
                 mtime_t getScaledPlaybackTimeByElementNumber(uint64_t) const;
                 size_t prune(mtime_t);
+                void mergeWith(SegmentTimeline &);
 
             private:
                 std::list<Element *> elements;



More information about the vlc-commits mailing list