From patchwork Wed May 17 10:20:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41664 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1078383pzb; Wed, 17 May 2023 03:22:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4JDmID19FIaIYfen5U3jibnZ4wfZt0zrJB6zHuiOBWdQQ7KzdEIfIed025KwW4SHQN3yWk X-Received: by 2002:a05:6402:128d:b0:509:d476:3a12 with SMTP id w13-20020a056402128d00b00509d4763a12mr1326516edv.34.1684318927503; Wed, 17 May 2023 03:22:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684318927; cv=none; d=google.com; s=arc-20160816; b=0s8/mBgRn4W5ZncgS8Rpt6QMBAP5Vid7xyGdadjO8I6jqEci8bJKpKEc9CXP6gXkgw VccRptPEt5WjVdN2VVJJuRVqVXoZpVS0oaVobQzBljT/9aLHszXms/KZYH7RwOLUBNrm KhrNIya8Xi1bm5BK37u1dRzfBdTM5dnSid1vcGeb5U9r75iO7K8s2kkQ/bHeMsoOJ33E 9nCtxwIGwXcfq9NEVnCMYpsacslOloZiwh1jzZ9ak0xMBMcfNopxl4rC3tx9mSSo3VXQ AJJ2oLK4S7TrOsGPci/QFaELETjLODJX1zFt2977lKHH97aC8jzbEfBJeQErP5itn1gZ fe0w== 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=X4kc92iFtsm5gO+eP9Vy+9gr8FLuKtvi7iIuWqkcNP0=; b=RqotV5zVmyp3vvWbxTP0K2c0a4M3jW7zi6S2LdU7ypCVKlaB9EWeFl262jUZX/KrrD k0Jf7QGG1zWTRBCtSsZmLZoGK23qRJmo814A+gY+3GUmiv4Nt8MfJs/n7ouEHiowYLOE CVbYjrArOaGb3jNbGFQl3U6pv+lm0YO1MilZzdqLOUhWaUtF8TaUz/ffK8nfprWD7LGh SnVcuu6fh3cBSzC4HAN7XiwwjV0Q5gcUiNDJxUws5KuYgKbqCbIcVgxR2nt6A3Bn43Dz a54oJQhiN69xPPDzvB+RMnJzrchxDjkkuTQDQr+kFTTS7JyxSfPkdEkus9ozocZfvqmp R8WQ== 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 n23-20020a056402515700b0050bd245d39asi1612778edd.160.2023.05.17.03.22.06; Wed, 17 May 2023 03:22:07 -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 BE01B68C17E; Wed, 17 May 2023 13:21:00 +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 6F76568C12D for ; Wed, 17 May 2023 13:20:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 340C02406CF for ; Wed, 17 May 2023 12:20:54 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 5M9_yiwKw_XR for ; Wed, 17 May 2023 12:20:53 +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 38529240D0E for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A64573A2125 for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:21 +0200 Message-Id: <20230517102029.541-28-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 28/36] fftools/ffmpeg: split decoding loop out of process_input_packet() 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: 6PRtIbJ3zi17 process_input_packet() contains two non-interacting pieces of nontrivial size and complexity - decoding and streamcopy. Separating them makes the code easier to read. --- fftools/ffmpeg.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 4cf8b54dc0..e84add50e5 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1344,18 +1344,10 @@ static int send_filter_eof(InputStream *ist) return 0; } -/* pkt = NULL means EOF (needed to flush decoder buffers) */ -static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eof) +static int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) { - InputFile *f = input_files[ist->file_index]; - const AVCodecParameters *par = ist->par; - int64_t dts_est = AV_NOPTS_VALUE; - int ret = 0; - int repeating = 0; - int eof_reached = 0; - int duration_exceeded; - AVPacket *avpkt = ist->pkt; + int ret, repeating = 0; if (pkt) { av_packet_unref(avpkt); @@ -1365,11 +1357,11 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo } // while we have more to decode or while the decoder did output something on EOF - while (ist->decoding_needed) { + while (1) { int got_output = 0; int decode_failed = 0; - switch (par->codec_type) { + switch (ist->par->codec_type) { case AVMEDIA_TYPE_AUDIO: ret = decode_audio (ist, repeating ? NULL : avpkt, &got_output, &decode_failed); @@ -1403,8 +1395,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo } } - eof_reached = 1; - break; + return AVERROR_EOF; } if (ret < 0) { @@ -1417,16 +1408,28 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo } if (!decode_failed || exit_on_error) exit_program(1); - break; + return ret; } if (!got_output) - break; + return 0; repeating = 1; } +} + +/* pkt = NULL means EOF (needed to flush decoder buffers) */ +static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eof) +{ + InputFile *f = input_files[ist->file_index]; + int64_t dts_est = AV_NOPTS_VALUE; + int ret = 0; + int eof_reached = 0; + int duration_exceeded; - if (!pkt && !ist->decoding_needed) + if (ist->decoding_needed) + ret = dec_packet(ist, pkt, no_eof); + if (ret == AVERROR_EOF || (!pkt && !ist->decoding_needed)) eof_reached = 1; if (pkt && pkt->opaque_ref) {