| 331 | } |
| 332 | |
| 333 | int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame) |
| 334 | { |
| 335 | SyncQueueStream *st; |
| 336 | int64_t ts; |
| 337 | int ret, nb_samples; |
| 338 | |
| 339 | av_assert0(stream_idx < sq->nb_streams); |
| 340 | st = &sq->streams[stream_idx]; |
| 341 | |
| 342 | if (frame_null(sq, frame)) { |
| 343 | av_log(sq->logctx, AV_LOG_DEBUG, "sq: %u EOF\n", stream_idx); |
| 344 | finish_stream(sq, stream_idx); |
| 345 | return 0; |
| 346 | } |
| 347 | if (st->finished) |
| 348 | return AVERROR_EOF; |
| 349 | |
| 350 | tb_update(sq, st, frame); |
| 351 | |
| 352 | nb_samples = frame_samples(sq, frame); |
| 353 | // make sure frame duration is consistent with sample count |
| 354 | if (nb_samples) { |
| 355 | av_assert0(frame.f->sample_rate > 0); |
| 356 | frame.f->duration = av_rescale_q(nb_samples, (AVRational){ 1, frame.f->sample_rate }, |
| 357 | frame.f->time_base); |
| 358 | } |
| 359 | |
| 360 | ts = frame_end(sq, frame, 0); |
| 361 | |
| 362 | av_log(sq->logctx, AV_LOG_DEBUG, "sq: send %u ts %s\n", stream_idx, |
| 363 | av_ts2timestr(ts, &st->tb)); |
| 364 | |
| 365 | ret = av_container_fifo_write(st->fifo, SQPTR(sq, frame), 0); |
| 366 | if (ret < 0) |
| 367 | return ret; |
| 368 | |
| 369 | stream_update_ts(sq, stream_idx, ts); |
| 370 | |
| 371 | st->samples_queued += nb_samples; |
| 372 | st->samples_sent += nb_samples; |
| 373 | |
| 374 | if (st->frame_samples) |
| 375 | st->frames_sent = st->samples_sent / st->frame_samples; |
| 376 | else |
| 377 | st->frames_sent++; |
| 378 | |
| 379 | if (st->frames_sent >= st->frames_max) { |
| 380 | av_log(sq->logctx, AV_LOG_DEBUG, "sq: %u frames_max %"PRIu64" reached\n", |
| 381 | stream_idx, st->frames_max); |
| 382 | |
| 383 | finish_stream(sq, stream_idx); |
| 384 | } |
| 385 | |
| 386 | return 0; |
| 387 | } |
| 388 | |
| 389 | static void offset_audio(AVFrame *f, int nb_samples) |
| 390 | { |
no test coverage detected