diff mbox series

[FFmpeg-devel,24/25] fftools/ffmpeg_demux: do not store demux packet in the context

Message ID 20220803135844.16662-24-anton@khirnov.net
State Accepted
Commit 61d9f34c70039f739bebf6870547edd9655002ec
Headers show
Series [FFmpeg-devel,01/25] fftools/ffmpeg_opt: move adding attachments out of open_output_file() | 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 Aug. 3, 2022, 1:58 p.m. UTC
Its use is local to input_thread().
---
 fftools/ffmpeg.c       |  1 -
 fftools/ffmpeg.h       |  2 --
 fftools/ffmpeg_demux.c | 11 ++++++++++-
 fftools/ffmpeg_opt.c   |  3 ---
 4 files changed, 10 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 0218f330b9..a9eda3c33e 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -593,7 +593,6 @@  static void ffmpeg_cleanup(int ret)
     free_input_threads();
     for (i = 0; i < nb_input_files; i++) {
         avformat_close_input(&input_files[i]->ctx);
-        av_packet_free(&input_files[i]->pkt);
         av_freep(&input_files[i]);
     }
     for (i = 0; i < nb_input_streams; i++) {
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index aa97f35310..2ac7cbe522 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -437,8 +437,6 @@  typedef struct InputFile {
     float readrate;
     int accurate_seek;
 
-    AVPacket *pkt;
-
     AVThreadMessageQueue *in_thread_queue;
     pthread_t thread;           /* thread reading from this file */
     int non_blocking;           /* reading packets from the thread should not block */
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index be734be581..af54ea3de1 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -117,10 +117,16 @@  static int seek_to_start(InputFile *ifile)
 static void *input_thread(void *arg)
 {
     InputFile *f = arg;
-    AVPacket *pkt = f->pkt;
+    AVPacket *pkt;
     unsigned flags = f->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0;
     int ret = 0;
 
+    pkt = av_packet_alloc();
+    if (!pkt) {
+        ret = AVERROR(ENOMEM);
+        goto finish;
+    }
+
     while (1) {
         DemuxMsg msg = { NULL };
 
@@ -185,9 +191,12 @@  static void *input_thread(void *arg)
         }
     }
 
+finish:
     av_assert0(ret < 0);
     av_thread_message_queue_set_err_recv(f->in_thread_queue, ret);
 
+    av_packet_free(&pkt);
+
     return NULL;
 }
 
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 25aa9aaff5..97f14b2a5b 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1407,9 +1407,6 @@  static int open_input_file(OptionsContext *o, const char *filename)
         f->rate_emu = 0;
     }
 
-    f->pkt = av_packet_alloc();
-    if (!f->pkt)
-        exit_program(1);
     f->thread_queue_size = o->thread_queue_size;
 
     /* check if all codec options have been used */