Commit b412a126 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen Committed by 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's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 8f9fd197
......@@ -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 ()
{
......
......@@ -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;
};
......
......@@ -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;
}
......@@ -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;
};
}
......
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