From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 7C91F45B33 for ; Wed, 17 May 2023 10:22:04 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8896168C160; Wed, 17 May 2023 13:21:00 +0300 (EEST) 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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) { -- 2.39.2 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".