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

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

Issue 227743004: Added a kEchoCancellation constraint to turn off the audio processing. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 6 years, 7 months 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "content/public/common/content_switches.h" 11 #include "content/public/common/content_switches.h"
12 #include "content/public/common/media_stream_request.h" 12 #include "content/public/common/media_stream_request.h"
13 #include "content/renderer/media/media_stream_audio_processor.h" 13 #include "content/renderer/media/media_stream_audio_processor.h"
14 #include "content/renderer/media/media_stream_audio_processor_options.h"
14 #include "content/renderer/media/mock_media_constraint_factory.h" 15 #include "content/renderer/media/mock_media_constraint_factory.h"
15 #include "media/audio/audio_parameters.h" 16 #include "media/audio/audio_parameters.h"
16 #include "media/base/audio_bus.h" 17 #include "media/base/audio_bus.h"
17 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" 20 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
20 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" 21 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h"
21 22
22 using ::testing::_; 23 using ::testing::_;
23 using ::testing::AnyNumber; 24 using ::testing::AnyNumber;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 EXPECT_TRUE(audio_processing->voice_detection()->likelihood() == 147 EXPECT_TRUE(audio_processing->voice_detection()->likelihood() ==
147 webrtc::VoiceDetection::kVeryLowLikelihood); 148 webrtc::VoiceDetection::kVeryLowLikelihood);
148 #endif 149 #endif
149 } 150 }
150 151
151 media::AudioParameters params_; 152 media::AudioParameters params_;
152 }; 153 };
153 154
154 TEST_F(MediaStreamAudioProcessorTest, WithoutAudioProcessing) { 155 TEST_F(MediaStreamAudioProcessorTest, WithoutAudioProcessing) {
155 // Setup the audio processor without enabling the flag. 156 // Setup the audio processor without enabling the flag.
156 blink::WebMediaConstraints constraints; 157 MockMediaConstraintFactory constraint_factory;
157 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 158 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
158 new WebRtcAudioDeviceImpl()); 159 new WebRtcAudioDeviceImpl());
159 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 160 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
160 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( 161 new talk_base::RefCountedObject<MediaStreamAudioProcessor>(
161 constraints, 0, MEDIA_DEVICE_AUDIO_CAPTURE, 162 constraint_factory.CreateWebMediaConstraints(), 0,
162 webrtc_audio_device.get())); 163 webrtc_audio_device.get()));
163 EXPECT_FALSE(audio_processor->has_audio_processing()); 164 EXPECT_FALSE(audio_processor->has_audio_processing());
164 audio_processor->OnCaptureFormatChanged(params_); 165 audio_processor->OnCaptureFormatChanged(params_);
165 166
166 ProcessDataAndVerifyFormat(audio_processor, 167 ProcessDataAndVerifyFormat(audio_processor,
167 params_.sample_rate(), 168 params_.sample_rate(),
168 params_.channels(), 169 params_.channels(),
169 params_.sample_rate() / 100); 170 params_.sample_rate() / 100);
170 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives 171 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives
171 // |audio_processor|. 172 // |audio_processor|.
172 audio_processor = NULL; 173 audio_processor = NULL;
173 } 174 }
174 175
175 TEST_F(MediaStreamAudioProcessorTest, WithAudioProcessing) { 176 TEST_F(MediaStreamAudioProcessorTest, WithAudioProcessing) {
176 // Setup the audio processor with the flag enabled. 177 // Setup the audio processor with the flag enabled.
177 CommandLine::ForCurrentProcess()->AppendSwitch( 178 CommandLine::ForCurrentProcess()->AppendSwitch(
178 switches::kEnableAudioTrackProcessing); 179 switches::kEnableAudioTrackProcessing);
179 blink::WebMediaConstraints constraints; 180 MockMediaConstraintFactory constraint_factory;
180 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 181 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
181 new WebRtcAudioDeviceImpl()); 182 new WebRtcAudioDeviceImpl());
182 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 183 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
183 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( 184 new talk_base::RefCountedObject<MediaStreamAudioProcessor>(
184 constraints, 0, MEDIA_DEVICE_AUDIO_CAPTURE, 185 constraint_factory.CreateWebMediaConstraints(), 0,
185 webrtc_audio_device.get())); 186 webrtc_audio_device.get()));
186 EXPECT_TRUE(audio_processor->has_audio_processing()); 187 EXPECT_TRUE(audio_processor->has_audio_processing());
187 audio_processor->OnCaptureFormatChanged(params_); 188 audio_processor->OnCaptureFormatChanged(params_);
188 VerifyDefaultComponents(audio_processor); 189 VerifyDefaultComponents(audio_processor);
189 190
190 ProcessDataAndVerifyFormat(audio_processor, 191 ProcessDataAndVerifyFormat(audio_processor,
191 kAudioProcessingSampleRate, 192 kAudioProcessingSampleRate,
192 kAudioProcessingNumberOfChannel, 193 kAudioProcessingNumberOfChannel,
193 kAudioProcessingSampleRate / 100); 194 kAudioProcessingSampleRate / 100);
194 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives 195 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives
195 // |audio_processor|. 196 // |audio_processor|.
196 audio_processor = NULL; 197 audio_processor = NULL;
197 } 198 }
198 199
199 TEST_F(MediaStreamAudioProcessorTest, VerifyTabCaptureWithoutAudioProcessing) { 200 TEST_F(MediaStreamAudioProcessorTest, VerifyTabCaptureWithoutAudioProcessing) {
200 // Setup the audio processor with enabling the flag. 201 // Setup the audio processor with enabling the flag.
201 CommandLine::ForCurrentProcess()->AppendSwitch( 202 CommandLine::ForCurrentProcess()->AppendSwitch(
202 switches::kEnableAudioTrackProcessing); 203 switches::kEnableAudioTrackProcessing);
203 blink::WebMediaConstraints constraints;
204 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 204 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
205 new WebRtcAudioDeviceImpl()); 205 new WebRtcAudioDeviceImpl());
206 // Create MediaStreamAudioProcessor instance for MEDIA_TAB_AUDIO_CAPTURE type. 206 // Create MediaStreamAudioProcessor instance for kMediaStreamSourceTab source.
207 MockMediaConstraintFactory tab_constraint_factory;
208 const std::string tab_string = kMediaStreamSourceTab;
209 tab_constraint_factory.AddMandatory(kMediaStreamSource,
210 tab_string);
207 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 211 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
208 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( 212 new talk_base::RefCountedObject<MediaStreamAudioProcessor>(
209 constraints, 0, MEDIA_TAB_AUDIO_CAPTURE, 213 tab_constraint_factory.CreateWebMediaConstraints(), 0,
210 webrtc_audio_device.get())); 214 webrtc_audio_device.get()));
211 EXPECT_FALSE(audio_processor->has_audio_processing()); 215 EXPECT_FALSE(audio_processor->has_audio_processing());
212 audio_processor->OnCaptureFormatChanged(params_); 216 audio_processor->OnCaptureFormatChanged(params_);
213 217
214 ProcessDataAndVerifyFormat(audio_processor, 218 ProcessDataAndVerifyFormat(audio_processor,
215 params_.sample_rate(), 219 params_.sample_rate(),
216 params_.channels(), 220 params_.channels(),
217 params_.sample_rate() / 100); 221 params_.sample_rate() / 100);
218 222
219 // Create MediaStreamAudioProcessor instance for MEDIA_LOOPBACK_AUDIO_CAPTURE. 223 // Create MediaStreamAudioProcessor instance for kMediaStreamSourceSystem
220 audio_processor = 224 // source.
221 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( 225 MockMediaConstraintFactory system_constraint_factory;
222 constraints, 0, MEDIA_LOOPBACK_AUDIO_CAPTURE, 226 const std::string system_string = kMediaStreamSourceSystem;
223 webrtc_audio_device.get()); 227 system_constraint_factory.AddMandatory(kMediaStreamSource,
228 system_string);
229 audio_processor = new talk_base::RefCountedObject<MediaStreamAudioProcessor>(
230 system_constraint_factory.CreateWebMediaConstraints(), 0,
231 webrtc_audio_device.get());
224 EXPECT_FALSE(audio_processor->has_audio_processing()); 232 EXPECT_FALSE(audio_processor->has_audio_processing());
225 233
226 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives 234 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives
227 // |audio_processor|. 235 // |audio_processor|.
228 audio_processor = NULL; 236 audio_processor = NULL;
229 } 237 }
230 238
231 TEST_F(MediaStreamAudioProcessorTest, TurnOffDefaultConstraints) { 239 TEST_F(MediaStreamAudioProcessorTest, TurnOffDefaultConstraints) {
232 // Setup the audio processor with enabling the flag. 240 // Setup the audio processor with enabling the flag.
233 CommandLine::ForCurrentProcess()->AppendSwitch( 241 CommandLine::ForCurrentProcess()->AppendSwitch(
234 switches::kEnableAudioTrackProcessing); 242 switches::kEnableAudioTrackProcessing);
235 243
236 // Turn off the default constraints and pass it to MediaStreamAudioProcessor. 244 // Turn off the default constraints and pass it to MediaStreamAudioProcessor.
237 MockMediaConstraintFactory constraint_factory; 245 MockMediaConstraintFactory constraint_factory;
238 constraint_factory.DisableDefaultAudioConstraints(); 246 constraint_factory.DisableDefaultAudioConstraints();
239 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 247 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
240 new WebRtcAudioDeviceImpl()); 248 new WebRtcAudioDeviceImpl());
241 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 249 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
242 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( 250 new talk_base::RefCountedObject<MediaStreamAudioProcessor>(
243 constraint_factory.CreateWebMediaConstraints(), 0, 251 constraint_factory.CreateWebMediaConstraints(), 0,
244 MEDIA_DEVICE_AUDIO_CAPTURE, webrtc_audio_device.get())); 252 webrtc_audio_device.get()));
245 EXPECT_FALSE(audio_processor->has_audio_processing()); 253 EXPECT_FALSE(audio_processor->has_audio_processing());
246 audio_processor->OnCaptureFormatChanged(params_); 254 audio_processor->OnCaptureFormatChanged(params_);
247 255
248 ProcessDataAndVerifyFormat(audio_processor, 256 ProcessDataAndVerifyFormat(audio_processor,
249 params_.sample_rate(), 257 params_.sample_rate(),
250 params_.channels(), 258 params_.channels(),
251 params_.sample_rate() / 100); 259 params_.sample_rate() / 100);
252 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives 260 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives
253 // |audio_processor|. 261 // |audio_processor|.
254 audio_processor = NULL; 262 audio_processor = NULL;
255 } 263 }
256 264
265 TEST_F(MediaStreamAudioProcessorTest, VerifyConstraints) {
266 // Setup the audio processor with enabling the flag.
267 CommandLine::ForCurrentProcess()->AppendSwitch(
268 switches::kEnableAudioTrackProcessing);
269
270 static const char* kDefaultAudioConstraints[] = {
271 MediaAudioConstraints::kEchoCancellation,
272 MediaAudioConstraints::kGoogAudioMirroring,
273 MediaAudioConstraints::kGoogAutoGainControl,
274 MediaAudioConstraints::kGoogEchoCancellation,
275 MediaAudioConstraints::kGoogExperimentalEchoCancellation,
276 MediaAudioConstraints::kGoogExperimentalAutoGainControl,
277 MediaAudioConstraints::kGoogExperimentalNoiseSuppression,
278 MediaAudioConstraints::kGoogHighpassFilter,
279 MediaAudioConstraints::kGoogNoiseSuppression,
280 MediaAudioConstraints::kGoogTypingNoiseDetection
281 };
282
283 // Verify mandatory constraints.
284 for (size_t i = 0; i < arraysize(kDefaultAudioConstraints); ++i) {
285 MockMediaConstraintFactory constraint_factory;
286 constraint_factory.AddMandatory(kDefaultAudioConstraints[i], false);
287 blink::WebMediaConstraints constraints =
288 constraint_factory.CreateWebMediaConstraints();
289 MediaAudioConstraints audio_constraints(constraints, 0);
290 EXPECT_FALSE(audio_constraints.GetProperty(kDefaultAudioConstraints[i]));
291 }
292
293 // Verify optional constraints.
294 for (size_t i = 0; i < arraysize(kDefaultAudioConstraints); ++i) {
295 MockMediaConstraintFactory constraint_factory;
296 constraint_factory.AddOptional(kDefaultAudioConstraints[i], false);
297 blink::WebMediaConstraints constraints =
298 constraint_factory.CreateWebMediaConstraints();
299 MediaAudioConstraints audio_constraints(constraints, 0);
300 EXPECT_FALSE(audio_constraints.GetProperty(kDefaultAudioConstraints[i]));
301 }
302
303 {
304 // Verify echo cancellation is off when platform aec effect is on.
305 MockMediaConstraintFactory constraint_factory;
306 MediaAudioConstraints audio_constraints(
307 constraint_factory.CreateWebMediaConstraints(),
308 media::AudioParameters::ECHO_CANCELLER);
309 EXPECT_FALSE(audio_constraints.GetEchoCancellationProperty());
310 }
311
312 {
313 // Verify |kEchoCancellation| overwrite |kGoogEchoCancellation|.
314 MockMediaConstraintFactory constraint_factory_1;
315 constraint_factory_1.AddOptional(MediaAudioConstraints::kEchoCancellation,
316 true);
317 constraint_factory_1.AddOptional(
318 MediaAudioConstraints::kGoogEchoCancellation, false);
319 blink::WebMediaConstraints constraints_1 =
320 constraint_factory_1.CreateWebMediaConstraints();
321 MediaAudioConstraints audio_constraints_1(constraints_1, 0);
322 EXPECT_TRUE(audio_constraints_1.GetEchoCancellationProperty());
323
324 MockMediaConstraintFactory constraint_factory_2;
325 constraint_factory_2.AddOptional(MediaAudioConstraints::kEchoCancellation,
326 false);
327 constraint_factory_2.AddOptional(
328 MediaAudioConstraints::kGoogEchoCancellation, true);
329 blink::WebMediaConstraints constraints_2 =
330 constraint_factory_2.CreateWebMediaConstraints();
331 MediaAudioConstraints audio_constraints_2(constraints_2, 0);
332 EXPECT_FALSE(audio_constraints_2.GetEchoCancellationProperty());
333 }
334
335 {
336 // When |kEchoCancellation| is explicitly set to false, the default values
337 // for all the constraints except |kMediaStreamAudioDucking| are false.
338 MockMediaConstraintFactory constraint_factory;
339 constraint_factory.AddOptional(MediaAudioConstraints::kEchoCancellation,
340 false);
341 blink::WebMediaConstraints constraints =
342 constraint_factory.CreateWebMediaConstraints();
343 MediaAudioConstraints audio_constraints(constraints, 0);
344 for (size_t i = 0; i < arraysize(kDefaultAudioConstraints); ++i) {
345 EXPECT_FALSE(audio_constraints.GetProperty(kDefaultAudioConstraints[i]));
346 }
347 EXPECT_FALSE(audio_constraints.NeedsAudioProcessing());
348 #if defined(OS_WIN)
349 EXPECT_TRUE(audio_constraints.GetProperty(kMediaStreamAudioDucking));
350 #else
351 EXPECT_FALSE(audio_constraints.GetProperty(kMediaStreamAudioDucking));
352 #endif
353 }
354 }
355
356 TEST_F(MediaStreamAudioProcessorTest, ValidateConstraints) {
357 MockMediaConstraintFactory constraint_factory;
358 const std::string dummy_constraint = "dummy";
359 constraint_factory.AddMandatory(dummy_constraint, true);
360 MediaAudioConstraints audio_constraints(
361 constraint_factory.CreateWebMediaConstraints(), 0);
362 EXPECT_FALSE(audio_constraints.IsValid());
363 }
364
257 } // namespace content 365 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_audio_processor_options.cc ('k') | content/renderer/media/media_stream_constraints_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698