Commit 5457d477 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen Committed by Jean-Baptiste Kempf

dash: Reworking ProgramInfo parsing.

Information are now computed once at parsing time.
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent a43d294f
...@@ -116,6 +116,7 @@ bool BasicCMParser::setMPD() ...@@ -116,6 +116,7 @@ bool BasicCMParser::setMPD()
this->setMPDBaseUrl(this->root); this->setMPDBaseUrl(this->root);
this->setPeriods(this->root); this->setPeriods(this->root);
this->mpd->setProgramInformation( this->parseProgramInformation() );
return true; return true;
} }
void BasicCMParser::setMPDBaseUrl (Node *root) void BasicCMParser::setMPDBaseUrl (Node *root)
...@@ -263,6 +264,29 @@ bool BasicCMParser::parseSegment(Segment *seg, const std::map<std::string, std:: ...@@ -263,6 +264,29 @@ bool BasicCMParser::parseSegment(Segment *seg, const std::map<std::string, std::
return true; return true;
} }
ProgramInformation* BasicCMParser::parseProgramInformation()
{
Node* pInfoNode = DOMHelper::getFirstChildElementByName( this->root, "ProgramInformation" );
if ( pInfoNode == NULL )
return NULL;
ProgramInformation *pInfo = new ProgramInformation;
const std::map<std::string, std::string> attr = pInfoNode->getAttributes();
std::map<std::string, std::string>::const_iterator it;
it = attr.find( "moreInformationURL" );
if ( it != attr.end() )
pInfo->setMoreInformationUrl( it->second );
Node* title = DOMHelper::getFirstChildElementByName( pInfoNode, "Title" );
if ( title )
pInfo->setTitle( title->getText() );
Node* source = DOMHelper::getFirstChildElementByName( pInfoNode, "Source" );
if ( source )
pInfo->setSource( source->getText() );
Node* copyright = DOMHelper::getFirstChildElementByName( pInfoNode, "copyright" );
if ( copyright )
pInfo->setCopyright( copyright->getText() );
return pInfo;
}
void BasicCMParser::setInitSegment (Node *root, SegmentInfo *info) void BasicCMParser::setInitSegment (Node *root, SegmentInfo *info)
{ {
const std::vector<Node *> initSeg = DOMHelper::getChildElementByTagName(root, "InitialisationSegmentURL"); const std::vector<Node *> initSeg = DOMHelper::getChildElementByTagName(root, "InitialisationSegmentURL");
......
...@@ -66,6 +66,7 @@ namespace dash ...@@ -66,6 +66,7 @@ namespace dash
void setMPDBaseUrl (dash::xml::Node *root); void setMPDBaseUrl (dash::xml::Node *root);
bool parseCommonAttributesElements( dash::xml::Node *node, CommonAttributesElements *common ) const; bool parseCommonAttributesElements( dash::xml::Node *node, CommonAttributesElements *common ) const;
bool parseSegment( Segment *seg, const std::map<std::string, std::string> &attr ); bool parseSegment( Segment *seg, const std::map<std::string, std::string> &attr );
ProgramInformation* parseProgramInformation();
}; };
} }
} }
......
...@@ -109,13 +109,11 @@ void MPD::setTimeShiftBufferDepth(time_t depth) ...@@ -109,13 +109,11 @@ void MPD::setTimeShiftBufferDepth(time_t depth)
this->timeShiftBufferDepth = depth; this->timeShiftBufferDepth = depth;
} }
ProgramInformation* MPD::getProgramInformation () throw(ElementNotPresentException) const ProgramInformation* MPD::getProgramInformation () const
{ {
if(this->programInfo == NULL)
throw ElementNotPresentException();
return this->programInfo; return this->programInfo;
} }
void MPD::addBaseUrl (BaseUrl *url) void MPD::addBaseUrl (BaseUrl *url)
{ {
this->baseUrls.push_back(url); this->baseUrls.push_back(url);
......
...@@ -63,9 +63,9 @@ namespace dash ...@@ -63,9 +63,9 @@ namespace dash
void setMinBufferTime( time_t time ); void setMinBufferTime( time_t time );
time_t getTimeShiftBufferDepth() const; time_t getTimeShiftBufferDepth() const;
void setTimeShiftBufferDepth( time_t depth ); void setTimeShiftBufferDepth( time_t depth );
const std::vector<BaseUrl *>& getBaseUrls () const; const std::vector<BaseUrl *>& getBaseUrls() const;
const std::vector<Period *>& getPeriods () const; const std::vector<Period *>& getPeriods() const;
ProgramInformation* getProgramInformation () throw(dash::exception::ElementNotPresentException); const ProgramInformation* getProgramInformation() const;
void addPeriod (Period *period); void addPeriod (Period *period);
void addBaseUrl (BaseUrl *url); void addBaseUrl (BaseUrl *url);
......
...@@ -30,52 +30,41 @@ ...@@ -30,52 +30,41 @@
using namespace dash::mpd; using namespace dash::mpd;
using namespace dash::exception; using namespace dash::exception;
ProgramInformation::ProgramInformation (std::map<std::string, std::string> attr) const std::string &ProgramInformation::getSource() const
{
this->attributes = attr;
}
ProgramInformation::~ProgramInformation ()
{ {
return this->source;
} }
std::string ProgramInformation::getTitle () throw(ElementNotPresentException) void ProgramInformation::setSource(const std::string &source)
{ {
if(this->title.empty()) if ( source.empty() == false )
throw ElementNotPresentException(); this->source = source;
return this->title;
} }
std::string ProgramInformation::getCopyright () throw(ElementNotPresentException)
{
if(this->copyright.empty())
throw ElementNotPresentException();
const std::string &ProgramInformation::getCopyright() const
{
return this->copyright; return this->copyright;
} }
std::string ProgramInformation::getSource () throw(ElementNotPresentException)
{
if(this->source.empty())
throw ElementNotPresentException();
return this->source; void ProgramInformation::setCopyright(const std::string &copyright)
}
std::string ProgramInformation::getMoreInformationUrl () throw(AttributeNotPresentException)
{ {
if(this->attributes.find("moreInformationURL") == this->attributes.end()) if ( copyright.empty() == false )
throw AttributeNotPresentException(); this->copyright = copyright;
return this->attributes["moreInformationURL"];
} }
void ProgramInformation::setTitle (std::string title)
void ProgramInformation::setMoreInformationUrl(const std::string &url)
{ {
this->title = title; if ( url.empty() == false )
this->moreInformationUrl = url;
} }
void ProgramInformation::setCopyright (std::string copyright)
const std::string &ProgramInformation::getTitle() const
{ {
this->copyright = copyright; return this->title;
} }
void ProgramInformation::setSource (std::string source)
void ProgramInformation::setTitle (const std::string &title)
{ {
this->source = source; if ( title.empty() == false )
this->title = title;
} }
...@@ -38,23 +38,22 @@ namespace dash ...@@ -38,23 +38,22 @@ namespace dash
class ProgramInformation class ProgramInformation
{ {
public: public:
ProgramInformation (std::map<std::string, std::string> attr); virtual ~ProgramInformation(){}
virtual ~ProgramInformation ();
std::string getMoreInformationUrl () throw(dash::exception::AttributeNotPresentException); const std::string& getMoreInformationUrl() const;
std::string getTitle () throw(dash::exception::ElementNotPresentException); void setMoreInformationUrl( const std::string &url );
std::string getSource () throw(dash::exception::ElementNotPresentException); const std::string& getTitle() const;
std::string getCopyright () throw(dash::exception::ElementNotPresentException); void setTitle( const std::string &title);
const std::string& getSource() const;
void setTitle (std::string title); void setSource( const std::string &source);
void setSource (std::string source); const std::string& getCopyright() const;
void setCopyright (std::string copyright); void setCopyright( const std::string &copyright);
private: private:
std::map<std::string, std::string> attributes; std::string moreInformationUrl;
std::string title; std::string title;
std::string source; std::string source;
std::string copyright; std::string copyright;
}; };
} }
} }
......
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