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 <[email protected]> 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 -- [email protected] To unsubscribe send an email to [email protected]
