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

Juho Vähä-Herttua juhovh at iki.fi
Sun Jul 25 11:27:01 CEST 2010


On 25.7.2010, at 10.07, Rémi Denis-Courmont wrote:
> Le dimanche 25 juillet 2010 00:48:28 Juho Vähä-Herttua, vous avez écrit :
>>> That thread looks quite useless.
>> 
>> It looks quite useless, but I plan to use it to start the playlist in the
>> middle of those two sem_wait calls.
> 
> You might as well do that after vlc_sem_post() directly. That's one line of 
> code (plus two lines of ifdef).

Could you give your comments on this one? It's basically the one I sent earlier, but makes sure that the semaphore is downed to zero before thread_join on non-OSX as well, and it starts the playlist on OSX. Actually I'm already quite happy with it, now that I can start the video on Qt4 interface by just adding it on command line. It adds just 7 lines of code and moves the vlc_sem_destroy to Close instead of Open. 


Juho



From 036413a0bbe39b942d34f217827ce2aa10c41aac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juho=20V=C3=A4h=C3=A4-Herttua?= <juhovh at iki.fi>
Date: Sun, 25 Jul 2010 12:16:37 +0300
Subject: [PATCH] qt4: Run mainloop on the main thread on OSX

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

diff --git a/modules/gui/qt4/qt4.cpp b/modules/gui/qt4/qt4.cpp
index 676a82b..2e19f78 100644
--- a/modules/gui/qt4/qt4.cpp
+++ b/modules/gui/qt4/qt4.cpp
@@ -324,6 +324,14 @@ static int Open( vlc_object_t *p_this, bool isDialogProvider )
     x11_display = display;
 #endif
     vlc_sem_init (&ready, 0);
+#ifdef Q_WS_MAC
+    /* Run mainloop thread on first thread instead */
+    p_intf->b_should_run_on_first_thread = true;
+    p_intf->pf_run = (void(*)(intf_thread_t *))Thread;
+
+    /* Avoid hanging up at the sem_wait later */
+    vlc_sem_post (&ready);
+#else
     if( vlc_clone( &p_sys->thread, Thread, p_intf, VLC_THREAD_PRIORITY_LOW ) )
     {
         delete p_sys;
@@ -333,10 +341,10 @@ static int Open( vlc_object_t *p_this, bool isDialogProvider )
         vlc_mutex_unlock (&one.lock);
         return VLC_ENOMEM;
     }
+#endif

-    /* */
+    /* Wait until the interface is initialized */
     vlc_sem_wait (&ready);
-    vlc_sem_destroy (&ready);

     if( !p_sys->b_isDialogProvider )
     {
@@ -374,7 +382,14 @@ static void Close( vlc_object_t *p_this )

     QVLCApp::triggerQuit();

+    vlc_sem_wait (&ready);
+#ifdef Q_WS_MAC
+    /* One additional wait for additional sem_post */
+    vlc_sem_wait (&ready);
+#else
     vlc_join (p_sys->thread, NULL);
+#endif
+    vlc_sem_destroy (&ready);
 #ifdef Q_WS_X11
     free (x11_display);
     x11_display = NULL;
@@ -458,9 +473,14 @@ 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);

+#ifdef Q_WS_MAC
+    /* Start playlist here, because we took over main thread */
+    playlist_Play( p_intf->p_sys->p_playlist );
+#endif Q_WS_MAC
+
     /* Last settings */
     app.setQuitOnLastWindowClosed( false );

@@ -510,6 +530,9 @@ static void *Thread( void *obj )
     /* Destroy the MainInputManager */
     MainInputManager::killInstance();

+    /* Notify that the interface is cleaned up */
+    vlc_sem_post (&ready);
+
     /* Delete the application automatically */
     return NULL;
 }
--
1.6.5.7

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4215 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20100725/159e0997/attachment.bin>


More information about the vlc-devel mailing list