[vlc-commits] demux: adaptive: fix in-band and out-of-band time offset handling

Francois Cartegnie git at videolan.org
Mon Sep 12 14:09:34 CEST 2016


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sun Sep 11 18:54:39 2016 +0200| [62ecf35d7e39639adf9464035384a5bb98450108] | committer: Francois Cartegnie

demux: adaptive: fix in-band and out-of-band time offset handling

was regression with AAC seek since rewrite of buffering

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

 modules/demux/adaptive/Streams.cpp | 20 +++++++++-----
 modules/demux/adaptive/Streams.hpp |  2 +-
 modules/demux/hls/HLSStreams.cpp   | 54 ++++++++++++++++----------------------
 modules/demux/hls/HLSStreams.hpp   |  8 ++----
 4 files changed, 38 insertions(+), 46 deletions(-)

diff --git a/modules/demux/adaptive/Streams.cpp b/modules/demux/adaptive/Streams.cpp
index b67cf7a..b59dc31 100644
--- a/modules/demux/adaptive/Streams.cpp
+++ b/modules/demux/adaptive/Streams.cpp
@@ -112,6 +112,7 @@ void AbstractStream::prepareRestart(bool b_discontinuity)
     {
         /* Enqueue Del Commands for all current ES */
         demuxer->drain();
+        setTimeOffset(true);
         /* Enqueue Del Commands for all current ES */
         fakeesout->scheduleAllForDeletion();
         if(b_discontinuity)
@@ -294,7 +295,6 @@ AbstractStream::buffering_status AbstractStream::bufferize(mtime_t nz_deadline,
             vlc_mutex_unlock(&lock);
             return AbstractStream::buffering_end;
         }
-        setTimeOffset();
     }
 
     const int64_t i_total_buffering = i_min_buffering + i_extra_buffering;
@@ -443,10 +443,11 @@ bool AbstractStream::setPosition(mtime_t time, bool tryonly)
             currentChunk = NULL;
             needrestart = false;
 
+            setTimeOffset(-1);
+            setTimeOffset(segmentTracker->getPlaybackTime());
+
             if( !restartDemux() )
                 dead = true;
-
-            setTimeOffset();
         }
         else commandsqueue->Abort( true );
 
@@ -475,14 +476,19 @@ void AbstractStream::fillExtraFMTInfo( es_format_t *p_fmt ) const
         p_fmt->psz_description = strdup(description.c_str());
 }
 
-void AbstractStream::setTimeOffset()
+void AbstractStream::setTimeOffset(mtime_t i_offset)
 {
     /* Check if we need to set an offset as the demuxer
      * will start from zero from seek point */
-    if(demuxer && demuxer->alwaysStartsFromZero())
-        fakeesout->setTimestampOffset(segmentTracker->getPlaybackTime());
-    else
+    if(i_offset < 0) /* reset */
+    {
         fakeesout->setTimestampOffset(0);
+    }
+    else if(demuxer)
+    {
+        if(demuxer->alwaysStartsFromZero())
+            fakeesout->setTimestampOffset(i_offset);
+    }
 }
 
 void AbstractStream::trackerEvent(const SegmentTrackerEvent &event)
diff --git a/modules/demux/adaptive/Streams.hpp b/modules/demux/adaptive/Streams.hpp
index ebf0962..3d8e508 100644
--- a/modules/demux/adaptive/Streams.hpp
+++ b/modules/demux/adaptive/Streams.hpp
@@ -95,7 +95,7 @@ namespace adaptive
 
     protected:
         bool seekAble() const;
-        virtual void setTimeOffset();
+        virtual void setTimeOffset(mtime_t);
         virtual block_t *checkBlock(block_t *, bool) = 0;
         virtual AbstractDemuxer * createDemux(const StreamFormat &) = 0;
         virtual bool startDemux();
