From patchwork Fri May 5 09:07:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41486 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp329869pzb; Fri, 5 May 2023 02:08:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4/3iuvLWe/uOBMrHxonVjNg4JJK5zWeVhPS6WMfZo4RN5CGd1KeiyiMVBce8s1u1VVMrxh X-Received: by 2002:a17:907:97c2:b0:965:d18b:f019 with SMTP id js2-20020a17090797c200b00965d18bf019mr609027ejc.20.1683277713705; Fri, 05 May 2023 02:08:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683277713; cv=none; d=google.com; s=arc-20160816; b=cSHV4hua0AMHbEkgrtxKJTbigmkM4rNviNg4vYWXzCJJnuozNwZi/2V2jIel7GoaGH I1cK9hFXsKZYu7os6ff2CZdEF39R7BRfI5PY1IcvjW8JSmEglr4pVhc+kHgdIlH7mfO9 7HDzXrja0Ue4+Tv2O36rmBT6YZ4HyCjjR0oh3D4qJPKHeaEgCPAOaTpYJfH/cpv5xb/z Pap+lffTgtTajKX6zbJpiPY5QAlBJ9AkpCvvjlUuxUD8lWKB+JSOvLSXmjupDqrH76BB U7IxHnN3yKaJzgT5QLeG6+aylYEJQYmM6SgKX3sPzuXXIsDhOW6KvhAcgz8W7NE1mx78 8U8Q== 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=FS3sgL58S3ggr1yWjPViGwRY7W4WUjhRQRagDqxI5ms=; b=sMLqNvXEum0LoUFWggMLK+X1B7WdW5x1jwQL8SjPKX9S3UiDtYx2iHstupdeOuQRop /GuKtoJur7awuAKqcFnOaoxUWQ3OE4FE6XIgunElx/HyRXfZVCpnCFTRS/fJvQYogi7d U8mp9JH0SaaDwIllF7N++PgJFvubBiERrrXAkoReU5G/AV00lvLKkBIDTieT28S4sjXl VUSnF2Fo9z7TbZfqKrs6E0KP4hfjhSldpjNlSY0Qzr1Z7uoLeycDX8fsY99efMhBH/QQ tHJZLOLMJX1OaxH7o+Q8EfbzhKQRP+uWqxtUlo8Du6nppO+hWJZcNl3DHXkqcIazWxDt fh2Q== 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 w3-20020a170906480300b009571602ba39si914620ejq.1054.2023.05.05.02.08.32; Fri, 05 May 2023 02:08:33 -0700 (PDT) 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 EC92068C137; Fri, 5 May 2023 12:07:43 +0300 (EEST) 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 693EA68BF68 for ; Fri, 5 May 2023 12:07:36 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id E006F2404F8 for ; Fri, 5 May 2023 11:07:32 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id zuP2I5n_Lb5G for ; Fri, 5 May 2023 11:07:32 +0200 (CEST) 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 10A7E240591 for ; Fri, 5 May 2023 11:07:30 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A49C43A031B for ; Fri, 5 May 2023 11:07:29 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 May 2023 11:07:13 +0200 Message-Id: <20230505090723.24872-1-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/11] fftools/ffmpeg: merge choose_output() and got_eagain() 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: jqAYzHEsVvvY These two functions are a part of a single logical action - determining which, if any, output stream needs to be processed next. Keeping them separate is a historical artifact that obscures what is actually being done. --- fftools/ffmpeg.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 27bfc28798..8c1c5b7fec 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1683,9 +1683,11 @@ static int need_output(void) /** * Select the output stream to process. * - * @return selected output stream, or NULL if none available + * @retval 0 an output stream was selected + * @retval AVERROR(EAGAIN) need to wait until more input is available + * @retval AVERROR_EOF no more streams need output */ -static OutputStream *choose_output(void) +static int choose_output(OutputStream **post) { int64_t opts_min = INT64_MAX; OutputStream *ost_min = NULL; @@ -1704,15 +1706,19 @@ static OutputStream *choose_output(void) ost->initialized, ost->inputs_done, ost->finished); } - if (!ost->initialized && !ost->inputs_done && !ost->finished) - return ost->unavailable ? NULL : ost; - + if (!ost->initialized && !ost->inputs_done && !ost->finished) { + ost_min = ost; + break; + } if (!ost->finished && opts < opts_min) { opts_min = opts; - ost_min = ost->unavailable ? NULL : ost; + ost_min = ost; } } - return ost_min; + if (!ost_min) + return AVERROR_EOF; + *post = ost_min; + return ost_min->unavailable ? AVERROR(EAGAIN) : 0; } static void set_tty_echo(int on) @@ -1800,14 +1806,6 @@ static int check_keyboard_interaction(int64_t cur_time) return 0; } -static int got_eagain(void) -{ - for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) - if (ost->unavailable) - return 1; - return 0; -} - static void reset_eagain(void) { int i; @@ -2052,13 +2050,12 @@ static int transcode_step(void) InputStream *ist = NULL; int ret; - ost = choose_output(); - if (!ost) { - if (got_eagain()) { - reset_eagain(); - av_usleep(10000); - return 0; - } + ret = choose_output(&ost); + if (ret == AVERROR(EAGAIN)) { + reset_eagain(); + av_usleep(10000); + return 0; + } else if (ret < 0) { av_log(NULL, AV_LOG_VERBOSE, "No more inputs to read from, finishing.\n"); return AVERROR_EOF; }