[vlc-commits] demux: adaptative: recursively merge segmentinfo

Francois Cartegnie git at videolan.org
Wed Jun 10 18:58:02 CEST 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sat May 23 21:11:17 2015 +0200| [361453549936153b2f808978db9adbe1a4b8ba95] | committer: Francois Cartegnie

demux: adaptative: recursively merge segmentinfo

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=361453549936153b2f808978db9adbe1a4b8ba95
---

 modules/demux/adaptative/playlist/AbstractPlaylist.cpp |   16 ++--------------
 modules/demux/adaptative/playlist/ICanonicalUrl.hpp    |    3 ++-
 .../demux/adaptative/playlist/SegmentInformation.cpp   |   15 +++++++++++++++
 .../demux/adaptative/playlist/SegmentInformation.hpp   |    1 +
 modules/demux/adaptative/playlist/SegmentList.cpp      |   16 ++++++++++++++++
 modules/demux/adaptative/playlist/SegmentList.h        |    1 +
 modules/demux/adaptative/playlist/SegmentTemplate.cpp  |   10 ++++++++++
 modules/demux/adaptative/playlist/SegmentTemplate.h    |    1 +
 8 files changed, 48 insertions(+), 15 deletions(-)

diff --git a/modules/demux/adaptative/playlist/AbstractPlaylist.cpp b/modules/demux/adaptative/playlist/AbstractPlaylist.cpp
index 4c69ff7..9376b19 100644
--- a/modules/demux/adaptative/playlist/AbstractPlaylist.cpp
+++ b/modules/demux/adaptative/playlist/AbstractPlaylist.cpp
@@ -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);
 }
 
diff --git a/modules/demux/adaptative/playlist/ICanonicalUrl.hpp b/modules/demux/adaptative/playlist/ICanonicalUrl.hpp
index acaf091..f3e0402 100644
--- a/modules/demux/adaptative/playlist/ICanonicalUrl.hpp
+++ b/modules/demux/adaptative/playlist/ICanonicalUrl.hpp
@@ -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 {
diff --git a/modules/demux/adaptative/playlist/SegmentInformation.cpp b/modules/demux/adaptative/playlist/SegmentInformation.cpp
index 9861aeb..0a5da37 100644
--- a/modules/demux/adaptative/playlist/SegmentInformation.cpp
+++ b/modules/demux/adaptative/playlist/SegmentInformation.cpp
@@ -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)
diff --git a/modules/demux/adaptative/playlist/SegmentInformation.hpp b/modules/demux/adaptative/playlist/SegmentInformation.hpp
index de0f27e..ea7ba25 100644
--- a/modules/demux/adaptative/playlist/SegmentInformation.hpp
+++ b/modules/demux/adaptative/playlist/SegmentInformation.hpp
@@ -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;
diff --git a/modules/demux/adaptative/playlist/SegmentList.cpp b/modules/demux/adaptative/playlist/SegmentList.cpp
index ab366da..4e8b54b 100644
--- a/modules/demux/adaptative/playlist/SegmentList.cpp
+++ b/modules/demux/adaptative/playlist/SegmentList.cpp
@@ -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();
+}
diff --git a/modules/demux/adaptative/playlist/SegmentList.h b/modules/demux/adaptative/playlist/SegmentList.h
index 6e57052..8db3fe7 100644
--- a/modules/demux/adaptative/playlist/SegmentList.h
+++ b/modules/demux/adaptative/playlist/SegmentList.h
@@ -47,6 +47,7 @@ namespace adaptative
 
                 const std::vector<Segment *>&   getSegments() const;
                 void                    addSegment(Segment *seg);
+                void                    mergeWith(SegmentList *);
 
             private:
                 std::vector<Segment *>  segments;
diff --git a/modules/demux/adaptative/playlist/SegmentTemplate.cpp b/modules/demux/adaptative/playlist/SegmentTemplate.cpp
index eed4b63..e7ae4d0 100644
--- a/modules/demux/adaptative/playlist/SegmentTemplate.cpp
+++ b/modules/demux/adaptative/playlist/SegmentTemplate.cpp
@@ -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)
 {
diff --git a/modules/demux/adaptative/playlist/SegmentTemplate.h b/modules/demux/adaptative/playlist/SegmentTemplate.h
index a67b765..5f4d6e3 100644
--- a/modules/demux/adaptative/playlist/SegmentTemplate.h
+++ b/modules/demux/adaptative/playlist/SegmentTemplate.h
@@ -50,6 +50,7 @@ namespace adaptative
         {
             public:
                 MediaSegmentTemplate( SegmentInformation * = NULL );
+                void mergeWith( MediaSegmentTemplate *, mtime_t );
                 Property<size_t>        startNumber;
         };
 



More information about the vlc-commits mailing list