Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 2/3 v2] avcodec/utils: add ff_thread_replace_frame()
Date: Wed,  3 Aug 2022 13:02:47 -0300
Message-ID: <20220803160248.4190-2-jamrial@gmail.com> (raw)
In-Reply-To: <20220803160248.4190-1-jamrial@gmail.com>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/pthread_frame.c | 30 ++++++++++++++++++++++++++++++
 libavcodec/threadframe.h   |  3 +++
 libavcodec/utils.c         | 21 +++++++++++++++++++++
 3 files changed, 54 insertions(+)

diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index a54d16fee4..ef447ee699 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -1071,6 +1071,36 @@ int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
     return ret;
 }
 
+int ff_thread_replace_frame(AVCodecContext *avctx, ThreadFrame *dst,
+                            const ThreadFrame *src)
+{
+    int ret;
+#if FF_API_THREAD_SAFE_CALLBACKS
+FF_DISABLE_DEPRECATION_WARNINGS
+    int can_direct_free = !(avctx->active_thread_type & FF_THREAD_FRAME) ||
+                          THREAD_SAFE_CALLBACKS(avctx);
+FF_ENABLE_DEPRECATION_WARNINGS
+
+    if (!can_direct_free)
+        ff_thread_release_ext_buffer(avctx, dst);
+#endif
+
+    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;
+}
+
 void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f)
 {
 #if FF_API_THREAD_SAFE_CALLBACKS
diff --git a/libavcodec/threadframe.h b/libavcodec/threadframe.h
index 100e068e06..a8403c8976 100644
--- a/libavcodec/threadframe.h
+++ b/libavcodec/threadframe.h
@@ -84,4 +84,7 @@ 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);
+
 #endif
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index e73e3a7d08..44ed19458c 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -928,6 +928,27 @@ int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
     return ff_get_buffer(avctx, f->f, flags);
 }
 
+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;
+}
+
 void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f)
 {
     if (f)
-- 
2.37.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  reply	other threads:[~2022-08-03 16:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-03 16:02 [FFmpeg-devel] [PATCH 1/3 v4] avutil/frame: add av_frame_replace James Almer
2022-08-03 16:02 ` James Almer [this message]
2022-08-04 18:33   ` [FFmpeg-devel] [PATCH 2/3 v2] avcodec/utils: add ff_thread_replace_frame() Michael Niedermayer
2022-08-04 18:39     ` James Almer
2022-08-03 16:02 ` [FFmpeg-devel] [PATCH 3/3 v2] avcodec/h264_picture: use ff_thread_replace_frame() James Almer
2023-05-18 12:55 ` [FFmpeg-devel] [PATCH 1/3 v4] avutil/frame: add av_frame_replace James Almer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220803160248.4190-2-jamrial@gmail.com \
    --to=jamrial@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git