[vlc-commits] visual: clean up clean up code

Rémi Denis-Courmont git at videolan.org
Fri Apr 19 22:08:27 CEST 2013


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Apr 19 23:08:06 2013 +0300| [3364219c0e43ca4ec7d28971c722000e00ad70f0] | committer: Rémi Denis-Courmont

visual: clean up clean up code

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

 modules/visualization/visual/effects.c |   58 +++++++++++++++++++++++++++++---
 modules/visualization/visual/visual.c  |   31 ++++-------------
 modules/visualization/visual/visual.h  |   35 ++++++-------------
 3 files changed, 69 insertions(+), 55 deletions(-)

diff --git a/modules/visualization/visual/effects.c b/modules/visualization/visual/effects.c
index 9f76914..d1b8932 100644
--- a/modules/visualization/visual/effects.c
+++ b/modules/visualization/visual/effects.c
@@ -56,9 +56,24 @@ static int dummy_Run( visual_effect_t * p_effect, vlc_object_t *p_aout,
     return 0;
 }
 
+static void dummy_Free( void *data )
+{
+    VLC_UNUSED(data);
+}
+
+
 /*****************************************************************************
  * spectrum_Run: spectrum analyser
  *****************************************************************************/
+typedef struct spectrum_data
+{
+    int *peaks;
+    int *prev_heights;
+
+    unsigned i_prev_nb_samples;
+    int16_t *p_prev_s16_buff;
+} spectrum_data;
+
 static int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
                         const block_t * p_buffer , picture_t * p_picture)
 {
@@ -332,10 +347,31 @@ static int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
     return 0;
 }
 
+static void spectrum_Free( void *data )
+{
+    spectrum_data *p_data = data;
+
+    if( p_data != NULL )
+    {
+        free( p_data->peaks );
+        free( p_data->prev_heights );
+        free( p_data->p_prev_s16_buff );
+        free( p_data );
+    }
+}
+
 
 /*****************************************************************************
  * spectrometer_Run: derivative spectrum analysis
  *****************************************************************************/
+typedef struct
+{
+    int *peaks;
+
+    unsigned i_prev_nb_samples;
+    int16_t *p_prev_s16_buff;
+} spectrometer_data;
+
 static int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
                             const block_t * p_buffer , picture_t * p_picture)
 {
@@ -789,6 +825,18 @@ static int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
     return 0;
 }
 
+static void spectrometer_Free( void *data )
+{
+    spectrometer_data *p_data = data;
+
+    if( p_data != NULL )
+    {
+        free( p_data->peaks );
+        free( p_data->p_prev_s16_buff );
+        free( p_data );
+    }
+}
+
 
 /*****************************************************************************
  * scope_Run: scope effect
@@ -988,10 +1036,10 @@ static int vuMeter_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
 
 /* Table of effects */
 const struct visual_cb_t effectv[] = {
-    { "scope",        scope_Run },
-    { "vuMeter",      vuMeter_Run },
-    { "spectrum",     spectrum_Run },
-    { "spectrometer", spectrometer_Run },
-    { "dummy",        dummy_Run },
+    { "scope",        scope_Run,        dummy_Free        },
+    { "vuMeter",      vuMeter_Run,      dummy_Free        },
+    { "spectrum",     spectrum_Run,     spectrum_Free     },
+    { "spectrometer", spectrometer_Run, spectrometer_Free },
+    { "dummy",        dummy_Run,        dummy_Free        },
 };
 const unsigned effectc = sizeof (effectv) / sizeof (effectv[0]);
diff --git a/modules/visualization/visual/visual.c b/modules/visualization/visual/visual.c
index 5ae54f1..9c31d89 100644
--- a/modules/visualization/visual/visual.c
+++ b/modules/visualization/visual/visual.c
@@ -209,9 +209,7 @@ static int Open( vlc_object_t *p_this )
         p_effect->i_idx_right = __MIN( 1, p_effect->i_nb_chans-1 );
 
         p_effect->p_data   = NULL;
