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 <windows.h> | 5 #include <windows.h> |
6 #include <mmsystem.h> | 6 #include <mmsystem.h> |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/memory/aligned_memory.h" | 10 #include "base/memory/aligned_memory.h" |
11 #include "base/sync_socket.h" | 11 #include "base/sync_socket.h" |
12 #include "base/win/scoped_com_initializer.h" | 12 #include "base/win/scoped_com_initializer.h" |
13 #include "base/win/windows_version.h" | 13 #include "base/win/windows_version.h" |
14 #include "media/base/limits.h" | 14 #include "media/base/limits.h" |
15 #include "media/audio/audio_io.h" | 15 #include "media/audio/audio_io.h" |
16 #include "media/audio/audio_manager.h" | 16 #include "media/audio/audio_manager.h" |
| 17 #include "media/audio/audio_unittest_util.h" |
17 #include "media/audio/mock_audio_source_callback.h" | 18 #include "media/audio/mock_audio_source_callback.h" |
18 #include "media/audio/simple_sources.h" | 19 #include "media/audio/simple_sources.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 | 22 |
22 using ::testing::_; | 23 using ::testing::_; |
23 using ::testing::AnyNumber; | 24 using ::testing::AnyNumber; |
24 using ::testing::DoAll; | 25 using ::testing::DoAll; |
25 using ::testing::Field; | 26 using ::testing::Field; |
26 using ::testing::Invoke; | 27 using ::testing::Invoke; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 // Validation of AudioManager::AUDIO_PCM_LINEAR | 154 // Validation of AudioManager::AUDIO_PCM_LINEAR |
154 // | 155 // |
155 // NOTE: | 156 // NOTE: |
156 // The tests can fail on the build bots when somebody connects to them via | 157 // The tests can fail on the build bots when somebody connects to them via |
157 // remote-desktop and the rdp client installs an audio device that fails to open | 158 // remote-desktop and the rdp client installs an audio device that fails to open |
158 // at some point, possibly when the connection goes idle. | 159 // at some point, possibly when the connection goes idle. |
159 | 160 |
160 // Test that can it be created and closed. | 161 // Test that can it be created and closed. |
161 TEST(WinAudioTest, PCMWaveStreamGetAndClose) { | 162 TEST(WinAudioTest, PCMWaveStreamGetAndClose) { |
162 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 163 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
163 if (!audio_man->HasAudioOutputDevices()) { | 164 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); |
164 LOG(WARNING) << "No output device detected."; | |
165 return; | |
166 } | |
167 | 165 |
168 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 166 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
169 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | 167 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, |
170 8000, 16, 256), | 168 8000, 16, 256), |
171 std::string()); | 169 std::string()); |
172 ASSERT_TRUE(NULL != oas); | 170 ASSERT_TRUE(NULL != oas); |
173 oas->Close(); | 171 oas->Close(); |
174 } | 172 } |
175 | 173 |
176 // Test that can it be cannot be created with invalid parameters. | 174 // Test that can it be cannot be created with invalid parameters. |
177 TEST(WinAudioTest, SanityOnMakeParams) { | 175 TEST(WinAudioTest, SanityOnMakeParams) { |
178 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 176 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
179 if (!audio_man->HasAudioOutputDevices()) { | 177 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); |
180 LOG(WARNING) << "No output device detected."; | |
181 return; | |
182 } | |
183 | 178 |
184 AudioParameters::Format fmt = AudioParameters::AUDIO_PCM_LINEAR; | 179 AudioParameters::Format fmt = AudioParameters::AUDIO_PCM_LINEAR; |
185 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 180 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
186 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256), | 181 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256), |
187 std::string())); | 182 std::string())); |
188 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 183 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
189 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 1024 * 1024, 16, 256), | 184 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 1024 * 1024, 16, 256), |
190 std::string())); | 185 std::string())); |
191 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 186 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
192 AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, 8000, 80, 256), | 187 AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, 8000, 80, 256), |
(...skipping 12 matching lines...) Expand all Loading... |
205 std::string())); | 200 std::string())); |
206 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 201 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
207 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, | 202 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, |
208 media::limits::kMaxSamplesPerPacket + 1), | 203 media::limits::kMaxSamplesPerPacket + 1), |
209 std::string())); | 204 std::string())); |
210 } | 205 } |
211 | 206 |
212 // Test that it can be opened and closed. | 207 // Test that it can be opened and closed. |
213 TEST(WinAudioTest, PCMWaveStreamOpenAndClose) { | 208 TEST(WinAudioTest, PCMWaveStreamOpenAndClose) { |
214 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 209 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
215 if (!audio_man->HasAudioOutputDevices()) { | 210 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); |
216 LOG(WARNING) << "No output device detected."; | |
217 return; | |
218 } | |
219 | 211 |
220 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 212 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
221 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | 213 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, |
222 8000, 16, 256), | 214 8000, 16, 256), |
223 std::string()); | 215 std::string()); |
224 ASSERT_TRUE(NULL != oas); | 216 ASSERT_TRUE(NULL != oas); |
225 EXPECT_TRUE(oas->Open()); | 217 EXPECT_TRUE(oas->Open()); |
226 oas->Close(); | 218 oas->Close(); |
227 } | 219 } |
228 | 220 |
229 // Test that it has a maximum packet size. | 221 // Test that it has a maximum packet size. |
230 TEST(WinAudioTest, PCMWaveStreamOpenLimit) { | 222 TEST(WinAudioTest, PCMWaveStreamOpenLimit) { |
231 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 223 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
232 if (!audio_man->HasAudioOutputDevices()) { | 224 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); |
233 LOG(WARNING) << "No output device detected."; | |
234 return; | |
235 } | |
236 | 225 |
237 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 226 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
238 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | 227 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, |
239 8000, 16, 1024 * 1024 * 1024), | 228 8000, 16, 1024 * 1024 * 1024), |
240 std::string()); | 229 std::string()); |
241 EXPECT_TRUE(NULL == oas); | 230 EXPECT_TRUE(NULL == oas); |
242 if (oas) | 231 if (oas) |
243 oas->Close(); | 232 oas->Close(); |
244 } | 233 } |
245 | 234 |
246 // Test potential deadlock situation if the source is slow or blocks for some | 235 // Test potential deadlock situation if the source is slow or blocks for some |
247 // time. The actual EXPECT_GT are mostly meaningless and the real test is that | 236 // time. The actual EXPECT_GT are mostly meaningless and the real test is that |
248 // the test completes in reasonable time. | 237 // the test completes in reasonable time. |
249 TEST(WinAudioTest, PCMWaveSlowSource) { | 238 TEST(WinAudioTest, PCMWaveSlowSource) { |
250 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 239 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
251 if (!audio_man->HasAudioOutputDevices()) { | 240 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); |
252 LOG(WARNING) << "No output device detected."; | |
253 return; | |
254 } | |
255 | 241 |
256 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 242 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
257 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 243 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
258 16000, 16, 256), | 244 16000, 16, 256), |
259 std::string()); | 245 std::string()); |
260 ASSERT_TRUE(NULL != oas); | 246 ASSERT_TRUE(NULL != oas); |
261 TestSourceLaggy test_laggy(2, 90); | 247 TestSourceLaggy test_laggy(2, 90); |
262 EXPECT_TRUE(oas->Open()); | 248 EXPECT_TRUE(oas->Open()); |
263 // The test parameters cause a callback every 32 ms and the source is | 249 // The test parameters cause a callback every 32 ms and the source is |
264 // sleeping for 90 ms, so it is guaranteed that we run out of ready buffers. | 250 // sleeping for 90 ms, so it is guaranteed that we run out of ready buffers. |
265 oas->Start(&test_laggy); | 251 oas->Start(&test_laggy); |
266 ::Sleep(500); | 252 ::Sleep(500); |
267 EXPECT_GT(test_laggy.callback_count(), 2); | 253 EXPECT_GT(test_laggy.callback_count(), 2); |
268 EXPECT_FALSE(test_laggy.had_error()); | 254 EXPECT_FALSE(test_laggy.had_error()); |
269 oas->Stop(); | 255 oas->Stop(); |
270 ::Sleep(500); | 256 ::Sleep(500); |
271 oas->Close(); | 257 oas->Close(); |
272 } | 258 } |
273 | 259 |
274 // Test another potential deadlock situation if the thread that calls Start() | 260 // Test another potential deadlock situation if the thread that calls Start() |
275 // gets paused. This test is best when run over RDP with audio enabled. See | 261 // gets paused. This test is best when run over RDP with audio enabled. See |
276 // bug 19276 for more details. | 262 // bug 19276 for more details. |
277 TEST(WinAudioTest, PCMWaveStreamPlaySlowLoop) { | 263 TEST(WinAudioTest, PCMWaveStreamPlaySlowLoop) { |
278 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 264 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
279 if (!audio_man->HasAudioOutputDevices()) { | 265 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); |
280 LOG(WARNING) << "No output device detected."; | |
281 return; | |
282 } | |
283 | 266 |
284 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 267 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
285 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 268 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
286 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 269 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
287 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), | 270 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), |
288 std::string()); | 271 std::string()); |
289 ASSERT_TRUE(NULL != oas); | 272 ASSERT_TRUE(NULL != oas); |
290 | 273 |
291 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); | 274 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); |
292 | 275 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 oas->Stop(); | 311 oas->Stop(); |
329 oas->Close(); | 312 oas->Close(); |
330 } | 313 } |
331 | 314 |
332 // This test produces actual audio for for .5 seconds on the default wave | 315 // This test produces actual audio for for .5 seconds on the default wave |
333 // device at 22K s/sec. Parameters have been chosen carefully so you should | 316 // device at 22K s/sec. Parameters have been chosen carefully so you should |
334 // not hear pops or noises while the sound is playing. The audio also should | 317 // not hear pops or noises while the sound is playing. The audio also should |
335 // sound with a lower volume than PCMWaveStreamPlay200HzTone44Kss. | 318 // sound with a lower volume than PCMWaveStreamPlay200HzTone44Kss. |
336 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) { | 319 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) { |
337 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 320 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
338 if (!audio_man->HasAudioOutputDevices()) { | 321 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); |
339 LOG(WARNING) << "No output device detected."; | |
340 return; | |
341 } | |
342 | 322 |
343 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 20; | 323 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 20; |
344 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 324 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
345 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 325 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
346 AudioParameters::kAudioCDSampleRate / 2, 16, | 326 AudioParameters::kAudioCDSampleRate / 2, 16, |
347 samples_100_ms), | 327 samples_100_ms), |
348 std::string()); | 328 std::string()); |
349 ASSERT_TRUE(NULL != oas); | 329 ASSERT_TRUE(NULL != oas); |
350 | 330 |
351 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate/2); | 331 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate/2); |
(...skipping 11 matching lines...) Expand all Loading... |
363 EXPECT_GT(volume, 0.49); | 343 EXPECT_GT(volume, 0.49); |
364 oas->Stop(); | 344 oas->Stop(); |
365 oas->Close(); | 345 oas->Close(); |
366 } | 346 } |
367 | 347 |
368 // Uses a restricted source to play ~2 seconds of audio for about 5 seconds. We | 348 // Uses a restricted source to play ~2 seconds of audio for about 5 seconds. We |
369 // try hard to generate situation where the two threads are accessing the | 349 // try hard to generate situation where the two threads are accessing the |
370 // object roughly at the same time. | 350 // object roughly at the same time. |
371 TEST(WinAudioTest, PushSourceFile16KHz) { | 351 TEST(WinAudioTest, PushSourceFile16KHz) { |
372 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 352 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
373 if (!audio_man->HasAudioOutputDevices()) { | 353 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); |
374 LOG(WARNING) << "No output device detected."; | |
375 return; | |
376 } | |
377 | 354 |
378 static const int kSampleRate = 16000; | 355 static const int kSampleRate = 16000; |
379 SineWaveAudioSource source(1, 200.0, kSampleRate); | 356 SineWaveAudioSource source(1, 200.0, kSampleRate); |
380 // Compute buffer size for 100ms of audio. | 357 // Compute buffer size for 100ms of audio. |
381 const uint32 kSamples100ms = (kSampleRate / 1000) * 100; | 358 const uint32 kSamples100ms = (kSampleRate / 1000) * 100; |
382 // Restrict SineWaveAudioSource to 100ms of samples. | 359 // Restrict SineWaveAudioSource to 100ms of samples. |
383 source.CapSamples(kSamples100ms); | 360 source.CapSamples(kSamples100ms); |
384 | 361 |
385 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 362 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
386 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 363 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
(...skipping 19 matching lines...) Expand all Loading... |
406 | 383 |
407 oas->Stop(); | 384 oas->Stop(); |
408 oas->Close(); | 385 oas->Close(); |
409 } | 386 } |
410 | 387 |
411 // This test is to make sure an AudioOutputStream can be started after it was | 388 // This test is to make sure an AudioOutputStream can be started after it was |
412 // stopped. You will here two .5 seconds wave signal separated by 0.5 seconds | 389 // stopped. You will here two .5 seconds wave signal separated by 0.5 seconds |
413 // of silence. | 390 // of silence. |
414 TEST(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) { | 391 TEST(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) { |
415 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 392 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
416 if (!audio_man->HasAudioOutputDevices()) { | 393 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); |
417 LOG(WARNING) << "No output device detected."; | |
418 return; | |
419 } | |
420 | 394 |
421 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 395 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
422 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 396 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
423 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 397 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
424 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), | 398 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), |
425 std::string()); | 399 std::string()); |
426 ASSERT_TRUE(NULL != oas); | 400 ASSERT_TRUE(NULL != oas); |
427 | 401 |
428 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); | 402 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); |
429 EXPECT_TRUE(oas->Open()); | 403 EXPECT_TRUE(oas->Open()); |
(...skipping 13 matching lines...) Expand all Loading... |
443 oas->Stop(); | 417 oas->Stop(); |
444 | 418 |
445 oas->Close(); | 419 oas->Close(); |
446 } | 420 } |
447 | 421 |
448 // With the low latency mode, WASAPI is utilized by default for Vista and | 422 // With the low latency mode, WASAPI is utilized by default for Vista and |
449 // higher and Wave is used for XP and lower. It is possible to utilize a | 423 // higher and Wave is used for XP and lower. It is possible to utilize a |
450 // smaller buffer size for WASAPI than for Wave. | 424 // smaller buffer size for WASAPI than for Wave. |
451 TEST(WinAudioTest, PCMWaveStreamPlay200HzToneLowLatency) { | 425 TEST(WinAudioTest, PCMWaveStreamPlay200HzToneLowLatency) { |
452 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 426 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
453 if (!audio_man->HasAudioOutputDevices()) { | 427 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); |
454 LOG(WARNING) << "No output device detected."; | |
455 return; | |
456 } | |
457 | 428 |
458 // The WASAPI API requires a correct COM environment. | 429 // The WASAPI API requires a correct COM environment. |
459 ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); | 430 ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); |
460 | 431 |
461 // Use 10 ms buffer size for WASAPI and 50 ms buffer size for Wave. | 432 // Use 10 ms buffer size for WASAPI and 50 ms buffer size for Wave. |
462 // Take the existing native sample rate into account. | 433 // Take the existing native sample rate into account. |
463 const AudioParameters params = audio_man->GetDefaultOutputStreamParameters(); | 434 const AudioParameters params = audio_man->GetDefaultOutputStreamParameters(); |
464 int sample_rate = params.sample_rate(); | 435 int sample_rate = params.sample_rate(); |
465 uint32 samples_10_ms = sample_rate / 100; | 436 uint32 samples_10_ms = sample_rate / 100; |
466 int n = 1; | 437 int n = 1; |
(...skipping 20 matching lines...) Expand all Loading... |
487 // Play the wave for .8 seconds. | 458 // Play the wave for .8 seconds. |
488 oas->Start(&source); | 459 oas->Start(&source); |
489 ::Sleep(800); | 460 ::Sleep(800); |
490 oas->Stop(); | 461 oas->Stop(); |
491 oas->Close(); | 462 oas->Close(); |
492 } | 463 } |
493 | 464 |
494 // Check that the pending bytes value is correct what the stream starts. | 465 // Check that the pending bytes value is correct what the stream starts. |
495 TEST(WinAudioTest, PCMWaveStreamPendingBytes) { | 466 TEST(WinAudioTest, PCMWaveStreamPendingBytes) { |
496 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 467 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
497 if (!audio_man->HasAudioOutputDevices()) { | 468 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); |
498 LOG(WARNING) << "No output device detected."; | |
499 return; | |
500 } | |
501 | 469 |
502 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 470 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
503 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 471 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
504 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 472 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
505 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), | 473 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), |
506 std::string()); | 474 std::string()); |
507 ASSERT_TRUE(NULL != oas); | 475 ASSERT_TRUE(NULL != oas); |
508 | 476 |
509 NiceMock<MockAudioSourceCallback> source; | 477 NiceMock<MockAudioSourceCallback> source; |
510 EXPECT_TRUE(oas->Open()); | 478 EXPECT_TRUE(oas->Open()); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 // Test the basic operation of AudioOutputStream used with a SyncSocket. | 591 // Test the basic operation of AudioOutputStream used with a SyncSocket. |
624 // The emphasis is to verify that it is possible to feed data to the audio | 592 // The emphasis is to verify that it is possible to feed data to the audio |
625 // layer using a source based on SyncSocket. In a real situation we would | 593 // layer using a source based on SyncSocket. In a real situation we would |
626 // go for the low-latency version in combination with SyncSocket, but to keep | 594 // go for the low-latency version in combination with SyncSocket, but to keep |
627 // the test more simple, AUDIO_PCM_LINEAR is utilized instead. The main | 595 // the test more simple, AUDIO_PCM_LINEAR is utilized instead. The main |
628 // principle of the test still remains and we avoid the additional complexity | 596 // principle of the test still remains and we avoid the additional complexity |
629 // related to the two different audio-layers for AUDIO_PCM_LOW_LATENCY. | 597 // related to the two different audio-layers for AUDIO_PCM_LOW_LATENCY. |
630 // In this test you should hear a continuous 200Hz tone for 2 seconds. | 598 // In this test you should hear a continuous 200Hz tone for 2 seconds. |
631 TEST(WinAudioTest, SyncSocketBasic) { | 599 TEST(WinAudioTest, SyncSocketBasic) { |
632 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 600 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
633 if (!audio_man->HasAudioOutputDevices()) { | 601 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); |
634 LOG(WARNING) << "No output device detected."; | |
635 return; | |
636 } | |
637 | 602 |
638 static const int sample_rate = AudioParameters::kAudioCDSampleRate; | 603 static const int sample_rate = AudioParameters::kAudioCDSampleRate; |
639 static const uint32 kSamples20ms = sample_rate / 50; | 604 static const uint32 kSamples20ms = sample_rate / 50; |
640 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, | 605 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
641 CHANNEL_LAYOUT_MONO, sample_rate, 16, kSamples20ms); | 606 CHANNEL_LAYOUT_MONO, sample_rate, 16, kSamples20ms); |
642 | 607 |
643 | 608 |
644 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(params, | 609 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(params, |
645 std::string()); | 610 std::string()); |
646 ASSERT_TRUE(NULL != oas); | 611 ASSERT_TRUE(NULL != oas); |
(...skipping 19 matching lines...) Expand all Loading... |
666 oas->Start(&source); | 631 oas->Start(&source); |
667 | 632 |
668 ::WaitForSingleObject(thread, INFINITE); | 633 ::WaitForSingleObject(thread, INFINITE); |
669 ::CloseHandle(thread); | 634 ::CloseHandle(thread); |
670 | 635 |
671 oas->Stop(); | 636 oas->Stop(); |
672 oas->Close(); | 637 oas->Close(); |
673 } | 638 } |
674 | 639 |
675 } // namespace media | 640 } // namespace media |
OLD | NEW |