| 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/audio_hardware.h" | 7 #include "content/renderer/media/audio_hardware.h" |
| 8 #include "content/renderer/media/webrtc_audio_device_impl.h" | 8 #include "content/renderer/media/webrtc_audio_device_impl.h" |
| 9 #include "content/test/webrtc_audio_device_test.h" | 9 #include "content/test/webrtc_audio_device_test.h" |
| 10 #include "media/audio/audio_manager.h" | 10 #include "media/audio/audio_manager.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 int channel_id_; | 129 int channel_id_; |
| 130 webrtc::ProcessingTypes type_; | 130 webrtc::ProcessingTypes type_; |
| 131 int packet_size_; | 131 int packet_size_; |
| 132 int sample_rate_; | 132 int sample_rate_; |
| 133 int channels_; | 133 int channels_; |
| 134 DISALLOW_COPY_AND_ASSIGN(WebRTCMediaProcessImpl); | 134 DISALLOW_COPY_AND_ASSIGN(WebRTCMediaProcessImpl); |
| 135 }; | 135 }; |
| 136 | 136 |
| 137 } // end namespace | 137 } // end namespace |
| 138 | 138 |
| 139 // Utility class to delete the AudioManager. | |
| 140 // TODO(tommi): Remove when we've fixed issue 105249. | |
| 141 class AutoAudioManagerCleanup { | |
| 142 public: | |
| 143 AutoAudioManagerCleanup() { | |
| 144 // Log an error if a previous test didn't clean up the AudioManager. | |
| 145 if (DeleteAndResurrect()) { | |
| 146 LOG(ERROR) | |
| 147 << "AudioManager singleton was not cleaned up by some previous test!"; | |
| 148 } | |
| 149 } | |
| 150 ~AutoAudioManagerCleanup() { | |
| 151 DeleteAndResurrect(); | |
| 152 } | |
| 153 | |
| 154 private: | |
| 155 // Returns true iff the AudioManager existed and was deleted. | |
| 156 bool DeleteAndResurrect() { | |
| 157 if (AudioManager::SingletonExists()) { | |
| 158 AudioManager::Destroy(NULL); | |
| 159 AudioManager::Resurrect(); | |
| 160 return true; | |
| 161 } | |
| 162 return false; | |
| 163 } | |
| 164 | |
| 165 DISALLOW_COPY_AND_ASSIGN(AutoAudioManagerCleanup); | |
| 166 }; | |
| 167 | |
| 168 // Basic test that instantiates and initializes an instance of | 139 // Basic test that instantiates and initializes an instance of |
| 169 // WebRtcAudioDeviceImpl. | 140 // WebRtcAudioDeviceImpl. |
| 170 TEST_F(WebRTCAudioDeviceTest, Construct) { | 141 TEST_F(WebRTCAudioDeviceTest, Construct) { |
| 171 AutoAudioManagerCleanup audio_manager_cleanup; | |
| 172 AudioUtilNoHardware audio_util(48000.0, 48000.0); | 142 AudioUtilNoHardware audio_util(48000.0, 48000.0); |
| 173 SetAudioUtilCallback(&audio_util); | 143 SetAudioUtilCallback(&audio_util); |
| 174 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( | 144 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( |
| 175 new WebRtcAudioDeviceImpl()); | 145 new WebRtcAudioDeviceImpl()); |
| 176 audio_device->SetSessionId(1); | 146 audio_device->SetSessionId(1); |
| 177 | 147 |
| 178 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); | 148 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); |
| 179 ASSERT_TRUE(engine.valid()); | 149 ASSERT_TRUE(engine.valid()); |
| 180 | 150 |
| 181 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); | 151 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); |
| 182 int err = base->Init(audio_device); | 152 int err = base->Init(audio_device); |
| 183 EXPECT_EQ(0, err); | 153 EXPECT_EQ(0, err); |
| 184 EXPECT_EQ(0, base->Terminate()); | 154 EXPECT_EQ(0, base->Terminate()); |
| 185 } | 155 } |
| 186 | 156 |
| 187 // Verify that a call to webrtc::VoEBase::StartPlayout() starts audio output | 157 // Verify that a call to webrtc::VoEBase::StartPlayout() starts audio output |
| 188 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will | 158 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will |
| 189 // be utilized to implement the actual audio path. The test registers a | 159 // be utilized to implement the actual audio path. The test registers a |
| 190 // webrtc::VoEExternalMedia implementation to hijack the output audio and | 160 // webrtc::VoEExternalMedia implementation to hijack the output audio and |
| 191 // verify that streaming starts correctly. | 161 // verify that streaming starts correctly. |
| 192 // Disabled when running headless since the bots don't have the required config. | 162 // Disabled when running headless since the bots don't have the required config. |
| 193 TEST_F(WebRTCAudioDeviceTest, StartPlayout) { | 163 TEST_F(WebRTCAudioDeviceTest, StartPlayout) { |
| 194 AutoAudioManagerCleanup audio_manager_cleanup; | |
| 195 | |
| 196 if (IsRunningHeadless()) | 164 if (IsRunningHeadless()) |
| 197 return; | 165 return; |
| 198 | 166 |
| 199 AudioUtil audio_util; | 167 AudioUtil audio_util; |
| 200 SetAudioUtilCallback(&audio_util); | 168 SetAudioUtilCallback(&audio_util); |
| 201 | 169 |
| 202 if (!HardwareSampleRatesAreValid()) | 170 if (!HardwareSampleRatesAreValid()) |
| 203 return; | 171 return; |
| 204 | 172 |
| 205 EXPECT_CALL(media_observer(), | 173 EXPECT_CALL(media_observer(), |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 // Verify that a call to webrtc::VoEBase::StartRecording() starts audio input | 226 // Verify that a call to webrtc::VoEBase::StartRecording() starts audio input |
| 259 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will | 227 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will |
| 260 // be utilized to implement the actual audio path. The test registers a | 228 // be utilized to implement the actual audio path. The test registers a |
| 261 // webrtc::VoEExternalMedia implementation to hijack the input audio and | 229 // webrtc::VoEExternalMedia implementation to hijack the input audio and |
| 262 // verify that streaming starts correctly. An external transport implementation | 230 // verify that streaming starts correctly. An external transport implementation |
| 263 // is also required to ensure that "sending" can start without actually trying | 231 // is also required to ensure that "sending" can start without actually trying |
| 264 // to send encoded packets to the network. Our main interest here is to ensure | 232 // to send encoded packets to the network. Our main interest here is to ensure |
| 265 // that the audio capturing starts as it should. | 233 // that the audio capturing starts as it should. |
| 266 // Disabled when running headless since the bots don't have the required config. | 234 // Disabled when running headless since the bots don't have the required config. |
| 267 TEST_F(WebRTCAudioDeviceTest, StartRecording) { | 235 TEST_F(WebRTCAudioDeviceTest, StartRecording) { |
| 268 AutoAudioManagerCleanup audio_manager_cleanup; | |
| 269 | |
| 270 if (IsRunningHeadless()) | 236 if (IsRunningHeadless()) |
| 271 return; | 237 return; |
| 272 | 238 |
| 273 AudioUtil audio_util; | 239 AudioUtil audio_util; |
| 274 SetAudioUtilCallback(&audio_util); | 240 SetAudioUtilCallback(&audio_util); |
| 275 | 241 |
| 276 if (!HardwareSampleRatesAreValid()) | 242 if (!HardwareSampleRatesAreValid()) |
| 277 return; | 243 return; |
| 278 | 244 |
| 279 // TODO(tommi): extend MediaObserver and MockMediaObserver with support | 245 // TODO(tommi): extend MediaObserver and MockMediaObserver with support |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 ch, webrtc::kRecordingPerChannel)); | 293 ch, webrtc::kRecordingPerChannel)); |
| 328 EXPECT_EQ(0, base->StopSend(ch)); | 294 EXPECT_EQ(0, base->StopSend(ch)); |
| 329 | 295 |
| 330 EXPECT_EQ(0, base->DeleteChannel(ch)); | 296 EXPECT_EQ(0, base->DeleteChannel(ch)); |
| 331 EXPECT_EQ(0, base->Terminate()); | 297 EXPECT_EQ(0, base->Terminate()); |
| 332 } | 298 } |
| 333 | 299 |
| 334 // Uses WebRtcAudioDeviceImpl to play a local wave file. | 300 // Uses WebRtcAudioDeviceImpl to play a local wave file. |
| 335 // Disabled when running headless since the bots don't have the required config. | 301 // Disabled when running headless since the bots don't have the required config. |
| 336 TEST_F(WebRTCAudioDeviceTest, PlayLocalFile) { | 302 TEST_F(WebRTCAudioDeviceTest, PlayLocalFile) { |
| 337 AutoAudioManagerCleanup audio_manager_cleanup; | |
| 338 | |
| 339 if (IsRunningHeadless()) | 303 if (IsRunningHeadless()) |
| 340 return; | 304 return; |
| 341 | 305 |
| 342 std::string file_path( | 306 std::string file_path( |
| 343 GetTestDataPath(FILE_PATH_LITERAL("speechmusic_mono_16kHz.pcm"))); | 307 GetTestDataPath(FILE_PATH_LITERAL("speechmusic_mono_16kHz.pcm"))); |
| 344 | 308 |
| 345 AudioUtil audio_util; | 309 AudioUtil audio_util; |
| 346 SetAudioUtilCallback(&audio_util); | 310 SetAudioUtilCallback(&audio_util); |
| 347 | 311 |
| 348 if (!HardwareSampleRatesAreValid()) | 312 if (!HardwareSampleRatesAreValid()) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 375 | 339 |
| 376 ScopedWebRTCPtr<webrtc::VoEFile> file(engine.get()); | 340 ScopedWebRTCPtr<webrtc::VoEFile> file(engine.get()); |
| 377 int duration = 0; | 341 int duration = 0; |
| 378 EXPECT_EQ(0, file->GetFileDuration(file_path.c_str(), duration, | 342 EXPECT_EQ(0, file->GetFileDuration(file_path.c_str(), duration, |
| 379 webrtc::kFileFormatPcm16kHzFile)); | 343 webrtc::kFileFormatPcm16kHzFile)); |
| 380 EXPECT_NE(0, duration); | 344 EXPECT_NE(0, duration); |
| 381 | 345 |
| 382 EXPECT_EQ(0, file->StartPlayingFileLocally(ch, file_path.c_str(), false, | 346 EXPECT_EQ(0, file->StartPlayingFileLocally(ch, file_path.c_str(), false, |
| 383 webrtc::kFileFormatPcm16kHzFile)); | 347 webrtc::kFileFormatPcm16kHzFile)); |
| 384 | 348 |
| 349 // Play 2 seconds worth of audio and then quit. |
| 385 message_loop_.PostDelayedTask(FROM_HERE, | 350 message_loop_.PostDelayedTask(FROM_HERE, |
| 386 new MessageLoop::QuitTask(), | 351 new MessageLoop::QuitTask(), |
| 387 TestTimeouts::action_timeout_ms()); | 352 2000); |
| 388 message_loop_.Run(); | 353 message_loop_.Run(); |
| 389 | 354 |
| 355 |
| 356 EXPECT_EQ(0, base->StopSend(ch)); |
| 357 EXPECT_EQ(0, base->StopPlayout(ch)); |
| 358 EXPECT_EQ(0, base->DeleteChannel(ch)); |
| 390 EXPECT_EQ(0, base->Terminate()); | 359 EXPECT_EQ(0, base->Terminate()); |
| 391 } | 360 } |
| 392 | 361 |
| 393 // Uses WebRtcAudioDeviceImpl to play out recorded audio in loopback. | 362 // Uses WebRtcAudioDeviceImpl to play out recorded audio in loopback. |
| 394 // An external transport implementation is utilized to feed back RTP packets | 363 // An external transport implementation is utilized to feed back RTP packets |
| 395 // which are recorded, encoded, packetized into RTP packets and finally | 364 // which are recorded, encoded, packetized into RTP packets and finally |
| 396 // "transmitted". The RTP packets are then fed back into the VoiceEngine | 365 // "transmitted". The RTP packets are then fed back into the VoiceEngine |
| 397 // where they are decoded and played out on the default audio output device. | 366 // where they are decoded and played out on the default audio output device. |
| 398 // Disabled when running headless since the bots don't have the required config. | 367 // Disabled when running headless since the bots don't have the required config. |
| 399 // TODO(henrika): improve quality by using a wideband codec, enabling noise- | 368 // TODO(henrika): improve quality by using a wideband codec, enabling noise- |
| 400 // suppressions and perhaps also the digital AGC. | 369 // suppressions and perhaps also the digital AGC. |
| 401 TEST_F(WebRTCAudioDeviceTest, FullDuplexAudio) { | 370 TEST_F(WebRTCAudioDeviceTest, FullDuplexAudio) { |
| 402 AutoAudioManagerCleanup audio_manager_cleanup; | |
| 403 | |
| 404 if (IsRunningHeadless()) | 371 if (IsRunningHeadless()) |
| 405 return; | 372 return; |
| 406 | 373 |
| 407 AudioUtil audio_util; | 374 AudioUtil audio_util; |
| 408 SetAudioUtilCallback(&audio_util); | 375 SetAudioUtilCallback(&audio_util); |
| 409 | 376 |
| 410 if (!HardwareSampleRatesAreValid()) | 377 if (!HardwareSampleRatesAreValid()) |
| 411 return; | 378 return; |
| 412 | 379 |
| 413 EXPECT_CALL(media_observer(), | 380 EXPECT_CALL(media_observer(), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 new MessageLoop::QuitTask(), | 412 new MessageLoop::QuitTask(), |
| 446 TestTimeouts::action_timeout_ms()); | 413 TestTimeouts::action_timeout_ms()); |
| 447 message_loop_.Run(); | 414 message_loop_.Run(); |
| 448 | 415 |
| 449 EXPECT_EQ(0, base->StopSend(ch)); | 416 EXPECT_EQ(0, base->StopSend(ch)); |
| 450 EXPECT_EQ(0, base->StopPlayout(ch)); | 417 EXPECT_EQ(0, base->StopPlayout(ch)); |
| 451 | 418 |
| 452 EXPECT_EQ(0, base->DeleteChannel(ch)); | 419 EXPECT_EQ(0, base->DeleteChannel(ch)); |
| 453 EXPECT_EQ(0, base->Terminate()); | 420 EXPECT_EQ(0, base->Terminate()); |
| 454 } | 421 } |
| OLD | NEW |