[vlc-commits] demux: adaptative: add minAheadTime for live playlists

Francois Cartegnie git at videolan.org
Sat Nov 28 19:15:51 CET 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Nov 25 18:24:03 2015 +0100| [1a4b8ae2463f0ddebe006a5fca7667ac96c93bd7] | committer: Francois Cartegnie

demux: adaptative: add minAheadTime for live playlists

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

 modules/demux/adaptative/SegmentTracker.cpp        |   10 +++++++
 modules/demux/adaptative/SegmentTracker.hpp        |    1 +
 modules/demux/adaptative/Streams.cpp               |    7 +++++
 modules/demux/adaptative/Streams.hpp               |    1 +
 .../adaptative/playlist/BaseRepresentation.cpp     |   28 ++++++++++++++++++++
 .../demux/adaptative/playlist/BaseRepresentation.h |    2 ++
 .../demux/adaptative/playlist/SegmentTimeline.cpp  |   24 +++++++++++++++++
 .../demux/adaptative/playlist/SegmentTimeline.h    |    1 +
 8 files changed, 74 insertions(+)

diff --git a/modules/demux/adaptative/SegmentTracker.cpp b/modules/demux/adaptative/SegmentTracker.cpp
index 91491bc..59bed9a 100644
--- a/modules/demux/adaptative/SegmentTracker.cpp
+++ b/modules/demux/adaptative/SegmentTracker.cpp
@@ -225,6 +225,16 @@ mtime_t SegmentTracker::getSegmentStart() const
         return 0;
 }
 
+mtime_t SegmentTracker::getMinAheadTime() const
+{
+    BaseRepresentation *rep = curRepresentation;
+    if(!rep)
+        rep = logic->getNextRepresentation(adaptationSet, NULL);
+    if(rep)
+        return rep->getMinAheadTime(count);
+    return 0;
+}
+
 void SegmentTracker::registerListener(SegmentTrackerListenerInterface *listener)
 {
     listeners.push_back(listener);
diff --git a/modules/demux/adaptative/SegmentTracker.hpp b/modules/demux/adaptative/SegmentTracker.hpp
index 996141c..86710b3 100644
--- a/modules/demux/adaptative/SegmentTracker.hpp
+++ b/modules/demux/adaptative/SegmentTracker.hpp
@@ -100,6 +100,7 @@ namespace adaptative
             bool setPositionByTime(mtime_t, bool, bool);
             void setPositionByNumber(uint64_t, bool);
             mtime_t getSegmentStart() const;
+            mtime_t getMinAheadTime() const;
             void registerListener(SegmentTrackerListenerInterface *);
             void pruneFromCurrent();
             void updateSelected();
diff --git a/modules/demux/adaptative/Streams.cpp b/modules/demux/adaptative/Streams.cpp
index e6aa9a0..1ec0608 100644
--- a/modules/demux/adaptative/Streams.cpp
+++ b/modules/demux/adaptative/Streams.cpp
@@ -120,6 +120,13 @@ mtime_t AbstractStream::getPCR() const
     return pcr;
 }
 
+mtime_t AbstractStream::getMinAheadTime() const
+{
+    if(!segmentTracker)
+        return 0;
+    return segmentTracker->getMinAheadTime();
+}
+
 mtime_t AbstractStream::getBufferingLevel() const
 {
     return fakeesout->commandsqueue.getBufferingLevel();
diff --git a/modules/demux/adaptative/Streams.hpp b/modules/demux/adaptative/Streams.hpp
index 7542a51..f625192 100644
--- a/modules/demux/adaptative/Streams.hpp
+++ b/modules/demux/adaptative/Streams.hpp
@@ -66,6 +66,7 @@ namespace adaptative
         bool isEOF() const;
         mtime_t getPCR() const;
         mtime_t getBufferingLevel() const;
+        mtime_t getMinAheadTime() const;
         mtime_t getFirstDTS() const;
         int esCount() const;
         bool seekAble() const;
diff --git a/modules/demux/adaptative/playlist/BaseRepresentation.cpp b/modules/demux/adaptative/playlist/BaseRepresentation.cpp
index d02a1d0..26f92b2 100644
--- a/modules/demux/adaptative/playlist/BaseRepresentation.cpp
+++ b/modules/demux/adaptative/playlist/BaseRepresentation.cpp
@@ -82,6 +82,34 @@ bool BaseRepresentation::consistentSegmentNumber() const
     return b_consistent;
 }
 
