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/environment.h" | 9 #include "base/environment.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 using ::testing::Gt; | 33 using ::testing::Gt; |
34 using ::testing::InvokeWithoutArgs; | 34 using ::testing::InvokeWithoutArgs; |
35 using ::testing::NotNull; | 35 using ::testing::NotNull; |
36 using ::testing::Return; | 36 using ::testing::Return; |
37 using base::win::ScopedCOMInitializer; | 37 using base::win::ScopedCOMInitializer; |
38 | 38 |
39 namespace media { | 39 namespace media { |
40 | 40 |
41 static const char kSpeechFile_16b_s_48k[] = "speech_16b_stereo_48kHz.raw"; | 41 static const char kSpeechFile_16b_s_48k[] = "speech_16b_stereo_48kHz.raw"; |
42 static const char kSpeechFile_16b_s_44k[] = "speech_16b_stereo_44kHz.raw"; | 42 static const char kSpeechFile_16b_s_44k[] = "speech_16b_stereo_44kHz.raw"; |
| 43 static const char kSpeechFile_16b_m_48k[] = "speech_16b_mono_48kHz.raw"; |
| 44 static const char kSpeechFile_16b_m_44k[] = "speech_16b_mono_44kHz.raw"; |
43 static const size_t kFileDurationMs = 20000; | 45 static const size_t kFileDurationMs = 20000; |
44 static const size_t kNumFileSegments = 2; | 46 static const size_t kNumFileSegments = 2; |
45 | 47 |
46 static const size_t kMaxDeltaSamples = 1000; | 48 static const size_t kMaxDeltaSamples = 1000; |
47 static const char* kDeltaTimeMsFileName = "delta_times_ms.txt"; | 49 static const char* kDeltaTimeMsFileName = "delta_times_ms.txt"; |
48 | 50 |
49 MATCHER_P(HasValidDelay, value, "") { | 51 MATCHER_P(HasValidDelay, value, "") { |
50 // It is difficult to come up with a perfect test condition for the delay | 52 // It is difficult to come up with a perfect test condition for the delay |
51 // estimation. For now, verify that the produced output delay is always | 53 // estimation. For now, verify that the produced output delay is always |
52 // larger than the selected buffer size. | 54 // larger than the selected buffer size. |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 AudioOutputStreamWrapper aosw(audio_manager); | 243 AudioOutputStreamWrapper aosw(audio_manager); |
242 AudioOutputStream* aos = aosw.Create(); | 244 AudioOutputStream* aos = aosw.Create(); |
243 return aos; | 245 return aos; |
244 } | 246 } |
245 | 247 |
246 // Verify that we can retrieve the current hardware/mixing sample rate | 248 // Verify that we can retrieve the current hardware/mixing sample rate |
247 // for all supported device roles. The ERole enumeration defines constants | 249 // for all supported device roles. The ERole enumeration defines constants |
248 // that indicate the role that the system/user has assigned to an audio | 250 // that indicate the role that the system/user has assigned to an audio |
249 // endpoint device. | 251 // endpoint device. |
250 // TODO(henrika): modify this test when we support full device enumeration. | 252 // TODO(henrika): modify this test when we support full device enumeration. |
251 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestHardwareSampleRate) { | 253 TEST(WASAPIAudioOutputStreamTest, HardwareSampleRate) { |
252 // Skip this test in exclusive mode since the resulting rate is only utilized | 254 // Skip this test in exclusive mode since the resulting rate is only utilized |
253 // for shared mode streams. | 255 // for shared mode streams. |
254 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 256 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
255 if (!CanRunAudioTests(audio_manager.get()) || ExclusiveModeIsEnabled()) | 257 if (!CanRunAudioTests(audio_manager.get()) || ExclusiveModeIsEnabled()) |
256 return; | 258 return; |
257 | 259 |
258 ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); | 260 ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); |
259 | 261 |
260 // Default device intended for games, system notification sounds, | 262 // Default device intended for games, system notification sounds, |
261 // and voice commands. | 263 // and voice commands. |
262 int fs = static_cast<int>( | 264 int fs = static_cast<int>( |
263 WASAPIAudioOutputStream::HardwareSampleRate(eConsole)); | 265 WASAPIAudioOutputStream::HardwareSampleRate(eConsole)); |
264 EXPECT_GE(fs, 0); | 266 EXPECT_GE(fs, 0); |
265 | 267 |
266 // Default communication device intended for e.g. VoIP communication. | 268 // Default communication device intended for e.g. VoIP communication. |
267 fs = static_cast<int>( | 269 fs = static_cast<int>( |
268 WASAPIAudioOutputStream::HardwareSampleRate(eCommunications)); | 270 WASAPIAudioOutputStream::HardwareSampleRate(eCommunications)); |
269 EXPECT_GE(fs, 0); | 271 EXPECT_GE(fs, 0); |
270 | 272 |
271 // Multimedia device for music, movies and live music recording. | 273 // Multimedia device for music, movies and live music recording. |
272 fs = static_cast<int>( | 274 fs = static_cast<int>( |
273 WASAPIAudioOutputStream::HardwareSampleRate(eMultimedia)); | 275 WASAPIAudioOutputStream::HardwareSampleRate(eMultimedia)); |
274 EXPECT_GE(fs, 0); | 276 EXPECT_GE(fs, 0); |
275 } | 277 } |
276 | 278 |
277 // Test Create(), Close() calling sequence. | 279 // Test Create(), Close() calling sequence. |
278 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestCreateAndClose) { | 280 TEST(WASAPIAudioOutputStreamTest, CreateAndClose) { |
279 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 281 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
280 if (!CanRunAudioTests(audio_manager.get())) | 282 if (!CanRunAudioTests(audio_manager.get())) |
281 return; | 283 return; |
282 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 284 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
283 aos->Close(); | 285 aos->Close(); |
284 } | 286 } |
285 | 287 |
286 // Test Open(), Close() calling sequence. | 288 // Verify that the created object is configured to use the same number of |
287 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestOpenAndClose) { | 289 // audio channels as is reported by the static HardwareChannelCount() method. |
| 290 TEST(WASAPIAudioOutputStreamTest, HardwareChannelCount) { |
288 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 291 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
289 if (!CanRunAudioTests(audio_manager.get())) | 292 if (!CanRunAudioTests(audio_manager.get())) |
290 return; | 293 return; |
| 294 |
| 295 ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); |
| 296 |
| 297 // First, verify that we can read a valid native/hardware channel-count. |
| 298 int hardware_channel_count = WASAPIAudioOutputStream::HardwareChannelCount(); |
| 299 EXPECT_GE(hardware_channel_count, 1); |
| 300 |
| 301 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 302 WASAPIAudioOutputStream* aos = |
| 303 static_cast<WASAPIAudioOutputStream*>(aosw.Create(CHANNEL_LAYOUT_MONO)); |
| 304 |
| 305 // Next, ensure that the created output stream object is really using the |
| 306 // hardware channel-count. |
| 307 EXPECT_EQ(hardware_channel_count, aos->endpoint_channel_count()); |
| 308 aos->Close(); |
| 309 |
| 310 // Try to use a non-supported combination of channel configurations if the |
| 311 // number of hardware channels is 2. |
| 312 if (hardware_channel_count == 2) { |
| 313 // It should be possible to create and object even for an invalid channel- |
| 314 // count combination (7.1 -> 2). |
| 315 WASAPIAudioOutputStream* aos = |
| 316 static_cast<WASAPIAudioOutputStream*>(aosw.Create(CHANNEL_LAYOUT_7_1)); |
| 317 |
| 318 // But an attempt to open a stream shall fail since down-mixing is not |
| 319 // yet supported. |
| 320 EXPECT_FALSE(aos->Open()); |
| 321 aos->Close(); |
| 322 } |
| 323 } |
| 324 |
| 325 // Test Open(), Close() calling sequence. |
| 326 TEST(WASAPIAudioOutputStreamTest, OpenAndClose) { |
| 327 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 328 if (!CanRunAudioTests(audio_manager.get())) |
| 329 return; |
291 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 330 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
292 EXPECT_TRUE(aos->Open()); | 331 EXPECT_TRUE(aos->Open()); |
293 aos->Close(); | 332 aos->Close(); |
294 } | 333 } |
295 | 334 |
296 // Test Open(), Start(), Close() calling sequence. | 335 // Test Open(), Start(), Close() calling sequence. |
297 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestOpenStartAndClose) { | 336 TEST(WASAPIAudioOutputStreamTest, OpenStartAndClose) { |
298 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 337 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
299 if (!CanRunAudioTests(audio_manager.get())) | 338 if (!CanRunAudioTests(audio_manager.get())) |
300 return; | 339 return; |
301 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 340 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
302 EXPECT_TRUE(aos->Open()); | 341 EXPECT_TRUE(aos->Open()); |
303 MockAudioSourceCallback source; | 342 MockAudioSourceCallback source; |
304 EXPECT_CALL(source, OnError(aos, _)) | 343 EXPECT_CALL(source, OnError(aos, _)) |
305 .Times(0); | 344 .Times(0); |
306 aos->Start(&source); | 345 aos->Start(&source); |
307 aos->Close(); | 346 aos->Close(); |
308 } | 347 } |
309 | 348 |
310 // Test Open(), Start(), Stop(), Close() calling sequence. | 349 // Test Open(), Start(), Stop(), Close() calling sequence. |
311 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestOpenStartStopAndClose) { | 350 TEST(WASAPIAudioOutputStreamTest, OpenStartStopAndClose) { |
312 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 351 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
313 if (!CanRunAudioTests(audio_manager.get())) | 352 if (!CanRunAudioTests(audio_manager.get())) |
314 return; | 353 return; |
315 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 354 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
316 EXPECT_TRUE(aos->Open()); | 355 EXPECT_TRUE(aos->Open()); |
317 MockAudioSourceCallback source; | 356 MockAudioSourceCallback source; |
318 EXPECT_CALL(source, OnError(aos, _)) | 357 EXPECT_CALL(source, OnError(aos, _)) |
319 .Times(0); | 358 .Times(0); |
320 aos->Start(&source); | 359 aos->Start(&source); |
321 aos->Stop(); | 360 aos->Stop(); |
322 aos->Close(); | 361 aos->Close(); |
323 } | 362 } |
324 | 363 |
325 // Test SetVolume(), GetVolume() | 364 // Test SetVolume(), GetVolume() |
326 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestVolume) { | 365 TEST(WASAPIAudioOutputStreamTest, Volume) { |
327 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 366 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
328 if (!CanRunAudioTests(audio_manager.get())) | 367 if (!CanRunAudioTests(audio_manager.get())) |
329 return; | 368 return; |
330 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 369 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
331 | 370 |
332 // Initial volume should be full volume (1.0). | 371 // Initial volume should be full volume (1.0). |
333 double volume = 0.0; | 372 double volume = 0.0; |
334 aos->GetVolume(&volume); | 373 aos->GetVolume(&volume); |
335 EXPECT_EQ(1.0, volume); | 374 EXPECT_EQ(1.0, volume); |
336 | 375 |
(...skipping 16 matching lines...) Expand all Loading... |
353 EXPECT_EQ(1.0, volume); | 392 EXPECT_EQ(1.0, volume); |
354 | 393 |
355 aos->SetVolume(-0.5); | 394 aos->SetVolume(-0.5); |
356 aos->GetVolume(&volume); | 395 aos->GetVolume(&volume); |
357 EXPECT_EQ(1.0, volume); | 396 EXPECT_EQ(1.0, volume); |
358 | 397 |
359 aos->Close(); | 398 aos->Close(); |
360 } | 399 } |
361 | 400 |
362 // Test some additional calling sequences. | 401 // Test some additional calling sequences. |
363 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestMiscCallingSequences) { | 402 TEST(WASAPIAudioOutputStreamTest, MiscCallingSequences) { |
364 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 403 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
365 if (!CanRunAudioTests(audio_manager.get())) | 404 if (!CanRunAudioTests(audio_manager.get())) |
366 return; | 405 return; |
367 | 406 |
368 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 407 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
369 WASAPIAudioOutputStream* waos = static_cast<WASAPIAudioOutputStream*>(aos); | 408 WASAPIAudioOutputStream* waos = static_cast<WASAPIAudioOutputStream*>(aos); |
370 | 409 |
371 // Open(), Open() is a valid calling sequence (second call does nothing). | 410 // Open(), Open() is a valid calling sequence (second call does nothing). |
372 EXPECT_TRUE(aos->Open()); | 411 EXPECT_TRUE(aos->Open()); |
373 EXPECT_TRUE(aos->Open()); | 412 EXPECT_TRUE(aos->Open()); |
(...skipping 19 matching lines...) Expand all Loading... |
393 EXPECT_FALSE(waos->started()); | 432 EXPECT_FALSE(waos->started()); |
394 aos->Start(&source); | 433 aos->Start(&source); |
395 EXPECT_TRUE(waos->started()); | 434 EXPECT_TRUE(waos->started()); |
396 aos->Stop(); | 435 aos->Stop(); |
397 EXPECT_FALSE(waos->started()); | 436 EXPECT_FALSE(waos->started()); |
398 | 437 |
399 aos->Close(); | 438 aos->Close(); |
400 } | 439 } |
401 | 440 |
402 // Use default packet size (10ms) and verify that rendering starts. | 441 // Use default packet size (10ms) and verify that rendering starts. |
403 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestPacketSizeInMilliseconds) { | 442 TEST(WASAPIAudioOutputStreamTest, PacketSizeInMilliseconds) { |
404 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 443 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
405 if (!CanRunAudioTests(audio_manager.get())) | 444 if (!CanRunAudioTests(audio_manager.get())) |
406 return; | 445 return; |
407 | 446 |
408 MessageLoopForUI loop; | 447 MessageLoopForUI loop; |
409 MockAudioSourceCallback source; | 448 MockAudioSourceCallback source; |
410 | 449 |
411 // Create default WASAPI output stream which plays out in stereo using | 450 // Create default WASAPI output stream which plays out in stereo using |
412 // the shared mixing rate. The default buffer size is 10ms. | 451 // the shared mixing rate. The default buffer size is 10ms. |
413 AudioOutputStreamWrapper aosw(audio_manager.get()); | 452 AudioOutputStreamWrapper aosw(audio_manager.get()); |
(...skipping 17 matching lines...) Expand all Loading... |
431 aos->Start(&source); | 470 aos->Start(&source); |
432 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), | 471 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
433 TestTimeouts::action_timeout()); | 472 TestTimeouts::action_timeout()); |
434 loop.Run(); | 473 loop.Run(); |
435 aos->Stop(); | 474 aos->Stop(); |
436 aos->Close(); | 475 aos->Close(); |
437 } | 476 } |
438 | 477 |
439 // Use a fixed packets size (independent of sample rate) and verify | 478 // Use a fixed packets size (independent of sample rate) and verify |
440 // that rendering starts. | 479 // that rendering starts. |
441 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestPacketSizeInSamples) { | 480 TEST(WASAPIAudioOutputStreamTest, PacketSizeInSamples) { |
442 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 481 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
443 if (!CanRunAudioTests(audio_manager.get())) | 482 if (!CanRunAudioTests(audio_manager.get())) |
444 return; | 483 return; |
445 | 484 |
446 MessageLoopForUI loop; | 485 MessageLoopForUI loop; |
447 MockAudioSourceCallback source; | 486 MockAudioSourceCallback source; |
448 | 487 |
449 // Create default WASAPI output stream which plays out in stereo using | 488 // Create default WASAPI output stream which reads data in stereo using |
450 // the shared mixing rate. The buffer size is set to 1024 samples. | 489 // the native mixing rate and channel count. The buffer size is set to |
| 490 // 1024 samples. |
451 AudioOutputStreamWrapper aosw(audio_manager.get()); | 491 AudioOutputStreamWrapper aosw(audio_manager.get()); |
452 AudioOutputStream* aos = aosw.Create(1024); | 492 AudioOutputStream* aos = aosw.Create(1024); |
453 EXPECT_TRUE(aos->Open()); | 493 EXPECT_TRUE(aos->Open()); |
454 | 494 |
455 // Derive the expected size in bytes of each packet. | 495 // Derive the expected size in bytes of each packet. |
456 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * | 496 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * |
457 (aosw.bits_per_sample() / 8); | 497 (aosw.bits_per_sample() / 8); |
458 | 498 |
459 // Set up expected minimum delay estimation. | 499 // Set up expected minimum delay estimation. |
460 AudioBuffersState state(0, bytes_per_packet); | 500 AudioBuffersState state(0, bytes_per_packet); |
461 | 501 |
462 // Ensure that callbacks start correctly. | 502 // Ensure that callbacks start correctly. |
463 EXPECT_CALL(source, OnMoreData(NotNull(), bytes_per_packet, | 503 EXPECT_CALL(source, OnMoreData(NotNull(), bytes_per_packet, |
464 HasValidDelay(state))) | 504 HasValidDelay(state))) |
465 .WillOnce(DoAll( | 505 .WillOnce(DoAll( |
466 QuitLoop(loop.message_loop_proxy()), | 506 QuitLoop(loop.message_loop_proxy()), |
467 Return(bytes_per_packet))) | 507 Return(bytes_per_packet))) |
468 .WillRepeatedly(Return(bytes_per_packet)); | 508 .WillRepeatedly(Return(bytes_per_packet)); |
469 | 509 |
470 aos->Start(&source); | 510 aos->Start(&source); |
471 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), | 511 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
472 TestTimeouts::action_timeout()); | 512 TestTimeouts::action_timeout()); |
473 loop.Run(); | 513 loop.Run(); |
474 aos->Stop(); | 514 aos->Stop(); |
475 aos->Close(); | 515 aos->Close(); |
476 } | 516 } |
477 | 517 |
478 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestMono) { | 518 TEST(WASAPIAudioOutputStreamTest, Mono) { |
479 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 519 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
480 if (!CanRunAudioTests(audio_manager.get())) | 520 if (!CanRunAudioTests(audio_manager.get())) |
481 return; | 521 return; |
482 | 522 |
483 MessageLoopForUI loop; | 523 MessageLoopForUI loop; |
484 MockAudioSourceCallback source; | 524 MockAudioSourceCallback source; |
485 | 525 |
486 // Create default WASAPI output stream which plays out in *mono* using | 526 // Create default WASAPI output stream which reads data *mono* using |
487 // the shared mixing rate. The default buffer size is 10ms. | 527 // the native mixing rate and channel count. The default buffer size is 10ms. |
488 AudioOutputStreamWrapper aosw(audio_manager.get()); | 528 AudioOutputStreamWrapper aosw(audio_manager.get()); |
489 AudioOutputStream* aos = aosw.Create(CHANNEL_LAYOUT_MONO); | 529 AudioOutputStream* aos = aosw.Create(CHANNEL_LAYOUT_MONO); |
| 530 EXPECT_TRUE(aos->Open()); |
490 | 531 |
491 bool opened = aos->Open(); | |
492 if (!opened) { | |
493 // It was not possible to open this audio device in mono. | |
494 // No point in continuing the test so let's break here. | |
495 LOG(WARNING) << "Mono is not supported. Skipping test."; | |
496 aos->Close(); | |
497 return; | |
498 } | |
499 // Derive the expected size in bytes of each packet. | 532 // Derive the expected size in bytes of each packet. |
500 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * | 533 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * |
501 (aosw.bits_per_sample() / 8); | 534 (aosw.bits_per_sample() / 8); |
502 | 535 |
503 // Set up expected minimum delay estimation. | 536 // Set up expected minimum delay estimation. |
504 AudioBuffersState state(0, bytes_per_packet); | 537 AudioBuffersState state(0, bytes_per_packet); |
505 | 538 |
506 EXPECT_CALL(source, OnMoreData(NotNull(), bytes_per_packet, | 539 EXPECT_CALL(source, OnMoreData(NotNull(), bytes_per_packet, |
507 HasValidDelay(state))) | 540 HasValidDelay(state))) |
508 .WillOnce(DoAll( | 541 .WillOnce(DoAll( |
509 QuitLoop(loop.message_loop_proxy()), | 542 QuitLoop(loop.message_loop_proxy()), |
510 Return(bytes_per_packet))) | 543 Return(bytes_per_packet))) |
511 .WillRepeatedly(Return(bytes_per_packet)); | 544 .WillRepeatedly(Return(bytes_per_packet)); |
512 | 545 |
513 aos->Start(&source); | 546 aos->Start(&source); |
514 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), | 547 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
515 TestTimeouts::action_timeout()); | 548 TestTimeouts::action_timeout()); |
516 loop.Run(); | 549 loop.Run(); |
517 aos->Stop(); | 550 aos->Stop(); |
518 aos->Close(); | 551 aos->Close(); |
519 } | 552 } |
520 | 553 |
521 // This test is intended for manual tests and should only be enabled | 554 // This test is intended for manual tests and should only be enabled |
522 // when it is required to store the captured data on a local file. | 555 // when it is required to play out data from a local PCM file. |
523 // By default, GTest will print out YOU HAVE 1 DISABLED TEST. | 556 // By default, GTest will print out YOU HAVE 1 DISABLED TEST. |
524 // To include disabled tests in test execution, just invoke the test program | 557 // To include disabled tests in test execution, just invoke the test program |
525 // with --gtest_also_run_disabled_tests or set the GTEST_ALSO_RUN_DISABLED_TESTS | 558 // with --gtest_also_run_disabled_tests or set the GTEST_ALSO_RUN_DISABLED_TESTS |
526 // environment variable to a value greater than 0. | 559 // environment variable to a value greater than 0. |
527 // The test files are approximately 20 seconds long. | 560 // The test files are approximately 20 seconds long. |
528 TEST(WinAudioOutputTest, DISABLED_WASAPIAudioOutputStreamReadFromFile) { | 561 TEST(WASAPIAudioOutputStreamTest, DISABLED_ReadFromStereoFile) { |
529 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 562 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
530 if (!CanRunAudioTests(audio_manager.get())) | 563 if (!CanRunAudioTests(audio_manager.get())) |
531 return; | 564 return; |
532 | 565 |
533 AudioOutputStreamWrapper aosw(audio_manager.get()); | 566 AudioOutputStreamWrapper aosw(audio_manager.get()); |
534 AudioOutputStream* aos = aosw.Create(); | 567 AudioOutputStream* aos = aosw.Create(); |
535 EXPECT_TRUE(aos->Open()); | 568 EXPECT_TRUE(aos->Open()); |
536 | 569 |
537 std::string file_name; | 570 std::string file_name; |
538 if (aosw.sample_rate() == 48000) { | 571 if (aosw.sample_rate() == 48000) { |
539 file_name = kSpeechFile_16b_s_48k; | 572 file_name = kSpeechFile_16b_s_48k; |
540 } else if (aosw.sample_rate() == 44100) { | 573 } else if (aosw.sample_rate() == 44100) { |
541 file_name = kSpeechFile_16b_s_44k; | 574 file_name = kSpeechFile_16b_s_44k; |
542 } else if (aosw.sample_rate() == 96000) { | 575 } else if (aosw.sample_rate() == 96000) { |
543 // Use 48kHz file at 96kHz as well. Will sound like Donald Duck. | 576 // Use 48kHz file at 96kHz as well. Will sound like Donald Duck. |
544 file_name = kSpeechFile_16b_s_48k; | 577 file_name = kSpeechFile_16b_s_48k; |
545 } else { | 578 } else { |
546 FAIL() << "This test supports 44.1, 48kHz and 96kHz only."; | 579 FAIL() << "This test supports 44.1, 48kHz and 96kHz only."; |
547 return; | 580 return; |
548 } | 581 } |
549 ReadFromFileAudioSource file_source(file_name); | 582 ReadFromFileAudioSource file_source(file_name); |
550 | 583 |
| 584 LOG(INFO) << "File name : " << file_name.c_str(); |
| 585 LOG(INFO) << "Sample rate : " << aosw.sample_rate(); |
| 586 LOG(INFO) << "Bits per sample: " << aosw.bits_per_sample(); |
| 587 LOG(INFO) << "#channels : " << aosw.channels(); |
| 588 LOG(INFO) << "File size : " << file_source.file_size(); |
| 589 LOG(INFO) << "#file segments : " << kNumFileSegments; |
| 590 LOG(INFO) << ">> Listen to the stereo file while playing..."; |
| 591 |
| 592 for (int i = 0; i < kNumFileSegments; i++) { |
| 593 // Each segment will start with a short (~20ms) block of zeros, hence |
| 594 // some short glitches might be heard in this test if kNumFileSegments |
| 595 // is larger than one. The exact length of the silence period depends on |
| 596 // the selected sample rate. |
| 597 aos->Start(&file_source); |
| 598 base::PlatformThread::Sleep( |
| 599 base::TimeDelta::FromMilliseconds(kFileDurationMs / kNumFileSegments)); |
| 600 aos->Stop(); |
| 601 } |
| 602 |
| 603 LOG(INFO) << ">> Stereo file playout has stopped."; |
| 604 aos->Close(); |
| 605 } |
| 606 |
| 607 // Same as the stereo test but reading and playing out a mono file instead. |
| 608 // It means that most likely a 1->2 channel up-mix will be performed. |
| 609 TEST(WASAPIAudioOutputStreamTest, DISABLED_ReadFromMonoFile) { |
| 610 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 611 if (!CanRunAudioTests(audio_manager.get())) |
| 612 return; |
| 613 |
| 614 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 615 AudioOutputStream* aos = aosw.Create(CHANNEL_LAYOUT_MONO); |
| 616 EXPECT_TRUE(aos->Open()); |
| 617 |
| 618 std::string file_name; |
| 619 if (aosw.sample_rate() == 48000) { |
| 620 file_name = kSpeechFile_16b_m_48k; |
| 621 } else if (aosw.sample_rate() == 44100) { |
| 622 file_name = kSpeechFile_16b_m_44k; |
| 623 } else if (aosw.sample_rate() == 96000) { |
| 624 // Use 48kHz file at 96kHz as well. Will sound like Donald Duck. |
| 625 file_name = kSpeechFile_16b_m_48k; |
| 626 } else { |
| 627 FAIL() << "This test supports 44.1, 48kHz and 96kHz only."; |
| 628 return; |
| 629 } |
| 630 ReadFromFileAudioSource file_source(file_name); |
| 631 |
551 LOG(INFO) << "File name : " << file_name.c_str(); | 632 LOG(INFO) << "File name : " << file_name.c_str(); |
552 LOG(INFO) << "Sample rate : " << aosw.sample_rate(); | 633 LOG(INFO) << "Sample rate : " << aosw.sample_rate(); |
| 634 LOG(INFO) << "#channels : " << aosw.channels(); |
553 LOG(INFO) << "File size : " << file_source.file_size(); | 635 LOG(INFO) << "File size : " << file_source.file_size(); |
554 LOG(INFO) << "#file segments: " << kNumFileSegments; | 636 LOG(INFO) << "#file segments: " << kNumFileSegments; |
555 LOG(INFO) << ">> Listen to the file while playing..."; | 637 LOG(INFO) << ">> Listen to the mono file while playing..."; |
556 | 638 |
557 for (int i = 0; i < kNumFileSegments; i++) { | 639 for (int i = 0; i < kNumFileSegments; i++) { |
558 // Each segment will start with a short (~20ms) block of zeros, hence | 640 // Each segment will start with a short (~20ms) block of zeros, hence |
559 // some short glitches might be heard in this test if kNumFileSegments | 641 // some short glitches might be heard in this test if kNumFileSegments |
560 // is larger than one. The exact length of the silence period depends on | 642 // is larger than one. The exact length of the silence period depends on |
561 // the selected sample rate. | 643 // the selected sample rate. |
562 aos->Start(&file_source); | 644 aos->Start(&file_source); |
563 base::PlatformThread::Sleep( | 645 base::PlatformThread::Sleep( |
564 base::TimeDelta::FromMilliseconds(kFileDurationMs / kNumFileSegments)); | 646 base::TimeDelta::FromMilliseconds(kFileDurationMs / kNumFileSegments)); |
565 aos->Stop(); | 647 aos->Stop(); |
566 } | 648 } |
567 | 649 |
568 LOG(INFO) << ">> File playout has stopped."; | 650 LOG(INFO) << ">> Mono file playout has stopped."; |
569 aos->Close(); | 651 aos->Close(); |
570 } | 652 } |
571 | 653 |
572 // Verify that we can open the output stream in exclusive mode using a | 654 // Verify that we can open the output stream in exclusive mode using a |
573 // certain set of audio parameters and a sample rate of 48kHz. | 655 // certain set of audio parameters and a sample rate of 48kHz. |
574 // The expected outcomes of each setting in this test has been derived | 656 // The expected outcomes of each setting in this test has been derived |
575 // manually using log outputs (--v=1). | 657 // manually using log outputs (--v=1). |
576 TEST(WinAudioOutputTest, WASAPIExclusiveModeBufferSizesAt48kHz) { | 658 TEST(WASAPIAudioOutputStreamTest, ExclusiveModeBufferSizesAt48kHz) { |
577 if (!ExclusiveModeIsEnabled()) | 659 if (!ExclusiveModeIsEnabled()) |
578 return; | 660 return; |
579 | 661 |
580 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 662 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
581 if (!CanRunAudioTests(audio_manager.get())) | 663 if (!CanRunAudioTests(audio_manager.get())) |
582 return; | 664 return; |
583 | 665 |
584 AudioOutputStreamWrapper aosw(audio_manager.get()); | 666 AudioOutputStreamWrapper aosw(audio_manager.get()); |
585 | 667 |
586 // 10ms @ 48kHz shall work. | 668 // 10ms @ 48kHz shall work. |
(...skipping 30 matching lines...) Expand all Loading... |
617 // 3.3333ms @ 48kHz <=> smallest possible buffer size we can use. | 699 // 3.3333ms @ 48kHz <=> smallest possible buffer size we can use. |
618 aos = aosw.Create(48000, 160); | 700 aos = aosw.Create(48000, 160); |
619 EXPECT_TRUE(aos->Open()); | 701 EXPECT_TRUE(aos->Open()); |
620 aos->Close(); | 702 aos->Close(); |
621 } | 703 } |
622 | 704 |
623 // Verify that we can open the output stream in exclusive mode using a | 705 // Verify that we can open the output stream in exclusive mode using a |
624 // certain set of audio parameters and a sample rate of 44.1kHz. | 706 // certain set of audio parameters and a sample rate of 44.1kHz. |
625 // The expected outcomes of each setting in this test has been derived | 707 // The expected outcomes of each setting in this test has been derived |
626 // manually using log outputs (--v=1). | 708 // manually using log outputs (--v=1). |
627 TEST(WinAudioOutputTest, WASAPIExclusiveModeBufferSizesAt44kHz) { | 709 TEST(WASAPIAudioOutputStreamTest, ExclusiveModeBufferSizesAt44kHz) { |
628 if (!ExclusiveModeIsEnabled()) | 710 if (!ExclusiveModeIsEnabled()) |
629 return; | 711 return; |
630 | 712 |
631 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 713 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
632 if (!CanRunAudioTests(audio_manager.get())) | 714 if (!CanRunAudioTests(audio_manager.get())) |
633 return; | 715 return; |
634 | 716 |
635 AudioOutputStreamWrapper aosw(audio_manager.get()); | 717 AudioOutputStreamWrapper aosw(audio_manager.get()); |
636 | 718 |
637 // 10ms @ 44.1kHz does not work due to misalignment. | 719 // 10ms @ 44.1kHz does not work due to misalignment. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 aos->Close(); | 757 aos->Close(); |
676 | 758 |
677 // 3.6281ms @ 44.1kHz <=> smallest possible buffer size we can use. | 759 // 3.6281ms @ 44.1kHz <=> smallest possible buffer size we can use. |
678 aos = aosw.Create(44100, 160); | 760 aos = aosw.Create(44100, 160); |
679 EXPECT_TRUE(aos->Open()); | 761 EXPECT_TRUE(aos->Open()); |
680 aos->Close(); | 762 aos->Close(); |
681 } | 763 } |
682 | 764 |
683 // Verify that we can open and start the output stream in exclusive mode at | 765 // Verify that we can open and start the output stream in exclusive mode at |
684 // the lowest possible delay at 48kHz. | 766 // the lowest possible delay at 48kHz. |
685 TEST(WinAudioOutputTest, WASAPIExclusiveModeMinBufferSizeAt48kHz) { | 767 TEST(WASAPIAudioOutputStreamTest, ExclusiveModeMinBufferSizeAt48kHz) { |
686 if (!ExclusiveModeIsEnabled()) | 768 if (!ExclusiveModeIsEnabled()) |
687 return; | 769 return; |
688 | 770 |
689 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 771 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
690 if (!CanRunAudioTests(audio_manager.get())) | 772 if (!CanRunAudioTests(audio_manager.get())) |
691 return; | 773 return; |
692 | 774 |
693 MessageLoopForUI loop; | 775 MessageLoopForUI loop; |
694 MockAudioSourceCallback source; | 776 MockAudioSourceCallback source; |
695 | 777 |
(...skipping 21 matching lines...) Expand all Loading... |
717 aos->Start(&source); | 799 aos->Start(&source); |
718 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), | 800 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
719 TestTimeouts::action_timeout()); | 801 TestTimeouts::action_timeout()); |
720 loop.Run(); | 802 loop.Run(); |
721 aos->Stop(); | 803 aos->Stop(); |
722 aos->Close(); | 804 aos->Close(); |
723 } | 805 } |
724 | 806 |
725 // Verify that we can open and start the output stream in exclusive mode at | 807 // Verify that we can open and start the output stream in exclusive mode at |
726 // the lowest possible delay at 44.1kHz. | 808 // the lowest possible delay at 44.1kHz. |
727 TEST(WinAudioOutputTest, WASAPIExclusiveModeMinBufferSizeAt44kHz) { | 809 TEST(WASAPIAudioOutputStreamTest, ExclusiveModeMinBufferSizeAt44kHz) { |
728 if (!ExclusiveModeIsEnabled()) | 810 if (!ExclusiveModeIsEnabled()) |
729 return; | 811 return; |
730 | 812 |
731 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 813 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
732 if (!CanRunAudioTests(audio_manager.get())) | 814 if (!CanRunAudioTests(audio_manager.get())) |
733 return; | 815 return; |
734 | 816 |
735 MessageLoopForUI loop; | 817 MessageLoopForUI loop; |
736 MockAudioSourceCallback source; | 818 MockAudioSourceCallback source; |
737 | 819 |
(...skipping 20 matching lines...) Expand all Loading... |
758 | 840 |
759 aos->Start(&source); | 841 aos->Start(&source); |
760 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), | 842 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
761 TestTimeouts::action_timeout()); | 843 TestTimeouts::action_timeout()); |
762 loop.Run(); | 844 loop.Run(); |
763 aos->Stop(); | 845 aos->Stop(); |
764 aos->Close(); | 846 aos->Close(); |
765 } | 847 } |
766 | 848 |
767 } // namespace media | 849 } // namespace media |
OLD | NEW |