From patchwork Thu Feb 9 15:57:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 40342 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:5494:b0:bf:7b3a:fd32 with SMTP id i20csp580125pzk; Thu, 9 Feb 2023 07:57:36 -0800 (PST) X-Google-Smtp-Source: AK7set+GuixEHDPzoR5ItPNnXIyIxZ1aWmDE1ekXwOMXSYAdOe4bUnQufIIIK+zvwFBbbdAfK/gJ X-Received: by 2002:a17:907:86a2:b0:8af:1a8c:eaa0 with SMTP id qa34-20020a17090786a200b008af1a8ceaa0mr7310974ejc.75.1675958256086; Thu, 09 Feb 2023 07:57:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675958256; cv=none; d=google.com; s=arc-20160816; b=LJIVkgHju5Gn74LDzgPlgUXpAVoZux5Ut1g4PUk5uBr0VlCcW9FjmHRGm0GJ6OcPGP hss31eaVZdNlEuEwxusNZNnsMiQHycy8o1Kmpi/Ic5Z/X2nPt3WeVnaPbyFZQMv+E+rt uhWQXl2Cqf7ezg0GDLScup6umnjv9L9MEoNz14LZDEBYa2XDdz+gOPHkHEdYwu909Cwv hi40ob6mjV33qqrxWxPA1Lni/bTAD+NK+zKbrrPcs0R00s2vE+QxSHV6nuw/jdfnSf2l zreapWhxKWIYtnlzJqJmmUSCOHFL20cmkIxMd5d9fkEwGeq72PaN+ZVFlmtIgNK7Ul5M dSnw== 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:references:in-reply-to:message-id :date:to:from:delivered-to; bh=alPegI2PE737R8r3PvIypae8nkuimKUpAkfh79haGAM=; b=tPT69xTZq38tXUyraANCecnm2S2B8Ai+AU6ksb4oUsFPAS7lUL/U1d4OF3k+9kBEqa O90bX5tiQogpTZxKP/VaukLxz1AawU9QPHTrCmwePjW/vJwwCJuSzssqNWVIFtFUYAUf VDThKnjridmYxPLL+fypj3hQ+hGY+AZ5PJ2sgzSah+sHzapVgvMSaChNqFI9OgRwIzRH b/J6sibuq+QlhH5ynyU8aH5subNMr9VclhRc1SU657P0j8JjSTewNbo/rgrfPkqGrmNW co/55ERiMf+0SqckrdeVH/jCcBmbUkpEklsiX7fwtawVlEdOMEYfc42mfi1BKdTH+seF dh3Q== 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 gh5-20020a1709073c0500b00897d0095947si2967702ejc.156.2023.02.09.07.57.35; Thu, 09 Feb 2023 07:57:36 -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 C743868BE51; Thu, 9 Feb 2023 17:57:32 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B761C68BA18 for ; Thu, 9 Feb 2023 17:57:26 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 6F0D12404EE for ; Thu, 9 Feb 2023 16:57:26 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id dqd8PHCfCcnX for ; Thu, 9 Feb 2023 16:57:25 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id CA8452404EC for ; Thu, 9 Feb 2023 16:57:25 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 86E713A0101 for ; Thu, 9 Feb 2023 16:57:25 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Feb 2023 16:57:22 +0100 Message-Id: <20230209155722.28285-1-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] fftools/ffmpeg_mux: distinguish between sync queue and muxer 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: brlDXny0fz+R --- How about something like this? --- fftools/ffmpeg_mux.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index dffc1410c8..cf58051949 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -159,14 +159,18 @@ fail: return ret; } -static int sync_queue_process(Muxer *mux, OutputStream *ost, AVPacket *pkt) +static int sync_queue_process(Muxer *mux, OutputStream *ost, AVPacket *pkt, int *stream_eof) { OutputFile *of = &mux->of; 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) + *stream_eof = 1; + return ret; + } while (1) { ret = sq_receive(mux->sq_mux, -1, SQPKT(mux->sq_pkt)); @@ -208,7 +212,7 @@ static void *muxer_thread(void *arg) while (1) { OutputStream *ost; - int stream_idx; + int stream_idx, stream_eof = 0; ret = tq_receive(mux->tq, &stream_idx, pkt); if (stream_idx < 0) { @@ -218,9 +222,9 @@ static void *muxer_thread(void *arg) } ost = of->streams[stream_idx]; - ret = sync_queue_process(mux, ost, ret < 0 ? NULL : pkt); + ret = sync_queue_process(mux, ost, ret < 0 ? NULL : pkt, &stream_eof); av_packet_unref(pkt); - if (ret == AVERROR_EOF) + if (ret == AVERROR_EOF && stream_eof) tq_receive_finish(mux->tq, stream_idx); else if (ret < 0) { av_log(mux, AV_LOG_ERROR, "Error muxing a packet\n");