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

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

Issue 2425353002: Data race fix: Replace use of MessageLoop raw pointer in MSAudioProcessor. (Closed)
Patch Set: Fix unit tests: They all need a MessageLoop instantiated. Created 4 years, 2 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/path_service.h" 16 #include "base/path_service.h"
17 #include "base/threading/thread_task_runner_handle.h"
16 #include "base/time/time.h" 18 #include "base/time/time.h"
17 #include "build/build_config.h" 19 #include "build/build_config.h"
18 #include "content/common/media/media_stream_options.h" 20 #include "content/common/media/media_stream_options.h"
19 #include "content/public/common/media_stream_request.h" 21 #include "content/public/common/media_stream_request.h"
20 #include "content/renderer/media/media_stream_audio_processor.h" 22 #include "content/renderer/media/media_stream_audio_processor.h"
21 #include "content/renderer/media/media_stream_audio_processor_options.h" 23 #include "content/renderer/media/media_stream_audio_processor_options.h"
22 #include "content/renderer/media/mock_constraint_factory.h" 24 #include "content/renderer/media/mock_constraint_factory.h"
23 #include "media/base/audio_bus.h" 25 #include "media/base/audio_bus.h"
24 #include "media/base/audio_parameters.h" 26 #include "media/base/audio_parameters.h"
25 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 EXPECT_FALSE(audio_processing->voice_detection()->is_enabled()); 192 EXPECT_FALSE(audio_processing->voice_detection()->is_enabled());
191 #else 193 #else
192 EXPECT_TRUE(audio_processing->gain_control()->mode() == 194 EXPECT_TRUE(audio_processing->gain_control()->mode() ==
193 webrtc::GainControl::kAdaptiveAnalog); 195 webrtc::GainControl::kAdaptiveAnalog);
194 EXPECT_TRUE(audio_processing->voice_detection()->is_enabled()); 196 EXPECT_TRUE(audio_processing->voice_detection()->is_enabled());
195 EXPECT_TRUE(audio_processing->voice_detection()->likelihood() == 197 EXPECT_TRUE(audio_processing->voice_detection()->likelihood() ==
196 webrtc::VoiceDetection::kVeryLowLikelihood); 198 webrtc::VoiceDetection::kVeryLowLikelihood);
197 #endif 199 #endif
198 } 200 }
199 201
202 base::MessageLoop main_thread_message_loop_;
200 media::AudioParameters params_; 203 media::AudioParameters params_;
201 MediaStreamDevice::AudioDeviceParameters input_device_params_; 204 MediaStreamDevice::AudioDeviceParameters input_device_params_;
202 }; 205 };
203 206
204 // Test crashing with ASAN on Android. crbug.com/468762 207 // Test crashing with ASAN on Android. crbug.com/468762
205 #if defined(OS_ANDROID) && defined(ADDRESS_SANITIZER) 208 #if defined(OS_ANDROID) && defined(ADDRESS_SANITIZER)
206 #define MAYBE_WithAudioProcessing DISABLED_WithAudioProcessing 209 #define MAYBE_WithAudioProcessing DISABLED_WithAudioProcessing
207 #else 210 #else
208 #define MAYBE_WithAudioProcessing WithAudioProcessing 211 #define MAYBE_WithAudioProcessing WithAudioProcessing
209 #endif 212 #endif
210 TEST_F(MediaStreamAudioProcessorTest, MAYBE_WithAudioProcessing) { 213 TEST_F(MediaStreamAudioProcessorTest, MAYBE_WithAudioProcessing) {
211 base::MessageLoop message_loop;
212 MockConstraintFactory constraint_factory; 214 MockConstraintFactory constraint_factory;
213 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 215 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
214 new WebRtcAudioDeviceImpl()); 216 new WebRtcAudioDeviceImpl());
215 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 217 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
216 new rtc::RefCountedObject<MediaStreamAudioProcessor>( 218 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
217 constraint_factory.CreateWebMediaConstraints(), input_device_params_, 219 constraint_factory.CreateWebMediaConstraints(), input_device_params_,
218 webrtc_audio_device.get())); 220 webrtc_audio_device.get()));
219 EXPECT_TRUE(audio_processor->has_audio_processing()); 221 EXPECT_TRUE(audio_processor->has_audio_processing());
220 audio_processor->OnCaptureFormatChanged(params_); 222 audio_processor->OnCaptureFormatChanged(params_);
221 VerifyDefaultComponents(audio_processor.get()); 223 VerifyDefaultComponents(audio_processor.get());
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 } 438 }
437 } 439 }
438 440
439 // Test crashing with ASAN on Android. crbug.com/468762 441 // Test crashing with ASAN on Android. crbug.com/468762
440 #if defined(OS_ANDROID) && defined(ADDRESS_SANITIZER) 442 #if defined(OS_ANDROID) && defined(ADDRESS_SANITIZER)
441 #define MAYBE_TestAllSampleRates DISABLED_TestAllSampleRates 443 #define MAYBE_TestAllSampleRates DISABLED_TestAllSampleRates
442 #else 444 #else
443 #define MAYBE_TestAllSampleRates TestAllSampleRates 445 #define MAYBE_TestAllSampleRates TestAllSampleRates
444 #endif 446 #endif
445 TEST_F(MediaStreamAudioProcessorTest, MAYBE_TestAllSampleRates) { 447 TEST_F(MediaStreamAudioProcessorTest, MAYBE_TestAllSampleRates) {
446 base::MessageLoop message_loop;
447 MockConstraintFactory constraint_factory; 448 MockConstraintFactory constraint_factory;
448 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 449 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
449 new WebRtcAudioDeviceImpl()); 450 new WebRtcAudioDeviceImpl());
450 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 451 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
451 new rtc::RefCountedObject<MediaStreamAudioProcessor>( 452 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
452 constraint_factory.CreateWebMediaConstraints(), input_device_params_, 453 constraint_factory.CreateWebMediaConstraints(), input_device_params_,
453 webrtc_audio_device.get())); 454 webrtc_audio_device.get()));
454 EXPECT_TRUE(audio_processor->has_audio_processing()); 455 EXPECT_TRUE(audio_processor->has_audio_processing());
455 456
456 static const int kSupportedSampleRates[] = 457 static const int kSupportedSampleRates[] =
(...skipping 16 matching lines...) Expand all
473 474
474 // Stop |audio_processor| so that it removes itself from 475 // Stop |audio_processor| so that it removes itself from
475 // |webrtc_audio_device| and clears its pointer to it. 476 // |webrtc_audio_device| and clears its pointer to it.
476 audio_processor->Stop(); 477 audio_processor->Stop();
477 } 478 }
478 479
479 // 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
480 // 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
481 // filter will be created. 482 // filter will be created.
482 TEST_F(MediaStreamAudioProcessorTest, GetAecDumpMessageFilter) { 483 TEST_F(MediaStreamAudioProcessorTest, GetAecDumpMessageFilter) {
483 base::MessageLoopForUI message_loop;
484 scoped_refptr<AecDumpMessageFilter> aec_dump_message_filter_( 484 scoped_refptr<AecDumpMessageFilter> aec_dump_message_filter_(
485 new AecDumpMessageFilter(message_loop.task_runner(), 485 new AecDumpMessageFilter(base::ThreadTaskRunnerHandle::Get(),
486 message_loop.task_runner())); 486 base::ThreadTaskRunnerHandle::Get()));
487 487
488 MockConstraintFactory constraint_factory; 488 MockConstraintFactory constraint_factory;
489 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 489 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
490 new WebRtcAudioDeviceImpl()); 490 new WebRtcAudioDeviceImpl());
491 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 491 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
492 new rtc::RefCountedObject<MediaStreamAudioProcessor>( 492 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
493 constraint_factory.CreateWebMediaConstraints(), input_device_params_, 493 constraint_factory.CreateWebMediaConstraints(), input_device_params_,
494 webrtc_audio_device.get())); 494 webrtc_audio_device.get()));
495 495
496 EXPECT_TRUE(audio_processor->aec_dump_message_filter_.get()); 496 EXPECT_TRUE(audio_processor->aec_dump_message_filter_.get());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 audio_processor->Stop(); 560 audio_processor->Stop();
561 } 561 }
562 562
563 // Disabled on android clang builds due to crbug.com/470499 563 // Disabled on android clang builds due to crbug.com/470499
564 #if defined(__clang__) && defined(OS_ANDROID) 564 #if defined(__clang__) && defined(OS_ANDROID)
565 #define MAYBE_TestWithKeyboardMicChannel DISABLED_TestWithKeyboardMicChannel 565 #define MAYBE_TestWithKeyboardMicChannel DISABLED_TestWithKeyboardMicChannel
566 #else 566 #else
567 #define MAYBE_TestWithKeyboardMicChannel TestWithKeyboardMicChannel 567 #define MAYBE_TestWithKeyboardMicChannel TestWithKeyboardMicChannel
568 #endif 568 #endif
569 TEST_F(MediaStreamAudioProcessorTest, MAYBE_TestWithKeyboardMicChannel) { 569 TEST_F(MediaStreamAudioProcessorTest, MAYBE_TestWithKeyboardMicChannel) {
570 base::MessageLoop message_loop;
571 MockConstraintFactory constraint_factory; 570 MockConstraintFactory constraint_factory;
572 constraint_factory.basic().googExperimentalNoiseSuppression.setExact(true); 571 constraint_factory.basic().googExperimentalNoiseSuppression.setExact(true);
573 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 572 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
574 new WebRtcAudioDeviceImpl()); 573 new WebRtcAudioDeviceImpl());
575 scoped_refptr<MediaStreamAudioProcessor> audio_processor( 574 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
576 new rtc::RefCountedObject<MediaStreamAudioProcessor>( 575 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
577 constraint_factory.CreateWebMediaConstraints(), input_device_params_, 576 constraint_factory.CreateWebMediaConstraints(), input_device_params_,
578 webrtc_audio_device.get())); 577 webrtc_audio_device.get()));
579 EXPECT_TRUE(audio_processor->has_audio_processing()); 578 EXPECT_TRUE(audio_processor->has_audio_processing());
580 579
581 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 580 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
582 media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC, 581 media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC,
583 48000, 16, 512); 582 48000, 16, 512);
584 audio_processor->OnCaptureFormatChanged(params); 583 audio_processor->OnCaptureFormatChanged(params);
585 584
586 ProcessDataAndVerifyFormat(audio_processor.get(), 585 ProcessDataAndVerifyFormat(audio_processor.get(),
587 kAudioProcessingSampleRate, 586 kAudioProcessingSampleRate,
588 kAudioProcessingNumberOfChannel, 587 kAudioProcessingNumberOfChannel,
589 kAudioProcessingSampleRate / 100); 588 kAudioProcessingSampleRate / 100);
590 589
591 // Stop |audio_processor| so that it removes itself from 590 // Stop |audio_processor| so that it removes itself from
592 // |webrtc_audio_device| and clears its pointer to it. 591 // |webrtc_audio_device| and clears its pointer to it.
593 audio_processor->Stop(); 592 audio_processor->Stop();
594 } 593 }
595 594
596 } // namespace content 595 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698