[vlc-commits] chromecast: fix clock gap when paused

Thomas Guillem git at videolan.org
Fri Feb 23 08:29:42 CET 2018


vlc/vlc-3.0 | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Feb 20 17:52:13 2018 +0100| [9b48f4bb199f3a9da8abc50fe6210b7cd34ebaac] | committer: Thomas Guillem

chromecast: fix clock gap when paused

This commit try to work arround the internal clock gap caused by
input_clock_ChangePause() when the input is paused since the chromecast
internal clock won't change when paused.

This is far from perfect and can fail in a number of cases.

(cherry picked from commit ab69d591898af6d64f0c4a75c03cd63d19e175de)
Signed-off-by: Thomas Guillem <thomas at gllm.fr>

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

 modules/stream_out/chromecast/cast.cpp             |  7 ++++++
 modules/stream_out/chromecast/chromecast.h         |  5 ++--
 modules/stream_out/chromecast/chromecast_common.h  |  2 +-
 modules/stream_out/chromecast/chromecast_ctrl.cpp  | 13 +++++++---
 modules/stream_out/chromecast/chromecast_demux.cpp | 28 ++++++++++++++++++----
 5 files changed, 45 insertions(+), 10 deletions(-)

diff --git a/modules/stream_out/chromecast/cast.cpp b/modules/stream_out/chromecast/cast.cpp
index 2b683014c3..d0556aea18 100644
--- a/modules/stream_out/chromecast/cast.cpp
+++ b/modules/stream_out/chromecast/cast.cpp
@@ -317,6 +317,13 @@ static int ProxySend(sout_stream_t *p_stream, sout_stream_id_sys_t *id,
                 return VLC_SUCCESS;
             }
         }
+
+        mtime_t pause_delay = p_sys->p_intf->getPauseDelay();
+        if( p_buffer->i_pts != VLC_TS_INVALID )
+            p_buffer->i_pts -= pause_delay;
+        if( p_buffer->i_dts != VLC_TS_INVALID )
+            p_buffer->i_dts -= pause_delay;
+
         int ret = sout_StreamIdSend(p_stream->p_next, id, p_buffer);
         if (ret == VLC_SUCCESS && !p_sys->cc_has_input)
         {
diff --git a/modules/stream_out/chromecast/chromecast.h b/modules/stream_out/chromecast/chromecast.h
index 35a74e8d44..417ad5b09f 100644
--- a/modules/stream_out/chromecast/chromecast.h
+++ b/modules/stream_out/chromecast/chromecast.h
@@ -180,6 +180,7 @@ struct intf_sys_t
     void setPacing(bool do_pace);
     int pace();
     void sendInputEvent(enum cc_input_event event, union cc_input_arg arg);
+    mtime_t getPauseDelay();
 
     int httpd_file_fill( uint8_t *psz_request, uint8_t **pp_data, int *pi_data );
     void interrupt_wake_up();
@@ -189,7 +190,7 @@ private:
     void processMessage(const castchannel::CastMessage &msg);
     void queueMessage( QueueableMessages msg );
 
-    void setPauseState(bool paused);
+    void setPauseState(bool paused, mtime_t delay);
     bool isFinishedPlaying();
     bool isStateError() const;
     bool isStatePlaying() const;
@@ -224,7 +225,7 @@ private:
     static void send_input_event(void *, enum cc_input_event event, union cc_input_arg arg);
     static void set_on_paused_changed_cb(void *, on_paused_changed_itf, void *);
 
-    static void set_pause_state(void*, bool paused);
+    static void set_pause_state(void*, bool paused, mtime_t delay);
 
     static void set_meta(void*, vlc_meta_t *p_meta);
 
diff --git a/modules/stream_out/chromecast/chromecast_common.h b/modules/stream_out/chromecast/chromecast_common.h
index 18487792e0..8b4199fed7 100644
--- a/modules/stream_out/chromecast/chromecast_common.h
+++ b/modules/stream_out/chromecast/chromecast_common.h
@@ -66,7 +66,7 @@ typedef struct
 
     void (*pf_send_input_event)(void*, enum cc_input_event, union cc_input_arg);
 
-    void (*pf_set_pause_state)(void*, bool paused);
+    void (*pf_set_pause_state)(void*, bool paused, mtime_t delay);
 
     void (*pf_set_meta)(void*, vlc_meta_t *p_meta);
 
diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp b/modules/stream_out/chromecast/chromecast_ctrl.cpp
index 72481d6612..2afcf54238 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -1029,7 +1029,7 @@ void intf_sys_t::setOnPausedChangedCb(on_paused_changed_itf on_paused_changed,
     m_on_paused_changed_data = on_paused_changed_data;
 }
 
-void intf_sys_t::setPauseState(bool paused)
+void intf_sys_t::setPauseState(bool paused, mtime_t delay)
 {
     vlc_mutex_locker locker( &m_lock );
     if ( m_mediaSessionId == 0 || paused == m_paused )
@@ -1041,12 +1041,19 @@ void intf_sys_t::setPauseState(bool paused)
     {
         m_last_request_id =
             m_communication.msgPlayerPlay( m_appTransportId, m_mediaSessionId );
+        m_pause_delay = delay;
     }
     else if ( m_state != Paused )
         m_last_request_id =
             m_communication.msgPlayerPause( m_appTransportId, m_mediaSessionId );
 }
 
+mtime_t intf_sys_t::getPauseDelay()
+{
+    vlc_mutex_locker locker( &m_lock );
+    return m_pause_delay;
+}
+
 bool intf_sys_t::isFinishedPlaying()
 {
     return m_cc_eof || isStateError() || m_state == Stopped;
@@ -1143,10 +1150,10 @@ void intf_sys_t::send_input_event(void *pt, enum cc_input_event event, union cc_
     return p_this->sendInputEvent(event, arg);
 }
 
-void intf_sys_t::set_pause_state(void *pt, bool paused)
+void intf_sys_t::set_pause_state(void *pt, bool paused, mtime_t delay)
 {
     intf_sys_t *p_this = static_cast<intf_sys_t*>(pt);
-    p_this->setPauseState( paused );
+    p_this->setPauseState( paused, delay );
 }
 
 void intf_sys_t::set_meta(void *pt, vlc_meta_t *p_meta)
diff --git a/modules/stream_out/chromecast/chromecast_demux.cpp b/modules/stream_out/chromecast/chromecast_demux.cpp
index cdce20d55e..eed399fdfe 100644
--- a/modules/stream_out/chromecast/chromecast_demux.cpp
+++ b/modules/stream_out/chromecast/chromecast_demux.cpp
@@ -45,6 +45,8 @@ struct demux_sys_t
         :p_demux(demux)
         ,p_renderer(renderer)
         ,m_enabled( true )
+        ,m_pause_date( VLC_TS_INVALID )
+        ,m_pause_delay( VLC_TS_INVALID )
     {
         init();
     }
@@ -167,9 +169,9 @@ struct demux_sys_t
                                          cc_input_arg { false } );
     }
 
