Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(578)

Side by Side Diff: content/renderer/media/webrtc_audio_device_unittest.cc

Issue 8558022: Expose a way for unit tests to terminate the AudioManager singleton to avoid conflicts between te... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: rebase + comments addressed Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | media/audio/audio_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.
119 // TODO(tommi): Remove when we've fixed issue 105249.
120 class AutoAudioManagerCleanup {
121 public:
122 AutoAudioManagerCleanup() {
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 EXPECT_FALSE(DeleteAndResurrect())
127 << "AudioManager singleton was not cleaned up by some previous test!";
128 }
129 ~AutoAudioManagerCleanup() {
130 DeleteAndResurrect();
131 }
132
133 private:
134 // Returns true iff the AudioManager existed and was deleted.
135 bool DeleteAndResurrect() {
136 if (AudioManager::SingletonExists()) {
137 AudioManager::Destroy(NULL);
138 AudioManager::Resurrect();
139 return true;
140 }
141 return false;
142 }
143
144 DISALLOW_COPY_AND_ASSIGN(AutoAudioManagerCleanup);
145 };
146
117 // Basic test that instantiates and initializes an instance of 147 // Basic test that instantiates and initializes an instance of
118 // WebRtcAudioDeviceImpl. 148 // WebRtcAudioDeviceImpl.
119 TEST_F(WebRTCAudioDeviceTest, Construct) { 149 TEST_F(WebRTCAudioDeviceTest, Construct) {
150 AutoAudioManagerCleanup audio_manager_cleanup;
120 AudioUtilNoHardware audio_util(48000.0, 48000.0); 151 AudioUtilNoHardware audio_util(48000.0, 48000.0);
121 SetAudioUtilCallback(&audio_util); 152 SetAudioUtilCallback(&audio_util);
122 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( 153 scoped_refptr<WebRtcAudioDeviceImpl> audio_device(
123 new WebRtcAudioDeviceImpl()); 154 new WebRtcAudioDeviceImpl());
124 audio_device->SetSessionId(1); 155 audio_device->SetSessionId(1);
125 156
126 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); 157 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create());
127 ASSERT_TRUE(engine.valid()); 158 ASSERT_TRUE(engine.valid());
128 159
129 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); 160 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get());
130 int err = base->Init(audio_device); 161 int err = base->Init(audio_device);
131 EXPECT_EQ(0, err); 162 EXPECT_EQ(0, err);
132 EXPECT_EQ(0, base->Terminate()); 163 EXPECT_EQ(0, base->Terminate());
133 } 164 }
134 165
135 // Verify that a call to webrtc::VoEBase::StartPlayout() starts audio output 166 // Verify that a call to webrtc::VoEBase::StartPlayout() starts audio output
136 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will 167 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will
137 // be utilized to implement the actual audio path. The test registers a 168 // be utilized to implement the actual audio path. The test registers a
138 // webrtc::VoEExternalMedia implementation to hijack the output audio and 169 // webrtc::VoEExternalMedia implementation to hijack the output audio and
139 // verify that streaming starts correctly. 170 // verify that streaming starts correctly.
140 // Disabled when running headless since the bots don't have the required config. 171 // Disabled when running headless since the bots don't have the required config.
141 TEST_F(WebRTCAudioDeviceTest, StartPlayout) { 172 TEST_F(WebRTCAudioDeviceTest, StartPlayout) {
173 AutoAudioManagerCleanup audio_manager_cleanup;
174
142 if (IsRunningHeadless()) 175 if (IsRunningHeadless())
143 return; 176 return;
144 177
145 AudioUtil audio_util; 178 AudioUtil audio_util;
146 SetAudioUtilCallback(&audio_util); 179 SetAudioUtilCallback(&audio_util);
147 180
148 EXPECT_CALL(media_observer(), 181 EXPECT_CALL(media_observer(),
149 OnSetAudioStreamStatus(_, 1, StrEq("created"))).Times(1); 182 OnSetAudioStreamStatus(_, 1, StrEq("created"))).Times(1);
150 EXPECT_CALL(media_observer(), 183 EXPECT_CALL(media_observer(),
151 OnSetAudioStreamPlaying(_, 1, true)).Times(1); 184 OnSetAudioStreamPlaying(_, 1, true)).Times(1);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 // Verify that a call to webrtc::VoEBase::StartRecording() starts audio input 234 // Verify that a call to webrtc::VoEBase::StartRecording() starts audio input
202 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will 235 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will
203 // be utilized to implement the actual audio path. The test registers a 236 // be utilized to implement the actual audio path. The test registers a
204 // webrtc::VoEExternalMedia implementation to hijack the input audio and 237 // webrtc::VoEExternalMedia implementation to hijack the input audio and
205 // verify that streaming starts correctly. An external transport implementation 238 // verify that streaming starts correctly. An external transport implementation
206 // is also required to ensure that "sending" can start without actually trying 239 // 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 240 // to send encoded packets to the network. Our main interest here is to ensure
208 // that the audio capturing starts as it should. 241 // that the audio capturing starts as it should.
209 // Disabled when running headless since the bots don't have the required config. 242 // Disabled when running headless since the bots don't have the required config.
210 TEST_F(WebRTCAudioDeviceTest, StartRecording) { 243 TEST_F(WebRTCAudioDeviceTest, StartRecording) {
244 AutoAudioManagerCleanup audio_manager_cleanup;
245
211 if (IsRunningHeadless()) 246 if (IsRunningHeadless())
212 return; 247 return;
213 248
214 AudioUtil audio_util; 249 AudioUtil audio_util;
215 SetAudioUtilCallback(&audio_util); 250 SetAudioUtilCallback(&audio_util);
216 251
217 // TODO(tommi): extend MediaObserver and MockMediaObserver with support 252 // TODO(tommi): extend MediaObserver and MockMediaObserver with support
218 // for new interfaces, like OnSetAudioStreamRecording(). When done, add 253 // for new interfaces, like OnSetAudioStreamRecording(). When done, add
219 // EXPECT_CALL() macros here. 254 // EXPECT_CALL() macros here.
220 255
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 ch, webrtc::kRecordingPerChannel)); 300 ch, webrtc::kRecordingPerChannel));
266 EXPECT_EQ(0, base->StopSend(ch)); 301 EXPECT_EQ(0, base->StopSend(ch));
267 302
268 EXPECT_EQ(0, base->DeleteChannel(ch)); 303 EXPECT_EQ(0, base->DeleteChannel(ch));
269 EXPECT_EQ(0, base->Terminate()); 304 EXPECT_EQ(0, base->Terminate());
270 } 305 }
271 306
272 // Uses WebRtcAudioDeviceImpl to play a local wave file. 307 // Uses WebRtcAudioDeviceImpl to play a local wave file.
273 // Disabled when running headless since the bots don't have the required config. 308 // Disabled when running headless since the bots don't have the required config.
274 TEST_F(WebRTCAudioDeviceTest, PlayLocalFile) { 309 TEST_F(WebRTCAudioDeviceTest, PlayLocalFile) {
310 AutoAudioManagerCleanup audio_manager_cleanup;
311
275 if (IsRunningHeadless()) 312 if (IsRunningHeadless())
276 return; 313 return;
277 314
278 std::string file_path( 315 std::string file_path(
279 GetTestDataPath(FILE_PATH_LITERAL("speechmusic_mono_16kHz.pcm"))); 316 GetTestDataPath(FILE_PATH_LITERAL("speechmusic_mono_16kHz.pcm")));
280 317
281 AudioUtil audio_util; 318 AudioUtil audio_util;
282 SetAudioUtilCallback(&audio_util); 319 SetAudioUtilCallback(&audio_util);
283 320
284 EXPECT_CALL(media_observer(), 321 EXPECT_CALL(media_observer(),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 362
326 // Uses WebRtcAudioDeviceImpl to play out recorded audio in loopback. 363 // Uses WebRtcAudioDeviceImpl to play out recorded audio in loopback.
327 // An external transport implementation is utilized to feed back RTP packets 364 // An external transport implementation is utilized to feed back RTP packets
328 // which are recorded, encoded, packetized into RTP packets and finally 365 // which are recorded, encoded, packetized into RTP packets and finally
329 // "transmitted". The RTP packets are then fed back into the VoiceEngine 366 // "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. 367 // 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. 368 // 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- 369 // TODO(henrika): improve quality by using a wideband codec, enabling noise-
333 // suppressions and perhaps also the digital AGC. 370 // suppressions and perhaps also the digital AGC.
334 TEST_F(WebRTCAudioDeviceTest, FullDuplexAudio) { 371 TEST_F(WebRTCAudioDeviceTest, FullDuplexAudio) {
372 AutoAudioManagerCleanup audio_manager_cleanup;
373
335 if (IsRunningHeadless()) 374 if (IsRunningHeadless())
336 return; 375 return;
337 376
338 EXPECT_CALL(media_observer(), 377 EXPECT_CALL(media_observer(),
339 OnSetAudioStreamStatus(_, 1, StrEq("created"))); 378 OnSetAudioStreamStatus(_, 1, StrEq("created")));
340 EXPECT_CALL(media_observer(), 379 EXPECT_CALL(media_observer(),
341 OnSetAudioStreamPlaying(_, 1, true)); 380 OnSetAudioStreamPlaying(_, 1, true));
342 EXPECT_CALL(media_observer(), 381 EXPECT_CALL(media_observer(),
343 OnSetAudioStreamStatus(_, 1, StrEq("closed"))); 382 OnSetAudioStreamStatus(_, 1, StrEq("closed")));
383 EXPECT_CALL(media_observer(),
384 OnDeleteAudioStream(_, 1)).Times(AnyNumber());
344 385
345 AudioUtil audio_util; 386 AudioUtil audio_util;
346 SetAudioUtilCallback(&audio_util); 387 SetAudioUtilCallback(&audio_util);
347 388
348 scoped_refptr<WebRtcAudioDeviceImpl> audio_device( 389 scoped_refptr<WebRtcAudioDeviceImpl> audio_device(
349 new WebRtcAudioDeviceImpl()); 390 new WebRtcAudioDeviceImpl());
350 audio_device->SetSessionId(1); 391 audio_device->SetSessionId(1);
351 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); 392 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create());
352 ASSERT_TRUE(engine.valid()); 393 ASSERT_TRUE(engine.valid());
353 394
(...skipping 17 matching lines...) Expand all
371 new MessageLoop::QuitTask(), 412 new MessageLoop::QuitTask(),
372 TestTimeouts::action_timeout_ms()); 413 TestTimeouts::action_timeout_ms());
373 message_loop_.Run(); 414 message_loop_.Run();
374 415
375 EXPECT_EQ(0, base->StopSend(ch)); 416 EXPECT_EQ(0, base->StopSend(ch));
376 EXPECT_EQ(0, base->StopPlayout(ch)); 417 EXPECT_EQ(0, base->StopPlayout(ch));
377 418
378 EXPECT_EQ(0, base->DeleteChannel(ch)); 419 EXPECT_EQ(0, base->DeleteChannel(ch));
379 EXPECT_EQ(0, base->Terminate()); 420 EXPECT_EQ(0, base->Terminate());
380 } 421 }
OLDNEW
« no previous file with comments | « no previous file | media/audio/audio_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698