]> git.sesse.net Git - vlc/blobdiff - modules/audio_filter/equalizer.c
Don't use var_CreateGet oly to Create the variable.
[vlc] / modules / audio_filter / equalizer.c
index 3d2df4af74a85cea7241b880bfa0e63ac6ab0145..ae70807a02cde676466a88146af31c9189f0cdef 100644 (file)
@@ -69,12 +69,12 @@ static void Close( vlc_object_t * );
 #define PREAMP_TEXT N_("Global gain" )
 #define PREAMP_LONGTEXT N_("Set the global gain in dB (-20 ... 20)." )
 
-vlc_module_begin();
-    set_description( N_("Equalizer with 10 bands") );
-    set_shortname( N_("Equalizer" ) );
-    set_capability( "audio filter", 0 );
-    set_category( CAT_AUDIO );
-    set_subcategory( SUBCAT_AUDIO_AFILTER );
+vlc_module_begin ()
+    set_description( N_("Equalizer with 10 bands") )
+    set_shortname( N_("Equalizer" ) )
+    set_capability( "audio filter", 0 )
+    set_category( CAT_AUDIO )
+    set_subcategory( SUBCAT_AUDIO_AFILTER )
 
     add_string( "equalizer-preset", "flat", NULL, PRESET_TEXT,
                 PRESET_LONGTEXT, false );
@@ -85,9 +85,9 @@ vlc_module_begin();
               TWOPASS_LONGTEXT, true );
     add_float( "equalizer-preamp", 12.0, NULL, PREAMP_TEXT,
                PREAMP_LONGTEXT, true );
-    set_callbacks( Open, Close );
-    add_shortcut( "equalizer" );
-vlc_module_end();
+    set_callbacks( Open, Close )
+    add_shortcut( "equalizer" )
+vlc_module_end ()
 
 /*****************************************************************************
  * Local prototypes
@@ -172,9 +172,14 @@ static int Open( vlc_object_t *p_this )
 
     /* Allocate structure */
     p_sys = p_filter->p_sys = malloc( sizeof( aout_filter_sys_t ) );
+    if( !p_sys )
+        return VLC_ENOMEM;
 
-    if( EqzInit( p_filter, p_filter->input.i_rate ) )
+    if( EqzInit( p_filter, p_filter->input.i_rate ) != VLC_SUCCESS )
+    {
+        free( p_sys );
         return VLC_EGENERIC;
+    }
 
     return VLC_SUCCESS;
 }
@@ -305,6 +310,14 @@ static int EqzInit( aout_filter_t *p_filter, int i_rate )
     p_sys->f_alpha = malloc( p_sys->i_band * sizeof(float) );
     p_sys->f_beta  = malloc( p_sys->i_band * sizeof(float) );
     p_sys->f_gamma = malloc( p_sys->i_band * sizeof(float) );
+    if( !p_sys->f_alpha || !p_sys->f_beta || !p_sys->f_gamma )
+    {
+        free( p_sys->f_alpha );
+        free( p_sys->f_beta );
+        free( p_sys->f_gamma );
+        return VLC_ENOMEM;
+    }
+
     for( i = 0; i < p_sys->i_band; i++ )
     {
         p_sys->f_alpha[i] = p_cfg->band[i].f_alpha;
@@ -315,7 +328,14 @@ static int EqzInit( aout_filter_t *p_filter, int i_rate )
     /* Filter dyn config */
     p_sys->b_2eqz = false;
     p_sys->f_gamp = 1.0;
-    p_sys->f_amp   = malloc( p_sys->i_band * sizeof(float) );
+    p_sys->f_amp  = malloc( p_sys->i_band * sizeof(float) );
+    if( !p_sys->f_amp )
+    {
+        free( p_sys->f_alpha );
+        free( p_sys->f_beta );
+        free( p_sys->f_gamma );
+        return VLC_ENOMEM;
+    }
     for( i = 0; i < p_sys->i_band; i++ )
     {
         p_sys->f_amp[i] = 0.0;
@@ -338,12 +358,12 @@ static int EqzInit( aout_filter_t *p_filter, int i_rate )
         }
     }
 
-    var_CreateGetString( p_aout,"equalizer-bands" );
-    var_CreateGetString( p_aout, "equalizer-preset" );
+    var_Create( p_aout, "equalizer-bands", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
+    var_Create( p_aout, "equalizer-preset", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
 
     p_sys->b_2eqz = var_CreateGetBool( p_aout, "equalizer-2pass" );
 
-    var_CreateGetFloat( p_aout, "equalizer-preamp" );
+    var_Create( p_aout, "equalizer-preamp", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
 
     /* Get initial values */
     var_Get( p_aout, "equalizer-preset", &val1 );
@@ -356,13 +376,20 @@ static int EqzInit( aout_filter_t *p_filter, int i_rate )
     PreampCallback( VLC_OBJECT( p_aout ), NULL, val3, val3, p_sys );
     p_sys->b_first = false;
 
+    free( val1.psz_string );
+
     /* Register preset bands (for intf) if : */
     /* We have no bands info --> the preset info must be given to the intf */
     /* or The bands info matches the preset */
     if (p_sys->psz_newbands == NULL)
     {
         msg_Err(p_filter, "No preset selected");
-        return (VLC_EGENERIC);
+        free( val2.psz_string );
+        free( p_sys->f_amp );
+        free( p_sys->f_alpha );
+        free( p_sys->f_beta );
+        free( p_sys->f_gamma );
+        return VLC_EGENERIC;
     }
     if( ( *(val2.psz_string) &&
         strstr( p_sys->psz_newbands, val2.psz_string ) ) || !*val2.psz_string )
@@ -371,6 +398,7 @@ static int EqzInit( aout_filter_t *p_filter, int i_rate )
         if( p_sys->f_newpreamp == p_sys->f_gamp )
             var_SetFloat( p_aout, "equalizer-preamp", p_sys->f_newpreamp );
     }
+    free( val2.psz_string );
 
     /* Add our own callbacks */
     var_AddCallback( p_aout, "equalizer-preset", PresetCallback, p_sys );
@@ -465,6 +493,7 @@ static void EqzClean( aout_filter_t *p_filter )
     free( p_sys->f_gamma );
 
     free( p_sys->f_amp );
+    free( p_sys->psz_newbands );
 }