[vlc-devel] [PATCH 09/11] chromecast: pause immediatly the device when pausing the player

Steve Lhomme robux4 at videolabs.io
Mon Jun 6 16:50:05 CEST 2016


---
 modules/stream_out/chromecast/chromecast.h         |   6 +
 modules/stream_out/chromecast/chromecast_common.h  |   4 +
 modules/stream_out/chromecast/chromecast_ctrl.cpp  |  33 ++++++
 modules/stream_out/chromecast/chromecast_demux.cpp | 132 +++++++++++++--------
 4 files changed, 124 insertions(+), 51 deletions(-)

diff --git a/modules/stream_out/chromecast/chromecast.h b/modules/stream_out/chromecast/chromecast.h
index 48017cc..18691f5 100644
--- a/modules/stream_out/chromecast/chromecast.h
+++ b/modules/stream_out/chromecast/chromecast.h
@@ -159,6 +159,8 @@ private:
     std::atomic_bool requested_stop;
     std::atomic_bool requested_seek;
 
+    void setInputState(input_state_e state);
+
     int sendMessage(const castchannel::CastMessage &msg);
 
     void buildMessage(const std::string & namespace_,
@@ -183,6 +185,8 @@ private:
     unsigned i_requestId;
 
     bool           has_input;
+    input_state_e  input_state;
+
     static void* ChromecastThread(void* p_data);
     vlc_interrupt_t *p_ctl_thread_interrupt;
 
@@ -241,6 +245,8 @@ private:
 
     static void request_seek(void*, mtime_t pos);
     static void wait_seek_done(void*);
+
+    static void set_input_state(void*, input_state_e state);
 };
 
 #endif /* VLC_CHROMECAST_H */
diff --git a/modules/stream_out/chromecast/chromecast_common.h b/modules/stream_out/chromecast/chromecast_common.h
index afd879b..44ef305 100644
--- a/modules/stream_out/chromecast/chromecast_common.h
+++ b/modules/stream_out/chromecast/chromecast_common.h
@@ -25,6 +25,8 @@
 #ifndef VLC_CHROMECAST_COMMON_H
 #define VLC_CHROMECAST_COMMON_H
 
+#include <vlc_input.h>
+
 # ifdef __cplusplus
 extern "C" {
 # endif
@@ -43,6 +45,8 @@ typedef struct
 
     void (*pf_request_seek)(void*, mtime_t pos);
     void (*pf_wait_seek_done)(void*);
+
+    void (*pf_set_input_state)(void*, input_state_e state);
 } chromecast_common;
 
 # ifdef __cplusplus
diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp b/modules/stream_out/chromecast/chromecast_ctrl.cpp
index e3f5b38..225dae4 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -109,6 +109,7 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int port, std::string device
  , i_receiver_requestId(0)
  , i_requestId(0)
  , has_input(false)
+ , input_state( INIT_S )
  , p_ctl_thread_interrupt(p_interrupt)
  , m_time_playback_started( VLC_TS_INVALID )
  , i_ts_local_start( VLC_TS_INVALID )
@@ -127,6 +128,7 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int port, std::string device
     common.pf_wait_app_started = wait_app_started;
     common.pf_request_seek     = request_seek;
     common.pf_wait_seek_done   = wait_seek_done;
+    common.pf_set_input_state  = set_input_state;
 
     assert( var_Type( p_module->p_parent->p_parent, CC_SHARED_VAR_NAME) == 0 );
     if (var_Create( p_module->p_parent->p_parent, CC_SHARED_VAR_NAME, VLC_VAR_ADDRESS ) == VLC_SUCCESS )
@@ -1018,6 +1020,31 @@ void intf_sys_t::requestPlayerSeek(mtime_t pos)
     notifySendRequest();
 }
 
+void intf_sys_t::setInputState(input_state_e state)
+{
+    input_state = state;
+    msg_Dbg( p_module, "new %d state", state );
+    switch( input_state )
+    {
+        case PLAYING_S:
+            if ( !mediaSessionId.empty() && receiverState != RECEIVER_IDLE )
+            {
+                msgPlayerPlay();
+                setPlayerStatus(CMD_PLAYBACK_SENT);
+            }
+            break;
+        case PAUSE_S:
+            if ( !mediaSessionId.empty() && receiverState != RECEIVER_IDLE )
+            {
+                msgPlayerPause();
+                setPlayerStatus(CMD_PLAYBACK_SENT);
+            }
+            break;
+        default:
+            break;
+    }
+}
+
 void intf_sys_t::waitAppStarted()
 {
     vlc_mutex_locker locker(&lock);
@@ -1087,3 +1114,9 @@ void intf_sys_t::wait_seek_done(void *pt)
     intf_sys_t *p_this = reinterpret_cast<intf_sys_t*>(pt);
     p_this->waitSeekDone();
 }
+
+void intf_sys_t::set_input_state(void *pt, input_state_e state)
+{
+    intf_sys_t *p_this = reinterpret_cast<intf_sys_t*>(pt);
+    p_this->setInputState( state );
+}
diff --git a/modules/stream_out/chromecast/chromecast_demux.cpp b/modules/stream_out/chromecast/chromecast_demux.cpp
index 69fe337..54f1999 100644
--- a/modules/stream_out/chromecast/chromecast_demux.cpp
+++ b/modules/stream_out/chromecast/chromecast_demux.cpp
@@ -46,10 +46,22 @@ struct demux_sys_t
         ,canSeek(false)
         ,m_seektime( VLC_TS_INVALID )
     {
+        demux_t *p_last_demux = demux->p_next;
+        while (p_last_demux->p_next)
+            p_last_demux = p_last_demux->p_next;
+        input_thread_t *p_input = p_last_demux->p_input;
+        p_renderer->pf_set_input_state( p_renderer->p_opaque,
+                                        (input_state_e) var_GetInteger( p_input, "state" ) );
+        var_AddCallback( p_input, "intf-event", InputEvent, this );
     }
 
     ~demux_sys_t()
     {
+        demux_t *p_last_demux = p_demux->p_next;
+        while (p_last_demux->p_next)
+            p_last_demux = p_last_demux->p_next;
+        input_thread_t *p_input = p_last_demux->p_input;
+        var_DelCallback( p_input, "intf-event", InputEvent, this );
     }
 
     /**
@@ -106,14 +118,14 @@ struct demux_sys_t
             msg_Dbg(p_demux, "ready to demux");
         }
 
-        /* hold the data while seeking */
-        /* wait until the device is buffering for data after the seek command */
-        if ( m_seektime != VLC_TS_INVALID )
-        {
-            p_renderer->pf_wait_seek_done( p_renderer->p_opaque );
-            m_seektime = VLC_TS_INVALID;
-        }
-
+        /* hold the data while seeking */
+        /* wait until the device is buffering for data after the seek command */
+        if ( m_seektime != VLC_TS_INVALID )
+        {
+            p_renderer->pf_wait_seek_done( p_renderer->p_opaque );
+            m_seektime = VLC_TS_INVALID;
+        }
+
         return demux_Demux( p_demux->p_next );
     }
 
@@ -125,6 +137,9 @@ protected:
     bool          canSeek;
     /* seek time kept while waiting for the chromecast to "seek" */
     mtime_t       m_seektime;
+
+    static int InputEvent( vlc_object_t *p_this, char const *psz_var,
+                           vlc_value_t oldval, vlc_value_t val, void * );
 };
 
 static int Demux( demux_t *p_demux_filter )
@@ -174,54 +189,69 @@ static int Control( demux_t *p_demux_filter, int i_query, va_list args)
         return ret;
     }
 
-    case DEMUX_SET_POSITION:
-    {
-        va_list ap;
-
-        va_copy( ap, args );
-        double pos = va_arg( ap, double );
-        va_end( ap );
-
-        if ( p_sys->getPlaybackTime() == VLC_TS_INVALID )
-        {
-            msg_Dbg( p_demux_filter, "internal seek to %f when the playback didn't start", pos );
-            break; // seek before device started, likely on-the-fly restart
-        }
-
-        if ( !p_sys->seekTo( pos ) )
-        {
-            msg_Err( p_demux_filter, "failed to seek to %f", pos );
-            return VLC_EGENERIC;
-        }
-        break;
-    }
-
-    case DEMUX_SET_TIME:
-    {
-        va_list ap;
-
-        va_copy( ap, args );
-        mtime_t pos = va_arg( ap, mtime_t );
-        va_end( ap );
-
-        if ( p_sys->getPlaybackTime() == VLC_TS_INVALID )
-        {
-            msg_Dbg( p_demux_filter, "internal seek to %" PRId64 " when the playback didn't start", pos );
-            break; // seek before device started, likely on-the-fly restart
-        }
-
-        if ( !p_sys->seekTo( pos ) )
-        {
-            msg_Err( p_demux_filter, "failed to seek to time %" PRId64, pos );
-            return VLC_EGENERIC;
-        }
-        break;
-    }
+    case DEMUX_SET_POSITION:
+    {
+        va_list ap;
+
+        va_copy( ap, args );
+        double pos = va_arg( ap, double );
+        va_end( ap );
+
+        if ( p_sys->getPlaybackTime() == VLC_TS_INVALID )
+        {
+            msg_Dbg( p_demux_filter, "internal seek to %f when the playback didn't start", pos );
+            break; // seek before device started, likely on-the-fly restart
+        }
+
+        if ( !p_sys->seekTo( pos ) )
+        {
+            msg_Err( p_demux_filter, "failed to seek to %f", pos );
+            return VLC_EGENERIC;
+        }
+        break;
+    }
+
+    case DEMUX_SET_TIME:
+    {
+        va_list ap;
+
+        va_copy( ap, args );
+        mtime_t pos = va_arg( ap, mtime_t );
+        va_end( ap );
+
+        if ( p_sys->getPlaybackTime() == VLC_TS_INVALID )
+        {
+            msg_Dbg( p_demux_filter, "internal seek to %" PRId64 " when the playback didn't start", pos );
+            break; // seek before device started, likely on-the-fly restart
+        }
+
+        if ( !p_sys->seekTo( pos ) )
+        {
+            msg_Err( p_demux_filter, "failed to seek to time %" PRId64, pos );
+            return VLC_EGENERIC;
+        }
+        break;
+    }
     }
 
     return demux_vaControl( p_demux_filter->p_next, i_query, args );
 }
 
+int demux_sys_t::InputEvent( vlc_object_t *p_this, char const *psz_var,
+                                    vlc_value_t oldval, vlc_value_t val, void *p_data )
+{
+    VLC_UNUSED(psz_var);
+    VLC_UNUSED(oldval);
+    input_thread_t *p_input = reinterpret_cast<input_thread_t*>( p_this );
+    demux_sys_t *p_sys = reinterpret_cast<demux_sys_t*>( p_data );
+
+    if( val.i_int == INPUT_EVENT_STATE )
+        p_sys->p_renderer->pf_set_input_state( p_sys->p_renderer->p_opaque,
+                                               (input_state_e) var_GetInteger( p_input, "state" ) );
+
+    return VLC_SUCCESS;
+}
+
 int Open(vlc_object_t *p_this)
 {
     demux_t *p_demux = reinterpret_cast<demux_t*>(p_this);
-- 
2.7.0



More information about the vlc-devel mailing list