]> git.sesse.net Git - vlc/commitdiff
stream_filter: dash: deduplicate parser code
authorFrancois Cartegnie <fcvlcdev@free.fr>
Mon, 17 Nov 2014 17:08:56 +0000 (18:08 +0100)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Mon, 17 Nov 2014 17:29:29 +0000 (18:29 +0100)
modules/stream_filter/Makefile.am
modules/stream_filter/dash/mpd/BasicCMParser.cpp
modules/stream_filter/dash/mpd/BasicCMParser.h
modules/stream_filter/dash/mpd/IMPDParser.cpp [new file with mode: 0644]
modules/stream_filter/dash/mpd/IMPDParser.h
modules/stream_filter/dash/mpd/IsoffMainParser.cpp
modules/stream_filter/dash/mpd/IsoffMainParser.h

index 10adcbb7b0d2baeec718a2f0da55559bf06ee552..c64e944897e710f286a2c024e023724f41a2bd00 100644 (file)
@@ -44,6 +44,7 @@ libdash_plugin_la_SOURCES = \
     stream_filter/dash/mpd/ContentDescription.h \
     stream_filter/dash/mpd/IMPDManager.h \
     stream_filter/dash/mpd/IMPDManager.cpp \
+    stream_filter/dash/mpd/IMPDParser.cpp \
     stream_filter/dash/mpd/IMPDParser.h \
     stream_filter/dash/mpd/IsoffMainParser.cpp \
     stream_filter/dash/mpd/IsoffMainParser.h \
index 9fefc08d46f17b25c1f8dee2b5a82f0b92ad25f7..7b59f4b4e843dc323130fc7c5cd0380b6767d870 100644 (file)
 #include "mpd/SegmentInfoDefault.h"
 #include "mpd/SegmentTemplate.h"
 #include "mpd/SegmentTimeline.h"
+#include "xml/DOMHelper.h"
 
 #include <cstdlib>
 #include <sstream>
-#include <sstream>
 
-#include <vlc_common.h>
-#include <vlc_stream.h>
 #include <vlc_strings.h>
 
 using namespace dash::mpd;
 using namespace dash::xml;
 
-BasicCMParser::BasicCMParser( Node *root, stream_t *p_stream ) :
-    root( root ),
-    mpd( NULL ),
-    p_stream( p_stream ),
-    currentRepresentation( NULL )
+BasicCMParser::BasicCMParser( Node *root_, stream_t *p_stream ) :
+    IMPDParser( root_, NULL, p_stream, NULL )
 {
     this->url = p_stream->psz_access;
     this->url += "://";
@@ -65,10 +60,6 @@ BasicCMParser::~BasicCMParser   ()
 }
 
 bool    BasicCMParser::parse                ()
-{
-    return this->setMPD();
-}
-bool    BasicCMParser::setMPD()
 {
     const std::map<std::string, std::string>    attr = this->root->getAttributes();
     this->mpd = new MPD;
@@ -136,28 +127,6 @@ bool    BasicCMParser::setMPD()
     this->mpd->setProgramInformation( this->parseProgramInformation() );
     return true;
 }
-void    BasicCMParser::setMPDBaseUrl        (Node *root)
-{
-    std::vector<Node *> baseUrls = DOMHelper::getChildElementByTagName(root, "BaseURL");
-
-    for(size_t i = 0; i < baseUrls.size(); i++)
-    {
-        BaseUrl *url = new BaseUrl(baseUrls.at(i)->getText());
-        this->mpd->addBaseUrl(url);
-    }
-}
-
-void    BasicCMParser::setPeriods           (Node *root)
-{
-    std::vector<Node *> periods = DOMHelper::getElementByTagName(root, "Period", false);
-
-    for(size_t i = 0; i < periods.size(); i++)
-    {
-        Period *period = new Period();
-        this->setAdaptationSet(periods.at(i), period);
-        this->mpd->addPeriod(period);
-    }
-}
 
 void BasicCMParser::parseSegmentTimeline(Node *node, SegmentInfoCommon *segmentInfo)
 {
@@ -243,7 +212,7 @@ void BasicCMParser::parseSegmentInfoDefault(Node *node, AdaptationSet *group)
     }
 }
 
