From: Dmitrii Ovchinnikov via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Dmitrii Ovchinnikov <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] avutil/hwcontext_amf: move AVMutex to internal context (PR #20915)
Date: Fri, 14 Nov 2025 09:31:48 -0000
Message-ID: <176311270945.25.17511555861951567400@2cb04c0e5124> (raw)
PR #20915 opened by Dmitrii Ovchinnikov (OvchinnikovDmitrii)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20915
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20915.patch
>From bfcdc58dee88778c8f48a54d7d7989417bba79c2 Mon Sep 17 00:00:00 2001
From: Dmitrii Ovchinnikov <ovchinnikov.dmitrii@gmail.com>
Date: Thu, 13 Nov 2025 17:40:26 +0100
Subject: [PATCH] avutil/hwcontext_amf: move AVMutex to internal context
---
libavcodec/amfenc.c | 4 ++--
libavutil/hwcontext_amf.c | 30 +++++++++++++++++++++++++-----
libavutil/hwcontext_amf.h | 5 +++--
3 files changed, 30 insertions(+), 9 deletions(-)
diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 2174c5bdb2..43eb393497 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -564,9 +564,9 @@ static int amf_submit_frame_locked(AVCodecContext *avctx, AVFrame *frame, AMFSur
AVHWDeviceContext *hw_device_ctx = (AVHWDeviceContext*)ctx->device_ctx_ref->data;
AVAMFDeviceContext *amf_device_ctx = (AVAMFDeviceContext *)hw_device_ctx->hwctx;
- ff_mutex_lock(&amf_device_ctx->mutex);
+ av_amf_device_lock(amf_device_ctx);
ret = amf_submit_frame(avctx, frame, surface_resubmit);
- ff_mutex_unlock(&amf_device_ctx->mutex);
+ av_amf_device_unlock(amf_device_ctx);
return ret;
}
diff --git a/libavutil/hwcontext_amf.c b/libavutil/hwcontext_amf.c
index acd9627c68..bf0adee0c6 100644
--- a/libavutil/hwcontext_amf.c
+++ b/libavutil/hwcontext_amf.c
@@ -39,6 +39,7 @@
#include "pixdesc.h"
#include "pixfmt.h"
#include "imgutils.h"
+#include "thread.h"
#include "libavutil/avassert.h"
#include <AMF/core/Surface.h>
#include <AMF/core/Trace.h>
@@ -49,6 +50,22 @@
#endif
#define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
+typedef struct AVAMFDeviceContextInternal {
+ AVAMFDeviceContext p;
+ AVMutex mutex;
+} AVAMFDeviceContextInternal ;
+
+void av_amf_device_lock(AVAMFDeviceContext *ctx)
+{
+ AVAMFDeviceContextInternal *priv = (AVAMFDeviceContextInternal*)ctx;
+ ff_mutex_lock(&priv->mutex);
+}
+
+void av_amf_device_unlock(AVAMFDeviceContext *ctx)
+{
+ AVAMFDeviceContextInternal *priv = (AVAMFDeviceContextInternal*)ctx;
+ ff_mutex_unlock(&priv->mutex);
+}
typedef struct AmfTraceWriter {
AMFTraceWriterVtbl *vtblp;
@@ -352,7 +369,8 @@ static int amf_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst,
static void amf_device_uninit(AVHWDeviceContext *device_ctx)
{
- AVAMFDeviceContext *amf_ctx = device_ctx->hwctx;
+ AVAMFDeviceContextInternal *priv = device_ctx->hwctx;
+ AVAMFDeviceContext *amf_ctx = &priv->p;
AMF_RESULT res = AMF_NOT_INITIALIZED;
AMFTrace *trace;
@@ -378,12 +396,13 @@ static void amf_device_uninit(AVHWDeviceContext *device_ctx)
}
amf_ctx->version = 0;
- ff_mutex_destroy(&amf_ctx->mutex);
+ ff_mutex_destroy(&priv->mutex);
}
static int amf_device_init(AVHWDeviceContext *ctx)
{
- AVAMFDeviceContext *amf_ctx = ctx->hwctx;
+ AVAMFDeviceContextInternal *priv = ctx->hwctx;
+ AVAMFDeviceContext *amf_ctx = &priv->p;
AMFContext1 *context1 = NULL;
AMF_RESULT res;
@@ -415,7 +434,8 @@ static int amf_device_init(AVHWDeviceContext *ctx)
}
}
#endif
- ff_mutex_init(&amf_ctx->mutex, NULL);
+
+ ff_mutex_init(&priv->mutex, NULL);
return 0;
}
@@ -644,7 +664,7 @@ const HWContextType ff_hwcontext_type_amf = {
.type = AV_HWDEVICE_TYPE_AMF,
.name = "AMF",
- .device_hwctx_size = sizeof(AVAMFDeviceContext),
+ .device_hwctx_size = sizeof(AVAMFDeviceContextInternal),
.frames_hwctx_size = sizeof(AMFFramesContext),
.device_create = amf_device_create,
diff --git a/libavutil/hwcontext_amf.h b/libavutil/hwcontext_amf.h
index 5b726e3b9e..56362e2e0b 100644
--- a/libavutil/hwcontext_amf.h
+++ b/libavutil/hwcontext_amf.h
@@ -26,7 +26,6 @@
#include <AMF/core/Context.h>
#include <AMF/core/Trace.h>
#include <AMF/core/Debug.h>
-#include "thread.h"
/**
* This struct is allocated as AVHWDeviceContext.hwctx
@@ -39,9 +38,11 @@ typedef struct AVAMFDeviceContext {
int64_t version; ///< version of AMF runtime
AMFContext *context;
AMF_MEMORY_TYPE memory_type;
- AVMutex mutex;
} AVAMFDeviceContext;
+void av_amf_device_lock (AVAMFDeviceContext *ctx);
+void av_amf_device_unlock(AVAMFDeviceContext *ctx);
+
enum AMF_SURFACE_FORMAT av_av_to_amf_format(enum AVPixelFormat fmt);
enum AVPixelFormat av_amf_to_av_format(enum AMF_SURFACE_FORMAT fmt);
--
2.49.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
reply other threads:[~2025-11-14 9:32 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=176311270945.25.17511555861951567400@2cb04c0e5124 \
--to=ffmpeg-devel@ffmpeg.org \
--cc=code@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