[vlc-commits] demux: hls: compute pdt time for pre discontinuity

Francois Cartegnie git at videolan.org
Wed Apr 7 12:36:06 UTC 2021


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Mar 30 20:11:32 2021 +0200| [8aeb1940264e488324753b6a898dddaec93c3b60] | committer: Francois Cartegnie

demux: hls: compute pdt time for pre discontinuity

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

 modules/demux/hls/playlist/Parser.cpp | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/modules/demux/hls/playlist/Parser.cpp b/modules/demux/hls/playlist/Parser.cpp
index aa2869dad7..824849ad26 100644
--- a/modules/demux/hls/playlist/Parser.cpp
+++ b/modules/demux/hls/playlist/Parser.cpp
@@ -234,6 +234,8 @@ void M3U8Parser::parseSegments(vlc_object_t *, HLSRepresentation *rep, const std
     CommonEncryption encryption;
     const ValuesListTag *ctx_extinf = nullptr;
 
+    std::list<HLSSegment *> segmentstoappend;
+
     std::list<Tag *>::const_iterator it;
     for(it = tagslist.begin(); it != tagslist.end(); ++it)
     {
@@ -288,7 +290,7 @@ void M3U8Parser::parseSegments(vlc_object_t *, HLSRepresentation *rep, const std
                     absReferenceTime += nzDuration;
                 }
 
-                segmentList->addSegment(segment);
+                segmentstoappend.push_back(segment);
 
                 if(ctx_byterange)
                 {
@@ -327,6 +329,20 @@ void M3U8Parser::parseSegments(vlc_object_t *, HLSRepresentation *rep, const std
                 rep->b_consistent = false;
                 absReferenceTime = VLC_TICK_0 +
                         UTCTime(static_cast<const SingleValueTag *>(tag)->getValue().value).mtime();
+                /* Reverse apply UTC timespec from first discont */
+                if(segmentstoappend.size() && segmentstoappend.back()->utcTime == VLC_TICK_INVALID)
+                {
+                    vlc_tick_t tempTime = absReferenceTime;
+                    for(auto it = segmentstoappend.crbegin(); it != segmentstoappend.crend(); ++it)
+                    {
+                        vlc_tick_t duration = timescale.ToTime((*it)->duration.Get());
+                        if( duration < tempTime - VLC_TICK_0 )
+                            tempTime -= duration;
+                        else
+                            tempTime = VLC_TICK_0;
+                        (*it)->utcTime = tempTime;
+                    }
+                }
                 break;
 
             case AttributesTag::EXTXKEY:
@@ -367,6 +383,10 @@ void M3U8Parser::parseSegments(vlc_object_t *, HLSRepresentation *rep, const std
         }
     }
 
+    for(HLSSegment *seg : segmentstoappend)
+        segmentList->addSegment(seg);
+    segmentstoappend.clear();
+
     if(rep->isLive())
     {
         rep->getPlaylist()->duration.Set(0);



More information about the vlc-commits mailing list