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 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 EXPECT_TRUE(AddInput(first_buffer)); | 713 EXPECT_TRUE(AddInput(first_buffer)); |
714 VerifyNextBuffer(first_buffer); | 714 VerifyNextBuffer(first_buffer); |
715 | 715 |
716 // Do not add |gap_buffer|. | 716 // Do not add |gap_buffer|. |
717 | 717 |
718 // |second_buffer| will complete the supposed splice. | 718 // |second_buffer| will complete the supposed splice. |
719 splicer_.SetSpliceTimestamp(kNoTimestamp()); | 719 splicer_.SetSpliceTimestamp(kNoTimestamp()); |
720 EXPECT_FALSE(AddInput(second_buffer)); | 720 EXPECT_FALSE(AddInput(second_buffer)); |
721 } | 721 } |
722 | 722 |
| 723 // Ensure we don't crash when a splice frame is incorrectly marked such that the |
| 724 // splice timestamp has already passed when SetSpliceTimestamp() is called. |
| 725 // This can happen if the encoded timestamps are too far behind the decoded |
| 726 // timestamps. |
| 727 TEST_F(AudioSplicerTest, IncorrectlyMarkedPastSplice) { |
| 728 const int kBufferSize = 200; |
| 729 |
| 730 scoped_refptr<AudioBuffer> first_buffer = |
| 731 GetNextInputBuffer(1.0f, kBufferSize); |
| 732 EXPECT_TRUE(AddInput(first_buffer)); |
| 733 VerifyNextBuffer(first_buffer); |
| 734 |
| 735 // Start the splice at a timestamp which has already occurred. |
| 736 splicer_.SetSpliceTimestamp(base::TimeDelta()); |
| 737 |
| 738 scoped_refptr<AudioBuffer> second_buffer = |
| 739 GetNextInputBuffer(0.5f, kBufferSize); |
| 740 EXPECT_TRUE(AddInput(second_buffer)); |
| 741 EXPECT_FALSE(splicer_.HasNextBuffer()); |
| 742 |
| 743 // |third_buffer| will complete the supposed splice. The buffer size is set |
| 744 // such that unchecked the splicer would try to trim off a negative number of |
| 745 // frames. |
| 746 splicer_.SetSpliceTimestamp(kNoTimestamp()); |
| 747 scoped_refptr<AudioBuffer> third_buffer = |
| 748 GetNextInputBuffer(0.0f, kBufferSize * 10); |
| 749 third_buffer->set_timestamp(base::TimeDelta()); |
| 750 EXPECT_TRUE(AddInput(third_buffer)); |
| 751 |
| 752 // The second buffer should come through unmodified. |
| 753 VerifyNextBuffer(second_buffer); |
| 754 |
| 755 // The third buffer should be partially dropped since it overlaps the second. |
| 756 ASSERT_TRUE(splicer_.HasNextBuffer()); |
| 757 const base::TimeDelta second_buffer_end_ts = |
| 758 second_buffer->timestamp() + second_buffer->duration(); |
| 759 scoped_refptr<AudioBuffer> output = splicer_.GetNextBuffer(); |
| 760 EXPECT_EQ(second_buffer_end_ts, output->timestamp()); |
| 761 EXPECT_EQ(third_buffer->duration() - |
| 762 (second_buffer_end_ts - third_buffer->timestamp()), |
| 763 output->duration()); |
| 764 EXPECT_TRUE(VerifyData(output, GetValue(third_buffer))); |
| 765 } |
| 766 |
723 } // namespace media | 767 } // namespace media |
OLD | NEW |