[vlc-devel] [PATCH 5/8] opus: factorize error cases in OpenEncoder
Rafaël Carré
funman at videolan.org
Sat Sep 21 16:54:32 CEST 2013
---
modules/codec/opus.c | 35 ++++++++++++++++-------------------
1 file changed, 16 insertions(+), 19 deletions(-)
diff --git a/modules/codec/opus.c b/modules/codec/opus.c
index fa96d2c..2f50b77 100644
--- a/modules/codec/opus.c
+++ b/modules/codec/opus.c
@@ -571,6 +571,9 @@ static int OpenEncoder(vlc_object_t *p_this)
if (!sys)
return VLC_ENOMEM;
+ sys->buffer = NULL;
+ sys->enc = NULL;
+
enc->pf_encode_audio = Encode;
enc->fmt_in.i_codec = VLC_CODEC_FL32;
enc->fmt_in.audio.i_rate = /* Only 48kHz */
@@ -584,8 +587,7 @@ static int OpenEncoder(vlc_object_t *p_this)
&header))
{
msg_Err(enc, "Failed to prepare header.");
- free(sys);
- return VLC_ENOMEM;
+ goto error;
}
/* needed for max encoded size calculation */
@@ -601,8 +603,8 @@ static int OpenEncoder(vlc_object_t *p_this)
if (err != OPUS_OK)
{
msg_Err(enc, "Could not create encoder: error %d", err);
- free(sys);
- return VLC_EGENERIC;
+ sys->enc = NULL;
+ goto error;
}
/* TODO: vbr, bitrate, fec */
@@ -612,11 +614,7 @@ static int OpenEncoder(vlc_object_t *p_this)
enc->p_sys = sys;
sys->buffer = malloc(OPUS_FRAME_SIZE * header.channels * sizeof(float));
if (!sys->buffer)
- {
- opus_multistream_encoder_destroy(sys->enc);
- free(sys);
- return VLC_ENOMEM;
- }
+ goto error;
sys->i_nb_samples = 0;
@@ -634,10 +632,7 @@ static int OpenEncoder(vlc_object_t *p_this)
&enc->fmt_out.i_extra, &header))
{
msg_Err(enc, "Failed to write header.");
- free(sys->buffer);
- opus_multistream_encoder_destroy(sys->enc);
- free(sys);
- return VLC_ENOMEM;
+ goto error;
}
if (sys->i_samples_delay > 0)
@@ -646,12 +641,7 @@ static int OpenEncoder(vlc_object_t *p_this)
enc->fmt_out.audio.i_channels;
sys->padding = block_Alloc(padding_samples * sizeof(float));
if (!sys->padding)
- {
- free(sys->buffer);
- opus_multistream_encoder_destroy(sys->enc);
- free(sys);
- return VLC_ENOMEM;
- }
+ goto error;
sys->padding->i_nb_samples = sys->i_samples_delay;
float *pad_ptr = (float *) sys->padding->p_buffer;
memset(pad_ptr, 0, padding_samples * sizeof(float));
@@ -662,6 +652,13 @@ static int OpenEncoder(vlc_object_t *p_this)
}
return VLC_SUCCESS;
+
+error:
+ if (sys->enc)
+ opus_multistream_encoder_destroy(sys->enc);
+ free(sys->buffer);
+ free(sys);
+ return VLC_EGENERIC;
}
static void CloseEncoder(vlc_object_t *p_this)
--
1.8.1.2
More information about the vlc-devel
mailing list