]> git.sesse.net Git - vlc/commitdiff
skins2: correct skins failing to display a video passed at the command line.
authorErwan Tulou <erwan10@videolan.org>
Fri, 17 Jul 2009 09:29:02 +0000 (11:29 +0200)
committerErwan Tulou <erwan10@videolan.org>
Sat, 18 Jul 2009 13:25:44 +0000 (15:25 +0200)
skins2 now does some intializations (GUI) in the Run function, and therefore needs the Open function to wait till the Run thread is ready. This patch fully copies the qt4 initialization process.

modules/gui/skins2/src/skin_common.hpp
modules/gui/skins2/src/skin_main.cpp

index 684deaf532f5ce270999e6cdb1ba21e73f9873ec..1540cf69a98729237591311f145cdd2ac8aab049 100644 (file)
@@ -140,6 +140,12 @@ struct intf_sys_t
 
     /// Current theme
     Theme *p_theme;
+
+    /// synchronisation at start of interface
+    vlc_thread_t thread;
+    vlc_mutex_t  init_lock;
+    vlc_cond_t   init_wait;
+    bool         b_ready;
 };
 
 
index d6cfd433f372866bb815276a4a92f8d19c0325b0..bbb7f32bbfdd92c54b215a5b92a204cee9d4a180 100644 (file)
@@ -65,7 +65,7 @@ extern "C" __declspec( dllexport )
 //---------------------------------------------------------------------------
 static int  Open  ( vlc_object_t * );
 static void Close ( vlc_object_t * );
-static void Run   ( intf_thread_t * );
+static void *Run  ( void * );
 
 static int DemuxOpen( vlc_object_t * );
 static int Demux( demux_t * );
@@ -99,8 +99,6 @@ static int Open( vlc_object_t *p_this )
     if( p_intf->p_sys == NULL )
         return VLC_ENOMEM;
 
-    p_intf->pf_run = Run;
-
     // Suscribe to messages bank
 #if 0
     p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
@@ -127,6 +125,27 @@ static int Open( vlc_object_t *p_this )
     // Create a variable to be notified of skins to be loaded
     var_Create( p_intf, "skin-to-load", VLC_VAR_STRING );
 
+    vlc_mutex_init( &p_intf->p_sys->init_lock );
+    vlc_cond_init( &p_intf->p_sys->init_wait );
+
+    vlc_mutex_lock( &p_intf->p_sys->init_lock );
+    p_intf->p_sys->b_ready = false;
+
+    if( vlc_clone( &p_intf->p_sys->thread, Run, p_intf,
+                               VLC_THREAD_PRIORITY_LOW ) )
+    {
+        vlc_mutex_unlock( &p_intf->p_sys->init_lock );
+        vlc_cond_destroy( &p_intf->p_sys->init_wait );
+        vlc_mutex_destroy( &p_intf->p_sys->init_lock );
+        pl_Release( p_intf->p_sys->p_playlist );
+        free( p_intf->p_sys );
+        return VLC_EGENERIC;
+    }
+
+    while( !p_intf->p_sys->b_ready )
+        vlc_cond_wait( &p_intf->p_sys->init_wait, &p_intf->p_sys->init_lock );
+    vlc_mutex_unlock( &p_intf->p_sys->init_lock );
+
     vlc_mutex_lock( &skin_load.mutex );
     skin_load.intf = p_intf;
     vlc_mutex_unlock( &skin_load.mutex );
@@ -147,6 +166,11 @@ static void Close( vlc_object_t *p_this )
     skin_load.intf = NULL;
     vlc_mutex_unlock( &skin_load.mutex);
 
+    vlc_mutex_destroy( &p_intf->p_sys->init_lock );
+    vlc_cond_destroy( &p_intf->p_sys->init_wait );
+
+    vlc_join( p_intf->p_sys->thread, NULL );
+
     if( p_intf->p_sys->p_playlist )
         pl_Release( p_this );
 
@@ -163,15 +187,19 @@ static void Close( vlc_object_t *p_this )
 //---------------------------------------------------------------------------
 // Run: main loop
 //---------------------------------------------------------------------------
-static void Run( intf_thread_t *p_intf )
+static void *Run( void * p_obj )
 {
     int canc = vlc_savecancel();
 
+    intf_thread_t *p_intf = (intf_thread_t *)p_obj;
+
     bool b_error = false;
     char *skin_last = NULL;
     ThemeLoader *pLoader = NULL;
     OSLoop *loop = NULL;
 
+    vlc_mutex_lock( &p_intf->p_sys->init_lock );
+
     // Initialize singletons
     if( OSFactory::instance( p_intf ) == NULL )
     {
@@ -270,6 +298,11 @@ static void Run( intf_thread_t *p_intf )
     // Get the instance of OSLoop
     loop = OSFactory::instance( p_intf )->getOSLoop();
 
+    // Signal the main thread this thread is now ready
+    p_intf->p_sys->b_ready = true;
+    vlc_cond_signal( &p_intf->p_sys->init_wait );
+    vlc_mutex_unlock( &p_intf->p_sys->init_lock );
+
     // Enter the main event loop
     loop->run();
 
@@ -302,7 +335,13 @@ end:
     OSFactory::destroy( p_intf );
 
     if( b_error )
+    {
+        p_intf->p_sys->b_ready = true;
+        vlc_cond_signal( &p_intf->p_sys->init_wait );
+        vlc_mutex_unlock( &p_intf->p_sys->init_lock );
+
         libvlc_Quit( p_intf->p_libvlc );
+    }
 
     vlc_restorecancel(canc);
 }