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 "media/audio/win/audio_low_latency_output_win.h" | 5 #include "media/audio/win/audio_low_latency_output_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <mmsystem.h> | 8 #include <mmsystem.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 | 11 |
12 #include <memory> | 12 #include <memory> |
13 | 13 |
14 #include "base/environment.h" | 14 #include "base/environment.h" |
15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 18 #include "base/run_loop.h" |
| 19 #include "base/single_thread_task_runner.h" |
18 #include "base/test/test_timeouts.h" | 20 #include "base/test/test_timeouts.h" |
19 #include "base/time/time.h" | 21 #include "base/time/time.h" |
20 #include "base/win/scoped_com_initializer.h" | 22 #include "base/win/scoped_com_initializer.h" |
21 #include "media/audio/audio_device_description.h" | 23 #include "media/audio/audio_device_description.h" |
22 #include "media/audio/audio_io.h" | 24 #include "media/audio/audio_io.h" |
23 #include "media/audio/audio_manager.h" | 25 #include "media/audio/audio_manager.h" |
24 #include "media/audio/audio_unittest_util.h" | 26 #include "media/audio/audio_unittest_util.h" |
25 #include "media/audio/mock_audio_source_callback.h" | 27 #include "media/audio/mock_audio_source_callback.h" |
26 #include "media/audio/win/core_audio_util_win.h" | 28 #include "media/audio/win/core_audio_util_win.h" |
27 #include "media/base/decoder_buffer.h" | 29 #include "media/base/decoder_buffer.h" |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 AudioOutputStreamWrapper aosw(audio_manager); | 230 AudioOutputStreamWrapper aosw(audio_manager); |
229 AudioOutputStream* aos = aosw.Create(); | 231 AudioOutputStream* aos = aosw.Create(); |
230 return aos; | 232 return aos; |
231 } | 233 } |
232 | 234 |
233 class WASAPIAudioOutputStreamTest : public ::testing::Test { | 235 class WASAPIAudioOutputStreamTest : public ::testing::Test { |
234 public: | 236 public: |
235 WASAPIAudioOutputStreamTest() { | 237 WASAPIAudioOutputStreamTest() { |
236 audio_manager_ = | 238 audio_manager_ = |
237 AudioManager::CreateForTesting(message_loop_.task_runner()); | 239 AudioManager::CreateForTesting(message_loop_.task_runner()); |
238 message_loop_.RunUntilIdle(); | 240 base::RunLoop().RunUntilIdle(); |
239 } | 241 } |
240 ~WASAPIAudioOutputStreamTest() override { | 242 ~WASAPIAudioOutputStreamTest() override { |
241 audio_manager_.reset(); | 243 audio_manager_.reset(); |
242 message_loop_.RunUntilIdle(); | 244 base::RunLoop().RunUntilIdle(); |
243 } | 245 } |
244 | 246 |
245 protected: | 247 protected: |
246 base::MessageLoopForUI message_loop_; | 248 base::MessageLoopForUI message_loop_; |
247 ScopedAudioManagerPtr audio_manager_; | 249 ScopedAudioManagerPtr audio_manager_; |
248 }; | 250 }; |
249 | 251 |
250 // Verify that we can retrieve the current hardware/mixing sample rate | 252 // Verify that we can retrieve the current hardware/mixing sample rate |
251 // for the default audio device. | 253 // for the default audio device. |
252 // TODO(henrika): modify this test when we support full device enumeration. | 254 // TODO(henrika): modify this test when we support full device enumeration. |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 (aosw.bits_per_sample() / 8); | 395 (aosw.bits_per_sample() / 8); |
394 | 396 |
395 // Wait for the first callback and verify its parameters. Ignore any | 397 // Wait for the first callback and verify its parameters. Ignore any |
396 // subsequent callbacks that might arrive. | 398 // subsequent callbacks that might arrive. |
397 EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet), 0)) | 399 EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet), 0)) |
398 .WillOnce(DoAll(QuitLoop(message_loop_.task_runner()), | 400 .WillOnce(DoAll(QuitLoop(message_loop_.task_runner()), |
399 Return(aosw.samples_per_packet()))) | 401 Return(aosw.samples_per_packet()))) |
400 .WillRepeatedly(Return(0)); | 402 .WillRepeatedly(Return(0)); |
401 | 403 |
402 aos->Start(&source); | 404 aos->Start(&source); |
403 message_loop_.PostDelayedTask(FROM_HERE, | 405 message_loop_.task_runner()->PostDelayedTask( |
404 base::MessageLoop::QuitWhenIdleClosure(), | 406 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
405 TestTimeouts::action_timeout()); | 407 TestTimeouts::action_timeout()); |
406 message_loop_.Run(); | 408 base::RunLoop().Run(); |
407 aos->Stop(); | 409 aos->Stop(); |
408 aos->Close(); | 410 aos->Close(); |
409 } | 411 } |
410 | 412 |
411 // This test is intended for manual tests and should only be enabled | 413 // This test is intended for manual tests and should only be enabled |
412 // when it is required to play out data from a local PCM file. | 414 // when it is required to play out data from a local PCM file. |
413 // By default, GTest will print out YOU HAVE 1 DISABLED TEST. | 415 // By default, GTest will print out YOU HAVE 1 DISABLED TEST. |
414 // To include disabled tests in test execution, just invoke the test program | 416 // To include disabled tests in test execution, just invoke the test program |
415 // with --gtest_also_run_disabled_tests or set the GTEST_ALSO_RUN_DISABLED_TESTS | 417 // with --gtest_also_run_disabled_tests or set the GTEST_ALSO_RUN_DISABLED_TESTS |
416 // environment variable to a value greater than 0. | 418 // environment variable to a value greater than 0. |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 uint32_t bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * | 585 uint32_t bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * |
584 (aosw.bits_per_sample() / 8); | 586 (aosw.bits_per_sample() / 8); |
585 | 587 |
586 // Wait for the first callback and verify its parameters. | 588 // Wait for the first callback and verify its parameters. |
587 EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet), 0)) | 589 EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet), 0)) |
588 .WillOnce(DoAll(QuitLoop(message_loop_.task_runner()), | 590 .WillOnce(DoAll(QuitLoop(message_loop_.task_runner()), |
589 Return(aosw.samples_per_packet()))) | 591 Return(aosw.samples_per_packet()))) |
590 .WillRepeatedly(Return(aosw.samples_per_packet())); | 592 .WillRepeatedly(Return(aosw.samples_per_packet())); |
591 | 593 |
592 aos->Start(&source); | 594 aos->Start(&source); |
593 message_loop_.PostDelayedTask(FROM_HERE, | 595 message_loop_.task_runner()->PostDelayedTask( |
594 base::MessageLoop::QuitWhenIdleClosure(), | 596 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
595 TestTimeouts::action_timeout()); | 597 TestTimeouts::action_timeout()); |
596 message_loop_.Run(); | 598 base::RunLoop().Run(); |
597 aos->Stop(); | 599 aos->Stop(); |
598 aos->Close(); | 600 aos->Close(); |
599 } | 601 } |
600 | 602 |
601 // Verify that we can open and start the output stream in exclusive mode at | 603 // Verify that we can open and start the output stream in exclusive mode at |
602 // the lowest possible delay at 44.1kHz. | 604 // the lowest possible delay at 44.1kHz. |
603 // It's disabled by default because a flag is required to enable exclusive mode. | 605 // It's disabled by default because a flag is required to enable exclusive mode. |
604 TEST_F(WASAPIAudioOutputStreamTest, | 606 TEST_F(WASAPIAudioOutputStreamTest, |
605 DISABLED_ExclusiveModeMinBufferSizeAt44kHz) { | 607 DISABLED_ExclusiveModeMinBufferSizeAt44kHz) { |
606 ABORT_AUDIO_TEST_IF_NOT(ExclusiveModeIsEnabled()); | 608 ABORT_AUDIO_TEST_IF_NOT(ExclusiveModeIsEnabled()); |
607 | 609 |
608 MockAudioSourceCallback source; | 610 MockAudioSourceCallback source; |
609 // Create exclusive-mode WASAPI output stream which plays out in stereo | 611 // Create exclusive-mode WASAPI output stream which plays out in stereo |
610 // using the minimum buffer size at 44.1kHz sample rate. | 612 // using the minimum buffer size at 44.1kHz sample rate. |
611 AudioOutputStreamWrapper aosw(audio_manager_.get()); | 613 AudioOutputStreamWrapper aosw(audio_manager_.get()); |
612 AudioOutputStream* aos = aosw.Create(44100, 160); | 614 AudioOutputStream* aos = aosw.Create(44100, 160); |
613 EXPECT_TRUE(aos->Open()); | 615 EXPECT_TRUE(aos->Open()); |
614 | 616 |
615 // Derive the expected size in bytes of each packet. | 617 // Derive the expected size in bytes of each packet. |
616 uint32_t bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * | 618 uint32_t bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * |
617 (aosw.bits_per_sample() / 8); | 619 (aosw.bits_per_sample() / 8); |
618 | 620 |
619 // Wait for the first callback and verify its parameters. | 621 // Wait for the first callback and verify its parameters. |
620 EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet), 0)) | 622 EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet), 0)) |
621 .WillOnce(DoAll(QuitLoop(message_loop_.task_runner()), | 623 .WillOnce(DoAll(QuitLoop(message_loop_.task_runner()), |
622 Return(aosw.samples_per_packet()))) | 624 Return(aosw.samples_per_packet()))) |
623 .WillRepeatedly(Return(aosw.samples_per_packet())); | 625 .WillRepeatedly(Return(aosw.samples_per_packet())); |
624 | 626 |
625 aos->Start(&source); | 627 aos->Start(&source); |
626 message_loop_.PostDelayedTask(FROM_HERE, | 628 message_loop_.task_runner()->PostDelayedTask( |
627 base::MessageLoop::QuitWhenIdleClosure(), | 629 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
628 TestTimeouts::action_timeout()); | 630 TestTimeouts::action_timeout()); |
629 message_loop_.Run(); | 631 base::RunLoop().Run(); |
630 aos->Stop(); | 632 aos->Stop(); |
631 aos->Close(); | 633 aos->Close(); |
632 } | 634 } |
633 | 635 |
634 } // namespace media | 636 } // namespace media |
OLD | NEW |