From 3fe74c901757a8d544f2f3ace3e3228dd686925f Mon Sep 17 00:00:00 2001 From: James Almer Date: Wed, 3 Aug 2022 12:36:39 -0300 Subject: [PATCH] avcodec/utils: add ff_thread_replace_frame() Signed-off-by: James Almer --- libavcodec/threadframe.h | 3 +++ libavcodec/utils.c | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/libavcodec/threadframe.h b/libavcodec/threadframe.h index d2f93c5cd0..d581c408a5 100644 --- a/libavcodec/threadframe.h +++ b/libavcodec/threadframe.h @@ -84,6 +84,9 @@ void ff_thread_release_ext_buffer(AVCodecContext *avctx, ThreadFrame *f); int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src); +int ff_thread_replace_frame(AVCodecContext *avctx, ThreadFrame *dst, + const ThreadFrame *src); + int ff_thread_can_start_frame(AVCodecContext *avctx); #endif diff --git a/libavcodec/utils.c b/libavcodec/utils.c index ef1845954e..a8514ba6c1 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -915,6 +915,27 @@ int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src) return 0; } +int ff_thread_replace_frame(AVCodecContext *avctx, ThreadFrame *dst, + const ThreadFrame *src) +{ + int ret; + + dst->owner[0] = src->owner[0]; + dst->owner[1] = src->owner[1]; + + ret = av_frame_replace(dst->f, src->f); + if (ret < 0) + return ret; + + ret = av_buffer_replace(&dst->progress, src->progress); + if (ret < 0) { + ff_thread_release_ext_buffer(dst->owner[0], dst); + return ret; + } + + return 0; +} + #if !HAVE_THREADS int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)