[vlc-commits] demux: adaptive: adapt buffering logic for any timeline

Francois Cartegnie git at videolan.org
Fri Nov 27 11:23:21 CET 2020


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Oct 22 21:11:25 2020 +0200| [ceef5624d6fc5ccfdfb8b18ed5e03d1832cca8aa] | committer: Francois Cartegnie

demux: adaptive: adapt buffering logic for any timeline

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

 modules/demux/adaptive/logic/BufferingLogic.cpp | 115 +++++++++++++-----------
 1 file changed, 62 insertions(+), 53 deletions(-)

diff --git a/modules/demux/adaptive/logic/BufferingLogic.cpp b/modules/demux/adaptive/logic/BufferingLogic.cpp
index 5829a025b0..a3db24368a 100644
--- a/modules/demux/adaptive/logic/BufferingLogic.cpp
+++ b/modules/demux/adaptive/logic/BufferingLogic.cpp
@@ -139,73 +139,82 @@ uint64_t DefaultBufferingLogic::getLiveStartSegmentNumber(BaseRepresentation *re
     SegmentList *segmentList = rep->inheritSegmentList();
     SegmentBase *segmentBase = rep->inheritSegmentBase();
     SegmentTemplate *mediaSegmentTemplate = rep->inheritSegmentTemplate();
+
+    SegmentTimeline *timeline;
     if(mediaSegmentTemplate)
+        timeline = mediaSegmentTemplate->inheritSegmentTimeline();
+    else if(segmentList)
+        timeline = segmentList->inheritSegmentTimeline();
+    else
+        timeline = NULL;
+
+    if(timeline)
     {
         uint64_t start = 0;
-        const Timescale timescale = mediaSegmentTemplate->inheritTimescale();
+        const Timescale timescale = timeline->inheritTimescale();
 
-        const SegmentTimeline *timeline = mediaSegmentTemplate->inheritSegmentTimeline();
-        if(timeline)
+        uint64_t safeMinElementNumber = timeline->minElementNumber();
+        uint64_t safeMaxElementNumber = timeline->maxElementNumber();
+        stime_t safeedgetime, safestarttime, duration;
+        for(unsigned i=0; i<SAFETY_BUFFERING_EDGE_OFFSET; i++)
         {
-            uint64_t safeMinElementNumber = timeline->minElementNumber();
-            uint64_t safeMaxElementNumber = timeline->maxElementNumber();
-            stime_t safeedgetime, safestarttime, duration;
-            for(unsigned i=0; i<SAFETY_BUFFERING_EDGE_OFFSET; i++)
-            {
-                if(safeMinElementNumber == safeMaxElementNumber)
-                    break;
-                safeMaxElementNumber--;
-            }
-            bool b_ret = timeline->getScaledPlaybackTimeDurationBySegmentNumber(safeMaxElementNumber,
-                                                                                &safeedgetime, &duration);
-            if(unlikely(!b_ret))
-                return 0;
-            safeedgetime += duration - 1;
+            if(safeMinElementNumber == safeMaxElementNumber)
+                break;
+            safeMaxElementNumber--;
+        }
+        bool b_ret = timeline->getScaledPlaybackTimeDurationBySegmentNumber(safeMaxElementNumber,
+                                                                            &safeedgetime, &duration);
+        if(unlikely(!b_ret))
+            return 0;
+        safeedgetime += duration - 1;
 
-            for(unsigned i=0; i<SAFETY_EXPURGING_OFFSET; i++)
-            {
-                if(safeMinElementNumber + 1 >= safeMaxElementNumber)
-                    break;
-                safeMinElementNumber++;
-            }
-            b_ret = timeline->getScaledPlaybackTimeDurationBySegmentNumber(safeMinElementNumber,
-                                                                           &safestarttime, &duration);
+        for(unsigned i=0; i<SAFETY_EXPURGING_OFFSET; i++)
+        {
+            if(safeMinElementNumber + 1 >= safeMaxElementNumber)
+                break;
+            safeMinElementNumber++;
+        }
+        b_ret = timeline->getScaledPlaybackTimeDurationBySegmentNumber(safeMinElementNumber,
+                                                                       &safestarttime, &duration);
+        if(unlikely(!b_ret))
+            return 0;
+
+        if(playlist->timeShiftBufferDepth.Get())
+        {
+            stime_t edgetime;
+            bool b_ret = timeline->getScaledPlaybackTimeDurationBySegmentNumber(timeline->maxElementNumber(),
+                                                                                &edgetime, &duration);
             if(unlikely(!b_ret))
                 return 0;
-
-            if(playlist->timeShiftBufferDepth.Get())
+            edgetime += duration - 1;
+            stime_t timeshiftdepth = timescale.ToScaled(playlist->timeShiftBufferDepth.Get());
+            if(safestarttime + timeshiftdepth < edgetime)
             {
-                stime_t edgetime;
-                bool b_ret = timeline->getScaledPlaybackTimeDurationBySegmentNumber(timeline->maxElementNumber(),
-                                                                                    &edgetime, &duration);
-                if(unlikely(!b_ret))
-                    return 0;
-                edgetime += duration - 1;
-                stime_t timeshiftdepth = timescale.ToScaled(playlist->timeShiftBufferDepth.Get());
-                if(safestarttime + timeshiftdepth < edgetime)
-                {
-                    safestarttime = edgetime - timeshiftdepth;
-                    safeMinElementNumber = timeline->getElementNumberByScaledPlaybackTime(safestarttime);
-                }
+                safestarttime = edgetime - timeshiftdepth;
+                safeMinElementNumber = timeline->getElementNumberByScaledPlaybackTime(safestarttime);
             }
-            assert(safestarttime<=safeedgetime);
+        }
+        assert(safestarttime<=safeedgetime);
 
-            stime_t starttime;
-            if(safeedgetime - safestarttime > timescale.ToScaled(i_buffering))
-                starttime = safeedgetime - timescale.ToScaled(i_buffering);
-            else
-                starttime = safestarttime;
+        stime_t starttime;
+        if(safeedgetime - safestarttime > timescale.ToScaled(i_buffering))
+            starttime = safeedgetime - timescale.ToScaled(i_buffering);
+        else
+            starttime = safestarttime;
 
-            start = timeline->getElementNumberByScaledPlaybackTime(starttime);
-            assert(start >= timeline->minElementNumber());
-            assert(start >= safeMinElementNumber);
-            assert(start <= timeline->maxElementNumber());
-            assert(start <= safeMaxElementNumber);
+        start = timeline->getElementNumberByScaledPlaybackTime(starttime);
+        assert(start >= timeline->minElementNumber());
+        assert(start >= safeMinElementNumber);
+        assert(start <= timeline->maxElementNumber());
+        assert(start <= safeMaxElementNumber);
 
-            return start;
-        }
+        return start;
+    }
+    else if(mediaSegmentTemplate)
+    {
         /* Else compute, current time and timeshiftdepth based */
-        else if(mediaSegmentTemplate->duration.Get())
+        uint64_t start = 0;
+        if(mediaSegmentTemplate->duration.Get())
         {
             /* Compute playback offset and effective finished segment from wall time */
             vlc_tick_t now = vlc_tick_from_sec(time(NULL));



More information about the vlc-commits mailing list