[vlc-commits] transcode: video: refactor error handling
Alexandre Janniaux
git at videolan.org
Sat Jun 27 12:42:29 CEST 2020
vlc | branch: master | Alexandre Janniaux <ajanni at videolabs.io> | Thu Jun 25 14:19:29 2020 +0200| [09f4085e9acbbc22e7143a0b9a582a6cae9d4b66] | committer: Alexandre Janniaux
transcode: video: refactor error handling
The same error handling path is duplicated at multiple location. Move it
after function success and jump to it when necessary instead.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=09f4085e9acbbc22e7143a0b9a582a6cae9d4b66
---
modules/stream_out/transcode/video.c | 41 ++++++++++++------------------------
1 file changed, 13 insertions(+), 28 deletions(-)
diff --git a/modules/stream_out/transcode/video.c b/modules/stream_out/transcode/video.c
index 1d5db5b84d..094c1a357f 100644
--- a/modules/stream_out/transcode/video.c
+++ b/modules/stream_out/transcode/video.c
@@ -226,13 +226,8 @@ int transcode_video_init( sout_stream_t *p_stream, const es_format_t *p_fmt,
struct encoder_owner *p_enc_owner = (struct encoder_owner*)sout_EncoderCreate(p_stream, sizeof(struct encoder_owner));
if ( unlikely(p_enc_owner == NULL))
- {
- module_unneed( id->p_decoder, id->p_decoder->p_module );
- id->p_decoder->p_module = NULL;
- es_format_Clean( &id->decoder_out );
- es_format_Clean( &encoder_tested_fmt_in );
- return VLC_EGENERIC;
- }
+ goto error;
+
p_enc_owner->id = id;
p_enc_owner->enc.cbs = &encoder_video_transcode_cbs;
@@ -241,33 +236,16 @@ int transcode_video_init( sout_stream_t *p_stream, const es_format_t *p_fmt,
&id->p_decoder->fmt_in,
id->p_decoder->fmt_out.i_codec,
&encoder_tested_fmt_in ) )
- {
- module_unneed( id->p_decoder, id->p_decoder->p_module );
- id->p_decoder->p_module = NULL;
- es_format_Clean( &id->decoder_out );
- es_format_Clean( &encoder_tested_fmt_in );
- return VLC_EGENERIC;
- }
+ goto error;
p_enc_owner = (struct encoder_owner *)sout_EncoderCreate(p_stream, sizeof(struct encoder_owner));
if ( unlikely(p_enc_owner == NULL))
- {
- module_unneed( id->p_decoder, id->p_decoder->p_module );
- id->p_decoder->p_module = NULL;
- es_format_Clean( &encoder_tested_fmt_in );
- es_format_Clean( &id->decoder_out );
- return VLC_EGENERIC;
- }
+ goto error;
id->encoder = transcode_encoder_new( &p_enc_owner->enc, &encoder_tested_fmt_in );
if( !id->encoder )
- {
- module_unneed( id->p_decoder, id->p_decoder->p_module );
- id->p_decoder->p_module = NULL;
- es_format_Clean( &encoder_tested_fmt_in );
- es_format_Clean( &id->decoder_out );
- return VLC_EGENERIC;
- }
+ goto error;
+
p_enc_owner->id = id;
p_enc_owner->enc.cbs = &encoder_video_transcode_cbs;
@@ -277,6 +255,13 @@ int transcode_video_init( sout_stream_t *p_stream, const es_format_t *p_fmt,
es_format_Clean( &encoder_tested_fmt_in );
return VLC_SUCCESS;
+
+error:
+ module_unneed( id->p_decoder, id->p_decoder->p_module );
+ id->p_decoder->p_module = NULL;
+ es_format_Clean( &encoder_tested_fmt_in );
+ es_format_Clean( &id->decoder_out );
+ return VLC_EGENERIC;
}
static const struct filter_video_callbacks transcode_filter_video_cbs =
More information about the vlc-commits
mailing list