diff mbox series

[FFmpeg-devel,04/20] fftools/ffmpeg: move closing the input file into a separate function

Message ID 20221018123701.25002-4-anton@khirnov.net
State Accepted
Commit 295848bacb120da0fbe74b7f98888c328ac8dd44
Headers show
Series [FFmpeg-devel,01/20] fftools/ffmpeg_opt: move opening input files to ffmpeg_demux.c | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Oct. 18, 2022, 12:36 p.m. UTC
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 mbox series

Patch

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)