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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/environment.h" | 9 #include "base/environment.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 127 |
128 // Convenience method which creates a default AudioInputStream object using | 128 // Convenience method which creates a default AudioInputStream object using |
129 // a 10ms frame size and a sample rate which is set to the hardware sample | 129 // a 10ms frame size and a sample rate which is set to the hardware sample |
130 // rate. | 130 // rate. |
131 AudioInputStream* CreateDefaultAudioInputStream() { | 131 AudioInputStream* CreateDefaultAudioInputStream() { |
132 int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate()); | 132 int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate()); |
133 int samples_per_packet = fs / 100; | 133 int samples_per_packet = fs / 100; |
134 AudioInputStream* ais = audio_manager_->MakeAudioInputStream( | 134 AudioInputStream* ais = audio_manager_->MakeAudioInputStream( |
135 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 135 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
136 CHANNEL_LAYOUT_STEREO, fs, 16, samples_per_packet), | 136 CHANNEL_LAYOUT_STEREO, fs, 16, samples_per_packet), |
137 AudioDeviceDescription::kDefaultDeviceId, | 137 AudioDeviceDescription::kDefaultDeviceId); |
138 base::Bind(&MacAudioInputTest::OnLogMessage, base::Unretained(this))); | |
139 EXPECT_TRUE(ais); | 138 EXPECT_TRUE(ais); |
140 return ais; | 139 return ais; |
141 } | 140 } |
142 | 141 |
143 // Convenience method which creates an AudioInputStream object with a | 142 // Convenience method which creates an AudioInputStream object with a |
144 // specified channel layout. | 143 // specified channel layout. |
145 AudioInputStream* CreateAudioInputStream(ChannelLayout channel_layout) { | 144 AudioInputStream* CreateAudioInputStream(ChannelLayout channel_layout) { |
146 int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate()); | 145 int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate()); |
147 int samples_per_packet = fs / 100; | 146 int samples_per_packet = fs / 100; |
148 AudioInputStream* ais = audio_manager_->MakeAudioInputStream( | 147 AudioInputStream* ais = audio_manager_->MakeAudioInputStream( |
149 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, | 148 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
150 fs, 16, samples_per_packet), | 149 fs, 16, samples_per_packet), |
151 AudioDeviceDescription::kDefaultDeviceId, | 150 AudioDeviceDescription::kDefaultDeviceId); |
152 base::Bind(&MacAudioInputTest::OnLogMessage, base::Unretained(this))); | |
153 EXPECT_TRUE(ais); | 151 EXPECT_TRUE(ais); |
154 return ais; | 152 return ais; |
155 } | 153 } |
156 | 154 |
157 void OnLogMessage(const std::string& message) { log_message_ = message; } | |
158 | |
159 base::MessageLoop message_loop_; | 155 base::MessageLoop message_loop_; |
160 ScopedAudioManagerPtr audio_manager_; | 156 ScopedAudioManagerPtr audio_manager_; |
161 std::string log_message_; | |
162 }; | 157 }; |
163 | 158 |
164 // Test Create(), Close(). | 159 // Test Create(), Close(). |
165 TEST_F(MacAudioInputTest, AUAudioInputStreamCreateAndClose) { | 160 TEST_F(MacAudioInputTest, AUAudioInputStreamCreateAndClose) { |
166 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 161 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); |
167 AudioInputStream* ais = CreateDefaultAudioInputStream(); | 162 AudioInputStream* ais = CreateDefaultAudioInputStream(); |
168 ais->Close(); | 163 ais->Close(); |
169 } | 164 } |
170 | 165 |
171 // Test Open(), Close(). | 166 // Test Open(), Close(). |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 // estimate. | 209 // estimate. |
215 base::RunLoop run_loop; | 210 base::RunLoop run_loop; |
216 EXPECT_CALL(sink, OnData(ais, NotNull(), _, _)) | 211 EXPECT_CALL(sink, OnData(ais, NotNull(), _, _)) |
217 .Times(AtLeast(10)) | 212 .Times(AtLeast(10)) |
218 .WillRepeatedly(CheckCountAndPostQuitTask( | 213 .WillRepeatedly(CheckCountAndPostQuitTask( |
219 &count, 10, &message_loop_, run_loop.QuitClosure())); | 214 &count, 10, &message_loop_, run_loop.QuitClosure())); |
220 ais->Start(&sink); | 215 ais->Start(&sink); |
221 run_loop.Run(); | 216 run_loop.Run(); |
222 ais->Stop(); | 217 ais->Stop(); |
223 ais->Close(); | 218 ais->Close(); |
224 | |
225 EXPECT_FALSE(log_message_.empty()); | |
226 } | 219 } |
227 | 220 |
228 // Verify that recording starts and stops correctly in mono using mocked sink. | 221 // Verify that recording starts and stops correctly in mono using mocked sink. |
229 TEST_F(MacAudioInputTest, AUAudioInputStreamVerifyStereoRecording) { | 222 TEST_F(MacAudioInputTest, AUAudioInputStreamVerifyStereoRecording) { |
230 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 223 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); |
231 | 224 |
232 int count = 0; | 225 int count = 0; |
233 | 226 |
234 // Create an audio input stream which records in stereo. | 227 // Create an audio input stream which records in stereo. |
235 AudioInputStream* ais = CreateAudioInputStream(CHANNEL_LAYOUT_STEREO); | 228 AudioInputStream* ais = CreateAudioInputStream(CHANNEL_LAYOUT_STEREO); |
(...skipping 13 matching lines...) Expand all Loading... |
249 // more analysis of the delay estimates are done. | 242 // more analysis of the delay estimates are done. |
250 base::RunLoop run_loop; | 243 base::RunLoop run_loop; |
251 EXPECT_CALL(sink, OnData(ais, NotNull(), _, _)) | 244 EXPECT_CALL(sink, OnData(ais, NotNull(), _, _)) |
252 .Times(AtLeast(10)) | 245 .Times(AtLeast(10)) |
253 .WillRepeatedly(CheckCountAndPostQuitTask( | 246 .WillRepeatedly(CheckCountAndPostQuitTask( |
254 &count, 10, &message_loop_, run_loop.QuitClosure())); | 247 &count, 10, &message_loop_, run_loop.QuitClosure())); |
255 ais->Start(&sink); | 248 ais->Start(&sink); |
256 run_loop.Run(); | 249 run_loop.Run(); |
257 ais->Stop(); | 250 ais->Stop(); |
258 ais->Close(); | 251 ais->Close(); |
259 | |
260 EXPECT_FALSE(log_message_.empty()); | |
261 } | 252 } |
262 | 253 |
263 // This test is intended for manual tests and should only be enabled | 254 // This test is intended for manual tests and should only be enabled |
264 // when it is required to store the captured data on a local file. | 255 // when it is required to store the captured data on a local file. |
265 // By default, GTest will print out YOU HAVE 1 DISABLED TEST. | 256 // By default, GTest will print out YOU HAVE 1 DISABLED TEST. |
266 // To include disabled tests in test execution, just invoke the test program | 257 // To include disabled tests in test execution, just invoke the test program |
267 // with --gtest_also_run_disabled_tests or set the GTEST_ALSO_RUN_DISABLED_TESTS | 258 // with --gtest_also_run_disabled_tests or set the GTEST_ALSO_RUN_DISABLED_TESTS |
268 // environment variable to a value greater than 0. | 259 // environment variable to a value greater than 0. |
269 TEST_F(MacAudioInputTest, DISABLED_AUAudioInputStreamRecordToFile) { | 260 TEST_F(MacAudioInputTest, DISABLED_AUAudioInputStreamRecordToFile) { |
270 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 261 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); |
271 const char* file_name = "out_stereo_10sec.pcm"; | 262 const char* file_name = "out_stereo_10sec.pcm"; |
272 | 263 |
273 int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate()); | 264 int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate()); |
274 AudioInputStream* ais = CreateDefaultAudioInputStream(); | 265 AudioInputStream* ais = CreateDefaultAudioInputStream(); |
275 EXPECT_TRUE(ais->Open()); | 266 EXPECT_TRUE(ais->Open()); |
276 | 267 |
277 fprintf(stderr, " File name : %s\n", file_name); | 268 fprintf(stderr, " File name : %s\n", file_name); |
278 fprintf(stderr, " Sample rate: %d\n", fs); | 269 fprintf(stderr, " Sample rate: %d\n", fs); |
279 WriteToFileAudioSink file_sink(file_name); | 270 WriteToFileAudioSink file_sink(file_name); |
280 fprintf(stderr, " >> Speak into the mic while recording...\n"); | 271 fprintf(stderr, " >> Speak into the mic while recording...\n"); |
281 ais->Start(&file_sink); | 272 ais->Start(&file_sink); |
282 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); | 273 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); |
283 ais->Stop(); | 274 ais->Stop(); |
284 fprintf(stderr, " >> Recording has stopped.\n"); | 275 fprintf(stderr, " >> Recording has stopped.\n"); |
285 ais->Close(); | 276 ais->Close(); |
286 } | 277 } |
287 | 278 |
288 } // namespace media | 279 } // namespace media |
OLD | NEW |