diff mbox series

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

Message ID 20221018123701.25002-3-anton@khirnov.net
State Accepted
Commit 09cd147dccc149ae17081d6016ccb79f1afcb592
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
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 mbox series

Patch

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 * (