-void    BasicCMParser::setAdaptationSet            (Node *root, Period *period)
+void    BasicCMParser::setAdaptationSets(Node *root, Period *period)
 {
     std::vector<Node *> adaptSets = DOMHelper::getElementByTagName(root, "AdaptationSet", false);
     if ( adaptSets.size() == 0 ) //In some old file, AdaptationSet may still be called Group
@@ -519,11 +488,6 @@ bool    BasicCMParser::resolveUrlTemplates( std::string &url, bool &containRunti
     return true;
 }
 
-MPD*    BasicCMParser::getMPD()
-{
-    return this->mpd;
-}
-
 void BasicCMParser::parseContentDescriptor(Node *node, const std::string &name, void (CommonAttributesElements::*addPtr)(ContentDescription *), CommonAttributesElements *self) const
 {
     std::vector<Node*>  descriptors = DOMHelper::getChildElementByTagName( node, name );
index 518200561d217698d212d5d1d59faafc8df18512..91232f034c18f2d4be08fb17b37c68aed7f93946 100644 (file)
 #define BASICCMPARSER_H_
 
 #include "xml/Node.h"
-#include "xml/DOMHelper.h"
 #include "mpd/IMPDParser.h"
-#include "mpd/MPD.h"
-#include "mpd/Period.h"
 #include "mpd/AdaptationSet.h"
-#include "mpd/Representation.h"
 #include "mpd/BaseUrl.h"
 #include "mpd/SegmentInfo.h"
 #include "mpd/Segment.h"
@@ -49,25 +45,21 @@ namespace dash
                 virtual ~BasicCMParser();
 
                 bool    parse  ();
-                MPD*    getMPD ();
 
             private:
                 void    handleDependencyId( Representation* rep, const AdaptationSet* adaptationSet, const std::string& dependencyId );
 
             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, AdaptationSet* group );
-                void    setAdaptationSet           (dash::xml::Node *root, Period *period);
+                void    setAdaptationSets   (dash::xml::Node *root, Period *period);
                 void    parseTrickMode( dash::xml::Node *node, Representation *repr );
                 void    setRepresentations  (dash::xml::Node *root, AdaptationSet *group);
                 bool    setSegmentInfo      (dash::xml::Node *root, Representation *rep);
                 void    setInitSegment      (dash::xml::Node *root, SegmentInfoCommon *info);
                 bool    setSegments         (dash::xml::Node *root, SegmentInfo *info );
                 bool    resolveUrlTemplates( std::string &url, bool &containRuntimeToken );
-                void    setMPDBaseUrl       (dash::xml::Node *root);
                 void    parseContentDescriptor( xml::Node *node, const std::string &name,
                                                 void (CommonAttributesElements::*addPtr)(ContentDescription*),
                                                 CommonAttributesElements *self ) const;
@@ -78,11 +70,7 @@ namespace dash
                 ProgramInformation*     parseProgramInformation();
 
             private:
-                dash::xml::Node *root;
-                MPD             *mpd;
                 std::string     url;
-                stream_t        *p_stream;
-                Representation  *currentRepresentation;
         };
     }
 }
diff --git a/modules/stream_filter/dash/mpd/IMPDParser.cpp b/modules/stream_filter/dash/mpd/IMPDParser.cpp
new file mode 100644 (file)
index 0000000..630677b
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * IMPDParser.cpp
+ *****************************************************************************
+ * Copyright (C) 2010 - 2014 VideoLAN Authors
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#include "IMPDParser.h"
+#include "xml/DOMHelper.h"
+
+using namespace dash::mpd;
+using namespace dash::xml;
+
+IMPDParser::IMPDParser(Node *root_, MPD *mpd_, stream_t *stream, Representation *rep)
+{
+    root = root_;
+    mpd = mpd_;
+    currentRepresentation = rep;
+    p_stream = stream;
+}
+
+void IMPDParser::setMPDBaseUrl(Node *root)
+{
+    std::vector<Node *> baseUrls = DOMHelper::getChildElementByTagName(root, "BaseURL");
+
+    for(size_t i = 0; i < baseUrls.size(); i++)
+    {
+        BaseUrl *url = new BaseUrl(baseUrls.at(i)->getText());
+        mpd->addBaseUrl(url);
+    }
+}
+
+void IMPDParser::setPeriods(Node *root_)
+{
+    std::vector<Node *> periods = DOMHelper::getElementByTagName(root_, "Period", false);
+
+    for(size_t i = 0; i < periods.size(); i++)
+    {
+        Period *period = new Period();
+        setAdaptationSets(periods.at(i), period);
+        mpd->addPeriod(period);
+    }
+}
+
+MPD* IMPDParser::getMPD()
+{
+    return mpd;
+}
index ab3e69eb8915665a16573daa61f1660baaf92fa1..da82aa3df98356890a71e1a92355b2b0aedef49b 100644 (file)
@@ -26,6 +26,9 @@
 #define IMPDPARSER_H_
 
 #include "mpd/MPD.h"