-
         p_effect->pf_run   = NULL;
-        p_effect->psz_name = NULL;
 
         for( unsigned i = 0; i < effectc; i++ )
         {
@@ -219,15 +217,14 @@ static int Open( vlc_object_t *p_this )
                               strlen( effectv[i].name ) ) )
             {
                 p_effect->pf_run = effectv[i].run_cb;
-                p_effect->psz_name = effectv[i].name;
+                p_effect->pf_free = effectv[i].free_cb;
+                psz_parser += strlen( effectv[i].name );
                 break;
             }
         }
 
-        if( p_effect->psz_name )
+        if( p_effect->pf_run != NULL )
         {
-            psz_parser += strlen( p_effect->psz_name );
-
             if( *psz_parser == '{' )
             {
                 char *psz_eoa;
@@ -355,28 +352,12 @@ static void Close( vlc_object_t *p_this )
     /* Free the list */
     for( int i = 0; i < p_sys->i_effect; i++ )
     {
-#define p_effect p_sys->effect[i]
-        if( p_effect->p_data != NULL )
-        {
-            if( !strncmp( p_effect->psz_name, "spectrum", strlen( "spectrum" ) ) )
-            {
-                spectrum_data* p_data = p_effect->p_data;
-                free( p_data->peaks );
-                free( p_data->prev_heights );
-                free( p_data->p_prev_s16_buff );
-            }
-            if( !strncmp( p_effect->psz_name, "spectrometer", strlen( "spectrometer" ) ) )
-            {
-                spectrometer_data* p_data = p_effect->p_data;
-                free( p_data->peaks );
-                free( p_data->p_prev_s16_buff );
-            }
-            free( p_effect->p_data );
-        }
+#define p_effect (p_sys->effect[i])
+        p_effect->pf_free( p_effect->p_data );
         free( p_effect );
 #undef p_effect
     }
 
     free( p_sys->effect );
-    free( p_filter->p_sys );
+    free( p_sys );
 }
diff --git a/modules/visualization/visual/visual.h b/modules/visualization/visual/visual.h
index 1d61138..a7875fc 100644
--- a/modules/visualization/visual/visual.h
+++ b/modules/visualization/visual/visual.h
@@ -21,12 +21,15 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-typedef struct visual_effect_t
-{
-    const char *psz_name;    /* Filter name*/
+typedef struct visual_effect_t visual_effect_t;
+typedef int (*visual_run_t)(visual_effect_t *, vlc_object_t *,
+                            const block_t *, picture_t *);
+typedef void (*visual_free_t)(void *);
 
-    int        (*pf_run)( struct visual_effect_t * , vlc_object_t *,
-                          const block_t *, picture_t *);
+struct visual_effect_t
+{
+    visual_run_t pf_run;
+    visual_free_t pf_free;
     void *     p_data; /* The effect stores whatever it wants here */
     int        i_width;
     int        i_height;
@@ -35,30 +38,12 @@ typedef struct visual_effect_t
     /* Channels index */
     int        i_idx_left;
     int        i_idx_right;
-} visual_effect_t ;
-
-typedef struct spectrum_data
-{
-    int *peaks;
-    int *prev_heights;
+};
 
-    unsigned i_prev_nb_samples;
-    int16_t *p_prev_s16_buff;
-} spectrum_data;
-
-typedef struct
-{
-    int *peaks;
-
-    unsigned i_prev_nb_samples;
-    int16_t *p_prev_s16_buff;
-} spectrometer_data;
-
-typedef int (*visual_run_t)(visual_effect_t *, vlc_object_t *,
-                            const block_t *, picture_t *);
 extern const struct visual_cb_t
 {
     char name[16];
     visual_run_t run_cb;
+    visual_free_t free_cb;
 } effectv[];
 extern const unsigned effectc;



More information about the vlc-commits mailing list