From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id E90044C563 for ; Thu, 13 Nov 2025 14:58:54 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'M0Wv8/8OC0VdjQwJXkLZWNNtx6HgYie9v/NWYfYVHcY=', expected b'0vIAtkuviaZcB4Tuwxz4iqufQSL10Ej7l81zthJ9lEo=')) header.d=ffmpeg.org header.i=@ffmpeg.org header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1763045926; h=mime-version : to : date : message-id : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=M0Wv8/8OC0VdjQwJXkLZWNNtx6HgYie9v/NWYfYVHcY=; b=Lua5do0t1QtA/M0SE9ruzNHbcu0SwoFHQKlGIuqCXC59bmfc9KlXMJTr+GrXHMHxZop12 DeWRia1vWT3cbi6fE3/4Nn89zsS9f8NAa0Mcxdz1jKZsIe27cVZq1UuvhX9PKaxpyDfnxsM PAj36nCUQgJsccjePtqlH7CEwXU/mb9MM0MBGgzHA16Kd8sZ3gfG1GYo4C0Cy9d0dUNeD+s TU5JePf/G309lroipgHVtvBMyLSZBhIRncOwPZRcj0oeM0x1qaKBKwHGFiSUT6VwgAXxL9R pCgRokgv1Mwjb3E1Tw/xDqqjVEhCFNw+Xb/UBVGE6CAzEEIij3RV+d4VbPIg== Received: from [172.19.0.2] (unknown [172.19.0.2]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 5ABAB68FDBE; Thu, 13 Nov 2025 16:58:46 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1763045904; b=FxjoT4ydO0p65B856mCDPYwS0GuDAAP2gbbYX6Tk7rbEqyv4j/7piKZbezPaCwROI38Rv hyV8vvB60err9O5iGIUcJfvXp2NoVmrmWXruyQ0040cntJYDFJL8vjZSLqYxERUft/by2nC LCSUT7ldo0iaO8TdRIDvHXmKLvTrKXzkcfaNOeWII0DLcY5daeLXfoOyc3Sv+ppO0ffAxUl Z/rQAxPRsr+e0sW9virtkH3joWrBSeuOpjj4HefluSy7ce1y2PGOXTxBOZWUsJWIrtvY9xu BnaBu0IMeq/31PgVOA9JAz1CAKNdqDWLRtt13hKGwAVQmkBzQMrkD0nAo47g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1763045904; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=F6W5M8OAhahAZmP30KpdQQ7wvkq1aHZYOjrJ+HUALBM=; b=IH+k3X6fWMcQV2ce36t4VjdI/1uWpTsJ8P2HwjUDZDBj5mwwx2XQq58/2DD/SK0FNSpyl WEch/VqgPw5rA9QxxTbMAKLMrhutXhL65CDZGBMS2lTnKAHobeFQiZsueQkgEChUIzJHgrr sNk8QJmSCoBpxsFEFEgX++APLbaGeCBrPnzsQPvc8PhidjuZ4qk6KiKmRpf/cNp0QvdK7fJ BuI0aqUhFVyzv6IWzwygaTjuvYcodvp8nVWCgoP7PW8hNNMpKjD23ezihYfD/58/uJUN6Lc 7ztQdbbZYxnpsTW9JrJ12YRSP4T510RtTdZy32dEAs7O2orUMRxJY/KSC4BQ== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none; dmarc=pass header.from=ffmpeg.org policy.dmarc=quarantine Authentication-Results: ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=ffmpeg.org policy.dmarc=quarantine DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1763045896; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=0vIAtkuviaZcB4Tuwxz4iqufQSL10Ej7l81zthJ9lEo=; b=qjcxE6Cd0I/Y4g7SoA9fJ/hTl0kZCAw2QWzu5oASLtUM0+YmP6vtRHJgVv2GME8Xky3zd kK3dyoLaZ3QBJfNFA8KqMkkeireup6tO7C9g0eGC3jL7N6FK6cKOHH6GxyOjyf5Peg3Ks5e 4gIIjlv4JbRZL/0Ydt4trVo5w2m3l5DciW5gpqSSq2BAf415LQrx2ZXA1t/8KA1MTD11jQl Oet8MmoHN8l57604e0FjakyxehaoiOCbUvzDEHfY/e7VRFdfY6H6KkE8L/aWVb3wgruArzO WakLq8kmtK5+nqz0/vjnnc1fasIGN3iTEJrVQfpATEYqFHNyA4RvGFhQey8w== Received: from 188d6d40ca7a (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 1176A68FCF1 for ; Thu, 13 Nov 2025 16:58:16 +0200 (EET) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Nov 2025 14:58:15 -0000 Message-ID: <176304589620.25.4377755801134751951@2cb04c0e5124> Message-ID-Hash: RXDQQ2IZK735A34XSM3SS6GPRLWE2V4A X-Message-ID-Hash: RXDQQ2IZK735A34XSM3SS6GPRLWE2V4A X-MailFrom: code@ffmpeg.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH] Revert "avutil/hwcontext_amf: Simplified blocking before frame submission" (PR #20912) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: mkver via ffmpeg-devel Cc: mkver Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #20912 opened by mkver URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20912 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20912.patch This reverts commit 62184be5486ec06d6976c20931b30738c8e83fd8. It includes a private header (lavu/mutex.h) in a public header (hwcontext_amf.h). >>From 446aeebee3575ff4a605ac0d94f62094a5afef3f Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Thu, 13 Nov 2025 15:56:16 +0100 Subject: [PATCH] Revert "avutil/hwcontext_amf: Simplified blocking before frame submission" This reverts commit 62184be5486ec06d6976c20931b30738c8e83fd8. It includes a private header (lavu/mutex.h) in a public header (hwcontext_amf.h). Signed-off-by: Andreas Rheinhardt --- libavcodec/amfenc.c | 93 ++++++++++++++++++++++++++++++++++++--- libavutil/hwcontext_amf.c | 6 +-- libavutil/hwcontext_amf.h | 2 - 3 files changed, 90 insertions(+), 11 deletions(-) diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c index 2174c5bdb2..f363192000 100644 --- a/libavcodec/amfenc.c +++ b/libavcodec/amfenc.c @@ -381,6 +381,89 @@ static AMF_RESULT amf_set_property_buffer(AMFSurface *object, const wchar_t *nam return res; } +static AMF_RESULT amf_lock_context(AVCodecContext *avctx) +{ + AMFEncoderContext *ctx = avctx->priv_data; + AVHWDeviceContext *hw_device_ctx = (AVHWDeviceContext*)ctx->device_ctx_ref->data; + AVAMFDeviceContext *amf_device_ctx = (AVAMFDeviceContext *)hw_device_ctx->hwctx; + AMF_RESULT res; + + switch(amf_device_ctx->memory_type) { + case AMF_MEMORY_DX11: + res = amf_device_ctx->context->pVtbl->LockDX11(amf_device_ctx->context); + AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), "LockDX11() failed with error %d\n", res); + break; + case AMF_MEMORY_DX12: + { + AMFContext2 *context2 = NULL; + AMFGuid guid = IID_AMFContext2(); + res = amf_device_ctx->context->pVtbl->QueryInterface(amf_device_ctx->context, &guid, (void**)&context2); + AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "QueryInterface for AMFContext2 failed with error %d\n", res); + res = context2->pVtbl->LockDX12(context2); + AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), "LockDX12() failed with error %d\n", res); + context2->pVtbl->Release(context2); + } + break; + case AMF_MEMORY_DX9: + res = amf_device_ctx->context->pVtbl->LockDX9(amf_device_ctx->context); + AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), "LockDX9() failed with error %d\n", res); + + case AMF_MEMORY_VULKAN: + { + AMFContext2 *context2 = NULL; + AMFGuid guid = IID_AMFContext2(); + res = amf_device_ctx->context->pVtbl->QueryInterface(amf_device_ctx->context, &guid, (void**)&context2); + AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "QueryInterface for AMFContext2 failed with error %d\n", res); + res = context2->pVtbl->LockVulkan(context2); + AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), "LockVulkan() failed with error %d\n", res); + context2->pVtbl->Release(context2); + } + break; + } + return AMF_OK; +} +static AMF_RESULT amf_unlock_context(AVCodecContext *avctx) +{ + AMFEncoderContext *ctx = avctx->priv_data; + AVHWDeviceContext *hw_device_ctx = (AVHWDeviceContext*)ctx->device_ctx_ref->data; + AVAMFDeviceContext *amf_device_ctx = (AVAMFDeviceContext *)hw_device_ctx->hwctx; + AMF_RESULT res; + + switch(amf_device_ctx->memory_type) { + case AMF_MEMORY_DX11: + res = amf_device_ctx->context->pVtbl->UnlockDX11(amf_device_ctx->context); + AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), "LockDX11() failed with error %d\n", res); + break; + case AMF_MEMORY_DX12: + { + AMFContext2 *context2 = NULL; + AMFGuid guid = IID_AMFContext2(); + res = amf_device_ctx->context->pVtbl->QueryInterface(amf_device_ctx->context, &guid, (void**)&context2); + AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "QueryInterface for AMFContext2 failed with error %d\n", res); + res = context2->pVtbl->UnlockDX12(context2); + AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), "LockDX12() failed with error %d\n", res); + context2->pVtbl->Release(context2); + } + break; + case AMF_MEMORY_DX9: + res = amf_device_ctx->context->pVtbl->UnlockDX9(amf_device_ctx->context); + AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), "LockDX9() failed with error %d\n", res); + + case AMF_MEMORY_VULKAN: + { + AMFContext2 *context2 = NULL; + AMFGuid guid = IID_AMFContext2(); + res = amf_device_ctx->context->pVtbl->QueryInterface(amf_device_ctx->context, &guid, (void**)&context2); + AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "QueryInterface for AMFContext2 failed with error %d\n", res); + res = context2->pVtbl->UnlockVulkan(context2); + AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR(ENOMEM), "LockVulkan() failed with error %d\n", res); + context2->pVtbl->Release(context2); + } + break; + } + return AMF_OK; +} + static AMF_RESULT amf_store_attached_frame_ref(AMFEncoderContext *ctx, const AVFrame *frame, AMFSurface *surface) { AMF_RESULT res = AMF_FAIL; @@ -560,14 +643,14 @@ static int amf_submit_frame(AVCodecContext *avctx, AVFrame *frame, AMFSurface static int amf_submit_frame_locked(AVCodecContext *avctx, AVFrame *frame, AMFSurface **surface_resubmit) { int ret; - AMFEncoderContext *ctx = avctx->priv_data; - AVHWDeviceContext *hw_device_ctx = (AVHWDeviceContext*)ctx->device_ctx_ref->data; - AVAMFDeviceContext *amf_device_ctx = (AVAMFDeviceContext *)hw_device_ctx->hwctx; + int locked = amf_lock_context(avctx); + if(locked != AMF_OK) + av_log(avctx, AV_LOG_WARNING, "amf_lock_context() failed with %d - should not happen\n", locked); - ff_mutex_lock(&amf_device_ctx->mutex); ret = amf_submit_frame(avctx, frame, surface_resubmit); - ff_mutex_unlock(&amf_device_ctx->mutex); + if(locked == AMF_OK) + amf_unlock_context(avctx); return ret; } static AMF_RESULT amf_query_output(AVCodecContext *avctx, AMFBuffer **buffer) diff --git a/libavutil/hwcontext_amf.c b/libavutil/hwcontext_amf.c index acd9627c68..20b9296e34 100644 --- a/libavutil/hwcontext_amf.c +++ b/libavutil/hwcontext_amf.c @@ -137,7 +137,7 @@ enum AVPixelFormat av_amf_to_av_format(enum AMF_SURFACE_FORMAT fmt) return format_map[i].av_format; } } - return AV_PIX_FMT_NONE; + return AMF_SURFACE_UNKNOWN; } static const enum AVPixelFormat supported_formats[] = { @@ -378,7 +378,6 @@ static void amf_device_uninit(AVHWDeviceContext *device_ctx) } amf_ctx->version = 0; - ff_mutex_destroy(&amf_ctx->mutex); } static int amf_device_init(AVHWDeviceContext *ctx) @@ -415,8 +414,7 @@ static int amf_device_init(AVHWDeviceContext *ctx) } } #endif - ff_mutex_init(&amf_ctx->mutex, NULL); - return 0; + return 0; } static int amf_load_library(AVAMFDeviceContext* amf_ctx, void* avcl) diff --git a/libavutil/hwcontext_amf.h b/libavutil/hwcontext_amf.h index 5b726e3b9e..8823190697 100644 --- a/libavutil/hwcontext_amf.h +++ b/libavutil/hwcontext_amf.h @@ -26,7 +26,6 @@ #include #include #include -#include "thread.h" /** * This struct is allocated as AVHWDeviceContext.hwctx @@ -39,7 +38,6 @@ typedef struct AVAMFDeviceContext { int64_t version; ///< version of AMF runtime AMFContext *context; AMF_MEMORY_TYPE memory_type; - AVMutex mutex; } AVAMFDeviceContext; enum AMF_SURFACE_FORMAT av_av_to_amf_format(enum AVPixelFormat fmt); -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org