From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTP id 49B3943EB1
	for <ffmpegdev@gitmailbox.com>; Tue, 18 Oct 2022 12:39:34 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A263468BD83;
	Tue, 18 Oct 2022 15:38:30 +0300 (EEST)
Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D70B268BD19
 for <ffmpeg-devel@ffmpeg.org>; Tue, 18 Oct 2022 15:38:15 +0300 (EEST)
Received: from localhost (localhost [IPv6:::1])
 by mail0.khirnov.net (Postfix) with ESMTP id 5D3F82404E4
 for <ffmpeg-devel@ffmpeg.org>; Tue, 18 Oct 2022 14:38:15 +0200 (CEST)
Received: from mail0.khirnov.net ([IPv6:::1])
 by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024)
 with ESMTP id ishFz7QJdNSt for <ffmpeg-devel@ffmpeg.org>;
 Tue, 18 Oct 2022 14:38:14 +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 95F6C2404F7
 for <ffmpeg-devel@ffmpeg.org>; Tue, 18 Oct 2022 14:38:13 +0200 (CEST)
Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1])
 by libav.khirnov.net (Postfix) with ESMTP id A73FA3A13E9
 for <ffmpeg-devel@ffmpeg.org>; Tue, 18 Oct 2022 14:38:13 +0200 (CEST)
From: Anton Khirnov <anton@khirnov.net>
To: ffmpeg-devel@ffmpeg.org
Date: Tue, 18 Oct 2022 14:36:45 +0200
Message-Id: <20221018123701.25002-4-anton@khirnov.net>
X-Mailer: git-send-email 2.35.1
In-Reply-To: <20221018123701.25002-1-anton@khirnov.net>
References: <20221018123701.25002-1-anton@khirnov.net>
MIME-Version: 1.0
Subject: [FFmpeg-devel] [PATCH 04/20] fftools/ffmpeg: move closing the input
 file into a separate function
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/20221018123701.25002-4-anton@khirnov.net/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>

For now this is just closing the format context and freeing InputFile,
but will contain more in the future.
---
 fftools/ffmpeg.c       |  7 +++----
 fftools/ffmpeg.h       |  1 +
 fftools/ffmpeg_demux.c | 12 ++++++++++++
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index aac35026bd..d29d2e4e88 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -556,10 +556,9 @@ static void ffmpeg_cleanup(int ret)
         of_close(&output_files[i]);
 
     free_input_threads();
-    for (i = 0; i < nb_input_files; i++) {
-        avformat_close_input(&input_files[i]->ctx);
-        av_freep(&input_files[i]);
-    }
+    for (i = 0; i < nb_input_files; i++)
+        ifile_close(&input_files[i]);
+
     for (i = 0; i < nb_input_streams; i++) {
         InputStream *ist = input_streams[i];
 
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index b60f415389..547660d5ef 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -747,6 +747,7 @@ AVChapter * const *
 of_get_chapters(OutputFile *of, unsigned int *nb_chapters);
 
 int ifile_open(OptionsContext *o, const char *filename);
+void ifile_close(InputFile **f);
 
 /**
  * Get next input packet from the demuxer.
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index aaa91293c3..d2db0663ab 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -423,6 +423,18 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt)
     return 0;
 }
 
+void ifile_close(InputFile **pf)
+{
+    InputFile *f = *pf;
+
+    if (!f)
+        return;
+
+    avformat_close_input(&f->ctx);
+
+    av_freep(pf);
+}
+
 static const AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st,
                                      enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type)
 
-- 
2.35.1

_______________________________________________
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".