[vlc-commits] demux: adaptive: fix timeline lookups

Francois Cartegnie git at videolan.org
Mon Mar 30 16:15:58 CEST 2020


vlc/vlc-3.0 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sun May 26 15:20:51 2019 +0200| [dc6343a5045616477850f3ffe9d3ec168c4a733b] | committer: Francois Cartegnie

demux: adaptive: fix timeline lookups

(cherry picked from commit 93a0c4a91404d3a5e3d1d9d7afe557e952f10a28)

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

 .../demux/adaptive/playlist/SegmentTimeline.cpp    | 66 +++++++++-------------
 1 file changed, 26 insertions(+), 40 deletions(-)

diff --git a/modules/demux/adaptive/playlist/SegmentTimeline.cpp b/modules/demux/adaptive/playlist/SegmentTimeline.cpp
index 3f36a0ef70..35f1184a6e 100644
--- a/modules/demux/adaptive/playlist/SegmentTimeline.cpp
+++ b/modules/demux/adaptive/playlist/SegmentTimeline.cpp
@@ -90,72 +90,58 @@ mtime_t SegmentTimeline::getMinAheadScaledTime(uint64_t number) const
 
 uint64_t SegmentTimeline::getElementNumberByScaledPlaybackTime(stime_t scaled) const
 {
-    uint64_t prevnumber = 0;
+    const Element *prevel = NULL;
     std::list<Element *>::const_iterator it;
+
+    if(!elements.size())
+        return 0;
+
     for(it = elements.begin(); it != elements.end(); ++it)
     {
         const Element *el = *it;
-        if(it == elements.begin())
+        if(scaled >= el->t)
         {
-            scaled -= el->t;
-            prevnumber = el->number;
+            if((uint64_t)scaled < el->t + (el->d * el->r))
+                return el->number + (scaled - el->t) / el->d;
         }
-
-        for(uint64_t repeat = 1 + el->r; repeat; repeat--)
+        /* might have been discontinuity */
+        else
         {
-            if(el->d >= scaled)
-                return prevnumber;
-
-            scaled -= el->d;
-            prevnumber++;
+            if(prevel) /* > prev but < current */
+                return prevel->number + prevel->r;
+            else /* << first of the list */
+                return el->number;
         }
-
-        /* might have been discontinuity */
-        prevnumber = el->number;
+        prevel = el;
     }
 
-    return prevnumber;
+    /* time is >> any of the list */
+    return prevel->number + prevel->r;
 }
 
 bool SegmentTimeline::getScaledPlaybackTimeDurationBySegmentNumber(uint64_t number,
                                                                    stime_t *time, stime_t *duration) const
 {
-    stime_t totalscaledtime = 0;
-    stime_t lastduration = 0;
-
     std::list<Element *>::const_iterator it;
     for(it = elements.begin(); it != elements.end(); ++it)
     {
         const Element *el = *it;
-
-        /* set start time, or from discontinuity */
-        if(it == elements.begin() || el->t)
+        if(number >= el->number)
         {
-            totalscaledtime = el->t;
+            if(number <= el->number + el->r)
+            {
+                *time = el->t + el->d * (number - el->number);
+                *duration = el->d;
+                return true;
+            }
         }
-
-        lastduration = el->d;
-
-        if(number <= el->number)
-            break;
-
-        if(number <= el->number + el->r)
-        {
-            totalscaledtime += el->d * (number - el->number);
-            break;
-        }
-
-        totalscaledtime += (el->d * (el->r + 1));
     }
-
-    *time = totalscaledtime;
-    *duration = lastduration;
-    return true;
+    return false;
 }
 
 stime_t SegmentTimeline::getScaledPlaybackTimeByElementNumber(uint64_t number) const
 {
-    stime_t time, duration;
+    stime_t time = 0, duration = 0;
     (void) getScaledPlaybackTimeDurationBySegmentNumber(number, &time, &duration);
     return time;
 }



More information about the vlc-commits mailing list