The branch, master has been updated
via 140b4f28c303abc531daeac4eb42dd014cdb5afb (commit)
from efd6e85abbf8cbea5992554823b27e2e32c8f2c3 (commit)
- Log -----------------------------------------------------------------
commit 140b4f28c303abc531daeac4eb42dd014cdb5afb
Author: Dmitrii Ovchinnikov <[email protected]>
AuthorDate: Thu Nov 13 17:40:26 2025 +0100
Commit: Dmitrii Ovchinnikov <[email protected]>
CommitDate: Mon Nov 24 20:06:24 2025 +0000
avutil/hwcontext_amf: move AVMutex to internal context
diff --git a/doc/APIchanges b/doc/APIchanges
index bfea83c73a..93c6f92704 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2025-03-28
API changes, most recent first:
+2025-11-18 - xxxxxxxxxx - lavu 60.19.100 - hwcontext_amf.h
+ avutil/hwcontext_amf: add lock and unlock for AVAMFDeviceContext.
+
2025-11-16 - xxxxxxxxxx - lavu 60.18.100 - cpu.h
Deprecate AV_CPU_FLAG_FORCE without replacement.
diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 2174c5bdb2..b07da236c7 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -564,9 +564,11 @@ 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);
+ if (amf_device_ctx->lock)
+ amf_device_ctx->lock(amf_device_ctx->lock_ctx);
ret = amf_submit_frame(avctx, frame, surface_resubmit);
- ff_mutex_unlock(&amf_device_ctx->mutex);
+ if (amf_device_ctx->unlock)
+ amf_device_ctx->unlock(amf_device_ctx->lock_ctx);
return ret;
}
diff --git a/libavutil/hwcontext_amf.c b/libavutil/hwcontext_amf.c
index acd9627c68..c754dc4ee5 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,15 @@
#endif
#define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
+static void amf_lock_default(void *opaque)
+{
+ ff_mutex_lock((AVMutex*)opaque);
+}
+
+static void amf_unlock_default(void *opaque)
+{
+ ff_mutex_unlock((AVMutex*)opaque);
+}
typedef struct AmfTraceWriter {
AMFTraceWriterVtbl *vtblp;
@@ -352,7 +362,7 @@ static int amf_transfer_data_from(AVHWFramesContext *ctx,
AVFrame *dst,
static void amf_device_uninit(AVHWDeviceContext *device_ctx)
{
- AVAMFDeviceContext *amf_ctx = device_ctx->hwctx;
+ AVAMFDeviceContext *amf_ctx = device_ctx->hwctx;
AMF_RESULT res = AMF_NOT_INITIALIZED;
AMFTrace *trace;
@@ -377,8 +387,14 @@ static void amf_device_uninit(AVHWDeviceContext
*device_ctx)
amf_writer_free(amf_ctx->trace_writer);
}
+ if (amf_ctx->lock_ctx == amf_lock_default) {
+ ff_mutex_destroy((AVMutex*)amf_ctx->lock_ctx);
+ av_freep(&amf_ctx->lock_ctx);
+ amf_ctx->lock = NULL;
+ amf_ctx->unlock = NULL;
+ }
+
amf_ctx->version = 0;
- ff_mutex_destroy(&amf_ctx->mutex);
}
static int amf_device_init(AVHWDeviceContext *ctx)
@@ -387,6 +403,16 @@ static int amf_device_init(AVHWDeviceContext *ctx)
AMFContext1 *context1 = NULL;
AMF_RESULT res;
+ if (!amf_ctx->lock) {
+ amf_ctx->lock_ctx = av_mallocz(sizeof(AVMutex));
+ if (!amf_ctx->lock_ctx) {
+ return AVERROR(ENOMEM);
+ }
+ ff_mutex_init((AVMutex*)amf_ctx->lock_ctx, NULL);
+ amf_ctx->lock = amf_lock_default;
+ amf_ctx->unlock = amf_unlock_default;
+ }
+
#ifdef _WIN32
res = amf_ctx->context->pVtbl->InitDX11(amf_ctx->context, NULL,
AMF_DX11_1);
if (res == AMF_OK || res == AMF_ALREADY_INITIALIZED) {
@@ -415,7 +441,7 @@ static int amf_device_init(AVHWDeviceContext *ctx)
}
}
#endif
- ff_mutex_init(&amf_ctx->mutex, NULL);
+
return 0;
}
diff --git a/libavutil/hwcontext_amf.h b/libavutil/hwcontext_amf.h
index 5b726e3b9e..6f2cabc878 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,7 +38,10 @@ typedef struct AVAMFDeviceContext {
int64_t version; ///< version of AMF runtime
AMFContext *context;
AMF_MEMORY_TYPE memory_type;
- AVMutex mutex;
+
+ void (*lock)(void *lock_ctx);
+ void (*unlock)(void *lock_ctx);
+ void *lock_ctx;
} AVAMFDeviceContext;
enum AMF_SURFACE_FORMAT av_av_to_amf_format(enum AVPixelFormat fmt);
diff --git a/libavutil/version.h b/libavutil/version.h
index d1385a8829..db250d5c9e 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 60
-#define LIBAVUTIL_VERSION_MINOR 18
+#define LIBAVUTIL_VERSION_MINOR 19
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-----------------------------------------------------------------------
Summary of changes:
doc/APIchanges | 3 +++
libavcodec/amfenc.c | 6 ++++--
libavutil/hwcontext_amf.c | 32 +++++++++++++++++++++++++++++---
libavutil/hwcontext_amf.h | 6 ++++--
libavutil/version.h | 2 +-
5 files changed, 41 insertions(+), 8 deletions(-)
hooks/post-receive
--
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]