demux: dash: add MPD merging for updates
authorFrancois Cartegnie <fcvlcdev@free.fr>
Sat, 10 Jan 2015 20:23:45 +0000 (21:23 +0100)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Mon, 12 Jan 2015 19:21:57 +0000 (20:21 +0100)
modules/demux/dash/mpd/MPD.cpp
modules/demux/dash/mpd/MPD.h

index c0cd432..21d5159 100644 (file)
@@ -28,6 +28,7 @@
 #include "MPD.h"
 #include "Helper.h"
 #include "dash.hpp"
 #include "MPD.h"
 #include "Helper.h"
 #include "dash.hpp"
+#include "SegmentTimeline.h"
 #include <vlc_common.h>
 #include <vlc_stream.h>
 
 #include <vlc_common.h>
 #include <vlc_stream.h>
 
@@ -59,7 +60,7 @@ MPD::~MPD   ()
     delete(programInfo.Get());
 }
 
     delete(programInfo.Get());
 }
 
-const std::vector<Period*>&    MPD::getPeriods             () const
+const std::vector<Period*>&    MPD::getPeriods             ()
 {
     return this->periods;
 }
 {
     return this->periods;
 }
@@ -110,7 +111,7 @@ vlc_object_t * MPD::getVLCObject() const
     return VLC_OBJECT(stream);
 }
 
     return VLC_OBJECT(stream);
 }
 
-Period* MPD::getFirstPeriod() const
+Period* MPD::getFirstPeriod()
 {
     std::vector<Period *> periods = getPeriods();
 
 {
     std::vector<Period *> periods = getPeriods();
 
@@ -132,3 +133,19 @@ Period* MPD::getNextPeriod(Period *period)
 
     return NULL;
 }
 
     return NULL;
 }
+
+void MPD::mergeWith(MPD *updatedMPD)
+{
+    availabilityEndTime.Set(updatedMPD->availabilityEndTime.Get());
+    /* Only merge timelines for now */
+    for(size_t i = 0; i < periods.size() && i < updatedMPD->periods.size(); i++)
+    {
+        std::vector<SegmentTimeline *> timelines;
+        std::vector<SegmentTimeline *> timelinesUpdate;
+        periods.at(i)->collectTimelines(&timelines);
+        updatedMPD->periods.at(i)->collectTimelines(&timelinesUpdate);
+
+        for(size_t j = 0; j < timelines.size() && j < timelinesUpdate.size(); j++)
+            timelines.at(j)->mergeWith(*timelinesUpdate.at(j));
+    }
+}
index 96c2100..0f9eb02 100644 (file)
@@ -56,10 +56,12 @@ namespace dash
                 virtual Url         getUrlSegment() const; /* impl */
                 vlc_object_t *      getVLCObject()  const;
 
                 virtual Url         getUrlSegment() const; /* impl */
                 vlc_object_t *      getVLCObject()  const;
 
-                virtual const std::vector<Period *>&    getPeriods() const;
-                virtual Period*                         getFirstPeriod() const;
+                virtual const std::vector<Period *>&    getPeriods();
+                virtual Period*                         getFirstPeriod();
                 virtual Period*                         getNextPeriod(Period *period);
 
                 virtual Period*                         getNextPeriod(Period *period);
 
+                void                mergeWith(MPD *);
+
                 Property<time_t>                    duration;
                 Property<time_t>                    playbackStart;
                 Property<time_t>                    availabilityEndTime;
                 Property<time_t>                    duration;
                 Property<time_t>                    playbackStart;
                 Property<time_t>                    availabilityEndTime;