libaribb24_close() does the same as the fail path in libaribb24_init().
Unified · Split
| @@ -147,12 +147,12 @@ static int libaribb24_init(AVCodecContext *avctx) · 146 unmodified lines | |||
| 147 | { | 147 | { |
| 148 | Libaribb24Context *b24 = avctx->priv_data; | 148 | Libaribb24Context *b24 = avctx->priv_data; |
| 149 | void(* arib_dec_init)(arib_decoder_t* decoder) = NULL; | 149 | void(* arib_dec_init)(arib_decoder_t* decoder) = NULL; |
| 150 | int ret_code = AVERROR_EXTERNAL; | 150 | int ret; |
| 151 | int profile = avctx->profile; | 151 | int profile = avctx->profile; |
| 152 | 152 | ||
| 153 | if (!(b24->lib_instance = arib_instance_new(avctx))) { | 153 | if (!(b24->lib_instance = arib_instance_new(avctx))) { |
| 154 | av_log(avctx, AV_LOG_ERROR, "Failed to initialize libaribb24!\n"); | 154 | av_log(avctx, AV_LOG_ERROR, "Failed to initialize libaribb24!\n"); |
| 155 | goto init_fail; | 155 | return AVERROR_EXTERNAL; |
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | if (b24->aribb24_base_path) { | 158 | if (b24->aribb24_base_path) { |
| @@ -165,11 +165,11 @@ static int libaribb24_init(AVCodecContext *avctx) · 6 unmodified lines | |||
| 165 | 165 | ||
| 166 | if (!(b24->parser = arib_get_parser(b24->lib_instance))) { | 166 | if (!(b24->parser = arib_get_parser(b24->lib_instance))) { |
| 167 | av_log(avctx, AV_LOG_ERROR, "Failed to initialize libaribb24 PES parser!\n"); | 167 | av_log(avctx, AV_LOG_ERROR, "Failed to initialize libaribb24 PES parser!\n"); |
| 168 | goto init_fail; | 168 | return AVERROR_EXTERNAL; |
| 169 | } | 169 | } |
| 170 | if (!(b24->decoder = arib_get_decoder(b24->lib_instance))) { | 170 | if (!(b24->decoder = arib_get_decoder(b24->lib_instance))) { |
| 171 | av_log(avctx, AV_LOG_ERROR, "Failed to initialize libaribb24 decoder!\n"); | 171 | av_log(avctx, AV_LOG_ERROR, "Failed to initialize libaribb24 decoder!\n"); |
| 172 | goto init_fail; | 172 | return AVERROR_EXTERNAL; |
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | if (profile == AV_PROFILE_UNKNOWN) | 175 | if (profile == AV_PROFILE_UNKNOWN) |
| @@ -184,27 +184,16 @@ static int libaribb24_init(AVCodecContext *avctx) · 8 unmodified lines | |||
| 184 | break; | 184 | break; |
| 185 | default: | 185 | default: |
| 186 | av_log(avctx, AV_LOG_ERROR, "Unknown or unsupported profile set!\n"); | 186 | av_log(avctx, AV_LOG_ERROR, "Unknown or unsupported profile set!\n"); |
| 187 | ret_code = AVERROR(EINVAL); | 187 | return AVERROR(EINVAL); |
| 188 | goto init_fail; | ||
| 189 | } | 188 | } |
| 190 | 189 | ||
| 191 | arib_dec_init(b24->decoder); | 190 | arib_dec_init(b24->decoder); |
| 192 | 191 | ||
| 193 | if (libaribb24_generate_ass_header(avctx) < 0) { | 192 | ret = libaribb24_generate_ass_header(avctx); |
| 194 | ret_code = AVERROR(ENOMEM); | 193 | if (ret < 0) |
| 195 | goto init_fail; | 194 | return ret; |
| 196 | } | ||
| 197 | 195 | ||
| 198 | return 0; | 196 | return 0; |
| 199 | |||
| 200 | init_fail: | ||
| 201 | if (b24->decoder) | ||
| 202 | arib_finalize_decoder(b24->decoder); | ||
| 203 | |||
| 204 | if (b24->lib_instance) | ||
| 205 | arib_instance_destroy(b24->lib_instance); | ||
| 206 | |||
| 207 | return ret_code; | ||
| 208 | } | 197 | } |
| 209 | 198 | ||
| 210 | static int libaribb24_close(AVCodecContext *avctx) | 199 | static int libaribb24_close(AVCodecContext *avctx) |
| @@ -410,7 +399,7 @@ const FFCodec ff_libaribb24_decoder = { · 199 unmodified lines | |||
| 410 | .p.id = AV_CODEC_ID_ARIB_CAPTION, | 399 | .p.id = AV_CODEC_ID_ARIB_CAPTION, |
| 411 | .p.priv_class = &aribb24_class, | 400 | .p.priv_class = &aribb24_class, |
| 412 | .p.wrapper_name = "libaribb24", | 401 | .p.wrapper_name = "libaribb24", |
| 413 | .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE, | 402 | .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_NOT_INIT_THREADSAFE, |
| 414 | .priv_data_size = sizeof(Libaribb24Context), | 403 | .priv_data_size = sizeof(Libaribb24Context), |
| 415 | .init = libaribb24_init, | 404 | .init = libaribb24_init, |
| 416 | .close = libaribb24_close, | 405 | .close = libaribb24_close, |