[vlc-devel] [PATCH 2/4] chromecast: Directly send request instead of using interruptions

Hugo Beauzée-Luyssen hugo at beauzee.fr
Thu Mar 2 10:46:46 CET 2017


---
 modules/stream_out/chromecast/chromecast.h        |  6 +--
 modules/stream_out/chromecast/chromecast_ctrl.cpp | 45 ++++++++---------------
 2 files changed, 16 insertions(+), 35 deletions(-)

diff --git a/modules/stream_out/chromecast/chromecast.h b/modules/stream_out/chromecast/chromecast.h
index fe63ee4072..301edb277b 100644
--- a/modules/stream_out/chromecast/chromecast.h
+++ b/modules/stream_out/chromecast/chromecast.h
@@ -131,7 +131,7 @@ private:
     vlc_tls_creds_t *m_creds;
     vlc_tls_t *m_tls;
     unsigned m_receiver_requestId;
-    unsigned m_requestId;
+    std::atomic_uint m_requestId;
     std::string m_serverIp;
 };
 
@@ -158,8 +158,6 @@ private:
 
     void processMessage(const castchannel::CastMessage &msg);
 
-    void notifySendRequest();
-
     void setPauseState(bool paused);
 
     void setTitle( const char *psz_title );
@@ -212,8 +210,6 @@ private:
 
     ChromecastCommunication m_communication;
     States m_state;
-    std::atomic_bool m_requested_stop;
-    std::atomic_bool m_requested_seek;
 
     std::string m_artwork;
     std::string m_title;
diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp b/modules/stream_out/chromecast/chromecast_ctrl.cpp
index 3434aa89a0..b76a554d17 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -82,8 +82,6 @@ intf_sys_t::intf_sys_t(vlc_object_t * const p_this, int port, std::string device
  , m_streaming_port(port)
  , m_communication( p_this, device_addr.c_str(), device_port )
  , m_state( Authenticating )
- , m_requested_stop(false)
- , m_requested_seek(false)
  , m_ctl_thread_interrupt(p_interrupt)
  , m_time_playback_started( VLC_TS_INVALID )
  , m_ts_local_start( VLC_TS_INVALID )
@@ -542,25 +540,6 @@ bool intf_sys_t::handleMessages()
     size_t i_received = 0;
     bool b_timeout = false;
 
-    if ( m_requested_stop.exchange(false) && !m_mediaSessionId.empty() )
-    {
-        m_communication.msgPlayerStop( m_appTransportId, m_mediaSessionId );
-    }
-
-    if ( m_requested_seek.exchange(false) && !m_mediaSessionId.empty() )
-    {
-        char current_time[32];
-        m_seek_request_time = mdate() + SEEK_FORWARD_OFFSET;
-        if( snprintf( current_time, sizeof(current_time), "%.3f", double( m_seek_request_time ) / 1000000.0 ) >= (int)sizeof(current_time) )
-        {
-            msg_Err( m_module, "snprintf() truncated string for mediaSessionId" );
-            current_time[sizeof(current_time) - 1] = '\0';
-        }
-        // No need to change the state to "Seeking" it was already done upon requesting
-        /* send a fake time to seek to, to make sure the device flushes its buffers */
-        m_communication.msgPlayerSeek( m_appTransportId, m_mediaSessionId, current_time );
-    }
-
     /* Packet structure:
      * +------------------------------------+------------------------------+
      * | Payload size (uint32_t big endian) |         Payload data         |
@@ -623,25 +602,31 @@ bool intf_sys_t::handleMessages()
     return true;
 }
 
-void intf_sys_t::notifySendRequest()
-{
-    vlc_interrupt_raise( m_ctl_thread_interrupt );
-}
-
 void intf_sys_t::requestPlayerStop()
 {
-    m_requested_stop = true;
-    notifySendRequest();
+    vlc_mutex_locker locker(&m_lock);
+    if ( m_mediaSessionId.empty() == true )
+        return;
+    m_communication.msgPlayerStop( m_appTransportId, m_mediaSessionId );
 }
 
 void intf_sys_t::requestPlayerSeek(mtime_t pos)
 {
     vlc_mutex_locker locker(&m_lock);
+    if ( m_mediaSessionId.empty() == true )
+        return;
     if ( pos != VLC_TS_INVALID )
         m_ts_local_start = pos;
-    m_requested_seek = true;
+    char current_time[32];
+    m_seek_request_time = mdate() + SEEK_FORWARD_OFFSET;
+    if( snprintf( current_time, sizeof(current_time), "%.3f", double( m_seek_request_time ) / 1000000.0 ) >= (int)sizeof(current_time) )
+    {
+        msg_Err( m_module, "snprintf() truncated string for mediaSessionId" );
+        current_time[sizeof(current_time) - 1] = '\0';
+    }
+    /* send a fake time to seek to, to make sure the device flushes its buffers */
+    m_communication.msgPlayerSeek( m_appTransportId, m_mediaSessionId, current_time );
     setState( Seeking );
-    notifySendRequest();
 }
 
 void intf_sys_t::setPauseState(bool paused)
-- 
2.11.0



More information about the vlc-devel mailing list