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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "media/audio/audio_io.h" | 7 #include "media/audio/audio_io.h" |
8 #include "media/audio/audio_manager.h" | 8 #include "media/audio/audio_manager.h" |
9 #include "media/audio/simple_sources.h" | 9 #include "media/audio/simple_sources.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 // =========================================================================== | 48 // =========================================================================== |
49 // Validation of AudioParameters::AUDIO_PCM_LINEAR | 49 // Validation of AudioParameters::AUDIO_PCM_LINEAR |
50 // | 50 // |
51 | 51 |
52 // Test that can it be created and closed. | 52 // Test that can it be created and closed. |
53 TEST(MacAudioTest, PCMWaveStreamGetAndClose) { | 53 TEST(MacAudioTest, PCMWaveStreamGetAndClose) { |
54 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 54 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
55 if (!audio_man->HasAudioOutputDevices()) | 55 if (!audio_man->HasAudioOutputDevices()) |
56 return; | 56 return; |
57 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 57 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
58 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | 58 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, false, |
| 59 CHANNEL_LAYOUT_STEREO, |
59 8000, 16, 1024)); | 60 8000, 16, 1024)); |
60 ASSERT_TRUE(NULL != oas); | 61 ASSERT_TRUE(NULL != oas); |
61 oas->Close(); | 62 oas->Close(); |
62 } | 63 } |
63 | 64 |
64 // Test that it can be opened and closed. | 65 // Test that it can be opened and closed. |
65 TEST(MacAudioTest, PCMWaveStreamOpenAndClose) { | 66 TEST(MacAudioTest, PCMWaveStreamOpenAndClose) { |
66 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 67 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
67 if (!audio_man->HasAudioOutputDevices()) | 68 if (!audio_man->HasAudioOutputDevices()) |
68 return; | 69 return; |
69 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 70 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
70 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | 71 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, false, |
| 72 CHANNEL_LAYOUT_STEREO, |
71 8000, 16, 1024)); | 73 8000, 16, 1024)); |
72 ASSERT_TRUE(NULL != oas); | 74 ASSERT_TRUE(NULL != oas); |
73 EXPECT_TRUE(oas->Open()); | 75 EXPECT_TRUE(oas->Open()); |
74 oas->Close(); | 76 oas->Close(); |
75 } | 77 } |
76 | 78 |
77 // This test produces actual audio for 1.5 seconds on the default wave device at | 79 // This test produces actual audio for 1.5 seconds on the default wave device at |
78 // 44.1K s/sec. Parameters have been chosen carefully so you should not hear | 80 // 44.1K s/sec. Parameters have been chosen carefully so you should not hear |
79 // pops or noises while the sound is playing. The sound must also be identical | 81 // pops or noises while the sound is playing. The sound must also be identical |
80 // to the sound of PCMWaveStreamPlay200HzTone22KssMono test. | 82 // to the sound of PCMWaveStreamPlay200HzTone22KssMono test. |
81 TEST(MacAudioTest, PCMWaveStreamPlay200HzTone44KssMono) { | 83 TEST(MacAudioTest, PCMWaveStreamPlay200HzTone44KssMono) { |
82 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 84 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
83 if (!audio_man->HasAudioOutputDevices()) | 85 if (!audio_man->HasAudioOutputDevices()) |
84 return; | 86 return; |
85 uint32 frames_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 87 uint32 frames_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
86 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 88 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
87 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 89 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, false, |
| 90 CHANNEL_LAYOUT_MONO, |
88 AudioParameters::kAudioCDSampleRate, 16, frames_100_ms)); | 91 AudioParameters::kAudioCDSampleRate, 16, frames_100_ms)); |
89 ASSERT_TRUE(NULL != oas); | 92 ASSERT_TRUE(NULL != oas); |
90 EXPECT_TRUE(oas->Open()); | 93 EXPECT_TRUE(oas->Open()); |
91 | 94 |
92 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 95 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
93 200.0, AudioParameters::kAudioCDSampleRate); | 96 200.0, AudioParameters::kAudioCDSampleRate); |
94 oas->SetVolume(0.5); | 97 oas->SetVolume(0.5); |
95 oas->Start(&source); | 98 oas->Start(&source); |
96 usleep(500000); | 99 usleep(500000); |
97 | 100 |
98 // Test that the volume is within the set limits. | 101 // Test that the volume is within the set limits. |
99 double volume = 0.0; | 102 double volume = 0.0; |
100 oas->GetVolume(&volume); | 103 oas->GetVolume(&volume); |
101 EXPECT_LT(volume, 0.51); | 104 EXPECT_LT(volume, 0.51); |
102 EXPECT_GT(volume, 0.49); | 105 EXPECT_GT(volume, 0.49); |
103 oas->Stop(); | 106 oas->Stop(); |
104 oas->Close(); | 107 oas->Close(); |
105 } | 108 } |
106 | 109 |
107 // This test produces actual audio for 1.5 seconds on the default wave device at | 110 // This test produces actual audio for 1.5 seconds on the default wave device at |
108 // 22K s/sec. Parameters have been chosen carefully so you should not hear pops | 111 // 22K s/sec. Parameters have been chosen carefully so you should not hear pops |
109 // or noises while the sound is playing. The sound must also be identical to the | 112 // or noises while the sound is playing. The sound must also be identical to the |
110 // sound of PCMWaveStreamPlay200HzTone44KssMono test. | 113 // sound of PCMWaveStreamPlay200HzTone44KssMono test. |
111 TEST(MacAudioTest, PCMWaveStreamPlay200HzTone22KssMono) { | 114 TEST(MacAudioTest, PCMWaveStreamPlay200HzTone22KssMono) { |
112 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 115 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
113 if (!audio_man->HasAudioOutputDevices()) | 116 if (!audio_man->HasAudioOutputDevices()) |
114 return; | 117 return; |
115 uint32 frames_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 118 uint32 frames_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
116 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 119 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
117 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 120 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, false, |
| 121 CHANNEL_LAYOUT_MONO, |
118 AudioParameters::kAudioCDSampleRate / 2, 16, | 122 AudioParameters::kAudioCDSampleRate / 2, 16, |
119 frames_100_ms)); | 123 frames_100_ms)); |
120 ASSERT_TRUE(NULL != oas); | 124 ASSERT_TRUE(NULL != oas); |
121 | 125 |
122 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 126 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
123 200.0, AudioParameters::kAudioCDSampleRate/2); | 127 200.0, AudioParameters::kAudioCDSampleRate/2); |
124 EXPECT_TRUE(oas->Open()); | 128 EXPECT_TRUE(oas->Open()); |
125 oas->Start(&source); | 129 oas->Start(&source); |
126 usleep(1500000); | 130 usleep(1500000); |
127 oas->Stop(); | 131 oas->Stop(); |
128 oas->Close(); | 132 oas->Close(); |
129 } | 133 } |
130 | 134 |
131 // Custom action to clear a memory buffer. | 135 // Custom action to clear a memory buffer. |
132 static void ClearBuffer(AudioOutputStream* stream, uint8* dest, | 136 static void ClearBuffer(AudioOutputStream* stream, uint8* dest, |
133 uint32 max_size, AudioBuffersState buffers_state) { | 137 uint32 max_size, AudioBuffersState buffers_state) { |
134 memset(dest, 0, max_size); | 138 memset(dest, 0, max_size); |
135 } | 139 } |
136 | 140 |
137 TEST(MacAudioTest, PCMWaveStreamPendingBytes) { | 141 TEST(MacAudioTest, PCMWaveStreamPendingBytes) { |
138 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 142 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
139 if (!audio_man->HasAudioOutputDevices()) | 143 if (!audio_man->HasAudioOutputDevices()) |
140 return; | 144 return; |
141 | 145 |
142 uint32 frames_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 146 uint32 frames_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
143 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 147 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
144 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 148 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, false, |
| 149 CHANNEL_LAYOUT_MONO, |
145 AudioParameters::kAudioCDSampleRate, 16, frames_100_ms)); | 150 AudioParameters::kAudioCDSampleRate, 16, frames_100_ms)); |
146 ASSERT_TRUE(NULL != oas); | 151 ASSERT_TRUE(NULL != oas); |
147 | 152 |
148 NiceMock<MockAudioSource> source; | 153 NiceMock<MockAudioSource> source; |
149 EXPECT_TRUE(oas->Open()); | 154 EXPECT_TRUE(oas->Open()); |
150 | 155 |
151 uint32 bytes_100_ms = frames_100_ms * 2; | 156 uint32 bytes_100_ms = frames_100_ms * 2; |
152 | 157 |
153 // We expect the amount of pending bytes will reaching |bytes_100_ms| | 158 // We expect the amount of pending bytes will reaching |bytes_100_ms| |
154 // because the audio output stream has a double buffer scheme. | 159 // because the audio output stream has a double buffer scheme. |
(...skipping 13 matching lines...) Expand all Loading... |
168 .WillOnce(Return(0)); | 173 .WillOnce(Return(0)); |
169 EXPECT_CALL(source, OnMoreData(oas, NotNull(), bytes_100_ms, _)) | 174 EXPECT_CALL(source, OnMoreData(oas, NotNull(), bytes_100_ms, _)) |
170 .Times(AnyNumber()) | 175 .Times(AnyNumber()) |
171 .WillRepeatedly(Return(0)); | 176 .WillRepeatedly(Return(0)); |
172 | 177 |
173 oas->Start(&source); | 178 oas->Start(&source); |
174 usleep(500000); | 179 usleep(500000); |
175 oas->Stop(); | 180 oas->Stop(); |
176 oas->Close(); | 181 oas->Close(); |
177 } | 182 } |
OLD | NEW |