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 2F61B4C7CA for ; Mon, 15 Sep 2025 22:42:01 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'qRkpNCpZVKTMseQkIHT7M7ZvTgA3KztCS6PUtwJ0W6U=', expected b'c9tl7Hw2yZV5iI2kxO8ymAgBK9grqdtjPxBXvH+4mgM=')) 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=1757976113; 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=qRkpNCpZVKTMseQkIHT7M7ZvTgA3KztCS6PUtwJ0W6U=; b=bPlanEgtFZ8357kKBG2MEihMXEiHEHuXiqdWjMClcanNkmcqMj4ioQDFFog//IVzMcyvR EbSUMv76gaRA3TWLfKnlZmx46GZkARfRqIpKi35clhN+8nK6aLgVY0hnAK1c8xAwsTloiDR wEzwgCJ8ryxmL39OBE4+3HjstQPFbgGNcIG1IDPU8U3eYprH+ZzbW4HHW0h+3KLIUnFRhDl eRHJwV5uEM7eevDWOI9Y1NzM2TmNdLuaYwX+s5agVymb3s/VJUL02+FLsWSvp4u3wbxUI3c dosfLLdk6n/XmxitYnymY7/2qzvFxNWxOq4jh7/wNjV3EAMaenhwDhOsCvQA== Received: from [172.19.0.4] (unknown [172.19.0.4]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id BCC3368E88F; Tue, 16 Sep 2025 01:41:53 +0300 (EEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1757976113; b=BurNZcmQwUdUmnnBwaFgryfguXEMZ3wUWXkIs0KlvTzKlVmhswvzlFY/dACrvkWQqjuaQ rmzm1/vz+YShGJ+K1A4Qmu7V+qLxf2pvXNeCiihjVMaTMvvVjcCfaJH476kRDacy27UqArR Zqp4tgRt2iRKx64XHEPgufOI1WPgipL+CkeCFjae+IGxXpHQMYXOa0a12hB9mzZtkkRTkoN 7PfWCt1MX4/i2W/5Oz6IqbHdZIsN4ruBCEVIa89jmeW/RJ3mP0ckpO6vkQSRCJ1T3Z60+Zy BQJhG+fOeMctbRTnIAu89sV+fW3uKlrNHNWIn560rI9ZnajN0MJZXhoqc0IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1757976113; 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=N68EoWxhu+/Zo/DnM4tqgguMX/3k/DGk2q17SK9adO0=; b=XyabbdiDuiG7GS8wDtHQb7Ch+hAmvYUh0Pdw4VPooxLYQgntWgYBhY8DN9qSkGQIn7ZHa Be2pf/ybPqYn+B72iUTgHM8sCmzNbpKypvyVc/fxrJ1LcaSN2PWmYwJ9+ueSBiiyMbGBXUd XrXSrmGSRJ+jRFNNkpXquLYp2nrIywVT68zVfgv+nr9dxX0qRCnKjFdbw9UNOM/uADiPYCW FqgdT96334Pid4w7GlYTrItTBin4u1CTJa27xEG4598xehI+5iQq36zlVUbhp/8vWbmTvKm BWQGbvGXr5zxLnkMVR2Ux/UxpCi1ELyJxXKrf/LTl9jkVpGHjdo3kSXK02gA== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none; dmarc=none Authentication-Results: ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none (Message is not ARC signed); dmarc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1757976104; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=c9tl7Hw2yZV5iI2kxO8ymAgBK9grqdtjPxBXvH+4mgM=; b=VP3vOdmQ03a1HvWMX0/opXaQzjuEybXBXPZ2BlYwUo2kk3B/r5kbjXdVIdpwez8Po6H+r b1etZjHpbf8UgO5PWpOoy6Lz61HUt+R08UQNOrwskvVYcSMnWlelcGTkKxf4xKbZfx4TL2s Yrj8yVcAsIOI18t0mTKRPN2bxxDmWNtW8Pg9fgmOZWTDtUBtWPPp1mi8UgDzPdfxogXA+Ft agtTHFGEv5rbZD0STqWLMbJavlqLCffJoMdgw9699/e/S3rJKGsHohiF1sGmYwb2nMy+l+A fXPYMNApdl7ST/hZ0R2eooTFANxGv8GorrIxXcB3V9Y5cYEPF8eSoNJee9EA== Received: from ed19c606a818 (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 6DA7468E874 for ; Tue, 16 Sep 2025 01:41:44 +0300 (EEST) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Mon, 15 Sep 2025 22:41:44 -0000 Message-ID: <175797610456.25.9960403475503736370@463a07221176> Message-ID-Hash: AJS76QQQZ3RIROM6HR3M3MERX6EPN6IQ X-Message-ID-Hash: AJS76QQQZ3RIROM6HR3M3MERX6EPN6IQ 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] avfilter/vsrc_gfxcapture: fix possible missed wakeup race in capture loop (PR #20531) 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: Timo Rothenpieler via ffmpeg-devel Cc: Timo Rothenpieler Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #20531 opened by Timo Rothenpieler (BtbN) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20531 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20531.patch There is the tiniest chance that the cond var wait function checks the predicate, but before it can enter the wait, the capture thread both updated the checked atomics and signals the cond var. In that case, the condvar would never be signaled, and an entire frame or even the closing of the captured window might be missed, and the cond var will wait until its timeout. The frame_arrived_mutex cannot be held over the process_frame_if_exists(), since it also synchronizes with the thread, so this would be a sure deadlock risk. This change moves the lock only over the condvar wait itself, and makes the callback handlers hold the lock while updating the atomic variables, eliminating the risk for a missed wakeup. I had previously thought the memory ordering of the atomics was enough to prevent this race, but there is still the off chance that it might race, however unlikely it may be. >>From e7e35207c68be1d4da584445f2e31d97b56c908f Mon Sep 17 00:00:00 2001 From: Timo Rothenpieler Date: Tue, 16 Sep 2025 00:13:46 +0200 Subject: [PATCH] avfilter/vsrc_gfxcapture: fix possible missed wakeup race in capture loop --- libavfilter/vsrc_gfxcapture_winrt.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libavfilter/vsrc_gfxcapture_winrt.cpp b/libavfilter/vsrc_gfxcapture_winrt.cpp index 6477e56918..2480aabe56 100644 --- a/libavfilter/vsrc_gfxcapture_winrt.cpp +++ b/libavfilter/vsrc_gfxcapture_winrt.cpp @@ -196,12 +196,18 @@ static HRESULT get_activation_factory(GfxCaptureContextCpp *ctx, PCWSTR clsid, T ****************************************************/ static void wgc_frame_arrived_handler(const std::unique_ptr &wgctx) { - wgctx->frame_seq.fetch_add(1, std::memory_order_release); + { + std::lock_guard lock(wgctx->frame_arrived_mutex); + wgctx->frame_seq.fetch_add(1, std::memory_order_release); + } wgctx->frame_arrived_cond.notify_one(); } static void wgc_closed_handler(const std::unique_ptr &wgctx) { - wgctx->window_closed.store(true, std::memory_order_release); + { + std::lock_guard lock(wgctx->frame_arrived_mutex); + wgctx->window_closed.store(true, std::memory_order_release); + } wgctx->frame_arrived_cond.notify_one(); } @@ -1455,8 +1461,6 @@ static int gfxcapture_activate(AVFilterContext *avctx) if (!ff_outlink_frame_wanted(outlink)) return FFERROR_NOT_READY; - std::unique_lock frame_lock(wgctx->frame_arrived_mutex); - for (;;) { uint64_t last_seq = wgctx->frame_seq.load(std::memory_order_acquire); @@ -1469,6 +1473,7 @@ static int gfxcapture_activate(AVFilterContext *avctx) break; } + std::unique_lock frame_lock(wgctx->frame_arrived_mutex); if (!wgctx->frame_arrived_cond.wait_for(frame_lock, std::chrono::seconds(1), [&]() { return wgctx->frame_seq.load(std::memory_order_acquire) != last_seq || wgctx->window_closed.load(std::memory_order_acquire); -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org