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

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

Issue 2941563002: Enable new getUserMedia audio constraints algorithm behind a flag. (Closed)
Patch Set: address hbos comments Created 3 years, 6 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/aligned_memory.h" 14 #include "base/memory/aligned_memory.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/test/scoped_feature_list.h"
17 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
18 #include "base/time/time.h" 19 #include "base/time/time.h"
19 #include "build/build_config.h" 20 #include "build/build_config.h"
20 #include "content/common/media/media_stream_options.h" 21 #include "content/common/media/media_stream_options.h"
22 #include "content/public/common/content_features.h"
21 #include "content/public/common/media_stream_request.h" 23 #include "content/public/common/media_stream_request.h"
22 #include "content/renderer/media/media_stream_audio_processor.h" 24 #include "content/renderer/media/media_stream_audio_processor.h"
23 #include "content/renderer/media/media_stream_audio_processor_options.h" 25 #include "content/renderer/media/media_stream_audio_processor_options.h"
24 #include "content/renderer/media/mock_constraint_factory.h" 26 #include "content/renderer/media/mock_constraint_factory.h"
25 #include "media/base/audio_bus.h" 27 #include "media/base/audio_bus.h"
26 #include "media/base/audio_parameters.h" 28 #include "media/base/audio_parameters.h"
27 #include "testing/gmock/include/gmock/gmock.h" 29 #include "testing/gmock/include/gmock/gmock.h"
28 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
29 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" 31 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
30 #include "third_party/webrtc/api/mediastreaminterface.h" 32 #include "third_party/webrtc/api/mediastreaminterface.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 .Append(FILE_PATH_LITERAL("test")) 69 .Append(FILE_PATH_LITERAL("test"))
68 .Append(FILE_PATH_LITERAL("data")) 70 .Append(FILE_PATH_LITERAL("data"))
69 .Append(FILE_PATH_LITERAL("speech_16b_stereo_48kHz.raw")); 71 .Append(FILE_PATH_LITERAL("speech_16b_stereo_48kHz.raw"));
70 DCHECK(base::PathExists(file)); 72 DCHECK(base::PathExists(file));
71 int64_t data_file_size64 = 0; 73 int64_t data_file_size64 = 0;
72 DCHECK(base::GetFileSize(file, &data_file_size64)); 74 DCHECK(base::GetFileSize(file, &data_file_size64));
73 EXPECT_EQ(length, base::ReadFile(file, data, length)); 75 EXPECT_EQ(length, base::ReadFile(file, data, length));
74 DCHECK(data_file_size64 > length); 76 DCHECK(data_file_size64 > length);
75 } 77 }
76 78
79 void DisableDefaultAudioProcessingProperties(
80 AudioProcessingProperties* properties) {
81 properties->enable_sw_echo_cancellation = false;
82 properties->goog_experimental_echo_cancellation = false;
83 properties->goog_auto_gain_control = false;
84 properties->goog_experimental_auto_gain_control = false;
85 properties->goog_noise_suppression = false;
86 properties->goog_highpass_filter = false;
87 properties->goog_typing_noise_detection = false;
88 properties->goog_experimental_noise_suppression = false;
89 properties->goog_beamforming = false;
90 }
91
77 } // namespace 92 } // namespace
78 93
79 class MediaStreamAudioProcessorTest : public ::testing::Test { 94 class MediaStreamAudioProcessorTest : public ::testing::Test {
80 public: 95 public:
81 MediaStreamAudioProcessorTest() 96 MediaStreamAudioProcessorTest()
82 : params_(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 97 : params_(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
83 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 512) { 98 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 512) {
99 // This file includes tests for MediaStreamAudioProcessor, but also for
100 // the old constraints algorithm. The MediaStreamAudioProcessor tests are
101 // insensitive to the constraints algorithm, but the constraints tests
102 // require that the old constraints algorithm be enabled.
103 scoped_feature_list_.InitAndEnableFeature(
104 features::kMediaStreamOldAudioConstraints);
84 } 105 }
85 106
86 protected: 107 protected:
87 // Helper method to save duplicated code. 108 // Helper method to save duplicated code.
88 void ProcessDataAndVerifyFormat(MediaStreamAudioProcessor* audio_processor, 109 void ProcessDataAndVerifyFormat(MediaStreamAudioProcessor* audio_processor,
89 int expected_output_sample_rate, 110 int expected_output_sample_rate,
90 int expected_output_channels, 111 int expected_output_channels,
91 int expected_output_buffer_size) { 112 int expected_output_buffer_size) {
92 // Read the audio data from a file. 113 // Read the audio data from a file.
93 const media::AudioParameters& params = audio_processor->InputFormat(); 114 const media::AudioParameters& params = audio_processor->InputFormat();
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 ADD_FAILURE() << "AudioProcessing object missing where it shouldn't be"; 226 ADD_FAILURE() << "AudioProcessing object missing where it shouldn't be";
206 return false; 227 return false;
207 } 228 }
208 return audio_processor->audio_processing_->GetConfig() 229 return audio_processor->audio_processing_->GetConfig()
209 .echo_canceller3.enabled; 230 .echo_canceller3.enabled;
210 } 231 }
211 232
212 base::MessageLoop main_thread_message_loop_; 233 base::MessageLoop main_thread_message_loop_;
213 media::AudioParameters params_; 234 media::AudioParameters params_;
214 MediaStreamDevice::AudioDeviceParameters input_device_params_; 235 MediaStreamDevice::AudioDeviceParameters input_device_params_;
236
237 // TODO(guidou): Remove this field. http://crbug.com/706408
238 base::test::ScopedFeatureList scoped_feature_list_;
215 }; 239 };
216 240
217 // Test crashing with ASAN on Android. crbug.com/468762 241 // Test crashing with ASAN on Android. crbug.com/468762
218 #if defined(OS_ANDROID) && defined(ADDRESS_SANITIZER) 242 #if defined(OS_ANDROID) && defined(ADDRESS_SANITIZER)
219 #define MAYBE_WithAudioProcessing DISABLED_WithAudioProcessing 243 #define MAYBE_WithAudioProcessing DISABLED_WithAudioProcessing
220 #else 244 #else
221 #define MAYBE_WithAudioProcessing WithAudioProcessing 245 #define MAYBE_WithAudioProcessing WithAudioProcessing
222 #endif 246 #endif
223 TEST_F(MediaStreamAudioProcessorTest, MAYBE_WithAudioProcessing) { 247 TEST_F(MediaStreamAudioProcessorTest, MAYBE_WithAudioProcessing) {
224 MockConstraintFactory constraint_factory;
225 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 248 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
226 new WebRtcAudioDeviceImpl()); 249 new WebRtcAudioDeviceImpl());
250 AudioProcessingProperties properties;
227 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 251 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
228 new rtc::RefCountedObject<MediaStreamAudioProcessor>( 252 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
229 constraint_factory.CreateWebMediaConstraints(), input_device_params_, 253 properties, webrtc_audio_device.get()));
230 webrtc_audio_device.get()));
231 EXPECT_TRUE(audio_processor->has_audio_processing()); 254 EXPECT_TRUE(audio_processor->has_audio_processing());
232 audio_processor->OnCaptureFormatChanged(params_); 255 audio_processor->OnCaptureFormatChanged(params_);
233 VerifyDefaultComponents(audio_processor.get()); 256 VerifyDefaultComponents(audio_processor.get());
234 257
235 ProcessDataAndVerifyFormat(audio_processor.get(), 258 ProcessDataAndVerifyFormat(audio_processor.get(),
236 kAudioProcessingSampleRate, 259 kAudioProcessingSampleRate,
237 kAudioProcessingNumberOfChannel, 260 kAudioProcessingNumberOfChannel,
238 kAudioProcessingSampleRate / 100); 261 kAudioProcessingSampleRate / 100);
239 262
240 // Stop |audio_processor| so that it removes itself from 263 // Stop |audio_processor| so that it removes itself from
241 // |webrtc_audio_device| and clears its pointer to it. 264 // |webrtc_audio_device| and clears its pointer to it.
242 audio_processor->Stop(); 265 audio_processor->Stop();
243 } 266 }
244 267
245 TEST_F(MediaStreamAudioProcessorTest, VerifyTabCaptureWithoutAudioProcessing) {
246 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
247 new WebRtcAudioDeviceImpl());
248 // Create MediaStreamAudioProcessor instance for kMediaStreamSourceTab source.
249 MockConstraintFactory tab_constraint_factory;
250 const std::string tab_string = kMediaStreamSourceTab;
251 tab_constraint_factory.basic().media_stream_source.SetExact(
252 blink::WebString::FromUTF8(tab_string));
253 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
254 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
255 tab_constraint_factory.CreateWebMediaConstraints(),
256 input_device_params_, webrtc_audio_device.get()));
257 EXPECT_FALSE(audio_processor->has_audio_processing());
258 audio_processor->OnCaptureFormatChanged(params_);
259
260 ProcessDataAndVerifyFormat(audio_processor.get(),
261 params_.sample_rate(),
262 params_.channels(),
263 params_.sample_rate() / 100);
264
265 // Create MediaStreamAudioProcessor instance for kMediaStreamSourceSystem
266 // source.
267 MockConstraintFactory system_constraint_factory;
268 const std::string system_string = kMediaStreamSourceSystem;
269 system_constraint_factory.basic().media_stream_source.SetExact(
270 blink::WebString::FromUTF8(system_string));
271 audio_processor = new rtc::RefCountedObject<MediaStreamAudioProcessor>(
272 system_constraint_factory.CreateWebMediaConstraints(),
273 input_device_params_, webrtc_audio_device.get());
274 EXPECT_FALSE(audio_processor->has_audio_processing());
275
276 // Stop |audio_processor| so that it removes itself from
277 // |webrtc_audio_device| and clears its pointer to it.
278 audio_processor->Stop();
279 }
280
281 TEST_F(MediaStreamAudioProcessorTest, TurnOffDefaultConstraints) { 268 TEST_F(MediaStreamAudioProcessorTest, TurnOffDefaultConstraints) {
269 AudioProcessingProperties properties;
282 // Turn off the default constraints and pass it to MediaStreamAudioProcessor. 270 // Turn off the default constraints and pass it to MediaStreamAudioProcessor.
283 MockConstraintFactory constraint_factory; 271 DisableDefaultAudioProcessingProperties(&properties);
284 constraint_factory.DisableDefaultAudioConstraints();
285 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 272 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
286 new WebRtcAudioDeviceImpl()); 273 new WebRtcAudioDeviceImpl());
287 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 274 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
288 new rtc::RefCountedObject<MediaStreamAudioProcessor>( 275 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
289 constraint_factory.CreateWebMediaConstraints(), input_device_params_, 276 properties, webrtc_audio_device.get()));
290 webrtc_audio_device.get()));
291 EXPECT_FALSE(audio_processor->has_audio_processing()); 277 EXPECT_FALSE(audio_processor->has_audio_processing());
292 audio_processor->OnCaptureFormatChanged(params_); 278 audio_processor->OnCaptureFormatChanged(params_);
293 279
294 ProcessDataAndVerifyFormat(audio_processor.get(), 280 ProcessDataAndVerifyFormat(audio_processor.get(),
295 params_.sample_rate(), 281 params_.sample_rate(),
296 params_.channels(), 282 params_.channels(),
297 params_.sample_rate() / 100); 283 params_.sample_rate() / 100);
298 284
299 // Stop |audio_processor| so that it removes itself from 285 // Stop |audio_processor| so that it removes itself from
300 // |webrtc_audio_device| and clears its pointer to it. 286 // |webrtc_audio_device| and clears its pointer to it.
301 audio_processor->Stop(); 287 audio_processor->Stop();
302 } 288 }
303 289
290 // TODO(guidou): Remove this test. http://crbug.com/706408
304 TEST_F(MediaStreamAudioProcessorTest, VerifyConstraints) { 291 TEST_F(MediaStreamAudioProcessorTest, VerifyConstraints) {
305 { 292 {
306 // Verify that echo cancellation is off when platform aec effect is on. 293 // Verify that echo cancellation is off when platform aec effect is on.
307 MockConstraintFactory constraint_factory; 294 MockConstraintFactory constraint_factory;
308 MediaAudioConstraints audio_constraints( 295 MediaAudioConstraints audio_constraints(
309 constraint_factory.CreateWebMediaConstraints(), 296 constraint_factory.CreateWebMediaConstraints(),
310 media::AudioParameters::ECHO_CANCELLER); 297 media::AudioParameters::ECHO_CANCELLER);
311 EXPECT_FALSE(audio_constraints.GetEchoCancellationProperty()); 298 EXPECT_FALSE(audio_constraints.GetEchoCancellationProperty());
312 } 299 }
313 300
(...skipping 19 matching lines...) Expand all
333 // When |kEchoCancellation| is explicitly set to false, the default values 320 // When |kEchoCancellation| is explicitly set to false, the default values
334 // for all the constraints are false. 321 // for all the constraints are false.
335 MockConstraintFactory constraint_factory; 322 MockConstraintFactory constraint_factory;
336 constraint_factory.AddAdvanced().echo_cancellation.SetExact(false); 323 constraint_factory.AddAdvanced().echo_cancellation.SetExact(false);
337 blink::WebMediaConstraints constraints = 324 blink::WebMediaConstraints constraints =
338 constraint_factory.CreateWebMediaConstraints(); 325 constraint_factory.CreateWebMediaConstraints();
339 MediaAudioConstraints audio_constraints(constraints, 0); 326 MediaAudioConstraints audio_constraints(constraints, 0);
340 } 327 }
341 } 328 }
342 329
330 // TODO(guidou): Remove this test. http://crbug.com/706408
343 TEST_F(MediaStreamAudioProcessorTest, ValidateBadConstraints) { 331 TEST_F(MediaStreamAudioProcessorTest, ValidateBadConstraints) {
344 MockConstraintFactory constraint_factory; 332 MockConstraintFactory constraint_factory;
345 // Add a constraint that is not valid for audio. 333 // Add a constraint that is not valid for audio.
346 constraint_factory.basic().width.SetExact(240); 334 constraint_factory.basic().width.SetExact(240);
347 MediaAudioConstraints audio_constraints( 335 MediaAudioConstraints audio_constraints(
348 constraint_factory.CreateWebMediaConstraints(), 0); 336 constraint_factory.CreateWebMediaConstraints(), 0);
349 EXPECT_FALSE(audio_constraints.IsValid()); 337 EXPECT_FALSE(audio_constraints.IsValid());
350 } 338 }
351 339
340 // TODO(guidou): Remove this test. http://crbug.com/706408
352 TEST_F(MediaStreamAudioProcessorTest, ValidateGoodConstraints) { 341 TEST_F(MediaStreamAudioProcessorTest, ValidateGoodConstraints) {
353 MockConstraintFactory constraint_factory; 342 MockConstraintFactory constraint_factory;
354 // Check that the renderToAssociatedSink constraint is considered valid. 343 // Check that the renderToAssociatedSink constraint is considered valid.
355 constraint_factory.basic().render_to_associated_sink.SetExact(true); 344 constraint_factory.basic().render_to_associated_sink.SetExact(true);
356 MediaAudioConstraints audio_constraints( 345 MediaAudioConstraints audio_constraints(
357 constraint_factory.CreateWebMediaConstraints(), 0); 346 constraint_factory.CreateWebMediaConstraints(), 0);
358 EXPECT_TRUE(audio_constraints.IsValid()); 347 EXPECT_TRUE(audio_constraints.IsValid());
359 } 348 }
360 349
350 // TODO(guidou): Remove this test. http://crbug.com/706408
361 TEST_F(MediaStreamAudioProcessorTest, NoEchoTurnsOffProcessing) { 351 TEST_F(MediaStreamAudioProcessorTest, NoEchoTurnsOffProcessing) {
362 { 352 {
363 MockConstraintFactory constraint_factory; 353 MockConstraintFactory constraint_factory;
364 MediaAudioConstraints audio_constraints( 354 MediaAudioConstraints audio_constraints(
365 constraint_factory.CreateWebMediaConstraints(), 0); 355 constraint_factory.CreateWebMediaConstraints(), 0);
366 // The default value for echo cancellation is true, except when all 356 // The default value for echo cancellation is true, except when all
367 // audio processing has been turned off. 357 // audio processing has been turned off.
368 EXPECT_TRUE(audio_constraints.default_audio_processing_constraint_value()); 358 EXPECT_TRUE(audio_constraints.default_audio_processing_constraint_value());
369 } 359 }
370 // Turning off audio processing via a mandatory constraint. 360 // Turning off audio processing via a mandatory constraint.
371 { 361 {
372 MockConstraintFactory constraint_factory; 362 MockConstraintFactory constraint_factory;
373 constraint_factory.basic().echo_cancellation.SetExact(false); 363 constraint_factory.basic().echo_cancellation.SetExact(false);
374 MediaAudioConstraints audio_constraints( 364 MediaAudioConstraints audio_constraints(
375 constraint_factory.CreateWebMediaConstraints(), 0); 365 constraint_factory.CreateWebMediaConstraints(), 0);
376 // The default value for echo cancellation is true, except when all 366 // The default value for echo cancellation is true, except when all
377 // audio processing has been turned off. 367 // audio processing has been turned off.
378 EXPECT_FALSE(audio_constraints.default_audio_processing_constraint_value()); 368 EXPECT_FALSE(audio_constraints.default_audio_processing_constraint_value());
379 } 369 }
380 // Turning off audio processing via an optional constraint. 370 // Turning off audio processing via an optional constraint.
381 { 371 {
382 MockConstraintFactory constraint_factory; 372 MockConstraintFactory constraint_factory;
383 constraint_factory.AddAdvanced().echo_cancellation.SetExact(false); 373 constraint_factory.AddAdvanced().echo_cancellation.SetExact(false);
384 MediaAudioConstraints audio_constraints( 374 MediaAudioConstraints audio_constraints(
385 constraint_factory.CreateWebMediaConstraints(), 0); 375 constraint_factory.CreateWebMediaConstraints(), 0);
386 EXPECT_FALSE(audio_constraints.default_audio_processing_constraint_value()); 376 EXPECT_FALSE(audio_constraints.default_audio_processing_constraint_value());
387 } 377 }
388 } 378 }
389 379
380 // TODO(guidou): Remove this function. http://crbug.com/706408
390 MediaAudioConstraints MakeMediaAudioConstraints( 381 MediaAudioConstraints MakeMediaAudioConstraints(
391 const MockConstraintFactory& constraint_factory) { 382 const MockConstraintFactory& constraint_factory) {
392 return MediaAudioConstraints(constraint_factory.CreateWebMediaConstraints(), 383 return MediaAudioConstraints(constraint_factory.CreateWebMediaConstraints(),
393 AudioParameters::NO_EFFECTS); 384 AudioParameters::NO_EFFECTS);
394 } 385 }
395 386
387 // TODO(guidou): Remove this test. http://crbug.com/706408
396 TEST_F(MediaStreamAudioProcessorTest, SelectsConstraintsArrayGeometryIfExists) { 388 TEST_F(MediaStreamAudioProcessorTest, SelectsConstraintsArrayGeometryIfExists) {
397 std::vector<webrtc::Point> constraints_geometry(1, 389 std::vector<media::Point> constraints_geometry(1, media::Point(-0.02f, 0, 0));
398 webrtc::Point(-0.02f, 0, 0)); 390 constraints_geometry.push_back(media::Point(0.02f, 0, 0));
399 constraints_geometry.push_back(webrtc::Point(0.02f, 0, 0));
400 391
401 std::vector<webrtc::Point> input_device_geometry(1, webrtc::Point(0, 0, 0)); 392 std::vector<media::Point> input_device_geometry(1, media::Point(0, 0, 0));
402 input_device_geometry.push_back(webrtc::Point(0, 0.05f, 0)); 393 input_device_geometry.push_back(media::Point(0, 0.05f, 0));
403 394
404 { 395 {
405 // Both geometries empty. 396 // Both geometries empty.
406 MockConstraintFactory constraint_factory; 397 MockConstraintFactory constraint_factory;
407 MediaStreamDevice::AudioDeviceParameters input_params; 398 MediaStreamDevice::AudioDeviceParameters input_params;
408 399
409 const auto& actual_geometry = GetArrayGeometryPreferringConstraints( 400 const auto& actual_geometry = GetArrayGeometryPreferringConstraints(
410 MakeMediaAudioConstraints(constraint_factory), input_params); 401 MakeMediaAudioConstraints(constraint_factory), input_params);
411 EXPECT_EQ(std::vector<webrtc::Point>(), actual_geometry); 402 EXPECT_EQ(std::vector<media::Point>(), actual_geometry);
412 } 403 }
413 { 404 {
414 // Constraints geometry empty. 405 // Constraints geometry empty.
415 MockConstraintFactory constraint_factory; 406 MockConstraintFactory constraint_factory;
416 MediaStreamDevice::AudioDeviceParameters input_params; 407 MediaStreamDevice::AudioDeviceParameters input_params;
417 input_params.mic_positions.push_back(media::Point(0, 0, 0)); 408 input_params.mic_positions.push_back(media::Point(0, 0, 0));
418 input_params.mic_positions.push_back(media::Point(0, 0.05f, 0)); 409 input_params.mic_positions.push_back(media::Point(0, 0.05f, 0));
419 410
420 const auto& actual_geometry = GetArrayGeometryPreferringConstraints( 411 const auto& actual_geometry = GetArrayGeometryPreferringConstraints(
421 MakeMediaAudioConstraints(constraint_factory), input_params); 412 MakeMediaAudioConstraints(constraint_factory), input_params);
(...skipping 26 matching lines...) Expand all
448 } 439 }
449 } 440 }
450 441
451 // Test crashing with ASAN on Android. crbug.com/468762 442 // Test crashing with ASAN on Android. crbug.com/468762
452 #if defined(OS_ANDROID) && defined(ADDRESS_SANITIZER) 443 #if defined(OS_ANDROID) && defined(ADDRESS_SANITIZER)
453 #define MAYBE_TestAllSampleRates DISABLED_TestAllSampleRates 444 #define MAYBE_TestAllSampleRates DISABLED_TestAllSampleRates
454 #else 445 #else
455 #define MAYBE_TestAllSampleRates TestAllSampleRates 446 #define MAYBE_TestAllSampleRates TestAllSampleRates
456 #endif 447 #endif
457 TEST_F(MediaStreamAudioProcessorTest, MAYBE_TestAllSampleRates) { 448 TEST_F(MediaStreamAudioProcessorTest, MAYBE_TestAllSampleRates) {
458 MockConstraintFactory constraint_factory;
459 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 449 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
460 new WebRtcAudioDeviceImpl()); 450 new WebRtcAudioDeviceImpl());
451 AudioProcessingProperties properties;
461 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 452 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
462 new rtc::RefCountedObject<MediaStreamAudioProcessor>( 453 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
463 constraint_factory.CreateWebMediaConstraints(), input_device_params_, 454 properties, webrtc_audio_device.get()));
464 webrtc_audio_device.get()));
465 EXPECT_TRUE(audio_processor->has_audio_processing()); 455 EXPECT_TRUE(audio_processor->has_audio_processing());
466 456
467 static const int kSupportedSampleRates[] = 457 static const int kSupportedSampleRates[] =
468 { 8000, 16000, 22050, 32000, 44100, 48000 }; 458 { 8000, 16000, 22050, 32000, 44100, 48000 };
469 for (size_t i = 0; i < arraysize(kSupportedSampleRates); ++i) { 459 for (size_t i = 0; i < arraysize(kSupportedSampleRates); ++i) {
470 int buffer_size = (kSupportedSampleRates[i] / 100) < 128 ? 460 int buffer_size = (kSupportedSampleRates[i] / 100) < 128 ?
471 kSupportedSampleRates[i] / 100 : 128; 461 kSupportedSampleRates[i] / 100 : 128;
472 media::AudioParameters params( 462 media::AudioParameters params(
473 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 463 media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
474 media::CHANNEL_LAYOUT_STEREO, kSupportedSampleRates[i], 16, 464 media::CHANNEL_LAYOUT_STEREO, kSupportedSampleRates[i], 16,
(...skipping 13 matching lines...) Expand all
488 } 478 }
489 479
490 // Test that if we have an AEC dump message filter created, we are getting it 480 // Test that if we have an AEC dump message filter created, we are getting it
491 // correctly in MSAP. Any IPC messages will be deleted since no sender in the 481 // correctly in MSAP. Any IPC messages will be deleted since no sender in the
492 // filter will be created. 482 // filter will be created.
493 TEST_F(MediaStreamAudioProcessorTest, GetAecDumpMessageFilter) { 483 TEST_F(MediaStreamAudioProcessorTest, GetAecDumpMessageFilter) {
494 scoped_refptr<AecDumpMessageFilter> aec_dump_message_filter_( 484 scoped_refptr<AecDumpMessageFilter> aec_dump_message_filter_(
495 new AecDumpMessageFilter(base::ThreadTaskRunnerHandle::Get(), 485 new AecDumpMessageFilter(base::ThreadTaskRunnerHandle::Get(),
496 base::ThreadTaskRunnerHandle::Get())); 486 base::ThreadTaskRunnerHandle::Get()));
497 487
498 MockConstraintFactory constraint_factory;
499 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 488 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
500 new WebRtcAudioDeviceImpl()); 489 new WebRtcAudioDeviceImpl());
490 AudioProcessingProperties properties;
501 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 491 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
502 new rtc::RefCountedObject<MediaStreamAudioProcessor>( 492 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
503 constraint_factory.CreateWebMediaConstraints(), input_device_params_, 493 properties, webrtc_audio_device.get()));
504 webrtc_audio_device.get()));
505 494
506 EXPECT_TRUE(audio_processor->aec_dump_message_filter_.get()); 495 EXPECT_TRUE(audio_processor->aec_dump_message_filter_.get());
507 496
508 // Stop |audio_processor| so that it removes itself from 497 // Stop |audio_processor| so that it removes itself from
509 // |webrtc_audio_device| and clears its pointer to it. 498 // |webrtc_audio_device| and clears its pointer to it.
510 audio_processor->Stop(); 499 audio_processor->Stop();
511 } 500 }
512 501
513 TEST_F(MediaStreamAudioProcessorTest, TestStereoAudio) { 502 TEST_F(MediaStreamAudioProcessorTest, TestStereoAudio) {
514 // Set up the correct constraints to turn off the audio processing and turn
515 // on the stereo channels mirroring.
516 MockConstraintFactory constraint_factory;
517 constraint_factory.basic().echo_cancellation.SetExact(false);
518 constraint_factory.basic().goog_audio_mirroring.SetExact(true);
519 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 503 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
520 new WebRtcAudioDeviceImpl()); 504 new WebRtcAudioDeviceImpl());
505 AudioProcessingProperties properties;
506 // Turn off the audio processing and turn on the stereo channels mirroring.
507 DisableDefaultAudioProcessingProperties(&properties);
508 properties.goog_audio_mirroring = true;
521 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 509 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
522 new rtc::RefCountedObject<MediaStreamAudioProcessor>( 510 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
523 constraint_factory.CreateWebMediaConstraints(), input_device_params_, 511 properties, webrtc_audio_device.get()));
524 webrtc_audio_device.get()));
525 EXPECT_FALSE(audio_processor->has_audio_processing()); 512 EXPECT_FALSE(audio_processor->has_audio_processing());
526 const media::AudioParameters source_params( 513 const media::AudioParameters source_params(
527 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 514 media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
528 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 480); 515 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 480);
529 audio_processor->OnCaptureFormatChanged(source_params); 516 audio_processor->OnCaptureFormatChanged(source_params);
530 // There's no sense in continuing if this fails. 517 // There's no sense in continuing if this fails.
531 ASSERT_EQ(2, audio_processor->OutputFormat().channels()); 518 ASSERT_EQ(2, audio_processor->OutputFormat().channels());
532 519
533 // Construct left and right channels, and assign different values to the 520 // Construct left and right channels, and assign different values to the
534 // first data of the left channel and right channel. 521 // first data of the left channel and right channel.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 audio_processor->Stop(); 557 audio_processor->Stop();
571 } 558 }
572 559
573 // Disabled on android clang builds due to crbug.com/470499 560 // Disabled on android clang builds due to crbug.com/470499
574 #if defined(__clang__) && defined(OS_ANDROID) 561 #if defined(__clang__) && defined(OS_ANDROID)
575 #define MAYBE_TestWithKeyboardMicChannel DISABLED_TestWithKeyboardMicChannel 562 #define MAYBE_TestWithKeyboardMicChannel DISABLED_TestWithKeyboardMicChannel
576 #else 563 #else
577 #define MAYBE_TestWithKeyboardMicChannel TestWithKeyboardMicChannel 564 #define MAYBE_TestWithKeyboardMicChannel TestWithKeyboardMicChannel
578 #endif 565 #endif
579 TEST_F(MediaStreamAudioProcessorTest, MAYBE_TestWithKeyboardMicChannel) { 566 TEST_F(MediaStreamAudioProcessorTest, MAYBE_TestWithKeyboardMicChannel) {
580 MockConstraintFactory constraint_factory;
581 constraint_factory.basic().goog_experimental_noise_suppression.SetExact(true);
582 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 567 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
583 new WebRtcAudioDeviceImpl()); 568 new WebRtcAudioDeviceImpl());
569 AudioProcessingProperties properties;
584 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 570 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
585 new rtc::RefCountedObject<MediaStreamAudioProcessor>( 571 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
586 constraint_factory.CreateWebMediaConstraints(), input_device_params_, 572 properties, webrtc_audio_device.get()));
587 webrtc_audio_device.get()));
588 EXPECT_TRUE(audio_processor->has_audio_processing()); 573 EXPECT_TRUE(audio_processor->has_audio_processing());
589 574
590 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 575 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
591 media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC, 576 media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC,
592 48000, 16, 512); 577 48000, 16, 512);
593 audio_processor->OnCaptureFormatChanged(params); 578 audio_processor->OnCaptureFormatChanged(params);
594 579
595 ProcessDataAndVerifyFormat(audio_processor.get(), 580 ProcessDataAndVerifyFormat(audio_processor.get(),
596 kAudioProcessingSampleRate, 581 kAudioProcessingSampleRate,
597 kAudioProcessingNumberOfChannel, 582 kAudioProcessingNumberOfChannel,
598 kAudioProcessingSampleRate / 100); 583 kAudioProcessingSampleRate / 100);
599 584
600 // Stop |audio_processor| so that it removes itself from 585 // Stop |audio_processor| so that it removes itself from
601 // |webrtc_audio_device| and clears its pointer to it. 586 // |webrtc_audio_device| and clears its pointer to it.
602 audio_processor->Stop(); 587 audio_processor->Stop();
603 } 588 }
604 589
605 // Test that the OnAec3Enable method has the desired effect on the APM config. 590 // Test that the OnAec3Enable method has the desired effect on the APM config.
606 TEST_F(MediaStreamAudioProcessorTest, TestAec3Switch) { 591 TEST_F(MediaStreamAudioProcessorTest, TestAec3Switch) {
607 MockConstraintFactory constraint_factory;
608 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 592 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
609 new WebRtcAudioDeviceImpl()); 593 new WebRtcAudioDeviceImpl());
594 AudioProcessingProperties properties;
610 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 595 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
611 new rtc::RefCountedObject<MediaStreamAudioProcessor>( 596 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
612 constraint_factory.CreateWebMediaConstraints(), input_device_params_, 597 properties, webrtc_audio_device.get()));
613 webrtc_audio_device.get()));
614 598
615 audio_processor->OnAec3Enable(true); 599 audio_processor->OnAec3Enable(true);
616 EXPECT_TRUE(GetAec3ConfigState(audio_processor.get())); 600 EXPECT_TRUE(GetAec3ConfigState(audio_processor.get()));
617 601
618 audio_processor->OnAec3Enable(false); 602 audio_processor->OnAec3Enable(false);
619 EXPECT_FALSE(GetAec3ConfigState(audio_processor.get())); 603 EXPECT_FALSE(GetAec3ConfigState(audio_processor.get()));
620 604
621 // Stop |audio_processor| so that it removes itself from 605 // Stop |audio_processor| so that it removes itself from
622 // |webrtc_audio_device| and clears its pointer to it. 606 // |webrtc_audio_device| and clears its pointer to it.
623 audio_processor->Stop(); 607 audio_processor->Stop();
624 } 608 }
625 609
626 // Same test as above, but when AEC is disabled in the constrants. The expected 610 // Same test as above, but when AEC is disabled in the constrants. The expected
627 // outcome is that AEC3 should be disabled in all cases. 611 // outcome is that AEC3 should be disabled in all cases.
628 TEST_F(MediaStreamAudioProcessorTest, TestAec3Switch_AecOff) { 612 TEST_F(MediaStreamAudioProcessorTest, TestAec3Switch_AecOff) {
629 MockConstraintFactory constraint_factory;
630 // Disable the AEC.
631 constraint_factory.DisableAecAudioConstraints();
632 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 613 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
633 new WebRtcAudioDeviceImpl()); 614 new WebRtcAudioDeviceImpl());
615 AudioProcessingProperties properties;
616 // Disable the AEC.
617 properties.enable_sw_echo_cancellation = false;
634 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 618 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
635 new rtc::RefCountedObject<MediaStreamAudioProcessor>( 619 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
636 constraint_factory.CreateWebMediaConstraints(), input_device_params_, 620 properties, webrtc_audio_device.get()));
637 webrtc_audio_device.get()));
638 621
639 EXPECT_FALSE(GetAec3ConfigState(audio_processor.get())); 622 EXPECT_FALSE(GetAec3ConfigState(audio_processor.get()));
640 623
641 audio_processor->OnAec3Enable(true); 624 audio_processor->OnAec3Enable(true);
642 EXPECT_FALSE(GetAec3ConfigState(audio_processor.get())); 625 EXPECT_FALSE(GetAec3ConfigState(audio_processor.get()));
643 626
644 audio_processor->OnAec3Enable(false); 627 audio_processor->OnAec3Enable(false);
645 EXPECT_FALSE(GetAec3ConfigState(audio_processor.get())); 628 EXPECT_FALSE(GetAec3ConfigState(audio_processor.get()));
646 629
647 // Stop |audio_processor| so that it removes itself from 630 // Stop |audio_processor| so that it removes itself from
648 // |webrtc_audio_device| and clears its pointer to it. 631 // |webrtc_audio_device| and clears its pointer to it.
649 audio_processor->Stop(); 632 audio_processor->Stop();
650 } 633 }
651 634
652 } // namespace content 635 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698