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.
7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h"
9 #include "base/logging.h"
10 #include "base/memory/aligned_memory.h"
11 #include "base/path_service.h"
12 #include "base/time/time.h"
13 #include "content/public/common/media_stream_request.h"
14 #include "content/renderer/media/media_stream_audio_processor.h"
15 #include "content/renderer/media/media_stream_audio_processor_options.h"
16 #include "content/renderer/media/mock_media_constraint_factory.h"
17 #include "media/audio/audio_parameters.h"
18 #include "media/base/audio_bus.h"
19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
22 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h"
25 using ::testing::AnyNumber
;
26 using ::testing::AtLeast
;
27 using ::testing::Return
;
34 const int kAudioProcessingSampleRate
= 16000;
36 const int kAudioProcessingSampleRate
= 48000;
38 const int kAudioProcessingNumberOfChannel
= 1;
40 // The number of packers used for testing.
41 const int kNumberOfPacketsForTest
= 100;
43 const int kMaxNumberOfPlayoutDataChannels
= 2;
45 void ReadDataFromSpeechFile(char* data
, int length
) {
47 CHECK(PathService::Get(base::DIR_SOURCE_ROOT
, &file
));
48 file
= file
.Append(FILE_PATH_LITERAL("media"))
49 .Append(FILE_PATH_LITERAL("test"))
50 .Append(FILE_PATH_LITERAL("data"))
51 .Append(FILE_PATH_LITERAL("speech_16b_stereo_48kHz.raw"));
52 DCHECK(base::PathExists(file
));
53 int64 data_file_size64
= 0;
54 DCHECK(base::GetFileSize(file
, &data_file_size64
));
55 EXPECT_EQ(length
, base::ReadFile(file
, data
, length
));
56 DCHECK(data_file_size64
> length
);
61 class MediaStreamAudioProcessorTest
: public ::testing::Test
{
63 MediaStreamAudioProcessorTest()
64 : params_(media::AudioParameters::AUDIO_PCM_LOW_LATENCY
,
65 media::CHANNEL_LAYOUT_STEREO
, 48000, 16, 512) {
69 // Helper method to save duplicated code.
70 void ProcessDataAndVerifyFormat(MediaStreamAudioProcessor
* audio_processor
,
71 int expected_output_sample_rate
,
72 int expected_output_channels
,
73 int expected_output_buffer_size
) {
74 // Read the audio data from a file.
75 const media::AudioParameters
& params
= audio_processor
->InputFormat();
76 const int packet_size
=
77 params
.frames_per_buffer() * 2 * params
.channels();
78 const size_t length
= packet_size
* kNumberOfPacketsForTest
;
79 scoped_ptr
<char[]> capture_data(new char[length
]);
80 ReadDataFromSpeechFile(capture_data
.get(), length
);
81 const int16
* data_ptr
= reinterpret_cast<const int16
*>(capture_data
.get());
82 scoped_ptr
<media::AudioBus
> data_bus
= media::AudioBus::Create(
83 params
.channels(), params
.frames_per_buffer());
85 // |data_bus_playout| is used if the number of capture channels is larger
86 // that max allowed playout channels. |data_bus_playout_to_use| points to
87 // the AudioBus to use, either |data_bus| or |data_bus_playout|.
88 scoped_ptr
<media::AudioBus
> data_bus_playout
;
89 media::AudioBus
* data_bus_playout_to_use
= data_bus
.get();
90 if (params
.channels() > kMaxNumberOfPlayoutDataChannels
) {
92 media::AudioBus::CreateWrapper(kMaxNumberOfPlayoutDataChannels
);
93 data_bus_playout
->set_frames(params
.frames_per_buffer());
94 data_bus_playout_to_use
= data_bus_playout
.get();
97 const base::TimeDelta input_capture_delay
=
98 base::TimeDelta::FromMilliseconds(20);
99 const base::TimeDelta output_buffer_duration
=
100 expected_output_buffer_size
* base::TimeDelta::FromSeconds(1) /
101 expected_output_sample_rate
;
102 for (int i
= 0; i
< kNumberOfPacketsForTest
; ++i
) {
103 data_bus
->FromInterleaved(data_ptr
, data_bus
->frames(), 2);
104 audio_processor
->PushCaptureData(*data_bus
, input_capture_delay
);
106 // |audio_processor| does nothing when the audio processing is off in
108 webrtc::AudioProcessing
* ap
= audio_processor
->audio_processing_
.get();
109 #if defined(OS_ANDROID) || defined(OS_IOS)
110 const bool is_aec_enabled
= ap
&& ap
->echo_control_mobile()->is_enabled();
111 // AEC should be turned off for mobiles.
112 DCHECK(!ap
|| !ap
->echo_cancellation()->is_enabled());
114 const bool is_aec_enabled
= ap
&& ap
->echo_cancellation()->is_enabled();
116 if (is_aec_enabled
) {
117 if (params
.channels() > kMaxNumberOfPlayoutDataChannels
) {
118 for (int i
= 0; i
< kMaxNumberOfPlayoutDataChannels
; ++i
) {
119 data_bus_playout
->SetChannelData(
120 i
, const_cast<float*>(data_bus
->channel(i
)));
123 audio_processor
->OnPlayoutData(data_bus_playout_to_use
,
124 params
.sample_rate(), 10);
127 media::AudioBus
* processed_data
= nullptr;
128 base::TimeDelta capture_delay
;
130 while (audio_processor
->ProcessAndConsumeData(
131 255, false, &processed_data
, &capture_delay
, &new_volume
)) {
132 EXPECT_TRUE(processed_data
);
133 EXPECT_NEAR(input_capture_delay
.InMillisecondsF(),
134 capture_delay
.InMillisecondsF(),
135 output_buffer_duration
.InMillisecondsF());
136 EXPECT_EQ(audio_processor
->OutputFormat().sample_rate(),
137 expected_output_sample_rate
);
138 EXPECT_EQ(audio_processor
->OutputFormat().channels(),
139 expected_output_channels
);
140 EXPECT_EQ(audio_processor
->OutputFormat().frames_per_buffer(),
141 expected_output_buffer_size
);
144 data_ptr
+= params
.frames_per_buffer() * params
.channels();
148 void VerifyDefaultComponents(MediaStreamAudioProcessor
* audio_processor
) {
149 webrtc::AudioProcessing
* audio_processing
=
150 audio_processor
->audio_processing_
.get();
151 #if defined(OS_ANDROID)
152 EXPECT_TRUE(audio_processing
->echo_control_mobile()->is_enabled());
153 EXPECT_TRUE(audio_processing
->echo_control_mobile()->routing_mode() ==
154 webrtc::EchoControlMobile::kSpeakerphone
);
155 EXPECT_FALSE(audio_processing
->echo_cancellation()->is_enabled());
156 #elif !defined(OS_IOS)
157 EXPECT_TRUE(audio_processing
->echo_cancellation()->is_enabled());
158 EXPECT_TRUE(audio_processing
->echo_cancellation()->suppression_level() ==
159 webrtc::EchoCancellation::kHighSuppression
);
160 EXPECT_TRUE(audio_processing
->echo_cancellation()->are_metrics_enabled());
162 audio_processing
->echo_cancellation()->is_delay_logging_enabled());
165 EXPECT_TRUE(audio_processing
->noise_suppression()->is_enabled());
166 EXPECT_TRUE(audio_processing
->noise_suppression()->level() ==
167 webrtc::NoiseSuppression::kHigh
);
168 EXPECT_TRUE(audio_processing
->high_pass_filter()->is_enabled());
169 EXPECT_TRUE(audio_processing
->gain_control()->is_enabled());
170 #if defined(OS_ANDROID) || defined(OS_IOS)
171 EXPECT_TRUE(audio_processing
->gain_control()->mode() ==
172 webrtc::GainControl::kFixedDigital
);
173 EXPECT_FALSE(audio_processing
->voice_detection()->is_enabled());
175 EXPECT_TRUE(audio_processing
->gain_control()->mode() ==
176 webrtc::GainControl::kAdaptiveAnalog
);
177 EXPECT_TRUE(audio_processing
->voice_detection()->is_enabled());
178 EXPECT_TRUE(audio_processing
->voice_detection()->likelihood() ==
179 webrtc::VoiceDetection::kVeryLowLikelihood
);
183 media::AudioParameters params_
;
186 // Test crashing with ASAN on Android. crbug.com/468762
187 #if defined(OS_ANDROID) && defined(ADDRESS_SANITIZER)
188 #define MAYBE_WithAudioProcessing DISABLED_WithAudioProcessing
190 #define MAYBE_WithAudioProcessing WithAudioProcessing
192 TEST_F(MediaStreamAudioProcessorTest
, MAYBE_WithAudioProcessing
) {
193 MockMediaConstraintFactory constraint_factory
;
194 scoped_refptr
<WebRtcAudioDeviceImpl
> webrtc_audio_device(
195 new WebRtcAudioDeviceImpl());
196 scoped_refptr
<MediaStreamAudioProcessor
> audio_processor(
197 new rtc::RefCountedObject
<MediaStreamAudioProcessor
>(
198 constraint_factory
.CreateWebMediaConstraints(), 0,
199 webrtc_audio_device
.get()));
200 EXPECT_TRUE(audio_processor
->has_audio_processing());
201 audio_processor
->OnCaptureFormatChanged(params_
);
202 VerifyDefaultComponents(audio_processor
.get());
204 ProcessDataAndVerifyFormat(audio_processor
.get(),
205 kAudioProcessingSampleRate
,
206 kAudioProcessingNumberOfChannel
,
207 kAudioProcessingSampleRate
/ 100);
208 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives
209 // |audio_processor|.
210 audio_processor
= NULL
;
213 TEST_F(MediaStreamAudioProcessorTest
, VerifyTabCaptureWithoutAudioProcessing
) {
214 scoped_refptr
<WebRtcAudioDeviceImpl
> webrtc_audio_device(
215 new WebRtcAudioDeviceImpl());
216 // Create MediaStreamAudioProcessor instance for kMediaStreamSourceTab source.
217 MockMediaConstraintFactory tab_constraint_factory
;
218 const std::string tab_string
= kMediaStreamSourceTab
;
219 tab_constraint_factory
.AddMandatory(kMediaStreamSource
,
221 scoped_refptr
<MediaStreamAudioProcessor
> audio_processor(
222 new rtc::RefCountedObject
<MediaStreamAudioProcessor
>(
223 tab_constraint_factory
.CreateWebMediaConstraints(), 0,
224 webrtc_audio_device
.get()));
225 EXPECT_FALSE(audio_processor
->has_audio_processing());
226 audio_processor
->OnCaptureFormatChanged(params_
);
228 ProcessDataAndVerifyFormat(audio_processor
.get(),
229 params_
.sample_rate(),
231 params_
.sample_rate() / 100);
233 // Create MediaStreamAudioProcessor instance for kMediaStreamSourceSystem
235 MockMediaConstraintFactory system_constraint_factory
;
236 const std::string system_string
= kMediaStreamSourceSystem
;
237 system_constraint_factory
.AddMandatory(kMediaStreamSource
,
239 audio_processor
= new rtc::RefCountedObject
<MediaStreamAudioProcessor
>(
240 system_constraint_factory
.CreateWebMediaConstraints(), 0,
241 webrtc_audio_device
.get());
242 EXPECT_FALSE(audio_processor
->has_audio_processing());
244 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives
245 // |audio_processor|.
246 audio_processor
= NULL
;
249 TEST_F(MediaStreamAudioProcessorTest
, TurnOffDefaultConstraints
) {
250 // Turn off the default constraints and pass it to MediaStreamAudioProcessor.
251 MockMediaConstraintFactory constraint_factory
;
252 constraint_factory
.DisableDefaultAudioConstraints();
253 scoped_refptr
<WebRtcAudioDeviceImpl
> webrtc_audio_device(
254 new WebRtcAudioDeviceImpl());
255 scoped_refptr
<MediaStreamAudioProcessor
> audio_processor(
256 new rtc::RefCountedObject
<MediaStreamAudioProcessor
>(
257 constraint_factory
.CreateWebMediaConstraints(), 0,
258 webrtc_audio_device
.get()));
259 EXPECT_FALSE(audio_processor
->has_audio_processing());
260 audio_processor
->OnCaptureFormatChanged(params_
);
262 ProcessDataAndVerifyFormat(audio_processor
.get(),
263 params_
.sample_rate(),
265 params_
.sample_rate() / 100);
266 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives
267 // |audio_processor|.
268 audio_processor
= NULL
;
271 TEST_F(MediaStreamAudioProcessorTest
, VerifyConstraints
) {
272 static const char* kDefaultAudioConstraints
[] = {
273 MediaAudioConstraints::kEchoCancellation
,
274 MediaAudioConstraints::kGoogAudioMirroring
,
275 MediaAudioConstraints::kGoogAutoGainControl
,
276 MediaAudioConstraints::kGoogEchoCancellation
,
277 MediaAudioConstraints::kGoogExperimentalEchoCancellation
,
278 MediaAudioConstraints::kGoogExperimentalAutoGainControl
,
279 MediaAudioConstraints::kGoogExperimentalNoiseSuppression
,
280 MediaAudioConstraints::kGoogHighpassFilter
,
281 MediaAudioConstraints::kGoogNoiseSuppression
,
282 MediaAudioConstraints::kGoogTypingNoiseDetection
,
283 kMediaStreamAudioHotword
286 // Verify mandatory constraints.
287 for (size_t i
= 0; i
< arraysize(kDefaultAudioConstraints
); ++i
) {
288 MockMediaConstraintFactory constraint_factory
;
289 constraint_factory
.AddMandatory(kDefaultAudioConstraints
[i
], false);
290 blink::WebMediaConstraints constraints
=
291 constraint_factory
.CreateWebMediaConstraints();
292 MediaAudioConstraints
audio_constraints(constraints
, 0);
293 EXPECT_FALSE(audio_constraints
.GetProperty(kDefaultAudioConstraints
[i
]));
296 // Verify optional constraints.
297 for (size_t i
= 0; i
< arraysize(kDefaultAudioConstraints
); ++i
) {
298 MockMediaConstraintFactory constraint_factory
;
299 constraint_factory
.AddOptional(kDefaultAudioConstraints
[i
], false);
300 blink::WebMediaConstraints constraints
=
301 constraint_factory
.CreateWebMediaConstraints();
302 MediaAudioConstraints
audio_constraints(constraints
, 0);
303 EXPECT_FALSE(audio_constraints
.GetProperty(kDefaultAudioConstraints
[i
]));
307 // Verify echo cancellation is off when platform aec effect is on.
308 MockMediaConstraintFactory constraint_factory
;
309 MediaAudioConstraints
audio_constraints(
310 constraint_factory
.CreateWebMediaConstraints(),
311 media::AudioParameters::ECHO_CANCELLER
);
312 EXPECT_FALSE(audio_constraints
.GetEchoCancellationProperty());
316 // Verify |kEchoCancellation| overwrite |kGoogEchoCancellation|.
317 MockMediaConstraintFactory constraint_factory_1
;
318 constraint_factory_1
.AddOptional(MediaAudioConstraints::kEchoCancellation
,
320 constraint_factory_1
.AddOptional(
321 MediaAudioConstraints::kGoogEchoCancellation
, false);
322 blink::WebMediaConstraints constraints_1
=
323 constraint_factory_1
.CreateWebMediaConstraints();
324 MediaAudioConstraints
audio_constraints_1(constraints_1
, 0);
325 EXPECT_TRUE(audio_constraints_1
.GetEchoCancellationProperty());
327 MockMediaConstraintFactory constraint_factory_2
;
328 constraint_factory_2
.AddOptional(MediaAudioConstraints::kEchoCancellation
,
330 constraint_factory_2
.AddOptional(
331 MediaAudioConstraints::kGoogEchoCancellation
, true);
332 blink::WebMediaConstraints constraints_2
=
333 constraint_factory_2
.CreateWebMediaConstraints();
334 MediaAudioConstraints
audio_constraints_2(constraints_2
, 0);
335 EXPECT_FALSE(audio_constraints_2
.GetEchoCancellationProperty());
339 // When |kEchoCancellation| is explicitly set to false, the default values
340 // for all the constraints except |kMediaStreamAudioDucking| are false.
341 MockMediaConstraintFactory constraint_factory
;
342 constraint_factory
.AddOptional(MediaAudioConstraints::kEchoCancellation
,
344 blink::WebMediaConstraints constraints
=
345 constraint_factory
.CreateWebMediaConstraints();
346 MediaAudioConstraints
audio_constraints(constraints
, 0);
347 for (size_t i
= 0; i
< arraysize(kDefaultAudioConstraints
); ++i
) {
348 EXPECT_FALSE(audio_constraints
.GetProperty(kDefaultAudioConstraints
[i
]));
351 EXPECT_TRUE(audio_constraints
.GetProperty(kMediaStreamAudioDucking
));
353 EXPECT_FALSE(audio_constraints
.GetProperty(kMediaStreamAudioDucking
));
358 // |kMediaStreamAudioHotword| is always off by default.
359 MockMediaConstraintFactory constraint_factory
;
360 MediaAudioConstraints
audio_constraints(
361 constraint_factory
.CreateWebMediaConstraints(), 0);
362 EXPECT_FALSE(audio_constraints
.GetProperty(kMediaStreamAudioHotword
));
366 TEST_F(MediaStreamAudioProcessorTest
, ValidateConstraints
) {
367 MockMediaConstraintFactory constraint_factory
;
368 const std::string dummy_constraint
= "dummy";
369 constraint_factory
.AddMandatory(dummy_constraint
, true);
370 MediaAudioConstraints
audio_constraints(
371 constraint_factory
.CreateWebMediaConstraints(), 0);
372 EXPECT_FALSE(audio_constraints
.IsValid());
375 // Test crashing with ASAN on Android. crbug.com/468762
376 #if defined(OS_ANDROID) && defined(ADDRESS_SANITIZER)
377 #define MAYBE_TestAllSampleRates DISABLED_TestAllSampleRates
379 #define MAYBE_TestAllSampleRates TestAllSampleRates
381 TEST_F(MediaStreamAudioProcessorTest
, MAYBE_TestAllSampleRates
) {
382 MockMediaConstraintFactory constraint_factory
;
383 scoped_refptr
<WebRtcAudioDeviceImpl
> webrtc_audio_device(
384 new WebRtcAudioDeviceImpl());
385 scoped_refptr
<MediaStreamAudioProcessor
> audio_processor(
386 new rtc::RefCountedObject
<MediaStreamAudioProcessor
>(
387 constraint_factory
.CreateWebMediaConstraints(), 0,
388 webrtc_audio_device
.get()));
389 EXPECT_TRUE(audio_processor
->has_audio_processing());
391 static const int kSupportedSampleRates
[] =
392 { 8000, 16000, 22050, 32000, 44100, 48000, 88200, 96000 };
393 for (size_t i
= 0; i
< arraysize(kSupportedSampleRates
); ++i
) {
394 int buffer_size
= (kSupportedSampleRates
[i
] / 100) < 128 ?
395 kSupportedSampleRates
[i
] / 100 : 128;
396 media::AudioParameters
params(
397 media::AudioParameters::AUDIO_PCM_LOW_LATENCY
,
398 media::CHANNEL_LAYOUT_STEREO
, kSupportedSampleRates
[i
], 16,
400 audio_processor
->OnCaptureFormatChanged(params
);
401 VerifyDefaultComponents(audio_processor
.get());
403 ProcessDataAndVerifyFormat(audio_processor
.get(),
404 kAudioProcessingSampleRate
,
405 kAudioProcessingNumberOfChannel
,
406 kAudioProcessingSampleRate
/ 100);
409 // Set |audio_processor| to NULL to make sure |webrtc_audio_device|
410 // outlives |audio_processor|.
411 audio_processor
= NULL
;
414 // Test that if we have an AEC dump message filter created, we are getting it
415 // correctly in MSAP. Any IPC messages will be deleted since no sender in the
416 // filter will be created.
417 TEST_F(MediaStreamAudioProcessorTest
, GetAecDumpMessageFilter
) {
418 base::MessageLoopForUI message_loop
;
419 scoped_refptr
<AecDumpMessageFilter
> aec_dump_message_filter_(
420 new AecDumpMessageFilter(message_loop
.task_runner(),
421 message_loop
.task_runner()));
423 MockMediaConstraintFactory constraint_factory
;
424 scoped_refptr
<WebRtcAudioDeviceImpl
> webrtc_audio_device(
425 new WebRtcAudioDeviceImpl());
426 scoped_refptr
<MediaStreamAudioProcessor
> audio_processor(
427 new rtc::RefCountedObject
<MediaStreamAudioProcessor
>(
428 constraint_factory
.CreateWebMediaConstraints(), 0,
429 webrtc_audio_device
.get()));
431 EXPECT_TRUE(audio_processor
->aec_dump_message_filter_
.get());
433 audio_processor
= NULL
;
436 TEST_F(MediaStreamAudioProcessorTest
, TestStereoAudio
) {
437 // Set up the correct constraints to turn off the audio processing and turn
438 // on the stereo channels mirroring.
439 MockMediaConstraintFactory constraint_factory
;
440 constraint_factory
.AddMandatory(MediaAudioConstraints::kEchoCancellation
,
442 constraint_factory
.AddMandatory(MediaAudioConstraints::kGoogAudioMirroring
,
444 scoped_refptr
<WebRtcAudioDeviceImpl
> webrtc_audio_device(
445 new WebRtcAudioDeviceImpl());
446 scoped_refptr
<MediaStreamAudioProcessor
> audio_processor(
447 new rtc::RefCountedObject
<MediaStreamAudioProcessor
>(
448 constraint_factory
.CreateWebMediaConstraints(), 0,
449 webrtc_audio_device
.get()));
450 EXPECT_FALSE(audio_processor
->has_audio_processing());
451 const media::AudioParameters
source_params(
452 media::AudioParameters::AUDIO_PCM_LOW_LATENCY
,
453 media::CHANNEL_LAYOUT_STEREO
, 48000, 16, 480);
454 audio_processor
->OnCaptureFormatChanged(source_params
);
455 EXPECT_EQ(audio_processor
->OutputFormat().channels(), 2);
457 // Construct left and right channels, and assign different values to the
458 // first data of the left channel and right channel.
459 const int size
= media::AudioBus::CalculateMemorySize(source_params
);
460 scoped_ptr
<float, base::AlignedFreeDeleter
> left_channel(
461 static_cast<float*>(base::AlignedAlloc(size
, 32)));
462 scoped_ptr
<float, base::AlignedFreeDeleter
> right_channel(
463 static_cast<float*>(base::AlignedAlloc(size
, 32)));
464 scoped_ptr
<media::AudioBus
> wrapper
= media::AudioBus::CreateWrapper(
465 source_params
.channels());
466 wrapper
->set_frames(source_params
.frames_per_buffer());
467 wrapper
->SetChannelData(0, left_channel
.get());
468 wrapper
->SetChannelData(1, right_channel
.get());
470 float* left_channel_ptr
= left_channel
.get();
471 left_channel_ptr
[0] = 1.0f
;
473 // Run the test consecutively to make sure the stereo channels are not
474 // flipped back and forth.
475 static const int kNumberOfPacketsForTest
= 100;
476 const base::TimeDelta pushed_capture_delay
=
477 base::TimeDelta::FromMilliseconds(42);
478 for (int i
= 0; i
< kNumberOfPacketsForTest
; ++i
) {
479 audio_processor
->PushCaptureData(*wrapper
, pushed_capture_delay
);
481 media::AudioBus
* processed_data
= nullptr;
482 base::TimeDelta capture_delay
;
484 EXPECT_TRUE(audio_processor
->ProcessAndConsumeData(
485 0, false, &processed_data
, &capture_delay
, &new_volume
));
486 EXPECT_TRUE(processed_data
);
487 EXPECT_EQ(processed_data
->channel(0)[0], 0);
488 EXPECT_NE(processed_data
->channel(1)[0], 0);
489 EXPECT_EQ(pushed_capture_delay
, capture_delay
);
492 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives
493 // |audio_processor|.
494 audio_processor
= NULL
;
497 // Disabled on android clang builds due to crbug.com/470499
498 #if defined(__clang__) && defined(OS_ANDROID)
499 #define MAYBE_TestWithKeyboardMicChannel DISABLED_TestWithKeyboardMicChannel
501 #define MAYBE_TestWithKeyboardMicChannel TestWithKeyboardMicChannel
504 TEST_F(MediaStreamAudioProcessorTest
, MAYBE_TestWithKeyboardMicChannel
) {
505 MockMediaConstraintFactory constraint_factory
;
506 constraint_factory
.AddMandatory(
507 MediaAudioConstraints::kGoogExperimentalNoiseSuppression
, true);
508 scoped_refptr
<WebRtcAudioDeviceImpl
> webrtc_audio_device(
509 new WebRtcAudioDeviceImpl());
510 scoped_refptr
<MediaStreamAudioProcessor
> audio_processor(
511 new rtc::RefCountedObject
<MediaStreamAudioProcessor
>(
512 constraint_factory
.CreateWebMediaConstraints(), 0,
513 webrtc_audio_device
.get()));
514 EXPECT_TRUE(audio_processor
->has_audio_processing());
516 media::AudioParameters
params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY
,
517 media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC
,
519 audio_processor
->OnCaptureFormatChanged(params
);
521 ProcessDataAndVerifyFormat(audio_processor
.get(),
522 kAudioProcessingSampleRate
,
523 kAudioProcessingNumberOfChannel
,
524 kAudioProcessingSampleRate
/ 100);
525 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives
526 // |audio_processor|.
527 audio_processor
= NULL
;
530 using Point
= webrtc::Point
;
531 using PointVector
= std::vector
<Point
>;
533 void ExpectPointVectorEqual(const PointVector
& expected
,
534 const PointVector
& actual
) {
535 EXPECT_EQ(expected
.size(), actual
.size());
536 for (size_t i
= 0; i
< actual
.size(); ++i
) {
537 EXPECT_EQ(expected
[i
].x(), actual
[i
].x());
538 EXPECT_EQ(expected
[i
].y(), actual
[i
].y());
539 EXPECT_EQ(expected
[i
].z(), actual
[i
].z());
543 TEST(MediaStreamAudioProcessorOptionsTest
, ParseArrayGeometry
) {
544 const PointVector expected_empty
;
545 ExpectPointVectorEqual(expected_empty
, ParseArrayGeometry(""));
546 ExpectPointVectorEqual(expected_empty
, ParseArrayGeometry("0 0 a"));
547 ExpectPointVectorEqual(expected_empty
, ParseArrayGeometry("1 2"));
548 ExpectPointVectorEqual(expected_empty
, ParseArrayGeometry("1 2 3 4"));
551 PointVector
expected(1, Point(-0.02f
, 0, 0));
552 expected
.push_back(Point(0.02f
, 0, 0));
553 ExpectPointVectorEqual(expected
, ParseArrayGeometry("-0.02 0 0 0.02 0 0"));
556 PointVector
expected(1, Point(1, 2, 3));
557 ExpectPointVectorEqual(expected
, ParseArrayGeometry("1 2 3"));
561 } // namespace content