[vlc-commits] demux: adaptative: add pruning by position

Francois Cartegnie git at videolan.org
Wed Jun 10 18:58:05 CEST 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sun Jun  7 14:10:06 2015 +0200| [2bf7935f51989a4a24054a83c59361d94b6babc1] | committer: Francois Cartegnie

demux: adaptative: add pruning by position

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

 modules/demux/adaptative/SegmentTracker.cpp        |    6 ++++
 modules/demux/adaptative/SegmentTracker.hpp        |    1 +
 modules/demux/adaptative/Streams.cpp               |    5 ++++
 modules/demux/adaptative/Streams.hpp               |    1 +
 .../demux/adaptative/playlist/AbstractPlaylist.cpp |    6 ++++
 .../demux/adaptative/playlist/AbstractPlaylist.hpp |    1 +
 .../adaptative/playlist/SegmentInformation.cpp     |   29 ++++++++++++++++----
 .../adaptative/playlist/SegmentInformation.hpp     |    3 +-
 modules/demux/adaptative/playlist/SegmentList.cpp  |   26 ++++++++++++++++++
 modules/demux/adaptative/playlist/SegmentList.h    |    3 ++
 10 files changed, 75 insertions(+), 6 deletions(-)

diff --git a/modules/demux/adaptative/SegmentTracker.cpp b/modules/demux/adaptative/SegmentTracker.cpp
index fc1822c..f5e49a3 100644
--- a/modules/demux/adaptative/SegmentTracker.cpp
+++ b/modules/demux/adaptative/SegmentTracker.cpp
@@ -131,3 +131,9 @@ mtime_t SegmentTracker::getSegmentStart() const
     else
         return 0;
 }
+
+void SegmentTracker::pruneFromCurrent()
+{
+    if(playlist->isLive())
+        playlist->pruneBySegmentNumber(count);
+}
diff --git a/modules/demux/adaptative/SegmentTracker.hpp b/modules/demux/adaptative/SegmentTracker.hpp
index 2acd902..e1d1510 100644
--- a/modules/demux/adaptative/SegmentTracker.hpp
+++ b/modules/demux/adaptative/SegmentTracker.hpp
@@ -61,6 +61,7 @@ namespace adaptative
             Chunk* getNextChunk(StreamType);
             bool setPosition(mtime_t, bool, bool);
             mtime_t getSegmentStart() const;
+            void pruneFromCurrent();
 
         private:
             bool initializing;
diff --git a/modules/demux/adaptative/Streams.cpp b/modules/demux/adaptative/Streams.cpp
index e79855c..0637357 100644
--- a/modules/demux/adaptative/Streams.cpp
+++ b/modules/demux/adaptative/Streams.cpp
@@ -249,6 +249,11 @@ mtime_t Stream::getPosition() const
     return segmentTracker->getSegmentStart();
 }
 
