[vlc-commits] demux: adaptive: allow to retimestamp on segmentList merge

Francois Cartegnie git at videolan.org
Thu Nov 24 18:16:25 CET 2016


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Nov 24 18:14:50 2016 +0100| [9b428d6823c675fd8c58f1fb2f7f16e4a8154c06] | committer: Francois Cartegnie

demux: adaptive: allow to retimestamp on segmentList merge

incorrect segment time with hls updates

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

 .../demux/adaptive/playlist/SegmentInformation.cpp |  4 ++--
 .../demux/adaptive/playlist/SegmentInformation.hpp |  2 +-
 modules/demux/adaptive/playlist/SegmentList.cpp    | 22 ++++++++++++++++++----
 modules/demux/adaptive/playlist/SegmentList.h      |  2 +-
 modules/demux/dash/mpd/IsoffMainParser.cpp         |  2 +-
 modules/demux/hls/playlist/Parser.cpp              |  2 +-
 modules/demux/smooth/playlist/Parser.cpp           |  2 +-
 7 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/modules/demux/adaptive/playlist/SegmentInformation.cpp b/modules/demux/adaptive/playlist/SegmentInformation.cpp
index 5d31f20..69c965f 100644
--- a/modules/demux/adaptive/playlist/SegmentInformation.cpp
+++ b/modules/demux/adaptive/playlist/SegmentInformation.cpp
@@ -500,11 +500,11 @@ mtime_t SegmentInformation::getPeriodStart() const
         return 0;
 }
 
-void SegmentInformation::setSegmentList(SegmentList *list)
+void SegmentInformation::appendSegmentList(SegmentList *list, bool restamp)
 {
     if(segmentList)
     {
-        segmentList->mergeWith(list);
+        segmentList->mergeWith(list, restamp);
         delete list;
     }
     else
diff --git a/modules/demux/adaptive/playlist/SegmentInformation.hpp b/modules/demux/adaptive/playlist/SegmentInformation.hpp
index 4284076..cb20e74 100644
--- a/modules/demux/adaptive/playlist/SegmentInformation.hpp
+++ b/modules/demux/adaptive/playlist/SegmentInformation.hpp
@@ -95,7 +95,7 @@ namespace adaptive
                 SwitchPolicy switchpolicy;
 
             public:
-                void setSegmentList(SegmentList *);
+                void appendSegmentList(SegmentList *, bool = false);
                 void setSegmentBase(SegmentBase *);
                 void setSegmentTemplate(MediaSegmentTemplate *);
                 void setSwitchPolicy(SwitchPolicy);
diff --git a/modules/demux/adaptive/playlist/SegmentList.cpp b/modules/demux/adaptive/playlist/SegmentList.cpp
index fa9dcfe..59755da 100644
--- a/modules/demux/adaptive/playlist/SegmentList.cpp
+++ b/modules/demux/adaptive/playlist/SegmentList.cpp
@@ -71,17 +71,31 @@ void SegmentList::addSegment(ISegment *seg)
     segments.push_back(seg);
 }
 
-void SegmentList::mergeWith(SegmentList *updated)
+void SegmentList::mergeWith(SegmentList *updated, bool b_restamp)
 {
     const ISegment * lastSegment = (segments.empty()) ? NULL : segments.back();
+    const ISegment * prevSegment = lastSegment;
 
     std::vector<ISegment *>::iterator it;
     for(it = updated->segments.begin(); it != updated->segments.end(); ++it)
     {
-        if( !lastSegment || lastSegment->compare( *it ) < 0 )
-            addSegment(*it);
+        ISegment *cur = *it;
+        if(!lastSegment || lastSegment->compare(cur) < 0)
+        {
+            if(b_restamp && prevSegment)
+            {
+                stime_t starttime = prevSegment->startTime.Get() + prevSegment->duration.Get();
+                if(starttime != cur->startTime.Get() && !cur->discontinuity)
+                {
+                    cur->startTime.Set(starttime);
+                }
+
+                prevSegment = cur;
+            }
+            addSegment(cur);
+        }
         else
-            delete *it;
+            delete cur;
     }
     updated->segments.clear();
 }
diff --git a/modules/demux/adaptive/playlist/SegmentList.h b/modules/demux/adaptive/playlist/SegmentList.h
index 815daeb..4c590c1 100644
--- a/modules/demux/adaptive/playlist/SegmentList.h
+++ b/modules/demux/adaptive/playlist/SegmentList.h
@@ -44,7 +44,7 @@ namespace adaptive
                 const std::vector<ISegment *>&   getSegments() const;
                 ISegment *              getSegmentByNumber(uint64_t);
                 void                    addSegment(ISegment *seg);
-                void                    mergeWith(SegmentList *);
+                void                    mergeWith(SegmentList *, bool = false);
                 void                    pruneBySegmentNumber(uint64_t);
                 void                    pruneByPlaybackTime(mtime_t);
                 bool                    getSegmentNumberByScaledTime(stime_t, uint64_t *) const;
diff --git a/modules/demux/dash/mpd/IsoffMainParser.cpp b/modules/demux/dash/mpd/IsoffMainParser.cpp
index 73b2b2f..d9ed049 100644
--- a/modules/demux/dash/mpd/IsoffMainParser.cpp
+++ b/modules/demux/dash/mpd/IsoffMainParser.cpp
@@ -409,7 +409,7 @@ size_t IsoffMainParser::parseSegmentList(Node * segListNode, SegmentInformation
                 total++;
             }
 
-            info->setSegmentList(list);
+            info->appendSegmentList(list, true);
         }
     }
     return total;
diff --git a/modules/demux/hls/playlist/Parser.cpp b/modules/demux/hls/playlist/Parser.cpp
index e2ff062..178d019 100644
--- a/modules/demux/hls/playlist/Parser.cpp
+++ b/modules/demux/hls/playlist/Parser.cpp
@@ -378,7 +378,7 @@ void M3U8Parser::parseSegments(vlc_object_t *p_obj, Representation *rep, const s
         rep->getPlaylist()->duration.Set(totalduration);
     }
 
-    rep->setSegmentList(segmentList);
+    rep->appendSegmentList(segmentList, true);
 }
 M3U8 * M3U8Parser::parse(vlc_object_t *p_object, stream_t *p_stream, const std::string &playlisturl)
 {
diff --git a/modules/demux/smooth/playlist/Parser.cpp b/modules/demux/smooth/playlist/Parser.cpp
index b16245c..82d5430 100644
--- a/modules/demux/smooth/playlist/Parser.cpp
+++ b/modules/demux/smooth/playlist/Parser.cpp
@@ -206,7 +206,7 @@ static void ParseQualityLevel(BaseAdaptationSet *adaptSet, Node *qualNode, const
                 initSegment->setSourceUrl("forged://");
                 segmentList->initialisationSegment.Set(initSegment);
             }
-            rep->setSegmentList(segmentList);
+            rep->appendSegmentList(segmentList);
 
             adaptSet->addRepresentation(rep);
         }



More information about the vlc-commits mailing list