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()
this->setMPDBaseUrl(this->root);
this->setPeriods(this->root);
this->mpd->setProgramInformation( this->parseProgramInformation() );
return true;
}
void BasicCMParser::setMPDBaseUrl (Node *root)
......@@ -263,6 +264,29 @@ bool BasicCMParser::parseSegment(Segment *seg, const std::map<std::string, std::
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)
{
const std::vector<Node *> initSeg = DOMHelper::getChildElementByTagName(root, "InitialisationSegmentURL");
......
......@@ -66,6 +66,7 @@ namespace dash
void setMPDBaseUrl (dash::xml::Node *root);
bool parseCommonAttributesElements( dash::xml::Node *node, CommonAttributesElements *common ) const;
bool parseSegment( Segment *seg, const std::map<std::string, std::string> &attr );
ProgramInformation* parseProgramInformation();
};
}
}
......
......@@ -109,13 +109,11 @@ void MPD::setTimeShiftBufferDepth(time_t depth)
this->timeShiftBufferDepth = depth;
}
ProgramInformation* MPD::getProgramInformation () throw(ElementNotPresentException)
const ProgramInformation* MPD::getProgramInformation () const
{
if(this->programInfo == NULL)
throw ElementNotPresentException();
return this->programInfo;
}
void MPD::addBaseUrl (BaseUrl *url)
{
this->baseUrls.push_back(url);
......
......@@ -63,9 +63,9 @@ namespace dash
void setMinBufferTime( time_t time );
time_t getTimeShiftBufferDepth() const;
void setTimeShiftBufferDepth( time_t depth );
const std::vector<BaseUrl *>& getBaseUrls () const;
const std::vector<Period *>& getPeriods () const;
ProgramInformation* getProgramInformation () throw(dash::exception::ElementNotPresentException);
const std::vector<BaseUrl *>& getBaseUrls() const;
const std::vector<Period *>& getPeriods() const;
const ProgramInformation* getProgramInformation() const;
void addPeriod (Period *period);
void addBaseUrl (BaseUrl *url);
......
......@@ -30,52 +30,41 @@
using namespace dash::mpd;
using namespace dash::exception;
ProgramInformation::ProgramInformation (std::map<std::string, std::string> attr)
{
this->attributes = attr;
}
ProgramInformation::~ProgramInformation ()
const std::string &ProgramInformation::getSource() const
{
return this->source;
}
std::string ProgramInformation::getTitle () throw(ElementNotPresentException)
void ProgramInformation::setSource(const std::string &source)
{
if(this->title.empty())
throw ElementNotPresentException();
return this->title;
if ( source.empty() == false )
this->source = source;
}
std::string ProgramInformation::getCopyright () throw(ElementNotPresentException)
{
if(this->copyright.empty())
throw ElementNotPresentException();
const std::string &ProgramInformation::getCopyright() const
{
return this->copyright;
}
std::string ProgramInformation::getSource () throw(ElementNotPresentException)
{
if(this->source.empty())
throw ElementNotPresentException();
return this->source;
}
std::string ProgramInformation::getMoreInformationUrl () throw(AttributeNotPresentException)
void ProgramInformation::setCopyright(const std::string &copyright)
{
if(this->attributes.find("moreInformationURL") == this->attributes.end())
throw AttributeNotPresentException();
return this->attributes["moreInformationURL"];
if ( copyright.empty() == false )
this->copyright = copyright;
}
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
class ProgramInformation
{
public:
ProgramInformation (std::map<std::string, std::string> attr);
virtual ~ProgramInformation ();
virtual ~ProgramInformation(){}
std::string getMoreInformationUrl () throw(dash::exception::AttributeNotPresentException);
std::string getTitle () throw(dash::exception::ElementNotPresentException);
std::string getSource () throw(dash::exception::ElementNotPresentException);
std::string getCopyright () throw(dash::exception::ElementNotPresentException);
void setTitle (std::string title);
void setSource (std::string source);
void setCopyright (std::string copyright);
const std::string& getMoreInformationUrl() const;
void setMoreInformationUrl( const std::string &url );
const std::string& getTitle() const;
void setTitle( const std::string &title);
const std::string& getSource() const;
void setSource( const std::string &source);
const std::string& getCopyright() const;
void setCopyright( const std::string &copyright);
private:
std::map<std::string, std::string> attributes;
std::string title;
std::string source;
std::string copyright;
std::string moreInformationUrl;
std::string title;
std::string source;
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