diff mbox series

[FFmpeg-devel,14/22] fftools/ffmpeg: simplify tracking -readrate start time

Message ID 20230508091738.20813-14-anton@khirnov.net
State Accepted
Commit f9657b7443f674c159f305a6033b985d034d0f3b
Headers show
Series [FFmpeg-devel,01/22] fftools/ffmpeg: consolidate InputStream.[next_]dts updates | expand

Checks

Context Check Description
andriy/configure_x86 warning Failed to apply patch

Commit Message

Anton Khirnov May 8, 2023, 9:17 a.m. UTC
There is no point in having a per-stream wallclock start time, since
they are all computed at the same instant. Keep a per-file start time
instead, initialized when the demuxer thread starts.
---
 fftools/ffmpeg.c       | 8 --------
 fftools/ffmpeg.h       | 2 --
 fftools/ffmpeg_demux.c | 6 +++++-
 3 files changed, 5 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 9cf94f2a22..40e97ad486 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1498,14 +1498,6 @@  static int transcode_init(void)
 {
     int ret = 0;
 
-    /* init framerate emulation */
-    for (int i = 0; i < nb_input_files; i++) {
-        InputFile *ifile = input_files[i];
-        if (ifile->readrate)
-            for (int j = 0; j < ifile->nb_streams; j++)
-                ifile->streams[j]->start = av_gettime_relative();
-    }
-
     /* discard unused programs */
     for (int i = 0; i < nb_input_files; i++) {
         InputFile *ifile = input_files[i];
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 7eb6301c74..d1af94590d 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -362,8 +362,6 @@  typedef struct InputStream {
 
     AVRational framerate_guessed;
 
-    int64_t       start;     /* time when read started */
-
     // pts/estimated duration of the last decoded frame
     // * in decoder timebase for video,
     // * in last_frame_tb (may change during decoding) for audio
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index d5924c05aa..1f8f3a73bd 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -88,6 +88,8 @@  typedef struct Demuxer {
     // name used for logging
     char log_name[32];
 
+    int64_t wallclock_start;
+
     /* number of times input stream should be looped */
     int loop;
     /* actual duration of the longest stream in a file at the moment when
@@ -517,7 +519,7 @@  static void readrate_sleep(Demuxer *d)
         int64_t stream_ts_offset, pts, now;
         stream_ts_offset = FFMAX(ds->first_dts != AV_NOPTS_VALUE ? ds->first_dts : 0, file_start);
         pts = av_rescale(ds->dts, 1000000, AV_TIME_BASE);
-        now = (av_gettime_relative() - ist->start) * f->readrate + stream_ts_offset;
+        now = (av_gettime_relative() - d->wallclock_start) * f->readrate + stream_ts_offset;
         if (pts - burst_until > now)
             av_usleep(pts - burst_until - now);
     }
@@ -546,6 +548,8 @@  static void *input_thread(void *arg)
 
     thread_set_name(f);
 
+    d->wallclock_start = av_gettime_relative();
+
     while (1) {
         DemuxMsg msg = { NULL };