]> git.sesse.net Git - vlc/blobdiff - modules/audio_filter/normvol.c
Trailing ;
[vlc] / modules / audio_filter / normvol.c
index 47bd3a86ae0d128e6d7e1aa56b312ff0d0fa7767..d0a2e351f3a9060cdc86d6f71cfbec24935741ea 100644 (file)
  * Preamble
  *****************************************************************************/
 
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <errno.h>                                                 /* ENOMEM */
 #include <ctype.h>
 #include <signal.h>
 #include <math.h>
 
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 #include <vlc_plugin.h>
 
 #include <vlc_aout.h>
@@ -57,12 +57,12 @@ static void Close    ( vlc_object_t * );
 static void DoWork   ( aout_instance_t * , aout_filter_t *,
                 aout_buffer_t * , aout_buffer_t *);
 
-typedef struct aout_filter_sys_t
+struct aout_filter_sys_t
 {
     int i_nb;
     float *p_last;
     float f_max;
-} aout_filter_sys_t;
+};
 
 /*****************************************************************************
  * Module descriptor
@@ -79,19 +79,19 @@ typedef struct aout_filter_sys_t
                "This value is a positive floating point number. A value " \
                "between 0.5 and 10 seems sensible." )
 
-vlc_module_begin();
-    set_description( N_("Volume normalizer") );
-    set_shortname( N_("Volume normalizer") );
-    set_category( CAT_AUDIO );
-    set_subcategory( SUBCAT_AUDIO_AFILTER );
-    add_shortcut( "volnorm" );
+vlc_module_begin ()
+    set_description( N_("Volume normalizer") )
+    set_shortname( N_("Volume normalizer") )
+    set_category( CAT_AUDIO )
+    set_subcategory( SUBCAT_AUDIO_AFILTER )
+    add_shortcut( "volnorm" )
     add_integer( "norm-buff-size", 20 ,NULL ,BUFF_TEXT, BUFF_LONGTEXT,
-                 true);
+                 true )
     add_float( "norm-max-level", 2.0, NULL, LEVEL_TEXT,
-               LEVEL_LONGTEXT, true );
-    set_capability( "audio filter", 0 );
-    set_callbacks( Open, Close );
-vlc_module_end();
+               LEVEL_LONGTEXT, true )
+    set_capability( "audio filter", 0 )
+    set_callbacks( Open, Close )
+vlc_module_end ()
 
 /*****************************************************************************
  * Open: initialize and create stuff
@@ -131,16 +131,21 @@ static int Open( vlc_object_t *p_this )
     i_channels = aout_FormatNbChannels( &p_filter->input );
 
     p_sys = p_filter->p_sys = malloc( sizeof( aout_filter_sys_t ) );
+    if( !p_sys )
+        return VLC_ENOMEM;
     p_sys->i_nb = var_CreateGetInteger( p_filter->p_parent, "norm-buff-size" );
     p_sys->f_max = var_CreateGetFloat( p_filter->p_parent, "norm-max-level" );
 
     if( p_sys->f_max <= 0 ) p_sys->f_max = 0.01;
 
     /* We need to store (nb_buffers+1)*nb_channels floats */
-    p_sys->p_last = malloc( sizeof( float ) * (i_channels) *
-                            (p_filter->p_sys->i_nb + 2) );
-    memset( p_sys->p_last, 0 ,sizeof( float ) * (i_channels) *
-            (p_filter->p_sys->i_nb + 2) );
+    p_sys->p_last = calloc( i_channels * (p_filter->p_sys->i_nb + 2), sizeof(float) );
+    if( !p_sys->p_last )
+    {
+        free( p_sys );
+        return VLC_ENOMEM;
+    }
+
     return VLC_SUCCESS;
 }
 
@@ -162,10 +167,16 @@ static int Open( vlc_object_t *p_this )
 
     struct aout_filter_sys_t *p_sys = p_filter->p_sys;
 
-    pf_sum = (float *)malloc( sizeof(float) * i_channels );
-    memset( pf_sum, 0, sizeof(float) * i_channels );
+    pf_sum = calloc( i_channels, sizeof(float) );
+    if( !pf_sum )
+        return;
 
-    pf_gain = (float *)malloc( sizeof(float) * i_channels );
+    pf_gain = malloc( sizeof(float) * i_channels );
+    if( !pf_gain )
+    {
+        free( pf_sum );
+        return;
+    }
 
     p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
     p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes;