[FFmpeg-cvslog] avcodec/utils: add ff_thread_replace_frame()

James Almer git at videolan.org
Thu May 18 17:00:17 EEST 2023


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Wed Aug  3 12:36:39 2022 -0300| [3fe74c901757a8d544f2f3ace3e3228dd686925f] | committer: James Almer

avcodec/utils: add ff_thread_replace_frame()

Signed-off-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3fe74c901757a8d544f2f3ace3e3228dd686925f
---

 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)



More information about the ffmpeg-cvslog mailing list