Commit 7219b037 authored by Francois Cartegnie's avatar Francois Cartegnie

stream_filter: dash: deduplicate parser code

parent 84bff07d
...@@ -44,6 +44,7 @@ libdash_plugin_la_SOURCES = \ ...@@ -44,6 +44,7 @@ libdash_plugin_la_SOURCES = \
stream_filter/dash/mpd/ContentDescription.h \ stream_filter/dash/mpd/ContentDescription.h \
stream_filter/dash/mpd/IMPDManager.h \ stream_filter/dash/mpd/IMPDManager.h \
stream_filter/dash/mpd/IMPDManager.cpp \ stream_filter/dash/mpd/IMPDManager.cpp \
stream_filter/dash/mpd/IMPDParser.cpp \
stream_filter/dash/mpd/IMPDParser.h \ stream_filter/dash/mpd/IMPDParser.h \
stream_filter/dash/mpd/IsoffMainParser.cpp \ stream_filter/dash/mpd/IsoffMainParser.cpp \
stream_filter/dash/mpd/IsoffMainParser.h \ stream_filter/dash/mpd/IsoffMainParser.h \
......
...@@ -30,23 +30,18 @@ ...@@ -30,23 +30,18 @@
#include "mpd/SegmentInfoDefault.h" #include "mpd/SegmentInfoDefault.h"
#include "mpd/SegmentTemplate.h" #include "mpd/SegmentTemplate.h"
#include "mpd/SegmentTimeline.h" #include "mpd/SegmentTimeline.h"
#include "xml/DOMHelper.h"
#include <cstdlib> #include <cstdlib>
#include <sstream> #include <sstream>
#include <sstream>
#include <vlc_common.h>
#include <vlc_stream.h>
#include <vlc_strings.h> #include <vlc_strings.h>
using namespace dash::mpd; using namespace dash::mpd;
using namespace dash::xml; using namespace dash::xml;
BasicCMParser::BasicCMParser( Node *root, stream_t *p_stream ) : BasicCMParser::BasicCMParser( Node *root_, stream_t *p_stream ) :
root( root ), IMPDParser( root_, NULL, p_stream, NULL )
mpd( NULL ),
p_stream( p_stream ),
currentRepresentation( NULL )
{ {
this->url = p_stream->psz_access; this->url = p_stream->psz_access;
this->url += "://"; this->url += "://";
...@@ -65,10 +60,6 @@ BasicCMParser::~BasicCMParser () ...@@ -65,10 +60,6 @@ BasicCMParser::~BasicCMParser ()
} }
bool BasicCMParser::parse () bool BasicCMParser::parse ()
{
return this->setMPD();
}
bool BasicCMParser::setMPD()
{ {
const std::map<std::string, std::string> attr = this->root->getAttributes(); const std::map<std::string, std::string> attr = this->root->getAttributes();
this->mpd = new MPD; this->mpd = new MPD;
...@@ -136,28 +127,6 @@ bool BasicCMParser::setMPD() ...@@ -136,28 +127,6 @@ bool BasicCMParser::setMPD()
this->mpd->setProgramInformation( this->parseProgramInformation() ); this->mpd->setProgramInformation( this->parseProgramInformation() );
return true; 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) void BasicCMParser::parseSegmentTimeline(Node *node, SegmentInfoCommon *segmentInfo)
{ {
...@@ -243,7 +212,7 @@ void BasicCMParser::parseSegmentInfoDefault(Node *node, AdaptationSet *group) ...@@ -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); std::vector<Node *> adaptSets = DOMHelper::getElementByTagName(root, "AdaptationSet", false);
if ( adaptSets.size() == 0 ) //In some old file, AdaptationSet may still be called Group 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 ...@@ -519,11 +488,6 @@ bool BasicCMParser::resolveUrlTemplates( std::string &url, bool &containRunti
return true; return true;
} }
MPD* BasicCMParser::getMPD()
{
return this->mpd;
}
void BasicCMParser::parseContentDescriptor(Node *node, const std::string &name, void (CommonAttributesElements::*addPtr)(ContentDescription *), CommonAttributesElements *self) const void BasicCMParser::parseContentDescriptor(Node *node, const std::string &name, void (CommonAttributesElements::*addPtr)(ContentDescription *), CommonAttributesElements *self) const
{ {
std::vector<Node*> descriptors = DOMHelper::getChildElementByTagName( node, name ); std::vector<Node*> descriptors = DOMHelper::getChildElementByTagName( node, name );
......
...@@ -26,12 +26,8 @@ ...@@ -26,12 +26,8 @@
#define BASICCMPARSER_H_ #define BASICCMPARSER_H_
#include "xml/Node.h" #include "xml/Node.h"
#include "xml/DOMHelper.h"
#include "mpd/IMPDParser.h" #include "mpd/IMPDParser.h"
#include "mpd/MPD.h"
#include "mpd/Period.h"
#include "mpd/AdaptationSet.h" #include "mpd/AdaptationSet.h"
#include "mpd/Representation.h"
#include "mpd/BaseUrl.h" #include "mpd/BaseUrl.h"
#include "mpd/SegmentInfo.h" #include "mpd/SegmentInfo.h"
#include "mpd/Segment.h" #include "mpd/Segment.h"
...@@ -49,25 +45,21 @@ namespace dash ...@@ -49,25 +45,21 @@ namespace dash
virtual ~BasicCMParser(); virtual ~BasicCMParser();
bool parse (); bool parse ();
MPD* getMPD ();
private: private:
void handleDependencyId( Representation* rep, const AdaptationSet* adaptationSet, const std::string& dependencyId ); void handleDependencyId( Representation* rep, const AdaptationSet* adaptationSet, const std::string& dependencyId );
private: private:
bool setMPD ();
void setPeriods (dash::xml::Node *root);
void parseSegmentTimeline( xml::Node* node, SegmentInfoCommon *segmentInfo ); void parseSegmentTimeline( xml::Node* node, SegmentInfoCommon *segmentInfo );
void parseSegmentInfoCommon( xml::Node* node, SegmentInfoCommon *segmentInfo ); void parseSegmentInfoCommon( xml::Node* node, SegmentInfoCommon *segmentInfo );
void parseSegmentInfoDefault( xml::Node* node, AdaptationSet* group ); 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 parseTrickMode( dash::xml::Node *node, Representation *repr );
void setRepresentations (dash::xml::Node *root, AdaptationSet *group); void setRepresentations (dash::xml::Node *root, AdaptationSet *group);
bool setSegmentInfo (dash::xml::Node *root, Representation *rep); bool setSegmentInfo (dash::xml::Node *root, Representation *rep);
void setInitSegment (dash::xml::Node *root, SegmentInfoCommon *info); void setInitSegment (dash::xml::Node *root, SegmentInfoCommon *info);
bool setSegments (dash::xml::Node *root, SegmentInfo *info ); bool setSegments (dash::xml::Node *root, SegmentInfo *info );
bool resolveUrlTemplates( std::string &url, bool &containRuntimeToken ); bool resolveUrlTemplates( std::string &url, bool &containRuntimeToken );
void setMPDBaseUrl (dash::xml::Node *root);
void parseContentDescriptor( xml::Node *node, const std::string &name, void parseContentDescriptor( xml::Node *node, const std::string &name,
void (CommonAttributesElements::*addPtr)(ContentDescription*), void (CommonAttributesElements::*addPtr)(ContentDescription*),
CommonAttributesElements *self ) const; CommonAttributesElements *self ) const;
...@@ -78,11 +70,7 @@ namespace dash ...@@ -78,11 +70,7 @@ namespace dash
ProgramInformation* parseProgramInformation(); ProgramInformation* parseProgramInformation();
private: private:
dash::xml::Node *root;
MPD *mpd;
std::string url; std::string url;
stream_t *p_stream;
Representation *currentRepresentation;
}; };
} }
} }
......
/*
* 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;
}
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
#define IMPDPARSER_H_ #define IMPDPARSER_H_
#include "mpd/MPD.h" #include "mpd/MPD.h"
#include "xml/DOMParser.h"
#include <vlc_common.h>
namespace dash namespace dash
{ {
...@@ -34,9 +37,19 @@ namespace dash ...@@ -34,9 +37,19 @@ namespace dash
class IMPDParser class IMPDParser
{ {
public: public:
virtual bool parse () = 0; IMPDParser(dash::xml::Node *, MPD*, stream_t*, Representation*);
virtual MPD* getMPD () = 0;
virtual ~IMPDParser(){} 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;
}; };
} }
} }
......
...@@ -27,15 +27,14 @@ ...@@ -27,15 +27,14 @@
#endif #endif
#include "IsoffMainParser.h" #include "IsoffMainParser.h"
#include "xml/DOMHelper.h"
#include <vlc_strings.h>
using namespace dash::mpd; using namespace dash::mpd;
using namespace dash::xml; using namespace dash::xml;
IsoffMainParser::IsoffMainParser (Node *root, stream_t *p_stream) : IsoffMainParser::IsoffMainParser (Node *root, stream_t *p_stream) :
root (root), IMPDParser(root, NULL, p_stream, NULL)
p_stream (p_stream),
mpd (NULL),
currentRepresentation( NULL )
{ {
} }
IsoffMainParser::~IsoffMainParser () IsoffMainParser::~IsoffMainParser ()
...@@ -44,19 +43,14 @@ IsoffMainParser::~IsoffMainParser () ...@@ -44,19 +43,14 @@ IsoffMainParser::~IsoffMainParser ()
bool IsoffMainParser::parse () bool IsoffMainParser::parse ()
{ {
this->mpd = new MPD(); mpd = new MPD();
setMPDAttributes();
this->setMPDAttributes(); setMPDBaseUrl(root);
this->setMPDBaseUrl(); setPeriods(root);
this->setPeriods(); print();
this->print();
return true; return true;
} }
MPD* IsoffMainParser::getMPD ()
{
return this->mpd;
}
void IsoffMainParser::setMPDAttributes () void IsoffMainParser::setMPDAttributes ()
{ {
const std::map<std::string, std::string> attr = this->root->getAttributes(); const std::map<std::string, std::string> attr = this->root->getAttributes();
...@@ -72,27 +66,7 @@ void IsoffMainParser::setMPDAttributes () ...@@ -72,27 +66,7 @@ void IsoffMainParser::setMPDAttributes ()
this->mpd->setMinBufferTime(str_duration( it->second.c_str())); 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) void IsoffMainParser::setAdaptationSets (Node *periodNode, Period *period)
{ {
std::vector<Node *> adaptationSets = DOMHelper::getElementByTagName(periodNode, "AdaptationSet", false); std::vector<Node *> adaptationSets = DOMHelper::getElementByTagName(periodNode, "AdaptationSet", false);
......
...@@ -26,12 +26,8 @@ ...@@ -26,12 +26,8 @@
#define ISOFFMAINPARSER_H_ #define ISOFFMAINPARSER_H_
#include "xml/Node.h" #include "xml/Node.h"
#include "xml/DOMHelper.h"
#include "mpd/IMPDParser.h" #include "mpd/IMPDParser.h"
#include "mpd/MPD.h"
#include "mpd/Period.h"
#include "mpd/AdaptationSet.h" #include "mpd/AdaptationSet.h"
#include "mpd/Representation.h"
#include "mpd/BaseUrl.h" #include "mpd/BaseUrl.h"
#include "mpd/SegmentBase.h" #include "mpd/SegmentBase.h"
#include "mpd/SegmentList.h" #include "mpd/SegmentList.h"
...@@ -40,10 +36,6 @@ ...@@ -40,10 +36,6 @@
#include <cstdlib> #include <cstdlib>
#include <sstream> #include <sstream>
#include <vlc_common.h>
#include <vlc_stream.h>
#include <vlc_strings.h>
namespace dash namespace dash
{ {
namespace mpd namespace mpd
...@@ -55,18 +47,10 @@ namespace dash ...@@ -55,18 +47,10 @@ namespace dash
virtual ~IsoffMainParser (); virtual ~IsoffMainParser ();
bool parse (); bool parse ();
MPD* getMPD ();
void print (); void print ();
private: private:
dash::xml::Node *root;
stream_t *p_stream;
MPD *mpd;
Representation *currentRepresentation;
void setMPDAttributes (); void setMPDAttributes ();
void setMPDBaseUrl ();
void setPeriods ();
void setAdaptationSets (dash::xml::Node *periodNode, Period *period); void setAdaptationSets (dash::xml::Node *periodNode, Period *period);
void setRepresentations (dash::xml::Node *adaptationSetNode, AdaptationSet *adaptationSet); void setRepresentations (dash::xml::Node *adaptationSetNode, AdaptationSet *adaptationSet);
void setSegmentBase (dash::xml::Node *repNode, Representation *rep); void setSegmentBase (dash::xml::Node *repNode, Representation *rep);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment