[vlc-commits] aout: handle filters creation/deletion from decoder, fix memory leak
Rémi Denis-Courmont
git at videolan.org
Tue Nov 6 22:56:22 CET 2012
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Nov 6 23:55:49 2012 +0200| [f8e940016f9d710ebfafe8e3898fe591dd9c76c2] | committer: Rémi Denis-Courmont
aout: handle filters creation/deletion from decoder, fix memory leak
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f8e940016f9d710ebfafe8e3898fe591dd9c76c2
---
src/audio_output/aout_internal.h | 8 +++-----
src/audio_output/dec.c | 31 +++++++++++++++++--------------
src/audio_output/filters.c | 2 +-
src/audio_output/input.c | 21 ++++-----------------
4 files changed, 25 insertions(+), 37 deletions(-)
diff --git a/src/audio_output/aout_internal.h b/src/audio_output/aout_internal.h
index caf6503..05901b6 100644
--- a/src/audio_output/aout_internal.h
+++ b/src/audio_output/aout_internal.h
@@ -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 *);
diff --git a/src/audio_output/dec.c b/src/audio_output/dec.c
index 124eb31..9c66267 100644
--- a/src/audio_output/dec.c
+++ b/src/audio_output/dec.c
@@ -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);
}
/**
diff --git a/src/audio_output/filters.c b/src/audio_output/filters.c
index 87317cb..ffaf575 100644
--- a/src/audio_output/filters.c
+++ b/src/audio_output/filters.c
@@ -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);
diff --git a/src/audio_output/input.c b/src/audio_output/input.c
index 3056809..bdea6ad 100644
--- a/src/audio_output/input.c
+++ b/src/audio_output/input.c
@@ -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);
}
/*****************************************************************************
More information about the vlc-commits
mailing list