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 ...@@ -32,7 +32,8 @@ SegmentTracker::SegmentTracker(AbstractAdaptationLogic *logic_, BaseAdaptationSe
{ {
count = 0; count = 0;
initializing = true; initializing = true;
indexed = false; index_sent = false;
init_sent = false;
prevRepresentation = NULL; prevRepresentation = NULL;
setAdaptationLogic(logic_); setAdaptationLogic(logic_);
adaptationSet = adaptSet; adaptationSet = adaptSet;
...@@ -62,6 +63,10 @@ SegmentChunk * SegmentTracker::getNextChunk(bool switch_allowed) ...@@ -62,6 +63,10 @@ SegmentChunk * SegmentTracker::getNextChunk(bool switch_allowed)
if(!adaptationSet) if(!adaptationSet)
return NULL; return NULL;
/* Ensure we don't keep chaining init/index without data */
if( initializing && prevRepresentation )
switch_allowed = false;
if( !switch_allowed || if( !switch_allowed ||
(prevRepresentation && prevRepresentation->getSwitchPolicy() == SegmentInformation::SWITCH_UNAVAILABLE) ) (prevRepresentation && prevRepresentation->getSwitchPolicy() == SegmentInformation::SWITCH_UNAVAILABLE) )
rep = prevRepresentation; rep = prevRepresentation;
...@@ -74,20 +79,21 @@ SegmentChunk * SegmentTracker::getNextChunk(bool switch_allowed) ...@@ -74,20 +79,21 @@ SegmentChunk * SegmentTracker::getNextChunk(bool switch_allowed)
if(rep != prevRepresentation) if(rep != prevRepresentation)
{ {
prevRepresentation = rep; prevRepresentation = rep;
init_sent = false;
initializing = true; initializing = true;
} }
if(initializing) if(!init_sent)
{ {
initializing = false; init_sent = true;
segment = rep->getSegment(BaseRepresentation::INFOTYPE_INIT); segment = rep->getSegment(BaseRepresentation::INFOTYPE_INIT);
if(segment) if(segment)
return segment->toChunk(count, rep); return segment->toChunk(count, rep);
} }
if(!indexed) if(!index_sent)
{ {
indexed = true; index_sent = true;
segment = rep->getSegment(BaseRepresentation::INFOTYPE_INDEX); segment = rep->getSegment(BaseRepresentation::INFOTYPE_INDEX);
if(segment) if(segment)
return segment->toChunk(count, rep); return segment->toChunk(count, rep);
...@@ -99,6 +105,8 @@ SegmentChunk * SegmentTracker::getNextChunk(bool switch_allowed) ...@@ -99,6 +105,8 @@ SegmentChunk * SegmentTracker::getNextChunk(bool switch_allowed)
resetCounter(); resetCounter();
return NULL; return NULL;
} }
/* stop initializing after 1st chunk */
initializing = false;
SegmentChunk *chunk = segment->toChunk(count, rep); SegmentChunk *chunk = segment->toChunk(count, rep);
if(chunk) if(chunk)
...@@ -116,7 +124,11 @@ bool SegmentTracker::setPosition(mtime_t time, bool restarted, bool tryonly) ...@@ -116,7 +124,11 @@ bool SegmentTracker::setPosition(mtime_t time, bool restarted, bool tryonly)
if(!tryonly) if(!tryonly)
{ {
if(restarted) if(restarted)
{
initializing = true; initializing = true;
index_sent = false;
init_sent = false;
}
count = segcount; count = segcount;
} }
return true; return true;
......
...@@ -59,7 +59,8 @@ namespace adaptative ...@@ -59,7 +59,8 @@ namespace adaptative
private: private:
bool initializing; bool initializing;
bool indexed; bool index_sent;
bool init_sent;
uint64_t count; uint64_t count;
AbstractAdaptationLogic *logic; AbstractAdaptationLogic *logic;
BaseAdaptationSet *adaptationSet; 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