Commit cdb6ccc5 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont
Browse files

simple mixer: remove useless allocation and simplify

parent f1d743d5
......@@ -39,24 +39,15 @@
* 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?
*****************************************************************************/
......@@ -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 );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment