[vlc-devel] commit: Reworked a bit projectm initialization. (Laurent Aimar )

git version control git at videolan.org
Sun Dec 13 13:53:40 CET 2009


vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Sat Dec 12 22:06:02 2009 +0100| [4edd5ddb746c7a8b73baa598c60159bfbe63dc43] | committer: Laurent Aimar 

Reworked a bit projectm initialization.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4edd5ddb746c7a8b73baa598c60159bfbe63dc43
---

 modules/visualization/projectm.cpp |   45 ++++++++++++++++++++++-------------
 1 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/modules/visualization/projectm.cpp b/modules/visualization/projectm.cpp
index 6d9b159..60452f1 100644
--- a/modules/visualization/projectm.cpp
+++ b/modules/visualization/projectm.cpp
@@ -74,6 +74,9 @@ typedef struct
 {
     VLC_COMMON_MEMBERS
 
+    /* */
+    vlc_sem_t ready;
+
     /* video output module and opengl provider */
     vout_thread_t *p_opengl;
     module_t      *p_module;
@@ -184,19 +187,11 @@ static int Open( vlc_object_t * p_this )
     p_sys->p_thread = p_thread = (projectm_thread_t *)
                     vlc_object_create( p_filter, sizeof( projectm_thread_t ) );
     vlc_object_attach( p_sys->p_thread, p_filter );
+    vlc_sem_init( &p_thread->ready, 0 );
+    p_thread->b_error = false;
     p_thread->i_width  = var_CreateGetInteger( p_filter, "projectm-width" );
     p_thread->i_height = var_CreateGetInteger( p_filter, "projectm-height" );
 
-    /* Create the openGL provider */
-    int i_ret = initOpenGL( p_sys->p_thread );
-    if( i_ret != VLC_SUCCESS )
-    {
-        vlc_object_detach( p_sys->p_thread );
-        vlc_object_release( p_sys->p_thread );
-        free( p_sys );
-        return i_ret;
-    }
-
     p_thread->i_channels = aout_FormatNbChannels( &p_filter->fmt_in.audio );
     p_thread->psz_config = var_CreateGetString( p_filter, "projectm-config" );
     vlc_mutex_init( &p_thread->lock );
@@ -207,15 +202,21 @@ static int Open( vlc_object_t * p_this )
     /* Create the thread */
     if( vlc_thread_create( p_thread, "projectm update thread", Thread,
                            VLC_THREAD_PRIORITY_LOW ) )
-    {
-        msg_Err( p_filter, "cannot launch the projectm thread" );
-        vlc_object_detach( p_thread );
-        vlc_object_release( p_thread );
-        free (p_sys );
-        return VLC_EGENERIC;
-    }
+        goto error;
+
+    vlc_sem_wait( &p_thread->ready );
+    if( p_thread->b_error )
+        goto error;
 
     return VLC_SUCCESS;
+
+error:
+    vlc_thread_join( p_thread );
+    vlc_sem_destroy( &p_thread->ready );
+    vlc_object_detach( p_thread );
+    vlc_object_release( p_thread );
+    free (p_sys );
+    return VLC_EGENERIC;
 }
 
 
@@ -234,6 +235,7 @@ static void Close( vlc_object_t *p_this )
     vlc_thread_join( p_thread );
 
     /* Free the ressources */
+    vlc_sem_destroy( &p_thread->ready );
     vlc_mutex_destroy( &p_thread->lock );
     free( p_thread->p_buffer );
     free( p_thread->psz_config );
@@ -282,6 +284,15 @@ static void* Thread( vlc_object_t *p_this )
     int cancel = vlc_savecancel();
     projectm_thread_t *p_thread = (projectm_thread_t *)p_this;
 
+    /* Create the openGL provider */
+    if( initOpenGL( p_thread ) )
+    {
+        p_thread->b_error = true;
+        vlc_sem_post( &p_thread->ready );
+        return NULL;
+    }
+    vlc_sem_post( &p_thread->ready );
+
     /* Initialize the opengl provider for this thread */
     p_thread->p_opengl->pf_init( p_thread->p_opengl );
 




More information about the vlc-devel mailing list