[vlc-devel] [PATCH 24/33] chromecast: only lock once when checking the current app

Steve Lhomme robux4 at videolabs.io
Wed Dec 23 12:58:43 CET 2015


---
 modules/stream_out/chromecast/chromecast_ctrl.cpp | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/modules/stream_out/chromecast/chromecast_ctrl.cpp b/modules/stream_out/chromecast/chromecast_ctrl.cpp
index 62a94e3..592ff56 100644
--- a/modules/stream_out/chromecast/chromecast_ctrl.cpp
+++ b/modules/stream_out/chromecast/chromecast_ctrl.cpp
@@ -273,21 +273,23 @@ void intf_sys_t::processMessage(const castchannel::CastMessage &msg)
         {
             json_value applications = (*p_data)["status"]["applications"];
             const json_value *p_app = NULL;
+
+            vlc_mutex_locker locker(&lock);
             for (unsigned i = 0; i < applications.u.array.length; ++i)
             {
                 std::string appId(applications[i]["appId"]);
                 if (appId == APP_ID)
                 {
-                    p_app = &applications[i];
-                    vlc_mutex_lock(&lock);
-                    if (appTransportId.empty())
-                        appTransportId = std::string(applications[i]["transportId"]);
-                    vlc_mutex_unlock(&lock);
+                    const char *pz_transportId = applications[i]["transportId"];
+                    if (pz_transportId != NULL)
+                    {
+                        appTransportId = std::string(pz_transportId);
+                        p_app = &applications[i];
+                    }
                     break;
                 }
             }
 
-            vlc_mutex_lock(&lock);
             if ( p_app )
             {
                 if (!appTransportId.empty()
@@ -316,7 +318,6 @@ void intf_sys_t::processMessage(const castchannel::CastMessage &msg)
                 }
 
             }
-            vlc_mutex_unlock(&lock);
         }
         else
         {
-- 
2.6.3



More information about the vlc-devel mailing list