avutil/hwcontext_amf: move AVMutex to internal context

This commit is contained in:
Dmitrii Ovchinnikov
2025-11-13 17:40:26 +01:00
parent efd6e85abb
commit 140b4f28c3
5 changed files with 41 additions and 8 deletions

View File

@@ -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.

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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, \