Commit 36145354 authored by François Cartegnie's avatar François Cartegnie 🤞

demux: adaptative: recursively merge segmentinfo

parent f48876f3
......@@ -133,20 +133,8 @@ void AbstractPlaylist::getTimeLinesBoundaries(mtime_t *min, mtime_t *max) const
void AbstractPlaylist::mergeWith(AbstractPlaylist *updatedAbstractPlaylist, mtime_t prunebarrier)
{
availabilityEndTime.Set(updatedAbstractPlaylist->availabilityEndTime.Get());
/* Only merge timelines for now */
for(size_t i = 0; i < periods.size() && i < updatedAbstractPlaylist->periods.size(); i++)
{
std::vector<SegmentTimeline *> timelines;
std::vector<SegmentTimeline *> timelinesUpdate;
periods.at(i)->collectTimelines(&timelines);
updatedAbstractPlaylist->periods.at(i)->collectTimelines(&timelinesUpdate);
for(size_t j = 0; j < timelines.size() && j < timelinesUpdate.size(); j++)
{
timelines.at(j)->mergeWith(*timelinesUpdate.at(j));
if(prunebarrier)
timelines.at(j)->prune(prunebarrier);
}
}
for(size_t i = 0; i < periods.size() && i < updatedAbstractPlaylist->periods.size(); i++)
periods.at(i)->mergeWith(updatedAbstractPlaylist->periods.at(i), prunebarrier);
}
......@@ -29,8 +29,9 @@ namespace adaptative
class ICanonicalUrl
{
public:
ICanonicalUrl( const ICanonicalUrl *parent = NULL ) { parentUrlMember = parent; }
ICanonicalUrl( const ICanonicalUrl *parent = NULL ) { setParent(parent); }
virtual Url getUrlSegment() const = 0;
void setParent( const ICanonicalUrl *parent ) { parentUrlMember = parent; }
protected:
Url getParentUrlSegment() const {
......
......@@ -251,6 +251,21 @@ void SegmentInformation::collectTimelines(std::vector<SegmentTimeline *> *timeli
(*it)->collectTimelines(timelines);
}
void SegmentInformation::mergeWith(SegmentInformation *updated, mtime_t prunetime)
{
/* Support Segment List for now */
if(segmentList && updated->segmentList)
segmentList->mergeWith(updated->segmentList);
if(mediaSegmentTemplate && updated->mediaSegmentTemplate)
mediaSegmentTemplate->mergeWith(updated->mediaSegmentTemplate, prunetime);
for(size_t i=0; i<childs.size() && i<updated->childs.size(); i++)
{
childs.at(i)->mergeWith(updated->childs.at(i), prunetime);
}
}
bool SegmentInformation::canBitswitch() const
{
if(bitswitch_policy == BITSWITCH_INHERIT)
......
......@@ -78,6 +78,7 @@ namespace adaptative
bool getSegmentNumberByTime(mtime_t, uint64_t *) const;
mtime_t getPlaybackTimeBySegmentNumber(uint64_t) const;
void collectTimelines(std::vector<SegmentTimeline *> *) const;
virtual void mergeWith(SegmentInformation *, mtime_t);
protected:
std::vector<ISegment *> getSegments() const;
......
......@@ -46,5 +46,21 @@ const std::vector<Segment*>& SegmentList::getSegments() const
void SegmentList::addSegment(Segment *seg)
{
seg->setParent(this);
segments.push_back(seg);
}
void SegmentList::mergeWith(SegmentList *updated)
{
const Segment * lastSegment = (segments.empty()) ? NULL : segments.back();
std::vector<Segment *>::iterator it;
for(it = updated->segments.begin(); it != updated->segments.end(); ++it)
{
if( !lastSegment || lastSegment->compare( *it ) < 0 )
addSegment(*it);
else
delete *it;
}
updated->segments.clear();
}
......@@ -47,6 +47,7 @@ namespace adaptative
const std::vector<Segment *>& getSegments() const;
void addSegment(Segment *seg);
void mergeWith(SegmentList *);
private:
std::vector<Segment *> segments;
......
......@@ -57,6 +57,16 @@ MediaSegmentTemplate::MediaSegmentTemplate( SegmentInformation *parent ) :
initialisationSegment.Set( NULL );
}
void MediaSegmentTemplate::mergeWith(MediaSegmentTemplate *updated, mtime_t prunebarrier)
{
if(segmentTimeline.Get() && updated->segmentTimeline.Get())
{
segmentTimeline.Get()->mergeWith(*updated->segmentTimeline.Get());
if(prunebarrier)
segmentTimeline.Get()->prune(prunebarrier);
}
}
InitSegmentTemplate::InitSegmentTemplate( ICanonicalUrl *parent ) :
BaseSegmentTemplate(parent)
{
......
......@@ -50,6 +50,7 @@ namespace adaptative
{
public:
MediaSegmentTemplate( SegmentInformation * = NULL );
void mergeWith( MediaSegmentTemplate *, mtime_t );
Property<size_t> startNumber;
};
......
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