Commit c1591aa1 authored by Francois Cartegnie's avatar Francois Cartegnie

demux: adaptative: fix chained initializations bug

Since the bw adaptation can go really fast now,
we need to be sure to send at least 1 data segment
before switching to another.
Otherwise we'll have multiple moov bug and can
also never get any data outside of init segments.
parent 6879a4fc
......@@ -32,7 +32,8 @@ SegmentTracker::SegmentTracker(AbstractAdaptationLogic *logic_, BaseAdaptationSe
{
count = 0;
initializing = true;
indexed = false;
index_sent = false;
init_sent = false;
prevRepresentation = NULL;
setAdaptationLogic(logic_);
adaptationSet = adaptSet;
......@@ -62,6 +63,10 @@ SegmentChunk * SegmentTracker::getNextChunk(bool switch_allowed)
if(!adaptationSet)
return NULL;
/* Ensure we don't keep chaining init/index without data */
if( initializing && prevRepresentation )
switch_allowed = false;
if( !switch_allowed ||
(prevRepresentation && prevRepresentation->getSwitchPolicy() == SegmentInformation::SWITCH_UNAVAILABLE) )
rep = prevRepresentation;
......@@ -74,20 +79,21 @@ SegmentChunk * SegmentTracker::getNextChunk(bool switch_allowed)
if(rep != prevRepresentation)
{
prevRepresentation = rep;
init_sent = false;
initializing = true;
}
if(initializing)
if(!init_sent)
{
initializing = false;
init_sent = true;
segment = rep->getSegment(BaseRepresentation::INFOTYPE_INIT);
if(segment)
return segment->toChunk(count, rep);
}
if(!indexed)
if(!index_sent)
{
indexed = true;
index_sent = true;
segment = rep->getSegment(BaseRepresentation::INFOTYPE_INDEX);
if(segment)
return segment->toChunk(count, rep);
......@@ -99,6 +105,8 @@ SegmentChunk * SegmentTracker::getNextChunk(bool switch_allowed)
resetCounter();
return NULL;
}
/* stop initializing after 1st chunk */
initializing = false;
SegmentChunk *chunk = segment->toChunk(count, rep);
if(chunk)
......@@ -116,7 +124,11 @@ bool SegmentTracker::setPosition(mtime_t time, bool restarted, bool tryonly)
if(!tryonly)
{
if(restarted)
{
initializing = true;
index_sent = false;
init_sent = false;
}
count = segcount;
}
return true;
......
......@@ -59,7 +59,8 @@ namespace adaptative
private:
bool initializing;
bool indexed;
bool index_sent;
bool init_sent;
uint64_t count;
AbstractAdaptationLogic *logic;
BaseAdaptationSet *adaptationSet;
......
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