Commit e9a42b2d authored by François Cartegnie's avatar François Cartegnie 🤞

stream_filter: dash: use dedicated segment classes and improve debug

parent 32402847
...@@ -369,7 +369,12 @@ Segment* BasicCMParser::parseSegment( Node* node, bool init ) ...@@ -369,7 +369,12 @@ Segment* BasicCMParser::parseSegment( Node* node, bool init )
seg = new SegmentTemplate( runtimeToken, this->currentRepresentation ); seg = new SegmentTemplate( runtimeToken, this->currentRepresentation );
} }
else else
seg = new Segment( this->currentRepresentation, init ); {
if ( init )
seg = new InitSegment( currentRepresentation );
else
seg = new Segment( currentRepresentation );
}
if ( url.find( this->p_stream->psz_access ) != 0 ) //Relative url if ( url.find( this->p_stream->psz_access ) != 0 ) //Relative url
url = this->url + url; url = this->url + url;
seg->setSourceUrl( url ); seg->setSourceUrl( url );
......
...@@ -123,17 +123,22 @@ void IsoffMainParser::setSegmentBase (dash::xml::Node *repNode, Represent ...@@ -123,17 +123,22 @@ void IsoffMainParser::setSegmentBase (dash::xml::Node *repNode, Represent
if(segmentBase.front()->hasAttribute("indexRange")) if(segmentBase.front()->hasAttribute("indexRange"))
{ {
SegmentList *list = new SegmentList(); SegmentList *list = new SegmentList();
Segment *seg = new Segment(rep); Segment *seg;
size_t start = 0, end = 0; size_t start = 0, end = 0;
if (std::sscanf(segmentBase.front()->getAttributeValue("indexRange").c_str(), "%"PRIu64"-%"PRIu64, &start, &end) == 2) if (std::sscanf(segmentBase.front()->getAttributeValue("indexRange").c_str(), "%"PRIu64"-%"PRIu64, &start, &end) == 2)
{ {
seg = new IndexSegment(rep);
seg->setByteRange(start, end); seg->setByteRange(start, end);
list->addSegment(seg); list->addSegment(seg);
/* index must be before data, so data starts at index end */ /* index must be before data, so data starts at index end */
seg = new Segment(rep); seg = new Segment(rep);
seg->setByteRange(end + 1, 0); seg->setByteRange(end + 1, 0);
} }
else
{
seg = new Segment(rep);
}
list->addSegment(seg); list->addSegment(seg);
rep->setSegmentList(list); rep->setSegmentList(list);
...@@ -174,7 +179,7 @@ void IsoffMainParser::setInitSegment (dash::xml::Node *segBaseNode, Segme ...@@ -174,7 +179,7 @@ void IsoffMainParser::setInitSegment (dash::xml::Node *segBaseNode, Segme
if(initSeg.size() > 0) if(initSeg.size() > 0)
{ {
Segment *seg = new Segment( currentRepresentation, true ); Segment *seg = new InitSegment( currentRepresentation );
seg->setSourceUrl(initSeg.at(0)->getAttributeValue("sourceURL")); seg->setSourceUrl(initSeg.at(0)->getAttributeValue("sourceURL"));
if(initSeg.at(0)->hasAttribute("range")) if(initSeg.at(0)->hasAttribute("range"))
......
...@@ -38,12 +38,17 @@ ISegment::ISegment(const ICanonicalUrl *parent): ...@@ -38,12 +38,17 @@ ISegment::ISegment(const ICanonicalUrl *parent):
startByte (0), startByte (0),
endByte (0) endByte (0)
{ {
debugName = "Segment";
}
dash::http::Chunk * ISegment::getChunk()
{
return new SegmentChunk(this);
} }
dash::http::Chunk* ISegment::toChunk() dash::http::Chunk* ISegment::toChunk()
{ {
Chunk *chunk = new SegmentChunk(this); Chunk *chunk = getChunk();
if (!chunk) if (!chunk)
return NULL; return NULL;
...@@ -75,11 +80,15 @@ void ISegment::setByteRange(size_t start, size_t end) ...@@ -75,11 +80,15 @@ void ISegment::setByteRange(size_t start, size_t end)
std::string ISegment::toString() const std::string ISegment::toString() const
{ {
return std::string(" Segment url=").append(getUrlSegment()); std::stringstream ss(" ");
ss << debugName << " url=" << getUrlSegment();
if(startByte!=endByte)
ss << " @" << startByte << ".." << endByte;
return ss.str();
} }
ISegment::SegmentChunk::SegmentChunk(ISegment *segment_) : ISegment::SegmentChunk::SegmentChunk(ISegment *segment_) :
Chunk() dash::http::Chunk()
{ {
segment = segment_; segment = segment_;
} }
...@@ -89,11 +98,9 @@ void ISegment::SegmentChunk::onDownload(void *, size_t) ...@@ -89,11 +98,9 @@ void ISegment::SegmentChunk::onDownload(void *, size_t)
} }
Segment::Segment(Representation *parent, bool isinit, bool tosplit) : Segment::Segment(Representation *parent) :
ISegment(parent), ISegment(parent),
parentRepresentation( parent ), parentRepresentation( parent )
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 )
...@@ -115,14 +122,28 @@ void Segment::setSourceUrl ( const std::string &url ) ...@@ -115,14 +122,28 @@ void Segment::setSourceUrl ( const std::string &url )
this->sourceUrl = url; this->sourceUrl = url;
} }
bool Segment::needsSplit() const Representation *Segment::getRepresentation() const
{ {
return needssplit; return parentRepresentation;
} }
Representation *Segment::getRepresentation() const
std::string Segment::toString() const
{ {
return parentRepresentation; if (subsegments.empty())
{
return ISegment::toString();
}
else
{
std::string ret;
std::vector<SubSegment *>::const_iterator l;
for(l = subsegments.begin(); l != subsegments.end(); l++)
{
ret.append( (*l)->toString() );
}
return ret;
}
} }
std::string Segment::getUrlSegment() const std::string Segment::getUrlSegment() const
...@@ -157,19 +178,38 @@ std::vector<ISegment*> Segment::subSegments() ...@@ -157,19 +178,38 @@ std::vector<ISegment*> Segment::subSegments()
return list; return list;
} }
std::string Segment::toString() const InitSegment::InitSegment(Representation *parent) :
Segment(parent)
{
debugName = "InitSegment";
}
IndexSegment::IndexSegment(Representation *parent) :
Segment(parent)
{
debugName = "IndexSegment";
}
dash::http::Chunk * IndexSegment::getChunk()
{
return new IndexSegmentChunk(this);
}
IndexSegment::IndexSegmentChunk::IndexSegmentChunk(ISegment *segment)
: SegmentChunk(segment)
{
}
void IndexSegment::IndexSegmentChunk::onDownload(void *buffer, size_t size)
{ {
if (init)
return std::string(" InitSeg url=")
.append(getUrlSegment());
else
return ISegment::toString();
} }
SubSegment::SubSegment(Segment *main, size_t start, size_t end) : SubSegment::SubSegment(Segment *main, size_t start, size_t end) :
ISegment(main), parent(main) ISegment(main), parent(main)
{ {
setByteRange(start, end); setByteRange(start, end);
debugName = "SubSegment";
} }
std::string SubSegment::getUrlSegment() const std::string SubSegment::getUrlSegment() const
......
...@@ -60,6 +60,7 @@ namespace dash ...@@ -60,6 +60,7 @@ namespace dash
protected: protected:
size_t startByte; size_t startByte;
size_t endByte; size_t endByte;
std::string debugName;
class SegmentChunk : public dash::http::Chunk class SegmentChunk : public dash::http::Chunk
{ {
...@@ -67,33 +68,53 @@ namespace dash ...@@ -67,33 +68,53 @@ namespace dash
SegmentChunk(ISegment *segment); SegmentChunk(ISegment *segment);
virtual void onDownload(void *, size_t); virtual void onDownload(void *, size_t);
private: protected:
ISegment *segment; ISegment *segment;
}; };
virtual dash::http::Chunk * getChunk();
}; };
class Segment : public ISegment class Segment : public ISegment
{ {
public: public:
Segment( Representation *parent, bool isinit = false, bool tosplit = false ); Segment( Representation *parent );
~Segment(); ~Segment();
virtual void setSourceUrl( const std::string &url ); virtual void setSourceUrl( const std::string &url );
virtual bool needsSplit() const;
virtual std::string getUrlSegment() const; /* impl */ virtual std::string getUrlSegment() const; /* impl */
virtual dash::http::Chunk* toChunk(); virtual dash::http::Chunk* toChunk();
virtual std::vector<ISegment*> subSegments(); virtual std::vector<ISegment*> subSegments();
virtual std::string toString() const;
virtual Representation* getRepresentation() const; virtual Representation* getRepresentation() const;
protected: protected:
Representation* parentRepresentation; Representation* parentRepresentation;
bool init;
bool needssplit;
std::vector<SubSegment *> subsegments; std::vector<SubSegment *> subsegments;
std::string sourceUrl; std::string sourceUrl;
int size; int size;
}; };
class InitSegment : public Segment
{
public:
InitSegment( Representation *parent );
};
class IndexSegment : public Segment
{
public:
IndexSegment( Representation *parent );
protected:
class IndexSegmentChunk : public SegmentChunk
{
public:
IndexSegmentChunk(ISegment *segment);
virtual void onDownload(void *, size_t);
};
virtual dash::http::Chunk * getChunk();
};
class SubSegment : public ISegment class SubSegment : public ISegment
{ {
public: public:
......
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