[vlc-commits] stream_filter: dash: Split monolithic segments using index

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


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sun Nov 30 15:38:36 2014 +0100| [dbcef6f754ff29d799623426df5941df128d5932] | committer: Francois Cartegnie

stream_filter: dash: Split monolithic segments using index

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

 modules/stream_filter/dash/mp4/AtomsReader.cpp    |   12 ++++--
 modules/stream_filter/dash/mpd/Representation.cpp |   44 +++++++++++++++++++++
 modules/stream_filter/dash/mpd/Representation.h   |    8 ++++
 modules/stream_filter/dash/mpd/Segment.cpp        |   20 ++++++++++
 modules/stream_filter/dash/mpd/Segment.h          |    4 ++
 5 files changed, 84 insertions(+), 4 deletions(-)

diff --git a/modules/stream_filter/dash/mp4/AtomsReader.cpp b/modules/stream_filter/dash/mp4/AtomsReader.cpp
index 1a04671..5d544f9 100644
--- a/modules/stream_filter/dash/mp4/AtomsReader.cpp
+++ b/modules/stream_filter/dash/mp4/AtomsReader.cpp
@@ -67,15 +67,19 @@ bool AtomsReader::parseBlock(void *buffer, size_t size)
             MP4_Box_t *sidxbox = MP4_BoxGet(rootbox, "sidx");
             if (sidxbox)
             {
+                Representation::SplitPoint point;
+                std::vector<Representation::SplitPoint> splitlist;
                 MP4_Box_data_sidx_t *sidx = sidxbox->data.p_sidx;
-                size_t offset = sidx->i_first_offset;
+                point.offset = sidx->i_first_offset;
+                point.time = 0;
                 for(uint16_t i=0; i<sidx->i_reference_count; i++)
                 {
-                    std::cerr << " offset " << offset << std::endl;
-                    offset += sidx->p_items[i].i_referenced_size;
+                    splitlist.push_back(point);
+                    point.offset += sidx->p_items[i].i_referenced_size;
+                    point.time += sidx->p_items[i].i_subsegment_duration;
                 }
+                segment->getRepresentation()->SplitUsingIndex(splitlist);
             }
-            std::cerr << "index seg " << ((uint8_t *)buffer)[4] << ((uint8_t *)buffer)[5] << std::endl;
         }
         stream_Delete(stream);
     }
diff --git a/modules/stream_filter/dash/mpd/Representation.cpp b/modules/stream_filter/dash/mpd/Representation.cpp
index a1306f1..cda86dc 100644
--- a/modules/stream_filter/dash/mpd/Representation.cpp
+++ b/modules/stream_filter/dash/mpd/Representation.cpp
@@ -229,3 +229,47 @@ MPD * Representation::getMPD() const
 {
     return mpd;
 }
+
+static void insertIntoSegment(std::vector<Segment *> &seglist, size_t start,
+                              size_t end)
+{
+    std::vector<Segment *>::iterator segIt;
+    for(segIt = seglist.begin(); segIt < seglist.end(); segIt++)
+    {
+        Segment *segment = *segIt;
+        if(segment->getClassId() == Segment::CLASSID_SEGMENT &&
+           segment->contains(end + segment->getOffset()))
+        {
+            SubSegment *subsegment = new SubSegment(segment,
+                                                    start + segment->getOffset(),
+                                                    end + segment->getOffset());
+            segment->addSubSegment(subsegment);
+            break;
+        }
+    }
+}
+
+void Representation::SplitUsingIndex(std::vector<SplitPoint> &splitlist)
+{
+    std::vector<Segment *> seglist = segmentList->getSegments();
+    std::vector<SplitPoint>::const_iterator splitIt;
+    size_t start = 0, end = 0;
+
+    for(splitIt = splitlist.begin(); splitIt < splitlist.end(); splitIt++)
+    {
+        start = end;
+        SplitPoint split = *splitIt;
+        end = split.offset;
+        if(splitIt == splitlist.begin() && split.offset == 0)
+            continue;
+        insertIntoSegment(seglist, start, end);
+        end++;
+    }
+
+    if(start != 0)
+    {
+        start = end;
+        end = 0;
+        insertIntoSegment(seglist, start, end);
+    }
+}
diff --git a/modules/stream_filter/dash/mpd/Representation.h b/modules/stream_filter/dash/mpd/Representation.h
index 6d971cb..68b360f 100644
--- a/modules/stream_filter/dash/mpd/Representation.h
+++ b/modules/stream_filter/dash/mpd/Representation.h
@@ -89,6 +89,14 @@ namespace dash
                 std::vector<std::string> toString() const;
                 virtual std::string getUrlSegment           () const; /* impl */
 
