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 493B54C09D for ; Tue, 7 Oct 2025 14:49:34 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'OXPylsg+9nEXqu0dl/1Rpo/27cnpELbBxToDVPZN1Tg=', expected b'cVtVE+W64GRSWLDEw8kLCXGOzmK/K29HoGV5ZKZWjXA=')) 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=1759848563; 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=OXPylsg+9nEXqu0dl/1Rpo/27cnpELbBxToDVPZN1Tg=; b=cdh0Fo3qDeQ6QeaswYfLGeM3VtjoKGJjDWeFAFtsg/mfsnj3/dyKcm7iWYBKmNERFWnZO 5vTascPafz15mjYtQflh6B0E32QtJtpmfKJw3fFMUQ5+dCdNE87CO/2XmcyGgL3OoW6VcYz sYU7CgXt31Dq7RCMjTGWkj1W1eiP6I4Lfxcwx+X93BCMpbJPnjTWtbQqSpDK+tDmk6Sn91x X+TAFqQPw5vWO1eGeO4EcvzFyzXlacAw1htOplJYu9lnVx94SEDe4CyrmacbGDMMobTRB8m yJBj2DiwS7v/RlNIdsgfLhAbmD5hj++H56OfrjsNq73kd7UrPDksxnpXOB8w== Received: from [172.18.0.2] (unknown [172.19.0.4]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 9F52968F0D8; Tue, 7 Oct 2025 17:49:23 +0300 (EEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1759848544; b=Z+eshVqmDcfO3zi8ITQ2ba5hEDOu1OuX8Tz+jjwUiQy5W/r4hKS01iNUPTAiB45W/FCIr Kx/TgldIEfZU6VNN6J9KKzKCO6JfhD+bhpTrzYZ2pOJId1MWYrfxNOVm77cIYlxgIsQrWyT DoFTNjwbfL6ASmOEe98P1hbCCgDRCA8RVSmIbwh5BL7AXwcUWanPkEdjEaGEcd77xK4Eou4 yXHajZyfe9H8WmbI6yHp+bt/C9ZXXYG3t1zD4ZxbkstI2ygYNxj+duG15mK7xtGqtObpdZZ Kuxbpye0BaWECCuJeTAshd6rn3ZLBAIHv/7elDB8aUjvfpy0DoFO18KC6Jfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1759848544; 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=i0W+L15yCsXy3/Tb7KaZwaqJfswny1PB5R/gNYOlvpA=; b=czM5N4XuuZ2ue9brOCT7JHoNM2SHV+5xfhWjJGEmhaBpTkxEmQLdZREQx4ryP8SgOfwbc b66W1zabimqqIWoH80kAV3m9Q3TKPeoUMwyCswTd4yTQodU40zGN1pBLVA1xn4dkn8BkfNa /pvNJMYa3pW62cqxeZOCpTW6XVWt5YC4tiqyfPIoEHF3UaSwGIrn82M5Bu2AbsW7wEq4wiC AXUH1OzGKPfzdVNyhctzCqk/Xa0zM/edujbKSHn2Dma0NttTjDZLU1GOZW/i/FsCgawjv43 IFTpFArj5lbcM/qQ0udwWkZoM/yNYf8ekuG5lgJafy9U4qxfTQiMMo2KlGJg== 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=1759848537; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=cVtVE+W64GRSWLDEw8kLCXGOzmK/K29HoGV5ZKZWjXA=; b=w5tYW5elzwKlqWyJdfOq5BA8Gago7Mq2Xpr1OOr1DCQtH4LZcm9ox/QgymoEFt/AF6rN2 UryIKmfE2oCyml38XRy1qeLnheCUZycpVGceRApKeScNrjy1076WJGiiZ0ZTn3yPrY7qDIh +ni/u3StPbx4ZqcttSPdMzAjEumvdnujAv3AKvNUx2BmPr/2erbT3ZOYxv971mZX4K2yMuZ 0wSeigBgCZHaDcH61U4bPdw2B1iSb7CHfymuiFQ5f1oFRGQAQlXGrd0q/5bk3V6bj4whpJH JhE4cpWq6UUUDj5pFFHcbfy62n4LGtvoArz7J07TDDY/x+LJNAucZ9jAjr5w== Received: from be50bb5a3685 (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id B220568F05B for ; Tue, 7 Oct 2025 17:48:57 +0300 (EEST) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Tue, 07 Oct 2025 14:48:57 -0000 Message-ID: <175984853798.65.709582289224105112@bf249f23a2c8> Message-ID-Hash: S3EMUUYJQYPIAZJO25MDE4C5YOLIK5GX X-Message-ID-Hash: S3EMUUYJQYPIAZJO25MDE4C5YOLIK5GX X-MailFrom: code@ffmpeg.org 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; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH] libavutil/hwcontext_amf: Simplified blocking before frame submission (PR #20660) 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: Dmitrii Ovchinnikov via ffmpeg-devel Cc: Dmitrii Ovchinnikov Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #20660 opened by Dmitrii Ovchinnikov (OvchinnikovDmitrii) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20660 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20660.patch Instead of blocking the entire context, which can cause issues in more complex pipelines, now only frame sending is blocked via AVMutex >>From 28a5a1446a7e93093bae15e686028e4c56c3e015 Mon Sep 17 00:00:00 2001 From: Dmitrii Ovchinnikov Date: Wed, 23 Jul 2025 16:51:33 +0200 Subject: [PATCH] libavutil/hwcontext_amf: Simplified blocking before frame submission Instead of blocking the entire context, which can cause issues in more complex pipelines, now only frame sending is blocked via AVMutex --- libavcodec/amfenc.c | 93 +++------------------------------------ libavutil/hwcontext_amf.c | 6 ++- libavutil/hwcontext_amf.h | 2 + 3 files changed, 11 insertions(+), 90 deletions(-) diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c index f363192000..2174c5bdb2 100644 --- a/libavcodec/amfenc.c +++ b/libavcodec/amfenc.c @@ -381,89 +381,6 @@ 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; @@ -643,14 +560,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; - 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); + AMFEncoderContext *ctx = avctx->priv_data; + 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); 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 20b9296e34..acd9627c68 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 AMF_SURFACE_UNKNOWN; + return AV_PIX_FMT_NONE; } static const enum AVPixelFormat supported_formats[] = { @@ -378,6 +378,7 @@ 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) @@ -414,7 +415,8 @@ static int amf_device_init(AVHWDeviceContext *ctx) } } #endif - return 0; + ff_mutex_init(&amf_ctx->mutex, NULL); + 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 8823190697..5b726e3b9e 100644 --- a/libavutil/hwcontext_amf.h +++ b/libavutil/hwcontext_amf.h @@ -26,6 +26,7 @@ #include #include #include +#include "thread.h" /** * This struct is allocated as AVHWDeviceContext.hwctx @@ -38,6 +39,7 @@ 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