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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 webrtc::ProcessingTypes type_; | 150 webrtc::ProcessingTypes type_; |
151 int packet_size_; | 151 int packet_size_; |
152 int sample_rate_; | 152 int sample_rate_; |
153 int channels_; | 153 int channels_; |
154 mutable base::Lock lock_; | 154 mutable base::Lock lock_; |
155 DISALLOW_COPY_AND_ASSIGN(WebRTCMediaProcessImpl); | 155 DISALLOW_COPY_AND_ASSIGN(WebRTCMediaProcessImpl); |
156 }; | 156 }; |
157 | 157 |
158 } // end namespace | 158 } // end namespace |
159 | 159 |
160 // Utility class to delete the AudioManager. | |
161 // TODO(tommi): Remove when we've fixed issue 105249. | |
162 class AutoAudioManagerCleanup { | |
163 public: | |
164 AutoAudioManagerCleanup() { | |
165 // Log an error if a previous test didn't clean up the AudioManager. | |
166 if (DeleteAndResurrect()) { | |
167 LOG(ERROR) | |
168 << "AudioManager singleton was not cleaned up by some previous test!"; | |
169 } | |
170 } | |
171 ~AutoAudioManagerCleanup() { | |
172 DeleteAndResurrect(); | |
173 } | |
174 | |
175 private: | |
176 // Returns true iff the AudioManager existed and was deleted. | |
177 bool DeleteAndResurrect() { | |
178 if (AudioManager::SingletonExists()) { | |
179 AudioManager::Destroy(NULL); | |
180 AudioManager::Resurrect(); | |
181 return true; | |
182 } | |
183 return false; | |
184 } | |
185 | |
186 DISALLOW_COPY_AND_ASSIGN(AutoAudioManagerCleanup); | |
187 }; | |
188 | |
189 // Basic test that instantiates and initializes an instance of | 160 // Basic test that instantiates and initializes an instance of |
190 // WebRtcAudioDeviceImpl. | 161 // WebRtcAudioDeviceImpl. |
191 TEST_F(WebRTCAudioDeviceTest, Construct) { | 162 TEST_F(WebRTCAudioDeviceTest, Construct) { |
192 AutoAudioManagerCleanup audio_manager_cleanup; | |
193 AudioUtilNoHardware audio_util(48000.0, 48000.0); | 163 AudioUtilNoHardware audio_util(48000.0, 48000.0); |
194 SetAudioUtilCallback(&audio_util); | 164 SetAudioUtilCallback(&audio_util); |
195 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( | 165 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( |
196 new WebRtcAudioDeviceImpl()); | 166 new WebRtcAudioDeviceImpl()); |
197 audio_device->SetSessionId(1); | 167 audio_device->SetSessionId(1); |
198 | 168 |
199 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); | 169 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); |
200 ASSERT_TRUE(engine.valid()); | 170 ASSERT_TRUE(engine.valid()); |
201 | 171 |
202 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); | 172 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); |
203 int err = base->Init(audio_device); | 173 int err = base->Init(audio_device); |
204 EXPECT_EQ(0, err); | 174 EXPECT_EQ(0, err); |
205 EXPECT_EQ(0, base->Terminate()); | 175 EXPECT_EQ(0, base->Terminate()); |
206 } | 176 } |
207 | 177 |
208 // Verify that a call to webrtc::VoEBase::StartPlayout() starts audio output | 178 // Verify that a call to webrtc::VoEBase::StartPlayout() starts audio output |
209 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will | 179 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will |
210 // be utilized to implement the actual audio path. The test registers a | 180 // be utilized to implement the actual audio path. The test registers a |
211 // webrtc::VoEExternalMedia implementation to hijack the output audio and | 181 // webrtc::VoEExternalMedia implementation to hijack the output audio and |
212 // verify that streaming starts correctly. | 182 // verify that streaming starts correctly. |
213 // Disabled when running headless since the bots don't have the required config. | 183 // Disabled when running headless since the bots don't have the required config. |
214 TEST_F(WebRTCAudioDeviceTest, StartPlayout) { | 184 TEST_F(WebRTCAudioDeviceTest, StartPlayout) { |
215 AutoAudioManagerCleanup audio_manager_cleanup; | |
216 | |
217 if (IsRunningHeadless()) | 185 if (IsRunningHeadless()) |
218 return; | 186 return; |
219 | 187 |
220 AudioUtil audio_util; | 188 AudioUtil audio_util; |
221 SetAudioUtilCallback(&audio_util); | 189 SetAudioUtilCallback(&audio_util); |
222 | 190 |
223 if (!HardwareSampleRatesAreValid()) | 191 if (!HardwareSampleRatesAreValid()) |
224 return; | 192 return; |
225 | 193 |
226 EXPECT_CALL(media_observer(), | 194 EXPECT_CALL(media_observer(), |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 // Verify that a call to webrtc::VoEBase::StartRecording() starts audio input | 247 // Verify that a call to webrtc::VoEBase::StartRecording() starts audio input |
280 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will | 248 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will |
281 // be utilized to implement the actual audio path. The test registers a | 249 // be utilized to implement the actual audio path. The test registers a |
282 // webrtc::VoEExternalMedia implementation to hijack the input audio and | 250 // webrtc::VoEExternalMedia implementation to hijack the input audio and |
283 // verify that streaming starts correctly. An external transport implementation | 251 // verify that streaming starts correctly. An external transport implementation |
284 // is also required to ensure that "sending" can start without actually trying | 252 // is also required to ensure that "sending" can start without actually trying |
285 // to send encoded packets to the network. Our main interest here is to ensure | 253 // to send encoded packets to the network. Our main interest here is to ensure |
286 // that the audio capturing starts as it should. | 254 // that the audio capturing starts as it should. |
287 // Disabled when running headless since the bots don't have the required config. | 255 // Disabled when running headless since the bots don't have the required config. |
288 TEST_F(WebRTCAudioDeviceTest, StartRecording) { | 256 TEST_F(WebRTCAudioDeviceTest, StartRecording) { |
289 AutoAudioManagerCleanup audio_manager_cleanup; | |
290 | |
291 if (IsRunningHeadless()) | 257 if (IsRunningHeadless()) |
292 return; | 258 return; |
293 | 259 |
294 AudioUtil audio_util; | 260 AudioUtil audio_util; |
295 SetAudioUtilCallback(&audio_util); | 261 SetAudioUtilCallback(&audio_util); |
296 | 262 |
297 if (!HardwareSampleRatesAreValid()) | 263 if (!HardwareSampleRatesAreValid()) |
298 return; | 264 return; |
299 | 265 |
300 // TODO(tommi): extend MediaObserver and MockMediaObserver with support | 266 // TODO(tommi): extend MediaObserver and MockMediaObserver with support |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 ch, webrtc::kRecordingPerChannel)); | 314 ch, webrtc::kRecordingPerChannel)); |
349 EXPECT_EQ(0, base->StopSend(ch)); | 315 EXPECT_EQ(0, base->StopSend(ch)); |
350 | 316 |
351 EXPECT_EQ(0, base->DeleteChannel(ch)); | 317 EXPECT_EQ(0, base->DeleteChannel(ch)); |
352 EXPECT_EQ(0, base->Terminate()); | 318 EXPECT_EQ(0, base->Terminate()); |
353 } | 319 } |
354 | 320 |
355 // Uses WebRtcAudioDeviceImpl to play a local wave file. | 321 // Uses WebRtcAudioDeviceImpl to play a local wave file. |
356 // Disabled when running headless since the bots don't have the required config. | 322 // Disabled when running headless since the bots don't have the required config. |
357 TEST_F(WebRTCAudioDeviceTest, PlayLocalFile) { | 323 TEST_F(WebRTCAudioDeviceTest, PlayLocalFile) { |
358 AutoAudioManagerCleanup audio_manager_cleanup; | |
359 | |
360 if (IsRunningHeadless()) | 324 if (IsRunningHeadless()) |
361 return; | 325 return; |
362 | 326 |
363 std::string file_path( | 327 std::string file_path( |
364 GetTestDataPath(FILE_PATH_LITERAL("speechmusic_mono_16kHz.pcm"))); | 328 GetTestDataPath(FILE_PATH_LITERAL("speechmusic_mono_16kHz.pcm"))); |
365 | 329 |
366 AudioUtil audio_util; | 330 AudioUtil audio_util; |
367 SetAudioUtilCallback(&audio_util); | 331 SetAudioUtilCallback(&audio_util); |
368 | 332 |
369 if (!HardwareSampleRatesAreValid()) | 333 if (!HardwareSampleRatesAreValid()) |
(...skipping 26 matching lines...) Expand all Loading... |
396 | 360 |
397 ScopedWebRTCPtr<webrtc::VoEFile> file(engine.get()); | 361 ScopedWebRTCPtr<webrtc::VoEFile> file(engine.get()); |
398 int duration = 0; | 362 int duration = 0; |
399 EXPECT_EQ(0, file->GetFileDuration(file_path.c_str(), duration, | 363 EXPECT_EQ(0, file->GetFileDuration(file_path.c_str(), duration, |
400 webrtc::kFileFormatPcm16kHzFile)); | 364 webrtc::kFileFormatPcm16kHzFile)); |
401 EXPECT_NE(0, duration); | 365 EXPECT_NE(0, duration); |
402 | 366 |
403 EXPECT_EQ(0, file->StartPlayingFileLocally(ch, file_path.c_str(), false, | 367 EXPECT_EQ(0, file->StartPlayingFileLocally(ch, file_path.c_str(), false, |
404 webrtc::kFileFormatPcm16kHzFile)); | 368 webrtc::kFileFormatPcm16kHzFile)); |
405 | 369 |
| 370 // Play 2 seconds worth of audio and then quit. |
406 message_loop_.PostDelayedTask(FROM_HERE, | 371 message_loop_.PostDelayedTask(FROM_HERE, |
407 MessageLoop::QuitClosure(), | 372 MessageLoop::QuitClosure(), |
408 TestTimeouts::action_timeout_ms()); | 373 2000); |
409 message_loop_.Run(); | 374 message_loop_.Run(); |
410 | 375 |
| 376 |
| 377 EXPECT_EQ(0, base->StopSend(ch)); |
| 378 EXPECT_EQ(0, base->StopPlayout(ch)); |
| 379 EXPECT_EQ(0, base->DeleteChannel(ch)); |
411 EXPECT_EQ(0, base->Terminate()); | 380 EXPECT_EQ(0, base->Terminate()); |
412 } | 381 } |
413 | 382 |
414 // Uses WebRtcAudioDeviceImpl to play out recorded audio in loopback. | 383 // Uses WebRtcAudioDeviceImpl to play out recorded audio in loopback. |
415 // An external transport implementation is utilized to feed back RTP packets | 384 // An external transport implementation is utilized to feed back RTP packets |
416 // which are recorded, encoded, packetized into RTP packets and finally | 385 // which are recorded, encoded, packetized into RTP packets and finally |
417 // "transmitted". The RTP packets are then fed back into the VoiceEngine | 386 // "transmitted". The RTP packets are then fed back into the VoiceEngine |
418 // where they are decoded and played out on the default audio output device. | 387 // where they are decoded and played out on the default audio output device. |
419 // Disabled when running headless since the bots don't have the required config. | 388 // Disabled when running headless since the bots don't have the required config. |
420 // TODO(henrika): improve quality by using a wideband codec, enabling noise- | 389 // TODO(henrika): improve quality by using a wideband codec, enabling noise- |
421 // suppressions and perhaps also the digital AGC. | 390 // suppressions and perhaps also the digital AGC. |
422 TEST_F(WebRTCAudioDeviceTest, FullDuplexAudio) { | 391 TEST_F(WebRTCAudioDeviceTest, FullDuplexAudio) { |
423 AutoAudioManagerCleanup audio_manager_cleanup; | |
424 | |
425 if (IsRunningHeadless()) | 392 if (IsRunningHeadless()) |
426 return; | 393 return; |
427 | 394 |
428 AudioUtil audio_util; | 395 AudioUtil audio_util; |
429 SetAudioUtilCallback(&audio_util); | 396 SetAudioUtilCallback(&audio_util); |
430 | 397 |
431 if (!HardwareSampleRatesAreValid()) | 398 if (!HardwareSampleRatesAreValid()) |
432 return; | 399 return; |
433 | 400 |
434 EXPECT_CALL(media_observer(), | 401 EXPECT_CALL(media_observer(), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 MessageLoop::QuitClosure(), | 433 MessageLoop::QuitClosure(), |
467 TestTimeouts::action_timeout_ms()); | 434 TestTimeouts::action_timeout_ms()); |
468 message_loop_.Run(); | 435 message_loop_.Run(); |
469 | 436 |
470 EXPECT_EQ(0, base->StopSend(ch)); | 437 EXPECT_EQ(0, base->StopSend(ch)); |
471 EXPECT_EQ(0, base->StopPlayout(ch)); | 438 EXPECT_EQ(0, base->StopPlayout(ch)); |
472 | 439 |
473 EXPECT_EQ(0, base->DeleteChannel(ch)); | 440 EXPECT_EQ(0, base->DeleteChannel(ch)); |
474 EXPECT_EQ(0, base->Terminate()); | 441 EXPECT_EQ(0, base->Terminate()); |
475 } | 442 } |
OLD | NEW |