[vlc-devel] [PATCH 4/6] chromecast: stop waiting in the Chromecast connection is dead

Steve Lhomme robux4 at videolabs.io
Wed Oct 7 15:36:40 CEST 2015


and replace some lock/unlock by vlc_mutex_locker
---
 modules/stream_out/chromecast/cast.cpp | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/modules/stream_out/chromecast/cast.cpp b/modules/stream_out/chromecast/cast.cpp
index 88a9ee7..de123b1 100644
--- a/modules/stream_out/chromecast/cast.cpp
+++ b/modules/stream_out/chromecast/cast.cpp
@@ -293,18 +293,24 @@ static int Open(vlc_object_t *p_this)
     int i_ret = 0;
     const mtime_t deadline = mdate() + 6 * CLOCK_FREQ;
     vlc_mutex_lock(&p_sys->lock);
-    while (p_sys->i_status != CHROMECAST_MEDIA_LOAD_SENT)
+    while (p_sys->i_status != CHROMECAST_MEDIA_LOAD_SENT && p_sys->i_status != CHROMECAST_CONNECTION_DEAD)
     {
         i_ret = vlc_cond_timedwait(&p_sys->loadCommandCond, &p_sys->lock, deadline);
         if (i_ret == ETIMEDOUT)
         {
             msg_Err(p_stream, "Timeout reached before sending the media loading command");
-            vlc_mutex_unlock(&p_sys->lock);
-            vlc_cancel(p_sys->chromecastThread);
-            Clean(p_stream);
-            return VLC_EGENERIC;
+            break;
         }
     }
+
+    if (p_sys->i_status != CHROMECAST_MEDIA_LOAD_SENT)
+    {
+        msg_Dbg(p_stream, "Failed to get the Chromecast to load our stream");
+        vlc_mutex_unlock(&p_sys->lock);
+        vlc_cancel(p_sys->chromecastThread);
+        Clean(p_stream);
+        return VLC_EGENERIC;
+    }
     vlc_mutex_unlock(&p_sys->lock);
 
     /* Even uglier: sleep more to let to the Chromecast initiate the connection
@@ -699,6 +705,7 @@ static int processMessage(sout_stream_t *p_stream, const castchannel::CastMessag
                     msg_Warn(p_stream, "app is no longer present. closing");
                     msgClose(p_stream, p_sys->appTransportId);
                     p_sys->i_status = CHROMECAST_CONNECTION_DEAD;
+                    vlc_cond_signal(&p_sys->loadCommandCond);
                     // ft
                 default:
                     break;
@@ -731,9 +738,9 @@ static int processMessage(sout_stream_t *p_stream, const castchannel::CastMessag
         {
             msg_Err(p_stream, "Media load failed");
             msgClose(p_stream, p_sys->appTransportId);
-            vlc_mutex_lock(&p_sys->lock);
+            vlc_mutex_locker locker(&p_sys->lock);
             p_sys->i_status = CHROMECAST_CONNECTION_DEAD;
-            vlc_mutex_unlock(&p_sys->lock);
+            vlc_cond_signal(&p_sys->loadCommandCond);
         }
         else
         {
@@ -753,9 +760,9 @@ static int processMessage(sout_stream_t *p_stream, const castchannel::CastMessag
         if (type == "CLOSE")
         {
             msg_Warn(p_stream, "received close message");
-            vlc_mutex_lock(&p_sys->lock);
+            vlc_mutex_locker locker(&p_sys->lock);
             p_sys->i_status = CHROMECAST_CONNECTION_DEAD;
-            vlc_mutex_unlock(&p_sys->lock);
+            vlc_cond_signal(&p_sys->loadCommandCond);
         }
         else
         {
@@ -959,6 +966,7 @@ static void* chromecastThread(void* p_data)
             msg_Err(p_stream, "The connection to the Chromecast died.");
             vlc_mutex_locker locker(&p_sys->lock);
             p_sys->i_status = CHROMECAST_CONNECTION_DEAD;
+            vlc_cond_signal(&p_sys->loadCommandCond);
             break;
         }
 
@@ -988,6 +996,7 @@ static void* chromecastThread(void* p_data)
                 msg_Err(p_stream, "The connection to the Chromecast died.");
                 vlc_mutex_locker locker(&p_sys->lock);
                 p_sys->i_status = CHROMECAST_CONNECTION_DEAD;
+                vlc_cond_signal(&p_sys->loadCommandCond);
             }
         }
 
-- 
2.5.2



More information about the vlc-devel mailing list