History

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.

Anton Khirnov committed 3 years ago

Commit 090950f1 parent 87e9f5a4 files · +22 −29Browse files

Unified · Split

4 files
  1. fftools/ffmpeg.c +0 −3
  2. fftools/ffmpeg_mux.c +0 −3
  3. fftools/sync_queue.c +22 −17
  4. fftools/sync_queue.h +0 −6
fftools/ffmpeg.c+0−3
@@ -3194,9 +3194,6 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame) · 3193 unmodified lines
3194 if (ost->bitexact)3194 if (ost->bitexact)
3195 enc_ctx->flags |= AV_CODEC_FLAG_BITEXACT;3195 enc_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
3196 3196
3197 if (ost->sq_idx_encode >= 0)
3198 sq_set_tb(of->sq_encode, ost->sq_idx_encode, enc_ctx->time_base);
3199
3200 ost->mux_timebase = enc_ctx->time_base;3197 ost->mux_timebase = enc_ctx->time_base;
3201 3198
3202 return 0;3199 return 0;
fftools/ffmpeg_mux.c+0−3
@@ -586,9 +586,6 @@ int of_stream_init(OutputFile *of, OutputStream *ost) · 585 unmodified lines
586 MuxStream *ms = ms_from_ost(ost);586 MuxStream *ms = ms_from_ost(ost);
587 int ret;587 int ret;
588 588
589 if (ost->sq_idx_mux >= 0)
590 sq_set_tb(mux->sq_mux, ost->sq_idx_mux, ost->mux_timebase);
591
592 /* initialize bitstream filters for the output stream589 /* initialize bitstream filters for the output stream
593 * needs to be done here, because the codec id for streamcopy is not590 * needs to be done here, because the codec id for streamcopy is not
594 * known until now */591 * known until now */
fftools/sync_queue.c+22−17
@@ -84,6 +84,26 @@ static int frame_null(const SyncQueue *sq, SyncQueueFrame frame) · 83 unmodified lines
84 return (sq->type == SYNC_QUEUE_PACKETS) ? (frame.p == NULL) : (frame.f == NULL);84 return (sq->type == SYNC_QUEUE_PACKETS) ? (frame.p == NULL) : (frame.f == NULL);
85}85}
86 86
87static void tb_update(const SyncQueue *sq, SyncQueueStream *st,
88 const SyncQueueFrame frame)
89{
90 AVRational tb = (sq->type == SYNC_QUEUE_PACKETS) ?
91 frame.p->time_base : frame.f->time_base;
92
93 av_assert0(tb.num > 0 && tb.den > 0);
94
95 if (tb.num == st->tb.num && tb.den == st->tb.den)
96 return;
97
98 // timebase should not change after the first frame
99 av_assert0(!av_fifo_can_read(st->fifo));
100
101 if (st->head_ts != AV_NOPTS_VALUE)
102 st->head_ts = av_rescale_q(st->head_ts, st->tb, tb);
103
104 st->tb = tb;
105}
106
87static void finish_stream(SyncQueue *sq, unsigned int stream_idx)107static void finish_stream(SyncQueue *sq, unsigned int stream_idx)
88{108{
89 SyncQueueStream *st = &sq->streams[stream_idx];109 SyncQueueStream *st = &sq->streams[stream_idx];
@@ -241,8 +261,6 @@ int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame) · 151 unmodified lines
241 av_assert0(stream_idx < sq->nb_streams);261 av_assert0(stream_idx < sq->nb_streams);
242 st = &sq->streams[stream_idx];262 st = &sq->streams[stream_idx];
243 263
244 av_assert0(st->tb.num > 0 && st->tb.den > 0);
245
246 if (frame_null(sq, frame)) {264 if (frame_null(sq, frame)) {
247 finish_stream(sq, stream_idx);265 finish_stream(sq, stream_idx);
248 return 0;266 return 0;
@@ -250,6 +268,8 @@ int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame) · 1 unmodified line
250 if (st->finished)268 if (st->finished)
251 return AVERROR_EOF;269 return AVERROR_EOF;
252 270
271 tb_update(sq, st, frame);
272
253 ret = objpool_get(sq->pool, (void**)&dst);273 ret = objpool_get(sq->pool, (void**)&dst);
254 if (ret < 0)274 if (ret < 0)
255 return ret;275 return ret;
@@ -375,21 +395,6 @@ int sq_add_stream(SyncQueue *sq, int limiting) · 119 unmodified lines
375 return sq->nb_streams++;395 return sq->nb_streams++;
376}396}
377 397
378void sq_set_tb(SyncQueue *sq, unsigned int stream_idx, AVRational tb)
379{
380 SyncQueueStream *st;
381
382 av_assert0(stream_idx < sq->nb_streams);
383 st = &sq->streams[stream_idx];
384
385 av_assert0(!av_fifo_can_read(st->fifo));
386
387 if (st->head_ts != AV_NOPTS_VALUE)
388 st->head_ts = av_rescale_q(st->head_ts, st->tb, tb);
389
390 st->tb = tb;
391}
392
393void sq_limit_frames(SyncQueue *sq, unsigned int stream_idx, uint64_t frames)398void sq_limit_frames(SyncQueue *sq, unsigned int stream_idx, uint64_t frames)
394{399{
395 SyncQueueStream *st;400 SyncQueueStream *st;
fftools/sync_queue.h+0−6
@@ -59,12 +59,6 @@ void sq_free(SyncQueue **sq); · 58 unmodified lines
59 */59 */
60int sq_add_stream(SyncQueue *sq, int limiting);60int sq_add_stream(SyncQueue *sq, int limiting);
61 61
62/**
63 * Set the timebase for the stream with index stream_idx. Should be called
64 * before sending any frames for this stream.
65 */
66void sq_set_tb(SyncQueue *sq, unsigned int stream_idx, AVRational tb);
67
68/**62/**
69 * Limit the number of output frames for stream with index stream_idx63 * Limit the number of output frames for stream with index stream_idx
70 * to max_frames.64 * to max_frames.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t