| 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 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/environment.h" | 10 #include "base/environment.h" |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 } | 229 } |
| 230 | 230 |
| 231 // Verify that we can retrieve the current hardware/mixing sample rate | 231 // Verify that we can retrieve the current hardware/mixing sample rate |
| 232 // for the default audio device. | 232 // for the default audio device. |
| 233 // TODO(henrika): modify this test when we support full device enumeration. | 233 // TODO(henrika): modify this test when we support full device enumeration. |
| 234 TEST(WASAPIAudioOutputStreamTest, HardwareSampleRate) { | 234 TEST(WASAPIAudioOutputStreamTest, HardwareSampleRate) { |
| 235 // Skip this test in exclusive mode since the resulting rate is only utilized | 235 // Skip this test in exclusive mode since the resulting rate is only utilized |
| 236 // for shared mode streams. | 236 // for shared mode streams. |
| 237 if (ExclusiveModeIsEnabled()) | 237 if (ExclusiveModeIsEnabled()) |
| 238 return; | 238 return; |
| 239 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 239 base::MessageLoop loop; |
| 240 ScopedAudioManagerPtr audio_manager( |
| 241 AudioManager::CreateForTesting(loop.task_runner())); |
| 240 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get())); | 242 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get())); |
| 241 | 243 |
| 242 // Default device intended for games, system notification sounds, | 244 // Default device intended for games, system notification sounds, |
| 243 // and voice commands. | 245 // and voice commands. |
| 244 int fs = static_cast<int>( | 246 int fs = static_cast<int>( |
| 245 WASAPIAudioOutputStream::HardwareSampleRate(std::string())); | 247 WASAPIAudioOutputStream::HardwareSampleRate(std::string())); |
| 246 EXPECT_GE(fs, 0); | 248 EXPECT_GE(fs, 0); |
| 247 } | 249 } |
| 248 | 250 |
| 249 // Test Create(), Close() calling sequence. | 251 // Test Create(), Close() calling sequence. |
| 250 TEST(WASAPIAudioOutputStreamTest, CreateAndClose) { | 252 TEST(WASAPIAudioOutputStreamTest, CreateAndClose) { |
| 251 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 253 base::MessageLoop loop; |
| 254 ScopedAudioManagerPtr audio_manager( |
| 255 AudioManager::CreateForTesting(loop.task_runner())); |
| 252 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get())); | 256 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get())); |
| 253 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 257 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
| 254 aos->Close(); | 258 aos->Close(); |
| 255 } | 259 } |
| 256 | 260 |
| 257 // Test Open(), Close() calling sequence. | 261 // Test Open(), Close() calling sequence. |
| 258 TEST(WASAPIAudioOutputStreamTest, OpenAndClose) { | 262 TEST(WASAPIAudioOutputStreamTest, OpenAndClose) { |
| 259 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 263 base::MessageLoop loop; |
| 264 ScopedAudioManagerPtr audio_manager( |
| 265 AudioManager::CreateForTesting(loop.task_runner())); |
| 260 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get())); | 266 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get())); |
| 261 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 267 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
| 262 EXPECT_TRUE(aos->Open()); | 268 EXPECT_TRUE(aos->Open()); |
| 263 aos->Close(); | 269 aos->Close(); |
| 264 } | 270 } |
| 265 | 271 |
| 266 // Test Open(), Start(), Close() calling sequence. | 272 // Test Open(), Start(), Close() calling sequence. |
| 267 TEST(WASAPIAudioOutputStreamTest, OpenStartAndClose) { | 273 TEST(WASAPIAudioOutputStreamTest, OpenStartAndClose) { |
| 268 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 274 base::MessageLoop loop; |
| 275 ScopedAudioManagerPtr audio_manager( |
| 276 AudioManager::CreateForTesting(loop.task_runner())); |
| 269 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get())); | 277 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get())); |
| 270 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 278 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
| 271 EXPECT_TRUE(aos->Open()); | 279 EXPECT_TRUE(aos->Open()); |
| 272 MockAudioSourceCallback source; | 280 MockAudioSourceCallback source; |
| 273 EXPECT_CALL(source, OnError(aos)) | 281 EXPECT_CALL(source, OnError(aos)) |
| 274 .Times(0); | 282 .Times(0); |
| 275 aos->Start(&source); | 283 aos->Start(&source); |
| 276 aos->Close(); | 284 aos->Close(); |
| 277 } | 285 } |
| 278 | 286 |
| 279 // Test Open(), Start(), Stop(), Close() calling sequence. | 287 // Test Open(), Start(), Stop(), Close() calling sequence. |
| 280 TEST(WASAPIAudioOutputStreamTest, OpenStartStopAndClose) { | 288 TEST(WASAPIAudioOutputStreamTest, OpenStartStopAndClose) { |
| 281 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 289 base::MessageLoop loop; |
| 290 ScopedAudioManagerPtr audio_manager( |
| 291 AudioManager::CreateForTesting(loop.task_runner())); |
| 282 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get())); | 292 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get())); |
| 283 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 293 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
| 284 EXPECT_TRUE(aos->Open()); | 294 EXPECT_TRUE(aos->Open()); |
| 285 MockAudioSourceCallback source; | 295 MockAudioSourceCallback source; |
| 286 EXPECT_CALL(source, OnError(aos)) | 296 EXPECT_CALL(source, OnError(aos)) |
| 287 .Times(0); | 297 .Times(0); |
| 288 aos->Start(&source); | 298 aos->Start(&source); |
| 289 aos->Stop(); | 299 aos->Stop(); |
| 290 aos->Close(); | 300 aos->Close(); |
| 291 } | 301 } |
| 292 | 302 |
| 293 // Test SetVolume(), GetVolume() | 303 // Test SetVolume(), GetVolume() |
| 294 TEST(WASAPIAudioOutputStreamTest, Volume) { | 304 TEST(WASAPIAudioOutputStreamTest, Volume) { |
| 295 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 305 base::MessageLoop loop; |
| 306 ScopedAudioManagerPtr audio_manager( |
| 307 AudioManager::CreateForTesting(loop.task_runner())); |
| 296 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get())); | 308 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get())); |
| 297 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 309 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
| 298 | 310 |
| 299 // Initial volume should be full volume (1.0). | 311 // Initial volume should be full volume (1.0). |
| 300 double volume = 0.0; | 312 double volume = 0.0; |
| 301 aos->GetVolume(&volume); | 313 aos->GetVolume(&volume); |
| 302 EXPECT_EQ(1.0, volume); | 314 EXPECT_EQ(1.0, volume); |
| 303 | 315 |
| 304 // Verify some valid volume settings. | 316 // Verify some valid volume settings. |
| 305 aos->SetVolume(0.0); | 317 aos->SetVolume(0.0); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 321 | 333 |
| 322 aos->SetVolume(-0.5); | 334 aos->SetVolume(-0.5); |
| 323 aos->GetVolume(&volume); | 335 aos->GetVolume(&volume); |
| 324 EXPECT_EQ(1.0, volume); | 336 EXPECT_EQ(1.0, volume); |
| 325 | 337 |
| 326 aos->Close(); | 338 aos->Close(); |
| 327 } | 339 } |
| 328 | 340 |
| 329 // Test some additional calling sequences. | 341 // Test some additional calling sequences. |
| 330 TEST(WASAPIAudioOutputStreamTest, MiscCallingSequences) { | 342 TEST(WASAPIAudioOutputStreamTest, MiscCallingSequences) { |
| 331 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 343 base::MessageLoop loop; |
| 344 ScopedAudioManagerPtr audio_manager( |
| 345 AudioManager::CreateForTesting(loop.task_runner())); |
| 332 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get())); | 346 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get())); |
| 333 | 347 |
| 334 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 348 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
| 335 WASAPIAudioOutputStream* waos = static_cast<WASAPIAudioOutputStream*>(aos); | 349 WASAPIAudioOutputStream* waos = static_cast<WASAPIAudioOutputStream*>(aos); |
| 336 | 350 |
| 337 // Open(), Open() is a valid calling sequence (second call does nothing). | 351 // Open(), Open() is a valid calling sequence (second call does nothing). |
| 338 EXPECT_TRUE(aos->Open()); | 352 EXPECT_TRUE(aos->Open()); |
| 339 EXPECT_TRUE(aos->Open()); | 353 EXPECT_TRUE(aos->Open()); |
| 340 | 354 |
| 341 MockAudioSourceCallback source; | 355 MockAudioSourceCallback source; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 360 aos->Start(&source); | 374 aos->Start(&source); |
| 361 EXPECT_TRUE(waos->started()); | 375 EXPECT_TRUE(waos->started()); |
| 362 aos->Stop(); | 376 aos->Stop(); |
| 363 EXPECT_FALSE(waos->started()); | 377 EXPECT_FALSE(waos->started()); |
| 364 | 378 |
| 365 aos->Close(); | 379 aos->Close(); |
| 366 } | 380 } |
| 367 | 381 |
| 368 // Use preferred packet size and verify that rendering starts. | 382 // Use preferred packet size and verify that rendering starts. |
| 369 TEST(WASAPIAudioOutputStreamTest, ValidPacketSize) { | 383 TEST(WASAPIAudioOutputStreamTest, ValidPacketSize) { |
| 370 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 384 base::MessageLoopForUI loop; |
| 385 ScopedAudioManagerPtr audio_manager( |
| 386 AudioManager::CreateForTesting(loop.task_runner())); |
| 371 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get())); | 387 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get())); |
| 372 | 388 |
| 373 base::MessageLoopForUI loop; | |
| 374 MockAudioSourceCallback source; | 389 MockAudioSourceCallback source; |
| 375 | |
| 376 // Create default WASAPI output stream which plays out in stereo using | 390 // Create default WASAPI output stream which plays out in stereo using |
| 377 // the shared mixing rate. The default buffer size is 10ms. | 391 // the shared mixing rate. The default buffer size is 10ms. |
| 378 AudioOutputStreamWrapper aosw(audio_manager.get()); | 392 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 379 AudioOutputStream* aos = aosw.Create(); | 393 AudioOutputStream* aos = aosw.Create(); |
| 380 EXPECT_TRUE(aos->Open()); | 394 EXPECT_TRUE(aos->Open()); |
| 381 | 395 |
| 382 // Derive the expected size in bytes of each packet. | 396 // Derive the expected size in bytes of each packet. |
| 383 uint32_t bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * | 397 uint32_t bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * |
| 384 (aosw.bits_per_sample() / 8); | 398 (aosw.bits_per_sample() / 8); |
| 385 | 399 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 399 } | 413 } |
| 400 | 414 |
| 401 // This test is intended for manual tests and should only be enabled | 415 // This test is intended for manual tests and should only be enabled |
| 402 // when it is required to play out data from a local PCM file. | 416 // when it is required to play out data from a local PCM file. |
| 403 // By default, GTest will print out YOU HAVE 1 DISABLED TEST. | 417 // By default, GTest will print out YOU HAVE 1 DISABLED TEST. |
| 404 // To include disabled tests in test execution, just invoke the test program | 418 // To include disabled tests in test execution, just invoke the test program |
| 405 // with --gtest_also_run_disabled_tests or set the GTEST_ALSO_RUN_DISABLED_TESTS | 419 // with --gtest_also_run_disabled_tests or set the GTEST_ALSO_RUN_DISABLED_TESTS |
| 406 // environment variable to a value greater than 0. | 420 // environment variable to a value greater than 0. |
| 407 // The test files are approximately 20 seconds long. | 421 // The test files are approximately 20 seconds long. |
| 408 TEST(WASAPIAudioOutputStreamTest, DISABLED_ReadFromStereoFile) { | 422 TEST(WASAPIAudioOutputStreamTest, DISABLED_ReadFromStereoFile) { |
| 409 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 423 base::MessageLoop loop; |
| 424 ScopedAudioManagerPtr audio_manager( |
| 425 AudioManager::CreateForTesting(loop.task_runner())); |
| 410 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get())); | 426 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get())); |
| 411 | 427 |
| 412 AudioOutputStreamWrapper aosw(audio_manager.get()); | 428 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 413 AudioOutputStream* aos = aosw.Create(); | 429 AudioOutputStream* aos = aosw.Create(); |
| 414 EXPECT_TRUE(aos->Open()); | 430 EXPECT_TRUE(aos->Open()); |
| 415 | 431 |
| 416 std::string file_name; | 432 std::string file_name; |
| 417 if (aosw.sample_rate() == 48000) { | 433 if (aosw.sample_rate() == 48000) { |
| 418 file_name = kSpeechFile_16b_s_48k; | 434 file_name = kSpeechFile_16b_s_48k; |
| 419 } else if (aosw.sample_rate() == 44100) { | 435 } else if (aosw.sample_rate() == 44100) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 449 DVLOG(0) << ">> Stereo file playout has stopped."; | 465 DVLOG(0) << ">> Stereo file playout has stopped."; |
| 450 aos->Close(); | 466 aos->Close(); |
| 451 } | 467 } |
| 452 | 468 |
| 453 // Verify that we can open the output stream in exclusive mode using a | 469 // Verify that we can open the output stream in exclusive mode using a |
| 454 // certain set of audio parameters and a sample rate of 48kHz. | 470 // certain set of audio parameters and a sample rate of 48kHz. |
| 455 // The expected outcomes of each setting in this test has been derived | 471 // The expected outcomes of each setting in this test has been derived |
| 456 // manually using log outputs (--v=1). | 472 // manually using log outputs (--v=1). |
| 457 // It's disabled by default because a flag is required to enable exclusive mode. | 473 // It's disabled by default because a flag is required to enable exclusive mode. |
| 458 TEST(WASAPIAudioOutputStreamTest, DISABLED_ExclusiveModeBufferSizesAt48kHz) { | 474 TEST(WASAPIAudioOutputStreamTest, DISABLED_ExclusiveModeBufferSizesAt48kHz) { |
| 459 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 475 base::MessageLoop loop; |
| 476 ScopedAudioManagerPtr audio_manager( |
| 477 AudioManager::CreateForTesting(loop.task_runner())); |
| 460 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get()) && | 478 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get()) && |
| 461 ExclusiveModeIsEnabled()); | 479 ExclusiveModeIsEnabled()); |
| 462 | 480 |
| 463 AudioOutputStreamWrapper aosw(audio_manager.get()); | 481 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 464 | 482 |
| 465 // 10ms @ 48kHz shall work. | 483 // 10ms @ 48kHz shall work. |
| 466 // Note that, this is the same size as we can use for shared-mode streaming | 484 // Note that, this is the same size as we can use for shared-mode streaming |
| 467 // but here the endpoint buffer delay is only 10ms instead of 20ms. | 485 // but here the endpoint buffer delay is only 10ms instead of 20ms. |
| 468 AudioOutputStream* aos = aosw.Create(48000, 480); | 486 AudioOutputStream* aos = aosw.Create(48000, 480); |
| 469 EXPECT_TRUE(aos->Open()); | 487 EXPECT_TRUE(aos->Open()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 498 EXPECT_TRUE(aos->Open()); | 516 EXPECT_TRUE(aos->Open()); |
| 499 aos->Close(); | 517 aos->Close(); |
| 500 } | 518 } |
| 501 | 519 |
| 502 // Verify that we can open the output stream in exclusive mode using a | 520 // Verify that we can open the output stream in exclusive mode using a |
| 503 // certain set of audio parameters and a sample rate of 44.1kHz. | 521 // certain set of audio parameters and a sample rate of 44.1kHz. |
| 504 // The expected outcomes of each setting in this test has been derived | 522 // The expected outcomes of each setting in this test has been derived |
| 505 // manually using log outputs (--v=1). | 523 // manually using log outputs (--v=1). |
| 506 // It's disabled by default because a flag is required to enable exclusive mode. | 524 // It's disabled by default because a flag is required to enable exclusive mode. |
| 507 TEST(WASAPIAudioOutputStreamTest, DISABLED_ExclusiveModeBufferSizesAt44kHz) { | 525 TEST(WASAPIAudioOutputStreamTest, DISABLED_ExclusiveModeBufferSizesAt44kHz) { |
| 508 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 526 base::MessageLoop loop; |
| 527 ScopedAudioManagerPtr audio_manager( |
| 528 AudioManager::CreateForTesting(loop.task_runner())); |
| 509 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get()) && | 529 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get()) && |
| 510 ExclusiveModeIsEnabled()); | 530 ExclusiveModeIsEnabled()); |
| 511 | 531 |
| 512 AudioOutputStreamWrapper aosw(audio_manager.get()); | 532 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 513 | 533 |
| 514 // 10ms @ 44.1kHz does not work due to misalignment. | 534 // 10ms @ 44.1kHz does not work due to misalignment. |
| 515 // This test will propose an aligned buffer size of 10.1587ms. | 535 // This test will propose an aligned buffer size of 10.1587ms. |
| 516 AudioOutputStream* aos = aosw.Create(44100, 441); | 536 AudioOutputStream* aos = aosw.Create(44100, 441); |
| 517 EXPECT_FALSE(aos->Open()); | 537 EXPECT_FALSE(aos->Open()); |
| 518 aos->Close(); | 538 aos->Close(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 // 3.6281ms @ 44.1kHz <=> smallest possible buffer size we can use. | 574 // 3.6281ms @ 44.1kHz <=> smallest possible buffer size we can use. |
| 555 aos = aosw.Create(44100, 160); | 575 aos = aosw.Create(44100, 160); |
| 556 EXPECT_TRUE(aos->Open()); | 576 EXPECT_TRUE(aos->Open()); |
| 557 aos->Close(); | 577 aos->Close(); |
| 558 } | 578 } |
| 559 | 579 |
| 560 // Verify that we can open and start the output stream in exclusive mode at | 580 // Verify that we can open and start the output stream in exclusive mode at |
| 561 // the lowest possible delay at 48kHz. | 581 // the lowest possible delay at 48kHz. |
| 562 // It's disabled by default because a flag is required to enable exclusive mode. | 582 // It's disabled by default because a flag is required to enable exclusive mode. |
| 563 TEST(WASAPIAudioOutputStreamTest, DISABLED_ExclusiveModeMinBufferSizeAt48kHz) { | 583 TEST(WASAPIAudioOutputStreamTest, DISABLED_ExclusiveModeMinBufferSizeAt48kHz) { |
| 564 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 584 base::MessageLoopForUI loop; |
| 585 ScopedAudioManagerPtr audio_manager( |
| 586 AudioManager::CreateForTesting(loop.task_runner())); |
| 565 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get()) && | 587 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get()) && |
| 566 ExclusiveModeIsEnabled()); | 588 ExclusiveModeIsEnabled()); |
| 567 | 589 |
| 568 base::MessageLoopForUI loop; | |
| 569 MockAudioSourceCallback source; | 590 MockAudioSourceCallback source; |
| 570 | |
| 571 // Create exclusive-mode WASAPI output stream which plays out in stereo | 591 // Create exclusive-mode WASAPI output stream which plays out in stereo |
| 572 // using the minimum buffer size at 48kHz sample rate. | 592 // using the minimum buffer size at 48kHz sample rate. |
| 573 AudioOutputStreamWrapper aosw(audio_manager.get()); | 593 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 574 AudioOutputStream* aos = aosw.Create(48000, 160); | 594 AudioOutputStream* aos = aosw.Create(48000, 160); |
| 575 EXPECT_TRUE(aos->Open()); | 595 EXPECT_TRUE(aos->Open()); |
| 576 | 596 |
| 577 // Derive the expected size in bytes of each packet. | 597 // Derive the expected size in bytes of each packet. |
| 578 uint32_t bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * | 598 uint32_t bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * |
| 579 (aosw.bits_per_sample() / 8); | 599 (aosw.bits_per_sample() / 8); |
| 580 | 600 |
| 581 // Wait for the first callback and verify its parameters. | 601 // Wait for the first callback and verify its parameters. |
| 582 EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet), 0)) | 602 EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet), 0)) |
| 583 .WillOnce(DoAll(QuitLoop(loop.task_runner()), | 603 .WillOnce(DoAll(QuitLoop(loop.task_runner()), |
| 584 Return(aosw.samples_per_packet()))) | 604 Return(aosw.samples_per_packet()))) |
| 585 .WillRepeatedly(Return(aosw.samples_per_packet())); | 605 .WillRepeatedly(Return(aosw.samples_per_packet())); |
| 586 | 606 |
| 587 aos->Start(&source); | 607 aos->Start(&source); |
| 588 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 608 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 589 TestTimeouts::action_timeout()); | 609 TestTimeouts::action_timeout()); |
| 590 loop.Run(); | 610 loop.Run(); |
| 591 aos->Stop(); | 611 aos->Stop(); |
| 592 aos->Close(); | 612 aos->Close(); |
| 593 } | 613 } |
| 594 | 614 |
| 595 // Verify that we can open and start the output stream in exclusive mode at | 615 // Verify that we can open and start the output stream in exclusive mode at |
| 596 // the lowest possible delay at 44.1kHz. | 616 // the lowest possible delay at 44.1kHz. |
| 597 // It's disabled by default because a flag is required to enable exclusive mode. | 617 // It's disabled by default because a flag is required to enable exclusive mode. |
| 598 TEST(WASAPIAudioOutputStreamTest, DISABLED_ExclusiveModeMinBufferSizeAt44kHz) { | 618 TEST(WASAPIAudioOutputStreamTest, DISABLED_ExclusiveModeMinBufferSizeAt44kHz) { |
| 599 ABORT_AUDIO_TEST_IF_NOT(ExclusiveModeIsEnabled()); | 619 ABORT_AUDIO_TEST_IF_NOT(ExclusiveModeIsEnabled()); |
| 600 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 620 base::MessageLoopForUI loop; |
| 621 ScopedAudioManagerPtr audio_manager( |
| 622 AudioManager::CreateForTesting(loop.task_runner())); |
| 601 | 623 |
| 602 base::MessageLoopForUI loop; | |
| 603 MockAudioSourceCallback source; | 624 MockAudioSourceCallback source; |
| 604 | |
| 605 // Create exclusive-mode WASAPI output stream which plays out in stereo | 625 // Create exclusive-mode WASAPI output stream which plays out in stereo |
| 606 // using the minimum buffer size at 44.1kHz sample rate. | 626 // using the minimum buffer size at 44.1kHz sample rate. |
| 607 AudioOutputStreamWrapper aosw(audio_manager.get()); | 627 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 608 AudioOutputStream* aos = aosw.Create(44100, 160); | 628 AudioOutputStream* aos = aosw.Create(44100, 160); |
| 609 EXPECT_TRUE(aos->Open()); | 629 EXPECT_TRUE(aos->Open()); |
| 610 | 630 |
| 611 // Derive the expected size in bytes of each packet. | 631 // Derive the expected size in bytes of each packet. |
| 612 uint32_t bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * | 632 uint32_t bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * |
| 613 (aosw.bits_per_sample() / 8); | 633 (aosw.bits_per_sample() / 8); |
| 614 | 634 |
| 615 // Wait for the first callback and verify its parameters. | 635 // Wait for the first callback and verify its parameters. |
| 616 EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet), 0)) | 636 EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet), 0)) |
| 617 .WillOnce(DoAll(QuitLoop(loop.task_runner()), | 637 .WillOnce(DoAll(QuitLoop(loop.task_runner()), |
| 618 Return(aosw.samples_per_packet()))) | 638 Return(aosw.samples_per_packet()))) |
| 619 .WillRepeatedly(Return(aosw.samples_per_packet())); | 639 .WillRepeatedly(Return(aosw.samples_per_packet())); |
| 620 | 640 |
| 621 aos->Start(&source); | 641 aos->Start(&source); |
| 622 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 642 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 623 TestTimeouts::action_timeout()); | 643 TestTimeouts::action_timeout()); |
| 624 loop.Run(); | 644 loop.Run(); |
| 625 aos->Stop(); | 645 aos->Stop(); |
| 626 aos->Close(); | 646 aos->Close(); |
| 627 } | 647 } |
| 628 | 648 |
| 629 } // namespace media | 649 } // namespace media |
| OLD | NEW |