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_manager.h" | |
9 #include "media/audio/audio_util.h" | 10 #include "media/audio/audio_util.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
11 #include "third_party/webrtc/voice_engine/main/interface/voe_audio_processing.h" | 12 #include "third_party/webrtc/voice_engine/main/interface/voe_audio_processing.h" |
12 #include "third_party/webrtc/voice_engine/main/interface/voe_base.h" | 13 #include "third_party/webrtc/voice_engine/main/interface/voe_base.h" |
13 #include "third_party/webrtc/voice_engine/main/interface/voe_external_media.h" | 14 #include "third_party/webrtc/voice_engine/main/interface/voe_external_media.h" |
14 #include "third_party/webrtc/voice_engine/main/interface/voe_file.h" | 15 #include "third_party/webrtc/voice_engine/main/interface/voe_file.h" |
15 #include "third_party/webrtc/voice_engine/main/interface/voe_network.h" | 16 #include "third_party/webrtc/voice_engine/main/interface/voe_network.h" |
16 | 17 |
17 using testing::_; | 18 using testing::_; |
18 using testing::AnyNumber; | 19 using testing::AnyNumber; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 int channel_id_; | 108 int channel_id_; |
108 webrtc::ProcessingTypes type_; | 109 webrtc::ProcessingTypes type_; |
109 int packet_size_; | 110 int packet_size_; |
110 int sample_rate_; | 111 int sample_rate_; |
111 int channels_; | 112 int channels_; |
112 DISALLOW_COPY_AND_ASSIGN(WebRTCMediaProcessImpl); | 113 DISALLOW_COPY_AND_ASSIGN(WebRTCMediaProcessImpl); |
113 }; | 114 }; |
114 | 115 |
115 } // end namespace | 116 } // end namespace |
116 | 117 |
118 // Utility class to delete the AudioManager | |
henrika (OOO until Aug 14)
2011/11/20 18:43:03
AudioManager.
tommi (sloooow) - chröme
2011/11/21 10:39:33
Done.
| |
119 class AutoAudioManagerCleanup { | |
120 public: | |
121 AutoAudioManagerCleanup() { | |
122 if (DeleteAndResurrectIfExists()) { | |
henrika (OOO until Aug 14)
2011/11/20 18:43:03
I would call it DeleteAndRessurrect(). If not, it
tommi (sloooow) - chröme
2011/11/21 10:39:33
Done. Although, FYI: The name says exactly what t
| |
123 // In order to prevent this from happening, we sacrifice this test even | |
124 // though some other test must have caused this. If we don't it won't | |
125 // get fixed. Sorry :) | |
126 ADD_FAILURE() | |
127 << "AudioManager singleton was not cleaned up by some previous test!"; | |
128 } | |
129 } | |
130 ~AutoAudioManagerCleanup() { | |
131 DeleteAndResurrectIfExists(); | |
132 } | |
133 | |
134 protected: | |
135 // Returns true iff the AudioManager existed and was deleted. | |
136 bool DeleteAndResurrectIfExists() { | |
137 if (AudioManager::SingletonExists()) { | |
138 AudioManager::Destroy(NULL); | |
139 AudioManager::Resurrect(); | |
140 return true; | |
141 } | |
142 return false; | |
143 } | |
144 }; | |
145 | |
117 // Basic test that instantiates and initializes an instance of | 146 // Basic test that instantiates and initializes an instance of |
118 // WebRtcAudioDeviceImpl. | 147 // WebRtcAudioDeviceImpl. |
119 TEST_F(WebRTCAudioDeviceTest, Construct) { | 148 TEST_F(WebRTCAudioDeviceTest, Construct) { |
henrika (OOO until Aug 14)
2011/11/20 18:43:03
Why is this the only test were we don't add if (I
tommi (sloooow) - chröme
2011/11/21 10:39:33
This is the only test that can currently pass on t
| |
149 AutoAudioManagerCleanup audio_manager_cleanup; | |
120 AudioUtilNoHardware audio_util(48000.0, 48000.0); | 150 AudioUtilNoHardware audio_util(48000.0, 48000.0); |
121 SetAudioUtilCallback(&audio_util); | 151 SetAudioUtilCallback(&audio_util); |
122 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( | 152 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( |
123 new WebRtcAudioDeviceImpl()); | 153 new WebRtcAudioDeviceImpl()); |
124 audio_device->SetSessionId(1); | 154 audio_device->SetSessionId(1); |
125 | 155 |
126 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); | 156 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); |
127 ASSERT_TRUE(engine.valid()); | 157 ASSERT_TRUE(engine.valid()); |
128 | 158 |
129 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); | 159 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); |
130 int err = base->Init(audio_device); | 160 int err = base->Init(audio_device); |
131 EXPECT_EQ(0, err); | 161 EXPECT_EQ(0, err); |
132 EXPECT_EQ(0, base->Terminate()); | 162 EXPECT_EQ(0, base->Terminate()); |
133 } | 163 } |
134 | 164 |
135 // Verify that a call to webrtc::VoEBase::StartPlayout() starts audio output | 165 // Verify that a call to webrtc::VoEBase::StartPlayout() starts audio output |
136 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will | 166 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will |
137 // be utilized to implement the actual audio path. The test registers a | 167 // be utilized to implement the actual audio path. The test registers a |
138 // webrtc::VoEExternalMedia implementation to hijack the output audio and | 168 // webrtc::VoEExternalMedia implementation to hijack the output audio and |
139 // verify that streaming starts correctly. | 169 // verify that streaming starts correctly. |
140 // Disabled when running headless since the bots don't have the required config. | 170 // Disabled when running headless since the bots don't have the required config. |
141 TEST_F(WebRTCAudioDeviceTest, StartPlayout) { | 171 TEST_F(WebRTCAudioDeviceTest, StartPlayout) { |
172 AutoAudioManagerCleanup audio_manager_cleanup; | |
173 | |
142 if (IsRunningHeadless()) | 174 if (IsRunningHeadless()) |
143 return; | 175 return; |
144 | 176 |
145 AudioUtil audio_util; | 177 AudioUtil audio_util; |
146 SetAudioUtilCallback(&audio_util); | 178 SetAudioUtilCallback(&audio_util); |
147 | 179 |
148 EXPECT_CALL(media_observer(), | 180 EXPECT_CALL(media_observer(), |
149 OnSetAudioStreamStatus(_, 1, StrEq("created"))).Times(1); | 181 OnSetAudioStreamStatus(_, 1, StrEq("created"))).Times(1); |
150 EXPECT_CALL(media_observer(), | 182 EXPECT_CALL(media_observer(), |
151 OnSetAudioStreamPlaying(_, 1, true)).Times(1); | 183 OnSetAudioStreamPlaying(_, 1, true)).Times(1); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 // Verify that a call to webrtc::VoEBase::StartRecording() starts audio input | 233 // Verify that a call to webrtc::VoEBase::StartRecording() starts audio input |
202 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will | 234 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will |
203 // be utilized to implement the actual audio path. The test registers a | 235 // be utilized to implement the actual audio path. The test registers a |
204 // webrtc::VoEExternalMedia implementation to hijack the input audio and | 236 // webrtc::VoEExternalMedia implementation to hijack the input audio and |
205 // verify that streaming starts correctly. An external transport implementation | 237 // verify that streaming starts correctly. An external transport implementation |
206 // is also required to ensure that "sending" can start without actually trying | 238 // is also required to ensure that "sending" can start without actually trying |
207 // to send encoded packets to the network. Our main interest here is to ensure | 239 // to send encoded packets to the network. Our main interest here is to ensure |
208 // that the audio capturing starts as it should. | 240 // that the audio capturing starts as it should. |
209 // Disabled when running headless since the bots don't have the required config. | 241 // Disabled when running headless since the bots don't have the required config. |
210 TEST_F(WebRTCAudioDeviceTest, StartRecording) { | 242 TEST_F(WebRTCAudioDeviceTest, StartRecording) { |
243 AutoAudioManagerCleanup audio_manager_cleanup; | |
244 | |
211 if (IsRunningHeadless()) | 245 if (IsRunningHeadless()) |
212 return; | 246 return; |
213 | 247 |
214 AudioUtil audio_util; | 248 AudioUtil audio_util; |
215 SetAudioUtilCallback(&audio_util); | 249 SetAudioUtilCallback(&audio_util); |
216 | 250 |
217 // TODO(tommi): extend MediaObserver and MockMediaObserver with support | 251 // TODO(tommi): extend MediaObserver and MockMediaObserver with support |
218 // for new interfaces, like OnSetAudioStreamRecording(). When done, add | 252 // for new interfaces, like OnSetAudioStreamRecording(). When done, add |
219 // EXPECT_CALL() macros here. | 253 // EXPECT_CALL() macros here. |
220 | 254 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 ch, webrtc::kRecordingPerChannel)); | 299 ch, webrtc::kRecordingPerChannel)); |
266 EXPECT_EQ(0, base->StopSend(ch)); | 300 EXPECT_EQ(0, base->StopSend(ch)); |
267 | 301 |
268 EXPECT_EQ(0, base->DeleteChannel(ch)); | 302 EXPECT_EQ(0, base->DeleteChannel(ch)); |
269 EXPECT_EQ(0, base->Terminate()); | 303 EXPECT_EQ(0, base->Terminate()); |
270 } | 304 } |
271 | 305 |
272 // Uses WebRtcAudioDeviceImpl to play a local wave file. | 306 // Uses WebRtcAudioDeviceImpl to play a local wave file. |
273 // Disabled when running headless since the bots don't have the required config. | 307 // Disabled when running headless since the bots don't have the required config. |
274 TEST_F(WebRTCAudioDeviceTest, PlayLocalFile) { | 308 TEST_F(WebRTCAudioDeviceTest, PlayLocalFile) { |
309 AutoAudioManagerCleanup audio_manager_cleanup; | |
310 | |
275 if (IsRunningHeadless()) | 311 if (IsRunningHeadless()) |
276 return; | 312 return; |
277 | 313 |
278 std::string file_path( | 314 std::string file_path( |
279 GetTestDataPath(FILE_PATH_LITERAL("speechmusic_mono_16kHz.pcm"))); | 315 GetTestDataPath(FILE_PATH_LITERAL("speechmusic_mono_16kHz.pcm"))); |
280 | 316 |
281 AudioUtil audio_util; | 317 AudioUtil audio_util; |
282 SetAudioUtilCallback(&audio_util); | 318 SetAudioUtilCallback(&audio_util); |
283 | 319 |
284 EXPECT_CALL(media_observer(), | 320 EXPECT_CALL(media_observer(), |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 | 361 |
326 // Uses WebRtcAudioDeviceImpl to play out recorded audio in loopback. | 362 // Uses WebRtcAudioDeviceImpl to play out recorded audio in loopback. |
327 // An external transport implementation is utilized to feed back RTP packets | 363 // An external transport implementation is utilized to feed back RTP packets |
328 // which are recorded, encoded, packetized into RTP packets and finally | 364 // which are recorded, encoded, packetized into RTP packets and finally |
329 // "transmitted". The RTP packets are then fed back into the VoiceEngine | 365 // "transmitted". The RTP packets are then fed back into the VoiceEngine |
330 // 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. |
331 // 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. |
332 // TODO(henrika): improve quality by using a wideband codec, enabling noise- | 368 // TODO(henrika): improve quality by using a wideband codec, enabling noise- |
333 // suppressions and perhaps also the digital AGC. | 369 // suppressions and perhaps also the digital AGC. |
334 TEST_F(WebRTCAudioDeviceTest, FullDuplexAudio) { | 370 TEST_F(WebRTCAudioDeviceTest, FullDuplexAudio) { |
371 AutoAudioManagerCleanup audio_manager_cleanup; | |
372 | |
335 if (IsRunningHeadless()) | 373 if (IsRunningHeadless()) |
336 return; | 374 return; |
337 | 375 |
338 EXPECT_CALL(media_observer(), | 376 EXPECT_CALL(media_observer(), |
339 OnSetAudioStreamStatus(_, 1, StrEq("created"))); | 377 OnSetAudioStreamStatus(_, 1, StrEq("created"))); |
340 EXPECT_CALL(media_observer(), | 378 EXPECT_CALL(media_observer(), |
341 OnSetAudioStreamPlaying(_, 1, true)); | 379 OnSetAudioStreamPlaying(_, 1, true)); |
342 EXPECT_CALL(media_observer(), | 380 EXPECT_CALL(media_observer(), |
343 OnSetAudioStreamStatus(_, 1, StrEq("closed"))); | 381 OnSetAudioStreamStatus(_, 1, StrEq("closed"))); |
382 EXPECT_CALL(media_observer(), | |
383 OnDeleteAudioStream(_, 1)).Times(AnyNumber()); | |
344 | 384 |
345 AudioUtil audio_util; | 385 AudioUtil audio_util; |
346 SetAudioUtilCallback(&audio_util); | 386 SetAudioUtilCallback(&audio_util); |
347 | 387 |
348 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( | 388 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( |
349 new WebRtcAudioDeviceImpl()); | 389 new WebRtcAudioDeviceImpl()); |
350 audio_device->SetSessionId(1); | 390 audio_device->SetSessionId(1); |
351 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); | 391 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); |
352 ASSERT_TRUE(engine.valid()); | 392 ASSERT_TRUE(engine.valid()); |
353 | 393 |
(...skipping 17 matching lines...) Expand all Loading... | |
371 new MessageLoop::QuitTask(), | 411 new MessageLoop::QuitTask(), |
372 TestTimeouts::action_timeout_ms()); | 412 TestTimeouts::action_timeout_ms()); |
373 message_loop_.Run(); | 413 message_loop_.Run(); |
374 | 414 |
375 EXPECT_EQ(0, base->StopSend(ch)); | 415 EXPECT_EQ(0, base->StopSend(ch)); |
376 EXPECT_EQ(0, base->StopPlayout(ch)); | 416 EXPECT_EQ(0, base->StopPlayout(ch)); |
377 | 417 |
378 EXPECT_EQ(0, base->DeleteChannel(ch)); | 418 EXPECT_EQ(0, base->DeleteChannel(ch)); |
379 EXPECT_EQ(0, base->Terminate()); | 419 EXPECT_EQ(0, base->Terminate()); |
380 } | 420 } |
OLD | NEW |