| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "media/base/audio_buffer.h" | 6 #include "media/base/audio_buffer.h" |
| 7 #include "media/base/audio_bus.h" | 7 #include "media/base/audio_bus.h" |
| 8 #include "media/base/audio_splicer.h" | 8 #include "media/base/audio_splicer.h" |
| 9 #include "media/base/audio_timestamp_helper.h" | 9 #include "media/base/audio_timestamp_helper.h" |
| 10 #include "media/base/buffers.h" | 10 #include "media/base/buffers.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 184 |
| 185 // Add some bytes to the timestamp helper so that the | 185 // Add some bytes to the timestamp helper so that the |
| 186 // next buffer starts many frames beyond the end of | 186 // next buffer starts many frames beyond the end of |
| 187 // |input_1|. This is to make sure that Reset() actually | 187 // |input_1|. This is to make sure that Reset() actually |
| 188 // clears its state and doesn't try to insert a gap. | 188 // clears its state and doesn't try to insert a gap. |
| 189 input_timestamp_helper_.AddFrames(100); | 189 input_timestamp_helper_.AddFrames(100); |
| 190 | 190 |
| 191 // Verify that a new input buffer passes through as expected. | 191 // Verify that a new input buffer passes through as expected. |
| 192 scoped_refptr<AudioBuffer> input_2 = GetNextInputBuffer(0.2f); | 192 scoped_refptr<AudioBuffer> input_2 = GetNextInputBuffer(0.2f); |
| 193 EXPECT_TRUE(AddInput(input_2)); | 193 EXPECT_TRUE(AddInput(input_2)); |
| 194 ASSERT_TRUE(splicer_.HasNextBuffer()); | |
| 195 VerifyNextBuffer(input_2); | 194 VerifyNextBuffer(input_2); |
| 196 EXPECT_FALSE(splicer_.HasNextBuffer()); | 195 EXPECT_FALSE(splicer_.HasNextBuffer()); |
| 197 } | 196 } |
| 198 | 197 |
| 199 TEST_F(AudioSplicerTest, EndOfStream) { | 198 TEST_F(AudioSplicerTest, EndOfStream) { |
| 200 scoped_refptr<AudioBuffer> input_1 = GetNextInputBuffer(0.1f); | 199 scoped_refptr<AudioBuffer> input_1 = GetNextInputBuffer(0.1f); |
| 201 scoped_refptr<AudioBuffer> input_2 = AudioBuffer::CreateEOSBuffer(); | 200 scoped_refptr<AudioBuffer> input_2 = AudioBuffer::CreateEOSBuffer(); |
| 202 scoped_refptr<AudioBuffer> input_3 = GetNextInputBuffer(0.2f); | 201 scoped_refptr<AudioBuffer> input_3 = GetNextInputBuffer(0.2f); |
| 203 EXPECT_TRUE(input_2->end_of_stream()); | 202 EXPECT_TRUE(input_2->end_of_stream()); |
| 204 | 203 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 input_timestamp_helper_.SetBaseTimestamp(input_1->timestamp()); | 325 input_timestamp_helper_.SetBaseTimestamp(input_1->timestamp()); |
| 327 input_timestamp_helper_.AddFrames(input_1->frame_count() - kOverlapSize); | 326 input_timestamp_helper_.AddFrames(input_1->frame_count() - kOverlapSize); |
| 328 | 327 |
| 329 scoped_refptr<AudioBuffer> input_2 = GetNextInputBuffer(0.2f); | 328 scoped_refptr<AudioBuffer> input_2 = GetNextInputBuffer(0.2f); |
| 330 | 329 |
| 331 EXPECT_TRUE(AddInput(input_1)); | 330 EXPECT_TRUE(AddInput(input_1)); |
| 332 EXPECT_TRUE(AddInput(input_2)); | 331 EXPECT_TRUE(AddInput(input_2)); |
| 333 | 332 |
| 334 // Verify that the first input buffer passed through unmodified. | 333 // Verify that the first input buffer passed through unmodified. |
| 335 VerifyNextBuffer(input_1); | 334 VerifyNextBuffer(input_1); |
| 335 |
| 336 ASSERT_TRUE(splicer_.HasNextBuffer()); | 336 ASSERT_TRUE(splicer_.HasNextBuffer()); |
| 337 | |
| 338 scoped_refptr<AudioBuffer> output_2 = splicer_.GetNextBuffer(); | 337 scoped_refptr<AudioBuffer> output_2 = splicer_.GetNextBuffer(); |
| 339 EXPECT_FALSE(splicer_.HasNextBuffer()); | 338 EXPECT_FALSE(splicer_.HasNextBuffer()); |
| 340 | 339 |
| 341 // Verify that the second input buffer was truncated to only contain | 340 // Verify that the second input buffer was truncated to only contain |
| 342 // the samples that are after the end of |input_1|. | 341 // the samples that are after the end of |input_1|. |
| 343 base::TimeDelta expected_timestamp = | 342 base::TimeDelta expected_timestamp = |
| 344 input_1->timestamp() + input_1->duration(); | 343 input_1->timestamp() + input_1->duration(); |
| 345 base::TimeDelta expected_duration = | 344 base::TimeDelta expected_duration = |
| 346 (input_2->timestamp() + input_2->duration()) - expected_timestamp; | 345 (input_2->timestamp() + input_2->duration()) - expected_timestamp; |
| 347 EXPECT_EQ(expected_timestamp, output_2->timestamp()); | 346 EXPECT_EQ(expected_timestamp, output_2->timestamp()); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 // |extra_pre_splice_buffer| is entirely before the splice and should be ready | 424 // |extra_pre_splice_buffer| is entirely before the splice and should be ready |
| 426 // for output. | 425 // for output. |
| 427 EXPECT_TRUE(AddInput(extra_pre_splice_buffer)); | 426 EXPECT_TRUE(AddInput(extra_pre_splice_buffer)); |
| 428 VerifyNextBuffer(extra_pre_splice_buffer); | 427 VerifyNextBuffer(extra_pre_splice_buffer); |
| 429 | 428 |
| 430 // The splicer should be internally queuing input since |overlapped_buffer| is | 429 // The splicer should be internally queuing input since |overlapped_buffer| is |
| 431 // part of the splice. | 430 // part of the splice. |
| 432 EXPECT_TRUE(AddInput(overlapped_buffer)); | 431 EXPECT_TRUE(AddInput(overlapped_buffer)); |
| 433 EXPECT_FALSE(splicer_.HasNextBuffer()); | 432 EXPECT_FALSE(splicer_.HasNextBuffer()); |
| 434 | 433 |
| 435 // Even though |overlapping_buffer| completes the splice, one extra buffer is | 434 // |overlapping_buffer| completes the splice. |
| 436 // required to confirm it's actually a splice. | 435 splicer_.SetSpliceTimestamp(kNoTimestamp()); |
| 437 EXPECT_TRUE(AddInput(overlapping_buffer)); | 436 EXPECT_TRUE(AddInput(overlapping_buffer)); |
| 438 EXPECT_FALSE(splicer_.HasNextBuffer()); | 437 ASSERT_TRUE(splicer_.HasNextBuffer()); |
| 439 | 438 |
| 440 // Add one more buffer to make sure it's passed through untouched. | 439 // Add one more buffer to make sure it's passed through untouched. |
| 441 scoped_refptr<AudioBuffer> extra_post_splice_buffer = | 440 scoped_refptr<AudioBuffer> extra_post_splice_buffer = |
| 442 GetNextInputBuffer(0.5f, kBufferSize); | 441 GetNextInputBuffer(0.5f, kBufferSize); |
| 443 EXPECT_TRUE(AddInput(extra_post_splice_buffer)); | 442 EXPECT_TRUE(AddInput(extra_post_splice_buffer)); |
| 444 | 443 |
| 445 VerifyPreSpliceOutput(overlapped_buffer, | 444 VerifyPreSpliceOutput(overlapped_buffer, |
| 446 overlapping_buffer, | 445 overlapping_buffer, |
| 447 221, | 446 221, |
| 448 base::TimeDelta::FromMicroseconds(5012)); | 447 base::TimeDelta::FromMicroseconds(5012)); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 scoped_refptr<AudioBuffer> overlapping_buffer = | 501 scoped_refptr<AudioBuffer> overlapping_buffer = |
| 503 GetNextInputBuffer(0.0f, kCrossfadeSize / 3); | 502 GetNextInputBuffer(0.0f, kCrossfadeSize / 3); |
| 504 | 503 |
| 505 // The splicer should be internally queuing input since |overlapped_buffer| is | 504 // The splicer should be internally queuing input since |overlapped_buffer| is |
| 506 // part of the splice. | 505 // part of the splice. |
| 507 EXPECT_TRUE(AddInput(overlapped_buffer)); | 506 EXPECT_TRUE(AddInput(overlapped_buffer)); |
| 508 EXPECT_FALSE(splicer_.HasNextBuffer()); | 507 EXPECT_FALSE(splicer_.HasNextBuffer()); |
| 509 | 508 |
| 510 // |overlapping_buffer| should not have enough data to complete the splice, so | 509 // |overlapping_buffer| should not have enough data to complete the splice, so |
| 511 // ensure output is not available. | 510 // ensure output is not available. |
| 511 splicer_.SetSpliceTimestamp(kNoTimestamp()); |
| 512 EXPECT_TRUE(AddInput(overlapping_buffer)); | 512 EXPECT_TRUE(AddInput(overlapping_buffer)); |
| 513 EXPECT_FALSE(splicer_.HasNextBuffer()); | 513 EXPECT_FALSE(splicer_.HasNextBuffer()); |
| 514 | 514 |
| 515 // Now add an EOS buffer which should complete the splice. | 515 // Now add an EOS buffer which should complete the splice. |
| 516 EXPECT_TRUE(AddInput(AudioBuffer::CreateEOSBuffer())); | 516 EXPECT_TRUE(AddInput(AudioBuffer::CreateEOSBuffer())); |
| 517 ASSERT_TRUE(splicer_.HasNextBuffer()); | |
| 518 | 517 |
| 519 VerifyPreSpliceOutput(overlapped_buffer, | 518 VerifyPreSpliceOutput(overlapped_buffer, |
| 520 overlapping_buffer, | 519 overlapping_buffer, |
| 521 331, | 520 331, |
| 522 base::TimeDelta::FromMicroseconds(7505)); | 521 base::TimeDelta::FromMicroseconds(7505)); |
| 523 VerifyCrossfadeOutput(overlapped_buffer, | 522 VerifyCrossfadeOutput(overlapped_buffer, |
| 524 NULL, | 523 NULL, |
| 525 overlapping_buffer, | 524 overlapping_buffer, |
| 526 0, | 525 0, |
| 527 overlapping_buffer->frame_count(), | 526 overlapping_buffer->frame_count(), |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 input_timestamp_helper_.AddFrames(overlapped_buffer->frame_count() / 2); | 560 input_timestamp_helper_.AddFrames(overlapped_buffer->frame_count() / 2); |
| 562 splicer_.SetSpliceTimestamp(input_timestamp_helper_.GetTimestamp()); | 561 splicer_.SetSpliceTimestamp(input_timestamp_helper_.GetTimestamp()); |
| 563 scoped_refptr<AudioBuffer> overlapping_buffer = | 562 scoped_refptr<AudioBuffer> overlapping_buffer = |
| 564 GetNextInputBuffer(0.0f, kCrossfadeSize * 2); | 563 GetNextInputBuffer(0.0f, kCrossfadeSize * 2); |
| 565 | 564 |
| 566 // The splicer should be internally queuing input since |overlapped_buffer| is | 565 // The splicer should be internally queuing input since |overlapped_buffer| is |
| 567 // part of the splice. | 566 // part of the splice. |
| 568 EXPECT_TRUE(AddInput(overlapped_buffer)); | 567 EXPECT_TRUE(AddInput(overlapped_buffer)); |
| 569 EXPECT_FALSE(splicer_.HasNextBuffer()); | 568 EXPECT_FALSE(splicer_.HasNextBuffer()); |
| 570 | 569 |
| 571 // Even though |overlapping_buffer| completes the splice, one extra buffer is | 570 // |overlapping_buffer| completes the splice. |
| 572 // required to confirm it's actually a splice. | 571 splicer_.SetSpliceTimestamp(kNoTimestamp()); |
| 573 EXPECT_TRUE(AddInput(overlapping_buffer)); | 572 EXPECT_TRUE(AddInput(overlapping_buffer)); |
| 574 EXPECT_FALSE(splicer_.HasNextBuffer()); | |
| 575 | |
| 576 // Add an EOS buffer to complete the splice. | |
| 577 EXPECT_TRUE(AddInput(AudioBuffer::CreateEOSBuffer())); | |
| 578 ASSERT_TRUE(splicer_.HasNextBuffer()); | |
| 579 | 573 |
| 580 const int kExpectedPreSpliceSize = 55; | 574 const int kExpectedPreSpliceSize = 55; |
| 581 const base::TimeDelta kExpectedPreSpliceDuration = | 575 const base::TimeDelta kExpectedPreSpliceDuration = |
| 582 base::TimeDelta::FromMicroseconds(1247); | 576 base::TimeDelta::FromMicroseconds(1247); |
| 583 VerifyPreSpliceOutput(overlapped_buffer, | 577 VerifyPreSpliceOutput(overlapped_buffer, |
| 584 overlapping_buffer, | 578 overlapping_buffer, |
| 585 kExpectedPreSpliceSize, | 579 kExpectedPreSpliceSize, |
| 586 kExpectedPreSpliceDuration); | 580 kExpectedPreSpliceDuration); |
| 587 VerifyCrossfadeOutput(overlapped_buffer, | 581 VerifyCrossfadeOutput(overlapped_buffer, |
| 588 NULL, | 582 NULL, |
| 589 overlapping_buffer, | 583 overlapping_buffer, |
| 590 0, | 584 0, |
| 591 kExpectedPreSpliceSize, | 585 kExpectedPreSpliceSize, |
| 592 kExpectedPreSpliceDuration); | 586 kExpectedPreSpliceDuration); |
| 593 | 587 |
| 594 // Retrieve the remaining portion after crossfade. | 588 // Retrieve the remaining portion after crossfade. |
| 595 ASSERT_TRUE(splicer_.HasNextBuffer()); | 589 ASSERT_TRUE(splicer_.HasNextBuffer()); |
| 596 scoped_refptr<AudioBuffer> post_splice_output = splicer_.GetNextBuffer(); | 590 scoped_refptr<AudioBuffer> post_splice_output = splicer_.GetNextBuffer(); |
| 597 EXPECT_EQ(overlapping_buffer->timestamp() + kExpectedPreSpliceDuration, | 591 EXPECT_EQ(overlapping_buffer->timestamp() + kExpectedPreSpliceDuration, |
| 598 post_splice_output->timestamp()); | 592 post_splice_output->timestamp()); |
| 599 EXPECT_EQ(overlapping_buffer->frame_count() - kExpectedPreSpliceSize, | 593 EXPECT_EQ(overlapping_buffer->frame_count() - kExpectedPreSpliceSize, |
| 600 post_splice_output->frame_count()); | 594 post_splice_output->frame_count()); |
| 601 EXPECT_EQ(overlapping_buffer->duration() - kExpectedPreSpliceDuration, | 595 EXPECT_EQ(overlapping_buffer->duration() - kExpectedPreSpliceDuration, |
| 602 post_splice_output->duration()); | 596 post_splice_output->duration()); |
| 603 | 597 |
| 604 EXPECT_TRUE(VerifyData(post_splice_output, GetValue(overlapping_buffer))); | 598 EXPECT_TRUE(VerifyData(post_splice_output, GetValue(overlapping_buffer))); |
| 605 | |
| 606 post_splice_output = splicer_.GetNextBuffer(); | |
| 607 EXPECT_TRUE(post_splice_output->end_of_stream()); | |
| 608 | |
| 609 EXPECT_FALSE(splicer_.HasNextBuffer()); | 599 EXPECT_FALSE(splicer_.HasNextBuffer()); |
| 610 } | 600 } |
| 611 | 601 |
| 612 // Test behavior when a splice frame is incorrectly marked and does not actually | 602 // Test behavior when a splice frame is incorrectly marked and does not actually |
| 613 // overlap. | 603 // overlap. |
| 614 // +----------+ | 604 // +----------+ |
| 615 // |1111111111| | 605 // |1111111111| |
| 616 // +----------+ | 606 // +----------+ |
| 617 // +--------------+ | 607 // +--------------+ |
| 618 // |22222222222222| | 608 // |22222222222222| |
| (...skipping 16 matching lines...) Expand all Loading... |
| 635 scoped_refptr<AudioBuffer> second_buffer = | 625 scoped_refptr<AudioBuffer> second_buffer = |
| 636 GetNextInputBuffer(0.0f, kBufferSize); | 626 GetNextInputBuffer(0.0f, kBufferSize); |
| 637 | 627 |
| 638 // The splicer should be internally queuing input since |first_buffer| is part | 628 // The splicer should be internally queuing input since |first_buffer| is part |
| 639 // of the supposed splice. | 629 // of the supposed splice. |
| 640 EXPECT_TRUE(AddInput(first_buffer)); | 630 EXPECT_TRUE(AddInput(first_buffer)); |
| 641 EXPECT_FALSE(splicer_.HasNextBuffer()); | 631 EXPECT_FALSE(splicer_.HasNextBuffer()); |
| 642 | 632 |
| 643 // |second_buffer| should complete the supposed splice, so ensure output is | 633 // |second_buffer| should complete the supposed splice, so ensure output is |
| 644 // now available. | 634 // now available. |
| 635 splicer_.SetSpliceTimestamp(kNoTimestamp()); |
| 645 EXPECT_TRUE(AddInput(second_buffer)); | 636 EXPECT_TRUE(AddInput(second_buffer)); |
| 646 ASSERT_TRUE(splicer_.HasNextBuffer()); | |
| 647 | 637 |
| 648 VerifyNextBuffer(first_buffer); | 638 VerifyNextBuffer(first_buffer); |
| 649 VerifyNextBuffer(second_buffer); | 639 VerifyNextBuffer(second_buffer); |
| 650 EXPECT_FALSE(splicer_.HasNextBuffer()); | 640 EXPECT_FALSE(splicer_.HasNextBuffer()); |
| 651 } | 641 } |
| 652 | 642 |
| 653 // Test behavior when a splice frame is incorrectly marked and there is a gap | 643 // Test behavior when a splice frame is incorrectly marked and there is a gap |
| 654 // between whats in the pre splice and post splice. | 644 // between whats in the pre splice and post splice. |
| 655 // +--------+ | 645 // +--------+ |
| 656 // |11111111| | 646 // |11111111| |
| (...skipping 14 matching lines...) Expand all Loading... |
| 671 GetNextInputBuffer(1.0f, kBufferSize - kGapSize); | 661 GetNextInputBuffer(1.0f, kBufferSize - kGapSize); |
| 672 scoped_refptr<AudioBuffer> gap_buffer = | 662 scoped_refptr<AudioBuffer> gap_buffer = |
| 673 GetNextInputBuffer(0.0f, kGapSize); | 663 GetNextInputBuffer(0.0f, kGapSize); |
| 674 splicer_.SetSpliceTimestamp(input_timestamp_helper_.GetTimestamp()); | 664 splicer_.SetSpliceTimestamp(input_timestamp_helper_.GetTimestamp()); |
| 675 scoped_refptr<AudioBuffer> second_buffer = | 665 scoped_refptr<AudioBuffer> second_buffer = |
| 676 GetNextInputBuffer(0.0f, kBufferSize); | 666 GetNextInputBuffer(0.0f, kBufferSize); |
| 677 | 667 |
| 678 // The splicer should pass through the first buffer since it's not part of the | 668 // The splicer should pass through the first buffer since it's not part of the |
| 679 // splice. | 669 // splice. |
| 680 EXPECT_TRUE(AddInput(first_buffer)); | 670 EXPECT_TRUE(AddInput(first_buffer)); |
| 681 EXPECT_TRUE(splicer_.HasNextBuffer()); | |
| 682 VerifyNextBuffer(first_buffer); | 671 VerifyNextBuffer(first_buffer); |
| 683 | 672 |
| 684 // Do not add |gap_buffer|. | 673 // Do not add |gap_buffer|. |
| 685 | 674 |
| 686 // |second_buffer| will trigger an exact overlap splice check. | 675 // |second_buffer| will complete the supposed splice. |
| 676 splicer_.SetSpliceTimestamp(kNoTimestamp()); |
| 687 EXPECT_TRUE(AddInput(second_buffer)); | 677 EXPECT_TRUE(AddInput(second_buffer)); |
| 688 EXPECT_FALSE(splicer_.HasNextBuffer()); | |
| 689 | |
| 690 // When the next buffer is not an exact overlap, the bad splice detection code | |
| 691 // will kick in and release the buffers. | |
| 692 EXPECT_TRUE(AddInput(AudioBuffer::CreateEOSBuffer())); | |
| 693 ASSERT_TRUE(splicer_.HasNextBuffer()); | |
| 694 | 678 |
| 695 VerifyNextBuffer(gap_buffer); | 679 VerifyNextBuffer(gap_buffer); |
| 696 VerifyNextBuffer(second_buffer); | 680 VerifyNextBuffer(second_buffer); |
| 697 scoped_refptr<AudioBuffer> eos_buffer = splicer_.GetNextBuffer(); | |
| 698 EXPECT_TRUE(eos_buffer->end_of_stream()); | |
| 699 EXPECT_FALSE(splicer_.HasNextBuffer()); | 681 EXPECT_FALSE(splicer_.HasNextBuffer()); |
| 700 } | 682 } |
| 701 | 683 |
| 702 // Test behavior when a splice frame gets fuzzed such that there is a pre splice | |
| 703 // buffer after the first which has a timestamp equal to the splice timestamp. | |
| 704 // +-----------+ | |
| 705 // |11111111111| | |
| 706 // +-----------+ | |
| 707 // +-------+ | |
| 708 // |2222222| | |
| 709 // +-------+ | |
| 710 // +--------------+ | |
| 711 // |33333333333333| | |
| 712 // +--------------+ | |
| 713 // Results in: | |
| 714 // +---------+--------------+ | |
| 715 // |111111111|xyyyyyy3333333| | |
| 716 // +---------+--------------+ | |
| 717 // Where x represents a crossfade between buffers 1 and 3; while y is a | |
| 718 // crossfade between buffers 2 and 3. | |
| 719 TEST_F(AudioSplicerTest, SpliceIncorrectlySlotted) { | |
| 720 const int kBufferSize = | |
| 721 input_timestamp_helper_.GetFramesToTarget(max_crossfade_duration()); | |
| 722 const int kOverlapSize = 2; | |
| 723 | |
| 724 scoped_refptr<AudioBuffer> buffer_1 = | |
| 725 GetNextInputBuffer(1.0f, kBufferSize + kOverlapSize); | |
| 726 input_timestamp_helper_.SetBaseTimestamp(buffer_1->timestamp()); | |
| 727 input_timestamp_helper_.AddFrames(kBufferSize); | |
| 728 | |
| 729 const base::TimeDelta splice_timestamp = | |
| 730 input_timestamp_helper_.GetTimestamp(); | |
| 731 splicer_.SetSpliceTimestamp(splice_timestamp); | |
| 732 | |
| 733 scoped_refptr<AudioBuffer> buffer_2 = GetNextInputBuffer(0.5f, kBufferSize); | |
| 734 | |
| 735 // Create an overlap buffer which is just short of the crossfade size. | |
| 736 input_timestamp_helper_.SetBaseTimestamp(splice_timestamp); | |
| 737 scoped_refptr<AudioBuffer> buffer_3 = | |
| 738 GetNextInputBuffer(0.0f, kBufferSize - kOverlapSize); | |
| 739 | |
| 740 // The splicer should be internally queuing input since |buffer_1| is part of | |
| 741 // the supposed splice. | |
| 742 EXPECT_TRUE(AddInput(buffer_1)); | |
| 743 EXPECT_FALSE(splicer_.HasNextBuffer()); | |
| 744 | |
| 745 // Adding |buffer_2| should look like a completion of the splice, but still no | |
| 746 // buffer should be handed out. | |
| 747 EXPECT_TRUE(AddInput(buffer_2)); | |
| 748 EXPECT_FALSE(splicer_.HasNextBuffer()); | |
| 749 | |
| 750 // Adding |buffer_3| should complete the splice correctly, but there is still | |
| 751 // not enough data for crossfade, so it shouldn't return yet. | |
| 752 EXPECT_TRUE(AddInput(buffer_3)); | |
| 753 EXPECT_FALSE(splicer_.HasNextBuffer()); | |
| 754 | |
| 755 // Add an EOS buffer which should trigger completion of the splice. | |
| 756 EXPECT_TRUE(AddInput(AudioBuffer::CreateEOSBuffer())); | |
| 757 ASSERT_TRUE(splicer_.HasNextBuffer()); | |
| 758 | |
| 759 const int kExpectedPreSpliceSize = kBufferSize; | |
| 760 const base::TimeDelta kExpectedPreSpliceDuration = splice_timestamp; | |
| 761 const base::TimeDelta kExpectedCrossfadeDuration = | |
| 762 base::TimeDelta::FromMicroseconds(4966); | |
| 763 VerifyPreSpliceOutput( | |
| 764 buffer_1, buffer_3, kExpectedPreSpliceSize, kExpectedPreSpliceDuration); | |
| 765 VerifyCrossfadeOutput(buffer_1, | |
| 766 buffer_2, | |
| 767 buffer_3, | |
| 768 kOverlapSize, | |
| 769 buffer_3->frame_count(), | |
| 770 kExpectedCrossfadeDuration); | |
| 771 | |
| 772 scoped_refptr<AudioBuffer> eos_buffer = splicer_.GetNextBuffer(); | |
| 773 EXPECT_TRUE(eos_buffer->end_of_stream()); | |
| 774 | |
| 775 EXPECT_FALSE(splicer_.HasNextBuffer()); | |
| 776 } | |
| 777 | |
| 778 } // namespace media | 684 } // namespace media |
| OLD | NEW |