Commit 0b80d620 authored by François Cartegnie's avatar François Cartegnie 🤞

stream_filter: dash: add subsegments

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