+                class SplitPoint
+                {
+                    public:
+                        size_t offset;
+                        mtime_t time;
+                };
+                void SplitUsingIndex(std::vector<SplitPoint>&);
+
             private:
                 MPD                                *mpd;
                 uint64_t                            bandwidth;
diff --git a/modules/stream_filter/dash/mpd/Segment.cpp b/modules/stream_filter/dash/mpd/Segment.cpp
index bbce30e..0397c11 100644
--- a/modules/stream_filter/dash/mpd/Segment.cpp
+++ b/modules/stream_filter/dash/mpd/Segment.cpp
@@ -81,6 +81,11 @@ void ISegment::setByteRange(size_t start, size_t end)
     endByte   = end;
 }
 
+size_t ISegment::getOffset() const
+{
+    return startByte;
+}
+
 std::string ISegment::toString() const
 {
     std::stringstream ss("    ");
@@ -90,6 +95,14 @@ std::string ISegment::toString() const
     return ss.str();
 }
 
+bool ISegment::contains(size_t byte) const
+{
+    if (startByte == endByte)
+        return false;
+    return (byte >= startByte &&
+            (!endByte || byte <= endByte) );
+}
+
 int ISegment::getClassId() const
 {
     return classId;
@@ -118,6 +131,11 @@ Segment::Segment(Representation *parent) :
     classId = CLASSID_SEGMENT;
 }
 
+void Segment::addSubSegment(SubSegment *subsegment)
+{
+    subsegments.push_back(subsegment);
+}
+
 Segment::~Segment()
 {
     std::vector<SubSegment*>::iterator it;
@@ -214,6 +232,8 @@ IndexSegment::IndexSegmentChunk::IndexSegmentChunk(ISegment *segment)
 
 void IndexSegment::IndexSegmentChunk::onDownload(void *buffer, size_t size)
 {
+    dash::mp4::AtomsReader br(segment);
+    br.parseBlock(buffer, size);
 }
 
 SubSegment::SubSegment(Segment *main, size_t start, size_t end) :
diff --git a/modules/stream_filter/dash/mpd/Segment.h b/modules/stream_filter/dash/mpd/Segment.h
index 722bade..4e09c5d 100644
--- a/modules/stream_filter/dash/mpd/Segment.h
+++ b/modules/stream_filter/dash/mpd/Segment.h
@@ -53,9 +53,11 @@ namespace dash
                 virtual void                            done            ();
                 virtual dash::http::Chunk*              toChunk         ();
                 virtual void                            setByteRange    (size_t start, size_t end);
+                virtual size_t                          getOffset       () const;
                 virtual std::vector<ISegment*>          subSegments     () = 0;
                 virtual std::string                     toString        () const;
                 virtual Representation*                 getRepresentation() const = 0;
+                virtual bool                            contains        (size_t byte) const;
                 int                                     getClassId      () const;
 
                 static const int CLASSID_ISEGMENT = 0;
@@ -89,6 +91,8 @@ namespace dash
                 virtual dash::http::Chunk* toChunk();
                 virtual std::vector<ISegment*> subSegments();
                 virtual Representation* getRepresentation() const;
+                virtual std::string toString() const;
+                virtual void addSubSegment(SubSegment *);
                 static const int CLASSID_SEGMENT = 1;
 
             protected:



More information about the vlc-commits mailing list