36#include "libavutil/avassert.h"
37#include "libavutil/error.h"
38#include "libavutil/fifo.h"
39#include "libavutil/mathematics.h"
40#include "libavutil/mem.h"
84 av_packet_move_ref(dst.
p, src.
p);
86 av_frame_move_ref(dst.
f, src.
f);
92 frame.
p->pts + frame.
p->duration :
93 frame.
f->pts + frame.
f->duration;
119 for (
unsigned int i = 0; i < sq->
nb_streams; i++) {
121 if (st != st1 && st1->
head_ts != AV_NOPTS_VALUE &&
128 for (
unsigned int i = 0; i < sq->
nb_streams; i++) {
140 for (
unsigned int i = 0; i < sq->
nb_streams; i++) {
150 for (
unsigned int i = 0; i < sq->
nb_streams; i++) {
154 av_compare_ts(st_other->
head_ts, st_other->
tb,
165 if (ts == AV_NOPTS_VALUE ||
194 int64_t tail_ts = AV_NOPTS_VALUE;
197 if (stream_idx < 0) {
198 int64_t ts = AV_NOPTS_VALUE;
202 if (st->
head_ts != AV_NOPTS_VALUE &&
203 (ts == AV_NOPTS_VALUE ||
204 av_compare_ts(ts, sq->
streams[stream_idx].
tb,
218 for (
size_t i = 0; tail_ts == AV_NOPTS_VALUE &&
219 av_fifo_peek(st->
fifo, &frame, 1, i) >= 0; i++)
223 if (tail_ts == AV_NOPTS_VALUE || tail_ts >= st->
head_ts ||
229 for (
unsigned int i = 0; i < sq->
nb_streams; i++) {
234 (st1->
head_ts != AV_NOPTS_VALUE &&
235 av_compare_ts(tail_ts, st->
tb, st1->
head_ts, st1->
tb) <= 0))
238 ts = av_rescale_q(tail_ts, st->
tb, st1->
tb);
239 if (st1->
head_ts != AV_NOPTS_VALUE)
240 ts = FFMAX(st1->
head_ts + 1, ts);
258 av_assert0(st->
tb.num > 0 && st->
tb.den > 0);
275 ret = av_fifo_write(st->
fifo, &dst, 1);
301 if (av_fifo_can_read(st->
fifo)) {
306 av_fifo_peek(st->
fifo, &peek, 1, 0);
311 if (ts != AV_NOPTS_VALUE && st_head)
312 cmp = av_compare_ts(ts, st->
tb, st_head->
head_ts, st_head->
tb);
317 if (cmp <= 0 || ts == AV_NOPTS_VALUE) {
320 av_fifo_drain2(st->
fifo, 1);
326 AVERROR_EOF : AVERROR(EAGAIN);
335 if (stream_idx >= 0) {
337 return (ret < 0) ? ret : stream_idx;
341 for (
unsigned int i = 0; i < sq->
nb_streams; i++) {
343 if (ret == AVERROR_EOF || ret == AVERROR(EAGAIN)) {
344 nb_eof += (ret == AVERROR_EOF);
347 return (ret < 0) ? ret : i;
350 return (nb_eof == sq->
nb_streams) ? AVERROR_EOF : AVERROR(EAGAIN);
371 return AVERROR(ENOMEM);
375 memset(st, 0,
sizeof(*st));
379 return AVERROR(ENOMEM);
384 st->
tb = (AVRational){ 1, 1 };
399 av_assert0(!av_fifo_can_read(st->
fifo));
401 if (st->
head_ts != AV_NOPTS_VALUE)
449 for (
unsigned int i = 0; i < sq->
nb_streams; i++) {
451 while (av_fifo_read(sq->
streams[i].
fifo, &frame, 1) >= 0)
SyncQueueStream * streams