Commit 4b7af730 authored by François Cartegnie's avatar François Cartegnie 🤞

demux: adaptative: don't use first segment for live streams

segment could become unavailable before we could fully download it.
parent 0b33ed30
......@@ -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);
......
......@@ -106,6 +106,7 @@ namespace adaptative
private:
void notify(const SegmentTrackerEvent &);
bool first;
bool initializing;
bool index_sent;
bool init_sent;
......
......@@ -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
......
......@@ -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 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment