[vlc-commits] demux: adaptative: compute segment time in segmentlist

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:11:11 2015 +0200| [0771fb4bb24c3920a48642cc4026d5629a3157e6] | committer: Francois Cartegnie

demux: adaptative: compute segment time in segmentlist

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

 .../adaptative/playlist/SegmentInformation.cpp     |   10 +++------
 modules/demux/adaptative/playlist/SegmentList.cpp  |   23 ++++++++++++++++++++
 modules/demux/adaptative/playlist/SegmentList.h    |    1 +
 3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/modules/demux/adaptative/playlist/SegmentInformation.cpp b/modules/demux/adaptative/playlist/SegmentInformation.cpp
index 725f95d..963d96f 100644
--- a/modules/demux/adaptative/playlist/SegmentInformation.cpp
+++ b/modules/demux/adaptative/playlist/SegmentInformation.cpp
@@ -223,11 +223,10 @@ mtime_t SegmentInformation::getPlaybackTimeBySegmentNumber(uint64_t number) cons
 {
     SegmentList *segList;
     MediaSegmentTemplate *mediaTemplate;
-    uint64_t timescale = 1;
     mtime_t time = 0;
     if( (mediaTemplate = inheritSegmentTemplate()) )
     {
-        timescale = mediaTemplate->inheritTimescale();
+        uint64_t timescale = mediaTemplate->inheritTimescale();
         if(mediaTemplate->segmentTimeline.Get())
         {
             time = mediaTemplate->segmentTimeline.Get()->
@@ -237,16 +236,13 @@ mtime_t SegmentInformation::getPlaybackTimeBySegmentNumber(uint64_t number) cons
         {
             time = number * mediaTemplate->duration.Get();
         }
+        time = CLOCK_FREQ * time / timescale;
     }
     else if ( (segList = inheritSegmentList()) )
     {
-        timescale = segList->inheritTimescale();
-        time = number * segList->duration.Get();
+        time = segList->getPlaybackTimeBySegmentNumber(number);
     }
 
-    if(time)
-        time = CLOCK_FREQ * time / timescale;
-
     return time;
 }
 
diff --git a/modules/demux/adaptative/playlist/SegmentList.cpp b/modules/demux/adaptative/playlist/SegmentList.cpp
index a298941..e2486eb 100644
--- a/modules/demux/adaptative/playlist/SegmentList.cpp
+++ b/modules/demux/adaptative/playlist/SegmentList.cpp
@@ -86,6 +86,29 @@ void SegmentList::pruneBySegmentNumber(uint64_t tobelownum)
     }
 }
 
+mtime_t SegmentList::getPlaybackTimeBySegmentNumber(uint64_t number)
+{
+    if(number < pruned || segments.empty())
+        return 0;
+
+    uint64_t timescale = inheritTimescale();
+    mtime_t time = segments.at(0)->startTime.Get();
+
+    if(segments.at(0)->duration.Get())
+    {
+        number -= pruned;
+
+        for(size_t i=0; i<number && i<segments.size(); i++)
+            time += segments.at(i)->duration.Get();
+    }
+    else
+    {
+        time = number * duration.Get();
+    }
+
+    return CLOCK_FREQ * time / timescale;
+}
+
 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 69e7aef..a32a460 100644
--- a/modules/demux/adaptative/playlist/SegmentList.h
+++ b/modules/demux/adaptative/playlist/SegmentList.h
@@ -49,6 +49,7 @@ namespace adaptative
                 void                    addSegment(Segment *seg);
                 void                    mergeWith(SegmentList *);
                 void                    pruneBySegmentNumber(uint64_t);
+                mtime_t                 getPlaybackTimeBySegmentNumber(uint64_t);
                 std::size_t             getOffset() const;
 
             private:



More information about the vlc-commits mailing list