]> git.sesse.net Git - vlc/blobdiff - modules/visualization/projectm.cpp
Reworked a bit projectm initialization.
[vlc] / modules / visualization / projectm.cpp
index 29afdbe8625aa9e18ddf08f1b405e1714a993d54..60452f1c0f5490f393f9dd367473d3ed396a8cc5 100644 (file)
@@ -29,6 +29,7 @@
 #include <vlc_plugin.h>
 #include <vlc_aout.h>
 #include <vlc_vout.h>
+#include <vlc_filter.h>
 
 #include <libprojectM/projectM.hpp>
 
@@ -52,7 +53,7 @@ static void Close        ( vlc_object_t * );
 vlc_module_begin ()
     set_shortname( N_("projectM"))
     set_description( N_("libprojectM effect") )
-    set_capability( "visualization", 0 )
+    set_capability( "visualization2", 0 )
     set_category( CAT_AUDIO )
     set_subcategory( SUBCAT_AUDIO_VISUAL )
     add_file( "projectm-config", "/usr/share/projectM/config.inp", NULL,
@@ -73,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;
@@ -95,14 +99,13 @@ typedef struct
 } projectm_thread_t;
 
 
-struct aout_filter_sys_t
+struct filter_sys_t
 {
     projectm_thread_t *p_thread;
 };
 
 
-static void DoWork( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
-                    aout_buffer_t * );
+static block_t *DoWork( filter_t *, block_t * );
 static void* Thread( vlc_object_t * );
 
 
@@ -129,6 +132,7 @@ static int initOpenGL( projectm_thread_t *p_thread )
     p_thread->p_opengl->render.i_height = p_thread->i_height;
     p_thread->p_opengl->render.i_aspect = VOUT_ASPECT_FACTOR;
     p_thread->p_opengl->b_fullscreen = false;
+    p_thread->p_opengl->b_autoscale = true;
     p_thread->p_opengl->i_alignment = 0;
     p_thread->p_opengl->fmt_in.i_sar_num = 1;
     p_thread->p_opengl->fmt_in.i_sar_den = 1;
@@ -156,27 +160,26 @@ static int initOpenGL( projectm_thread_t *p_thread )
  */
 static int Open( vlc_object_t * p_this )
 {
-    aout_filter_t       *p_filter = (aout_filter_t *)p_this;
-    aout_filter_sys_t   *p_sys;
+    filter_t            *p_filter = (filter_t *)p_this;
+    filter_sys_t        *p_sys;
     projectm_thread_t   *p_thread;
 
     /* Test the audio format */
-    if( p_filter->input.i_format != VLC_CODEC_FL32 ||
-        p_filter->output.i_format != VLC_CODEC_FL32 )
+    if( p_filter->fmt_in.audio.i_format != VLC_CODEC_FL32 ||
+        p_filter->fmt_out.audio.i_format != VLC_CODEC_FL32 )
     {
         msg_Warn( p_filter, "bad input or output format" );
         return VLC_EGENERIC;
     }
-    if( !AOUT_FMTS_SIMILAR( &p_filter->input, &p_filter->output ) )
+    if( !AOUT_FMTS_SIMILAR( &p_filter->fmt_in.audio, &p_filter->fmt_out.audio ) )
     {
         msg_Warn( p_filter, "input and outut are not similar" );
         return VLC_EGENERIC;
     }
 
-    p_filter->pf_do_work = DoWork;
-    p_filter->b_in_place = true;
+    p_filter->pf_audio_filter = DoWork;
 
-    p_sys = p_filter->p_sys = (aout_filter_sys_t*)malloc( sizeof( *p_sys ) );
+    p_sys = p_filter->p_sys = (filter_sys_t*)malloc( sizeof( *p_sys ) );
     if( !p_sys )
         return VLC_ENOMEM;
 
@@ -184,20 +187,12 @@ 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->input );
+    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 );
     p_thread->p_buffer = NULL;
@@ -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;
 }
 
 
@@ -225,8 +226,8 @@ static int Open( vlc_object_t * p_this )
  */
 static void Close( vlc_object_t *p_this )
 {
-    aout_filter_t     *p_filter = (aout_filter_t *)p_this;
-    aout_filter_sys_t *p_sys = p_filter->p_sys;
+    filter_t     *p_filter = (filter_t *)p_this;
+    filter_sys_t *p_sys = p_filter->p_sys;
     projectm_thread_t *p_thread = p_sys->p_thread;
 
     /* Stop the thread */
@@ -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 );
@@ -252,14 +254,10 @@ static void Close( vlc_object_t *p_this )
  * @param p_in_buf: input buffer
  * @param p_out_buf: output buffer
  */
-static void DoWork( aout_instance_t *p_aout, aout_filter_t *p_filter,
-                    aout_buffer_t *p_in_buf, aout_buffer_t *p_out_buf )
+static block_t *DoWork( filter_t *p_filter, block_t *p_in_buf )
 {
     projectm_thread_t *p_thread = p_filter->p_sys->p_thread;
 
-    p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
-    p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes;
-
     vlc_mutex_lock( &p_thread->lock );
     if( p_thread->i_buffer_size > 0 )
     {
@@ -272,7 +270,7 @@ static void DoWork( aout_instance_t *p_aout, aout_filter_t *p_filter,
 
     vlc_mutex_unlock( &p_thread->lock );
 
-    return;
+    return p_in_buf;
 }
 
 
@@ -286,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 );
 
@@ -304,6 +311,8 @@ static void* Thread( vlc_object_t *p_this )
 
     while( vlc_object_alive( p_thread ) )
     {
+        /* Manage the events */
+        p_thread->p_opengl->pf_manage( p_thread->p_opengl );
         /* Render the image and swap the buffers */
         vlc_mutex_lock( &p_thread->lock );
         if( p_thread->i_nb_samples > 0 )
@@ -315,7 +324,7 @@ static void* Thread( vlc_object_t *p_this )
         vlc_mutex_unlock( &p_thread->lock );
 
         /* TODO: use a fps limiter */
-        msleep( 1000 );
+        msleep( 10000 );
     }