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 6B3C44BCDD for ; Tue, 30 Sep 2025 11:22:57 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'9/ho6fWalOqB3yJosPYQ92oqtLTcEgeUShrLlHlV6/I=', expected b'Dn6N97gxqZ5uH070BISAPr5GQ0X0MULAYqz/X720zZM=')) 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=1759231364; 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=9/ho6fWalOqB3yJosPYQ92oqtLTcEgeUShrLlHlV6/I=; b=D3gB1wPnekZm3U42fTIVjdgdJFUh2HSu0Y5erRWMBhXxB0CitCsq9EgHHGIJArKOuVqgu 8W+g5QhdepK3PmhO8Bk3uQGEIaGdagAss/4L2+9ZEMoc22mWlfCwkqnWvjtMs+fM/VqjiXh Vk9s3pPueJYm/FsT64wTeO0gTAPrKJvWAD73T8qf9755jPk+UbdmBs1+RXg+gPcSw/fqgFd v+MeBFCcSwUQzkzgI6nr3c49rZYuVnuPCYMe/pU29L96Z3R2MCWDTfs+gSsxHofodhxJhqn Sy2Kosf3q/OSTiwd/4xjajV23iNWjRTO31gkNLej+Iuqm4LPvHQdzlgwUI7Q== Received: from [172.19.0.4] (unknown [172.19.0.4]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 8384B68EE07; Tue, 30 Sep 2025 14:22:44 +0300 (EEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1759231359; b=Js0MCk1D4uZKAyUouNHdByASq8uGsOVpylZrjETahrXYR+sgzp6rRY5lJtIqbA5HNSFcC ehk9pGlzCT3v0g2pVJLAut1b+zhx5sgS7xmrPdqvEQ1k0uuY+VYschUvCyG6P+b9tgOCw3t YxxAYFx/dE9/e9TkQKxq0cBBn99DfaeBXw7hUMfKmWMFT7oyHz1SY7InTlAgAtM8L1alEDV mzox11FMYo6YeZJYyekmyMu4Du+AVJGucRDqdzO8FzNoRGKyorej956aO5wVjiPTRa/WW3G Tl4VTqwkDjXNi68awoNnJzNWdjb3obFIkArCrASaPUle91l/rc84k7iM0Y+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1759231359; 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=SuvPV7ydZhoiJ5z5lzvAGPP9BO0G5e1F4jaLnyb0Z30=; b=I4LHH3IBNTA0Fv/5k1jtI//kHFODyL3Uu4D3DE4qGm8pn2ASQ2KTGNO98B67Sb1Yh4sOB arKlVqKwdV6/uXisc0qxstJFE0aUv4iIpUX3uIp0pnS/TIGemRAcojvr9Inv2TZiiDo31cn ombSM7cBQweImQ4bNtD43g22MgumqBoBTcUz+6JpOF5y6zrbKWK3BCCLTjanw/VmQfVWOiP z5fpak9FAj/a4lBzFm0gbeDtzTkPvbRcwXrImddqtKu2s72mG7eVc+Tl6As4eIFL4orZsUL eLYNWxofbl2WBIrkfMfkbvCosNa54ybmqlkgdkhmEulxwwHJ2dvAVeCorEjg== 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=1759231353; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=Dn6N97gxqZ5uH070BISAPr5GQ0X0MULAYqz/X720zZM=; b=l2PrbhNuKGkZsQa+OxnTUzQhhIrXf3uaGcVmFy0Misk/5GrUanTrMWomM14s1UAKIm6GM DvLmofloyY1kCnl0Yh+btw07Owe6H/cW+8HnK/5LhmJ3g0hSp1ASpcDcDRnzJztQc8JLLud 6f/RfSCvCtHtZLspnLCe2J6EWoUb//F7IVhW5sGo+wjixU6IJnGNmCh/3syg98ocYogJhiI Lf1h0ZNzjmQo7Te23Oz6onvNJcEybHAMHDGbBCrmmGHkSnaaLQi1FVB+I31atBdjRsIgTmP 9Egf1hBmI+HfxHnQKSn04InS3i+OzYdhvaga8PY1x2uII2rnq2QG8ctiB1Sw== Received: from 13289e625de8 (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 33A5F68ED94 for ; Tue, 30 Sep 2025 14:22:33 +0300 (EEST) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Tue, 30 Sep 2025 11:22:32 -0000 Message-ID: <175923135332.25.2250248666489226242@bf249f23a2c8> Message-ID-Hash: IH7CGGYWH2B5TXGKO5M2QEOFA6ZR6PO6 X-Message-ID-Hash: IH7CGGYWH2B5TXGKO5M2QEOFA6ZR6PO6 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] fftools/ffmpeg_sched: prevent demuxers from getting stuck (PR #20631) 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: Niklas Haas via ffmpeg-devel Cc: Niklas Haas Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #20631 opened by Niklas Haas (haasn) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20631 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20631.patch When the furthest-behind stream is being fed by a demuxer that is also feeding packets to a choked filter graph, we need to unchoke that filter graph to prevent the demuxer from getting stuck trying to write packets to the choked filter graph. This situation can also apply recursively - if the demuxer is also writing to a filtergraph that is also reading from a choked demuxer, there is a similar deadlock. Solve all such deadlocks by just brute-force recursively unchoking all nodes that can somehow prevent this demuxer from writing packets. This should normally not result in any change in behavior, unless audio/video streams are badly desynchronized, in which case it may result in extra memory usage from the too-far-ahead stream buffering packets inside the muxer. (But this is, of course, preferable to a deadlock) Fixes: https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/20611 >>From aa593acdfdb1e9285619b944781fcf92b0652865 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Sat, 27 Sep 2025 20:02:07 +0200 Subject: [PATCH] fftools/ffmpeg_sched: prevent demuxers from getting stuck When the furthest-behind stream is being fed by a demuxer that is also feeding packets to a choked filter graph, we need to unchoke that filter graph to prevent the demuxer from getting stuck trying to write packets to the choked filter graph. This situation can also apply recursively - if the demuxer is also writing to a filtergraph that is also reading from a choked demuxer, there is a similar deadlock. Solve all such deadlocks by just brute-force recursively unchoking all nodes that can somehow prevent this demuxer from writing packets. This should normally not result in any change in behavior, unless audio/video streams are badly desynchronized, in which case it may result in extra memory usage from the too-far-ahead stream buffering packets inside the muxer. (But this is, of course, preferable to a deadlock) Fixes: https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/20611 --- fftools/ffmpeg_sched.c | 47 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/fftools/ffmpeg_sched.c b/fftools/ffmpeg_sched.c index d08f4a061d..20daa0b3e2 100644 --- a/fftools/ffmpeg_sched.c +++ b/fftools/ffmpeg_sched.c @@ -1262,14 +1262,59 @@ int sch_mux_sub_heartbeat_add(Scheduler *sch, unsigned mux_idx, unsigned stream_ return 0; } +static void unchoke_for_stream(Scheduler *sch, SchedulerNode src); + +// Unchoke any filter graphs that are downstream of this node, to prevent it +// from getting stuck trying to push data to a full queue +static void unchoke_downstream(Scheduler *sch, SchedulerNode *dst) +{ + SchFilterGraph *fg; + SchDec *dec; + SchEnc *enc; + switch (dst->type) { + case SCH_NODE_TYPE_DEC: + dec = &sch->dec[dst->idx]; + for (int i = 0; i < dec->nb_outputs; i++) + unchoke_downstream(sch, dec->outputs[i].dst); + break; + case SCH_NODE_TYPE_ENC: + enc = &sch->enc[dst->idx]; + for (int i = 0; i < enc->nb_dst; i++) + unchoke_downstream(sch, &enc->dst[i]); + break; + case SCH_NODE_TYPE_MUX: + // muxers are never choked + break; + case SCH_NODE_TYPE_FILTER_IN: + fg = &sch->filters[dst->idx]; + if (fg->best_input == fg->nb_inputs) { + fg->waiter.choked_next = 0; + } else { + // ensure that this filter graph is not stuck waiting for + // input from a different upstream demuxer + unchoke_for_stream(sch, fg->inputs[fg->best_input].src); + } + break; + default: + av_unreachable("Invalid destination node type?"); + break; + } +} + static void unchoke_for_stream(Scheduler *sch, SchedulerNode src) { while (1) { SchFilterGraph *fg; + SchDemux *demux; switch (src.type) { case SCH_NODE_TYPE_DEMUX: // fed directly by a demuxer (i.e. not through a filtergraph) - sch->demux[src.idx].waiter.choked_next = 0; + demux = &sch->demux[src.idx]; + if (demux->waiter.choked_next == 0) + return; // prevent infinite loop + demux->waiter.choked_next = 0; + for (int i = 0; i < demux->nb_streams; i++) + unchoke_downstream(sch, demux->streams[i].dst); return; case SCH_NODE_TYPE_DEC: src = sch->dec[src.idx].src; -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org