[vlc-commits] demux: adaptive: cache total segments length
Francois Cartegnie
git at videolan.org
Mon Mar 30 16:15:55 CEST 2020
vlc/vlc-3.0 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu May 23 23:10:13 2019 +0200| [dbbaf3a996407e5822be958c3882836d07801475] | committer: Francois Cartegnie
demux: adaptive: cache total segments length
(cherry picked from commit 00021e8e6ec133f3e6f643627112a17706bcda56)
> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=dbbaf3a996407e5822be958c3882836d07801475
---
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 fbb9587178..e775c27ba6 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_TS_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 4c590c18db..27ccc2487a 100644
--- a/modules/demux/adaptive/playlist/SegmentList.h
+++ b/modules/demux/adaptive/playlist/SegmentList.h
@@ -49,9 +49,11 @@ namespace adaptive
void pruneByPlaybackTime(mtime_t);
bool getSegmentNumberByScaledTime(stime_t, uint64_t *) const;
bool getPlaybackTimeDurationBySegmentNumber(uint64_t, mtime_t *, mtime_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 92eb1f470c..3f36a0ef70 100644
--- a/modules/demux/adaptive/playlist/SegmentTimeline.cpp
+++ b/modules/demux/adaptive/playlist/SegmentTimeline.cpp
@@ -33,6 +33,7 @@ using namespace adaptive::playlist;
SegmentTimeline::SegmentTimeline(TimescaleAble *parent)
:TimescaleAble(parent)
{
+ totalLength = 0;
}
SegmentTimeline::SegmentTimeline(uint64_t scale)
@@ -59,6 +60,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));
}
}
@@ -158,6 +160,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())
@@ -204,6 +211,7 @@ size_t SegmentTimeline::pruneBySequenceNumber(uint64_t number)
{
prunednow += el->r + 1;
elements.pop_front();
+ totalLength -= (el->d * (el->r + 1));
delete el;
}
}
@@ -232,7 +240,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)
@@ -241,6 +251,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 4094963bf2..204c6ed2b2 100644
--- a/modules/demux/adaptive/playlist/SegmentTimeline.h
+++ b/modules/demux/adaptive/playlist/SegmentTimeline.h
@@ -45,6 +45,7 @@ namespace adaptive
bool getScaledPlaybackTimeDurationBySegmentNumber(uint64_t, mtime_t *, mtime_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(mtime_t);
@@ -56,6 +57,7 @@ namespace adaptive
private:
std::list<Element *> elements;
+ stime_t totalLength;
class Element
{
More information about the vlc-commits
mailing list