Commit 9b428d68 authored by François Cartegnie's avatar François Cartegnie 🤞

demux: adaptive: allow to retimestamp on segmentList merge

incorrect segment time with hls updates
parent 9037ee6e
...@@ -500,11 +500,11 @@ mtime_t SegmentInformation::getPeriodStart() const ...@@ -500,11 +500,11 @@ mtime_t SegmentInformation::getPeriodStart() const
return 0; return 0;
} }
void SegmentInformation::setSegmentList(SegmentList *list) void SegmentInformation::appendSegmentList(SegmentList *list, bool restamp)
{ {
if(segmentList) if(segmentList)
{ {
segmentList->mergeWith(list); segmentList->mergeWith(list, restamp);
delete list; delete list;
} }
else else
......
...@@ -95,7 +95,7 @@ namespace adaptive ...@@ -95,7 +95,7 @@ namespace adaptive
SwitchPolicy switchpolicy; SwitchPolicy switchpolicy;
public: public:
void setSegmentList(SegmentList *); void appendSegmentList(SegmentList *, bool = false);
void setSegmentBase(SegmentBase *); void setSegmentBase(SegmentBase *);
void setSegmentTemplate(MediaSegmentTemplate *); void setSegmentTemplate(MediaSegmentTemplate *);
void setSwitchPolicy(SwitchPolicy); void setSwitchPolicy(SwitchPolicy);
......
...@@ -71,17 +71,31 @@ void SegmentList::addSegment(ISegment *seg) ...@@ -71,17 +71,31 @@ void SegmentList::addSegment(ISegment *seg)
segments.push_back(seg); segments.push_back(seg);
} }
void SegmentList::mergeWith(SegmentList *updated) void SegmentList::mergeWith(SegmentList *updated, bool b_restamp)
{ {
const ISegment * lastSegment = (segments.empty()) ? NULL : segments.back(); const ISegment * lastSegment = (segments.empty()) ? NULL : segments.back();
const ISegment * prevSegment = lastSegment;
std::vector<ISegment *>::iterator it; std::vector<ISegment *>::iterator it;
for(it = updated->segments.begin(); it != updated->segments.end(); ++it) for(it = updated->segments.begin(); it != updated->segments.end(); ++it)
{ {
if( !lastSegment || lastSegment->compare( *it ) < 0 ) ISegment *cur = *it;
addSegment(*it); if(!lastSegment || lastSegment->compare(cur) < 0)
{
if(b_restamp && prevSegment)
{
stime_t starttime = prevSegment->startTime.Get() + prevSegment->duration.Get();
if(starttime != cur->startTime.Get() && !cur->discontinuity)
{
cur->startTime.Set(starttime);
}
prevSegment = cur;
}
addSegment(cur);
}
else else
delete *it; delete cur;
} }
updated->segments.clear(); updated->segments.clear();
} }
......
...@@ -44,7 +44,7 @@ namespace adaptive ...@@ -44,7 +44,7 @@ namespace adaptive
const std::vector<ISegment *>& getSegments() const; const std::vector<ISegment *>& getSegments() const;
ISegment * getSegmentByNumber(uint64_t); ISegment * getSegmentByNumber(uint64_t);
void addSegment(ISegment *seg); void addSegment(ISegment *seg);
void mergeWith(SegmentList *); void mergeWith(SegmentList *, bool = false);
void pruneBySegmentNumber(uint64_t); void pruneBySegmentNumber(uint64_t);
void pruneByPlaybackTime(mtime_t); void pruneByPlaybackTime(mtime_t);
bool getSegmentNumberByScaledTime(stime_t, uint64_t *) const; bool getSegmentNumberByScaledTime(stime_t, uint64_t *) const;
......
...@@ -409,7 +409,7 @@ size_t IsoffMainParser::parseSegmentList(Node * segListNode, SegmentInformation ...@@ -409,7 +409,7 @@ size_t IsoffMainParser::parseSegmentList(Node * segListNode, SegmentInformation
total++; total++;
} }
info->setSegmentList(list); info->appendSegmentList(list, true);
} }
} }
return total; return total;
......
...@@ -378,7 +378,7 @@ void M3U8Parser::parseSegments(vlc_object_t *p_obj, Representation *rep, const s ...@@ -378,7 +378,7 @@ void M3U8Parser::parseSegments(vlc_object_t *p_obj, Representation *rep, const s
rep->getPlaylist()->duration.Set(totalduration); rep->getPlaylist()->duration.Set(totalduration);
} }
rep->setSegmentList(segmentList); rep->appendSegmentList(segmentList, true);
} }
M3U8 * M3U8Parser::parse(vlc_object_t *p_object, stream_t *p_stream, const std::string &playlisturl) M3U8 * M3U8Parser::parse(vlc_object_t *p_object, stream_t *p_stream, const std::string &playlisturl)
{ {
......
...@@ -206,7 +206,7 @@ static void ParseQualityLevel(BaseAdaptationSet *adaptSet, Node *qualNode, const ...@@ -206,7 +206,7 @@ static void ParseQualityLevel(BaseAdaptationSet *adaptSet, Node *qualNode, const
initSegment->setSourceUrl("forged://"); initSegment->setSourceUrl("forged://");
segmentList->initialisationSegment.Set(initSegment); segmentList->initialisationSegment.Set(initSegment);
} }
rep->setSegmentList(segmentList); rep->appendSegmentList(segmentList);
adaptSet->addRepresentation(rep); adaptSet->addRepresentation(rep);
} }
......
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