[vlc-commits] demux: adaptive: cache total segments length

Francois Cartegnie git at videolan.org
Sun May 26 16:58:36 CEST 2019


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu May 23 23:10:13 2019 +0200| [00021e8e6ec133f3e6f643627112a17706bcda56] | committer: Francois Cartegnie

demux: adaptive: cache total segments length

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

 modules/demux/adaptive/playlist/SegmentList.cpp     |  8 ++++++++
 modules/demux/adaptive/playlist/SegmentList.h       |  2 ++
 modules/demux/adaptive/playlist/SegmentTimeline.cpp | 11 +++++++++++
 modules/demux/adaptive/playlist/SegmentTimeline.h   |  2 ++
 4 files changed, 23 insertions(+)

diff --git a/modules/demux/adaptive/playlist/SegmentList.cpp b/modules/demux/adaptive/playlist/SegmentList.cpp
index 4813425c7e..4be39a99a5 100644
--- a/modules/demux/adaptive/playlist/SegmentList.cpp
+++ b/modules/demux/adaptive/playlist/SegmentList.cpp
@@ -34,6 +34,7 @@ using namespace adaptive::playlist;
 SegmentList::SegmentList( SegmentInformation *parent ):
     SegmentInfoCommon( parent ), TimescaleAble( parent )
 {
+    totalLength = 0;
 }
 SegmentList::~SegmentList()
 {
@@ -69,6 +70,7 @@ void SegmentList::addSegment(ISegment *seg)
 {
     seg->setParent(this);
     segments.push_back(seg);
+    totalLength += seg->duration.Get();
 }
 
 void SegmentList::mergeWith(SegmentList *updated, bool b_restamp)
@@ -118,6 +120,7 @@ void SegmentList::pruneBySegmentNumber(uint64_t tobelownum)
         if(seg->getSequenceNumber() >= tobelownum)
             break;
 
+        totalLength -= (*it)->duration.Get();
         delete *it;
         it = segments.erase(it);
     }
@@ -179,3 +182,8 @@ bool SegmentList::getPlaybackTimeDurationBySegmentNumber(uint64_t number,
     *dur = VLC_TICK_0 + timescale.ToTime(seg_dura);
     return true;
 }
+
+stime_t SegmentList::getTotalLength() const
+{
+    return totalLength;
+}
diff --git a/modules/demux/adaptive/playlist/SegmentList.h b/modules/demux/adaptive/playlist/SegmentList.h
index 58156b1550..5b2ad6c183 100644
--- a/modules/demux/adaptive/playlist/SegmentList.h
+++ b/modules/demux/adaptive/playlist/SegmentList.h
@@ -49,9 +49,11 @@ namespace adaptive
                 void                    pruneByPlaybackTime(vlc_tick_t);
                 bool                    getSegmentNumberByScaledTime(stime_t, uint64_t *) const;
                 bool                    getPlaybackTimeDurationBySegmentNumber(uint64_t, vlc_tick_t *, vlc_tick_t *) const;
+                stime_t                 getTotalLength() const;
 
             private:
                 std::vector<ISegment *>  segments;
+                stime_t totalLength;
         };
     }
 }
diff --git a/modules/demux/adaptive/playlist/SegmentTimeline.cpp b/modules/demux/adaptive/playlist/SegmentTimeline.cpp
index 04430d49e2..862725b31d 100644
--- a/modules/demux/adaptive/playlist/SegmentTimeline.cpp
+++ b/modules/demux/adaptive/playlist/SegmentTimeline.cpp
@@ -32,6 +32,7 @@ using namespace adaptive::playlist;
 SegmentTimeline::SegmentTimeline(TimescaleAble *parent)
     :TimescaleAble(parent)
 {
+    totalLength = 0;
 }
 
 SegmentTimeline::SegmentTimeline(uint64_t scale)
@@ -58,6 +59,7 @@ void SegmentTimeline::addElement(uint64_t number, stime_t d, uint64_t r, stime_t
             element->t = el->t + (el->d * (el->r + 1));
         }
         elements.push_back(element);
+        totalLength += (d * (r + 1));
     }
 }
 
@@ -157,6 +159,11 @@ stime_t SegmentTimeline::getScaledPlaybackTimeByElementNumber(uint64_t number) c
     return time;
 }
 
+stime_t SegmentTimeline::getTotalLength() const
+{
+    return totalLength;
+}
+
 uint64_t SegmentTimeline::maxElementNumber() const
 {
     if(elements.empty())
@@ -203,6 +210,7 @@ size_t SegmentTimeline::pruneBySequenceNumber(uint64_t number)
         {
             prunednow += el->r + 1;
             elements.pop_front();
+            totalLength -= (el->d * (el->r + 1));
             delete el;
         }
     }
@@ -231,7 +239,9 @@ void SegmentTimeline::mergeWith(SegmentTimeline &other)
         if(last->contains(el->t)) /* Same element, but prev could have been middle of repeat */
         {
             const uint64_t count = (el->t - last->t) / last->d;
+            totalLength -= (last->d * (last->r + 1));
             last->r = std::max(last->r, el->r + count);
+            totalLength += (last->d * (last->r + 1));
             delete el;
         }
         else if(el->t < last->t)
@@ -240,6 +250,7 @@ void SegmentTimeline::mergeWith(SegmentTimeline &other)
         }
         else /* Did not exist in previous list */
         {
+            totalLength += (el->d * (el->r + 1));
             elements.push_back(el);
             el->number = last->number + last->r + 1;
             last = el;
diff --git a/modules/demux/adaptive/playlist/SegmentTimeline.h b/modules/demux/adaptive/playlist/SegmentTimeline.h
index 447ef6b9ea..d95b0e82db 100644
--- a/modules/demux/adaptive/playlist/SegmentTimeline.h
+++ b/modules/demux/adaptive/playlist/SegmentTimeline.h
@@ -44,6 +44,7 @@ namespace adaptive
                 bool    getScaledPlaybackTimeDurationBySegmentNumber(uint64_t, stime_t *, stime_t *) const;
                 stime_t getScaledPlaybackTimeByElementNumber(uint64_t) const;
                 stime_t getMinAheadScaledTime(uint64_t) const;
+                stime_t getTotalLength() const;
                 uint64_t maxElementNumber() const;
                 uint64_t minElementNumber() const;
                 void pruneByPlaybackTime(vlc_tick_t);
@@ -53,6 +54,7 @@ namespace adaptive
 
             private:
                 std::list<Element *> elements;
+                stime_t totalLength;
 
                 class Element
                 {



More information about the vlc-commits mailing list