[vlc-commits] demux: adaptive: simplify subsegments

Francois Cartegnie git at videolan.org
Fri Nov 27 11:23:16 CET 2020


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Oct 14 17:56:23 2020 +0200| [961c06b95899d0b9f6246d0e2e7e6860c29eb72e] | committer: Francois Cartegnie

demux: adaptive: simplify subsegments

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

 modules/demux/adaptive/playlist/Segment.cpp        | 30 +++-------------------
 modules/demux/adaptive/playlist/Segment.h          |  8 ++----
 .../demux/adaptive/playlist/SegmentInformation.cpp | 18 ++++++-------
 modules/demux/adaptive/playlist/SegmentList.cpp    | 10 +-------
 4 files changed, 16 insertions(+), 50 deletions(-)

diff --git a/modules/demux/adaptive/playlist/Segment.cpp b/modules/demux/adaptive/playlist/Segment.cpp
index a61b0fc188..fbe171e6a5 100644
--- a/modules/demux/adaptive/playlist/Segment.cpp
+++ b/modules/demux/adaptive/playlist/Segment.cpp
@@ -213,7 +213,7 @@ void Segment::addSubSegment(SubSegment *subsegment)
 
 Segment::~Segment()
 {
-    std::vector<SubSegment*>::iterator it;
+    std::vector<ISegment*>::iterator it;
     for(it=subsegments.begin();it!=subsegments.end();++it)
         delete *it;
 }
@@ -235,7 +235,7 @@ void Segment::debug(vlc_object_t *obj, int indent) const
         std::string text(indent, ' ');
         text.append("Segment");
         msg_Dbg(obj, "%s", text.c_str());
-        std::vector<SubSegment *>::const_iterator l;
+        std::vector<ISegment *>::const_iterator l;
         for(l = subsegments.begin(); l != subsegments.end(); ++l)
             (*l)->debug(obj, indent + 1);
     }
@@ -256,20 +256,9 @@ Url Segment::getUrlSegment() const
     }
 }
 
-std::vector<ISegment*> Segment::subSegments()
+std::vector<ISegment*> & Segment::subSegments()
 {
-    std::vector<ISegment*> list;
-    if(!subsegments.empty())
-    {
-        std::vector<SubSegment*>::iterator it;
-        for(it=subsegments.begin();it!=subsegments.end();++it)
-            list.push_back(*it);
-    }
-    else
-    {
-        list.push_back(this);
-    }
-    return list;
+    return subsegments;
 }
 
 InitSegment::InitSegment(ICanonicalUrl *parent) :
@@ -305,14 +294,3 @@ Url SubSegment::getUrlSegment() const
     return getParentUrlSegment();
 }
 
-std::vector<ISegment*> SubSegment::subSegments()
-{
-    std::vector<ISegment*> list;
-    list.push_back(this);
-    return list;
-}
-
-void SubSegment::addSubSegment(SubSegment *)
-{
-
-}
diff --git a/modules/demux/adaptive/playlist/Segment.h b/modules/demux/adaptive/playlist/Segment.h
index 46b4b131ad..595dcd9592 100644
--- a/modules/demux/adaptive/playlist/Segment.h
+++ b/modules/demux/adaptive/playlist/Segment.h
@@ -70,8 +70,6 @@ namespace adaptive
                 virtual uint64_t                        getSequenceNumber() const;
                 virtual bool                            isTemplate      () const;
                 virtual size_t                          getOffset       () const;
-                virtual std::vector<ISegment*>          subSegments     () = 0;
-                virtual void                            addSubSegment   (SubSegment *) = 0;
                 virtual void                            debug           (vlc_object_t *,int = 0) const;
                 virtual bool                            contains        (size_t byte) const;
                 virtual int                             compare         (ISegment *) const;
@@ -104,13 +102,13 @@ namespace adaptive
                 virtual SegmentChunk* createChunk(AbstractChunkSource *, BaseRepresentation *); /* impl */
                 virtual void setSourceUrl( const std::string &url );
                 virtual Url getUrlSegment() const; /* impl */
-                virtual std::vector<ISegment*> subSegments();
+                virtual std::vector<ISegment*> & subSegments();
                 virtual void debug(vlc_object_t *,int = 0) const;
                 virtual void addSubSegment(SubSegment *);
                 static const int CLASSID_SEGMENT = 1;
 
             protected:
-                std::vector<SubSegment *> subsegments;
+                std::vector<ISegment *> subsegments;
                 Url sourceUrl;
                 int size;
         };
@@ -135,8 +133,6 @@ namespace adaptive
                 SubSegment(ISegment *, size_t start, size_t end);
                 virtual SegmentChunk* createChunk(AbstractChunkSource *, BaseRepresentation *); /* impl */
                 virtual Url getUrlSegment() const; /* impl */
-                virtual std::vector<ISegment*> subSegments();
-                virtual void addSubSegment(SubSegment *);
                 static const int CLASSID_SUBSEGMENT = 4;
         };
     }
diff --git a/modules/demux/adaptive/playlist/SegmentInformation.cpp b/modules/demux/adaptive/playlist/SegmentInformation.cpp
index 0f70969e8e..6a71601645 100644
--- a/modules/demux/adaptive/playlist/SegmentInformation.cpp
+++ b/modules/demux/adaptive/playlist/SegmentInformation.cpp
@@ -107,13 +107,8 @@ std::size_t SegmentInformation::getSegments(SegmentInfoType type, std::vector<IS
             }
             else if ( segmentList && !segmentList->getSegments().empty() )
             {
-                std::vector<ISegment *>::const_iterator it;
-                for(it=segmentList->getSegments().begin();
-                    it!=segmentList->getSegments().end(); ++it)
-                {
-                    std::vector<ISegment *> list = (*it)->subSegments();
-                    retSegments.insert( retSegments.end(), list.begin(), list.end() );
-                }
+                std::vector<ISegment *> list = segmentList->getSegments();
+                retSegments.insert( retSegments.end(), list.begin(), list.end() );
             }
             else if( segmentBase )
             {
@@ -401,7 +396,7 @@ static void insertIntoSegment(std::vector<ISegment *> &seglist, size_t start,
             SubSegment *subsegment = new SubSegment(segment, start, (end != 0) ? end : 0);
             subsegment->startTime.Set(time);
             subsegment->duration.Set(duration);
-            segment->addSubSegment(subsegment);
+            static_cast<Segment *>(segment)->addSubSegment(subsegment);
             break;
         }
     }
@@ -409,8 +404,13 @@ static void insertIntoSegment(std::vector<ISegment *> &seglist, size_t start,
 
 void SegmentInformation::SplitUsingIndex(std::vector<SplitPoint> &splitlist)
 {
+    SegmentBase *segmentBase = inheritSegmentBase();
+    if(!segmentBase)
+        return;
+
     std::vector<ISegment *> seglist;
-    getSegments(INFOTYPE_MEDIA, seglist);
+    seglist.push_back( segmentBase );
+
     size_t prevstart = 0;
     stime_t prevtime = 0;
 
diff --git a/modules/demux/adaptive/playlist/SegmentList.cpp b/modules/demux/adaptive/playlist/SegmentList.cpp
index 7985e3ee85..3b47867e5f 100644
--- a/modules/demux/adaptive/playlist/SegmentList.cpp
+++ b/modules/demux/adaptive/playlist/SegmentList.cpp
@@ -135,15 +135,7 @@ void SegmentList::pruneBySegmentNumber(uint64_t tobelownum)
 
 bool SegmentList::getSegmentNumberByScaledTime(stime_t time, uint64_t *ret) const
 {
-    std::vector<ISegment *> allsubsegments;
-    std::vector<ISegment *>::const_iterator it;
-    for(it=segments.begin(); it!=segments.end(); ++it)
-    {
-        std::vector<ISegment *> list = (*it)->subSegments();
-        allsubsegments.insert( allsubsegments.end(), list.begin(), list.end() );
-    }
-
-    return SegmentInfoCommon::getSegmentNumberByScaledTime(allsubsegments, time, ret);
+    return SegmentInfoCommon::getSegmentNumberByScaledTime(segments, time, ret);
 }
 
 bool SegmentList::getPlaybackTimeDurationBySegmentNumber(uint64_t number,



More information about the vlc-commits mailing list