Commit 75dda0a5 authored by Francois Cartegnie's avatar Francois Cartegnie

demux: adaptative: unify and make default id local to parent node

parent d1ee36b8
......@@ -34,7 +34,7 @@
#include "SegmentTemplate.h"
#include "BasePeriod.h"
#include "ID.hpp"
#include "Inheritables.hpp"
using namespace adaptative;
using namespace adaptative::playlist;
......
......@@ -84,8 +84,3 @@ void CommonAttributesElements::addLang( const std::string &lang )
if ( lang.empty() == false )
this->lang.push_back( lang );
}
const ID & CommonAttributesElements::getID() const
{
return id;
}
......@@ -26,7 +26,6 @@
#include <list>
#include <string>
#include "ID.hpp"
namespace adaptative
{
......@@ -45,14 +44,12 @@ namespace adaptative
void setHeight( int height );
const std::list<std::string>& getLang() const;
void addLang( const std::string &lang );
const ID & getID() const;
protected:
std::string mimeType;
int width;
int height;
std::list<std::string> lang;
ID id;
};
}
}
......
......@@ -22,36 +22,25 @@
using namespace adaptative::playlist;
int64_t ID::nextid = 0;
ID::ID()
{
id = nextid++;
}
ID::ID(int64_t i_id)
ID::ID(const std::string &id_)
{
id = i_id;
id = id_;
}
ID::~ID()
ID::ID(uint64_t id_)
{
std::stringstream ss;
ss << "default_id#" << id_;
id = ss.str();
}
bool ID::operator==(const ID &other) const
{
return id == other.id;
return (!id.empty() && id == other.id);
}
std::string ID::str() const
{
std::stringstream ss;
ss << id;
return ss.str();
}
int64_t ID::toInt() const
{
return id;
}
......@@ -31,16 +31,13 @@ namespace adaptative
class ID
{
public:
ID();
ID(int64_t);
virtual ~ID();
virtual bool operator==(const ID &) const;
virtual std::string str() const;
virtual int64_t toInt() const;
ID(const std::string &);
ID(uint64_t = 0);
bool operator==(const ID &) const;
std::string str() const;
protected:
int64_t id;
static int64_t nextid;
private:
std::string id;
};
}
......
......@@ -57,3 +57,12 @@ uint64_t TimescaleAble::inheritTimescale() const
return 1;
}
const ID & Unique::getID() const
{
return id;
}
void Unique::setID(const ID &id_)
{
id = id_;
}
......@@ -23,6 +23,7 @@
#include "../tools/Properties.hpp"
#include <string>
#include <stdint.h>
#include "ID.hpp"
namespace adaptative
{
......@@ -50,19 +51,14 @@ namespace adaptative
TimescaleAble *parentTimescale;
};
template<class T> class UniqueNess
class Unique
{
public:
UniqueNess(){}
~UniqueNess() {}
void setId(const std::string &id_) {id = id_;}
const std::string & getId() const {return id;}
bool sameAs(const T &other) const
{
return (!id.empty() && id == other.id);
}
private:
std::string id;
const ID & getID() const;
void setID(const ID &);
protected:
ID id;
};
}
}
......
......@@ -44,7 +44,8 @@ namespace adaptative
/* common segment elements for period/adaptset/rep 5.3.9.1,
* with properties inheritance */
class SegmentInformation : public ICanonicalUrl,
public TimescaleAble
public TimescaleAble,
public Unique
{
public:
SegmentInformation( SegmentInformation * = 0 );
......
......@@ -66,17 +66,4 @@ void AdaptationSet::setSubsegmentAlignmentFlag(bool alignment)
subsegmentAlignmentFlag = alignment;
}
const Representation *AdaptationSet::getRepresentationById(const std::string &id) const
{
std::vector<BaseRepresentation*>::const_iterator it = representations.begin();
std::vector<BaseRepresentation*>::const_iterator end = representations.end();
while ( it != end )
{
Representation *rep = dynamic_cast<Representation *>(*it);
if ( rep->getId() == id )
return rep;
++it;
}
return NULL;
}
......@@ -51,7 +51,6 @@ namespace dash
virtual StreamFormat getStreamFormat() const; /* reimpl */
bool getSubsegmentAlignmentFlag() const;
void setSubsegmentAlignmentFlag( bool alignment );
const Representation* getRepresentationById ( const std::string &id ) const;
private:
bool subsegmentAlignmentFlag;
......
......@@ -132,19 +132,18 @@ void IsoffMainParser::parsePeriods(Node *root)
{
std::vector<Node *> periods = DOMHelper::getElementByTagName(root, "Period", false);
std::vector<Node *>::const_iterator it;
uint64_t nextid = 0;
for(it = periods.begin(); it != periods.end(); ++it)
{
Period *period = new (std::nothrow) Period(mpd);
if (!period)
continue;
parseSegmentInformation(*it, period);
parseSegmentInformation(*it, period, &nextid);
if((*it)->hasAttribute("start"))
period->startTime.Set(IsoTime((*it)->getAttributeValue("start")) * CLOCK_FREQ);
if((*it)->hasAttribute("duration"))
period->duration.Set(IsoTime((*it)->getAttributeValue("duration")) * CLOCK_FREQ);
if((*it)->hasAttribute("id"))
period->setId((*it)->getAttributeValue("id"));
std::vector<Node *> baseUrls = DOMHelper::getChildElementByTagName(*it, "BaseURL");
if(!baseUrls.empty())
period->baseUrl.Set( new Url( baseUrls.front()->getText() ) );
......@@ -194,7 +193,7 @@ size_t IsoffMainParser::parseSegmentTemplate(Node *templateNode, SegmentInformat
return total;
}
size_t IsoffMainParser::parseSegmentInformation(Node *node, SegmentInformation *info)
size_t IsoffMainParser::parseSegmentInformation(Node *node, SegmentInformation *info, uint64_t *nextid)
{
size_t total = 0;
total += parseSegmentBase(DOMHelper::getFirstChildElementByName(node, "SegmentBase"), info);
......@@ -213,6 +212,12 @@ size_t IsoffMainParser::parseSegmentInformation(Node *node, SegmentInformation *
}
if(node->hasAttribute("timescale"))
info->timescale.Set(Integer<uint64_t>(node->getAttributeValue("timescale")));
if(node->hasAttribute("id"))
info->setID(node->getAttributeValue("id"));
else
info->setID(ID((*nextid)++));
return total;
}
......@@ -220,6 +225,7 @@ void IsoffMainParser::setAdaptationSets (Node *periodNode, Period *period)
{
std::vector<Node *> adaptationSets = DOMHelper::getElementByTagName(periodNode, "AdaptationSet", false);
std::vector<Node *>::const_iterator it;
uint64_t nextid = 0;
for(it = adaptationSets.begin(); it != adaptationSets.end(); ++it)
{
......@@ -251,7 +257,7 @@ void IsoffMainParser::setAdaptationSets (Node *periodNode, Period *period)
adaptationSet->description.Set(role->getAttributeValue("value"));
}
parseSegmentInformation( *it, adaptationSet );
parseSegmentInformation(*it, adaptationSet, &nextid);
setRepresentations((*it), adaptationSet);
period->addAdaptationSet(adaptationSet);
......@@ -260,6 +266,7 @@ void IsoffMainParser::setAdaptationSets (Node *periodNode, Period *period)
void IsoffMainParser::setRepresentations (Node *adaptationSetNode, AdaptationSet *adaptationSet)
{
std::vector<Node *> representations = DOMHelper::getElementByTagName(adaptationSetNode, "Representation", false);
uint64_t nextid = 0;
for(size_t i = 0; i < representations.size(); i++)
{
......@@ -271,7 +278,7 @@ void IsoffMainParser::setRepresentations (Node *adaptationSetNode, Adaptation
currentRepresentation->baseUrl.Set(new Url(baseUrls.front()->getText()));
if(repNode->hasAttribute("id"))
currentRepresentation->setId(repNode->getAttributeValue("id"));
currentRepresentation->setID(ID(repNode->getAttributeValue("id")));
if(repNode->hasAttribute("width"))
currentRepresentation->setWidth(atoi(repNode->getAttributeValue("width").c_str()));
......@@ -299,7 +306,7 @@ void IsoffMainParser::setRepresentations (Node *adaptationSetNode, Adaptation
}
}
size_t i_total = parseSegmentInformation(repNode, currentRepresentation);
size_t i_total = parseSegmentInformation(repNode, currentRepresentation, &nextid);
/* Empty Representation with just baseurl (ex: subtitles) */
if(i_total == 0 &&
(currentRepresentation->baseUrl.Get() && !currentRepresentation->baseUrl.Get()->empty()) &&
......
......@@ -78,7 +78,7 @@ namespace dash
void parseInitSegment (xml::Node *, Initializable<Segment> *, SegmentInformation *);
void parseTimeline (xml::Node *, MediaSegmentTemplate *);
void parsePeriods (xml::Node *);
size_t parseSegmentInformation(xml::Node *, SegmentInformation *);
size_t parseSegmentInformation(xml::Node *, SegmentInformation *, uint64_t *);
size_t parseSegmentBase (xml::Node *, SegmentInformation *);
size_t parseSegmentList (xml::Node *, SegmentInformation *);
size_t parseSegmentTemplate(xml::Node *, SegmentInformation *);
......
......@@ -35,8 +35,7 @@ namespace dash
using namespace adaptative;
using namespace adaptative::playlist;
class Period : public BasePeriod,
public UniqueNess<Period>
class Period : public BasePeriod
{
public:
Period(MPD *);
......
......@@ -152,11 +152,7 @@ std::string Representation::contextualize(size_t index, const std::string &compo
pos = ret.find("$RepresentationID$");
if(pos != std::string::npos)
{
std::stringstream ss;
ss << getId();
ret.replace(pos, std::string("$RepresentationID$").length(), ss.str());
}
ret.replace(pos, std::string("$RepresentationID$").length(), id.str());
return ret;
}
......
......@@ -41,8 +41,7 @@ namespace dash
using namespace adaptative::playlist;
class Representation : public BaseRepresentation,
public DASHCommonAttributesElements,
public UniqueNess<Representation>
public DASHCommonAttributesElements
{
public:
Representation( AdaptationSet * );
......
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