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
return 0;
}
void SegmentInformation::setSegmentList(SegmentList *list)
void SegmentInformation::appendSegmentList(SegmentList *list, bool restamp)
{
if(segmentList)
{
segmentList->mergeWith(list);
segmentList->mergeWith(list, restamp);
delete list;
}
else
......
......@@ -95,7 +95,7 @@ namespace adaptive
SwitchPolicy switchpolicy;
public:
void setSegmentList(SegmentList *);
void appendSegmentList(SegmentList *, bool = false);
void setSegmentBase(SegmentBase *);
void setSegmentTemplate(MediaSegmentTemplate *);
void setSwitchPolicy(SwitchPolicy);
......
......@@ -71,17 +71,31 @@ void SegmentList::addSegment(ISegment *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 * prevSegment = lastSegment;
std::vector<ISegment *>::iterator it;
for(it = updated->segments.begin(); it != updated->segments.end(); ++it)
{
if( !lastSegment || lastSegment->compare( *it ) < 0 )
addSegment(*it);
ISegment *cur = *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
delete *it;
delete cur;
}
updated->segments.clear();
}
......
......@@ -44,7 +44,7 @@ namespace adaptive
const std::vector<ISegment *>& getSegments() const;
ISegment * getSegmentByNumber(uint64_t);
void addSegment(ISegment *seg);
void mergeWith(SegmentList *);
void mergeWith(SegmentList *, bool = false);
void pruneBySegmentNumber(uint64_t);
void pruneByPlaybackTime(mtime_t);
bool getSegmentNumberByScaledTime(stime_t, uint64_t *) const;
......
......@@ -409,7 +409,7 @@ size_t IsoffMainParser::parseSegmentList(Node * segListNode, SegmentInformation
total++;
}
info->setSegmentList(list);
info->appendSegmentList(list, true);
}
}
return total;
......
......@@ -378,7 +378,7 @@ void M3U8Parser::parseSegments(vlc_object_t *p_obj, Representation *rep, const s
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)
{
......
......@@ -206,7 +206,7 @@ static void ParseQualityLevel(BaseAdaptationSet *adaptSet, Node *qualNode, const
initSegment->setSourceUrl("forged://");
segmentList->initialisationSegment.Set(initSegment);
}
rep->setSegmentList(segmentList);
rep->appendSegmentList(segmentList);
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