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

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

Issue 2103483002: Add UMA stats for AEC filter divergence metric. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed unit test. Created 4 years, 5 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"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 MediaStreamDevice::AudioDeviceParameters input_device_params_; 201 MediaStreamDevice::AudioDeviceParameters input_device_params_;
202 }; 202 };
203 203
204 // Test crashing with ASAN on Android. crbug.com/468762 204 // Test crashing with ASAN on Android. crbug.com/468762
205 #if defined(OS_ANDROID) && defined(ADDRESS_SANITIZER) 205 #if defined(OS_ANDROID) && defined(ADDRESS_SANITIZER)
206 #define MAYBE_WithAudioProcessing DISABLED_WithAudioProcessing 206 #define MAYBE_WithAudioProcessing DISABLED_WithAudioProcessing
207 #else 207 #else
208 #define MAYBE_WithAudioProcessing WithAudioProcessing 208 #define MAYBE_WithAudioProcessing WithAudioProcessing
209 #endif 209 #endif
210 TEST_F(MediaStreamAudioProcessorTest, MAYBE_WithAudioProcessing) { 210 TEST_F(MediaStreamAudioProcessorTest, MAYBE_WithAudioProcessing) {
211 base::MessageLoop message_loop;
211 MockConstraintFactory constraint_factory; 212 MockConstraintFactory constraint_factory;
212 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 213 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
213 new WebRtcAudioDeviceImpl()); 214 new WebRtcAudioDeviceImpl());
214 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 215 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
215 new rtc::RefCountedObject<MediaStreamAudioProcessor>( 216 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
216 constraint_factory.CreateWebMediaConstraints(), input_device_params_, 217 constraint_factory.CreateWebMediaConstraints(), input_device_params_,
217 webrtc_audio_device.get())); 218 webrtc_audio_device.get()));
218 EXPECT_TRUE(audio_processor->has_audio_processing()); 219 EXPECT_TRUE(audio_processor->has_audio_processing());
219 audio_processor->OnCaptureFormatChanged(params_); 220 audio_processor->OnCaptureFormatChanged(params_);
220 VerifyDefaultComponents(audio_processor.get()); 221 VerifyDefaultComponents(audio_processor.get());
221 222
222 ProcessDataAndVerifyFormat(audio_processor.get(), 223 ProcessDataAndVerifyFormat(audio_processor.get(),
223 kAudioProcessingSampleRate, 224 kAudioProcessingSampleRate,
224 kAudioProcessingNumberOfChannel, 225 kAudioProcessingNumberOfChannel,
225 kAudioProcessingSampleRate / 100); 226 kAudioProcessingSampleRate / 100);
226 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives 227
227 // |audio_processor|. 228 // Stop |audio_processor| so that it removes itself from
228 audio_processor = NULL; 229 // |webrtc_audio_device| and clears its pointer to it.
230 audio_processor->Stop();
229 } 231 }
230 232
231 TEST_F(MediaStreamAudioProcessorTest, VerifyTabCaptureWithoutAudioProcessing) { 233 TEST_F(MediaStreamAudioProcessorTest, VerifyTabCaptureWithoutAudioProcessing) {
232 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 234 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
233 new WebRtcAudioDeviceImpl()); 235 new WebRtcAudioDeviceImpl());
234 // Create MediaStreamAudioProcessor instance for kMediaStreamSourceTab source. 236 // Create MediaStreamAudioProcessor instance for kMediaStreamSourceTab source.
235 MockConstraintFactory tab_constraint_factory; 237 MockConstraintFactory tab_constraint_factory;
236 const std::string tab_string = kMediaStreamSourceTab; 238 const std::string tab_string = kMediaStreamSourceTab;
237 tab_constraint_factory.basic().mediaStreamSource.setExact( 239 tab_constraint_factory.basic().mediaStreamSource.setExact(
238 blink::WebString::fromUTF8(tab_string)); 240 blink::WebString::fromUTF8(tab_string));
(...skipping 13 matching lines...) Expand all
252 // source. 254 // source.
253 MockConstraintFactory system_constraint_factory; 255 MockConstraintFactory system_constraint_factory;
254 const std::string system_string = kMediaStreamSourceSystem; 256 const std::string system_string = kMediaStreamSourceSystem;
255 system_constraint_factory.basic().mediaStreamSource.setExact( 257 system_constraint_factory.basic().mediaStreamSource.setExact(
256 blink::WebString::fromUTF8(system_string)); 258 blink::WebString::fromUTF8(system_string));
257 audio_processor = new rtc::RefCountedObject<MediaStreamAudioProcessor>( 259 audio_processor = new rtc::RefCountedObject<MediaStreamAudioProcessor>(
258 system_constraint_factory.CreateWebMediaConstraints(), 260 system_constraint_factory.CreateWebMediaConstraints(),
259 input_device_params_, webrtc_audio_device.get()); 261 input_device_params_, webrtc_audio_device.get());
260 EXPECT_FALSE(audio_processor->has_audio_processing()); 262 EXPECT_FALSE(audio_processor->has_audio_processing());
261 263
262 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives 264 // Stop |audio_processor| so that it removes itself from
263 // |audio_processor|. 265 // |webrtc_audio_device| and clears its pointer to it.
264 audio_processor = NULL; 266 audio_processor->Stop();
265 } 267 }
266 268
267 TEST_F(MediaStreamAudioProcessorTest, TurnOffDefaultConstraints) { 269 TEST_F(MediaStreamAudioProcessorTest, TurnOffDefaultConstraints) {
268 // Turn off the default constraints and pass it to MediaStreamAudioProcessor. 270 // Turn off the default constraints and pass it to MediaStreamAudioProcessor.
269 MockConstraintFactory constraint_factory; 271 MockConstraintFactory constraint_factory;
270 constraint_factory.DisableDefaultAudioConstraints(); 272 constraint_factory.DisableDefaultAudioConstraints();
271 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 273 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
272 new WebRtcAudioDeviceImpl()); 274 new WebRtcAudioDeviceImpl());
273 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 275 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
274 new rtc::RefCountedObject<MediaStreamAudioProcessor>( 276 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
275 constraint_factory.CreateWebMediaConstraints(), input_device_params_, 277 constraint_factory.CreateWebMediaConstraints(), input_device_params_,
276 webrtc_audio_device.get())); 278 webrtc_audio_device.get()));
277 EXPECT_FALSE(audio_processor->has_audio_processing()); 279 EXPECT_FALSE(audio_processor->has_audio_processing());
278 audio_processor->OnCaptureFormatChanged(params_); 280 audio_processor->OnCaptureFormatChanged(params_);
279 281
280 ProcessDataAndVerifyFormat(audio_processor.get(), 282 ProcessDataAndVerifyFormat(audio_processor.get(),
281 params_.sample_rate(), 283 params_.sample_rate(),
282 params_.channels(), 284 params_.channels(),
283 params_.sample_rate() / 100); 285 params_.sample_rate() / 100);
284 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives 286
285 // |audio_processor|. 287 // Stop |audio_processor| so that it removes itself from
286 audio_processor = NULL; 288 // |webrtc_audio_device| and clears its pointer to it.
289 audio_processor->Stop();
287 } 290 }
288 291
289 TEST_F(MediaStreamAudioProcessorTest, VerifyConstraints) { 292 TEST_F(MediaStreamAudioProcessorTest, VerifyConstraints) {
290 { 293 {
291 // Verify that echo cancellation is off when platform aec effect is on. 294 // Verify that echo cancellation is off when platform aec effect is on.
292 MockConstraintFactory constraint_factory; 295 MockConstraintFactory constraint_factory;
293 MediaAudioConstraints audio_constraints( 296 MediaAudioConstraints audio_constraints(
294 constraint_factory.CreateWebMediaConstraints(), 297 constraint_factory.CreateWebMediaConstraints(),
295 media::AudioParameters::ECHO_CANCELLER); 298 media::AudioParameters::ECHO_CANCELLER);
296 EXPECT_FALSE(audio_constraints.GetEchoCancellationProperty()); 299 EXPECT_FALSE(audio_constraints.GetEchoCancellationProperty());
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 } 436 }
434 } 437 }
435 438
436 // Test crashing with ASAN on Android. crbug.com/468762 439 // Test crashing with ASAN on Android. crbug.com/468762
437 #if defined(OS_ANDROID) && defined(ADDRESS_SANITIZER) 440 #if defined(OS_ANDROID) && defined(ADDRESS_SANITIZER)
438 #define MAYBE_TestAllSampleRates DISABLED_TestAllSampleRates 441 #define MAYBE_TestAllSampleRates DISABLED_TestAllSampleRates
439 #else 442 #else
440 #define MAYBE_TestAllSampleRates TestAllSampleRates 443 #define MAYBE_TestAllSampleRates TestAllSampleRates
441 #endif 444 #endif
442 TEST_F(MediaStreamAudioProcessorTest, MAYBE_TestAllSampleRates) { 445 TEST_F(MediaStreamAudioProcessorTest, MAYBE_TestAllSampleRates) {
446 base::MessageLoop message_loop;
443 MockConstraintFactory constraint_factory; 447 MockConstraintFactory constraint_factory;
444 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 448 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
445 new WebRtcAudioDeviceImpl()); 449 new WebRtcAudioDeviceImpl());
446 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 450 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
447 new rtc::RefCountedObject<MediaStreamAudioProcessor>( 451 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
448 constraint_factory.CreateWebMediaConstraints(), input_device_params_, 452 constraint_factory.CreateWebMediaConstraints(), input_device_params_,
449 webrtc_audio_device.get())); 453 webrtc_audio_device.get()));
450 EXPECT_TRUE(audio_processor->has_audio_processing()); 454 EXPECT_TRUE(audio_processor->has_audio_processing());
451 455
452 static const int kSupportedSampleRates[] = 456 static const int kSupportedSampleRates[] =
453 { 8000, 16000, 22050, 32000, 44100, 48000 }; 457 { 8000, 16000, 22050, 32000, 44100, 48000 };
454 for (size_t i = 0; i < arraysize(kSupportedSampleRates); ++i) { 458 for (size_t i = 0; i < arraysize(kSupportedSampleRates); ++i) {
455 int buffer_size = (kSupportedSampleRates[i] / 100) < 128 ? 459 int buffer_size = (kSupportedSampleRates[i] / 100) < 128 ?
456 kSupportedSampleRates[i] / 100 : 128; 460 kSupportedSampleRates[i] / 100 : 128;
457 media::AudioParameters params( 461 media::AudioParameters params(
458 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 462 media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
459 media::CHANNEL_LAYOUT_STEREO, kSupportedSampleRates[i], 16, 463 media::CHANNEL_LAYOUT_STEREO, kSupportedSampleRates[i], 16,
460 buffer_size); 464 buffer_size);
461 audio_processor->OnCaptureFormatChanged(params); 465 audio_processor->OnCaptureFormatChanged(params);
462 VerifyDefaultComponents(audio_processor.get()); 466 VerifyDefaultComponents(audio_processor.get());
463 467
464 ProcessDataAndVerifyFormat(audio_processor.get(), 468 ProcessDataAndVerifyFormat(audio_processor.get(),
465 kAudioProcessingSampleRate, 469 kAudioProcessingSampleRate,
466 kAudioProcessingNumberOfChannel, 470 kAudioProcessingNumberOfChannel,
467 kAudioProcessingSampleRate / 100); 471 kAudioProcessingSampleRate / 100);
468 } 472 }
469 473
470 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| 474 // Stop |audio_processor| so that it removes itself from
471 // outlives |audio_processor|. 475 // |webrtc_audio_device| and clears its pointer to it.
472 audio_processor = NULL; 476 audio_processor->Stop();
473 } 477 }
474 478
475 // Test that if we have an AEC dump message filter created, we are getting it 479 // Test that if we have an AEC dump message filter created, we are getting it
476 // correctly in MSAP. Any IPC messages will be deleted since no sender in the 480 // correctly in MSAP. Any IPC messages will be deleted since no sender in the
477 // filter will be created. 481 // filter will be created.
478 TEST_F(MediaStreamAudioProcessorTest, GetAecDumpMessageFilter) { 482 TEST_F(MediaStreamAudioProcessorTest, GetAecDumpMessageFilter) {
479 base::MessageLoopForUI message_loop; 483 base::MessageLoopForUI message_loop;
480 scoped_refptr<AecDumpMessageFilter> aec_dump_message_filter_( 484 scoped_refptr<AecDumpMessageFilter> aec_dump_message_filter_(
481 new AecDumpMessageFilter(message_loop.task_runner(), 485 new AecDumpMessageFilter(message_loop.task_runner(),
482 message_loop.task_runner(), nullptr)); 486 message_loop.task_runner(), nullptr));
483 487
484 MockConstraintFactory constraint_factory; 488 MockConstraintFactory constraint_factory;
485 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 489 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
486 new WebRtcAudioDeviceImpl()); 490 new WebRtcAudioDeviceImpl());
487 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 491 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
488 new rtc::RefCountedObject<MediaStreamAudioProcessor>( 492 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
489 constraint_factory.CreateWebMediaConstraints(), input_device_params_, 493 constraint_factory.CreateWebMediaConstraints(), input_device_params_,
490 webrtc_audio_device.get())); 494 webrtc_audio_device.get()));
491 495
492 EXPECT_TRUE(audio_processor->aec_dump_message_filter_.get()); 496 EXPECT_TRUE(audio_processor->aec_dump_message_filter_.get());
493 497
494 audio_processor = NULL; 498 // Stop |audio_processor| so that it removes itself from
499 // |webrtc_audio_device| and clears its pointer to it.
500 audio_processor->Stop();
495 } 501 }
496 502
497 TEST_F(MediaStreamAudioProcessorTest, TestStereoAudio) { 503 TEST_F(MediaStreamAudioProcessorTest, TestStereoAudio) {
498 // Set up the correct constraints to turn off the audio processing and turn 504 // Set up the correct constraints to turn off the audio processing and turn
499 // on the stereo channels mirroring. 505 // on the stereo channels mirroring.
500 MockConstraintFactory constraint_factory; 506 MockConstraintFactory constraint_factory;
501 constraint_factory.basic().echoCancellation.setExact(false); 507 constraint_factory.basic().echoCancellation.setExact(false);
502 constraint_factory.basic().googAudioMirroring.setExact(true); 508 constraint_factory.basic().googAudioMirroring.setExact(true);
503 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 509 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
504 new WebRtcAudioDeviceImpl()); 510 new WebRtcAudioDeviceImpl());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 base::TimeDelta capture_delay; 548 base::TimeDelta capture_delay;
543 int new_volume = 0; 549 int new_volume = 0;
544 EXPECT_TRUE(audio_processor->ProcessAndConsumeData( 550 EXPECT_TRUE(audio_processor->ProcessAndConsumeData(
545 0, false, &processed_data, &capture_delay, &new_volume)); 551 0, false, &processed_data, &capture_delay, &new_volume));
546 EXPECT_TRUE(processed_data); 552 EXPECT_TRUE(processed_data);
547 EXPECT_EQ(processed_data->channel(0)[0], 0); 553 EXPECT_EQ(processed_data->channel(0)[0], 0);
548 EXPECT_NE(processed_data->channel(1)[0], 0); 554 EXPECT_NE(processed_data->channel(1)[0], 0);
549 EXPECT_EQ(pushed_capture_delay, capture_delay); 555 EXPECT_EQ(pushed_capture_delay, capture_delay);
550 } 556 }
551 557
552 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives 558 // Stop |audio_processor| so that it removes itself from
553 // |audio_processor|. 559 // |webrtc_audio_device| and clears its pointer to it.
554 audio_processor = NULL; 560 audio_processor->Stop();
555 } 561 }
556 562
557 // Disabled on android clang builds due to crbug.com/470499 563 // Disabled on android clang builds due to crbug.com/470499
558 #if defined(__clang__) && defined(OS_ANDROID) 564 #if defined(__clang__) && defined(OS_ANDROID)
559 #define MAYBE_TestWithKeyboardMicChannel DISABLED_TestWithKeyboardMicChannel 565 #define MAYBE_TestWithKeyboardMicChannel DISABLED_TestWithKeyboardMicChannel
560 #else 566 #else
561 #define MAYBE_TestWithKeyboardMicChannel TestWithKeyboardMicChannel 567 #define MAYBE_TestWithKeyboardMicChannel TestWithKeyboardMicChannel
562 #endif 568 #endif
563
564 TEST_F(MediaStreamAudioProcessorTest, MAYBE_TestWithKeyboardMicChannel) { 569 TEST_F(MediaStreamAudioProcessorTest, MAYBE_TestWithKeyboardMicChannel) {
570 base::MessageLoop message_loop;
565 MockConstraintFactory constraint_factory; 571 MockConstraintFactory constraint_factory;
566 constraint_factory.basic().googExperimentalNoiseSuppression.setExact(true); 572 constraint_factory.basic().googExperimentalNoiseSuppression.setExact(true);
567 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 573 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
568 new WebRtcAudioDeviceImpl()); 574 new WebRtcAudioDeviceImpl());
569 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 575 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
570 new rtc::RefCountedObject<MediaStreamAudioProcessor>( 576 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
571 constraint_factory.CreateWebMediaConstraints(), input_device_params_, 577 constraint_factory.CreateWebMediaConstraints(), input_device_params_,
572 webrtc_audio_device.get())); 578 webrtc_audio_device.get()));
573 EXPECT_TRUE(audio_processor->has_audio_processing()); 579 EXPECT_TRUE(audio_processor->has_audio_processing());
574 580
575 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 581 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
576 media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC, 582 media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC,
577 48000, 16, 512); 583 48000, 16, 512);
578 audio_processor->OnCaptureFormatChanged(params); 584 audio_processor->OnCaptureFormatChanged(params);
579 585
580 ProcessDataAndVerifyFormat(audio_processor.get(), 586 ProcessDataAndVerifyFormat(audio_processor.get(),
581 kAudioProcessingSampleRate, 587 kAudioProcessingSampleRate,
582 kAudioProcessingNumberOfChannel, 588 kAudioProcessingNumberOfChannel,
583 kAudioProcessingSampleRate / 100); 589 kAudioProcessingSampleRate / 100);
584 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives 590
585 // |audio_processor|. 591 // Stop |audio_processor| so that it removes itself from
586 audio_processor = NULL; 592 // |webrtc_audio_device| and clears its pointer to it.
593 audio_processor->Stop();
587 } 594 }
588 595
589 } // namespace content 596 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_audio_processor_options.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698