[FFmpeg-devel] [PATCH 03/20] fftools/ffmpeg: drop init_input_threads()

Anton Khirnov anton at khirnov.net
Tue Oct 18 15:36:44 EEST 2022


Start threads implicitly when ifile_get_packet() is called. Simplifies
the demuxer API.
---
 fftools/ffmpeg.c       |  3 ---
 fftools/ffmpeg.h       |  1 -
 fftools/ffmpeg_demux.c | 24 +++++++++---------------
 3 files changed, 9 insertions(+), 19 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index ceb26145a3..aac35026bd 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3910,9 +3910,6 @@ static int transcode(void)
 
     timer_start = av_gettime_relative();
 
-    if ((ret = init_input_threads()) < 0)
-        goto fail;
-
     while (!received_sigterm) {
         int64_t cur_time= av_gettime_relative();
 
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 35410ec4a1..b60f415389 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -759,7 +759,6 @@ int ifile_open(OptionsContext *o, const char *filename);
  * - a negative error code on failure
  */
 int ifile_get_packet(InputFile *f, AVPacket **pkt);
-int init_input_threads(void);
 void free_input_threads(void);
 
 #define SPECIFIER_OPT_FMT_str  "%s"
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index f92500abf9..aaa91293c3 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -330,11 +330,10 @@ void free_input_threads(void)
         free_input_thread(i);
 }
 
-static int init_input_thread(int i)
+static int thread_start(Demuxer *d)
 {
     int ret;
-    InputFile *f = input_files[i];
-    Demuxer   *d = demuxer_from_ifile(f);
+    InputFile *f = &d->f;
 
     if (f->thread_queue_size <= 0)
         f->thread_queue_size = (nb_input_files > 1 ? 8 : 1);
@@ -377,24 +376,19 @@ fail:
     return ret;
 }
 
-int init_input_threads(void)
-{
-    int i, ret;
-
-    for (i = 0; i < nb_input_files; i++) {
-        ret = init_input_thread(i);
-        if (ret < 0)
-            return ret;
-    }
-    return 0;
-}
-
 int ifile_get_packet(InputFile *f, AVPacket **pkt)
 {
+    Demuxer *d = demuxer_from_ifile(f);
     InputStream *ist;
     DemuxMsg msg;
     int ret;
 
+    if (!f->in_thread_queue) {
+        ret = thread_start(d);
+        if (ret < 0)
+            return ret;
+    }
+
     if (f->readrate || f->rate_emu) {
         int i;
         int64_t file_start = copy_ts * (
-- 
2.35.1



More information about the ffmpeg-devel mailing list