diff options
author | Anton Khirnov <anton@khirnov.net> | 2023-03-21 12:36:03 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2023-04-09 15:47:45 +0200 |
commit | 090950f8327c01b1775615b1da723dc6cc8a30a0 (patch) | |
tree | f0970c60181867c6111d71d7fd42fc60e3d5bbc7 /fftools/sync_queue.c | |
parent | 87e9f5ad3c119b1058c66bcc5747f1417e0fbddc (diff) | |
download | ffmpeg-090950f8327c01b1775615b1da723dc6cc8a30a0.tar.gz |
fftools/sync_queue: use timebase from input frames/packets
They are always properly set now. Avoid a separate timebase-setting
call, which duplicates the knowledge of the timebase being used.
Diffstat (limited to 'fftools/sync_queue.c')
-rw-r--r-- | fftools/sync_queue.c | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/fftools/sync_queue.c b/fftools/sync_queue.c index c2b23ee4f5..7c348af300 100644 --- a/fftools/sync_queue.c +++ b/fftools/sync_queue.c @@ -84,6 +84,26 @@ static int frame_null(const SyncQueue *sq, SyncQueueFrame frame) return (sq->type == SYNC_QUEUE_PACKETS) ? (frame.p == NULL) : (frame.f == NULL); } +static void tb_update(const SyncQueue *sq, SyncQueueStream *st, + const SyncQueueFrame frame) +{ + AVRational tb = (sq->type == SYNC_QUEUE_PACKETS) ? + frame.p->time_base : frame.f->time_base; + + av_assert0(tb.num > 0 && tb.den > 0); + + if (tb.num == st->tb.num && tb.den == st->tb.den) + return; + + // timebase should not change after the first frame + av_assert0(!av_fifo_can_read(st->fifo)); + + if (st->head_ts != AV_NOPTS_VALUE) + st->head_ts = av_rescale_q(st->head_ts, st->tb, tb); + + st->tb = tb; +} + static void finish_stream(SyncQueue *sq, unsigned int stream_idx) { SyncQueueStream *st = &sq->streams[stream_idx]; @@ -241,8 +261,6 @@ int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame) av_assert0(stream_idx < sq->nb_streams); st = &sq->streams[stream_idx]; - av_assert0(st->tb.num > 0 && st->tb.den > 0); - if (frame_null(sq, frame)) { finish_stream(sq, stream_idx); return 0; @@ -250,6 +268,8 @@ int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame) if (st->finished) return AVERROR_EOF; + tb_update(sq, st, frame); + ret = objpool_get(sq->pool, (void**)&dst); if (ret < 0) return ret; @@ -375,21 +395,6 @@ int sq_add_stream(SyncQueue *sq, int limiting) return sq->nb_streams++; } -void sq_set_tb(SyncQueue *sq, unsigned int stream_idx, AVRational tb) -{ - SyncQueueStream *st; - - av_assert0(stream_idx < sq->nb_streams); - st = &sq->streams[stream_idx]; - - av_assert0(!av_fifo_can_read(st->fifo)); - - if (st->head_ts != AV_NOPTS_VALUE) - st->head_ts = av_rescale_q(st->head_ts, st->tb, tb); - - st->tb = tb; -} - void sq_limit_frames(SyncQueue *sq, unsigned int stream_idx, uint64_t frames) { SyncQueueStream *st; |