Remove now-unused objpool.
Showing the changes to fftools/sync_queue.c (1 of 4 files). Show all
Unified · Split
| @@ -20,16 +20,15 @@ · 19 unmodified lines | ||
| 20 | 20 | #include <string.h> |
| 21 | 21 | |
| 22 | 22 | #include "libavutil/avassert.h" |
| 23 | +#include "libavutil/container_fifo.h" | |
| 23 | 24 | #include "libavutil/channel_layout.h" |
| 24 | 25 | #include "libavutil/cpu.h" |
| 25 | 26 | #include "libavutil/error.h" |
| 26 | −#include "libavutil/fifo.h" | |
| 27 | 27 | #include "libavutil/mathematics.h" |
| 28 | 28 | #include "libavutil/mem.h" |
| 29 | 29 | #include "libavutil/samplefmt.h" |
| 30 | 30 | #include "libavutil/timestamp.h" |
| 31 | 31 | |
| 32 | −#include "objpool.h" | |
| 33 | 32 | #include "sync_queue.h" |
| 34 | 33 | |
| 35 | 34 | /* |
| @@ -67,8 +66,11 @@ · 31 unmodified lines | ||
| 67 | 66 | * frame from stream 1, and all 4 frames from stream 2. |
| 68 | 67 | */ |
| 69 | 68 | |
| 69 | +#define SQPTR(sq, frame) ((sq->type == SYNC_QUEUE_FRAMES) ? \ | |
| 70 | + (void*)frame.f : (void*)frame.p) | |
| 71 | + | |
| 70 | 72 | typedef struct SyncQueueStream { |
| 71 | − AVFifo *fifo; | |
| 73 | + AVContainerFifo *fifo; | |
| 72 | 74 | AVRational tb; |
| 73 | 75 | |
| 74 | 76 | /* number of audio samples in fifo */ |
| @@ -104,23 +106,11 @@ struct SyncQueue { · 29 unmodified lines | ||
| 104 | 106 | SyncQueueStream *streams; |
| 105 | 107 | unsigned int nb_streams; |
| 106 | 108 | |
| 107 | − // pool of preallocated frames to avoid constant allocations | |
| 108 | − ObjPool *pool; | |
| 109 | − | |
| 110 | 109 | int have_limiting; |
| 111 | 110 | |
| 112 | 111 | uintptr_t align_mask; |
| 113 | 112 | }; |
| 114 | 113 | |
| 115 | −static void frame_move(const SyncQueue *sq, SyncQueueFrame dst, | |
| 116 | − SyncQueueFrame src) | |
| 117 | −{ | |
| 118 | − if (sq->type == SYNC_QUEUE_PACKETS) | |
| 119 | − av_packet_move_ref(dst.p, src.p); | |
| 120 | − else | |
| 121 | − av_frame_move_ref(dst.f, src.f); | |
| 122 | −} | |
| 123 | − | |
| 124 | 114 | /** |
| 125 | 115 | * Compute the end timestamp of a frame. If nb_samples is provided, consider |
| 126 | 116 | * the frame to have this number of audio samples, otherwise use frame duration. |
| @@ -160,7 +150,7 @@ static void tb_update(const SyncQueue *sq, SyncQueueStream *st, · 33 unmodified lines | ||
| 160 | 150 | return; |
| 161 | 151 | |
| 162 | 152 | // timebase should not change after the first frame |
| 163 | − av_assert0(!av_fifo_can_read(st->fifo)); | |
| 153 | + av_assert0(!av_container_fifo_can_read(st->fifo)); | |
| 164 | 154 | |
| 165 | 155 | if (st->head_ts != AV_NOPTS_VALUE) |
| 166 | 156 | st->head_ts = av_rescale_q(st->head_ts, st->tb, tb); |
| @@ -308,7 +298,7 @@ static int overflow_heartbeat(SyncQueue *sq, int stream_idx) · 141 unmodified lines | ||
| 308 | 298 | |
| 309 | 299 | /* get the chosen stream's tail timestamp */ |
| 310 | 300 | for (size_t i = 0; tail_ts == AV_NOPTS_VALUE && |
| 311 | − av_fifo_peek(st->fifo, &frame, 1, i) >= 0; i++) | |
| 301 | + av_container_fifo_peek(st->fifo, (void**)&frame, i) >= 0; i++) | |
| 312 | 302 | tail_ts = frame_end(sq, frame, 0); |
| 313 | 303 | |
| 314 | 304 | /* overflow triggers when the tail is over specified duration behind the head */ |
| @@ -343,7 +333,6 @@ static int overflow_heartbeat(SyncQueue *sq, int stream_idx) · 28 unmodified lines | ||
| 343 | 333 | int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame) |
| 344 | 334 | { |
| 345 | 335 | SyncQueueStream *st; |
| 346 | − SyncQueueFrame dst; | |
| 347 | 336 | int64_t ts; |
| 348 | 337 | int ret, nb_samples; |
| 349 | 338 | |
| @@ -360,31 +349,22 @@ int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame) · 10 unmodified lines | ||
| 360 | 349 | |
| 361 | 350 | tb_update(sq, st, frame); |
| 362 | 351 | |
| 363 | − ret = objpool_get(sq->pool, (void**)&dst); | |
| 364 | − if (ret < 0) | |
| 365 | − return ret; | |
| 366 | − | |
| 367 | − frame_move(sq, dst, frame); | |
| 368 | − | |
| 369 | − nb_samples = frame_samples(sq, dst); | |
| 352 | + nb_samples = frame_samples(sq, frame); | |
| 370 | 353 | // make sure frame duration is consistent with sample count |
| 371 | 354 | if (nb_samples) { |
| 372 | − av_assert0(dst.f->sample_rate > 0); | |
| 373 | − dst.f->duration = av_rescale_q(nb_samples, (AVRational){ 1, dst.f->sample_rate }, | |
| 374 | − dst.f->time_base); | |
| 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); | |
| 375 | 358 | } |
| 376 | 359 | |
| 377 | − ts = frame_end(sq, dst, 0); | |
| 360 | + ts = frame_end(sq, frame, 0); | |
| 378 | 361 | |
| 379 | 362 | av_log(sq->logctx, AV_LOG_DEBUG, "sq: send %u ts %s\n", stream_idx, |
| 380 | 363 | av_ts2timestr(ts, &st->tb)); |
| 381 | 364 | |
| 382 | − ret = av_fifo_write(st->fifo, &dst, 1); | |
| 383 | − if (ret < 0) { | |
| 384 | − frame_move(sq, frame, dst); | |
| 385 | − objpool_release(sq->pool, (void**)&dst); | |
| 365 | + ret = av_container_fifo_write(st->fifo, SQPTR(sq, frame), 0); | |
| 366 | + if (ret < 0) | |
| 386 | 367 | return ret; |
| 387 | − } | |
| 388 | 368 | |
| 389 | 369 | stream_update_ts(sq, stream_idx, ts); |
| 390 | 370 | |
| @@ -453,7 +433,7 @@ static int receive_samples(SyncQueue *sq, SyncQueueStream *st, · 62 unmodified lines | ||
| 453 | 433 | |
| 454 | 434 | av_assert0(st->samples_queued >= nb_samples); |
| 455 | 435 | |
| 456 | − ret = av_fifo_peek(st->fifo, &src, 1, 0); | |
| 436 | + ret = av_container_fifo_peek(st->fifo, (void**)&src, 0); | |
| 457 | 437 | av_assert0(ret >= 0); |
| 458 | 438 | |
| 459 | 439 | // peeked frame has enough samples and its data is aligned |
| @@ -490,7 +470,7 @@ static int receive_samples(SyncQueue *sq, SyncQueueStream *st, · 30 unmodified lines | ||
| 490 | 470 | while (dst->nb_samples < nb_samples) { |
| 491 | 471 | int to_copy; |
| 492 | 472 | |
| 493 | − ret = av_fifo_peek(st->fifo, &src, 1, 0); | |
| 473 | + ret = av_container_fifo_peek(st->fifo, (void**)&src, 0); | |
| 494 | 474 | av_assert0(ret >= 0); |
| 495 | 475 | |
| 496 | 476 | to_copy = FFMIN(nb_samples - dst->nb_samples, src.f->nb_samples); |
| @@ -500,11 +480,9 @@ static int receive_samples(SyncQueue *sq, SyncQueueStream *st, · 3 unmodified lines | ||
| 500 | 480 | |
| 501 | 481 | if (to_copy < src.f->nb_samples) |
| 502 | 482 | offset_audio(src.f, to_copy); |
| 503 | − else { | |
| 504 | − av_frame_unref(src.f); | |
| 505 | − objpool_release(sq->pool, (void**)&src); | |
| 506 | − av_fifo_drain2(st->fifo, 1); | |
| 507 | − } | |
| 483 | + else | |
| 484 | + av_container_fifo_drain(st->fifo, 1); | |
| 485 | + | |
| 508 | 486 | st->samples_queued -= to_copy; |
| 509 | 487 | |
| 510 | 488 | dst->nb_samples += to_copy; |
| @@ -531,7 +509,7 @@ static int receive_for_stream(SyncQueue *sq, unsigned int stream_idx, · 20 unmodified lines | ||
| 531 | 509 | av_assert0(stream_idx < sq->nb_streams); |
| 532 | 510 | st = &sq->streams[stream_idx]; |
| 533 | 511 | |
| 534 | − if (av_fifo_can_read(st->fifo) && | |
| 512 | + if (av_container_fifo_can_read(st->fifo) && | |
| 535 | 513 | (st->frame_samples <= st->samples_queued || st->finished)) { |
| 536 | 514 | int nb_samples = st->frame_samples; |
| 537 | 515 | SyncQueueFrame peek; |
| @@ -541,7 +519,7 @@ static int receive_for_stream(SyncQueue *sq, unsigned int stream_idx, · 3 unmodified lines | ||
| 541 | 519 | if (st->finished) |
| 542 | 520 | nb_samples = FFMIN(nb_samples, st->samples_queued); |
| 543 | 521 | |
| 544 | − av_fifo_peek(st->fifo, &peek, 1, 0); | |
| 522 | + av_container_fifo_peek(st->fifo, (void**)&peek, 0); | |
| 545 | 523 | ts = frame_end(sq, peek, nb_samples); |
| 546 | 524 | |
| 547 | 525 | /* check if this stream's tail timestamp does not overtake |
| @@ -560,9 +538,9 @@ static int receive_for_stream(SyncQueue *sq, unsigned int stream_idx, · 12 unmodified lines | ||
| 560 | 538 | if (ret < 0) |
| 561 | 539 | return ret; |
| 562 | 540 | } else { |
| 563 | − frame_move(sq, frame, peek); | |
| 564 | − objpool_release(sq->pool, (void**)&peek); | |
| 565 | − av_fifo_drain2(st->fifo, 1); | |
| 541 | + int ret = av_container_fifo_read(st->fifo, SQPTR(sq, frame), 0); | |
| 542 | + av_assert0(ret >= 0); | |
| 543 | + | |
| 566 | 544 | av_assert0(st->samples_queued >= frame_samples(sq, frame)); |
| 567 | 545 | st->samples_queued -= frame_samples(sq, frame); |
| 568 | 546 | } |
| @@ -577,7 +555,7 @@ static int receive_for_stream(SyncQueue *sq, unsigned int stream_idx, · 8 unmodified lines | ||
| 577 | 555 | } |
| 578 | 556 | } |
| 579 | 557 | |
| 580 | − return (sq->finished || (st->finished && !av_fifo_can_read(st->fifo))) ? | |
| 558 | + return (sq->finished || (st->finished && !av_container_fifo_can_read(st->fifo))) ? | |
| 581 | 559 | AVERROR_EOF : AVERROR(EAGAIN); |
| 582 | 560 | } |
| 583 | 561 | |
| @@ -629,7 +607,8 @@ int sq_add_stream(SyncQueue *sq, int limiting) · 45 unmodified lines | ||
| 629 | 607 | st = &sq->streams[sq->nb_streams]; |
| 630 | 608 | memset(st, 0, sizeof(*st)); |
| 631 | 609 | |
| 632 | − st->fifo = av_fifo_alloc2(1, sizeof(SyncQueueFrame), AV_FIFO_FLAG_AUTO_GROW); | |
| 610 | + st->fifo = (sq->type == SYNC_QUEUE_FRAMES) ? | |
| 611 | + av_container_fifo_alloc_avframe(0) : av_container_fifo_alloc_avpacket(0); | |
| 633 | 612 | if (!st->fifo) |
| 634 | 613 | return AVERROR(ENOMEM); |
| 635 | 614 | |
| @@ -686,13 +665,6 @@ SyncQueue *sq_alloc(enum SyncQueueType type, int64_t buf_size_us, void *logctx) · 50 unmodified lines | ||
| 686 | 665 | sq->head_stream = -1; |
| 687 | 666 | sq->head_finished_stream = -1; |
| 688 | 667 | |
| 689 | − sq->pool = (type == SYNC_QUEUE_PACKETS) ? objpool_alloc_packets() : | |
| 690 | − objpool_alloc_frames(); | |
| 691 | − if (!sq->pool) { | |
| 692 | − av_freep(&sq); | |
| 693 | − return NULL; | |
| 694 | − } | |
| 695 | − | |
| 696 | 668 | return sq; |
| 697 | 669 | } |
| 698 | 670 | |
| @@ -703,17 +675,10 @@ void sq_free(SyncQueue **psq) · 4 unmodified lines | ||
| 703 | 675 | if (!sq) |
| 704 | 676 | return; |
| 705 | 677 | |
| 706 | − for (unsigned int i = 0; i < sq->nb_streams; i++) { | |
| 707 | − SyncQueueFrame frame; | |
| 708 | − while (av_fifo_read(sq->streams[i].fifo, &frame, 1) >= 0) | |
| 709 | − objpool_release(sq->pool, (void**)&frame); | |
| 710 | − | |
| 711 | − av_fifo_freep2(&sq->streams[i].fifo); | |
| 712 | − } | |
| 678 | + for (unsigned int i = 0; i < sq->nb_streams; i++) | |
| 679 | + av_container_fifo_free(&sq->streams[i].fifo); | |
| 713 | 680 | |
| 714 | 681 | av_freep(&sq->streams); |
| 715 | 682 | |
| 716 | − objpool_free(&sq->pool); | |
| 717 | − | |
| 718 | 683 | av_freep(psq); |
| 719 | 684 | } |