-    void setPauseState(bool paused)
+    void setPauseState(bool paused, mtime_t delay)
     {
-        p_renderer->pf_set_pause_state( p_renderer->p_opaque, paused );
+        p_renderer->pf_set_pause_state( p_renderer->p_opaque, paused, delay );
     }
 
     mtime_t getCCTime()
@@ -180,7 +182,7 @@ struct demux_sys_t
 
         mtime_t cc_time = p_renderer->pf_get_time( p_renderer->p_opaque );
         if( cc_time != VLC_TS_INVALID )
-            return cc_time - system;
+            return cc_time - system + m_pause_delay;
         return VLC_TS_INVALID;
     }
 
@@ -331,6 +333,7 @@ struct demux_sys_t
 
         case DEMUX_SET_POSITION:
         {
+            m_pause_delay = m_pause_date = VLC_TS_INVALID;
 
             double pos = va_arg( args, double );
             /* Force unprecise seek */
@@ -344,6 +347,7 @@ struct demux_sys_t
         }
         case DEMUX_SET_TIME:
         {
+            m_pause_delay = m_pause_date = VLC_TS_INVALID;
 
             mtime_t time = va_arg( args, int64_t );
             /* Force unprecise seek */
@@ -363,7 +367,21 @@ struct demux_sys_t
             int paused = va_arg( ap, int );
             va_end( ap );
 
-            setPauseState( paused != 0 );
+            if (paused)
+            {
+                if (m_pause_date == VLC_TS_INVALID)
+                    m_pause_date = mdate();
+            }
+            else
+            {
+                if (m_pause_date != VLC_TS_INVALID)
+                {
+                    m_pause_delay += mdate() - m_pause_date;
+                    m_pause_date = VLC_TS_INVALID;
+                }
+            }
+
+            setPauseState( paused != 0, m_pause_delay );
             break;
         }
         case DEMUX_SET_ES:
@@ -434,6 +452,8 @@ protected:
     double        m_last_pos;
     mtime_t       m_start_time;
     mtime_t       m_last_time;
+    mtime_t       m_pause_date;
+    mtime_t       m_pause_delay;
 };
 
 static void on_paused_changed_cb( void *data, bool paused )



More information about the vlc-commits mailing list