From patchwork Sat Feb 4 10:01:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gyan Doshi X-Patchwork-Id: 40246 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:5494:b0:bf:7b3a:fd32 with SMTP id i20csp1850273pzk; Sat, 4 Feb 2023 02:02:04 -0800 (PST) X-Google-Smtp-Source: AK7set+pkbsJFC8A//4PzCiIOnvCK4g49jVR4JSVlrG+6RmMWF/td4/WBP/jOhj2zLwmACAYLYao X-Received: by 2002:a17:907:cf48:b0:895:58be:94a with SMTP id uv8-20020a170907cf4800b0089558be094amr629395ejc.14.1675504924617; Sat, 04 Feb 2023 02:02:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675504924; cv=none; d=google.com; s=arc-20160816; b=F6qISCjzKLuBh2siFRFGZvSWaMxdobyJYlcRjmrXqnFj7glYrwWseRcwfV+p0ON8n2 9Ft1W3UEVrON4SQDTTvvg/k1QViwzyNr0KchFpLUVe55ta8zefGjYZGcANWg+iVwwj5X bCtJv+757TQXe9a+14Sm3Tez+hj6AK+Sebgc4ODHFSIJ/tHDeg0yMJ377jDHkNrdstk3 FnXD7f8zgrZcnLf5n6ujFKOzDkNJmmWcT0xq4oYSf0IlpmU99nP+wqFmyfiz5xzvQna2 bUrHpPpWX0fQSbZ7D89AQwSRfsLIqj9NuXihVuqI2CUdCMP75krjwERoJ9ntTVltYTd/ 3iCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=TMSoLUv6Rr0NujdUl6woRed9iYDwgfKL973aKihfj9s=; b=XbWl+EC5bqa7717ADYU8wRBGtB2UYaMLMk4He676ExqhAqD6iuoUvc1LhqSB+FhQbP LziGJNS7eemaSpEovmM0XCr/Ki8oBdH3QXSBJZyGE3n8kscy5VbtXOApANqX2/Ja0ELY ekWh4AX2UBC4dfvMy0p9oWl+TDOdmmDlHYlm3LaWXvn8GxuDTgzyH/6U7s9OJYmKq46n OOK8WM+GDJGT3GXPNUGQGJc3jKuaqD9iCZj3wN9J6J9CkrgNaXyYCve7LJT5RIBohL9e giNsfabQD/j5zlGr5rIz09Et6cdN2A8CVVfX+Vgz27gojf7mlSo6z0Vw/lx65heiUNfO FihQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y14-20020a17090668ce00b008432fa22567si6086178ejr.649.2023.02.04.02.02.04; Sat, 04 Feb 2023 02:02:04 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C57F068BE0E; Sat, 4 Feb 2023 12:02:00 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6C82E68BD45 for ; Sat, 4 Feb 2023 12:01:53 +0200 (EET) Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4P87NH04kVz9sSH for ; Sat, 4 Feb 2023 11:01:51 +0100 (CET) From: Gyan Doshi To: ffmpeg-devel@ffmpeg.org Date: Sat, 4 Feb 2023 15:31:21 +0530 Message-Id: <20230204100121.6815-1-ffmpeg@gyani.pro> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4P87NH04kVz9sSH Subject: [FFmpeg-devel] [PATCH] ffmpeg_mux: terminate stream thread queue only on sq_send EOF X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: E7b9tZlshCwd Prior to 2d924b3a630, ffmpeg would exit if any packet write failed. After the switch to threaded mode for muxing, ffmpeg only closes that OutputStream instead of closng the file. This happens because EOF returned by write_packet isn't distinguished from EOF returned by sq_send, both relayed via sync_queue_process. This breaks the abort behaviour when there are multiple streams in an output, and can leave the ffmpeg process running beyond the intended point of abortion. Fixed by marking the OutputStream as finished upon sq_send EOF and letting write_packet EOF lead to muxer termination. --- fftools/ffmpeg_mux.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 5d427b44ea..b40a2d01a7 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -160,8 +160,12 @@ static int sync_queue_process(Muxer *mux, OutputStream *ost, AVPacket *pkt) if (ost->sq_idx_mux >= 0) { int ret = sq_send(mux->sq_mux, ost->sq_idx_mux, SQPKT(pkt)); - if (ret < 0) + if (ret < 0) { + if (ret == AVERROR_EOF) + ost->finished |= ENCODER_FINISHED; return ret; + } + while (1) { ret = sq_receive(mux->sq_mux, -1, SQPKT(mux->sq_pkt)); @@ -215,7 +219,7 @@ static void *muxer_thread(void *arg) ost = of->streams[stream_idx]; ret = sync_queue_process(mux, ost, ret < 0 ? NULL : pkt); av_packet_unref(pkt); - if (ret == AVERROR_EOF) + if (ret == AVERROR_EOF && ost->finished) tq_receive_finish(mux->tq, stream_idx); else if (ret < 0) { av_log(mux, AV_LOG_ERROR, "Error muxing a packet\n");