Chromium Code Reviews| 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 414 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 | 425 // |extra_pre_splice_buffer| is entirely before the splice and should be ready |
| 426 // for output. | 426 // for output. |
| 427 EXPECT_TRUE(AddInput(extra_pre_splice_buffer)); | 427 EXPECT_TRUE(AddInput(extra_pre_splice_buffer)); |
| 428 VerifyNextBuffer(extra_pre_splice_buffer); | 428 VerifyNextBuffer(extra_pre_splice_buffer); |
| 429 | 429 |
| 430 // The splicer should be internally queuing input since |overlapped_buffer| is | 430 // The splicer should be internally queuing input since |overlapped_buffer| is |
| 431 // part of the splice. | 431 // part of the splice. |
| 432 EXPECT_TRUE(AddInput(overlapped_buffer)); | 432 EXPECT_TRUE(AddInput(overlapped_buffer)); |
| 433 EXPECT_FALSE(splicer_.HasNextBuffer()); | 433 EXPECT_FALSE(splicer_.HasNextBuffer()); |
| 434 | 434 |
| 435 // Even though |overlapping_buffer| completes the splice, one extra buffer is | 435 // |overlapping_buffer| completes the splice. |
| 436 // required to confirm it's actually a splice. | 436 splicer_.SetSpliceTimestamp(kNoTimestamp()); |
| 437 EXPECT_TRUE(AddInput(overlapping_buffer)); | 437 EXPECT_TRUE(AddInput(overlapping_buffer)); |
| 438 EXPECT_FALSE(splicer_.HasNextBuffer()); | 438 EXPECT_TRUE(splicer_.HasNextBuffer()); |
| 439 | 439 |
| 440 // Add one more buffer to make sure it's passed through untouched. | 440 // Add one more buffer to make sure it's passed through untouched. |
| 441 scoped_refptr<AudioBuffer> extra_post_splice_buffer = | 441 scoped_refptr<AudioBuffer> extra_post_splice_buffer = |
| 442 GetNextInputBuffer(0.5f, kBufferSize); | 442 GetNextInputBuffer(0.5f, kBufferSize); |
| 443 EXPECT_TRUE(AddInput(extra_post_splice_buffer)); | 443 EXPECT_TRUE(AddInput(extra_post_splice_buffer)); |
| 444 | 444 |
| 445 VerifyPreSpliceOutput(overlapped_buffer, | 445 VerifyPreSpliceOutput(overlapped_buffer, |
| 446 overlapping_buffer, | 446 overlapping_buffer, |
| 447 221, | 447 221, |
| 448 base::TimeDelta::FromMicroseconds(5012)); | 448 base::TimeDelta::FromMicroseconds(5012)); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 scoped_refptr<AudioBuffer> overlapping_buffer = | 502 scoped_refptr<AudioBuffer> overlapping_buffer = |
| 503 GetNextInputBuffer(0.0f, kCrossfadeSize / 3); | 503 GetNextInputBuffer(0.0f, kCrossfadeSize / 3); |
| 504 | 504 |
| 505 // The splicer should be internally queuing input since |overlapped_buffer| is | 505 // The splicer should be internally queuing input since |overlapped_buffer| is |
| 506 // part of the splice. | 506 // part of the splice. |
| 507 EXPECT_TRUE(AddInput(overlapped_buffer)); | 507 EXPECT_TRUE(AddInput(overlapped_buffer)); |
| 508 EXPECT_FALSE(splicer_.HasNextBuffer()); | 508 EXPECT_FALSE(splicer_.HasNextBuffer()); |
| 509 | 509 |
| 510 // |overlapping_buffer| should not have enough data to complete the splice, so | 510 // |overlapping_buffer| should not have enough data to complete the splice, so |
| 511 // ensure output is not available. | 511 // ensure output is not available. |
| 512 splicer_.SetSpliceTimestamp(kNoTimestamp()); | |
| 512 EXPECT_TRUE(AddInput(overlapping_buffer)); | 513 EXPECT_TRUE(AddInput(overlapping_buffer)); |
| 513 EXPECT_FALSE(splicer_.HasNextBuffer()); | 514 EXPECT_FALSE(splicer_.HasNextBuffer()); |
| 514 | 515 |
| 515 // Now add an EOS buffer which should complete the splice. | 516 // Now add an EOS buffer which should complete the splice. |
| 516 EXPECT_TRUE(AddInput(AudioBuffer::CreateEOSBuffer())); | 517 EXPECT_TRUE(AddInput(AudioBuffer::CreateEOSBuffer())); |
| 517 ASSERT_TRUE(splicer_.HasNextBuffer()); | 518 ASSERT_TRUE(splicer_.HasNextBuffer()); |
| 518 | 519 |
| 519 VerifyPreSpliceOutput(overlapped_buffer, | 520 VerifyPreSpliceOutput(overlapped_buffer, |
| 520 overlapping_buffer, | 521 overlapping_buffer, |
| 521 331, | 522 331, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 input_timestamp_helper_.AddFrames(overlapped_buffer->frame_count() / 2); | 562 input_timestamp_helper_.AddFrames(overlapped_buffer->frame_count() / 2); |
| 562 splicer_.SetSpliceTimestamp(input_timestamp_helper_.GetTimestamp()); | 563 splicer_.SetSpliceTimestamp(input_timestamp_helper_.GetTimestamp()); |
| 563 scoped_refptr<AudioBuffer> overlapping_buffer = | 564 scoped_refptr<AudioBuffer> overlapping_buffer = |
| 564 GetNextInputBuffer(0.0f, kCrossfadeSize * 2); | 565 GetNextInputBuffer(0.0f, kCrossfadeSize * 2); |
| 565 | 566 |
| 566 // The splicer should be internally queuing input since |overlapped_buffer| is | 567 // The splicer should be internally queuing input since |overlapped_buffer| is |
| 567 // part of the splice. | 568 // part of the splice. |
| 568 EXPECT_TRUE(AddInput(overlapped_buffer)); | 569 EXPECT_TRUE(AddInput(overlapped_buffer)); |
| 569 EXPECT_FALSE(splicer_.HasNextBuffer()); | 570 EXPECT_FALSE(splicer_.HasNextBuffer()); |
| 570 | 571 |
| 571 // Even though |overlapping_buffer| completes the splice, one extra buffer is | 572 // |overlapping_buffer| completes the splice. |
| 572 // required to confirm it's actually a splice. | 573 splicer_.SetSpliceTimestamp(kNoTimestamp()); |
| 573 EXPECT_TRUE(AddInput(overlapping_buffer)); | 574 EXPECT_TRUE(AddInput(overlapping_buffer)); |
| 574 EXPECT_FALSE(splicer_.HasNextBuffer()); | 575 EXPECT_TRUE(splicer_.HasNextBuffer()); |
| 575 | |
| 576 // Add an EOS buffer to complete the splice. | |
| 577 EXPECT_TRUE(AddInput(AudioBuffer::CreateEOSBuffer())); | |
| 578 ASSERT_TRUE(splicer_.HasNextBuffer()); | |
| 579 | 576 |
| 580 const int kExpectedPreSpliceSize = 55; | 577 const int kExpectedPreSpliceSize = 55; |
| 581 const base::TimeDelta kExpectedPreSpliceDuration = | 578 const base::TimeDelta kExpectedPreSpliceDuration = |
| 582 base::TimeDelta::FromMicroseconds(1247); | 579 base::TimeDelta::FromMicroseconds(1247); |
| 583 VerifyPreSpliceOutput(overlapped_buffer, | 580 VerifyPreSpliceOutput(overlapped_buffer, |
| 584 overlapping_buffer, | 581 overlapping_buffer, |
| 585 kExpectedPreSpliceSize, | 582 kExpectedPreSpliceSize, |
| 586 kExpectedPreSpliceDuration); | 583 kExpectedPreSpliceDuration); |
| 587 VerifyCrossfadeOutput(overlapped_buffer, | 584 VerifyCrossfadeOutput(overlapped_buffer, |
| 588 NULL, | 585 NULL, |
| 589 overlapping_buffer, | 586 overlapping_buffer, |
| 590 0, | 587 0, |
| 591 kExpectedPreSpliceSize, | 588 kExpectedPreSpliceSize, |
| 592 kExpectedPreSpliceDuration); | 589 kExpectedPreSpliceDuration); |
| 593 | 590 |
| 594 // Retrieve the remaining portion after crossfade. | 591 // Retrieve the remaining portion after crossfade. |
| 595 ASSERT_TRUE(splicer_.HasNextBuffer()); | 592 ASSERT_TRUE(splicer_.HasNextBuffer()); |
| 596 scoped_refptr<AudioBuffer> post_splice_output = splicer_.GetNextBuffer(); | 593 scoped_refptr<AudioBuffer> post_splice_output = splicer_.GetNextBuffer(); |
| 597 EXPECT_EQ(overlapping_buffer->timestamp() + kExpectedPreSpliceDuration, | 594 EXPECT_EQ(overlapping_buffer->timestamp() + kExpectedPreSpliceDuration, |
| 598 post_splice_output->timestamp()); | 595 post_splice_output->timestamp()); |
| 599 EXPECT_EQ(overlapping_buffer->frame_count() - kExpectedPreSpliceSize, | 596 EXPECT_EQ(overlapping_buffer->frame_count() - kExpectedPreSpliceSize, |
| 600 post_splice_output->frame_count()); | 597 post_splice_output->frame_count()); |
| 601 EXPECT_EQ(overlapping_buffer->duration() - kExpectedPreSpliceDuration, | 598 EXPECT_EQ(overlapping_buffer->duration() - kExpectedPreSpliceDuration, |
| 602 post_splice_output->duration()); | 599 post_splice_output->duration()); |
| 603 | 600 |
| 604 EXPECT_TRUE(VerifyData(post_splice_output, GetValue(overlapping_buffer))); | 601 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()); | 602 EXPECT_FALSE(splicer_.HasNextBuffer()); |
| 610 } | 603 } |
| 611 | 604 |
| 612 // Test behavior when a splice frame is incorrectly marked and does not actually | 605 // Test behavior when a splice frame is incorrectly marked and does not actually |
| 613 // overlap. | 606 // overlap. |
| 614 // +----------+ | 607 // +----------+ |
| 615 // |1111111111| | 608 // |1111111111| |
| 616 // +----------+ | 609 // +----------+ |
| 617 // +--------------+ | 610 // +--------------+ |
| 618 // |22222222222222| | 611 // |22222222222222| |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 635 scoped_refptr<AudioBuffer> second_buffer = | 628 scoped_refptr<AudioBuffer> second_buffer = |
| 636 GetNextInputBuffer(0.0f, kBufferSize); | 629 GetNextInputBuffer(0.0f, kBufferSize); |
| 637 | 630 |
| 638 // The splicer should be internally queuing input since |first_buffer| is part | 631 // The splicer should be internally queuing input since |first_buffer| is part |
| 639 // of the supposed splice. | 632 // of the supposed splice. |
| 640 EXPECT_TRUE(AddInput(first_buffer)); | 633 EXPECT_TRUE(AddInput(first_buffer)); |
| 641 EXPECT_FALSE(splicer_.HasNextBuffer()); | 634 EXPECT_FALSE(splicer_.HasNextBuffer()); |
| 642 | 635 |
| 643 // |second_buffer| should complete the supposed splice, so ensure output is | 636 // |second_buffer| should complete the supposed splice, so ensure output is |
| 644 // now available. | 637 // now available. |
| 638 splicer_.SetSpliceTimestamp(kNoTimestamp()); | |
| 645 EXPECT_TRUE(AddInput(second_buffer)); | 639 EXPECT_TRUE(AddInput(second_buffer)); |
| 646 ASSERT_TRUE(splicer_.HasNextBuffer()); | 640 ASSERT_TRUE(splicer_.HasNextBuffer()); |
| 647 | 641 |
| 648 VerifyNextBuffer(first_buffer); | 642 VerifyNextBuffer(first_buffer); |
| 649 VerifyNextBuffer(second_buffer); | 643 VerifyNextBuffer(second_buffer); |
| 650 EXPECT_FALSE(splicer_.HasNextBuffer()); | 644 EXPECT_FALSE(splicer_.HasNextBuffer()); |
| 651 } | 645 } |
| 652 | 646 |
| 653 // Test behavior when a splice frame is incorrectly marked and there is a gap | 647 // Test behavior when a splice frame is incorrectly marked and there is a gap |
| 654 // between whats in the pre splice and post splice. | 648 // between whats in the pre splice and post splice. |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 676 GetNextInputBuffer(0.0f, kBufferSize); | 670 GetNextInputBuffer(0.0f, kBufferSize); |
| 677 | 671 |
| 678 // The splicer should pass through the first buffer since it's not part of the | 672 // The splicer should pass through the first buffer since it's not part of the |
| 679 // splice. | 673 // splice. |
| 680 EXPECT_TRUE(AddInput(first_buffer)); | 674 EXPECT_TRUE(AddInput(first_buffer)); |
| 681 EXPECT_TRUE(splicer_.HasNextBuffer()); | 675 EXPECT_TRUE(splicer_.HasNextBuffer()); |
| 682 VerifyNextBuffer(first_buffer); | 676 VerifyNextBuffer(first_buffer); |
| 683 | 677 |
| 684 // Do not add |gap_buffer|. | 678 // Do not add |gap_buffer|. |
| 685 | 679 |
| 686 // |second_buffer| will trigger an exact overlap splice check. | 680 // |second_buffer| will complete the supposed splice. |
| 681 splicer_.SetSpliceTimestamp(kNoTimestamp()); | |
| 687 EXPECT_TRUE(AddInput(second_buffer)); | 682 EXPECT_TRUE(AddInput(second_buffer)); |
| 688 EXPECT_FALSE(splicer_.HasNextBuffer()); | 683 EXPECT_TRUE(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 | 684 |
| 695 VerifyNextBuffer(gap_buffer); | 685 VerifyNextBuffer(gap_buffer); |
| 696 VerifyNextBuffer(second_buffer); | 686 VerifyNextBuffer(second_buffer); |
| 697 scoped_refptr<AudioBuffer> eos_buffer = splicer_.GetNextBuffer(); | |
| 698 EXPECT_TRUE(eos_buffer->end_of_stream()); | |
| 699 EXPECT_FALSE(splicer_.HasNextBuffer()); | 687 EXPECT_FALSE(splicer_.HasNextBuffer()); |
| 700 } | 688 } |
| 701 | 689 |
| 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) { | |
|
wolenetz
2014/04/17 18:24:03
I'm confused I think. Why is this test no longer a
DaleCurtis
2014/04/17 20:03:18
It was necessary because we relied on the checking
| |
| 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 | 690 } // namespace media |
| OLD | NEW |