demux: dash: parse SegmentTimeline
authorFrancois Cartegnie <fcvlcdev@free.fr>
Wed, 7 Jan 2015 01:26:18 +0000 (02:26 +0100)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Mon, 12 Jan 2015 19:21:57 +0000 (20:21 +0100)
modules/demux/dash/mpd/IsoffMainParser.cpp
modules/demux/dash/mpd/IsoffMainParser.h

index 16d3524..f781369 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "IsoffMainParser.h"
 #include "SegmentTemplate.h"
+#include "SegmentTimeline.h"
 #include "ProgramInformation.h"
 #include "xml/DOMHelper.h"
 #include <vlc_strings.h>
@@ -136,6 +137,8 @@ size_t IsoffMainParser::parseSegmentTemplate(Node *templateNode, SegmentInformat
     mediaTemplate->initialisationSegment.Set(initTemplate);
     info->setSegmentTemplate(mediaTemplate);
 
+    parseTimeline(DOMHelper::getFirstChildElementByName(templateNode, "SegmentTimeline"), mediaTemplate);
+
     total += ( mediaTemplate != NULL );
 
     return total;
@@ -340,6 +343,37 @@ void IsoffMainParser::parseInitSegment(Node *initNode, Initializable<Segment> *i
     init->initialisationSegment.Set(seg);
 }
 
+void IsoffMainParser::parseTimeline(Node *node, Timelineable *timelineable)
+{
+    if(!node)
+        return;
+
+    SegmentTimeline *timeline = new (std::nothrow) SegmentTimeline();
+    if(timeline)
+    {
+        std::vector<Node *> elements = DOMHelper::getElementByTagName(node, "S", false);
+        std::vector<Node *>::const_iterator it;
+        for(it = elements.begin(); it != elements.end(); it++)
+        {
+            const Node *s = *it;
+            if(!s->hasAttribute("d")) /* Mandatory */
+                continue;
+            mtime_t d = Integer<mtime_t>(s->getAttributeValue("d"));
+            mtime_t r = 0; // never repeats by default
+            if(s->hasAttribute("r"))
+                r = Integer<uint64_t>(s->getAttributeValue("r"));
+            if(s->hasAttribute("t"))
+            {
+                mtime_t t = Integer<mtime_t>(s->getAttributeValue("t"));
+                timeline->addElement(d, r, t);
+            }
+            else timeline->addElement(d, r);
+
+            timelineable->segmentTimeline.Set(timeline);
+        }
+    }
+}
+
 void IsoffMainParser::parseProgramInformation(Node * node, MPD *mpd)
 {
     if(!node)
index ba36e11..0891b37 100644 (file)
@@ -54,6 +54,7 @@ namespace dash
                 void    setAdaptationSets   (dash::xml::Node *periodNode, Period *period);
                 void    setRepresentations  (dash::xml::Node *adaptationSetNode, AdaptationSet *adaptationSet);
                 void    parseInitSegment    (dash::xml::Node *, Initializable<Segment> *);
+                void    parseTimeline       (dash::xml::Node *, Timelineable *);
                 void    parsePeriods        (dash::xml::Node *);
                 size_t  parseSegmentInformation(dash::xml::Node *, SegmentInformation *);
                 void    parseSegmentBase    (dash::xml::Node *, SegmentInformation *);