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 CED8D48CCD for ; Mon, 22 Dec 2025 16:15:27 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'QE4ohgykKdD541gPUT7oo+TvbNtdJIU5OtU1yoQ1Sx8=', expected b'DJZOEyboujcGKto3TQGSBPYgU9HidkrZ33fXYX/tLXU=')) 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=1766420115; 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=QE4ohgykKdD541gPUT7oo+TvbNtdJIU5OtU1yoQ1Sx8=; b=a0g9FsV2xclF5AgDfxnakwMuFDM0Gd0NmyJGLuPFpqTgOnXlT+qfkNG+yZmFQXOeBY8eP Hhdz3UoHbQNQk0AgojqSoXayW+hkB8JVwY3ULyIV+cYUriMaOePD+rxejqRC/AZrtxydsMw I/9A0Xg8KU07WtB3w2O9BhniFtVjK6dxoloqxvL/+REhEee7dY2F5JAwM8AF28sGlp+sazB yPGhvzyqxRLcthsQEhjDijFcP5VMx6iAi+/+GuzGaIHFj4L8i5qkqRUc73xamX4A8Zrl498 NcHbytJlcXrMzFbzu9EexxA13qr9yYPphIen0TlaUT41u65gRLRYLc0e0VkA== Received: from [172.20.0.2] (unknown [172.19.0.4]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 602A2690AF4; Mon, 22 Dec 2025 18:15:15 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1766420107; b=TXveiF+jtEpcvPzurjDDp1whI4Z2oWX8bHU1sgUMbOD63mVII9uSCF5tqdpRgTpgf0XM6 aq+/x0aimlYBEaY7oznjIoHlmVoohRX+hj38gC1kJvY9NN2GDbl2UJqAARUnFKLfwMHTwHW u00ipQRMH6uGMCO6lCW8srDJW/iIzo8YS4AwA9n82BYOK3QrBOBbbANFkkY17T28ndwZYS1 DM87FV6glH/qjLDpWWa9ZtvaVPQ6wdYimsYu2iJdbsAuEytBTqJx0gyO1Wq7Tp9rJLhKH/q MQXmbobXruHszoE0H3T0qQmTRpG6hVTtMKG4KqWxcxxyzxcl8Q+rtXK0UIsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1766420107; 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=mET7Gm2Hwi6NWhxrFTOhG6eZMq4x4lHpqoHva38y3OA=; b=g3bvqTWrRbQdu8ObuCJF0hpuCQ/1LrPHFwCR43rrj3W/9ihY/QH8IoMW198SYpjPPNmQj +34fKkBLesU9t57sVscSEzh3/UkO9si+Z5GwwxEVEu1mTqKjxN80ZpdDvggqHQ7tedMDS5i UZuLMu9HoXexWkTdAnjiyIGG2tTRD+v80irFnwPzBHXXw68HhtnoU3ntaaUoAMvrISiSNAD farxqNywlLw484Z6R3edBNSp5LD8IsOPAIkdvTStFlVnhISIMotLuk22FTvyp1OZQLIE5fV fnM7POsVD61otfRQfPpCiZazL01G232ibPSykAWRFYs1YeHlVaMTLok1g0Lw== 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=1766420099; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=DJZOEyboujcGKto3TQGSBPYgU9HidkrZ33fXYX/tLXU=; b=a2aRTbywNw5rFMkkCoq/+IxI8UcOx4V/5TzN1U0iYSttWnHloa6xIdH0etb4y4rPYji1O aYKehxbA6+qdGQC27pcqAOM2pVeXma6D4lS4D9M0mWKZa974roynCzZzaceGkTodCP9IdVO 3R9jd5yQE6X49FBA+dGAvtplRAtiUwB/WaVhJIncj7T3zduK+0buW8EMS3z7cyQsfFsghJc Rx9j1Dm3qog+8HZua/Ar6G/Qbx1jjdBEjDinBzhxXlwISKw7BnzVX2WzaAKI7Eo5p8JhGFY SzZk0G+B5n70JdGUErpG7B5PW/ceJ/B6LOQ/fU/H4Qma8Q8oNYv3eyjhFx0w== Received: from 55ca25703178 (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id D5C39690AAD for ; Mon, 22 Dec 2025 18:14:59 +0200 (EET) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Mon, 22 Dec 2025 16:14:59 -0000 Message-ID: <176642009998.60.13340699229307041033@2cb04c0e5124> Message-ID-Hash: NPALNZ5LUTAC2TKPJ7HXHZWFP2EIJTEE X-Message-ID-Hash: NPALNZ5LUTAC2TKPJ7HXHZWFP2EIJTEE 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] avcodec/amfenc: fix async_depth deadlock with lookahead (PR #21266) 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: ArazIusubov via ffmpeg-devel Cc: ArazIusubov Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #21266 opened by ArazIusubov URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21266 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21266.patch AMF encoders may deadlock when lookahead > async_depth. Automatically adjust async_depth to lookahead + 1 to prevent hangs. >>From 699104934bf3da0e98011915374d9e5717acca60 Mon Sep 17 00:00:00 2001 From: Araz Iusubov Date: Mon, 22 Dec 2025 17:09:16 +0100 Subject: [PATCH] avcodec/amfenc: fix async_depth deadlock with lookahead AMF encoders may deadlock when lookahead > async_depth. Automatically adjust async_depth to lookahead + 1 to prevent hangs. --- libavcodec/amfenc.c | 9 +++++++++ libavcodec/amfenc_av1.c | 2 +- libavcodec/amfenc_h264.c | 2 +- libavcodec/amfenc_hevc.c | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c index b07da236c7..329ce29005 100644 --- a/libavcodec/amfenc.c +++ b/libavcodec/amfenc.c @@ -351,6 +351,15 @@ int ff_amf_encode_init(AVCodecContext *avctx) AMF_RETURN_IF_FALSE(ctx, ret == 0, ret, "Failed to create hardware device context (AMF) : %s\n", av_err2str(ret)); } + if (ctx->pa_lookahead_buffer_depth >= ctx->hwsurfaces_in_queue_max) { + av_log(avctx, AV_LOG_WARNING, + "async_depth (%d) too small for lookahead (%d), increasing to (%d)\n", + ctx->hwsurfaces_in_queue_max, + ctx->pa_lookahead_buffer_depth, + ctx->pa_lookahead_buffer_depth + 1); + ctx->hwsurfaces_in_queue_max = ctx->pa_lookahead_buffer_depth + 1; + } + if ((ret = amf_init_encoder(avctx)) == 0) { return 0; } diff --git a/libavcodec/amfenc_av1.c b/libavcodec/amfenc_av1.c index 7202e0fcd5..70642a6b54 100644 --- a/libavcodec/amfenc_av1.c +++ b/libavcodec/amfenc_av1.c @@ -101,7 +101,7 @@ static const AVOption options[] = { { "gop", "", 0, AV_OPT_TYPE_CONST, {.i64 = AMF_VIDEO_ENCODER_AV1_HEADER_INSERTION_MODE_GOP_ALIGNED }, 0, 0, VE, .unit = "hdrmode" }, { "frame", "", 0, AV_OPT_TYPE_CONST, {.i64 = AMF_VIDEO_ENCODER_AV1_HEADER_INSERTION_MODE_KEY_FRAME_ALIGNED }, 0, 0, VE, .unit = "hdrmode" }, - { "async_depth", "Set maximum encoding parallelism. Higher values increase output latency.", OFFSET(hwsurfaces_in_queue_max), AV_OPT_TYPE_INT, {.i64 = 16 }, 1, 16, VE }, + { "async_depth", "Set maximum encoding parallelism. Higher values increase output latency.", OFFSET(hwsurfaces_in_queue_max), AV_OPT_TYPE_INT, {.i64 = 16 }, 1, MAX_LOOKAHEAD_DEPTH + 1, VE }, { "preencode", "Enable preencode", OFFSET(preencode), AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1, VE}, { "enforce_hrd", "Enforce HRD", OFFSET(enforce_hrd), AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1, VE}, diff --git a/libavcodec/amfenc_h264.c b/libavcodec/amfenc_h264.c index 131ba871f5..c39a65aead 100644 --- a/libavcodec/amfenc_h264.c +++ b/libavcodec/amfenc_h264.c @@ -111,7 +111,7 @@ static const AVOption options[] = { { "header_spacing", "Header Insertion Spacing", OFFSET(header_spacing), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1000, VE }, /// Maximum queued frames - { "async_depth", "Set maximum encoding parallelism. Higher values increase output latency.", OFFSET(hwsurfaces_in_queue_max), AV_OPT_TYPE_INT, {.i64 = 16 }, 1, 16, VE }, + { "async_depth", "Set maximum encoding parallelism. Higher values increase output latency.", OFFSET(hwsurfaces_in_queue_max), AV_OPT_TYPE_INT, {.i64 = 16 }, 1, MAX_LOOKAHEAD_DEPTH + 1, VE }, /// B-Frames // BPicturesPattern=bf diff --git a/libavcodec/amfenc_hevc.c b/libavcodec/amfenc_hevc.c index 73c555db38..fe1d948c92 100644 --- a/libavcodec/amfenc_hevc.c +++ b/libavcodec/amfenc_hevc.c @@ -87,7 +87,7 @@ static const AVOption options[] = { { "gop", "", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_ENCODER_HEVC_HEADER_INSERTION_MODE_GOP_ALIGNED }, 0, 0, VE, .unit = "hdrmode" }, { "idr", "", 0, AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_ENCODER_HEVC_HEADER_INSERTION_MODE_IDR_ALIGNED }, 0, 0, VE, .unit = "hdrmode" }, - { "async_depth", "Set maximum encoding parallelism. Higher values increase output latency.", OFFSET(hwsurfaces_in_queue_max), AV_OPT_TYPE_INT, {.i64 = 16 }, 1, 16, VE }, + { "async_depth", "Set maximum encoding parallelism. Higher values increase output latency.", OFFSET(hwsurfaces_in_queue_max), AV_OPT_TYPE_INT, {.i64 = 16 }, 1, MAX_LOOKAHEAD_DEPTH + 1, VE }, { "high_motion_quality_boost_enable", "Enable High motion quality boost mode", OFFSET(hw_high_motion_quality_boost), AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1, VE }, { "gops_per_idr", "GOPs per IDR 0-no IDR will be inserted", OFFSET(gops_per_idr), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, INT_MAX, VE }, -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org