[vlc-commits] dash: Parsing SegmentInfoDefault & SegmentTimeline elements.

Hugo Beauzée-Luyssen git at videolan.org
Tue Jan 24 23:21:59 CET 2012


vlc/vlc-1.2 | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Fri Dec 30 15:09:32 2011 +0100| [92c43bb6f045a701714aedd06ebc06f828b60dac] | committer: Jean-Baptiste Kempf

dash: Parsing SegmentInfoDefault & SegmentTimeline elements.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
(cherry picked from commit 6502b3a0c8e16ec4f2216fe037b0a1bd82de979c)

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-1.2.git/?a=commit;h=92c43bb6f045a701714aedd06ebc06f828b60dac
---

 modules/stream_filter/dash/mpd/BasicCMParser.cpp |   98 ++++++++++++++++++++--
 modules/stream_filter/dash/mpd/BasicCMParser.h   |    5 +-
 modules/stream_filter/dash/mpd/Group.cpp         |   11 +++
 modules/stream_filter/dash/mpd/Group.h           |    5 +
 4 files changed, 109 insertions(+), 10 deletions(-)

diff --git a/modules/stream_filter/dash/mpd/BasicCMParser.cpp b/modules/stream_filter/dash/mpd/BasicCMParser.cpp
index ae7d4dc..d72334b 100644
--- a/modules/stream_filter/dash/mpd/BasicCMParser.cpp
+++ b/modules/stream_filter/dash/mpd/BasicCMParser.cpp
@@ -27,6 +27,8 @@
 
 #include "BasicCMParser.h"
 #include "mpd/ContentDescription.h"
+#include "mpd/SegmentInfoDefault.h"
+#include "mpd/SegmentTimeline.h"
 
 #include <cstdlib>
 #include <sstream>
@@ -149,6 +151,90 @@ void    BasicCMParser::setPeriods           (Node *root)
     }
 }
 
+void BasicCMParser::parseSegmentTimeline(Node *node, SegmentInfoCommon *segmentInfo)
+{
+    Node*   segmentTimelineNode = DOMHelper::getFirstChildElementByName( node, "SegmentTimeline" );
+    if ( segmentTimelineNode )
+    {
+        SegmentTimeline     *segmentTimeline = new SegmentTimeline;
+        std::vector<Node*>  sNodes = DOMHelper::getChildElementByTagName( segmentTimelineNode, "S" );
+        std::vector<Node*>::const_iterator  it = sNodes.begin();
+        std::vector<Node*>::const_iterator  end = sNodes.end();
+
+        while ( it != end )
+        {
+            SegmentTimeline::Element*    s = new SegmentTimeline::Element;
+            const std::map<std::string, std::string>    sAttr = (*it)->getAttributes();
+            std::map<std::string, std::string>::const_iterator  sIt;
+
+            sIt = sAttr.find( "t" );
+            if ( sIt == sAttr.end() )
+            {
+                std::cerr << "'t' attribute is mandatory for every SegmentTimeline/S element" << std::endl;
+                delete s;
+                ++it;
+                continue ;
+            }
+            s->t = atoll( sIt->second.c_str() );
+            sIt = sAttr.find( "d" );
+            if ( sIt == sAttr.end() )
+            {
+                std::cerr << "'d' attribute is mandatory for every SegmentTimeline/S element" << std::endl;
+                delete s;
+                ++it;
+                continue ;
+            }
+            s->d = atoll( sIt->second.c_str() );
+            sIt = sAttr.find( "r" );
+            if ( sIt != sAttr.end() )
+                s->r = atoi( sIt->second.c_str() );
+            segmentTimeline->addElement( s );
+            ++it;
+        }
+        segmentInfo->setSegmentTimeline( segmentTimeline );
+    }
+}
+
+void BasicCMParser::parseSegmentInfoCommon(Node *node, SegmentInfoCommon *segmentInfo)
+{
+    const std::map<std::string, std::string>            attr = node->getAttributes();
+
+    const std::vector<Node*>            baseUrls = DOMHelper::getChildElementByTagName( node, "BaseURL" );
+    if ( baseUrls.size() > 0 )
+    {
+        std::vector<Node*>::const_iterator  it = baseUrls.begin();
+        std::vector<Node*>::const_iterator  end = baseUrls.end();
+        while ( it != end )
+        {
+            segmentInfo->appendBaseURL( (*it)->getText() );
+            ++it;
+        }
+    }
+    std::map<std::string, std::string>::const_iterator  it = attr.begin();
+
+    this->setInitSegment( node, segmentInfo );
+    it = attr.find( "duration" );
+    if ( it != attr.end() )
+        segmentInfo->setDuration( str_duration( it->second.c_str() ) );
+    it = attr.find( "startIndex" );
+    if ( it != attr.end() )
+        segmentInfo->setStartIndex( atoi( it->second.c_str() ) );
+    this->parseSegmentTimeline( node, segmentInfo );
+}
+
+void BasicCMParser::parseSegmentInfoDefault(Node *node, Group *group)
+{
+    Node*   segmentInfoDefaultNode = DOMHelper::getFirstChildElementByName( node, "SegmentInfoDefault" );
+
+    if ( segmentInfoDefaultNode != NULL )
+    {
+        SegmentInfoDefault* segInfoDef = new SegmentInfoDefault;
+        this->parseSegmentInfoCommon( segmentInfoDefaultNode, segInfoDef );
+
+        group->setSegmentInfoDefault( segInfoDef );
+    }
+}
+
 void    BasicCMParser::setGroups            (Node *root, Period *period)
 {
     std::vector<Node *> groups = DOMHelper::getElementByTagName(root, "Group", false);
@@ -261,19 +347,13 @@ bool    BasicCMParser::setSegmentInfo       (Node *root, Representation *rep)
         const std::map<std::string, std::string> attr = segmentInfo->getAttributes();
 
         SegmentInfo *info = new SegmentInfo();
-        //Init segment is not mandatory.
-        this->setInitSegment( segmentInfo, info );
+        this->parseSegmentInfoCommon( segmentInfo, info );
         //If we don't have any segment, there's no point keeping this SegmentInfo.
         if ( this->setSegments( segmentInfo, info ) == false )
         {
             delete info;
             return false;
         }
-        std::map<std::string, std::string>::const_iterator  it;
-        it = attr.find( "duration" );
-        if ( it != attr.end() )
-            info->setDuration( str_duration( it->second.c_str() ) );
-
         rep->setSegmentInfo( info );
         return true;
     }
