Commit 34bc07f8 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

aout: allocate input from input.c, simplify

parent b97b9eb9
...@@ -66,9 +66,6 @@ struct aout_input_t ...@@ -66,9 +66,6 @@ struct aout_input_t
mtime_t i_resamp_start_date; mtime_t i_resamp_start_date;
int i_resamp_start_drift; int i_resamp_start_drift;
/* If b_error == 1, there is no input pipeline. */
bool b_error;
/* last rate from input */ /* last rate from input */
int i_last_input_rate; int i_last_input_rate;
...@@ -130,9 +127,9 @@ static inline aout_owner_t *aout_owner (audio_output_t *aout) ...@@ -130,9 +127,9 @@ static inline aout_owner_t *aout_owner (audio_output_t *aout)
*****************************************************************************/ *****************************************************************************/
/* From input.c : */ /* From input.c : */
int aout_InputNew(audio_output_t *, const audio_sample_format_t *, aout_input_t *aout_InputNew(audio_output_t *, const audio_sample_format_t *,
const audio_sample_format_t *, const audio_sample_format_t *,
aout_input_t *, const aout_request_vout_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 * );
......
...@@ -80,15 +80,9 @@ int aout_DecNew( audio_output_t *p_aout, ...@@ -80,15 +80,9 @@ int aout_DecNew( audio_output_t *p_aout,
return -1; return -1;
} }
aout_input_t *p_input = calloc( 1, sizeof(aout_input_t));
if( !p_input )
return -1;
p_input->b_error = true;
/* We can only be called by the decoder, so no need to lock
* p_input->lock. */
aout_owner_t *owner = aout_owner(p_aout); aout_owner_t *owner = aout_owner(p_aout);
int ret = -1;
aout_lock( p_aout ); aout_lock( p_aout );
/* Create the audio output stream */ /* Create the audio output stream */
...@@ -114,15 +108,15 @@ int aout_DecNew( audio_output_t *p_aout, ...@@ -114,15 +108,15 @@ int aout_DecNew( audio_output_t *p_aout,
date_Set (&owner->sync.date, VLC_TS_INVALID); date_Set (&owner->sync.date, VLC_TS_INVALID);
assert (owner->input == NULL); assert (owner->input == NULL);
owner->input = p_input; owner->input = aout_InputNew (p_aout, p_format, &owner->mixer_format,
aout_InputNew( p_aout, p_format, &owner->mixer_format, p_input, p_request_vout);
p_request_vout ); if (owner->input == NULL)
aout_unlock( p_aout ); aout_OutputDelete (p_aout);
return 0; else
ret = 0;
error: error:
aout_unlock( p_aout ); aout_unlock( p_aout );
free( p_input ); return ret;
return -1;
} }
/***************************************************************************** /*****************************************************************************
...@@ -161,7 +155,6 @@ void aout_DecDelete( audio_output_t * p_aout ) ...@@ -161,7 +155,6 @@ void aout_DecDelete( audio_output_t * p_aout )
static void aout_CheckRestart (audio_output_t *aout) static void aout_CheckRestart (audio_output_t *aout)
{ {
aout_owner_t *owner = aout_owner (aout); aout_owner_t *owner = aout_owner (aout);
aout_input_t *input = owner->input;
aout_assert_locked (aout); aout_assert_locked (aout);
...@@ -170,7 +163,11 @@ static void aout_CheckRestart (audio_output_t *aout) ...@@ -170,7 +163,11 @@ static void aout_CheckRestart (audio_output_t *aout)
return; return;
assert (restart & AOUT_RESTART_INPUT); assert (restart & AOUT_RESTART_INPUT);
aout_InputDelete (aout, input);
const aout_request_vout_t request_vout = owner->input->request_vout;
aout_InputDelete (aout, owner->input);
owner->input = NULL;
/* Reinitializes the output */ /* Reinitializes the output */
if (restart & AOUT_RESTART_OUTPUT) if (restart & AOUT_RESTART_OUTPUT)
...@@ -180,19 +177,13 @@ static void aout_CheckRestart (audio_output_t *aout) ...@@ -180,19 +177,13 @@ static void aout_CheckRestart (audio_output_t *aout)
aout_OutputDelete (aout); aout_OutputDelete (aout);
if (aout_OutputNew (aout, &owner->input_format)) if (aout_OutputNew (aout, &owner->input_format))
{
input->b_error = true;
return; /* we are officially screwed */ return; /* we are officially screwed */
}
owner->volume.mixer = aout_MixerNew (aout, owner->volume.mixer = aout_MixerNew (aout,
owner->mixer_format.i_format); owner->mixer_format.i_format);
} }
if (aout_InputNew (aout, &owner->input_format, &owner->mixer_format, input, owner->input = aout_InputNew (aout, &owner->input_format,
&input->request_vout)) &owner->mixer_format, &request_vout);
assert (input->b_error);
else
assert (!input->b_error);
} }
/** /**
...@@ -267,7 +258,7 @@ int aout_DecPlay (audio_output_t *p_aout, block_t *p_buffer, int i_input_rate) ...@@ -267,7 +258,7 @@ int aout_DecPlay (audio_output_t *p_aout, block_t *p_buffer, int i_input_rate)
/ owner->input_format.i_rate; / owner->input_format.i_rate;
aout_lock( p_aout ); aout_lock( p_aout );
if( p_input->b_error ) if (unlikely(p_input == NULL)) /* can happen due to restart */
{ {
aout_unlock( p_aout ); aout_unlock( p_aout );
aout_BufferFree( p_buffer ); aout_BufferFree( p_buffer );
......
...@@ -29,8 +29,6 @@ ...@@ -29,8 +29,6 @@
# include "config.h" # include "config.h"
#endif #endif
#include <assert.h>
#include <vlc_common.h> #include <vlc_common.h>
#include <stdio.h> #include <stdio.h>
...@@ -46,7 +44,6 @@ ...@@ -46,7 +44,6 @@
#include "aout_internal.h" #include "aout_internal.h"
static void inputFailure( audio_output_t *, aout_input_t *, const char * );
static void inputDrop( aout_input_t *, aout_buffer_t * ); static void inputDrop( aout_input_t *, aout_buffer_t * );
static void inputResamplingStop( aout_input_t *p_input ); static void inputResamplingStop( aout_input_t *p_input );
...@@ -61,16 +58,14 @@ static vout_thread_t *RequestVout( void *, ...@@ -61,16 +58,14 @@ 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 *aout_InputNew (audio_output_t * p_aout,
const audio_sample_format_t *restrict infmt, const audio_sample_format_t *restrict infmt,
const audio_sample_format_t *restrict outfmt, const audio_sample_format_t *restrict outfmt,
aout_input_t * p_input, const aout_request_vout_t *p_request_vout)
const aout_request_vout_t *p_request_vout )
{ {
audio_sample_format_t chain_input_format; aout_input_t *p_input = malloc (sizeof (*p_input));
audio_sample_format_t chain_output_format; if (unlikely(p_input == NULL))
char *psz_filters, *psz_visual, *psz_scaletempo; return NULL;
int i_visual;
aout_FormatPrint( p_aout, "input", infmt ); aout_FormatPrint( p_aout, "input", infmt );
p_input->samplerate = infmt->i_rate; p_input->samplerate = infmt->i_rate;
...@@ -89,8 +84,9 @@ int aout_InputNew( audio_output_t * p_aout, ...@@ -89,8 +84,9 @@ int aout_InputNew( audio_output_t * p_aout,
} }
/* Prepare format structure */ /* Prepare format structure */
chain_input_format = *infmt; audio_sample_format_t chain_input_format = *infmt;
chain_output_format = *outfmt; audio_sample_format_t chain_output_format = *outfmt;
chain_output_format.i_rate = infmt->i_rate; chain_output_format.i_rate = infmt->i_rate;
aout_FormatPrepare( &chain_output_format ); aout_FormatPrepare( &chain_output_format );
...@@ -98,9 +94,9 @@ int aout_InputNew( audio_output_t * p_aout, ...@@ -98,9 +94,9 @@ int aout_InputNew( audio_output_t * p_aout,
var_AddCallback( p_aout, "visual", VisualizationCallback, p_input ); var_AddCallback( p_aout, "visual", VisualizationCallback, p_input );
var_AddCallback( p_aout, "equalizer", EqualizerCallback, p_input ); var_AddCallback( p_aout, "equalizer", EqualizerCallback, p_input );
psz_filters = var_GetString( p_aout, "audio-filter" ); char *psz_filters = var_GetString( p_aout, "audio-filter" );
psz_visual = var_GetString( p_aout, "audio-visual"); char *psz_visual = var_GetString( p_aout, "audio-visual");
psz_scaletempo = var_InheritBool( p_aout, "audio-time-stretch" ) ? strdup( "scaletempo" ) : NULL; char *psz_scaletempo = var_InheritBool( p_aout, "audio-time-stretch" ) ? strdup( "scaletempo" ) : NULL;
p_input->b_recycle_vout = psz_visual && *psz_visual; p_input->b_recycle_vout = psz_visual && *psz_visual;
...@@ -108,7 +104,9 @@ int aout_InputNew( audio_output_t * p_aout, ...@@ -108,7 +104,9 @@ int aout_InputNew( audio_output_t * p_aout,
char *const ppsz_array[] = { psz_scaletempo, psz_filters, psz_visual }; char *const ppsz_array[] = { psz_scaletempo, psz_filters, psz_visual };
p_input->p_playback_rate_filter = NULL; p_input->p_playback_rate_filter = NULL;
for( i_visual = 0; i_visual < 3 && AOUT_FMT_LINEAR(&chain_output_format); i_visual++ ) for (unsigned i_visual = 0;
i_visual < 3 && AOUT_FMT_LINEAR(&chain_output_format);
i_visual++)
{ {
char *psz_next = NULL; char *psz_next = NULL;
char *psz_parser = ppsz_array[i_visual]; char *psz_parser = ppsz_array[i_visual];
...@@ -254,8 +252,8 @@ int aout_InputNew( audio_output_t * p_aout, ...@@ -254,8 +252,8 @@ int aout_InputNew( audio_output_t * p_aout,
&chain_input_format, &chain_input_format,
&chain_output_format ) < 0 ) &chain_output_format ) < 0 )
{ {
inputFailure( p_aout, p_input, "couldn't set an input pipeline" ); msg_Err (p_aout, "cannot setup filtering pipeline");
return -1; goto error;
} }
/* Create resamplers. */ /* Create resamplers. */
...@@ -273,8 +271,8 @@ int aout_InputNew( audio_output_t * p_aout, ...@@ -273,8 +271,8 @@ int aout_InputNew( audio_output_t * p_aout,
&p_input->i_nb_resamplers, &p_input->i_nb_resamplers,
&chain_output_format, outfmt) < 0) &chain_output_format, outfmt) < 0)
{ {
inputFailure( p_aout, p_input, "couldn't set a resampler pipeline"); msg_Err (p_aout, "cannot setup a resampling pipeline");
return -1; goto error;
} }
/* Setup the initial rate of the resampler */ /* Setup the initial rate of the resampler */
...@@ -288,10 +286,16 @@ int aout_InputNew( audio_output_t * p_aout, ...@@ -288,10 +286,16 @@ int aout_InputNew( audio_output_t * p_aout,
} }
/* Success */ /* Success */
p_input->b_error = false;
p_input->i_last_input_rate = INPUT_RATE_DEFAULT; p_input->i_last_input_rate = INPUT_RATE_DEFAULT;
p_input->i_buffer_lost = 0;
return p_input;
return 0; error:
aout_FiltersDestroyPipeline( p_input->pp_filters, p_input->i_nb_filters );
aout_FiltersDestroyPipeline( p_input->pp_resamplers,
p_input->i_nb_resamplers );
free (p_input);
return NULL;
} }
/***************************************************************************** /*****************************************************************************
...@@ -301,10 +305,6 @@ int aout_InputNew( audio_output_t * p_aout, ...@@ -301,10 +305,6 @@ int aout_InputNew( audio_output_t * p_aout,
*****************************************************************************/ *****************************************************************************/
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 )
{ {
aout_assert_locked( p_aout );
if ( p_input->b_error )
return 0;
var_DelCallback (p_aout, "equalizer", EqualizerCallback, p_input); var_DelCallback (p_aout, "equalizer", EqualizerCallback, p_input);
var_DelCallback (p_aout, "visual", VisualizationCallback, p_input); var_DelCallback (p_aout, "visual", VisualizationCallback, p_input);
...@@ -548,21 +548,6 @@ block_t *aout_InputPlay(audio_output_t *p_aout, aout_input_t *p_input, ...@@ -548,21 +548,6 @@ block_t *aout_InputPlay(audio_output_t *p_aout, aout_input_t *p_input,
* static functions * static functions
*****************************************************************************/ *****************************************************************************/
static void inputFailure( audio_output_t * p_aout, aout_input_t * p_input,
const char * psz_error_message )
{
/* error message */
msg_Err( p_aout, "%s", psz_error_message );
/* clean up */
aout_FiltersDestroyPipeline( p_input->pp_filters, p_input->i_nb_filters );
aout_FiltersDestroyPipeline( p_input->pp_resamplers,
p_input->i_nb_resamplers );
/* error flag */
p_input->b_error = 1;
}
static void inputDrop( aout_input_t *p_input, aout_buffer_t *p_buffer ) static void inputDrop( aout_input_t *p_input, aout_buffer_t *p_buffer )
{ {
aout_BufferFree( p_buffer ); aout_BufferFree( p_buffer );
......
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