Commit 502b865b authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

aout: move input format to aout_owner

parent a489b9cb
...@@ -51,8 +51,8 @@ block_t *aout_FilterBufferNew( filter_t *, int ); ...@@ -51,8 +51,8 @@ block_t *aout_FilterBufferNew( filter_t *, int );
/** an input stream for the audio output */ /** an input stream for the audio output */
struct aout_input_t struct aout_input_t
{ {
audio_sample_format_t input;
float multiplier; /**< Replay gain multiplier */ float multiplier; /**< Replay gain multiplier */
unsigned samplerate; /**< Input sample rate */
/* pre-filters */ /* pre-filters */
filter_t * pp_filters[AOUT_MAX_FILTERS]; filter_t * pp_filters[AOUT_MAX_FILTERS];
...@@ -106,6 +106,7 @@ typedef struct ...@@ -106,6 +106,7 @@ typedef struct
} volume; /**< Volume and gain management (FIXME: input manager?) */ } volume; /**< Volume and gain management (FIXME: input manager?) */
audio_sample_format_t mixer_format; audio_sample_format_t mixer_format;
audio_sample_format_t input_format;
/* Filters between mixer and output */ /* Filters between mixer and output */
filter_t *filters[AOUT_MAX_FILTERS]; filter_t *filters[AOUT_MAX_FILTERS];
...@@ -130,7 +131,8 @@ static inline aout_owner_t *aout_owner (audio_output_t *aout) ...@@ -130,7 +131,8 @@ static inline aout_owner_t *aout_owner (audio_output_t *aout)
*****************************************************************************/ *****************************************************************************/
/* From input.c : */ /* From input.c : */
int aout_InputNew( audio_output_t * p_aout, aout_input_t * p_input, const aout_request_vout_t * ); int aout_InputNew(audio_output_t *, const audio_sample_format_t *,
aout_input_t *, const aout_request_vout_t *);
int aout_InputDelete( audio_output_t * p_aout, aout_input_t * p_input ); int aout_InputDelete( audio_output_t * p_aout, aout_input_t * p_input );
block_t *aout_InputPlay( audio_output_t *p_aout, aout_input_t *p_input, block_t *aout_InputPlay( audio_output_t *p_aout, aout_input_t *p_input,
block_t *p_buffer, int i_input_rate, date_t * ); block_t *p_buffer, int i_input_rate, date_t * );
......
...@@ -83,8 +83,6 @@ int aout_DecNew( audio_output_t *p_aout, ...@@ -83,8 +83,6 @@ int aout_DecNew( audio_output_t *p_aout,
p_input->b_error = true; p_input->b_error = true;
memcpy( &p_input->input, p_format,
sizeof(audio_sample_format_t) );
if( p_replay_gain ) if( p_replay_gain )
p_input->replay_gain = *p_replay_gain; p_input->replay_gain = *p_replay_gain;
...@@ -98,6 +96,7 @@ int aout_DecNew( audio_output_t *p_aout, ...@@ -98,6 +96,7 @@ int aout_DecNew( audio_output_t *p_aout,
var_Destroy( p_aout, "audio-channels" ); var_Destroy( p_aout, "audio-channels" );
/* Recreate the output using the new format. */ /* Recreate the output using the new format. */
owner->input_format = *p_format;
if( aout_OutputNew( p_aout, p_format ) < 0 ) if( aout_OutputNew( p_aout, p_format ) < 0 )
goto error; goto error;
...@@ -108,7 +107,7 @@ int aout_DecNew( audio_output_t *p_aout, ...@@ -108,7 +107,7 @@ int aout_DecNew( audio_output_t *p_aout,
date_Set (&owner->sync.date, VLC_TS_INVALID); date_Set (&owner->sync.date, VLC_TS_INVALID);
owner->input = p_input; owner->input = p_input;
aout_InputNew( p_aout, p_input, p_request_vout ); aout_InputNew( p_aout, p_format, p_input, p_request_vout );
aout_unlock( p_aout ); aout_unlock( p_aout );
return 0; return 0;
error: error:
...@@ -161,7 +160,7 @@ static void aout_CheckRestart (audio_output_t *aout) ...@@ -161,7 +160,7 @@ static void aout_CheckRestart (audio_output_t *aout)
owner->volume.mixer = NULL; owner->volume.mixer = NULL;
aout_OutputDelete (aout); aout_OutputDelete (aout);
if (aout_OutputNew (aout, &input->input)) if (aout_OutputNew (aout, &owner->input_format))
{ {
input->b_error = true; input->b_error = true;
return; /* we are officially screwed */ return; /* we are officially screwed */
...@@ -169,7 +168,7 @@ static void aout_CheckRestart (audio_output_t *aout) ...@@ -169,7 +168,7 @@ static void aout_CheckRestart (audio_output_t *aout)
owner->volume.mixer = aout_MixerNew (aout, owner->mixer_format.i_format); owner->volume.mixer = aout_MixerNew (aout, owner->mixer_format.i_format);
if (aout_InputNew (aout, input, &input->request_vout)) if (aout_InputNew (aout, &owner->input_format, input, &input->request_vout))
assert (input->b_error); assert (input->b_error);
else else
assert (!input->b_error); assert (!input->b_error);
...@@ -187,10 +186,9 @@ block_t *aout_DecNewBuffer (audio_output_t *aout, size_t samples) ...@@ -187,10 +186,9 @@ block_t *aout_DecNewBuffer (audio_output_t *aout, size_t samples)
{ {
/* NOTE: the caller is responsible for serializing input change */ /* NOTE: the caller is responsible for serializing input change */
aout_owner_t *owner = aout_owner (aout); aout_owner_t *owner = aout_owner (aout);
aout_input_t *input = owner->input;
size_t length = samples * input->input.i_bytes_per_frame size_t length = samples * owner->input_format.i_bytes_per_frame
/ input->input.i_frame_length; / owner->input_format.i_frame_length;
block_t *block = block_Alloc( length ); block_t *block = block_Alloc( length );
if( likely(block != NULL) ) if( likely(block != NULL) )
{ {
...@@ -222,7 +220,7 @@ int aout_DecPlay (audio_output_t *p_aout, block_t *p_buffer, int i_input_rate) ...@@ -222,7 +220,7 @@ int aout_DecPlay (audio_output_t *p_aout, block_t *p_buffer, int i_input_rate)
assert( p_buffer->i_pts > 0 ); assert( p_buffer->i_pts > 0 );
p_buffer->i_length = (mtime_t)p_buffer->i_nb_samples * 1000000 p_buffer->i_length = (mtime_t)p_buffer->i_nb_samples * 1000000
/ p_input->input.i_rate; / owner->input_format.i_rate;
aout_lock( p_aout ); aout_lock( p_aout );
if( p_input->b_error ) if( p_input->b_error )
......
...@@ -66,7 +66,10 @@ static vout_thread_t *RequestVout( void *, ...@@ -66,7 +66,10 @@ static vout_thread_t *RequestVout( void *,
/***************************************************************************** /*****************************************************************************
* aout_InputNew : allocate a new input and rework the filter pipeline * aout_InputNew : allocate a new input and rework the filter pipeline
*****************************************************************************/ *****************************************************************************/
int aout_InputNew( audio_output_t * p_aout, aout_input_t * p_input, const aout_request_vout_t *p_request_vout ) int aout_InputNew( audio_output_t * p_aout,
const audio_sample_format_t *restrict format,
aout_input_t * p_input,
const aout_request_vout_t *p_request_vout )
{ {
aout_owner_t *owner = aout_owner (p_aout); aout_owner_t *owner = aout_owner (p_aout);
audio_sample_format_t chain_input_format; audio_sample_format_t chain_input_format;
...@@ -75,7 +78,8 @@ int aout_InputNew( audio_output_t * p_aout, aout_input_t * p_input, const aout_r ...@@ -75,7 +78,8 @@ int aout_InputNew( audio_output_t * p_aout, aout_input_t * p_input, const aout_r
char *psz_filters, *psz_visual, *psz_scaletempo; char *psz_filters, *psz_visual, *psz_scaletempo;
int i_visual; int i_visual;
aout_FormatPrint( p_aout, "input", &p_input->input ); aout_FormatPrint( p_aout, "input", format );
p_input->samplerate = format->i_rate;
p_input->i_nb_resamplers = p_input->i_nb_filters = 0; p_input->i_nb_resamplers = p_input->i_nb_filters = 0;
...@@ -91,9 +95,9 @@ int aout_InputNew( audio_output_t * p_aout, aout_input_t * p_input, const aout_r ...@@ -91,9 +95,9 @@ int aout_InputNew( audio_output_t * p_aout, aout_input_t * p_input, const aout_r
} }
/* Prepare format structure */ /* Prepare format structure */
chain_input_format = p_input->input; chain_input_format = *format;
chain_output_format = owner->mixer_format; chain_output_format = owner->mixer_format;
chain_output_format.i_rate = p_input->input.i_rate; chain_output_format.i_rate = format->i_rate;
aout_FormatPrepare( &chain_output_format ); aout_FormatPrepare( &chain_output_format );
/* Now add user filters */ /* Now add user filters */
...@@ -382,7 +386,7 @@ int aout_InputNew( audio_output_t * p_aout, aout_input_t * p_input, const aout_r ...@@ -382,7 +386,7 @@ int aout_InputNew( audio_output_t * p_aout, aout_input_t * p_input, const aout_r
/* Create resamplers. */ /* Create resamplers. */
if (AOUT_FMT_LINEAR(&owner->mixer_format)) if (AOUT_FMT_LINEAR(&owner->mixer_format))
{ {
chain_output_format.i_rate = (__MAX(p_input->input.i_rate, chain_output_format.i_rate = (__MAX(p_input->samplerate,
owner->mixer_format.i_rate) owner->mixer_format.i_rate)
* (100 + AOUT_MAX_RESAMPLING)) / 100; * (100 + AOUT_MAX_RESAMPLING)) / 100;
if ( chain_output_format.i_rate == owner->mixer_format.i_rate ) if ( chain_output_format.i_rate == owner->mixer_format.i_rate )
...@@ -400,7 +404,7 @@ int aout_InputNew( audio_output_t * p_aout, aout_input_t * p_input, const aout_r ...@@ -400,7 +404,7 @@ int aout_InputNew( audio_output_t * p_aout, aout_input_t * p_input, const aout_r
} }
/* Setup the initial rate of the resampler */ /* Setup the initial rate of the resampler */
p_input->pp_resamplers[0]->fmt_in.audio.i_rate = p_input->input.i_rate; p_input->pp_resamplers[0]->fmt_in.audio.i_rate = p_input->samplerate;
} }
p_input->i_resampling_type = AOUT_RESAMPLING_NONE; p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
...@@ -453,13 +457,14 @@ int aout_InputDelete( audio_output_t * p_aout, aout_input_t * p_input ) ...@@ -453,13 +457,14 @@ int aout_InputDelete( audio_output_t * p_aout, aout_input_t * p_input )
*****************************************************************************/ *****************************************************************************/
void aout_InputCheckAndRestart( audio_output_t * p_aout, aout_input_t * p_input ) void aout_InputCheckAndRestart( audio_output_t * p_aout, aout_input_t * p_input )
{ {
aout_owner_t *owner = aout_owner(p_aout);
aout_assert_locked( p_aout ); aout_assert_locked( p_aout );
if( !p_input->b_restart ) if( !p_input->b_restart )
return; return;
aout_InputDelete( p_aout, p_input ); aout_InputDelete( p_aout, p_input );
aout_InputNew( p_aout, p_input, &p_input->request_vout ); aout_InputNew( p_aout, &owner->input_format, p_input, &p_input->request_vout );
p_input->b_restart = false; p_input->b_restart = false;
} }
...@@ -513,8 +518,8 @@ block_t *aout_InputPlay(audio_output_t *p_aout, aout_input_t *p_input, ...@@ -513,8 +518,8 @@ block_t *aout_InputPlay(audio_output_t *p_aout, aout_input_t *p_input,
{ {
unsigned int * const pi_rate = &p_input->p_playback_rate_filter->fmt_in.audio.i_rate; unsigned int * const pi_rate = &p_input->p_playback_rate_filter->fmt_in.audio.i_rate;
#define F(r,ir) ( INPUT_RATE_DEFAULT * (r) / (ir) ) #define F(r,ir) ( INPUT_RATE_DEFAULT * (r) / (ir) )
const int i_delta = *pi_rate - F(p_input->input.i_rate,p_input->i_last_input_rate); const int i_delta = *pi_rate - F(p_input->samplerate,p_input->i_last_input_rate);
*pi_rate = F(p_input->input.i_rate + i_delta, i_input_rate); *pi_rate = F(p_input->samplerate + i_delta, i_input_rate);
#undef F #undef F
p_input->i_last_input_rate = i_input_rate; p_input->i_last_input_rate = i_input_rate;
} }
...@@ -628,8 +633,8 @@ block_t *aout_InputPlay(audio_output_t *p_aout, aout_input_t *p_input, ...@@ -628,8 +633,8 @@ block_t *aout_InputPlay(audio_output_t *p_aout, aout_input_t *p_input,
* resampling */ * resampling */
unsigned int i_nominal_rate = unsigned int i_nominal_rate =
(p_input->pp_resamplers[0] == p_input->p_playback_rate_filter) (p_input->pp_resamplers[0] == p_input->p_playback_rate_filter)
? INPUT_RATE_DEFAULT * p_input->input.i_rate / i_input_rate ? INPUT_RATE_DEFAULT * p_input->samplerate / i_input_rate
: p_input->input.i_rate; : p_input->samplerate;
if( p_input->pp_resamplers[0]->fmt_in.audio.i_rate == i_nominal_rate ) if( p_input->pp_resamplers[0]->fmt_in.audio.i_rate == i_nominal_rate )
{ {
p_input->i_resampling_type = AOUT_RESAMPLING_NONE; p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
...@@ -724,8 +729,8 @@ static void inputResamplingStop( aout_input_t *p_input ) ...@@ -724,8 +729,8 @@ static void inputResamplingStop( aout_input_t *p_input )
{ {
p_input->pp_resamplers[0]->fmt_in.audio.i_rate = p_input->pp_resamplers[0]->fmt_in.audio.i_rate =
( p_input->pp_resamplers[0] == p_input->p_playback_rate_filter ) ( p_input->pp_resamplers[0] == p_input->p_playback_rate_filter )
? INPUT_RATE_DEFAULT * p_input->input.i_rate / p_input->i_last_input_rate ? INPUT_RATE_DEFAULT * p_input->samplerate / p_input->i_last_input_rate
: p_input->input.i_rate; : p_input->samplerate;
} }
} }
......
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