+void Stream::prune()
+{
+    segmentTracker->pruneFromCurrent();
+}
+
 AbstractStreamOutput::AbstractStreamOutput(demux_t *demux)
 {
     realdemux = demux;
diff --git a/modules/demux/adaptative/Streams.hpp b/modules/demux/adaptative/Streams.hpp
index 1970c30..6cfd66b 100644
--- a/modules/demux/adaptative/Streams.hpp
+++ b/modules/demux/adaptative/Streams.hpp
@@ -71,6 +71,7 @@ namespace adaptative
         status demux(HTTPConnectionManager *, mtime_t);
         bool setPosition(mtime_t, bool);
         mtime_t getPosition() const;
+        void prune();
 
     private:
         Chunk *getChunk();
diff --git a/modules/demux/adaptative/playlist/AbstractPlaylist.cpp b/modules/demux/adaptative/playlist/AbstractPlaylist.cpp
index 5030a8f..5e3022e 100644
--- a/modules/demux/adaptative/playlist/AbstractPlaylist.cpp
+++ b/modules/demux/adaptative/playlist/AbstractPlaylist.cpp
@@ -145,3 +145,9 @@ void AbstractPlaylist::mergeWith(AbstractPlaylist *updatedAbstractPlaylist, mtim
         periods.at(i)->mergeWith(updatedAbstractPlaylist->periods.at(i), prunebarrier);
 }
 
+void AbstractPlaylist::pruneBySegmentNumber(uint64_t num)
+{
+    for(size_t i = 0; i < periods.size(); i++)
+        periods.at(i)->pruneBySegmentNumber(num);
+}
+
diff --git a/modules/demux/adaptative/playlist/AbstractPlaylist.hpp b/modules/demux/adaptative/playlist/AbstractPlaylist.hpp
index b80621e..30ec6cd 100644
--- a/modules/demux/adaptative/playlist/AbstractPlaylist.hpp
+++ b/modules/demux/adaptative/playlist/AbstractPlaylist.hpp
@@ -54,6 +54,7 @@ namespace adaptative
                 virtual BasePeriod*                      getNextPeriod(BasePeriod *period);
 
                 void                mergeWith(AbstractPlaylist *, mtime_t = 0);
+                void                pruneBySegmentNumber(uint64_t);
                 void                getTimeLinesBoundaries(mtime_t *, mtime_t *) const;
                 void                getPlaylistDurationsRange(mtime_t *, mtime_t *) const;
 
diff --git a/modules/demux/adaptative/playlist/SegmentInformation.cpp b/modules/demux/adaptative/playlist/SegmentInformation.cpp
index ac4c578..725f95d 100644
--- a/modules/demux/adaptative/playlist/SegmentInformation.cpp
+++ b/modules/demux/adaptative/playlist/SegmentInformation.cpp
@@ -69,8 +69,10 @@ AbstractPlaylist * SegmentInformation::getPlaylist() const
         return NULL;
 }
 
-std::size_t SegmentInformation::getSegments(SegmentInfoType type, vector<ISegment *> &retSegments) const
+std::size_t SegmentInformation::getSegments(SegmentInfoType type, vector<ISegment *> &retSegments,
+                                            std::size_t *offset) const
 {
+    std::size_t off = 0;
     switch (type)
     {
         case INFOTYPE_INIT:
@@ -106,6 +108,7 @@ std::size_t SegmentInformation::getSegments(SegmentInfoType type, vector<ISegmen
                     std::vector<ISegment *> list = (*it)->subSegments();
                     retSegments.insert( retSegments.end(), list.begin(), list.end() );
                 }
+                off = segmentList->getOffset();
             }
             else if( segmentBase )
             {
@@ -134,9 +137,15 @@ std::size_t SegmentInformation::getSegments(SegmentInfoType type, vector<ISegmen
     }
 
     if( retSegments.empty() && parent )
-        return parent->getSegments( type, retSegments );
+    {
+        return parent->getSegments( type, retSegments, offset );
+    }
     else
+    {
+        if( offset )
+            *offset = off;
         return retSegments.size();
+    }
 }
 
 std::size_t SegmentInformation::getAllSegments(vector<ISegment *> &retSegments) const
@@ -155,7 +164,8 @@ ISegment * SegmentInformation::getSegment(SegmentInfoType type, uint64_t pos) co
     ISegment *segment = NULL;
 
     vector<ISegment *> retSegments;
-    const size_t size = getSegments( type, retSegments );
+    std::size_t offset = 0;
+    const size_t size = getSegments( type, retSegments, &offset );
     if( size )
     {
         /* check if that's a template (fixme: find a better way) */
@@ -166,9 +176,9 @@ ISegment * SegmentInformation::getSegment(SegmentInfoType type, uint64_t pos) co
                templ->segmentTimeline.Get()->maxElementNumber() > pos)
                 return templ;
         }
-        else if( pos < size )
+        else if( pos < size + offset && pos >= offset )
         {
-            segment = retSegments[pos];
+            segment = retSegments[pos - offset];
         }
     }
 
@@ -291,6 +301,15 @@ void SegmentInformation::mergeWith(SegmentInformation *updated, mtime_t prunetim
     }
 }
 
+void SegmentInformation::pruneBySegmentNumber(uint64_t num)
+{
+    if(segmentList)
+        segmentList->pruneBySegmentNumber(num);
+
+    for(size_t i=0; i<childs.size(); i++)
+        childs.at(i)->pruneBySegmentNumber(num);
+}
+
 bool SegmentInformation::canBitswitch() const
 {
     if(bitswitch_policy == BITSWITCH_INHERIT)
diff --git a/modules/demux/adaptative/playlist/SegmentInformation.hpp b/modules/demux/adaptative/playlist/SegmentInformation.hpp
index 503ac67..895458d 100644
--- a/modules/demux/adaptative/playlist/SegmentInformation.hpp
+++ b/modules/demux/adaptative/playlist/SegmentInformation.hpp
@@ -80,10 +80,11 @@ namespace adaptative
                 void collectTimelines(std::vector<SegmentTimeline *> *) const;
                 void getDurationsRange(mtime_t *, mtime_t *) const;
                 virtual void mergeWith(SegmentInformation *, mtime_t);
+                virtual void pruneBySegmentNumber(uint64_t);
 
             protected:
                 std::size_t getAllSegments(std::vector<ISegment *> &) const;
-                std::size_t getSegments(SegmentInfoType, std::vector<ISegment *>&) const;
+                std::size_t getSegments(SegmentInfoType, std::vector<ISegment *>&, std::size_t * = NULL) const;
                 std::vector<SegmentInformation *> childs;
                 SegmentInformation *parent;
 
diff --git a/modules/demux/adaptative/playlist/SegmentList.cpp b/modules/demux/adaptative/playlist/SegmentList.cpp
index 4e8b54b..a298941 100644
--- a/modules/demux/adaptative/playlist/SegmentList.cpp
+++ b/modules/demux/adaptative/playlist/SegmentList.cpp
@@ -31,6 +31,7 @@ using namespace adaptative::playlist;
 SegmentList::SegmentList( SegmentInformation *parent ):
     SegmentInfoCommon( parent ), TimescaleAble( parent )
 {
+    pruned = 0;
 }
 SegmentList::~SegmentList()
 {
@@ -64,3 +65,28 @@ void SegmentList::mergeWith(SegmentList *updated)
     }
     updated->segments.clear();
 }
+
+void SegmentList::pruneBySegmentNumber(uint64_t tobelownum)
+{
+    if(tobelownum < pruned)
+        return;
+
+    uint64_t current = pruned;
+    std::vector<Segment *>::iterator it = segments.begin();
+    while(it != segments.end() && current < tobelownum)
+    {
+        Segment *seg = *it;
+        if(seg->chunksuse.Get()) /* can't prune from here, still in use */
+            break;
+        delete *it;
+        it = segments.erase(it);
+
+        current++;
+        pruned++;
+    }
+}
+
+std::size_t SegmentList::getOffset() const
+{
+    return pruned;
+}
diff --git a/modules/demux/adaptative/playlist/SegmentList.h b/modules/demux/adaptative/playlist/SegmentList.h
index 8db3fe7..69e7aef 100644
--- a/modules/demux/adaptative/playlist/SegmentList.h
+++ b/modules/demux/adaptative/playlist/SegmentList.h
@@ -48,9 +48,12 @@ namespace adaptative
                 const std::vector<Segment *>&   getSegments() const;
                 void                    addSegment(Segment *seg);
                 void                    mergeWith(SegmentList *);
+                void                    pruneBySegmentNumber(uint64_t);
+                std::size_t             getOffset() const;
 
             private:
                 std::vector<Segment *>  segments;
+                std::size_t pruned;
         };
     }
 }



More information about the vlc-commits mailing list