| 556 | } |
| 557 | |
| 558 | static void alignStreams( sync_common_t * common, int64_t pts ) |
| 559 | { |
| 560 | int ii; |
| 561 | hb_buffer_t * buf; |
| 562 | |
| 563 | if (common->job->align_av_start) |
| 564 | { |
| 565 | int64_t first_pts = AV_NOPTS_VALUE; |
| 566 | int audio_passthru = 0; |
| 567 | |
| 568 | for (ii = 0; ii < common->stream_count; ii++) |
| 569 | { |
| 570 | sync_stream_t * stream = &common->streams[ii]; |
| 571 | |
| 572 | buf = hb_list_item(stream->in_queue, 0); |
| 573 | |
| 574 | // P-to-P encoding will pass the start point in pts. |
| 575 | // Drop any buffers that are before the start point. |
| 576 | while (buf != NULL && buf->s.start < pts) |
| 577 | { |
| 578 | hb_list_rem(stream->in_queue, buf); |
| 579 | hb_buffer_close(&buf); |
| 580 | buf = hb_list_item(stream->in_queue, 0); |
| 581 | } |
| 582 | if (buf == NULL) |
| 583 | { |
| 584 | continue; |
| 585 | } |
| 586 | if (stream->type == SYNC_TYPE_AUDIO && |
| 587 | stream->audio.audio->config.out.codec & HB_ACODEC_PASS_FLAG) |
| 588 | { |
| 589 | // Find the largest initial pts of all passthru audio streams. |
| 590 | // We can not add silence to passthru audio streams. |
| 591 | // To align with a passthru audio stream, we must drop |
| 592 | // buffers from all other streams that are before |
| 593 | // the first buffer in the passthru audio stream. |
| 594 | audio_passthru = 1; |
| 595 | if (first_pts < buf->s.start) |
| 596 | { |
| 597 | first_pts = buf->s.start; |
| 598 | } |
| 599 | } |
| 600 | else if (!audio_passthru) |
| 601 | { |
| 602 | // Find the smallest initial pts of all streams when |
| 603 | // there is *no* passthru audio. |
| 604 | // When there is no passthru audio stream, we insert |
| 605 | // silence or black buffers to fill any gaps between |
| 606 | // the start of any stream and the start of the stream |
| 607 | // with the smallest pts. |
| 608 | if (first_pts == AV_NOPTS_VALUE || first_pts > buf->s.start) |
| 609 | { |
| 610 | first_pts = buf->s.start; |
| 611 | } |
| 612 | } |
| 613 | } |
| 614 | if (first_pts != AV_NOPTS_VALUE) |
| 615 | { |
no test coverage detected