Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / renderer / media / media_stream_audio_processor_unittest.cc
bloba2f1b4e8729afd0f82b56ebdeaba0a5455be8309
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
3 // found in the LICENSE file.
5 #include "base/files/file_path.h"
6 #include "base/files/file_util.h"
7 #include "base/logging.h"
8 #include "base/memory/aligned_memory.h"
9 #include "base/path_service.h"
10 #include "base/time/time.h"
11 #include "content/public/common/media_stream_request.h"
12 #include "content/renderer/media/media_stream_audio_processor.h"
13 #include "content/renderer/media/media_stream_audio_processor_options.h"
14 #include "content/renderer/media/mock_media_constraint_factory.h"
15 #include "media/audio/audio_parameters.h"
16 #include "media/base/audio_bus.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
20 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h"
22 using ::testing::_;
23 using ::testing::AnyNumber;
24 using ::testing::AtLeast;
25 using ::testing::Return;
27 namespace content {
29 namespace {
31 #if defined(ANDROID)
32 const int kAudioProcessingSampleRate = 16000;
33 #else
34 const int kAudioProcessingSampleRate = 32000;
35 #endif
36 const int kAudioProcessingNumberOfChannel = 1;
38 // The number of packers used for testing.
39 const int kNumberOfPacketsForTest = 100;
41 const int kMaxNumberOfPlayoutDataChannels = 2;
43 void ReadDataFromSpeechFile(char* data, int length) {
44 base::FilePath file;
45 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &file));
46 file = file.Append(FILE_PATH_LITERAL("media"))
47 .Append(FILE_PATH_LITERAL("test"))
48 .Append(FILE_PATH_LITERAL("data"))
49 .Append(FILE_PATH_LITERAL("speech_16b_stereo_48kHz.raw"));
50 DCHECK(base::PathExists(file));
51 int64 data_file_size64 = 0;
52 DCHECK(base::GetFileSize(file, &data_file_size64));
53 EXPECT_EQ(length, base::ReadFile(file, data, length));
54 DCHECK(data_file_size64 > length);
57 } // namespace
59 class MediaStreamAudioProcessorTest : public ::testing::Test {
60 public:
61 MediaStreamAudioProcessorTest()
62 : params_(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
63 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 512) {
66 protected:
67 // Helper method to save duplicated code.
68 void ProcessDataAndVerifyFormat(MediaStreamAudioProcessor* audio_processor,
69 int expected_output_sample_rate,
70 int expected_output_channels,
71 int expected_output_buffer_size) {
72 // Read the audio data from a file.
73 const media::AudioParameters& params = audio_processor->InputFormat();
74 const int packet_size =
75 params.frames_per_buffer() * 2 * params.channels();
76 const size_t length = packet_size * kNumberOfPacketsForTest;
77 scoped_ptr<char[]> capture_data(new char[length]);
78 ReadDataFromSpeechFile(capture_data.get(), length);
79 const int16* data_ptr = reinterpret_cast<const int16*>(capture_data.get());
80 scoped_ptr<media::AudioBus> data_bus = media::AudioBus::Create(
81 params.channels(), params.frames_per_buffer());
83 // |data_bus_playout| is used if the number of capture channels is larger
84 // that max allowed playout channels. |data_bus_playout_to_use| points to
85 // the AudioBus to use, either |data_bus| or |data_bus_playout|.
86 scoped_ptr<media::AudioBus> data_bus_playout;
87 media::AudioBus* data_bus_playout_to_use = data_bus.get();
88 if (params.channels() > kMaxNumberOfPlayoutDataChannels) {
89 data_bus_playout =
90 media::AudioBus::CreateWrapper(kMaxNumberOfPlayoutDataChannels);
91 data_bus_playout->set_frames(params.frames_per_buffer());
92 data_bus_playout_to_use = data_bus_playout.get();
95 const base::TimeDelta input_capture_delay =
96 base::TimeDelta::FromMilliseconds(20);
97 const base::TimeDelta output_buffer_duration =
98 expected_output_buffer_size * base::TimeDelta::FromSeconds(1) /
99 expected_output_sample_rate;
100 for (int i = 0; i < kNumberOfPacketsForTest; ++i) {
101 data_bus->FromInterleaved(data_ptr, data_bus->frames(), 2);
102 audio_processor->PushCaptureData(*data_bus, input_capture_delay);
104 // |audio_processor| does nothing when the audio processing is off in
105 // the processor.
106 webrtc::AudioProcessing* ap = audio_processor->audio_processing_.get();
107 #if defined(OS_ANDROID) || defined(OS_IOS)
108 const bool is_aec_enabled = ap && ap->echo_control_mobile()->is_enabled();
109 // AEC should be turned off for mobiles.
110 DCHECK(!ap || !ap->echo_cancellation()->is_enabled());
111 #else
112 const bool is_aec_enabled = ap && ap->echo_cancellation()->is_enabled();
113 #endif
114 if (is_aec_enabled) {
115 if (params.channels() > kMaxNumberOfPlayoutDataChannels) {
116 for (int i = 0; i < kMaxNumberOfPlayoutDataChannels; ++i) {
117 data_bus_playout->SetChannelData(
118 i, const_cast<float*>(data_bus->channel(i)));
121 audio_processor->OnPlayoutData(data_bus_playout_to_use,
122 params.sample_rate(), 10);
125 media::AudioBus* processed_data = nullptr;
126 base::TimeDelta capture_delay;
127 int new_volume = 0;
128 while (audio_processor->ProcessAndConsumeData(
129 255, false, &processed_data, &capture_delay, &new_volume)) {
130 EXPECT_TRUE(processed_data);
131 EXPECT_NEAR(input_capture_delay.InMillisecondsF(),
132 capture_delay.InMillisecondsF(),
133 output_buffer_duration.InMillisecondsF());
134 EXPECT_EQ(audio_processor->OutputFormat().sample_rate(),
135 expected_output_sample_rate);
136 EXPECT_EQ(audio_processor->OutputFormat().channels(),
137 expected_output_channels);
138 EXPECT_EQ(audio_processor->OutputFormat().frames_per_buffer(),
139 expected_output_buffer_size);
142 data_ptr += params.frames_per_buffer() * params.channels();
146 void VerifyDefaultComponents(MediaStreamAudioProcessor* audio_processor) {
147 webrtc::AudioProcessing* audio_processing =
148 audio_processor->audio_processing_.get();
149 #if defined(OS_ANDROID)
150 EXPECT_TRUE(audio_processing->echo_control_mobile()->is_enabled());
151 EXPECT_TRUE(audio_processing->echo_control_mobile()->routing_mode() ==
152 webrtc::EchoControlMobile::kSpeakerphone);
153 EXPECT_FALSE(audio_processing->echo_cancellation()->is_enabled());
154 #elif !defined(OS_IOS)
155 EXPECT_TRUE(audio_processing->echo_cancellation()->is_enabled());
156 EXPECT_TRUE(audio_processing->echo_cancellation()->suppression_level() ==
157 webrtc::EchoCancellation::kHighSuppression);
158 EXPECT_TRUE(audio_processing->echo_cancellation()->are_metrics_enabled());
159 EXPECT_TRUE(
160 audio_processing->echo_cancellation()->is_delay_logging_enabled());
161 #endif
163 EXPECT_TRUE(audio_processing->noise_suppression()->is_enabled());
164 EXPECT_TRUE(audio_processing->noise_suppression()->level() ==
165 webrtc::NoiseSuppression::kHigh);
166 EXPECT_TRUE(audio_processing->high_pass_filter()->is_enabled());
167 EXPECT_TRUE(audio_processing->gain_control()->is_enabled());
168 #if defined(OS_ANDROID) || defined(OS_IOS)
169 EXPECT_TRUE(audio_processing->gain_control()->mode() ==
170 webrtc::GainControl::kFixedDigital);
171 EXPECT_FALSE(audio_processing->voice_detection()->is_enabled());
172 #else
173 EXPECT_TRUE(audio_processing->gain_control()->mode() ==
174 webrtc::GainControl::kAdaptiveAnalog);
175 EXPECT_TRUE(audio_processing->voice_detection()->is_enabled());
176 EXPECT_TRUE(audio_processing->voice_detection()->likelihood() ==
177 webrtc::VoiceDetection::kVeryLowLikelihood);
178 #endif
181 media::AudioParameters params_;
184 // Test crashing with ASAN on Android. crbug.com/468762
185 #if defined(OS_ANDROID) && defined(ADDRESS_SANITIZER)
186 #define MAYBE_WithAudioProcessing DISABLED_WithAudioProcessing
187 #else
188 #define MAYBE_WithAudioProcessing WithAudioProcessing
189 #endif
190 TEST_F(MediaStreamAudioProcessorTest, MAYBE_WithAudioProcessing) {
191 MockMediaConstraintFactory constraint_factory;
192 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
193 new WebRtcAudioDeviceImpl());
194 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
195 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
196 constraint_factory.CreateWebMediaConstraints(), 0,
197 webrtc_audio_device.get()));
198 EXPECT_TRUE(audio_processor->has_audio_processing());
199 audio_processor->OnCaptureFormatChanged(params_);
200 VerifyDefaultComponents(audio_processor.get());
202 ProcessDataAndVerifyFormat(audio_processor.get(),
203 kAudioProcessingSampleRate,
204 kAudioProcessingNumberOfChannel,
205 kAudioProcessingSampleRate / 100);
206 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives
207 // |audio_processor|.
208 audio_processor = NULL;
211 TEST_F(MediaStreamAudioProcessorTest, VerifyTabCaptureWithoutAudioProcessing) {
212 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
213 new WebRtcAudioDeviceImpl());
214 // Create MediaStreamAudioProcessor instance for kMediaStreamSourceTab source.
215 MockMediaConstraintFactory tab_constraint_factory;
216 const std::string tab_string = kMediaStreamSourceTab;
217 tab_constraint_factory.AddMandatory(kMediaStreamSource,
218 tab_string);
219 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
220 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
221 tab_constraint_factory.CreateWebMediaConstraints(), 0,
222 webrtc_audio_device.get()));
223 EXPECT_FALSE(audio_processor->has_audio_processing());
224 audio_processor->OnCaptureFormatChanged(params_);
226 ProcessDataAndVerifyFormat(audio_processor.get(),
227 params_.sample_rate(),
228 params_.channels(),
229 params_.sample_rate() / 100);
231 // Create MediaStreamAudioProcessor instance for kMediaStreamSourceSystem
232 // source.
233 MockMediaConstraintFactory system_constraint_factory;
234 const std::string system_string = kMediaStreamSourceSystem;
235 system_constraint_factory.AddMandatory(kMediaStreamSource,
236 system_string);
237 audio_processor = new rtc::RefCountedObject<MediaStreamAudioProcessor>(
238 system_constraint_factory.CreateWebMediaConstraints(), 0,
239 webrtc_audio_device.get());
240 EXPECT_FALSE(audio_processor->has_audio_processing());
242 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives
243 // |audio_processor|.
244 audio_processor = NULL;
247 TEST_F(MediaStreamAudioProcessorTest, TurnOffDefaultConstraints) {
248 // Turn off the default constraints and pass it to MediaStreamAudioProcessor.
249 MockMediaConstraintFactory constraint_factory;
250 constraint_factory.DisableDefaultAudioConstraints();
251 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
252 new WebRtcAudioDeviceImpl());
253 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
254 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
255 constraint_factory.CreateWebMediaConstraints(), 0,
256 webrtc_audio_device.get()));
257 EXPECT_FALSE(audio_processor->has_audio_processing());
258 audio_processor->OnCaptureFormatChanged(params_);
260 ProcessDataAndVerifyFormat(audio_processor.get(),
261 params_.sample_rate(),
262 params_.channels(),
263 params_.sample_rate() / 100);
264 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives
265 // |audio_processor|.
266 audio_processor = NULL;
269 TEST_F(MediaStreamAudioProcessorTest, VerifyConstraints) {
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 kMediaStreamAudioHotword
284 // Verify mandatory constraints.
285 for (size_t i = 0; i < arraysize(kDefaultAudioConstraints); ++i) {
286 MockMediaConstraintFactory constraint_factory;
287 constraint_factory.AddMandatory(kDefaultAudioConstraints[i], false);
288 blink::WebMediaConstraints constraints =
289 constraint_factory.CreateWebMediaConstraints();
290 MediaAudioConstraints audio_constraints(constraints, 0);
291 EXPECT_FALSE(audio_constraints.GetProperty(kDefaultAudioConstraints[i]));
294 // Verify optional constraints.
295 for (size_t i = 0; i < arraysize(kDefaultAudioConstraints); ++i) {
296 MockMediaConstraintFactory constraint_factory;
297 constraint_factory.AddOptional(kDefaultAudioConstraints[i], false);
298 blink::WebMediaConstraints constraints =
299 constraint_factory.CreateWebMediaConstraints();
300 MediaAudioConstraints audio_constraints(constraints, 0);
301 EXPECT_FALSE(audio_constraints.GetProperty(kDefaultAudioConstraints[i]));
305 // Verify echo cancellation is off when platform aec effect is on.
306 MockMediaConstraintFactory constraint_factory;
307 MediaAudioConstraints audio_constraints(
308 constraint_factory.CreateWebMediaConstraints(),
309 media::AudioParameters::ECHO_CANCELLER);
310 EXPECT_FALSE(audio_constraints.GetEchoCancellationProperty());
314 // Verify |kEchoCancellation| overwrite |kGoogEchoCancellation|.
315 MockMediaConstraintFactory constraint_factory_1;
316 constraint_factory_1.AddOptional(MediaAudioConstraints::kEchoCancellation,
317 true);
318 constraint_factory_1.AddOptional(
319 MediaAudioConstraints::kGoogEchoCancellation, false);
320 blink::WebMediaConstraints constraints_1 =
321 constraint_factory_1.CreateWebMediaConstraints();
322 MediaAudioConstraints audio_constraints_1(constraints_1, 0);
323 EXPECT_TRUE(audio_constraints_1.GetEchoCancellationProperty());
325 MockMediaConstraintFactory constraint_factory_2;
326 constraint_factory_2.AddOptional(MediaAudioConstraints::kEchoCancellation,
327 false);
328 constraint_factory_2.AddOptional(
329 MediaAudioConstraints::kGoogEchoCancellation, true);
330 blink::WebMediaConstraints constraints_2 =
331 constraint_factory_2.CreateWebMediaConstraints();
332 MediaAudioConstraints audio_constraints_2(constraints_2, 0);
333 EXPECT_FALSE(audio_constraints_2.GetEchoCancellationProperty());
337 // When |kEchoCancellation| is explicitly set to false, the default values
338 // for all the constraints except |kMediaStreamAudioDucking| are false.
339 MockMediaConstraintFactory constraint_factory;
340 constraint_factory.AddOptional(MediaAudioConstraints::kEchoCancellation,
341 false);
342 blink::WebMediaConstraints constraints =
343 constraint_factory.CreateWebMediaConstraints();
344 MediaAudioConstraints audio_constraints(constraints, 0);
345 for (size_t i = 0; i < arraysize(kDefaultAudioConstraints); ++i) {
346 EXPECT_FALSE(audio_constraints.GetProperty(kDefaultAudioConstraints[i]));
348 #if defined(OS_WIN)
349 EXPECT_TRUE(audio_constraints.GetProperty(kMediaStreamAudioDucking));
350 #else
351 EXPECT_FALSE(audio_constraints.GetProperty(kMediaStreamAudioDucking));
352 #endif
356 // |kMediaStreamAudioHotword| is always off by default.
357 MockMediaConstraintFactory constraint_factory;
358 MediaAudioConstraints audio_constraints(
359 constraint_factory.CreateWebMediaConstraints(), 0);
360 EXPECT_FALSE(audio_constraints.GetProperty(kMediaStreamAudioHotword));
364 TEST_F(MediaStreamAudioProcessorTest, ValidateConstraints) {
365 MockMediaConstraintFactory constraint_factory;
366 const std::string dummy_constraint = "dummy";
367 constraint_factory.AddMandatory(dummy_constraint, true);
368 MediaAudioConstraints audio_constraints(
369 constraint_factory.CreateWebMediaConstraints(), 0);
370 EXPECT_FALSE(audio_constraints.IsValid());
373 // Test crashing with ASAN on Android. crbug.com/468762
374 #if defined(OS_ANDROID) && defined(ADDRESS_SANITIZER)
375 #define MAYBE_TestAllSampleRates DISABLED_TestAllSampleRates
376 #else
377 #define MAYBE_TestAllSampleRates TestAllSampleRates
378 #endif
379 TEST_F(MediaStreamAudioProcessorTest, MAYBE_TestAllSampleRates) {
380 MockMediaConstraintFactory constraint_factory;
381 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
382 new WebRtcAudioDeviceImpl());
383 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
384 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
385 constraint_factory.CreateWebMediaConstraints(), 0,
386 webrtc_audio_device.get()));
387 EXPECT_TRUE(audio_processor->has_audio_processing());
389 static const int kSupportedSampleRates[] =
390 { 8000, 16000, 22050, 32000, 44100, 48000, 88200, 96000 };
391 for (size_t i = 0; i < arraysize(kSupportedSampleRates); ++i) {
392 int buffer_size = (kSupportedSampleRates[i] / 100) < 128 ?
393 kSupportedSampleRates[i] / 100 : 128;
394 media::AudioParameters params(
395 media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
396 media::CHANNEL_LAYOUT_STEREO, kSupportedSampleRates[i], 16,
397 buffer_size);
398 audio_processor->OnCaptureFormatChanged(params);
399 VerifyDefaultComponents(audio_processor.get());
401 ProcessDataAndVerifyFormat(audio_processor.get(),
402 kAudioProcessingSampleRate,
403 kAudioProcessingNumberOfChannel,
404 kAudioProcessingSampleRate / 100);
407 // Set |audio_processor| to NULL to make sure |webrtc_audio_device|
408 // outlives |audio_processor|.
409 audio_processor = NULL;
412 // Test that if we have an AEC dump message filter created, we are getting it
413 // correctly in MSAP. Any IPC messages will be deleted since no sender in the
414 // filter will be created.
415 TEST_F(MediaStreamAudioProcessorTest, GetAecDumpMessageFilter) {
416 base::MessageLoopForUI message_loop;
417 scoped_refptr<AecDumpMessageFilter> aec_dump_message_filter_(
418 new AecDumpMessageFilter(message_loop.message_loop_proxy(),
419 message_loop.message_loop_proxy()));
421 MockMediaConstraintFactory constraint_factory;
422 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
423 new WebRtcAudioDeviceImpl());
424 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
425 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
426 constraint_factory.CreateWebMediaConstraints(), 0,
427 webrtc_audio_device.get()));
429 EXPECT_TRUE(audio_processor->aec_dump_message_filter_.get());
431 audio_processor = NULL;
434 TEST_F(MediaStreamAudioProcessorTest, TestStereoAudio) {
435 // Set up the correct constraints to turn off the audio processing and turn
436 // on the stereo channels mirroring.
437 MockMediaConstraintFactory constraint_factory;
438 constraint_factory.AddMandatory(MediaAudioConstraints::kEchoCancellation,
439 false);
440 constraint_factory.AddMandatory(MediaAudioConstraints::kGoogAudioMirroring,
441 true);
442 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
443 new WebRtcAudioDeviceImpl());
444 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
445 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
446 constraint_factory.CreateWebMediaConstraints(), 0,
447 webrtc_audio_device.get()));
448 EXPECT_FALSE(audio_processor->has_audio_processing());
449 const media::AudioParameters source_params(
450 media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
451 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 480);
452 audio_processor->OnCaptureFormatChanged(source_params);
453 EXPECT_EQ(audio_processor->OutputFormat().channels(), 2);
455 // Construct left and right channels, and assign different values to the
456 // first data of the left channel and right channel.
457 const int size = media::AudioBus::CalculateMemorySize(source_params);
458 scoped_ptr<float, base::AlignedFreeDeleter> left_channel(
459 static_cast<float*>(base::AlignedAlloc(size, 32)));
460 scoped_ptr<float, base::AlignedFreeDeleter> right_channel(
461 static_cast<float*>(base::AlignedAlloc(size, 32)));
462 scoped_ptr<media::AudioBus> wrapper = media::AudioBus::CreateWrapper(
463 source_params.channels());
464 wrapper->set_frames(source_params.frames_per_buffer());
465 wrapper->SetChannelData(0, left_channel.get());
466 wrapper->SetChannelData(1, right_channel.get());
467 wrapper->Zero();
468 float* left_channel_ptr = left_channel.get();
469 left_channel_ptr[0] = 1.0f;
471 // Run the test consecutively to make sure the stereo channels are not
472 // flipped back and forth.
473 static const int kNumberOfPacketsForTest = 100;
474 const base::TimeDelta pushed_capture_delay =
475 base::TimeDelta::FromMilliseconds(42);
476 for (int i = 0; i < kNumberOfPacketsForTest; ++i) {
477 audio_processor->PushCaptureData(*wrapper, pushed_capture_delay);
479 media::AudioBus* processed_data = nullptr;
480 base::TimeDelta capture_delay;
481 int new_volume = 0;
482 EXPECT_TRUE(audio_processor->ProcessAndConsumeData(
483 0, false, &processed_data, &capture_delay, &new_volume));
484 EXPECT_TRUE(processed_data);
485 EXPECT_EQ(processed_data->channel(0)[0], 0);
486 EXPECT_NE(processed_data->channel(1)[0], 0);
487 EXPECT_EQ(pushed_capture_delay, capture_delay);
490 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives
491 // |audio_processor|.
492 audio_processor = NULL;
495 // Disabled on android clang builds due to crbug.com/470499
496 #if defined(__clang__) && defined(OS_ANDROID)
497 #define MAYBE_TestWithKeyboardMicChannel DISABLED_TestWithKeyboardMicChannel
498 #else
499 #define MAYBE_TestWithKeyboardMicChannel TestWithKeyboardMicChannel
500 #endif
502 TEST_F(MediaStreamAudioProcessorTest, MAYBE_TestWithKeyboardMicChannel) {
503 MockMediaConstraintFactory constraint_factory;
504 constraint_factory.AddMandatory(
505 MediaAudioConstraints::kGoogExperimentalNoiseSuppression, true);
506 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
507 new WebRtcAudioDeviceImpl());
508 scoped_refptr<MediaStreamAudioProcessor> audio_processor(
509 new rtc::RefCountedObject<MediaStreamAudioProcessor>(
510 constraint_factory.CreateWebMediaConstraints(), 0,
511 webrtc_audio_device.get()));
512 EXPECT_TRUE(audio_processor->has_audio_processing());
514 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
515 media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC,
516 48000, 16, 512);
517 audio_processor->OnCaptureFormatChanged(params);
519 ProcessDataAndVerifyFormat(audio_processor.get(),
520 kAudioProcessingSampleRate,
521 kAudioProcessingNumberOfChannel,
522 kAudioProcessingSampleRate / 100);
523 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives
524 // |audio_processor|.
525 audio_processor = NULL;
528 } // namespace content