[vlc-devel] [PATCH 09/16] chromecast: simplify the message sending loop

Steve Lhomme robux4 at videolabs.io
Thu Apr 28 14:18:42 CEST 2016


--
it's all in the class now
---
 modules/stream_out/chromecast/chromecast.h        |  2 +-
 modules/stream_out/chromecast/chromecast_ctrl.cpp | 17 +++++------------
 2 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/modules/stream_out/chromecast/chromecast.h b/modules/stream_out/chromecast/chromecast.h
index 833339c..a76cc56 100644
--- a/modules/stream_out/chromecast/chromecast.h
+++ b/modules/stream_out/chromecast/chromecast.h
@@ -106,7 +106,7 @@ private:
     void msgAuth();
     void msgReceiverClose(std::string destinationId);
 
-    void handleMessages();
+    bool handleMessages();
 
     connection_status getConnectionStatus() const
     {
diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp b/modules/stream_out/chromecast/chromecast_ctrl.cpp
index c9ac020..de0e6d1 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -846,19 +846,12 @@ void* intf_sys_t::ChromecastThread(void* p_data)
     p_sys->msgAuth();
     vlc_restorecancel(canc);
 
-    while (1)
-    {
-        p_sys->handleMessages();
-
-        vlc_mutex_locker locker(&p_sys->lock);
-        if ( p_sys->getConnectionStatus() == CHROMECAST_CONNECTION_DEAD )
-            break;
-    }
+    while ( p_sys->handleMessages() );
 
     return NULL;
 }
 
-void intf_sys_t::handleMessages()
+bool intf_sys_t::handleMessages()
 {
     unsigned i_received = 0;
     uint8_t p_packet[PACKET_MAX_LEN];
@@ -885,8 +878,6 @@ void intf_sys_t::handleMessages()
         msg_Err( p_module, "The connection to the Chromecast died (receiving).");
         vlc_mutex_locker locker(&lock);
         setConnectionStatus(CHROMECAST_CONNECTION_DEAD);
-        vlc_restorecancel(canc);
-        return;
     }
 
     if (b_pingTimeout)
@@ -901,6 +892,8 @@ void intf_sys_t::handleMessages()
         msg.ParseFromArray(p_packet + PACKET_HEADER_LEN, i_payloadSize);
         processMessage(msg);
     }
-
     vlc_restorecancel(canc);
+
+    vlc_mutex_locker locker(&lock);
+    return conn_status != CHROMECAST_CONNECTION_DEAD;
 }
-- 
2.7.0



More information about the vlc-devel mailing list