[vlc-commits] simple mixer: remove useless allocation and simplify
Rémi Denis-Courmont
git at videolan.org
Sun Sep 7 13:12:42 CEST 2014
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Sep 7 13:33:45 2014 +0300| [cdb6ccc5ace7db495b1c8e315d6886342adc6dc8] | committer: Rémi Denis-Courmont
simple mixer: remove useless allocation and simplify
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=cdb6ccc5ace7db495b1c8e315d6886342adc6dc8
---
modules/audio_filter/channel_mixer/simple.c | 61 +++++++++------------------
1 file changed, 21 insertions(+), 40 deletions(-)
diff --git a/modules/audio_filter/channel_mixer/simple.c b/modules/audio_filter/channel_mixer/simple.c
index ad3b350..a2f64ca 100644
--- a/modules/audio_filter/channel_mixer/simple.c
+++ b/modules/audio_filter/channel_mixer/simple.c
@@ -39,25 +39,16 @@
* Module descriptor
*****************************************************************************/
static int OpenFilter( vlc_object_t * );
-static void CloseFilter( vlc_object_t * );
vlc_module_begin ()
set_description( N_("Audio filter for simple channel mixing") )
set_category( CAT_AUDIO )
set_subcategory( SUBCAT_AUDIO_MISC )
set_capability( "audio converter", 10 )
- set_callbacks( OpenFilter, CloseFilter );
+ set_callbacks( OpenFilter, NULL );
vlc_module_end ()
/*****************************************************************************
- * Local prototypes
- *****************************************************************************/
-struct filter_sys_t
-{
- void (*pf_dowork)(filter_t *, block_t *, block_t * );
-};
-
-/*****************************************************************************
* IsSupported: can we downmix?
*****************************************************************************/
static bool IsSupported( const audio_format_t *p_input, const audio_format_t *p_output )
@@ -327,7 +318,7 @@ static void DoWork_6_1_to_5_x( filter_t * p_filter, block_t * p_in_buf, block_t
static int OpenFilter( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t *)p_this;
- filter_sys_t *p_sys;
+ void (*do_work)(filter_t *, block_t *, block_t *) = NULL;
audio_format_t fmt_in = p_filter->fmt_in.audio;
audio_format_t fmt_out = p_filter->fmt_out.audio;
@@ -335,12 +326,6 @@ static int OpenFilter( vlc_object_t *p_this )
if( !IsSupported( &fmt_in, &fmt_out ) )
return VLC_EGENERIC;
- p_filter->p_sys = malloc( sizeof(*p_sys) );
- if( unlikely(!p_filter->p_sys) )
- return VLC_ENOMEM;
-
- p_filter->pf_audio_filter = Filter;
-
const unsigned i_input_physical = p_filter->fmt_in.audio.i_physical_channels;
const bool b_input_7_0 = (i_input_physical & ~AOUT_CHAN_LFE) == AOUT_CHANS_7_0;
const bool b_input_6_1 = !b_input_7_0 &&
@@ -356,61 +341,57 @@ static int OpenFilter( vlc_object_t *p_this )
if( p_filter->fmt_out.audio.i_physical_channels == AOUT_CHANS_2_0 )
{
if( b_input_7_0 )
- p_filter->p_sys->pf_dowork = DoWork_7_x_to_2_0;
+ do_work = DoWork_7_x_to_2_0;
else if( b_input_6_1 )
- p_filter->p_sys->pf_dowork = DoWork_6_1_to_2_0;
+ do_work = DoWork_6_1_to_2_0;
else if( b_input_5_0 )
- p_filter->p_sys->pf_dowork = DoWork_5_x_to_2_0;
+ do_work = DoWork_5_x_to_2_0;
else if( b_input_4_center_rear )
- p_filter->p_sys->pf_dowork = DoWork_4_0_to_2_0;
+ do_work = DoWork_4_0_to_2_0;
else if( b_input_3_0 )
- p_filter->p_sys->pf_dowork = DoWork_3_x_to_2_0;
+ do_work = DoWork_3_x_to_2_0;
}
else if( p_filter->fmt_out.audio.i_physical_channels == AOUT_CHAN_CENTER )
{
if( b_input_7_0 )
- p_filter->p_sys->pf_dowork = DoWork_7_x_to_1_0;
+ do_work = DoWork_7_x_to_1_0;
else if( b_input_5_0 )
- p_filter->p_sys->pf_dowork = DoWork_5_x_to_1_0;
+ do_work = DoWork_5_x_to_1_0;
else if( b_input_4_center_rear )
- p_filter->p_sys->pf_dowork = DoWork_4_0_to_1_0;
+ do_work = DoWork_4_0_to_1_0;
else if( b_input_3_0 )
- p_filter->p_sys->pf_dowork = DoWork_3_x_to_1_0;
+ do_work = DoWork_3_x_to_1_0;
else
- p_filter->p_sys->pf_dowork = DoWork_2_x_to_1_0;
+ do_work = DoWork_2_x_to_1_0;
}
else if(p_filter->fmt_out.audio.i_physical_channels == AOUT_CHANS_4_0)
{
if( b_input_7_0 )
- p_filter->p_sys->pf_dowork = DoWork_7_x_to_4_0;
+ do_work = DoWork_7_x_to_4_0;
else
- p_filter->p_sys->pf_dowork = DoWork_5_x_to_4_0;
+ do_work = DoWork_5_x_to_4_0;
}
else
{
assert( b_input_7_0 || b_input_6_1 );
if( b_input_7_0 )
- p_filter->p_sys->pf_dowork = DoWork_7_x_to_5_x;
+ do_work = DoWork_7_x_to_5_x;
else
- p_filter->p_sys->pf_dowork = DoWork_6_1_to_5_x;
+ do_work = DoWork_6_1_to_5_x;
}
+ p_filter->pf_audio_filter = Filter;
+ p_filter->p_sys = (void *)do_work;
return VLC_SUCCESS;
}
-static void CloseFilter( vlc_object_t *p_this )
-{
- filter_t *p_filter = (filter_t *) p_this;
- filter_sys_t *p_sys = p_filter->p_sys;
- free( p_sys );
-}
-
/*****************************************************************************
* Filter:
*****************************************************************************/
static block_t *Filter( filter_t *p_filter, block_t *p_block )
{
- filter_sys_t *p_sys = (filter_sys_t *)p_filter->p_sys;
+ void (*work)(filter_t *, block_t *, block_t *) = (void *)p_filter->p_sys;
+
if( !p_block || !p_block->i_nb_samples )
{
if( p_block )
@@ -440,7 +421,7 @@ static block_t *Filter( filter_t *p_filter, block_t *p_block )
p_out->i_nb_samples = p_block->i_nb_samples;
p_out->i_buffer = p_block->i_buffer * i_output_nb / i_input_nb;
- p_sys->pf_dowork( p_filter, p_block, p_out );
+ work( p_filter, p_block, p_out );
block_Release( p_block );
More information about the vlc-commits
mailing list