[vlc-devel] [PATCH 5/6] qt4: Run mainloop on the main thread on OSX

Juho Vähä-Herttua juhovh at iki.fi
Sat Jul 24 22:31:13 CEST 2010


---
 modules/gui/qt4/qt4.cpp |   38 +++++++++++++++++++++++++++++++++++---
 1 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/modules/gui/qt4/qt4.cpp b/modules/gui/qt4/qt4.cpp
index 05ef8b8..68b16f9 100644
--- a/modules/gui/qt4/qt4.cpp
+++ b/modules/gui/qt4/qt4.cpp
@@ -62,6 +62,7 @@ static void Close        ( vlc_object_t * );
 static int  WindowOpen   ( vlc_object_t * );
 static void WindowClose  ( vlc_object_t * );
 static void *Thread      ( void * );
+static void *Monitor     ( void * );
 static void Cleanup      ( void * );
 static void ShowDialog   ( intf_thread_t *, int, int, intf_dialog_args_t * );
 
@@ -324,8 +325,16 @@ static int Open( vlc_object_t *p_this, bool isDialogProvider )
 #ifdef Q_WS_X11
     x11_display = display;
 #endif
+
     vlc_sem_init (&ready, 0);
+#ifdef Q_WS_MAC
+    /* Start the monitor thread for the first thread */
+    p_intf->b_should_run_on_first_thread = true;
+    p_intf->pf_run = (void(*)(intf_thread_t *))Thread;
+    if( vlc_clone( &p_sys->thread, Monitor, p_intf, VLC_THREAD_PRIORITY_LOW ) )
+#else
     if( vlc_clone( &p_sys->thread, Thread, p_intf, VLC_THREAD_PRIORITY_LOW ) )
+#endif
     {
         delete p_sys;
         free (display);
@@ -335,9 +344,14 @@ static int Open( vlc_object_t *p_this, bool isDialogProvider )
         return VLC_ENOMEM;
     }
 
-    /* */
+#ifndef Q_WS_MAC
+    /* Wait until the interface is initialized, This is to avoid a race
+     * condition where playlist is started before the interface is initialized
+     * and therefore first video is not run in the embedded window. On Mac the
+     * interface is run on main thread so this problem doesn't exist, playlist
+     * needs to be started explicitly for Mac OS X. */
     vlc_sem_wait (&ready);
-    vlc_sem_destroy (&ready);
+#endif
 
     if( !p_sys->b_isDialogProvider )
     {
@@ -376,6 +390,7 @@ static void Close( vlc_object_t *p_this )
     QVLCApp::triggerQuit();
 
     vlc_join (p_sys->thread, NULL);
+    vlc_sem_destroy (&ready);
 #ifdef Q_WS_X11
     free (x11_display);
     x11_display = NULL;
@@ -460,7 +475,7 @@ static void *Thread( void *obj )
     /* Explain how to show a dialog :D */
     p_intf->pf_show_dialog = ShowDialog;
 
-    /* */
+    /* Notify that the interface is initialized */
     vlc_sem_post (&ready);
 
     /* Last settings */
@@ -478,6 +493,9 @@ static void *Thread( void *obj )
     /* Launch */
     app.exec();
 
+    /* Notify that the interface is cleaned up */
+    vlc_sem_post (&ready);
+
     /* Delete the application automatically */
     return NULL;
 }
@@ -524,6 +542,20 @@ static void Cleanup( void *obj )
     MainInputManager::killInstance();
 }
 
+static void *Monitor( void *obj )
+{
+    intf_thread_t *p_intf = (intf_thread_t *)obj;
+
+    /* Wait for interface to initialize */
+    vlc_sem_wait (&ready);
+
+    /* Wait for interface to cleanup */
+    vlc_sem_wait (&ready);
+
+    msg_Dbg( p_intf, "Monitor thread finished" );
+    return NULL;
+}
+
 /*****************************************************************************
  * Callback to show a dialog
  *****************************************************************************/
-- 
1.6.5.7




More information about the vlc-devel mailing list