+#include "xml/DOMParser.h"
+
+#include <vlc_common.h>
 
 namespace dash
 {
@@ -34,9 +37,19 @@ namespace dash
         class IMPDParser
         {
             public:
-                virtual bool    parse  () = 0;
-                virtual MPD*    getMPD () = 0;
+                IMPDParser(dash::xml::Node *, MPD*, stream_t*, Representation*);
                 virtual ~IMPDParser(){}
+                virtual bool    parse  () = 0;
+                virtual MPD*    getMPD ();
+                virtual void    setMPDBaseUrl(dash::xml::Node *root);
+                virtual void    setAdaptationSets(dash::xml::Node *periodNode, Period *period) = 0;
+                virtual void    setPeriods(dash::xml::Node *root);
+
+            protected:
+                dash::xml::Node *root;
+                MPD             *mpd;
+                stream_t        *p_stream;
+                Representation  *currentRepresentation;
         };
     }
 }
index 4d35accd7641c0b404756184aff97d484517a7c9..94c09eb8edf027787a7dfb2918eaa1f9e957c752 100644 (file)
 #endif
 
 #include "IsoffMainParser.h"
+#include "xml/DOMHelper.h"
+#include <vlc_strings.h>
 
 using namespace dash::mpd;
 using namespace dash::xml;
 
 IsoffMainParser::IsoffMainParser    (Node *root, stream_t *p_stream) :
-                 root               (root),
-                 p_stream           (p_stream),
-                 mpd                (NULL),
-                 currentRepresentation( NULL )
+                 IMPDParser(root, NULL, p_stream, NULL)
 {
 }
 IsoffMainParser::~IsoffMainParser   ()
@@ -44,19 +43,14 @@ IsoffMainParser::~IsoffMainParser   ()
 
 bool    IsoffMainParser::parse              ()
 {
-    this->mpd = new MPD();
-
-    this->setMPDAttributes();
-    this->setMPDBaseUrl();
-    this->setPeriods();
-    this->print();
-
+    mpd = new MPD();
+    setMPDAttributes();
+    setMPDBaseUrl(root);
+    setPeriods(root);
+    print();
     return true;
 }
-MPD*    IsoffMainParser::getMPD             ()
-{
-    return this->mpd;
-}
+
 void    IsoffMainParser::setMPDAttributes   ()
 {
     const std::map<std::string, std::string> attr = this->root->getAttributes();
@@ -72,27 +66,7 @@ void    IsoffMainParser::setMPDAttributes   ()
         this->mpd->setMinBufferTime(str_duration( it->second.c_str()));
 
 }
-void    IsoffMainParser::setMPDBaseUrl      ()
-{
-    std::vector<Node *> baseUrls = DOMHelper::getChildElementByTagName(this->root, "BaseURL");
-
-    for(size_t i = 0; i < baseUrls.size(); i++)
-    {
-        BaseUrl *url = new BaseUrl(baseUrls.at(i)->getText());
-        this->mpd->addBaseUrl(url);
-    }
-}
-void    IsoffMainParser::setPeriods         ()
-{
-    std::vector<Node *> periods = DOMHelper::getElementByTagName(this->root, "Period", false);
 
-    for(size_t i = 0; i < periods.size(); i++)
-    {
-        Period *period = new Period();
-        this->setAdaptationSets(periods.at(i), period);
-        this->mpd->addPeriod(period);
-    }
-}
 void    IsoffMainParser::setAdaptationSets  (Node *periodNode, Period *period)
 {
     std::vector<Node *> adaptationSets = DOMHelper::getElementByTagName(periodNode, "AdaptationSet", false);
index 20688794b78eb14541e63b3901498e91ee4fe159..84bc348b83a5c12444b8ae5881755dcbb38deaae 100644 (file)
 #define ISOFFMAINPARSER_H_
 
 #include "xml/Node.h"
-#include "xml/DOMHelper.h"
 #include "mpd/IMPDParser.h"
-#include "mpd/MPD.h"
-#include "mpd/Period.h"
 #include "mpd/AdaptationSet.h"
-#include "mpd/Representation.h"
 #include "mpd/BaseUrl.h"
 #include "mpd/SegmentBase.h"
 #include "mpd/SegmentList.h"
 #include <cstdlib>
 #include <sstream>
 
-#include <vlc_common.h>
-#include <vlc_stream.h>
-#include <vlc_strings.h>
-
 namespace dash
 {
     namespace mpd
@@ -55,18 +47,10 @@ namespace dash
                 virtual ~IsoffMainParser    ();
 
                 bool    parse  ();
-                MPD*    getMPD ();
                 void    print  ();
 
             private:
-                dash::xml::Node *root;
-                stream_t        *p_stream;
-                MPD             *mpd;
-                Representation  *currentRepresentation;
-
                 void    setMPDAttributes    ();
-                void    setMPDBaseUrl       ();
-                void    setPeriods          ();
                 void    setAdaptationSets   (dash::xml::Node *periodNode, Period *period);
                 void    setRepresentations  (dash::xml::Node *adaptationSetNode, AdaptationSet *adaptationSet);
                 void    setSegmentBase      (dash::xml::Node *repNode, Representation *rep);