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