| @@ -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 | |
| | 87 | static 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 | |
| 87 | static void finish_stream(SyncQueue *sq, unsigned int stream_idx) | 107 | static 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 | |
| 378 | void 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 | | | |
| 393 | void sq_limit_frames(SyncQueue *sq, unsigned int stream_idx, uint64_t frames) | 398 | void sq_limit_frames(SyncQueue *sq, unsigned int stream_idx, uint64_t frames) |
| 394 | { | 399 | { |
| 395 | SyncQueueStream *st; | 400 | SyncQueueStream *st; |