]> git.sesse.net Git - vlc/blobdiff - modules/audio_filter/channel_mixer/mono.c
Prefer mono over trivial (in case trivial somehow wants to work).
[vlc] / modules / audio_filter / channel_mixer / mono.c
index bbe6b2df61407c59fade2d47fdf97f1ce0d63327..fbea2dd5ec9ae38fc813e6eeba0b94852b042019 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <math.h>                                        /* sqrt */
 
 #ifdef HAVE_STDINT_H
 #   include <unistd.h>
 #endif
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_es.h>
 #include <vlc_block.h>
 #include <vlc_filter.h>
@@ -80,14 +81,14 @@ struct filter_sys_t
     int i_bitspersample;
 
     size_t i_overflow_buffer_size;/* in bytes */
-    byte_t * p_overflow_buffer;
+    uint8_t * p_overflow_buffer;
     unsigned int i_nb_atomic_operations;
     struct atomic_operation_t * p_atomic_operations;
 };
 
 #define MONO_DOWNMIX_TEXT N_("Use downmix algorithm")
 #define MONO_DOWNMIX_LONGTEXT N_("This option selects a stereo to mono " \
-    "downmix algorithm that is used in the headphone channel mixer. It" \
+    "downmix algorithm that is used in the headphone channel mixer. It " \
     "gives the effect of standing in a room full of speakers." )
 
 #define MONO_CHANNEL_TEXT N_("Select channel to keep")
@@ -96,7 +97,7 @@ struct filter_sys_t
     "2=rear left, 3=rear right, 4=center, 5=left front)")
 
 static const int pi_pos_values[] = { 0, 1, 2, 4, 8, 5 };
-static const char *ppsz_pos_descriptions[] =
+static const char *const ppsz_pos_descriptions[] =
 { N_("Left"), N_("Right"), N_("Left rear"), N_("Right rear"), N_("Center"),
   N_("Left front") };
 
@@ -110,10 +111,10 @@ static const uint32_t pi_channels_out[] =
  * Module descriptor
  *****************************************************************************/
 vlc_module_begin();
-    set_description( _("Audio filter for stereo to mono conversion") );
-    set_capability( "audio filter2", 0 );
+    set_description( N_("Audio filter for stereo to mono conversion") );
+    set_capability( "audio filter2", 2 );
 
-    add_bool( MONO_CFG "downmix", false, NULL, MONO_DOWNMIX_TEXT,
+    add_bool( MONO_CFG "downmix", true, NULL, MONO_DOWNMIX_TEXT,
               MONO_DOWNMIX_LONGTEXT, false );
     add_integer( MONO_CFG "channel", -1, NULL, MONO_CHANNEL_TEXT,
         MONO_CHANNEL_LONGTEXT, false );
@@ -218,12 +219,6 @@ static int Init( vlc_object_t *p_this, struct filter_sys_t * p_data,
     int i_source_channel_offset;
     unsigned int i;
 
-    if( p_data == NULL )
-    {
-        msg_Dbg( p_this, "passing a null pointer as argument" );
-        return 0;
-    }
-
     if( config_GetInt( p_this, "headphone-compensate" ) )
     {
         /* minimal distance to any speaker */
@@ -246,10 +241,7 @@ static int Init( vlc_object_t *p_this, struct filter_sys_t * p_data,
     p_data->p_atomic_operations = malloc( sizeof(struct atomic_operation_t)
             * p_data->i_nb_atomic_operations );
     if( p_data->p_atomic_operations == NULL )
-    {
-        msg_Err( p_this, "out of memory" );
         return -1;
-    }
 
     /* For each virtual speaker, computes elementary wave propagation time
      * to each ear */
@@ -346,9 +338,9 @@ static int Init( vlc_object_t *p_this, struct filter_sys_t * p_data,
         }
     }
     p_data->p_overflow_buffer = malloc( p_data->i_overflow_buffer_size );
-    if( p_data->p_atomic_operations == NULL )
+    if( p_data->p_overflow_buffer == NULL )
     {
-        msg_Err( p_this, "out of memory" );
+        free( p_data->p_atomic_operations );
         return -1;
     }
     memset( p_data->p_overflow_buffer, 0, p_data->i_overflow_buffer_size );
@@ -392,10 +384,7 @@ static int OpenFilter( vlc_object_t *p_this )
     /* Allocate the memory needed to store the module's structure */
     p_sys = p_filter->p_sys = malloc( sizeof(filter_sys_t) );
     if( p_sys == NULL )
-    {
-        msg_Err( p_filter, "out of memory" );
         return VLC_EGENERIC;
-    }
 
     var_Create( p_this, MONO_CFG "downmix",
                 VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
@@ -436,6 +425,9 @@ static int OpenFilter( vlc_object_t *p_this )
               p_filter->fmt_in.audio.i_physical_channels,
               p_filter->fmt_in.audio.i_rate ) < 0 )
     {
+        var_Destroy( p_this, MONO_CFG "channel" );
+        var_Destroy( p_this, MONO_CFG "downmix" );
+        free( p_sys );
         return VLC_EGENERIC;
     }
 
@@ -462,6 +454,8 @@ static void CloseFilter( vlc_object_t *p_this)
 
     var_Destroy( p_this, MONO_CFG "channel" );
     var_Destroy( p_this, MONO_CFG "downmix" );
+    free( p_sys->p_atomic_operations );
+    free( p_sys->p_overflow_buffer );
     free( p_sys );
 }
 
@@ -479,7 +473,7 @@ static block_t *Convert( filter_t *p_filter, block_t *p_block )
     if( !p_block || !p_block->i_samples )
     {
         if( p_block )
-            p_block->pf_release( p_block );
+            block_Release( p_block );
         return NULL;
     }
 
@@ -490,7 +484,7 @@ static block_t *Convert( filter_t *p_filter, block_t *p_block )
     if( !p_out )
     {
         msg_Warn( p_filter, "can't get output buffer" );
-        p_block->pf_release( p_block );
+        block_Release( p_block );
         return NULL;
     }
     p_out->i_samples = (p_block->i_samples / p_filter->p_sys->i_nb_channels) *
@@ -537,7 +531,7 @@ static block_t *Convert( filter_t *p_filter, block_t *p_block )
     p_out->i_buffer = out_buf.i_nb_bytes;
     p_out->i_samples = out_buf.i_nb_samples;
 
-    p_block->pf_release( p_block );
+    block_Release( p_block );
     return p_out;
 }
 
@@ -555,9 +549,9 @@ static void stereo2mono_downmix( aout_filter_t * p_filter,
     int i_output_nb = aout_FormatNbChannels( &p_filter->output );
 
     int16_t * p_in = (int16_t*) p_in_buf->p_buffer;
-    byte_t * p_out;
-    byte_t * p_overflow;
-    byte_t * p_slide;
+    uint8_t * p_out;
+    uint8_t * p_overflow;
+    uint8_t * p_slide;
 
     size_t i_overflow_size;     /* in bytes */
     size_t i_out_size;          /* in bytes */