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

aout: handle filters creation/deletion from decoder, fix memory leak

parent 5864ae43
......@@ -108,10 +108,8 @@ static inline aout_owner_t *aout_owner (audio_output_t *aout)
*****************************************************************************/
/* From input.c : */
aout_input_t *aout_InputNew(audio_output_t *, const audio_sample_format_t *,
const audio_sample_format_t *,
const aout_request_vout_t *);
int aout_InputDelete( audio_output_t * p_aout, aout_input_t * p_input );
aout_input_t *aout_InputNew(const audio_sample_format_t *);
void aout_InputDelete(aout_input_t *);
block_t *aout_InputPlay( audio_output_t *p_aout, aout_input_t *p_input,
block_t *p_buffer, int i_input_rate, date_t * );
......@@ -125,7 +123,7 @@ void aout_FiltersPlay( filter_t *const *, unsigned, block_t ** );
int aout_FiltersNew(audio_output_t *, const audio_sample_format_t *,
const audio_sample_format_t *, const aout_request_vout_t *);
void aout_FiltersDestroy(audio_output_t *);
void aout_FiltersDelete(audio_output_t *);
/* From mixer.c : */
aout_volume_t *aout_volume_New(vlc_object_t *, const audio_replay_gain_t *);
......
......@@ -83,19 +83,21 @@ int aout_DecNew( audio_output_t *p_aout,
aout_volume_SetFormat (owner->volume, owner->mixer_format.i_format);
/* Create the audio filtering "input" pipeline */
date_Init (&owner->sync.date, owner->mixer_format.i_rate, 1);
date_Set (&owner->sync.date, VLC_TS_INVALID);
assert (owner->input == NULL);
owner->input = aout_InputNew (p_aout, p_format, &owner->mixer_format,
p_request_vout);
if (owner->input == NULL)
if (aout_FiltersNew (p_aout, p_format, &owner->mixer_format,
p_request_vout))
{
aout_OutputDelete (p_aout);
error:
aout_volume_Delete (owner->volume);
ret = -1;
goto error;
}
date_Init (&owner->sync.date, owner->mixer_format.i_rate, 1);
date_Set (&owner->sync.date, VLC_TS_INVALID);
assert (owner->input == NULL);
owner->input = aout_InputNew (p_format);
aout_unlock( p_aout );
return ret;
}
......@@ -111,17 +113,16 @@ void aout_DecDelete (audio_output_t *p_aout)
aout_lock( p_aout );
/* Remove the input. */
input = owner->input;
if (likely(input != NULL))
aout_InputDelete (p_aout, input);
aout_InputDelete (input);
owner->input = NULL;
aout_FiltersDelete (p_aout);
aout_OutputDelete( p_aout );
aout_volume_Delete (owner->volume);
var_Destroy( p_aout, "stereo-mode" );
aout_unlock( p_aout );
free (input);
}
#define AOUT_RESTART_OUTPUT 1
......@@ -140,10 +141,11 @@ static void aout_CheckRestart (audio_output_t *aout)
const aout_request_vout_t request_vout = owner->request_vout;
if (likely(owner->input != NULL))
aout_InputDelete (aout, owner->input);
aout_InputDelete (owner->input);
owner->input = NULL;
aout_FiltersDelete (aout);
/* Reinitializes the output */
if (restart & AOUT_RESTART_OUTPUT)
{
......@@ -156,8 +158,9 @@ static void aout_CheckRestart (audio_output_t *aout)
aout_volume_SetFormat (owner->volume, owner->mixer_format.i_format);
}
owner->input = aout_InputNew (aout, &owner->input_format,
&owner->mixer_format, &request_vout);
if (aout_FiltersNew (aout, &owner->input_format, &owner->mixer_format,
&request_vout) == 0)
owner->input = aout_InputNew (&owner->input_format);
}
/**
......
......@@ -518,7 +518,7 @@ error:
/**
* Destroys the audio filters.
*/
void aout_FiltersDestroy (audio_output_t *aout)
void aout_FiltersDelete (audio_output_t *aout)
{
aout_owner_t *owner = aout_owner (aout);
......
......@@ -43,23 +43,12 @@ static void inputResamplingStop( audio_output_t *, aout_input_t * );
/*****************************************************************************
* aout_InputNew : allocate a new input and rework the filter pipeline
*****************************************************************************/
aout_input_t *aout_InputNew (audio_output_t * p_aout,
const audio_sample_format_t *restrict infmt,
const audio_sample_format_t *restrict outfmt,
const aout_request_vout_t *p_request_vout)
aout_input_t *aout_InputNew (const audio_sample_format_t *restrict infmt)
{
aout_input_t *p_input = malloc (sizeof (*p_input));
if (unlikely(p_input == NULL))
return NULL;
aout_input_t *p_input = xmalloc (sizeof (*p_input));
p_input->samplerate = infmt->i_rate;
if (aout_FiltersNew (p_aout, infmt, outfmt, p_request_vout))
{
free(p_input);
return NULL;
}
p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
p_input->i_last_input_rate = INPUT_RATE_DEFAULT;
p_input->i_buffer_lost = 0;
......@@ -71,11 +60,9 @@ aout_input_t *aout_InputNew (audio_output_t * p_aout,
*****************************************************************************
* This function must be entered with the mixer lock.
*****************************************************************************/
int aout_InputDelete( audio_output_t * p_aout, aout_input_t * p_input )
void aout_InputDelete (aout_input_t * p_input )
{
aout_FiltersDestroy (p_aout);
(void) p_input;
return 0;
free (p_input);
}
/*****************************************************************************
......
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