[vlc-commits] dash: Reworking SemgentInfo parsing

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


vlc/vlc-1.2 | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Sat Dec 24 14:31:04 2011 +0100| [09ffaf1884fcff969ef8442db5ea5bbeddec3245] | committer: Jean-Baptiste Kempf

dash: Reworking SemgentInfo parsing

Elements/attributes are now parsed once, and not everytime a getter is
called.
Also, mandatory elements are now checked, also at parsing time.

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

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

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

 modules/stream_filter/dash/mpd/BasicCMParser.cpp |   51 ++++++++++++++++-----
 modules/stream_filter/dash/mpd/BasicCMParser.h   |    4 +-
 modules/stream_filter/dash/mpd/SegmentInfo.cpp   |   26 +++++++----
 modules/stream_filter/dash/mpd/SegmentInfo.h     |   10 +++--
 4 files changed, 64 insertions(+), 27 deletions(-)

diff --git a/modules/stream_filter/dash/mpd/BasicCMParser.cpp b/modules/stream_filter/dash/mpd/BasicCMParser.cpp
index 6c37dc8..339406a 100644
--- a/modules/stream_filter/dash/mpd/BasicCMParser.cpp
+++ b/modules/stream_filter/dash/mpd/BasicCMParser.cpp
@@ -30,6 +30,9 @@
 #include <cstdlib>
 #include <sstream>
 
+#include <vlc_common.h>
+#include <vlc_strings.h>
+
 using namespace dash::mpd;
 using namespace dash::xml;
 
@@ -133,9 +136,12 @@ void    BasicCMParser::setRepresentations   (Node *root, Group *group)
         if ( it != attributes.end() )
             this->handleDependencyId( rep, group, it->second );
 
-        this->setSegmentInfo(representations.at(i), rep);
-        if ( rep->getSegmentInfo() && rep->getSegmentInfo()->getSegments().size() > 0 )
-            group->addRepresentation(rep);        
+        if ( this->setSegmentInfo(representations.at(i), rep) == false )
+        {
+            delete rep;
+            continue ;
+        }
+        group->addRepresentation(rep);
     }
 }
 
@@ -154,39 +160,60 @@ void    BasicCMParser::handleDependencyId( Representation *rep, const Group *gro
     }
 }
 
-void    BasicCMParser::setSegmentInfo       (Node *root, Representation *rep)
+bool    BasicCMParser::setSegmentInfo       (Node *root, Representation *rep)
 {
     Node    *segmentInfo = DOMHelper::getFirstChildElementByName( root, "SegmentInfo");
 
     if ( segmentInfo )
     {
-        SegmentInfo *info = new SegmentInfo( segmentInfo->getAttributes() );
+        const std::map<std::string, std::string> attr = segmentInfo->getAttributes();
+
+        SegmentInfo *info = new SegmentInfo();
+        //Init segment is not mandatory.
         this->setInitSegment( segmentInfo, info );
-        this->setSegments(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;
     }
+    return false;
 }
 
 void    BasicCMParser::setInitSegment       (Node *root, SegmentInfo *info)
 {
-    std::vector<Node *> initSeg = DOMHelper::getChildElementByTagName(root, "InitialisationSegmentURL");
+    const std::vector<Node *> initSeg = DOMHelper::getChildElementByTagName(root, "InitialisationSegmentURL");
 
-    for(size_t i = 0; i < initSeg.size(); i++)
+    if (  initSeg.size() > 1 )
+        std::cerr << "There could be at most one InitialisationSegmentURL per SegmentInfo"
+                     " other InitialisationSegmentURL will be dropped." << std::endl;
+    if ( initSeg.size() == 1 )
     {
-        InitSegment *seg = new InitSegment(initSeg.at(i)->getAttributes());
-        info->setInitSegment(seg);
-        return;
+        InitSegment *seg = new InitSegment( initSeg.at(0)->getAttributes() );
+        info->setInitSegment( seg );
     }
 }
-void    BasicCMParser::setSegments          (Node *root, SegmentInfo *info)
+
+bool    BasicCMParser::setSegments          (Node *root, SegmentInfo *info)
 {
     std::vector<Node *> segments = DOMHelper::getElementByTagName(root, "Url", false);
 
+    if ( segments.size() == 0 )
+        return false;
     for(size_t i = 0; i < segments.size(); i++)
     {
         Segment *seg = new Segment(segments.at(i)->getAttributes());
         info->addSegment(seg);
     }
+    return true;
 }
 MPD*    BasicCMParser::getMPD               ()
 {
diff --git a/modules/stream_filter/dash/mpd/BasicCMParser.h b/modules/stream_filter/dash/mpd/BasicCMParser.h
index 2c867dc..dbc80eb 100644
--- a/modules/stream_filter/dash/mpd/BasicCMParser.h
+++ b/modules/stream_filter/dash/mpd/BasicCMParser.h
@@ -61,9 +61,9 @@ namespace dash
                 void    setPeriods          (dash::xml::Node *root);
                 void    setGroups           (dash::xml::Node *root, Period *period);
                 void    setRepresentations  (dash::xml::Node *root, Group *group);
-                void    setSegmentInfo      (dash::xml::Node *root, Representation *rep);
+                bool    setSegmentInfo      (dash::xml::Node *root, Representation *rep);
                 void    setInitSegment      (dash::xml::Node *root, SegmentInfo *info);
-                void    setSegments         (dash::xml::Node *root, SegmentInfo *info);
+                bool    setSegments         (dash::xml::Node *root, SegmentInfo *info);
                 void    setMPDBaseUrl       (dash::xml::Node *root);
                 bool    parseCommonAttributesElements( dash::xml::Node *node, CommonAttributesElements *common ) const;
         };
diff --git a/modules/stream_filter/dash/mpd/SegmentInfo.cpp b/modules/stream_filter/dash/mpd/SegmentInfo.cpp
index c7d7126..6c60142 100644
--- a/modules/stream_filter/dash/mpd/SegmentInfo.cpp
+++ b/modules/stream_filter/dash/mpd/SegmentInfo.cpp
@@ -30,9 +30,9 @@
 using namespace dash::mpd;
 using namespace dash::exception;
 
-SegmentInfo::SegmentInfo( const std::map<std::string,std::string>& attr) :
-    attributes( attr ),
-    initSeg( NULL )
+SegmentInfo::SegmentInfo() :
+    initSeg( NULL ),
+    duration( -1 )
 {
 }
 
@@ -44,14 +44,16 @@ SegmentInfo::~SegmentInfo   ()
     delete(this->initSeg);
 }
 
-InitSegment*            SegmentInfo::getInitSegment     () throw(ElementNotPresentException)
+InitSegment*            SegmentInfo::getInitSegment() const
 {
-    if(this->initSeg == NULL)
-        throw ElementNotPresentException();
-
     return this->initSeg;
 }
 
+void                    SegmentInfo::setInitSegment( InitSegment *initSeg )
+{
+    this->initSeg = initSeg;
+}
+
 const std::vector<Segment*>&   SegmentInfo::getSegments        () const
 {
     return this->segments;
@@ -62,7 +64,13 @@ void                    SegmentInfo::addSegment         (Segment *seg)
     this->segments.push_back(seg);
 }
 
-void                    SegmentInfo::setInitSegment     (InitSegment *initSeg)
+time_t      SegmentInfo::getDuration() const
 {
-    this->initSeg = initSeg;
+    return this->duration;
+}
+
+void        SegmentInfo::setDuration( time_t duration )
+{
+    if ( duration >= 0 )
+        this->duration = duration;
 }
diff --git a/modules/stream_filter/dash/mpd/SegmentInfo.h b/modules/stream_filter/dash/mpd/SegmentInfo.h
index 120ec14..b96a054 100644
--- a/modules/stream_filter/dash/mpd/SegmentInfo.h
+++ b/modules/stream_filter/dash/mpd/SegmentInfo.h
@@ -40,17 +40,19 @@ namespace dash
         class SegmentInfo
         {
             public:
-                SegmentInfo             ( const std::map<std::string, std::string>& attr);
+                SegmentInfo             ();
                 virtual ~SegmentInfo    ();
 
-                InitSegment*            getInitSegment  () throw(dash::exception::ElementNotPresentException);
+                InitSegment*            getInitSegment() const;
+                void                    setInitSegment( InitSegment *seg );
+                time_t                  getDuration() const;
+                void                    setDuration( time_t duration );
                 const std::vector<Segment *>&   getSegments () const;
-                void                    setInitSegment  (InitSegment *initSeg);
                 void                    addSegment      (Segment *seg);
 
             private:
-                std::map<std::string, std::string>  attributes;
                 InitSegment                         *initSeg;
+                time_t                              duration;
                 std::vector<Segment *>              segments;
         };
     }



More information about the vlc-commits mailing list