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/audio/audio_util.h" | |
14 #include "media/base/audio_hardware_config.h" | 13 #include "media/base/audio_hardware_config.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "third_party/webrtc/voice_engine/include/voe_audio_processing.h" | 15 #include "third_party/webrtc/voice_engine/include/voe_audio_processing.h" |
17 #include "third_party/webrtc/voice_engine/include/voe_base.h" | 16 #include "third_party/webrtc/voice_engine/include/voe_base.h" |
18 #include "third_party/webrtc/voice_engine/include/voe_external_media.h" | 17 #include "third_party/webrtc/voice_engine/include/voe_external_media.h" |
19 #include "third_party/webrtc/voice_engine/include/voe_file.h" | 18 #include "third_party/webrtc/voice_engine/include/voe_file.h" |
20 #include "third_party/webrtc/voice_engine/include/voe_network.h" | 19 #include "third_party/webrtc/voice_engine/include/voe_network.h" |
21 | 20 |
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( |
| 34 media::AudioManager* manager) { |
| 35 const media::AudioParameters output_parameters = |
| 36 manager->GetDefaultOutputStreamParameters(); |
| 37 const media::AudioParameters input_parameters = |
| 38 manager->GetInputStreamParameters( |
| 39 media::AudioManagerBase::kDefaultDeviceId); |
35 return make_scoped_ptr(new media::AudioHardwareConfig( | 40 return make_scoped_ptr(new media::AudioHardwareConfig( |
36 media::GetAudioHardwareBufferSize(), media::GetAudioHardwareSampleRate(), | 41 output_parameters.frames_per_buffer(), output_parameters.sample_rate(), |
37 media::GetAudioInputHardwareSampleRate( | 42 input_parameters.sample_rate(), input_parameters.channel_layout())); |
38 media::AudioManagerBase::kDefaultDeviceId), | |
39 media::GetAudioInputHardwareChannelLayout( | |
40 media::AudioManagerBase::kDefaultDeviceId))); | |
41 } | 43 } |
42 | 44 |
43 // 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|. |
44 bool FindElementInArray(const int* array, int size, int value) { | 46 bool FindElementInArray(const int* array, int size, int value) { |
45 return (std::find(&array[0], &array[0] + size, value) != &array[size]); | 47 return (std::find(&array[0], &array[0] + size, value) != &array[size]); |
46 } | 48 } |
47 | 49 |
48 // 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 |
49 // input or output side. | 51 // input or output side. |
50 // TODO(henrika): add support for automatic fallback to Windows Wave audio | 52 // TODO(henrika): add support for automatic fallback to Windows Wave audio |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 // webrtc::VoEExternalMedia implementation to hijack the output audio and | 245 // webrtc::VoEExternalMedia implementation to hijack the output audio and |
244 // verify that streaming starts correctly. | 246 // verify that streaming starts correctly. |
245 // Disabled when running headless since the bots don't have the required config. | 247 // Disabled when running headless since the bots don't have the required config. |
246 // Flaky, http://crbug.com/167299 . | 248 // Flaky, http://crbug.com/167299 . |
247 TEST_F(WebRTCAudioDeviceTest, DISABLED_StartPlayout) { | 249 TEST_F(WebRTCAudioDeviceTest, DISABLED_StartPlayout) { |
248 if (!has_output_devices_) { | 250 if (!has_output_devices_) { |
249 LOG(WARNING) << "No output device detected."; | 251 LOG(WARNING) << "No output device detected."; |
250 return; | 252 return; |
251 } | 253 } |
252 | 254 |
253 scoped_ptr<media::AudioHardwareConfig> config = CreateRealHardwareConfig(); | 255 scoped_ptr<media::AudioHardwareConfig> config = |
| 256 CreateRealHardwareConfig(audio_manager_.get()); |
254 SetAudioHardwareConfig(config.get()); | 257 SetAudioHardwareConfig(config.get()); |
255 | 258 |
256 if (!HardwareSampleRatesAreValid()) | 259 if (!HardwareSampleRatesAreValid()) |
257 return; | 260 return; |
258 | 261 |
259 EXPECT_CALL(media_observer(), | 262 EXPECT_CALL(media_observer(), |
260 OnSetAudioStreamStatus(_, 1, StrEq("created"))).Times(1); | 263 OnSetAudioStreamStatus(_, 1, StrEq("created"))).Times(1); |
261 EXPECT_CALL(media_observer(), | 264 EXPECT_CALL(media_observer(), |
262 OnSetAudioStreamPlaying(_, 1, true)).Times(1); | 265 OnSetAudioStreamPlaying(_, 1, true)).Times(1); |
263 EXPECT_CALL(media_observer(), | 266 EXPECT_CALL(media_observer(), |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 #define MAYBE_StartRecording DISABLED_StartRecording | 332 #define MAYBE_StartRecording DISABLED_StartRecording |
330 #else | 333 #else |
331 #define MAYBE_StartRecording StartRecording | 334 #define MAYBE_StartRecording StartRecording |
332 #endif | 335 #endif |
333 TEST_F(WebRTCAudioDeviceTest, MAYBE_StartRecording) { | 336 TEST_F(WebRTCAudioDeviceTest, MAYBE_StartRecording) { |
334 if (!has_input_devices_ || !has_output_devices_) { | 337 if (!has_input_devices_ || !has_output_devices_) { |
335 LOG(WARNING) << "Missing audio devices."; | 338 LOG(WARNING) << "Missing audio devices."; |
336 return; | 339 return; |
337 } | 340 } |
338 | 341 |
339 scoped_ptr<media::AudioHardwareConfig> config = CreateRealHardwareConfig(); | 342 scoped_ptr<media::AudioHardwareConfig> config = |
| 343 CreateRealHardwareConfig(audio_manager_.get()); |
340 SetAudioHardwareConfig(config.get()); | 344 SetAudioHardwareConfig(config.get()); |
341 | 345 |
342 if (!HardwareSampleRatesAreValid()) | 346 if (!HardwareSampleRatesAreValid()) |
343 return; | 347 return; |
344 | 348 |
345 // TODO(tommi): extend MediaObserver and MockMediaObserver with support | 349 // TODO(tommi): extend MediaObserver and MockMediaObserver with support |
346 // for new interfaces, like OnSetAudioStreamRecording(). When done, add | 350 // for new interfaces, like OnSetAudioStreamRecording(). When done, add |
347 // EXPECT_CALL() macros here. | 351 // EXPECT_CALL() macros here. |
348 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | 352 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
349 new WebRtcAudioDeviceImpl()); | 353 new WebRtcAudioDeviceImpl()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 // Flaky, http://crbug.com/167298 . | 406 // Flaky, http://crbug.com/167298 . |
403 TEST_F(WebRTCAudioDeviceTest, DISABLED_PlayLocalFile) { | 407 TEST_F(WebRTCAudioDeviceTest, DISABLED_PlayLocalFile) { |
404 if (!has_output_devices_) { | 408 if (!has_output_devices_) { |
405 LOG(WARNING) << "No output device detected."; | 409 LOG(WARNING) << "No output device detected."; |
406 return; | 410 return; |
407 } | 411 } |
408 | 412 |
409 std::string file_path( | 413 std::string file_path( |
410 GetTestDataPath(FILE_PATH_LITERAL("speechmusic_mono_16kHz.pcm"))); | 414 GetTestDataPath(FILE_PATH_LITERAL("speechmusic_mono_16kHz.pcm"))); |
411 | 415 |
412 scoped_ptr<media::AudioHardwareConfig> config = CreateRealHardwareConfig(); | 416 scoped_ptr<media::AudioHardwareConfig> config = |
| 417 CreateRealHardwareConfig(audio_manager_.get()); |
413 SetAudioHardwareConfig(config.get()); | 418 SetAudioHardwareConfig(config.get()); |
414 | 419 |
415 if (!HardwareSampleRatesAreValid()) | 420 if (!HardwareSampleRatesAreValid()) |
416 return; | 421 return; |
417 | 422 |
418 EXPECT_CALL(media_observer(), | 423 EXPECT_CALL(media_observer(), |
419 OnSetAudioStreamStatus(_, 1, StrEq("created"))).Times(1); | 424 OnSetAudioStreamStatus(_, 1, StrEq("created"))).Times(1); |
420 EXPECT_CALL(media_observer(), | 425 EXPECT_CALL(media_observer(), |
421 OnSetAudioStreamPlaying(_, 1, true)).Times(1); | 426 OnSetAudioStreamPlaying(_, 1, true)).Times(1); |
422 EXPECT_CALL(media_observer(), | 427 EXPECT_CALL(media_observer(), |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 #define MAYBE_FullDuplexAudioWithAGC DISABLED_FullDuplexAudioWithAGC | 484 #define MAYBE_FullDuplexAudioWithAGC DISABLED_FullDuplexAudioWithAGC |
480 #else | 485 #else |
481 #define MAYBE_FullDuplexAudioWithAGC FullDuplexAudioWithAGC | 486 #define MAYBE_FullDuplexAudioWithAGC FullDuplexAudioWithAGC |
482 #endif | 487 #endif |
483 TEST_F(WebRTCAudioDeviceTest, MAYBE_FullDuplexAudioWithAGC) { | 488 TEST_F(WebRTCAudioDeviceTest, MAYBE_FullDuplexAudioWithAGC) { |
484 if (!has_output_devices_ || !has_input_devices_) { | 489 if (!has_output_devices_ || !has_input_devices_) { |
485 LOG(WARNING) << "Missing audio devices."; | 490 LOG(WARNING) << "Missing audio devices."; |
486 return; | 491 return; |
487 } | 492 } |
488 | 493 |
489 scoped_ptr<media::AudioHardwareConfig> config = CreateRealHardwareConfig(); | 494 scoped_ptr<media::AudioHardwareConfig> config = |
| 495 CreateRealHardwareConfig(audio_manager_.get()); |
490 SetAudioHardwareConfig(config.get()); | 496 SetAudioHardwareConfig(config.get()); |
491 | 497 |
492 if (!HardwareSampleRatesAreValid()) | 498 if (!HardwareSampleRatesAreValid()) |
493 return; | 499 return; |
494 | 500 |
495 EXPECT_CALL(media_observer(), | 501 EXPECT_CALL(media_observer(), |
496 OnSetAudioStreamStatus(_, 1, StrEq("created"))); | 502 OnSetAudioStreamStatus(_, 1, StrEq("created"))); |
497 EXPECT_CALL(media_observer(), | 503 EXPECT_CALL(media_observer(), |
498 OnSetAudioStreamPlaying(_, 1, true)); | 504 OnSetAudioStreamPlaying(_, 1, true)); |
499 EXPECT_CALL(media_observer(), | 505 EXPECT_CALL(media_observer(), |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 | 559 |
554 renderer->Stop(); | 560 renderer->Stop(); |
555 EXPECT_EQ(0, base->StopSend(ch)); | 561 EXPECT_EQ(0, base->StopSend(ch)); |
556 EXPECT_EQ(0, base->StopPlayout(ch)); | 562 EXPECT_EQ(0, base->StopPlayout(ch)); |
557 | 563 |
558 EXPECT_EQ(0, base->DeleteChannel(ch)); | 564 EXPECT_EQ(0, base->DeleteChannel(ch)); |
559 EXPECT_EQ(0, base->Terminate()); | 565 EXPECT_EQ(0, base->Terminate()); |
560 } | 566 } |
561 | 567 |
562 } // namespace content | 568 } // namespace content |
OLD | NEW |