[vlc-commits] demux: adaptative: don't use first segment for live streams
Francois Cartegnie
git at videolan.org
Sat Nov 28 19:15:50 CET 2015
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Nov 24 22:13:48 2015 +0100| [4b7af7307869166a2eecd923213f53bb182617e1] | committer: Francois Cartegnie
demux: adaptative: don't use first segment for live streams
segment could become unavailable before we could fully download it.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4b7af7307869166a2eecd923213f53bb182617e1
---
modules/demux/adaptative/SegmentTracker.cpp | 6 +++
modules/demux/adaptative/SegmentTracker.hpp | 1 +
.../adaptative/playlist/SegmentInformation.cpp | 43 ++++++++++++++++++++
.../adaptative/playlist/SegmentInformation.hpp | 1 +
4 files changed, 51 insertions(+)
diff --git a/modules/demux/adaptative/SegmentTracker.cpp b/modules/demux/adaptative/SegmentTracker.cpp
index cc738f6..91491bc 100644
--- a/modules/demux/adaptative/SegmentTracker.cpp
+++ b/modules/demux/adaptative/SegmentTracker.cpp
@@ -50,6 +50,7 @@ SegmentTrackerEvent::SegmentTrackerEvent(const StreamFormat *fmt)
SegmentTracker::SegmentTracker(AbstractAdaptationLogic *logic_, BaseAdaptationSet *adaptSet)
{
+ first = true;
count = 0;
initializing = true;
index_sent = false;
@@ -127,6 +128,11 @@ SegmentChunk * SegmentTracker::getNextChunk(bool switch_allowed, HTTPConnectionM
/* Convert our segment number */
count = rep->translateSegmentNumber(count, prevRep);
}
+ else if(first && rep->getPlaylist()->isLive())
+ {
+ count = rep->getLiveStartSegmentNumber(count);
+ first = false;
+ }
if(!rep->consistentSegmentNumber())
curRepresentation->pruneBySegmentNumber(count);
diff --git a/modules/demux/adaptative/SegmentTracker.hpp b/modules/demux/adaptative/SegmentTracker.hpp
index fe4a3c0..996141c 100644
--- a/modules/demux/adaptative/SegmentTracker.hpp
+++ b/modules/demux/adaptative/SegmentTracker.hpp
@@ -106,6 +106,7 @@ namespace adaptative
private:
void notify(const SegmentTrackerEvent &);
+ bool first;
bool initializing;
bool index_sent;
bool init_sent;
diff --git a/modules/demux/adaptative/playlist/SegmentInformation.cpp b/modules/demux/adaptative/playlist/SegmentInformation.cpp
index 7582010..5b8480e 100644
--- a/modules/demux/adaptative/playlist/SegmentInformation.cpp
+++ b/modules/demux/adaptative/playlist/SegmentInformation.cpp
@@ -155,6 +155,49 @@ std::size_t SegmentInformation::getAllSegments(std::vector<ISegment *> &retSegme
return retSegments.size();
}
+uint64_t SegmentInformation::getLiveStartSegmentNumber(uint64_t def) const
+{
+ if( mediaSegmentTemplate )
+ {
+ SegmentTimeline *timeline = mediaSegmentTemplate->segmentTimeline.Get();
+ if(timeline)
+ {
+ const uint64_t start = timeline->minElementNumber();
+ const uint64_t end = timeline->maxElementNumber();
+ if(end > 2 && (end - start >= 2))
+ return end - 2;
+ else
+ return start;
+ }
+ return mediaSegmentTemplate->startNumber.Get();
+ }
+ else if ( segmentList && !segmentList->getSegments().empty() )
+ {
+ const std::vector<ISegment *> list = segmentList->getSegments();
+ if(list.size() > 3)
+ return list.at(list.size() - 3)->getSequenceNumber();
+ else if(!list.empty())
+ return list.front()->getSequenceNumber();
+ else
+ return segmentList->getStartIndex();
+ }
+ else if( segmentBase )
+ {
+ const std::vector<ISegment *> list = segmentBase->subSegments();
+ if(list.size() > 3)
+ return list.at(list.size() - 3)->getSequenceNumber();
+ else if(!list.empty())
+ return list.front()->getSequenceNumber();
+ else
+ return segmentBase->getSequenceNumber();
+ }
+
+ if(parent)
+ return parent->getLiveStartSegmentNumber(def);
+ else
+ return def;
+}
+
/* Returns wanted segment, or next in sequence if not found */
ISegment * SegmentInformation::getNextSegment(SegmentInfoType type, uint64_t i_pos,
uint64_t *pi_newpos, bool *pb_gap) const
diff --git a/modules/demux/adaptative/playlist/SegmentInformation.hpp b/modules/demux/adaptative/playlist/SegmentInformation.hpp
index b22e984..46ba934 100644
--- a/modules/demux/adaptative/playlist/SegmentInformation.hpp
+++ b/modules/demux/adaptative/playlist/SegmentInformation.hpp
@@ -82,6 +82,7 @@ namespace adaptative
ISegment * getNextSegment(SegmentInfoType, uint64_t, uint64_t *, bool *) const;
bool getSegmentNumberByTime(mtime_t, uint64_t *) const;
mtime_t getPlaybackTimeBySegmentNumber(uint64_t) const;
+ uint64_t getLiveStartSegmentNumber(uint64_t) const;
virtual void getDurationsRange(mtime_t *, mtime_t *) const;
virtual void mergeWith(SegmentInformation *, mtime_t);
virtual void mergeWithTimeline(SegmentTimeline *); /* ! don't use with global merge */
More information about the vlc-commits
mailing list