Use av_frame_replace() instead. Also remove the error message: It was highly misleading (as if av_frame_clone() duplicated the AVFrame data buffers instead of just creating a new reference).
Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -297,7 +297,7 @@ static int fic_decode_frame(AVCodecContext *avctx, AVFrame *rframe, · 296 unmodified lines | |||
| 297 | 297 | ||
| 298 | /* Is it a skip frame? */ | 298 | /* Is it a skip frame? */ |
| 299 | if (src[17]) { | 299 | if (src[17]) { |
| 300 | if (!ctx->final_frame) { | 300 | if (!ctx->final_frame->data[0]) { |
| 301 | av_log(avctx, AV_LOG_WARNING, "Initial frame is skipped\n"); | 301 | av_log(avctx, AV_LOG_WARNING, "Initial frame is skipped\n"); |
| 302 | return AVERROR_INVALIDDATA; | 302 | return AVERROR_INVALIDDATA; |
| 303 | } | 303 | } |
| @@ -416,12 +416,9 @@ static int fic_decode_frame(AVCodecContext *avctx, AVFrame *rframe, · 112 unmodified lines | |||
| 416 | break; | 416 | break; |
| 417 | } | 417 | } |
| 418 | } | 418 | } |
| 419 | av_frame_free(&ctx->final_frame); | 419 | ret = av_frame_replace(ctx->final_frame, ctx->frame); |
| 420 | ctx->final_frame = av_frame_clone(ctx->frame); | 420 | if (ret < 0) |
| 421 | if (!ctx->final_frame) { | 421 | return ret; |
| 422 | av_log(avctx, AV_LOG_ERROR, "Could not clone frame buffer.\n"); | ||
| 423 | return AVERROR(ENOMEM); | ||
| 424 | } | ||
| 425 | 422 | ||
| 426 | /* Make sure we use a user-supplied buffer. */ | 423 | /* Make sure we use a user-supplied buffer. */ |
| 427 | if ((ret = ff_reget_buffer(avctx, ctx->final_frame, 0)) < 0) { | 424 | if ((ret = ff_reget_buffer(avctx, ctx->final_frame, 0)) < 0) { |
| @@ -468,6 +465,9 @@ static av_cold int fic_decode_init(AVCodecContext *avctx) · 40 unmodified lines | |||
| 468 | ctx->frame = av_frame_alloc(); | 465 | ctx->frame = av_frame_alloc(); |
| 469 | if (!ctx->frame) | 466 | if (!ctx->frame) |
| 470 | return AVERROR(ENOMEM); | 467 | return AVERROR(ENOMEM); |
| 468 | ctx->final_frame = av_frame_alloc(); | ||
| 469 | if (!ctx->final_frame) | ||
| 470 | return AVERROR(ENOMEM); | ||
| 471 | 471 | ||
| 472 | return 0; | 472 | return 0; |
| 473 | } | 473 | } |
| @@ -495,4 +495,5 @@ const FFCodec ff_fic_decoder = { · 21 unmodified lines | |||
| 495 | .close = fic_decode_close, | 495 | .close = fic_decode_close, |
| 496 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_SLICE_THREADS, | 496 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_SLICE_THREADS, |
| 497 | .p.priv_class = &fic_decoder_class, | 497 | .p.priv_class = &fic_decoder_class, |
| 498 | .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, | ||
| 498 | }; | 499 | }; |