[vlc-devel] [PATCH] qt: replace "qt4-iface" variable by a singleton

Thomas Guillem thomas at gllm.fr
Fri Mar 29 18:27:00 CET 2019


The Qt interface was already unique, therefore there is no need to store it in
a VLC variable.
---
 modules/gui/qt/qt.cpp | 31 ++++++++++++-------------------
 1 file changed, 12 insertions(+), 19 deletions(-)

diff --git a/modules/gui/qt/qt.cpp b/modules/gui/qt/qt.cpp
index a390d3b7ae..58ba9a77dc 100644
--- a/modules/gui/qt/qt.cpp
+++ b/modules/gui/qt/qt.cpp
@@ -353,7 +353,7 @@ vlc_module_end ()
 /* Ugly, but the Qt interface assumes single instance anyway */
 static vlc_sem_t ready;
 static QMutex lock;
-static bool busy = false;
+static intf_thread_t *intf_singleton = NULL;
 static bool active = false;
 
 /*****************************************************************************
@@ -406,7 +406,7 @@ static int Open( vlc_object_t *p_this, bool isDialogProvider )
 #endif
 
     QMutexLocker locker (&lock);
-    if (busy)
+    if (intf_singleton)
     {
         msg_Err (p_this, "cannot start Qt multiple times");
         return VLC_EGENERIC;
@@ -443,7 +443,8 @@ static int Open( vlc_object_t *p_this, bool isDialogProvider )
      * an embedded video window. */
     vlc_sem_wait (&ready);
     vlc_sem_destroy (&ready);
-    busy = active = true;
+    active = true;
+    intf_singleton = p_intf;
 
     return VLC_SUCCESS;
 }
@@ -483,8 +484,8 @@ static void Close( vlc_object_t *p_this )
     delete p_sys;
 
     QMutexLocker locker (&lock);
-    assert (busy);
-    busy = false;
+    assert (intf_singleton);
+    intf_singleton = NULL;
 }
 
 static void *Thread( void *obj )
@@ -589,14 +590,10 @@ static void *Thread( void *obj )
             known_type = false;
         }
 
-        var_Create( THEPL, "qt4-iface", VLC_VAR_ADDRESS );
         var_Create( THEPL, "window", VLC_VAR_STRING );
 
         if( known_type )
-        {
-            var_SetAddress( THEPL, "qt4-iface", p_intf );
             var_SetString( THEPL, "window", "qt,any" );
-        }
     }
 
     /* Explain how to show a dialog :D */
@@ -630,7 +627,6 @@ static void *Thread( void *obj )
     if (p_mi != NULL)
     {
         var_Destroy( THEPL, "window" );
-        var_Destroy( THEPL, "qt4-iface" );
 
         QMutexLocker locker (&lock);
         active = false;
@@ -693,13 +689,13 @@ static int WindowOpen( vout_window_t *p_wnd )
     if( !var_InheritBool( p_wnd, "embedded-video" ) )
         return VLC_EGENERIC;
 
-    intf_thread_t *p_intf =
-        (intf_thread_t *)var_InheritAddress( p_wnd, "qt4-iface" );
-    if( !p_intf )
-    {   /* If another interface is used, this plugin cannot work */
-        msg_Dbg( p_wnd, "Qt interface not found" );
+    QMutexLocker locker (&lock);
+
+    if (unlikely(!active))
         return VLC_EGENERIC;
-    }
+
+    intf_thread_t *p_intf = intf_singleton;
+    assert(p_intf);
 
     switch( p_intf->p_sys->voutWindowType )
     {
@@ -710,9 +706,6 @@ static int WindowOpen( vout_window_t *p_wnd )
             break;
     }
 
-    QMutexLocker locker (&lock);
-    if (unlikely(!active))
-        return VLC_EGENERIC;
 
     MainInterface *p_mi = p_intf->p_sys->p_mi;
 
-- 
2.20.1



More information about the vlc-devel mailing list