@@ -316,7 +396,7 @@ ProgramInformation* BasicCMParser::parseProgramInformation()
     return pInfo;
 }
 
-void    BasicCMParser::setInitSegment       (Node *root, SegmentInfo *info)
+void    BasicCMParser::setInitSegment       (Node *root, SegmentInfoCommon *info)
 {
     const std::vector<Node *> initSeg = DOMHelper::getChildElementByTagName(root, "InitialisationSegmentURL");
 
@@ -327,7 +407,7 @@ void    BasicCMParser::setInitSegment       (Node *root, SegmentInfo *info)
     {
         Segment     *seg = new Segment();
         parseSegment( seg, initSeg.at(0)->getAttributes() );
-        info->setInitSegment( seg );
+        info->setInitialisationSegment( seg );
     }
 }
 
diff --git a/modules/stream_filter/dash/mpd/BasicCMParser.h b/modules/stream_filter/dash/mpd/BasicCMParser.h
index 0d3328a..e76f577 100644
--- a/modules/stream_filter/dash/mpd/BasicCMParser.h
+++ b/modules/stream_filter/dash/mpd/BasicCMParser.h
@@ -57,11 +57,14 @@ namespace dash
             private:
                 bool    setMPD              ();
                 void    setPeriods          (dash::xml::Node *root);
+                void    parseSegmentTimeline( xml::Node* node, SegmentInfoCommon *segmentInfo );
+                void    parseSegmentInfoCommon( xml::Node* node, SegmentInfoCommon *segmentInfo );
+                void    parseSegmentInfoDefault( xml::Node* node, Group* group );
                 void    setGroups           (dash::xml::Node *root, Period *period);
                 void    parseTrickMode( dash::xml::Node *node, Representation *repr );
                 void    setRepresentations  (dash::xml::Node *root, Group *group);
                 bool    setSegmentInfo      (dash::xml::Node *root, Representation *rep);
-                void    setInitSegment      (dash::xml::Node *root, SegmentInfo *info);
+                void    setInitSegment      (dash::xml::Node *root, SegmentInfoCommon *info);
                 bool    setSegments         (dash::xml::Node *root, SegmentInfo *info);
                 void    setMPDBaseUrl       (dash::xml::Node *root);
                 void    parseContentDescriptor( xml::Node *node, const std::string &name,
diff --git a/modules/stream_filter/dash/mpd/Group.cpp b/modules/stream_filter/dash/mpd/Group.cpp
index cd1bd1e..0723396 100644
--- a/modules/stream_filter/dash/mpd/Group.cpp
+++ b/modules/stream_filter/dash/mpd/Group.cpp
@@ -68,6 +68,17 @@ const Representation *Group::getRepresentationById(const std::string &id) const
     return NULL;
 }
 
+const SegmentInfoDefault *Group::getSegmentInfoDefault() const
+{
+    return this->segmentInfoDefault;
+}
+
+void Group::setSegmentInfoDefault(const SegmentInfoDefault *seg)
+{
+    if ( seg != NULL )
+        this->segmentInfoDefault = seg;
+}
+
 void                            Group::addRepresentation        (Representation *rep)
 {
     this->representations.push_back(rep);
diff --git a/modules/stream_filter/dash/mpd/Group.h b/modules/stream_filter/dash/mpd/Group.h
index 11ab414..a4e7985 100644
--- a/modules/stream_filter/dash/mpd/Group.h
+++ b/modules/stream_filter/dash/mpd/Group.h
@@ -36,6 +36,8 @@ namespace dash
 {
     namespace mpd
     {
+        class SegmentInfoDefault;
+
         class Group : public CommonAttributesElements
         {
             public:
@@ -46,12 +48,15 @@ namespace dash
                 void                            setSubsegmentAlignmentFlag( bool alignment );
                 std::vector<Representation *>   getRepresentations      ();
                 const Representation*           getRepresentationById   ( const std::string &id ) const;
+                const SegmentInfoDefault*       getSegmentInfoDefault() const;
+                void                            setSegmentInfoDefault( const SegmentInfoDefault* seg );
 
                 void addRepresentation( Representation *rep );
 
             private:
                 bool                                subsegmentAlignmentFlag;
                 std::vector<Representation *>       representations;
+                const SegmentInfoDefault*           segmentInfoDefault;
         };
     }
 }



More information about the vlc-commits mailing list