[FFmpeg-devel] [PATCH 01/10] fftools/ffmpeg: move freeing an input stream into a separate function

Anton Khirnov anton at khirnov.net
Thu Nov 17 12:16:31 EET 2022


---
 fftools/ffmpeg.c | 41 ++++++++++++++++++++++++-----------------
 1 file changed, 24 insertions(+), 17 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index dfdfad3ce4..25155e155e 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -502,6 +502,28 @@ static int decode_interrupt_cb(void *ctx)
 
 const AVIOInterruptCB int_cb = { decode_interrupt_cb, NULL };
 
+static void ist_free(InputStream **pist)
+{
+    InputStream *ist = *pist;
+
+    if (!ist)
+        return;
+
+    av_frame_free(&ist->decoded_frame);
+    av_packet_free(&ist->pkt);
+    av_dict_free(&ist->decoder_opts);
+    avsubtitle_free(&ist->prev_sub.subtitle);
+    av_frame_free(&ist->sub2video.frame);
+    av_freep(&ist->filters);
+    av_freep(&ist->hwaccel_device);
+    av_freep(&ist->dts_buffer);
+
+    avcodec_free_context(&ist->dec_ctx);
+    avcodec_parameters_free(&ist->par);
+
+    av_freep(pist);
+}
+
 static void ffmpeg_cleanup(int ret)
 {
     int i, j;
@@ -558,23 +580,8 @@ static void ffmpeg_cleanup(int ret)
     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];
-
-        av_frame_free(&ist->decoded_frame);
-        av_packet_free(&ist->pkt);
-        av_dict_free(&ist->decoder_opts);
-        avsubtitle_free(&ist->prev_sub.subtitle);
-        av_frame_free(&ist->sub2video.frame);
-        av_freep(&ist->filters);
-        av_freep(&ist->hwaccel_device);
-        av_freep(&ist->dts_buffer);
-
-        avcodec_free_context(&ist->dec_ctx);
-        avcodec_parameters_free(&ist->par);
-
-        av_freep(&input_streams[i]);
-    }
+    for (i = 0; i < nb_input_streams; i++)
+        ist_free(&input_streams[i]);
 
     if (vstats_file) {
         if (fclose(vstats_file))
-- 
2.35.1



More information about the ffmpeg-devel mailing list