[vlc-commits] stream_filter: dash: use dedicated segment classes and improve debug

Francois Cartegnie git at videolan.org
Thu Dec 18 22:39:51 CET 2014


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Nov 26 22:25:04 2014 +0100| [e9a42b2dffa3c606a38ee90b3b8ecd54bb58843b] | committer: Francois Cartegnie

stream_filter: dash: use dedicated segment classes and improve debug

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e9a42b2dffa3c606a38ee90b3b8ecd54bb58843b
---

 modules/stream_filter/dash/mpd/BasicCMParser.cpp   |    7 +-
 modules/stream_filter/dash/mpd/IsoffMainParser.cpp |    9 ++-
 modules/stream_filter/dash/mpd/Segment.cpp         |   74 +++++++++++++++-----
 modules/stream_filter/dash/mpd/Segment.h           |   33 +++++++--
 4 files changed, 97 insertions(+), 26 deletions(-)

diff --git a/modules/stream_filter/dash/mpd/BasicCMParser.cpp b/modules/stream_filter/dash/mpd/BasicCMParser.cpp
index 6470716..d02839b 100644
--- a/modules/stream_filter/dash/mpd/BasicCMParser.cpp
+++ b/modules/stream_filter/dash/mpd/BasicCMParser.cpp
@@ -369,7 +369,12 @@ Segment*    BasicCMParser::parseSegment( Node* node, bool init )
             seg = new SegmentTemplate( runtimeToken, this->currentRepresentation );
         }
         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
             url = this->url + url;
         seg->setSourceUrl( url );
diff --git a/modules/stream_filter/dash/mpd/IsoffMainParser.cpp b/modules/stream_filter/dash/mpd/IsoffMainParser.cpp
index 9f9f53b..0a15f1a 100644
--- a/modules/stream_filter/dash/mpd/IsoffMainParser.cpp
+++ b/modules/stream_filter/dash/mpd/IsoffMainParser.cpp
@@ -123,17 +123,22 @@ void    IsoffMainParser::setSegmentBase     (dash::xml::Node *repNode, Represent
     if(segmentBase.front()->hasAttribute("indexRange"))
     {
         SegmentList *list = new SegmentList();
-        Segment *seg = new Segment(rep);
+        Segment *seg;
 
         size_t start = 0, end = 0;
         if (std::sscanf(segmentBase.front()->getAttributeValue("indexRange").c_str(), "%"PRIu64"-%"PRIu64, &start, &end) == 2)
         {
+            seg = new IndexSegment(rep);
             seg->setByteRange(start, end);
             list->addSegment(seg);
             /* index must be before data, so data starts at index end */
             seg = new Segment(rep);
             seg->setByteRange(end + 1, 0);
         }
+        else
+        {
+            seg = new Segment(rep);
+        }
 
         list->addSegment(seg);
         rep->setSegmentList(list);
@@ -174,7 +179,7 @@ void    IsoffMainParser::setInitSegment     (dash::xml::Node *segBaseNode, Segme
 
     if(initSeg.size() > 0)
     {
-        Segment *seg = new Segment( currentRepresentation, true );
+        Segment *seg = new InitSegment( currentRepresentation );
         seg->setSourceUrl(initSeg.at(0)->getAttributeValue("sourceURL"));
 
         if(initSeg.at(0)->hasAttribute("range"))
diff --git a/modules/stream_filter/dash/mpd/Segment.cpp b/modules/stream_filter/dash/mpd/Segment.cpp
index 24cf130..1dc20e8 100644
--- a/modules/stream_filter/dash/mpd/Segment.cpp
+++ b/modules/stream_filter/dash/mpd/Segment.cpp
@@ -38,12 +38,17 @@ ISegment::ISegment(const ICanonicalUrl *parent):
     startByte  (0),
     endByte    (0)
 {
+    debugName = "Segment";
+}
 
+dash::http::Chunk * ISegment::getChunk()
+{
+    return new SegmentChunk(this);
 }
 
 dash::http::Chunk* ISegment::toChunk()
 {
-    Chunk *chunk = new SegmentChunk(this);
+    Chunk *chunk = getChunk();
     if (!chunk)
         return NULL;
 
@@ -75,11 +80,15 @@ void ISegment::setByteRange(size_t start, size_t end)
 
 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_) :
-    Chunk()
+    dash::http::Chunk()
 {
     segment = segment_;
 }
@@ -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),
-        parentRepresentation( parent ),
-        init( isinit ),
-        needssplit( tosplit )
+        parentRepresentation( parent )
 {
     assert( parent != NULL );
     if ( parent->getSegmentInfo() != NULL && parent->getSegmentInfo()->getDuration() >= 0 )
@@ -115,14 +122,28 @@ void                    Segment::setSourceUrl   ( const std::string &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
@@ -157,19 +178,38 @@ std::vector<ISegment*> Segment::subSegments()
     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) :
     ISegment(main), parent(main)
 {
     setByteRange(start, end);
+    debugName = "SubSegment";
 }
 
 std::string SubSegment::getUrlSegment() const
diff --git a/modules/stream_filter/dash/mpd/Segment.h b/modules/stream_filter/dash/mpd/Segment.h
index 404471c..7c94124 100644
--- a/modules/stream_filter/dash/mpd/Segment.h
+++ b/modules/stream_filter/dash/mpd/Segment.h
@@ -60,6 +60,7 @@ namespace dash
             protected:
                 size_t                  startByte;
                 size_t                  endByte;
+                std::string             debugName;
 
                 class SegmentChunk : public dash::http::Chunk
                 {
@@ -67,33 +68,53 @@ namespace dash
                         SegmentChunk(ISegment *segment);
                         virtual void onDownload(void *, size_t);
 
-                    private:
+                    protected:
                         ISegment *segment;
                 };
+
+                virtual dash::http::Chunk * getChunk();
         };
 
         class Segment : public ISegment
         {
             public:
-                Segment( Representation *parent, bool isinit = false, bool tosplit = false );
+                Segment( Representation *parent );
                 ~Segment();
                 virtual void setSourceUrl( const std::string &url );
-                virtual bool needsSplit() const;
                 virtual std::string getUrlSegment() const; /* impl */
                 virtual dash::http::Chunk* toChunk();
                 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 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
         {
             public:



More information about the vlc-commits mailing list