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/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/test/test_timeouts.h" | 14 #include "base/test/test_timeouts.h" |
15 #include "base/win/scoped_com_initializer.h" | 15 #include "base/win/scoped_com_initializer.h" |
16 #include "media/audio/audio_io.h" | 16 #include "media/audio/audio_io.h" |
17 #include "media/audio/audio_manager_base.h" | 17 #include "media/audio/audio_manager_base.h" |
18 #include "media/audio/audio_unittest_util.h" | 18 #include "media/audio/audio_unittest_util.h" |
19 #include "media/audio/win/audio_low_latency_input_win.h" | 19 #include "media/audio/win/audio_low_latency_input_win.h" |
20 #include "media/audio/win/core_audio_util_win.h" | 20 #include "media/audio/win/core_audio_util_win.h" |
21 #include "media/base/seekable_buffer.h" | 21 #include "media/base/seekable_buffer.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 | 24 |
25 using base::win::ScopedCOMInitializer; | |
26 using ::testing::_; | 25 using ::testing::_; |
27 using ::testing::AnyNumber; | 26 using ::testing::AnyNumber; |
28 using ::testing::AtLeast; | 27 using ::testing::AtLeast; |
29 using ::testing::Gt; | 28 using ::testing::Gt; |
30 using ::testing::NotNull; | 29 using ::testing::NotNull; |
31 | 30 |
32 namespace media { | 31 namespace media { |
33 | 32 |
34 ACTION_P3(CheckCountAndPostQuitTask, count, limit, loop) { | 33 ACTION_P3(CheckCountAndPostQuitTask, count, limit, loop) { |
35 if (++*count >= limit) { | 34 if (++*count >= limit) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 // TODO(henrika): note that we use Wave today to query the number of | 155 // TODO(henrika): note that we use Wave today to query the number of |
157 // existing input devices. | 156 // existing input devices. |
158 return CoreAudioUtil::IsSupported() && audio_man->HasAudioInputDevices(); | 157 return CoreAudioUtil::IsSupported() && audio_man->HasAudioInputDevices(); |
159 } | 158 } |
160 | 159 |
161 // Convenience method which creates a default AudioInputStream object but | 160 // Convenience method which creates a default AudioInputStream object but |
162 // also allows the user to modify the default settings. | 161 // also allows the user to modify the default settings. |
163 class AudioInputStreamWrapper { | 162 class AudioInputStreamWrapper { |
164 public: | 163 public: |
165 explicit AudioInputStreamWrapper(AudioManager* audio_manager) | 164 explicit AudioInputStreamWrapper(AudioManager* audio_manager) |
166 : com_init_(ScopedCOMInitializer::kMTA), | 165 : audio_man_(audio_manager), |
167 audio_man_(audio_manager), | |
168 default_params_( | 166 default_params_( |
169 audio_manager->GetInputStreamParameters( | 167 audio_manager->GetInputStreamParameters( |
170 AudioManagerBase::kDefaultDeviceId)) { | 168 AudioManagerBase::kDefaultDeviceId)) { |
171 EXPECT_EQ(format(), AudioParameters::AUDIO_PCM_LOW_LATENCY); | 169 EXPECT_EQ(format(), AudioParameters::AUDIO_PCM_LOW_LATENCY); |
172 frames_per_buffer_ = default_params_.frames_per_buffer(); | 170 frames_per_buffer_ = default_params_.frames_per_buffer(); |
173 // We expect the default buffer size to be a 10ms buffer. | 171 // We expect the default buffer size to be a 10ms buffer. |
174 EXPECT_EQ(frames_per_buffer_, sample_rate() / 100); | 172 EXPECT_EQ(frames_per_buffer_, sample_rate() / 100); |
175 } | 173 } |
176 | 174 |
177 ~AudioInputStreamWrapper() {} | 175 ~AudioInputStreamWrapper() {} |
(...skipping 22 matching lines...) Expand all Loading... |
200 AudioInputStream* CreateInputStream() { | 198 AudioInputStream* CreateInputStream() { |
201 AudioInputStream* ais = audio_man_->MakeAudioInputStream( | 199 AudioInputStream* ais = audio_man_->MakeAudioInputStream( |
202 AudioParameters(format(), default_params_.channel_layout(), | 200 AudioParameters(format(), default_params_.channel_layout(), |
203 sample_rate(), bits_per_sample(), frames_per_buffer_, | 201 sample_rate(), bits_per_sample(), frames_per_buffer_, |
204 default_params_.effects()), | 202 default_params_.effects()), |
205 AudioManagerBase::kDefaultDeviceId); | 203 AudioManagerBase::kDefaultDeviceId); |
206 EXPECT_TRUE(ais); | 204 EXPECT_TRUE(ais); |
207 return ais; | 205 return ais; |
208 } | 206 } |
209 | 207 |
210 ScopedCOMInitializer com_init_; | |
211 AudioManager* audio_man_; | 208 AudioManager* audio_man_; |
212 const AudioParameters default_params_; | 209 const AudioParameters default_params_; |
213 int frames_per_buffer_; | 210 int frames_per_buffer_; |
214 }; | 211 }; |
215 | 212 |
216 // Convenience method which creates a default AudioInputStream object. | 213 // Convenience method which creates a default AudioInputStream object. |
217 static AudioInputStream* CreateDefaultAudioInputStream( | 214 static AudioInputStream* CreateDefaultAudioInputStream( |
218 AudioManager* audio_manager) { | 215 AudioManager* audio_manager) { |
219 AudioInputStreamWrapper aisw(audio_manager); | 216 AudioInputStreamWrapper aisw(audio_manager); |
220 AudioInputStream* ais = aisw.Create(); | 217 AudioInputStream* ais = aisw.Create(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 | 250 |
254 DISALLOW_COPY_AND_ASSIGN(ScopedAudioInputStream); | 251 DISALLOW_COPY_AND_ASSIGN(ScopedAudioInputStream); |
255 }; | 252 }; |
256 | 253 |
257 // Verify that we can retrieve the current hardware/mixing sample rate | 254 // Verify that we can retrieve the current hardware/mixing sample rate |
258 // for all available input devices. | 255 // for all available input devices. |
259 TEST(WinAudioInputTest, WASAPIAudioInputStreamHardwareSampleRate) { | 256 TEST(WinAudioInputTest, WASAPIAudioInputStreamHardwareSampleRate) { |
260 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 257 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); |
261 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndInputDevices(audio_manager.get())); | 258 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndInputDevices(audio_manager.get())); |
262 | 259 |
263 ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); | |
264 | |
265 // Retrieve a list of all available input devices. | 260 // Retrieve a list of all available input devices. |
266 media::AudioDeviceNames device_names; | 261 media::AudioDeviceNames device_names; |
267 audio_manager->GetAudioInputDeviceNames(&device_names); | 262 audio_manager->GetAudioInputDeviceNames(&device_names); |
268 | 263 |
269 // Scan all available input devices and repeat the same test for all of them. | 264 // Scan all available input devices and repeat the same test for all of them. |
270 for (media::AudioDeviceNames::const_iterator it = device_names.begin(); | 265 for (media::AudioDeviceNames::const_iterator it = device_names.begin(); |
271 it != device_names.end(); ++it) { | 266 it != device_names.end(); ++it) { |
272 // Retrieve the hardware sample rate given a specified audio input device. | 267 // Retrieve the hardware sample rate given a specified audio input device. |
273 AudioParameters params = WASAPIAudioInputStream::GetInputStreamParameters( | 268 AudioParameters params = WASAPIAudioInputStream::GetInputStreamParameters( |
274 it->unique_id); | 269 it->unique_id); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 WriteToFileAudioSink file_sink(file_name, aisw.bits_per_sample()); | 465 WriteToFileAudioSink file_sink(file_name, aisw.bits_per_sample()); |
471 VLOG(0) << ">> Speak into the default microphone while recording."; | 466 VLOG(0) << ">> Speak into the default microphone while recording."; |
472 ais->Start(&file_sink); | 467 ais->Start(&file_sink); |
473 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); | 468 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); |
474 ais->Stop(); | 469 ais->Stop(); |
475 VLOG(0) << ">> Recording has stopped."; | 470 VLOG(0) << ">> Recording has stopped."; |
476 ais.Close(); | 471 ais.Close(); |
477 } | 472 } |
478 | 473 |
479 } // namespace media | 474 } // namespace media |
OLD | NEW |