| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_device_impl.h" | 7 #include "content/renderer/media/webrtc_audio_device_impl.h" |
| 8 #include "content/test/webrtc_audio_device_test.h" | 8 #include "content/test/webrtc_audio_device_test.h" |
| 9 #include "media/audio/audio_util.h" | 9 #include "media/audio/audio_util.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "third_party/webrtc/voice_engine/main/interface/voe_audio_processing.h" | 11 #include "third_party/webrtc/voice_engine/main/interface/voe_audio_processing.h" |
| 12 #include "third_party/webrtc/voice_engine/main/interface/voe_base.h" | 12 #include "third_party/webrtc/voice_engine/main/interface/voe_base.h" |
| 13 #include "third_party/webrtc/voice_engine/main/interface/voe_external_media.h" | 13 #include "third_party/webrtc/voice_engine/main/interface/voe_external_media.h" |
| 14 #include "third_party/webrtc/voice_engine/main/interface/voe_file.h" | 14 #include "third_party/webrtc/voice_engine/main/interface/voe_file.h" |
| 15 #include "third_party/webrtc/voice_engine/main/interface/voe_network.h" | 15 #include "third_party/webrtc/voice_engine/main/interface/voe_network.h" |
| 16 | 16 |
| 17 using testing::_; | 17 using testing::_; |
| 18 using testing::AnyNumber; |
| 18 using testing::InvokeWithoutArgs; | 19 using testing::InvokeWithoutArgs; |
| 19 using testing::Return; | 20 using testing::Return; |
| 20 using testing::StrEq; | 21 using testing::StrEq; |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 ACTION_P(QuitMessageLoop, loop_or_proxy) { | 25 ACTION_P(QuitMessageLoop, loop_or_proxy) { |
| 25 loop_or_proxy->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 26 loop_or_proxy->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 26 } | 27 } |
| 27 | 28 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 int channels_; | 111 int channels_; |
| 111 DISALLOW_COPY_AND_ASSIGN(WebRTCMediaProcessImpl); | 112 DISALLOW_COPY_AND_ASSIGN(WebRTCMediaProcessImpl); |
| 112 }; | 113 }; |
| 113 | 114 |
| 114 } // end namespace | 115 } // end namespace |
| 115 | 116 |
| 116 // Basic test that instantiates and initializes an instance of | 117 // Basic test that instantiates and initializes an instance of |
| 117 // WebRtcAudioDeviceImpl. | 118 // WebRtcAudioDeviceImpl. |
| 118 TEST_F(WebRTCAudioDeviceTest, Construct) { | 119 TEST_F(WebRTCAudioDeviceTest, Construct) { |
| 119 AudioUtilNoHardware audio_util(48000.0, 48000.0); | 120 AudioUtilNoHardware audio_util(48000.0, 48000.0); |
| 120 set_audio_util_callback(&audio_util); | 121 SetAudioUtilCallback(&audio_util); |
| 121 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( | 122 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( |
| 122 new WebRtcAudioDeviceImpl()); | 123 new WebRtcAudioDeviceImpl()); |
| 123 audio_device->SetSessionId(1); | 124 audio_device->SetSessionId(1); |
| 124 | 125 |
| 125 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); | 126 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); |
| 126 ASSERT_TRUE(engine.valid()); | 127 ASSERT_TRUE(engine.valid()); |
| 127 | 128 |
| 128 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); | 129 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); |
| 129 int err = base->Init(audio_device); | 130 int err = base->Init(audio_device); |
| 130 EXPECT_EQ(0, err); | 131 EXPECT_EQ(0, err); |
| 131 EXPECT_EQ(0, base->Terminate()); | 132 EXPECT_EQ(0, base->Terminate()); |
| 132 } | 133 } |
| 133 | 134 |
| 134 // Verify that a call to webrtc::VoEBase::StartPlayout() starts audio output | 135 // Verify that a call to webrtc::VoEBase::StartPlayout() starts audio output |
| 135 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will | 136 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will |
| 136 // be utilized to implement the actual audio path. The test registers a | 137 // be utilized to implement the actual audio path. The test registers a |
| 137 // webrtc::VoEExternalMedia implementation to hijack the output audio and | 138 // webrtc::VoEExternalMedia implementation to hijack the output audio and |
| 138 // verify that streaming starts correctly. | 139 // verify that streaming starts correctly. |
| 139 // Disabled when running headless since the bots don't have the required config. | 140 // Disabled when running headless since the bots don't have the required config. |
| 140 TEST_F(WebRTCAudioDeviceTest, StartPlayout) { | 141 TEST_F(WebRTCAudioDeviceTest, StartPlayout) { |
| 141 if (IsRunningHeadless()) | 142 if (IsRunningHeadless()) |
| 142 return; | 143 return; |
| 143 | 144 |
| 144 AudioUtil audio_util; | 145 AudioUtil audio_util; |
| 145 set_audio_util_callback(&audio_util); | 146 SetAudioUtilCallback(&audio_util); |
| 146 | 147 |
| 147 EXPECT_CALL(media_observer(), | 148 EXPECT_CALL(media_observer(), |
| 148 OnSetAudioStreamStatus(_, 1, StrEq("created"))).Times(1); | 149 OnSetAudioStreamStatus(_, 1, StrEq("created"))).Times(1); |
| 149 EXPECT_CALL(media_observer(), | 150 EXPECT_CALL(media_observer(), |
| 150 OnSetAudioStreamPlaying(_, 1, true)).Times(1); | 151 OnSetAudioStreamPlaying(_, 1, true)).Times(1); |
| 151 EXPECT_CALL(media_observer(), | 152 EXPECT_CALL(media_observer(), |
| 152 OnSetAudioStreamStatus(_, 1, StrEq("closed"))).Times(1); | 153 OnSetAudioStreamStatus(_, 1, StrEq("closed"))).Times(1); |
| 153 EXPECT_CALL(media_observer(), | 154 EXPECT_CALL(media_observer(), |
| 154 OnDeleteAudioStream(_, 1)).Times(1); | 155 OnDeleteAudioStream(_, 1)).Times(AnyNumber()); |
| 155 | 156 |
| 156 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( | 157 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( |
| 157 new WebRtcAudioDeviceImpl()); | 158 new WebRtcAudioDeviceImpl()); |
| 158 audio_device->SetSessionId(1); | 159 audio_device->SetSessionId(1); |
| 159 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); | 160 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); |
| 160 ASSERT_TRUE(engine.valid()); | 161 ASSERT_TRUE(engine.valid()); |
| 161 | 162 |
| 162 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); | 163 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); |
| 163 ASSERT_TRUE(base.valid()); | 164 ASSERT_TRUE(base.valid()); |
| 164 int err = base->Init(audio_device); | 165 int err = base->Init(audio_device); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 // verify that streaming starts correctly. An external transport implementation | 205 // verify that streaming starts correctly. An external transport implementation |
| 205 // is also required to ensure that "sending" can start without actually trying | 206 // is also required to ensure that "sending" can start without actually trying |
| 206 // to send encoded packets to the network. Our main interest here is to ensure | 207 // to send encoded packets to the network. Our main interest here is to ensure |
| 207 // that the audio capturing starts as it should. | 208 // that the audio capturing starts as it should. |
| 208 // Disabled when running headless since the bots don't have the required config. | 209 // Disabled when running headless since the bots don't have the required config. |
| 209 TEST_F(WebRTCAudioDeviceTest, StartRecording) { | 210 TEST_F(WebRTCAudioDeviceTest, StartRecording) { |
| 210 if (IsRunningHeadless()) | 211 if (IsRunningHeadless()) |
| 211 return; | 212 return; |
| 212 | 213 |
| 213 AudioUtil audio_util; | 214 AudioUtil audio_util; |
| 214 set_audio_util_callback(&audio_util); | 215 SetAudioUtilCallback(&audio_util); |
| 215 | 216 |
| 216 // TODO(tommi): extend MediaObserver and MockMediaObserver with support | 217 // TODO(tommi): extend MediaObserver and MockMediaObserver with support |
| 217 // for new interfaces, like OnSetAudioStreamRecording(). When done, add | 218 // for new interfaces, like OnSetAudioStreamRecording(). When done, add |
| 218 // EXPECT_CALL() macros here. | 219 // EXPECT_CALL() macros here. |
| 219 | 220 |
| 220 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( | 221 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( |
| 221 new WebRtcAudioDeviceImpl()); | 222 new WebRtcAudioDeviceImpl()); |
| 222 audio_device->SetSessionId(1); | 223 audio_device->SetSessionId(1); |
| 223 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); | 224 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); |
| 224 ASSERT_TRUE(engine.valid()); | 225 ASSERT_TRUE(engine.valid()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 // Uses WebRtcAudioDeviceImpl to play a local wave file. | 272 // Uses WebRtcAudioDeviceImpl to play a local wave file. |
| 272 // Disabled when running headless since the bots don't have the required config. | 273 // Disabled when running headless since the bots don't have the required config. |
| 273 TEST_F(WebRTCAudioDeviceTest, PlayLocalFile) { | 274 TEST_F(WebRTCAudioDeviceTest, PlayLocalFile) { |
| 274 if (IsRunningHeadless()) | 275 if (IsRunningHeadless()) |
| 275 return; | 276 return; |
| 276 | 277 |
| 277 std::string file_path( | 278 std::string file_path( |
| 278 GetTestDataPath(FILE_PATH_LITERAL("speechmusic_mono_16kHz.pcm"))); | 279 GetTestDataPath(FILE_PATH_LITERAL("speechmusic_mono_16kHz.pcm"))); |
| 279 | 280 |
| 280 AudioUtil audio_util; | 281 AudioUtil audio_util; |
| 281 set_audio_util_callback(&audio_util); | 282 SetAudioUtilCallback(&audio_util); |
| 282 | 283 |
| 283 EXPECT_CALL(media_observer(), | 284 EXPECT_CALL(media_observer(), |
| 284 OnSetAudioStreamStatus(_, 1, StrEq("created"))).Times(1); | 285 OnSetAudioStreamStatus(_, 1, StrEq("created"))).Times(1); |
| 285 EXPECT_CALL(media_observer(), | 286 EXPECT_CALL(media_observer(), |
| 286 OnSetAudioStreamPlaying(_, 1, true)).Times(1); | 287 OnSetAudioStreamPlaying(_, 1, true)).Times(1); |
| 287 EXPECT_CALL(media_observer(), | 288 EXPECT_CALL(media_observer(), |
| 288 OnSetAudioStreamStatus(_, 1, StrEq("closed"))).Times(1); | 289 OnSetAudioStreamStatus(_, 1, StrEq("closed"))).Times(1); |
| 289 EXPECT_CALL(media_observer(), | 290 EXPECT_CALL(media_observer(), |
| 290 OnDeleteAudioStream(_, 1)).Times(1); | 291 OnDeleteAudioStream(_, 1)).Times(AnyNumber()); |
| 291 | 292 |
| 292 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( | 293 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( |
| 293 new WebRtcAudioDeviceImpl()); | 294 new WebRtcAudioDeviceImpl()); |
| 294 audio_device->SetSessionId(1); | 295 audio_device->SetSessionId(1); |
| 295 | 296 |
| 296 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); | 297 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); |
| 297 ASSERT_TRUE(engine.valid()); | 298 ASSERT_TRUE(engine.valid()); |
| 298 | 299 |
| 299 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); | 300 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); |
| 300 ASSERT_TRUE(base.valid()); | 301 ASSERT_TRUE(base.valid()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 327 // which are recorded, encoded, packetized into RTP packets and finally | 328 // which are recorded, encoded, packetized into RTP packets and finally |
| 328 // "transmitted". The RTP packets are then fed back into the VoiceEngine | 329 // "transmitted". The RTP packets are then fed back into the VoiceEngine |
| 329 // where they are decoded and played out on the default audio output device. | 330 // where they are decoded and played out on the default audio output device. |
| 330 // Disabled when running headless since the bots don't have the required config. | 331 // Disabled when running headless since the bots don't have the required config. |
| 331 // TODO(henrika): improve quality by using a wideband codec, enabling noise- | 332 // TODO(henrika): improve quality by using a wideband codec, enabling noise- |
| 332 // suppressions and perhaps also the digital AGC. | 333 // suppressions and perhaps also the digital AGC. |
| 333 TEST_F(WebRTCAudioDeviceTest, FullDuplexAudio) { | 334 TEST_F(WebRTCAudioDeviceTest, FullDuplexAudio) { |
| 334 if (IsRunningHeadless()) | 335 if (IsRunningHeadless()) |
| 335 return; | 336 return; |
| 336 | 337 |
| 338 EXPECT_CALL(media_observer(), |
| 339 OnSetAudioStreamStatus(_, 1, StrEq("created"))); |
| 340 EXPECT_CALL(media_observer(), |
| 341 OnSetAudioStreamPlaying(_, 1, true)); |
| 342 EXPECT_CALL(media_observer(), |
| 343 OnSetAudioStreamStatus(_, 1, StrEq("closed"))); |
| 344 |
| 337 AudioUtil audio_util; | 345 AudioUtil audio_util; |
| 338 set_audio_util_callback(&audio_util); | 346 SetAudioUtilCallback(&audio_util); |
| 339 | 347 |
| 340 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( | 348 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( |
| 341 new WebRtcAudioDeviceImpl()); | 349 new WebRtcAudioDeviceImpl()); |
| 342 audio_device->SetSessionId(1); | 350 audio_device->SetSessionId(1); |
| 343 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); | 351 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); |
| 344 ASSERT_TRUE(engine.valid()); | 352 ASSERT_TRUE(engine.valid()); |
| 345 | 353 |
| 346 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); | 354 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); |
| 347 ASSERT_TRUE(base.valid()); | 355 ASSERT_TRUE(base.valid()); |
| 348 int err = base->Init(audio_device); | 356 int err = base->Init(audio_device); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 363 new MessageLoop::QuitTask(), | 371 new MessageLoop::QuitTask(), |
| 364 TestTimeouts::action_timeout_ms()); | 372 TestTimeouts::action_timeout_ms()); |
| 365 message_loop_.Run(); | 373 message_loop_.Run(); |
| 366 | 374 |
| 367 EXPECT_EQ(0, base->StopSend(ch)); | 375 EXPECT_EQ(0, base->StopSend(ch)); |
| 368 EXPECT_EQ(0, base->StopPlayout(ch)); | 376 EXPECT_EQ(0, base->StopPlayout(ch)); |
| 369 | 377 |
| 370 EXPECT_EQ(0, base->DeleteChannel(ch)); | 378 EXPECT_EQ(0, base->DeleteChannel(ch)); |
| 371 EXPECT_EQ(0, base->Terminate()); | 379 EXPECT_EQ(0, base->Terminate()); |
| 372 } | 380 } |
| OLD | NEW |