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 "media/base/audio_splicer.h" | 5 #include "media/base/audio_splicer.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "media/base/audio_buffer.h" | 10 #include "media/base/audio_buffer.h" |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 // for output. | 427 // for output. |
428 EXPECT_TRUE(AddInput(extra_pre_splice_buffer)); | 428 EXPECT_TRUE(AddInput(extra_pre_splice_buffer)); |
429 VerifyNextBuffer(extra_pre_splice_buffer); | 429 VerifyNextBuffer(extra_pre_splice_buffer); |
430 | 430 |
431 // The splicer should be internally queuing input since |overlapped_buffer| is | 431 // The splicer should be internally queuing input since |overlapped_buffer| is |
432 // part of the splice. | 432 // part of the splice. |
433 EXPECT_TRUE(AddInput(overlapped_buffer)); | 433 EXPECT_TRUE(AddInput(overlapped_buffer)); |
434 EXPECT_FALSE(splicer_.HasNextBuffer()); | 434 EXPECT_FALSE(splicer_.HasNextBuffer()); |
435 | 435 |
436 // |overlapping_buffer| completes the splice. | 436 // |overlapping_buffer| completes the splice. |
437 splicer_.SetSpliceTimestamp(kNoTimestamp()); | 437 splicer_.SetSpliceTimestamp(kNoTimestamp); |
438 EXPECT_TRUE(AddInput(overlapping_buffer)); | 438 EXPECT_TRUE(AddInput(overlapping_buffer)); |
439 ASSERT_TRUE(splicer_.HasNextBuffer()); | 439 ASSERT_TRUE(splicer_.HasNextBuffer()); |
440 | 440 |
441 // Add one more buffer to make sure it's passed through untouched. | 441 // Add one more buffer to make sure it's passed through untouched. |
442 scoped_refptr<AudioBuffer> extra_post_splice_buffer = | 442 scoped_refptr<AudioBuffer> extra_post_splice_buffer = |
443 GetNextInputBuffer(0.5f, kBufferSize); | 443 GetNextInputBuffer(0.5f, kBufferSize); |
444 EXPECT_TRUE(AddInput(extra_post_splice_buffer)); | 444 EXPECT_TRUE(AddInput(extra_post_splice_buffer)); |
445 | 445 |
446 VerifyPreSpliceOutput(overlapped_buffer, | 446 VerifyPreSpliceOutput(overlapped_buffer, |
447 overlapping_buffer, | 447 overlapping_buffer, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 scoped_refptr<AudioBuffer> overlapping_buffer = | 503 scoped_refptr<AudioBuffer> overlapping_buffer = |
504 GetNextInputBuffer(0.0f, kCrossfadeSize / 3); | 504 GetNextInputBuffer(0.0f, kCrossfadeSize / 3); |
505 | 505 |
506 // The splicer should be internally queuing input since |overlapped_buffer| is | 506 // The splicer should be internally queuing input since |overlapped_buffer| is |
507 // part of the splice. | 507 // part of the splice. |
508 EXPECT_TRUE(AddInput(overlapped_buffer)); | 508 EXPECT_TRUE(AddInput(overlapped_buffer)); |
509 EXPECT_FALSE(splicer_.HasNextBuffer()); | 509 EXPECT_FALSE(splicer_.HasNextBuffer()); |
510 | 510 |
511 // |overlapping_buffer| should not have enough data to complete the splice, so | 511 // |overlapping_buffer| should not have enough data to complete the splice, so |
512 // ensure output is not available. | 512 // ensure output is not available. |
513 splicer_.SetSpliceTimestamp(kNoTimestamp()); | 513 splicer_.SetSpliceTimestamp(kNoTimestamp); |
514 EXPECT_TRUE(AddInput(overlapping_buffer)); | 514 EXPECT_TRUE(AddInput(overlapping_buffer)); |
515 EXPECT_FALSE(splicer_.HasNextBuffer()); | 515 EXPECT_FALSE(splicer_.HasNextBuffer()); |
516 | 516 |
517 // Now add an EOS buffer which should complete the splice. | 517 // Now add an EOS buffer which should complete the splice. |
518 EXPECT_TRUE(AddInput(AudioBuffer::CreateEOSBuffer())); | 518 EXPECT_TRUE(AddInput(AudioBuffer::CreateEOSBuffer())); |
519 | 519 |
520 VerifyPreSpliceOutput(overlapped_buffer, | 520 VerifyPreSpliceOutput(overlapped_buffer, |
521 overlapping_buffer, | 521 overlapping_buffer, |
522 331, | 522 331, |
523 base::TimeDelta::FromMicroseconds(7505)); | 523 base::TimeDelta::FromMicroseconds(7505)); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 splicer_.SetSpliceTimestamp(input_timestamp_helper_.GetTimestamp()); | 563 splicer_.SetSpliceTimestamp(input_timestamp_helper_.GetTimestamp()); |
564 scoped_refptr<AudioBuffer> overlapping_buffer = | 564 scoped_refptr<AudioBuffer> overlapping_buffer = |
565 GetNextInputBuffer(0.0f, kCrossfadeSize * 2); | 565 GetNextInputBuffer(0.0f, kCrossfadeSize * 2); |
566 | 566 |
567 // The splicer should be internally queuing input since |overlapped_buffer| is | 567 // The splicer should be internally queuing input since |overlapped_buffer| is |
568 // part of the splice. | 568 // part of the splice. |
569 EXPECT_TRUE(AddInput(overlapped_buffer)); | 569 EXPECT_TRUE(AddInput(overlapped_buffer)); |
570 EXPECT_FALSE(splicer_.HasNextBuffer()); | 570 EXPECT_FALSE(splicer_.HasNextBuffer()); |
571 | 571 |
572 // |overlapping_buffer| completes the splice. | 572 // |overlapping_buffer| completes the splice. |
573 splicer_.SetSpliceTimestamp(kNoTimestamp()); | 573 splicer_.SetSpliceTimestamp(kNoTimestamp); |
574 EXPECT_TRUE(AddInput(overlapping_buffer)); | 574 EXPECT_TRUE(AddInput(overlapping_buffer)); |
575 | 575 |
576 const int kExpectedPreSpliceSize = 55; | 576 const int kExpectedPreSpliceSize = 55; |
577 const base::TimeDelta kExpectedPreSpliceDuration = | 577 const base::TimeDelta kExpectedPreSpliceDuration = |
578 base::TimeDelta::FromMicroseconds(1247); | 578 base::TimeDelta::FromMicroseconds(1247); |
579 VerifyPreSpliceOutput(overlapped_buffer, | 579 VerifyPreSpliceOutput(overlapped_buffer, |
580 overlapping_buffer, | 580 overlapping_buffer, |
581 kExpectedPreSpliceSize, | 581 kExpectedPreSpliceSize, |
582 kExpectedPreSpliceDuration); | 582 kExpectedPreSpliceDuration); |
583 VerifyCrossfadeOutput(overlapped_buffer, | 583 VerifyCrossfadeOutput(overlapped_buffer, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 GetNextInputBuffer(0.0f, kBufferSize); | 629 GetNextInputBuffer(0.0f, kBufferSize); |
630 second_buffer->set_timestamp(kSpliceTimestamp); | 630 second_buffer->set_timestamp(kSpliceTimestamp); |
631 | 631 |
632 // The splicer should be internally queuing input since |first_buffer| is part | 632 // The splicer should be internally queuing input since |first_buffer| is part |
633 // of the supposed splice. | 633 // of the supposed splice. |
634 EXPECT_TRUE(AddInput(first_buffer)); | 634 EXPECT_TRUE(AddInput(first_buffer)); |
635 EXPECT_FALSE(splicer_.HasNextBuffer()); | 635 EXPECT_FALSE(splicer_.HasNextBuffer()); |
636 | 636 |
637 // |second_buffer| should complete the supposed splice, so ensure output is | 637 // |second_buffer| should complete the supposed splice, so ensure output is |
638 // now available. | 638 // now available. |
639 splicer_.SetSpliceTimestamp(kNoTimestamp()); | 639 splicer_.SetSpliceTimestamp(kNoTimestamp); |
640 EXPECT_TRUE(AddInput(second_buffer)); | 640 EXPECT_TRUE(AddInput(second_buffer)); |
641 | 641 |
642 VerifyNextBuffer(first_buffer); | 642 VerifyNextBuffer(first_buffer); |
643 VerifyNextBuffer(second_buffer); | 643 VerifyNextBuffer(second_buffer); |
644 EXPECT_FALSE(splicer_.HasNextBuffer()); | 644 EXPECT_FALSE(splicer_.HasNextBuffer()); |
645 } | 645 } |
646 | 646 |
647 // 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 |
648 // between whats in the pre splice and post splice. | 648 // between whats in the pre splice and post splice. |
649 // +--------+ | 649 // +--------+ |
(...skipping 20 matching lines...) Expand all Loading... |
670 GetNextInputBuffer(0.0f, kBufferSize); | 670 GetNextInputBuffer(0.0f, kBufferSize); |
671 | 671 |
672 // 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 |
673 // splice. | 673 // splice. |
674 EXPECT_TRUE(AddInput(first_buffer)); | 674 EXPECT_TRUE(AddInput(first_buffer)); |
675 VerifyNextBuffer(first_buffer); | 675 VerifyNextBuffer(first_buffer); |
676 | 676 |
677 // Do not add |gap_buffer|. | 677 // Do not add |gap_buffer|. |
678 | 678 |
679 // |second_buffer| will complete the supposed splice. | 679 // |second_buffer| will complete the supposed splice. |
680 splicer_.SetSpliceTimestamp(kNoTimestamp()); | 680 splicer_.SetSpliceTimestamp(kNoTimestamp); |
681 EXPECT_TRUE(AddInput(second_buffer)); | 681 EXPECT_TRUE(AddInput(second_buffer)); |
682 | 682 |
683 VerifyNextBuffer(gap_buffer); | 683 VerifyNextBuffer(gap_buffer); |
684 VerifyNextBuffer(second_buffer); | 684 VerifyNextBuffer(second_buffer); |
685 EXPECT_FALSE(splicer_.HasNextBuffer()); | 685 EXPECT_FALSE(splicer_.HasNextBuffer()); |
686 } | 686 } |
687 | 687 |
688 // Test behavior when a splice frame is incorrectly marked and there is a gap | 688 // Test behavior when a splice frame is incorrectly marked and there is a gap |
689 // between what's in the pre splice and post splice that is too large to recover | 689 // between what's in the pre splice and post splice that is too large to recover |
690 // from. | 690 // from. |
(...skipping 21 matching lines...) Expand all Loading... |
712 GetNextInputBuffer(0.0f, kBufferSize); | 712 GetNextInputBuffer(0.0f, kBufferSize); |
713 | 713 |
714 // The splicer should pass through the first buffer since it's not part of the | 714 // The splicer should pass through the first buffer since it's not part of the |
715 // splice. | 715 // splice. |
716 EXPECT_TRUE(AddInput(first_buffer)); | 716 EXPECT_TRUE(AddInput(first_buffer)); |
717 VerifyNextBuffer(first_buffer); | 717 VerifyNextBuffer(first_buffer); |
718 | 718 |
719 // Do not add |gap_buffer|. | 719 // Do not add |gap_buffer|. |
720 | 720 |
721 // |second_buffer| will complete the supposed splice. | 721 // |second_buffer| will complete the supposed splice. |
722 splicer_.SetSpliceTimestamp(kNoTimestamp()); | 722 splicer_.SetSpliceTimestamp(kNoTimestamp); |
723 EXPECT_FALSE(AddInput(second_buffer)); | 723 EXPECT_FALSE(AddInput(second_buffer)); |
724 } | 724 } |
725 | 725 |
726 // Ensure we don't crash when a splice frame is incorrectly marked such that the | 726 // Ensure we don't crash when a splice frame is incorrectly marked such that the |
727 // splice timestamp has already passed when SetSpliceTimestamp() is called. | 727 // splice timestamp has already passed when SetSpliceTimestamp() is called. |
728 // This can happen if the encoded timestamps are too far behind the decoded | 728 // This can happen if the encoded timestamps are too far behind the decoded |
729 // timestamps. | 729 // timestamps. |
730 TEST_F(AudioSplicerTest, IncorrectlyMarkedPastSplice) { | 730 TEST_F(AudioSplicerTest, IncorrectlyMarkedPastSplice) { |
731 const int kBufferSize = 200; | 731 const int kBufferSize = 200; |
732 | 732 |
733 scoped_refptr<AudioBuffer> first_buffer = | 733 scoped_refptr<AudioBuffer> first_buffer = |
734 GetNextInputBuffer(1.0f, kBufferSize); | 734 GetNextInputBuffer(1.0f, kBufferSize); |
735 EXPECT_TRUE(AddInput(first_buffer)); | 735 EXPECT_TRUE(AddInput(first_buffer)); |
736 VerifyNextBuffer(first_buffer); | 736 VerifyNextBuffer(first_buffer); |
737 | 737 |
738 // Start the splice at a timestamp which has already occurred. | 738 // Start the splice at a timestamp which has already occurred. |
739 splicer_.SetSpliceTimestamp(base::TimeDelta()); | 739 splicer_.SetSpliceTimestamp(base::TimeDelta()); |
740 | 740 |
741 scoped_refptr<AudioBuffer> second_buffer = | 741 scoped_refptr<AudioBuffer> second_buffer = |
742 GetNextInputBuffer(0.5f, kBufferSize); | 742 GetNextInputBuffer(0.5f, kBufferSize); |
743 EXPECT_TRUE(AddInput(second_buffer)); | 743 EXPECT_TRUE(AddInput(second_buffer)); |
744 EXPECT_FALSE(splicer_.HasNextBuffer()); | 744 EXPECT_FALSE(splicer_.HasNextBuffer()); |
745 | 745 |
746 // |third_buffer| will complete the supposed splice. The buffer size is set | 746 // |third_buffer| will complete the supposed splice. The buffer size is set |
747 // such that unchecked the splicer would try to trim off a negative number of | 747 // such that unchecked the splicer would try to trim off a negative number of |
748 // frames. | 748 // frames. |
749 splicer_.SetSpliceTimestamp(kNoTimestamp()); | 749 splicer_.SetSpliceTimestamp(kNoTimestamp); |
750 scoped_refptr<AudioBuffer> third_buffer = | 750 scoped_refptr<AudioBuffer> third_buffer = |
751 GetNextInputBuffer(0.0f, kBufferSize * 10); | 751 GetNextInputBuffer(0.0f, kBufferSize * 10); |
752 third_buffer->set_timestamp(base::TimeDelta()); | 752 third_buffer->set_timestamp(base::TimeDelta()); |
753 EXPECT_TRUE(AddInput(third_buffer)); | 753 EXPECT_TRUE(AddInput(third_buffer)); |
754 | 754 |
755 // The second buffer should come through unmodified. | 755 // The second buffer should come through unmodified. |
756 VerifyNextBuffer(second_buffer); | 756 VerifyNextBuffer(second_buffer); |
757 | 757 |
758 // The third buffer should be partially dropped since it overlaps the second. | 758 // The third buffer should be partially dropped since it overlaps the second. |
759 ASSERT_TRUE(splicer_.HasNextBuffer()); | 759 ASSERT_TRUE(splicer_.HasNextBuffer()); |
760 const base::TimeDelta second_buffer_end_ts = | 760 const base::TimeDelta second_buffer_end_ts = |
761 second_buffer->timestamp() + second_buffer->duration(); | 761 second_buffer->timestamp() + second_buffer->duration(); |
762 scoped_refptr<AudioBuffer> output = splicer_.GetNextBuffer(); | 762 scoped_refptr<AudioBuffer> output = splicer_.GetNextBuffer(); |
763 EXPECT_EQ(second_buffer_end_ts, output->timestamp()); | 763 EXPECT_EQ(second_buffer_end_ts, output->timestamp()); |
764 EXPECT_EQ(third_buffer->duration() - | 764 EXPECT_EQ(third_buffer->duration() - |
765 (second_buffer_end_ts - third_buffer->timestamp()), | 765 (second_buffer_end_ts - third_buffer->timestamp()), |
766 output->duration()); | 766 output->duration()); |
767 EXPECT_TRUE(VerifyData(output, GetValue(third_buffer))); | 767 EXPECT_TRUE(VerifyData(output, GetValue(third_buffer))); |
768 } | 768 } |
769 | 769 |
770 } // namespace media | 770 } // namespace media |
OLD | NEW |