[vlc-commits] demux: adaptive: enable pause

Francois Cartegnie git at videolan.org
Fri Jan 22 15:12:29 UTC 2021


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Jan 14 14:04:12 2021 +0100| [f8ac5e2c52f85d5e85d3b74de5aae9be321c74d7] | committer: Francois Cartegnie

demux: adaptive: enable pause

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

 modules/demux/adaptive/PlaylistManager.cpp | 34 +++++++++++++++++++++++++++++-
 modules/demux/adaptive/PlaylistManager.h   |  2 ++
 modules/demux/adaptive/Streams.cpp         | 10 +++++++++
 modules/demux/adaptive/Streams.hpp         |  1 +
 4 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/modules/demux/adaptive/PlaylistManager.cpp b/modules/demux/adaptive/PlaylistManager.cpp
index 9f007892bc..66a7af3357 100644
--- a/modules/demux/adaptive/PlaylistManager.cpp
+++ b/modules/demux/adaptive/PlaylistManager.cpp
@@ -374,6 +374,16 @@ bool PlaylistManager::setPosition(vlc_tick_t time)
     return ret;
 }
 
+void PlaylistManager::setLivePause(bool b)
+{
+    if(!started())
+        return;
+
+    for(AbstractStream* st : streams)
+        if(st->isValid() && !st->isDisabled())
+            st->setLivePause(b);
+}
+
 bool PlaylistManager::needsUpdate() const
 {
     return playlist->needsUpdates() &&
@@ -541,7 +551,29 @@ int PlaylistManager::doControl(int i_query, va_list args)
         case DEMUX_SET_PAUSE_STATE:
         {
             vlc_mutex_locker locker(&cached.lock);
-            return cached.b_live ? VLC_EGENERIC : VLC_SUCCESS;
+            bool b_pause = (bool)va_arg(args, int);
+            if(playlist->isLive())
+            {
+                setBufferingRunState(false); /* stop downloader first */
+                vlc_tick_t now = vlc_tick_now();
+                if(b_pause)
+                {
+                    setLivePause(true);
+                    pause_start = now;
+                    msg_Dbg(p_demux,"Buffering and playback paused. No timeshift support.");
+                }
+                else
+                {
+                    setLivePause(false);
+                    msg_Dbg(p_demux,"Resuming buffering/playback after %" PRId64 "ms",
+                            MS_FROM_VLC_TICK(now-pause_start));
+                    es_out_Control(p_demux->out, ES_OUT_RESET_PCR);
+                }
+                setBufferingRunState(true);
+                demux.i_nzpcr = VLC_TICK_INVALID;
+                cached.lastupdate = 0;
+            }
+            return VLC_SUCCESS;
         }
 
         case DEMUX_GET_TIME:
diff --git a/modules/demux/adaptive/PlaylistManager.h b/modules/demux/adaptive/PlaylistManager.h
index e1ab594e46..32b9c691e1 100644
--- a/modules/demux/adaptive/PlaylistManager.h
+++ b/modules/demux/adaptive/PlaylistManager.h
@@ -76,6 +76,7 @@ namespace adaptive
             virtual int doControl(int, va_list);
             virtual int doDemux(vlc_tick_t);
 
+            void    setLivePause(bool);
             virtual bool    setPosition(vlc_tick_t);
             vlc_tick_t getResumeTime() const;
             vlc_tick_t getFirstDTS() const;
@@ -142,6 +143,7 @@ namespace adaptive
             bool         b_thread;
             bool         b_buffering;
             bool         b_canceled;
+            vlc_tick_t   pause_start;
     };
 
 }
diff --git a/modules/demux/adaptive/Streams.cpp b/modules/demux/adaptive/Streams.cpp
index 3928a01d34..9cf5be89c2 100644
--- a/modules/demux/adaptive/Streams.cpp
+++ b/modules/demux/adaptive/Streams.cpp
@@ -317,6 +317,16 @@ bool AbstractStream::isDisabled() const
     return disabled;
 }
 
+void AbstractStream::setLivePause(bool b)
+{
+    vlc_mutex_locker locker(&lock);
+    if(!b)
+    {
+        segmentTracker->setPosition(segmentTracker->getStartPosition(),
+                                    !demuxer || demuxer->needsRestartOnSeek());
+    }
+}
+
 bool AbstractStream::decodersDrained()
 {
     return fakeEsOut()->decodersDrained();
diff --git a/modules/demux/adaptive/Streams.hpp b/modules/demux/adaptive/Streams.hpp
index 2b961416f7..325c65c036 100644
--- a/modules/demux/adaptive/Streams.hpp
+++ b/modules/demux/adaptive/Streams.hpp
@@ -69,6 +69,7 @@ namespace adaptive
         virtual bool reactivate(vlc_tick_t);
         bool isDisabled() const;
         bool isValid() const;
+        void setLivePause(bool);
         enum class Status {
             Eof = 0, /* prioritized */
             Discontinuity,



More information about the vlc-commits mailing list