Commit 79bf979e authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

aout: reduce filter table for resamplers and converters

There should never be a need for more than 5 of them. Only the
filters proper might require more than 5 members in a chain.
parent f8d33b35
......@@ -28,9 +28,6 @@
* This file defines functions, structures and macros for audio output object
*/
/* Max number of pre-filters per input, and max number of post-filters */
#define AOUT_MAX_FILTERS 10
/* Buffers which arrive in advance of more than AOUT_MAX_ADVANCE_TIME
* will be considered as bogus and be trashed */
#define AOUT_MAX_ADVANCE_TIME (AOUT_MAX_PREPARE_TIME + CLOCK_FREQ)
......
......@@ -29,6 +29,8 @@
/* Max input rate factor (1/4 -> 4) */
# define AOUT_MAX_INPUT_RATE (4)
# define AOUT_MAX_FILTERS 10
enum {
AOUT_RESAMPLING_NONE=0,
AOUT_RESAMPLING_UP,
......@@ -49,15 +51,15 @@ struct aout_input_t
{
unsigned samplerate; /**< Input sample rate */
/* pre-filters */
/* filters */
filter_t * pp_filters[AOUT_MAX_FILTERS];
int i_nb_filters;
unsigned i_nb_filters;
filter_t * p_playback_rate_filter;
/* resamplers */
filter_t * pp_resamplers[AOUT_MAX_FILTERS];
int i_nb_resamplers;
/* Resampler + converter to mixer */
filter_t * pp_resamplers[5];
unsigned i_nb_resamplers;
int i_resampling_type;
mtime_t i_resamp_start_date;
int i_resamp_start_drift;
......@@ -89,8 +91,8 @@ typedef struct
audio_sample_format_t input_format;
/* Filters between mixer and output */
filter_t *filters[AOUT_MAX_FILTERS];
int nb_filters;
filter_t *filters[5];
unsigned nb_filters;
vlc_atomic_t restart;
} aout_owner_t;
......@@ -119,10 +121,10 @@ block_t *aout_InputPlay( audio_output_t *p_aout, aout_input_t *p_input,
block_t *p_buffer, int i_input_rate, date_t * );
/* From filters.c : */
int aout_FiltersCreatePipeline( vlc_object_t *, filter_t **, int *,
const audio_sample_format_t *, const audio_sample_format_t * );
#define aout_FiltersCreatePipeline(o, pv, pc, inf, outf) \
aout_FiltersCreatePipeline(VLC_OBJECT(o), pv, pc, inf, outf)
int aout_FiltersCreatePipeline( vlc_object_t *, filter_t **, unsigned *,
unsigned, const audio_sample_format_t *, const audio_sample_format_t * );
#define aout_FiltersCreatePipeline(o, pv, pc, max, inf, outf) \
aout_FiltersCreatePipeline(VLC_OBJECT(o), pv, pc, max, inf, outf)
void aout_FiltersDestroyPipeline( filter_t *const *, unsigned );
void aout_FiltersPlay( filter_t *const *, unsigned, block_t ** );
......
......@@ -130,30 +130,31 @@ static int SplitConversion( const audio_sample_format_t *restrict infmt,
* @param obj parent VLC object for new filters
* @param filters table of filters [IN/OUT]
* @param nb_filters pointer to the number of filters in the table [IN/OUT]
* @param max_filters size of filters table [IN]
* @param infmt input audio format
* @param outfmt output audio format
* @return 0 on success, -1 on failure
*/
int aout_FiltersCreatePipeline( vlc_object_t *obj,
filter_t **filters,
int *nb_filters,
int aout_FiltersCreatePipeline( vlc_object_t *obj, filter_t **filters,
unsigned *nb_filters, unsigned max_filters,
const audio_sample_format_t *restrict infmt,
const audio_sample_format_t *restrict outfmt )
{
audio_sample_format_t curfmt = *outfmt;
unsigned i = 0, max = *nb_filters - AOUT_MAX_FILTERS;
unsigned i = 0;
max_filters -= *nb_filters;
filters += *nb_filters;
aout_FormatsPrint( obj, "filter(s)", infmt, outfmt );
while( !AOUT_FMTS_IDENTICAL( infmt, &curfmt ) )
{
if( i >= max )
if( i >= max_filters )
{
msg_Err( obj, "max (%u) filters reached", AOUT_MAX_FILTERS );
msg_Err( obj, "maximum of %u filters reached", max_filters );
dialog_Fatal( obj, _("Audio filtering failed"),
_("The maximum number of filters (%u) was reached."),
AOUT_MAX_FILTERS );
max_filters );
goto rollback;
}
......
......@@ -211,6 +211,7 @@ aout_input_t *aout_InputNew (audio_output_t * p_aout,
/* complete the filter chain if necessary */
if ( aout_FiltersCreatePipeline( p_aout, p_input->pp_filters,
&p_input->i_nb_filters,
AOUT_MAX_FILTERS,
&chain_input_format,
&p_filter->fmt_in.audio ) < 0 )
{
......@@ -242,7 +243,7 @@ aout_input_t *aout_InputNew (audio_output_t * p_aout,
/* complete the filter chain if necessary */
if ( aout_FiltersCreatePipeline( p_aout, p_input->pp_filters,
&p_input->i_nb_filters,
&p_input->i_nb_filters, AOUT_MAX_FILTERS,
&chain_input_format,
&chain_output_format ) < 0 )
{
......@@ -263,6 +264,8 @@ aout_input_t *aout_InputNew (audio_output_t * p_aout,
}
if (aout_FiltersCreatePipeline (p_aout, p_input->pp_resamplers,
&p_input->i_nb_resamplers,
sizeof (p_input->pp_resamplers)
/ sizeof (p_input->pp_resamplers[0]),
&chain_output_format, outfmt) < 0)
{
msg_Err (p_aout, "cannot setup a resampling pipeline");
......
......@@ -406,6 +406,8 @@ int aout_OutputNew (audio_output_t *aout, const audio_sample_format_t *fmtp)
/* Create filters. */
owner->nb_filters = 0;
if (aout_FiltersCreatePipeline (aout, owner->filters, &owner->nb_filters,
sizeof (owner->filters)
/ sizeof (owner->filters[0]),
&owner->mixer_format, &fmt) < 0)
{
msg_Err (aout, "couldn't create audio output pipeline");
......
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