Commit 0b80d620 authored by Francois Cartegnie's avatar Francois Cartegnie

stream_filter: dash: add subsegments

We'll need to split single file, ranged chunks
parent 33097d5d
......@@ -58,7 +58,7 @@ Chunk* AlwaysBestAdaptationLogic::getNextChunk()
const Representation *AlwaysBestAdaptationLogic::getCurrentRepresentation() const
{
if ( this->count < this->schedule.size() )
return this->schedule.at( this->count )->getParentRepresentation();
return this->schedule.at( this->count )->getRepresentation();
return NULL;
}
......
......@@ -33,12 +33,56 @@
using namespace dash::mpd;
using namespace dash::http;
Segment::Segment(const Representation *parent, bool isinit) :
ICanonicalUrl( parent ),
startByte (0),
endByte (0),
ISegment::ISegment(const ICanonicalUrl *parent):
ICanonicalUrl( parent ),
startByte (0),
endByte (0)
{
}
dash::http::Chunk* ISegment::toChunk() const
{
Chunk *chunk = new Chunk();
if (!chunk)
return NULL;
if(startByte != endByte)
{
chunk->setStartByte(startByte);
chunk->setEndByte(endByte);
}
chunk->setUrl(getUrlSegment());
return chunk;
}
bool ISegment::isSingleShot() const
{
return true;
}
void ISegment::done()
{
//Only used for a SegmentTemplate.
}
void ISegment::setByteRange(size_t start, size_t end)
{
startByte = start;
endByte = end;
}
std::string ISegment::toString() const
{
return std::string(" Segment url=").append(getUrlSegment());
}
Segment::Segment(Representation *parent, bool isinit, bool tosplit) :
ISegment(parent),
parentRepresentation( parent ),
init( isinit )
init( isinit ),
needssplit( tosplit )
{
assert( parent != NULL );
if ( parent->getSegmentInfo() != NULL && parent->getSegmentInfo()->getDuration() >= 0 )
......@@ -47,57 +91,89 @@ Segment::Segment(const Representation *parent, bool isinit) :
this->size = -1;
}
Segment::~Segment()
{
std::vector<SubSegment*>::iterator it;
for(it=subsegments.begin();it!=subsegments.end();it++)
delete *it;
}
void Segment::setSourceUrl ( const std::string &url )
{
if ( url.empty() == false )
this->sourceUrl = url;
}
bool Segment::isSingleShot () const
bool Segment::needsSplit() const
{
return true;
return needssplit;
}
void Segment::done ()
Representation *Segment::getRepresentation() const
{
//Only used for a SegmentTemplate.
return parentRepresentation;
}
void Segment::setByteRange (int start, int end)
std::string Segment::getUrlSegment() const
{
this->startByte = start;
this->endByte = end;
std::string ret = getParentUrlSegment();
if (!sourceUrl.empty())
ret.append(sourceUrl);
return ret;
}
dash::http::Chunk* Segment::toChunk ()
dash::http::Chunk* Segment::toChunk() const
{
Chunk *chunk = new Chunk();
Chunk *chunk = ISegment::toChunk();
if (chunk)
chunk->setBitrate(parentRepresentation->getBandwidth());
return chunk;
}
if(startByte != endByte)
std::vector<ISegment*> Segment::subSegments()
{
std::vector<ISegment*> list;
if(!subsegments.empty())
{
chunk->setStartByte(startByte);
chunk->setEndByte(endByte);
std::vector<SubSegment*>::iterator it;
for(it=subsegments.begin();it!=subsegments.end();it++)
list.push_back(*it);
}
else
{
list.push_back(this);
}
return list;
}
chunk->setUrl( getUrlSegment() );
chunk->setBitrate(this->parentRepresentation->getBandwidth());
std::string Segment::toString() const
{
if (init)
return std::string(" InitSeg url=")
.append(getUrlSegment());
else
return ISegment::toString();
}
return chunk;
SubSegment::SubSegment(Segment *main, size_t start, size_t end) :
ISegment(main), parent(main)
{
setByteRange(start, end);
}
const Representation *Segment::getParentRepresentation() const
std::string SubSegment::getUrlSegment() const
{
return this->parentRepresentation;
return getParentUrlSegment();
}
std::string Segment::getUrlSegment() const
std::vector<ISegment*> SubSegment::subSegments()
{
std::string ret = getParentUrlSegment();
if (!sourceUrl.empty())
ret.append(sourceUrl);
return ret;
std::vector<ISegment*> list;
list.push_back(this);
return list;
}
bool Segment::isInit() const
Representation *SubSegment::getRepresentation() const
{
return init;
return parent->getRepresentation();
}
......@@ -37,32 +37,62 @@ namespace dash
namespace mpd
{
class Representation;
class Segment : public ICanonicalUrl
class SubSegment;
class ISegment : public ICanonicalUrl
{
public:
Segment( const Representation *parent, bool isinit = false );
virtual ~Segment(){}
virtual void setSourceUrl( const std::string &url );
ISegment(const ICanonicalUrl *parent);
virtual ~ISegment(){}
/**
* @return true if the segment should be dropped after being read.
* That is basically true when using an Url, and false
* when using an UrlTemplate
*/
virtual bool isSingleShot () const;
virtual bool isInit () const;
virtual void done ();
virtual void setByteRange (int start, int end);
virtual dash::http::Chunk* toChunk ();
const Representation* getParentRepresentation() const;
virtual std::string getUrlSegment () const; /* impl */
virtual dash::http::Chunk* toChunk () const;
virtual void setByteRange (size_t start, size_t end);
virtual std::vector<ISegment*> subSegments () = 0;
virtual std::string toString () const;
virtual Representation* getRepresentation() const = 0;
protected:
std::string sourceUrl;
size_t startByte;
size_t endByte;
const Representation* parentRepresentation;
int size;
bool init;
};
class Segment : public ISegment
{
public:
Segment( Representation *parent, bool isinit = false, bool tosplit = false );
~Segment();
virtual void setSourceUrl( const std::string &url );
virtual bool needsSplit() const;
virtual std::string getUrlSegment() const; /* impl */
virtual dash::http::Chunk* toChunk() const;
virtual std::vector<ISegment*> subSegments();
virtual std::string toString() const;
virtual Representation* getRepresentation() const;
protected:
Representation* parentRepresentation;
bool init;
bool needssplit;
std::vector<SubSegment *> subsegments;
std::string sourceUrl;
int size;
};
class SubSegment : public ISegment
{
public:
SubSegment(Segment *, size_t start, size_t end);
virtual std::string getUrlSegment() const; /* impl */
virtual std::vector<ISegment*> subSegments();
virtual Representation* getRepresentation() const;
private:
Segment *parent;
};
}
}
......
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