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 "base/environment.h" | 5 #include "base/environment.h" |
6 #include "base/test/test_timeouts.h" | 6 #include "base/test/test_timeouts.h" |
7 #include "content/renderer/media/webrtc_audio_capturer.h" | 7 #include "content/renderer/media/webrtc_audio_capturer.h" |
8 #include "content/renderer/media/webrtc_audio_device_impl.h" | 8 #include "content/renderer/media/webrtc_audio_device_impl.h" |
9 #include "content/renderer/media/webrtc_audio_renderer.h" | 9 #include "content/renderer/media/webrtc_audio_renderer.h" |
10 #include "content/renderer/render_thread_impl.h" | 10 #include "content/renderer/render_thread_impl.h" |
11 #include "content/test/webrtc_audio_device_test.h" | 11 #include "content/test/webrtc_audio_device_test.h" |
12 #include "media/audio/audio_manager_base.h" | 12 #include "media/audio/audio_manager_base.h" |
13 #include "media/base/audio_hardware_config.h" | 13 #include "media/base/audio_hardware_config.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "third_party/webrtc/voice_engine/include/voe_audio_processing.h" | 15 #include "third_party/webrtc/voice_engine/include/voe_audio_processing.h" |
16 #include "third_party/webrtc/voice_engine/include/voe_base.h" | 16 #include "third_party/webrtc/voice_engine/include/voe_base.h" |
17 #include "third_party/webrtc/voice_engine/include/voe_external_media.h" | 17 #include "third_party/webrtc/voice_engine/include/voe_external_media.h" |
18 #include "third_party/webrtc/voice_engine/include/voe_file.h" | 18 #include "third_party/webrtc/voice_engine/include/voe_file.h" |
19 #include "third_party/webrtc/voice_engine/include/voe_network.h" | 19 #include "third_party/webrtc/voice_engine/include/voe_network.h" |
20 | 20 |
21 using media::AudioParameters; | |
22 using testing::_; | 21 using testing::_; |
23 using testing::AnyNumber; | 22 using testing::AnyNumber; |
24 using testing::InvokeWithoutArgs; | 23 using testing::InvokeWithoutArgs; |
25 using testing::Return; | 24 using testing::Return; |
26 using testing::StrEq; | 25 using testing::StrEq; |
27 | 26 |
28 namespace content { | 27 namespace content { |
29 | 28 |
30 namespace { | 29 namespace { |
31 | 30 |
32 const int kRenderViewId = 1; | 31 const int kRenderViewId = 1; |
33 | 32 |
34 scoped_ptr<media::AudioHardwareConfig> CreateRealHardwareConfig( | 33 scoped_ptr<media::AudioHardwareConfig> CreateRealHardwareConfig( |
35 media::AudioManager* manager) { | 34 media::AudioManager* manager) { |
36 const AudioParameters output_parameters = | 35 const media::AudioParameters output_parameters = |
37 manager->GetDefaultOutputStreamParameters(); | 36 manager->GetDefaultOutputStreamParameters(); |
38 const AudioParameters input_parameters = | 37 const media::AudioParameters input_parameters = |
39 manager->GetInputStreamParameters( | 38 manager->GetInputStreamParameters( |
40 media::AudioManagerBase::kDefaultDeviceId); | 39 media::AudioManagerBase::kDefaultDeviceId); |
41 return make_scoped_ptr(new media::AudioHardwareConfig( | 40 return make_scoped_ptr(new media::AudioHardwareConfig( |
42 input_parameters, output_parameters)); | 41 output_parameters.frames_per_buffer(), output_parameters.sample_rate(), |
| 42 input_parameters.sample_rate(), input_parameters.channel_layout())); |
43 } | 43 } |
44 | 44 |
45 // Return true if at least one element in the array matches |value|. | 45 // Return true if at least one element in the array matches |value|. |
46 bool FindElementInArray(const int* array, int size, int value) { | 46 bool FindElementInArray(const int* array, int size, int value) { |
47 return (std::find(&array[0], &array[0] + size, value) != &array[size]); | 47 return (std::find(&array[0], &array[0] + size, value) != &array[size]); |
48 } | 48 } |
49 | 49 |
50 // This method returns false if a non-supported rate is detected on the | 50 // This method returns false if a non-supported rate is detected on the |
51 // input or output side. | 51 // input or output side. |
52 // TODO(henrika): add support for automatic fallback to Windows Wave audio | 52 // TODO(henrika): add support for automatic fallback to Windows Wave audio |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 int invalid_rates[] = {-1, 0, 8000, 11025, 22050, 32000, 192000}; | 211 int invalid_rates[] = {-1, 0, 8000, 11025, 22050, 32000, 192000}; |
212 for (size_t i = 0; i < arraysize(invalid_rates); ++i) { | 212 for (size_t i = 0; i < arraysize(invalid_rates); ++i) { |
213 EXPECT_FALSE(FindElementInArray(valid_rates, arraysize(valid_rates), | 213 EXPECT_FALSE(FindElementInArray(valid_rates, arraysize(valid_rates), |
214 invalid_rates[i])); | 214 invalid_rates[i])); |
215 } | 215 } |
216 } | 216 } |
217 | 217 |
218 // Basic test that instantiates and initializes an instance of | 218 // Basic test that instantiates and initializes an instance of |
219 // WebRtcAudioDeviceImpl. | 219 // WebRtcAudioDeviceImpl. |
220 TEST_F(WebRTCAudioDeviceTest, Construct) { | 220 TEST_F(WebRTCAudioDeviceTest, Construct) { |
221 AudioParameters input_params( | 221 media::AudioHardwareConfig audio_config( |
222 AudioParameters::AUDIO_PCM_LOW_LATENCY, | 222 480, 48000, 48000, media::CHANNEL_LAYOUT_MONO); |
223 media::CHANNEL_LAYOUT_MONO, | |
224 48000, | |
225 16, | |
226 480); | |
227 | |
228 AudioParameters output_params( | |
229 AudioParameters::AUDIO_PCM_LOW_LATENCY, | |
230 media::CHANNEL_LAYOUT_STEREO, | |
231 48000, | |
232 16, | |
233 480); | |
234 | |
235 media::AudioHardwareConfig audio_config(input_params, output_params); | |
236 SetAudioHardwareConfig(&audio_config); | 223 SetAudioHardwareConfig(&audio_config); |
237 | 224 |
238 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | 225 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
239 new WebRtcAudioDeviceImpl()); | 226 new WebRtcAudioDeviceImpl()); |
240 | 227 |
241 // The capturer is not created until after the WebRtcAudioDeviceImpl has | 228 // The capturer is not created until after the WebRtcAudioDeviceImpl has |
242 // been initialized. | 229 // been initialized. |
243 EXPECT_FALSE(InitializeCapturer(webrtc_audio_device.get())); | 230 EXPECT_FALSE(InitializeCapturer(webrtc_audio_device.get())); |
244 | 231 |
245 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); | 232 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 | 559 |
573 renderer->Stop(); | 560 renderer->Stop(); |
574 EXPECT_EQ(0, base->StopSend(ch)); | 561 EXPECT_EQ(0, base->StopSend(ch)); |
575 EXPECT_EQ(0, base->StopPlayout(ch)); | 562 EXPECT_EQ(0, base->StopPlayout(ch)); |
576 | 563 |
577 EXPECT_EQ(0, base->DeleteChannel(ch)); | 564 EXPECT_EQ(0, base->DeleteChannel(ch)); |
578 EXPECT_EQ(0, base->Terminate()); | 565 EXPECT_EQ(0, base->Terminate()); |
579 } | 566 } |
580 | 567 |
581 } // namespace content | 568 } // namespace content |
OLD | NEW |