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_input_win.h" | 5 #include "media/audio/win/audio_low_latency_input_win.h" |
6 | 6 |
7 #include <mmsystem.h> | 7 #include <mmsystem.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <windows.h> | 10 #include <windows.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/macros.h" | 16 #include "base/macros.h" |
17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
19 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
20 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
22 #include "base/test/test_timeouts.h" | 22 #include "base/test/test_timeouts.h" |
23 #include "base/win/scoped_com_initializer.h" | 23 #include "base/win/scoped_com_initializer.h" |
24 #include "media/audio/audio_device_description.h" | 24 #include "media/audio/audio_device_description.h" |
| 25 #include "media/audio/audio_device_info_accessor_for_tests.h" |
25 #include "media/audio/audio_io.h" | 26 #include "media/audio/audio_io.h" |
26 #include "media/audio/audio_manager.h" | 27 #include "media/audio/audio_manager.h" |
27 #include "media/audio/audio_unittest_util.h" | 28 #include "media/audio/audio_unittest_util.h" |
28 #include "media/audio/win/core_audio_util_win.h" | 29 #include "media/audio/win/core_audio_util_win.h" |
29 #include "media/base/seekable_buffer.h" | 30 #include "media/base/seekable_buffer.h" |
30 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
32 | 33 |
33 using ::testing::_; | 34 using ::testing::_; |
34 using ::testing::AnyNumber; | 35 using ::testing::AnyNumber; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 int bits_per_sample_; | 153 int bits_per_sample_; |
153 media::SeekableBuffer buffer_; | 154 media::SeekableBuffer buffer_; |
154 FILE* binary_file_; | 155 FILE* binary_file_; |
155 size_t bytes_to_write_; | 156 size_t bytes_to_write_; |
156 }; | 157 }; |
157 | 158 |
158 static bool HasCoreAudioAndInputDevices(AudioManager* audio_man) { | 159 static bool HasCoreAudioAndInputDevices(AudioManager* audio_man) { |
159 // The low-latency (WASAPI-based) version requires Windows Vista or higher. | 160 // The low-latency (WASAPI-based) version requires Windows Vista or higher. |
160 // TODO(henrika): note that we use Wave today to query the number of | 161 // TODO(henrika): note that we use Wave today to query the number of |
161 // existing input devices. | 162 // existing input devices. |
162 return CoreAudioUtil::IsSupported() && audio_man->HasAudioInputDevices(); | 163 return CoreAudioUtil::IsSupported() && |
| 164 AudioDeviceInfoAccessorForTests(audio_man).HasAudioInputDevices(); |
163 } | 165 } |
164 | 166 |
165 // Convenience method which creates a default AudioInputStream object but | 167 // Convenience method which creates a default AudioInputStream object but |
166 // also allows the user to modify the default settings. | 168 // also allows the user to modify the default settings. |
167 class AudioInputStreamWrapper { | 169 class AudioInputStreamWrapper { |
168 public: | 170 public: |
169 explicit AudioInputStreamWrapper(AudioManager* audio_manager) | 171 explicit AudioInputStreamWrapper(AudioManager* audio_manager) |
170 : audio_man_(audio_manager) { | 172 : audio_man_(audio_manager) { |
171 EXPECT_TRUE(SUCCEEDED(CoreAudioUtil::GetPreferredAudioParameters( | 173 EXPECT_TRUE(SUCCEEDED(CoreAudioUtil::GetPreferredAudioParameters( |
172 AudioDeviceDescription::kDefaultDeviceId, false, &default_params_))); | 174 AudioDeviceDescription::kDefaultDeviceId, false, &default_params_))); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 ScopedAudioManagerPtr audio_manager_; | 274 ScopedAudioManagerPtr audio_manager_; |
273 }; | 275 }; |
274 | 276 |
275 // Verify that we can retrieve the current hardware/mixing sample rate | 277 // Verify that we can retrieve the current hardware/mixing sample rate |
276 // for all available input devices. | 278 // for all available input devices. |
277 TEST_F(WinAudioInputTest, WASAPIAudioInputStreamHardwareSampleRate) { | 279 TEST_F(WinAudioInputTest, WASAPIAudioInputStreamHardwareSampleRate) { |
278 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndInputDevices(audio_manager_.get())); | 280 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndInputDevices(audio_manager_.get())); |
279 | 281 |
280 // Retrieve a list of all available input devices. | 282 // Retrieve a list of all available input devices. |
281 media::AudioDeviceDescriptions device_descriptions; | 283 media::AudioDeviceDescriptions device_descriptions; |
282 audio_manager_->GetAudioInputDeviceDescriptions(&device_descriptions); | 284 AudioDeviceInfoAccessorForTests(audio_manager_.get()) |
| 285 .GetAudioInputDeviceDescriptions(&device_descriptions); |
283 | 286 |
284 // Scan all available input devices and repeat the same test for all of them. | 287 // Scan all available input devices and repeat the same test for all of them. |
285 for (const auto& device : device_descriptions) { | 288 for (const auto& device : device_descriptions) { |
286 // Retrieve the hardware sample rate given a specified audio input device. | 289 // Retrieve the hardware sample rate given a specified audio input device. |
287 AudioParameters params; | 290 AudioParameters params; |
288 ASSERT_TRUE(SUCCEEDED(CoreAudioUtil::GetPreferredAudioParameters( | 291 ASSERT_TRUE(SUCCEEDED(CoreAudioUtil::GetPreferredAudioParameters( |
289 device.unique_id, false, ¶ms))); | 292 device.unique_id, false, ¶ms))); |
290 EXPECT_GE(params.sample_rate(), 0); | 293 EXPECT_GE(params.sample_rate(), 0); |
291 } | 294 } |
292 } | 295 } |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 run_loop.QuitWhenIdleClosure())); | 439 run_loop.QuitWhenIdleClosure())); |
437 ais->Start(&sink); | 440 ais->Start(&sink); |
438 run_loop.Run(); | 441 run_loop.Run(); |
439 ais->Stop(); | 442 ais->Stop(); |
440 ais.Close(); | 443 ais.Close(); |
441 } | 444 } |
442 } | 445 } |
443 | 446 |
444 // Test that we can capture a stream in loopback. | 447 // Test that we can capture a stream in loopback. |
445 TEST_F(WinAudioInputTest, WASAPIAudioInputStreamLoopback) { | 448 TEST_F(WinAudioInputTest, WASAPIAudioInputStreamLoopback) { |
446 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices() && | 449 AudioDeviceInfoAccessorForTests device_info_accessor(audio_manager_.get()); |
| 450 ABORT_AUDIO_TEST_IF_NOT(device_info_accessor.HasAudioOutputDevices() && |
447 CoreAudioUtil::IsSupported()); | 451 CoreAudioUtil::IsSupported()); |
448 | 452 AudioParameters params = device_info_accessor.GetInputStreamParameters( |
449 AudioParameters params = audio_manager_->GetInputStreamParameters( | |
450 AudioDeviceDescription::kLoopbackInputDeviceId); | 453 AudioDeviceDescription::kLoopbackInputDeviceId); |
451 EXPECT_EQ(params.effects(), 0); | 454 EXPECT_EQ(params.effects(), 0); |
452 | 455 |
453 AudioParameters output_params = | 456 AudioParameters output_params = |
454 audio_manager_->GetOutputStreamParameters(std::string()); | 457 device_info_accessor.GetOutputStreamParameters(std::string()); |
455 EXPECT_EQ(params.sample_rate(), output_params.sample_rate()); | 458 EXPECT_EQ(params.sample_rate(), output_params.sample_rate()); |
456 EXPECT_EQ(params.channel_layout(), output_params.channel_layout()); | 459 EXPECT_EQ(params.channel_layout(), output_params.channel_layout()); |
457 | 460 |
458 ScopedAudioInputStream stream(audio_manager_->MakeAudioInputStream( | 461 ScopedAudioInputStream stream(audio_manager_->MakeAudioInputStream( |
459 params, AudioDeviceDescription::kLoopbackInputDeviceId, | 462 params, AudioDeviceDescription::kLoopbackInputDeviceId, |
460 AudioManager::LogCallback())); | 463 AudioManager::LogCallback())); |
461 ASSERT_TRUE(stream->Open()); | 464 ASSERT_TRUE(stream->Open()); |
462 FakeAudioInputCallback sink; | 465 FakeAudioInputCallback sink; |
463 stream->Start(&sink); | 466 stream->Start(&sink); |
464 ASSERT_FALSE(sink.error()); | 467 ASSERT_FALSE(sink.error()); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 ais->Start(&file_sink); | 554 ais->Start(&file_sink); |
552 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); | 555 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); |
553 // base::PlatformThread::Sleep(base::TimeDelta::FromMinutes(10)); | 556 // base::PlatformThread::Sleep(base::TimeDelta::FromMinutes(10)); |
554 ais->Stop(); | 557 ais->Stop(); |
555 VLOG(0) << ">> Recording has stopped."; | 558 VLOG(0) << ">> Recording has stopped."; |
556 ais.Close(); | 559 ais.Close(); |
557 } | 560 } |
558 } | 561 } |
559 | 562 |
560 } // namespace media | 563 } // namespace media |
OLD | NEW |