diff --git a/modules/demux/hls/HLSStreams.cpp b/modules/demux/hls/HLSStreams.cpp
index 18302f8..49f125d 100644
--- a/modules/demux/hls/HLSStreams.cpp
+++ b/modules/demux/hls/HLSStreams.cpp
@@ -34,28 +34,27 @@ using namespace hls;
 HLSStream::HLSStream(demux_t *demux)
     : AbstractStream(demux)
 {
-    b_timestamps_offset_set = false;
-    i_aac_offset = 0;
+    b_id3_timestamps_offset_set = false;
 }
 
-bool HLSStream::setPosition(mtime_t time, bool tryonly)
+void HLSStream::setTimeOffset(mtime_t i_offset)
 {
-    bool b_ret = AbstractStream::setPosition(time, tryonly);
-    if(!tryonly && b_ret)
+    if(i_offset >= 0)
     {
-        /* Should be correct, has a restarted demux shouldn't have been fed with data yet */
-        fakeesout->setTimestampOffset( VLC_TS_INVALID );
-        b_timestamps_offset_set = false;
+        if((unsigned)format == StreamFormat::PACKEDAAC)
+        {
+            if(!b_id3_timestamps_offset_set)
+            {
+                fakeesout->setTimestampOffset(i_offset);
+            }
+            return;
+        }
     }
-    return b_ret;
-}
-
-bool HLSStream::restartDemux()
-{
-    bool b_ret = AbstractStream::restartDemux();
-    if(b_ret)
-        b_timestamps_offset_set = false;
-    return b_ret;
+    else
+    {
+        b_id3_timestamps_offset_set = false;
+    }
+    AbstractStream::setTimeOffset(i_offset);
 }
 
 AbstractDemuxer * HLSStream::createDemux(const StreamFormat &format)
@@ -93,26 +92,17 @@ AbstractDemuxer * HLSStream::createDemux(const StreamFormat &format)
     return ret;
 }
 
-void HLSStream::prepareRestart(bool b_discontinuity)
-{
-    AbstractStream::prepareRestart(b_discontinuity);
-    if((unsigned)format == StreamFormat::PACKEDAAC)
-    {
-        fakeesout->setTimestampOffset( i_aac_offset );
-    }
-    else
-    {
-        fakeesout->setTimestampOffset( 0 );
-    }
-}
-
 int HLSStream::ID3PrivTagHandler(const uint8_t *p_payload, size_t i_payload)
 {
     if(i_payload == 53 &&
        !memcmp( p_payload, "com.apple.streaming.transportStreamTimestamp", 45))
     {
-        i_aac_offset = GetQWBE(&p_payload[45]) * 100 / 9;
-        b_timestamps_offset_set = true;
+        if(!b_id3_timestamps_offset_set)
+        {
+            const mtime_t i_aac_offset = GetQWBE(&p_payload[45]) * 100 / 9;
+            setTimeOffset(i_aac_offset);
+            b_id3_timestamps_offset_set = true;
+        }
         return VLC_EGENERIC; /* stop parsing */
     }
     return VLC_SUCCESS;
diff --git a/modules/demux/hls/HLSStreams.hpp b/modules/demux/hls/HLSStreams.hpp
index 4cdf99f..fb32a70 100644
--- a/modules/demux/hls/HLSStreams.hpp
+++ b/modules/demux/hls/HLSStreams.hpp
@@ -30,19 +30,15 @@ namespace hls
     {
         public:
             HLSStream(demux_t *);
-            virtual bool setPosition(mtime_t, bool); /* reimpl */
             int ID3PrivTagHandler( const uint8_t *, size_t );
 
         protected:
             virtual AbstractDemuxer * createDemux(const StreamFormat &); /* reimpl */
-            virtual bool restartDemux(); /* reimpl */
-            virtual void prepareRestart(bool = true); /* reimpl */
-
+            virtual void setTimeOffset(mtime_t); /* reimpl */
             virtual block_t *checkBlock(block_t *, bool); /* reimpl */
 
         private:
-            bool b_timestamps_offset_set;
-            mtime_t i_aac_offset;
+            bool b_id3_timestamps_offset_set;
     };
 
     class HLSStreamFactory : public AbstractStreamFactory



More information about the vlc-commits mailing list