+mtime_t BaseRepresentation::getMinAheadTime(uint64_t curnum) const
+{
+    std::vector<ISegment *> seglist;
+    getSegments(INFOTYPE_MEDIA, seglist);
+
+    if(seglist.size() == 1 && seglist.front()->isTemplate())
+    {
+        const MediaSegmentTemplate *templ = dynamic_cast<MediaSegmentTemplate *>(seglist.front());
+        const SegmentTimeline *timeline;
+        if(templ && (timeline = templ->segmentTimeline.Get()))
+        {
+            const uint64_t timescale = templ->inheritTimescale();
+            return timeline->getMinAheadScaledTime(curnum) * CLOCK_FREQ / timescale;
+        }
+    }
+
+    mtime_t minTime = 0;
+    std::vector<ISegment *>::const_iterator it;
+    for(it = seglist.begin(); it != seglist.end(); ++it)
+    {
+        const ISegment *seg = *it;
+        if(seg->getSequenceNumber() > curnum)
+            minTime += seg->duration.Get() * CLOCK_FREQ / inheritTimescale();
+    }
+
+    return minTime;
+}
+
 void BaseRepresentation::debug(vlc_object_t *obj, int indent) const
 {
     std::string text(indent, ' ');
diff --git a/modules/demux/adaptative/playlist/BaseRepresentation.h b/modules/demux/adaptative/playlist/BaseRepresentation.h
index 87ef85c..18fec95 100644
--- a/modules/demux/adaptative/playlist/BaseRepresentation.h
+++ b/modules/demux/adaptative/playlist/BaseRepresentation.h
@@ -61,6 +61,8 @@ namespace adaptative
                 virtual bool        needsUpdate()           const;
                 bool                consistentSegmentNumber () const;
 
+                virtual mtime_t     getMinAheadTime         (uint64_t) const;
+
                 virtual void        debug                   (vlc_object_t *,int = 0) const;
 
                 /* for segment templates */
diff --git a/modules/demux/adaptative/playlist/SegmentTimeline.cpp b/modules/demux/adaptative/playlist/SegmentTimeline.cpp
index 2d6acb7..0fd3288 100644
--- a/modules/demux/adaptative/playlist/SegmentTimeline.cpp
+++ b/modules/demux/adaptative/playlist/SegmentTimeline.cpp
@@ -59,6 +59,30 @@ void SegmentTimeline::addElement(uint64_t number, stime_t d, uint64_t r, stime_t
     }
 }
 
+mtime_t SegmentTimeline::getMinAheadScaledTime(uint64_t number) const
+{
+    stime_t totalscaledtime = 0;
+
+    std::list<Element *>::const_reverse_iterator it;
+    for(it = elements.rbegin(); it != elements.rend(); ++it)
+    {
+        const Element *el = *it;
+
+        if(number < el->number)
+        {
+            totalscaledtime += (el->d * (el->r + 1));
+            break;
+        }
+        else if(number <= el->number + el->r)
+        {
+            totalscaledtime += el->d * (el->number + el->r - number);
+        }
+        else break;
+    }
+
+    return totalscaledtime;
+}
+
 uint64_t SegmentTimeline::getElementNumberByScaledPlaybackTime(stime_t scaled) const
 {
     uint64_t prevnumber = 0;
diff --git a/modules/demux/adaptative/playlist/SegmentTimeline.h b/modules/demux/adaptative/playlist/SegmentTimeline.h
index 5cb2834..730c9ef 100644
--- a/modules/demux/adaptative/playlist/SegmentTimeline.h
+++ b/modules/demux/adaptative/playlist/SegmentTimeline.h
@@ -47,6 +47,7 @@ namespace adaptative
                 void addElement(uint64_t, stime_t d, uint64_t r = 0, stime_t t = 0);
                 uint64_t getElementNumberByScaledPlaybackTime(stime_t) const;
                 stime_t getScaledPlaybackTimeByElementNumber(uint64_t) const;
+                stime_t getMinAheadScaledTime(uint64_t) const;
                 uint64_t maxElementNumber() const;
                 uint64_t minElementNumber() const;
                 size_t pruneBySequenceNumber(uint64_t);



More information about the vlc-commits mailing list