[FFmpeg-cvslog] fftools/ffmpeg: move duration/time_base from InputFile to Demuxer
Anton Khirnov
git at videolan.org
Tue Oct 25 12:16:13 EEST 2022
ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Mon Oct 17 12:49:51 2022 +0200| [541104f3a3f61eae84ea4bbc283f2e29c2cfa692] | committer: Anton Khirnov
fftools/ffmpeg: move duration/time_base from InputFile to Demuxer
They are private to the demuxer and do not need to be visible outside of
it.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=541104f3a3f61eae84ea4bbc283f2e29c2cfa692
---
fftools/ffmpeg.h | 3 ---
fftools/ffmpeg_demux.c | 30 ++++++++++++++++++------------
2 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index c0ad9a764a..d914673abe 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -441,9 +441,6 @@ typedef struct InputFile {
int eof_reached; /* true if eof reached */
int eagain; /* true if last read attempt returned EAGAIN */
int ist_index; /* index of first stream in input_streams */
- int64_t duration; /* actual duration of the longest stream in a file
- at the moment when looping happens */
- AVRational time_base; /* time base of the duration */
int64_t input_ts_offset;
int input_sync_ref;
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index d604ee2930..16663e2663 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -57,6 +57,11 @@ typedef struct Demuxer {
/* number of times input stream should be looped */
int loop;
+ /* actual duration of the longest stream in a file at the moment when
+ * looping happens */
+ int64_t duration;
+ /* time base of the duration */
+ AVRational time_base;
AVThreadMessageQueue *in_thread_queue;
int thread_queue_size;
@@ -91,7 +96,7 @@ static void report_new_stream(InputFile *file, const AVPacket *pkt)
file->nb_streams_warn = pkt->stream_index + 1;
}
-static void ifile_duration_update(InputFile *f, InputStream *ist,
+static void ifile_duration_update(Demuxer *d, InputStream *ist,
int64_t last_duration)
{
/* the total duration of the stream, max_pts - min_pts is
@@ -100,11 +105,11 @@ static void ifile_duration_update(InputFile *f, InputStream *ist,
ist->max_pts - (uint64_t)ist->min_pts < INT64_MAX - last_duration)
last_duration += ist->max_pts - ist->min_pts;
- if (!f->duration ||
- av_compare_ts(f->duration, f->time_base,
+ if (!d->duration ||
+ av_compare_ts(d->duration, d->time_base,
last_duration, ist->st->time_base) < 0) {
- f->duration = last_duration;
- f->time_base = ist->st->time_base;
+ d->duration = last_duration;
+ d->time_base = ist->st->time_base;
}
}
@@ -133,7 +138,7 @@ static int seek_to_start(Demuxer *d)
got_durations++;
ist = input_streams[ifile->ist_index + dur.stream_idx];
- ifile_duration_update(ifile, ist, dur.duration);
+ ifile_duration_update(d, ist, dur.duration);
}
} else {
for (int i = 0; i < ifile->nb_streams; i++) {
@@ -148,7 +153,7 @@ static int seek_to_start(Demuxer *d)
duration = 1;
}
- ifile_duration_update(ifile, ist, duration);
+ ifile_duration_update(d, ist, duration);
}
}
@@ -158,8 +163,9 @@ static int seek_to_start(Demuxer *d)
return ret;
}
-static void ts_fixup(InputFile *ifile, AVPacket *pkt, int *repeat_pict)
+static void ts_fixup(Demuxer *d, AVPacket *pkt, int *repeat_pict)
{
+ InputFile *ifile = &d->f;
InputStream *ist = input_streams[ifile->ist_index + pkt->stream_index];
const int64_t start_time = ifile->ctx->start_time;
int64_t duration;
@@ -202,7 +208,7 @@ static void ts_fixup(InputFile *ifile, AVPacket *pkt, int *repeat_pict)
if (pkt->dts != AV_NOPTS_VALUE)
pkt->dts *= ist->ts_scale;
- duration = av_rescale_q(ifile->duration, ifile->time_base, ist->st->time_base);
+ duration = av_rescale_q(d->duration, d->time_base, ist->st->time_base);
if (pkt->pts != AV_NOPTS_VALUE) {
pkt->pts += duration;
ist->max_pts = FFMAX(pkt->pts, ist->max_pts);
@@ -290,7 +296,7 @@ static void *input_thread(void *arg)
}
}
- ts_fixup(f, pkt, &msg.repeat_pict);
+ ts_fixup(d, pkt, &msg.repeat_pict);
msg.pkt = av_packet_alloc();
if (!msg.pkt) {
@@ -1011,8 +1017,8 @@ int ifile_open(OptionsContext *o, const char *filename)
f->rate_emu = o->rate_emu;
f->accurate_seek = o->accurate_seek;
d->loop = o->loop;
- f->duration = 0;
- f->time_base = (AVRational){ 1, 1 };
+ d->duration = 0;
+ d->time_base = (AVRational){ 1, 1 };
f->readrate = o->readrate ? o->readrate : 0.0;
if (f->readrate < 0.0f) {
More information about the ffmpeg-cvslog
mailing list