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

dash: Reworking MPD attributes parsing.

Mandatory elements are now checked.
Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 04be885b
......@@ -49,17 +49,74 @@ bool BasicCMParser::parse ()
this->setMPD();
return true;
}
void BasicCMParser::setMPD ()
bool BasicCMParser::setMPD()
{
const std::map<std::string, std::string> attr = this->root->getAttributes();
this->mpd = new MPD( attr );
this->mpd = new MPD;
std::map<std::string, std::string>::const_iterator it;
it = attr.find( "profile" );
if ( it != attr.end() )
this->mpd->setProfile( it->second );
it = attr.find("mediaPresentationDuration");
/*
Standard specifies a default of "On-Demand",
so anything that is not "Live" is "On-Demand"
*/
this->mpd->setLive( it != attr.end() && it->second == "Live" );
it = attr.find( "availabilityStartTime" );
if ( it == attr.end() && this->mpd->isLive() == true )
{
std::cerr << "An @availabilityStartTime attribute must be specified when"
" the stream @type is Live" << std::endl;
return false;
}
if ( it != attr.end() )
{
struct tm t;
char *res = strptime( it->second.c_str(), "%Y-%m-%dT%T", &t );
if ( res == NULL )
{
if ( this->mpd->isLive() == true )
{
std::cerr << "An @availabilityStartTime attribute must be specified when"
" the stream @type is Live" << std::endl;
return false;
}
}
else
this->mpd->setAvailabilityStartTime( mktime( &t ) );
}
it = attr.find( "availabilityEndTime" );
if ( it != attr.end() )
{
struct tm t;
char *res = strptime( it->second.c_str(), "%Y-%m-%dT%T", &t );
if ( res != NULL )
this->mpd->setAvailabilityEndTime( mktime( &t ) );
}
it = attr.find( "mediaPresentationDuration" );
if ( it != attr.end() )
this->mpd->setDuration( str_duration( it->second.c_str() ) );
it = attr.find( "minimumUpdatePeriodMPD" );
if ( it != attr.end() )
this->mpd->setMinUpdatePeriod( str_duration( it->second.c_str() ) );
it = attr.find( "minBufferTime" );
if ( it != attr.end() )
this->mpd->setMinBufferTime( str_duration( it->second.c_str() ) );
if ( this->mpd->isLive() )
{
//This value is undefined when using type "On-Demand"
it = attr.find( "timeshiftBufferDepth" );
if ( it != attr.end() )
this->mpd->setTimeShiftBufferDepth( str_duration( it->second.c_str() ) );
}
this->setMPDBaseUrl(this->root);
this->setPeriods(this->root);
return true;
}
void BasicCMParser::setMPDBaseUrl (Node *root)
{
......
......@@ -56,7 +56,7 @@ namespace dash
dash::xml::Node *root;
MPD *mpd;
void setMPD ();
bool setMPD ();
void setPeriods (dash::xml::Node *root);
void setGroups (dash::xml::Node *root, Period *period);
void setRepresentations (dash::xml::Node *root, Group *group);
......
......@@ -30,9 +30,15 @@
using namespace dash::mpd;
using namespace dash::exception;
MPD::MPD (const AttributesMap& attributes) :
MPD::MPD () :
profile( dash::mpd::NotValid ),
attributes( attributes ),
live( false ),
availabilityStartTime( -1 ),
availabilityEndTime( -1 ),
duration( -1 ),
minUpdatePeriod( -1 ),
minBufferTime( -1 ),
timeShiftBufferDepth( -1 ),
programInfo( NULL )
{
}
......@@ -58,24 +64,51 @@ const std::vector<BaseUrl*>& MPD::getBaseUrls () const
return this->baseUrls;
}
const std::string& MPD::getMinBufferTime () const throw(AttributeNotPresentException)
time_t MPD::getDuration() const
{
return this->duration;
}
void MPD::setDuration(time_t duration)
{
if ( duration >= 0 )
this->duration = duration;
}
time_t MPD::getMinUpdatePeriod() const
{
return this->minUpdatePeriod;
}
void MPD::setMinUpdatePeriod(time_t period)
{
AttributesMap::const_iterator it = this->attributes.find("minBufferTime");
if( it == this->attributes.end())
throw AttributeNotPresentException();
if ( period >= 0 )
this->minUpdatePeriod = period;
}
return it->second;
time_t MPD::getMinBufferTime() const
{
return this->minBufferTime;
}
const std::string& MPD::getDuration () const throw(AttributeNotPresentException)
void MPD::setMinBufferTime(time_t time)
{
AttributesMap::const_iterator it = this->attributes.find("mediaPresentationDuration");
if ( time >= 0 )
this->minBufferTime = time;
}
if( it == this->attributes.end())
throw AttributeNotPresentException();
time_t MPD::getTimeShiftBufferDepth() const
{
return this->timeShiftBufferDepth;
}
return it->second;
void MPD::setTimeShiftBufferDepth(time_t depth)
{
if ( depth >= 0 )
this->timeShiftBufferDepth = depth;
}
ProgramInformation* MPD::getProgramInformation () throw(ElementNotPresentException)
{
if(this->programInfo == NULL)
......@@ -98,13 +131,34 @@ void MPD::setProgramInformation (ProgramInformation *progInf
bool MPD::isLive() const
{
AttributesMap::const_iterator it = this->attributes.find("mediaPresentationDuration");
return this->live;
}
void MPD::setLive( bool live )
{
this->live = live;
}
time_t MPD::getAvailabilityStartTime() const
{
return this->availabilityStartTime;
}
/*
Standard specifies a default of "On-Demand",
so anything that is not "Live" is "On-Demand"
*/
return ( it != this->attributes.end() && it->second == "Live" );
void MPD::setAvailabilityStartTime(time_t time)
{
if ( time >=0 )
this->availabilityStartTime = time;
}
time_t MPD::getAvailabilityEndTime() const
{
return this->availabilityEndTime;
}
void MPD::setAvailabilityEndTime(time_t time)
{
if ( time >= 0 )
this->availabilityEndTime = time;
}
Profile MPD::getProfile() const
......
......@@ -42,18 +42,27 @@ namespace dash
{
class MPD
{
typedef std::map<std::string, std::string> AttributesMap;
public:
MPD (const AttributesMap& attributes);
MPD();
virtual ~MPD();
Profile getProfile() const;
void setProfile( const std::string &strProfile );
void setProfile( Profile profile );
bool isLive() const;
const std::string& getDuration () const throw(dash::exception::AttributeNotPresentException);
const std::string& getMinBufferTime () const throw(dash::exception::AttributeNotPresentException);
bool isLive() const;
void setLive( bool live );
time_t getAvailabilityStartTime() const;
void setAvailabilityStartTime( time_t time );
time_t getAvailabilityEndTime() const;
void setAvailabilityEndTime( time_t time );
time_t getDuration() const;
void setDuration( time_t duration );
time_t getMinUpdatePeriod() const;
void setMinUpdatePeriod( time_t period );
time_t getMinBufferTime() const;
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);
......@@ -64,7 +73,13 @@ namespace dash
private:
Profile profile;
AttributesMap attributes;
bool live;
time_t availabilityStartTime;
time_t availabilityEndTime;
time_t duration;
time_t minUpdatePeriod;
time_t minBufferTime;
time_t timeShiftBufferDepth;
std::vector<Period *> periods;
std::vector<BaseUrl *> baseUrls;
ProgramInformation *programInfo;
......
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