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 <algorithm> // std::min |
| 6 |
5 #include "base/logging.h" | 7 #include "base/logging.h" |
6 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
7 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
8 #include "base/time.h" | 10 #include "base/time.h" |
9 #include "media/audio/audio_manager.h" | 11 #include "media/audio/audio_manager.h" |
10 #include "media/audio/fake_audio_output_stream.h" | 12 #include "media/audio/fake_audio_output_stream.h" |
11 #include "media/audio/simple_sources.h" | 13 #include "media/audio/simple_sources.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
13 | 15 |
14 namespace media { | 16 namespace media { |
(...skipping 29 matching lines...) Expand all Loading... |
44 // Write everything into this push source. | 46 // Write everything into this push source. |
45 for (uint32 i = 0; i < kDataSize; i += kWriteSize) { | 47 for (uint32 i = 0; i < kDataSize; i += kWriteSize) { |
46 uint32 size = std::min(kDataSize - i, kWriteSize); | 48 uint32 size = std::min(kDataSize - i, kWriteSize); |
47 EXPECT_TRUE(push_source.Write(data.get() + i, size)); | 49 EXPECT_TRUE(push_source.Write(data.get() + i, size)); |
48 } | 50 } |
49 EXPECT_EQ(kDataSize, push_source.UnProcessedBytes()); | 51 EXPECT_EQ(kDataSize, push_source.UnProcessedBytes()); |
50 | 52 |
51 // Read everything from the push source. | 53 // Read everything from the push source. |
52 for (uint32 i = 0; i < kDataSize; i += kReadSize) { | 54 for (uint32 i = 0; i < kDataSize; i += kReadSize) { |
53 uint32 size = std::min(kDataSize - i , kReadSize); | 55 uint32 size = std::min(kDataSize - i , kReadSize); |
54 EXPECT_EQ(size, push_source.OnMoreData(NULL, read_data.get(), size, | 56 EXPECT_EQ(size, push_source.OnMoreData(read_data.get(), size, |
55 AudioBuffersState())); | 57 AudioBuffersState())); |
56 EXPECT_EQ(0, memcmp(data.get() + i, read_data.get(), size)); | 58 EXPECT_EQ(0, memcmp(data.get() + i, read_data.get(), size)); |
57 } | 59 } |
58 EXPECT_EQ(0u, push_source.UnProcessedBytes()); | 60 EXPECT_EQ(0u, push_source.UnProcessedBytes()); |
59 } | 61 } |
60 | 62 |
61 // Validate that the SineWaveAudioSource writes the expected values for | 63 // Validate that the SineWaveAudioSource writes the expected values for |
62 // the FORMAT_16BIT_MONO. The values are carefully selected so rounding issues | 64 // the FORMAT_16BIT_MONO. The values are carefully selected so rounding issues |
63 // do not affect the result. We also test that AudioManager::GetLastMockBuffer | 65 // do not affect the result. We also test that AudioManager::GetLastMockBuffer |
64 // works. | 66 // works. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 EXPECT_TRUE(last_buffer[2] < last_buffer[3]); | 98 EXPECT_TRUE(last_buffer[2] < last_buffer[3]); |
97 // Spot test negative incursion of sine wave. | 99 // Spot test negative incursion of sine wave. |
98 EXPECT_EQ(0, last_buffer[half_period]); | 100 EXPECT_EQ(0, last_buffer[half_period]); |
99 EXPECT_EQ(-5126, last_buffer[half_period + 1]); | 101 EXPECT_EQ(-5126, last_buffer[half_period + 1]); |
100 EXPECT_TRUE(last_buffer[half_period + 1] > last_buffer[half_period + 2]); | 102 EXPECT_TRUE(last_buffer[half_period + 1] > last_buffer[half_period + 2]); |
101 EXPECT_TRUE(last_buffer[half_period + 2] > last_buffer[half_period + 3]); | 103 EXPECT_TRUE(last_buffer[half_period + 2] > last_buffer[half_period + 3]); |
102 oas->Close(); | 104 oas->Close(); |
103 } | 105 } |
104 | 106 |
105 } // namespace media | 107 } // namespace media |
OLD | NEW |