OLD | NEW |
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 "base/command_line.h" | |
6 #include "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
7 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
8 #include "base/logging.h" | 7 #include "base/logging.h" |
9 #include "base/memory/aligned_memory.h" | 8 #include "base/memory/aligned_memory.h" |
10 #include "base/path_service.h" | 9 #include "base/path_service.h" |
11 #include "base/time/time.h" | 10 #include "base/time/time.h" |
12 #include "content/public/common/content_switches.h" | |
13 #include "content/public/common/media_stream_request.h" | 11 #include "content/public/common/media_stream_request.h" |
14 #include "content/renderer/media/media_stream_audio_processor.h" | 12 #include "content/renderer/media/media_stream_audio_processor.h" |
15 #include "content/renderer/media/media_stream_audio_processor_options.h" | 13 #include "content/renderer/media/media_stream_audio_processor_options.h" |
16 #include "content/renderer/media/mock_media_constraint_factory.h" | 14 #include "content/renderer/media/mock_media_constraint_factory.h" |
17 #include "media/audio/audio_parameters.h" | 15 #include "media/audio/audio_parameters.h" |
18 #include "media/base/audio_bus.h" | 16 #include "media/base/audio_bus.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 19 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
22 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" | 20 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 webrtc::GainControl::kAdaptiveAnalog); | 166 webrtc::GainControl::kAdaptiveAnalog); |
169 EXPECT_TRUE(audio_processing->voice_detection()->is_enabled()); | 167 EXPECT_TRUE(audio_processing->voice_detection()->is_enabled()); |
170 EXPECT_TRUE(audio_processing->voice_detection()->likelihood() == | 168 EXPECT_TRUE(audio_processing->voice_detection()->likelihood() == |
171 webrtc::VoiceDetection::kVeryLowLikelihood); | 169 webrtc::VoiceDetection::kVeryLowLikelihood); |
172 #endif | 170 #endif |
173 } | 171 } |
174 | 172 |
175 media::AudioParameters params_; | 173 media::AudioParameters params_; |
176 }; | 174 }; |
177 | 175 |
178 TEST_F(MediaStreamAudioProcessorTest, WithoutAudioProcessing) { | |
179 // Setup the audio processor with disabled flag on. | |
180 CommandLine::ForCurrentProcess()->AppendSwitch( | |
181 switches::kDisableAudioTrackProcessing); | |
182 MockMediaConstraintFactory constraint_factory; | |
183 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | |
184 new WebRtcAudioDeviceImpl()); | |
185 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | |
186 new rtc::RefCountedObject<MediaStreamAudioProcessor>( | |
187 constraint_factory.CreateWebMediaConstraints(), 0, | |
188 webrtc_audio_device.get())); | |
189 EXPECT_FALSE(audio_processor->has_audio_processing()); | |
190 audio_processor->OnCaptureFormatChanged(params_); | |
191 | |
192 ProcessDataAndVerifyFormat(audio_processor.get(), | |
193 params_.sample_rate(), | |
194 params_.channels(), | |
195 params_.sample_rate() / 100); | |
196 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives | |
197 // |audio_processor|. | |
198 audio_processor = NULL; | |
199 } | |
200 | |
201 TEST_F(MediaStreamAudioProcessorTest, WithAudioProcessing) { | 176 TEST_F(MediaStreamAudioProcessorTest, WithAudioProcessing) { |
202 MockMediaConstraintFactory constraint_factory; | 177 MockMediaConstraintFactory constraint_factory; |
203 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | 178 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
204 new WebRtcAudioDeviceImpl()); | 179 new WebRtcAudioDeviceImpl()); |
205 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | 180 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
206 new rtc::RefCountedObject<MediaStreamAudioProcessor>( | 181 new rtc::RefCountedObject<MediaStreamAudioProcessor>( |
207 constraint_factory.CreateWebMediaConstraints(), 0, | 182 constraint_factory.CreateWebMediaConstraints(), 0, |
208 webrtc_audio_device.get())); | 183 webrtc_audio_device.get())); |
209 EXPECT_TRUE(audio_processor->has_audio_processing()); | 184 EXPECT_TRUE(audio_processor->has_audio_processing()); |
210 audio_processor->OnCaptureFormatChanged(params_); | 185 audio_processor->OnCaptureFormatChanged(params_); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 // for all the constraints except |kMediaStreamAudioDucking| are false. | 323 // for all the constraints except |kMediaStreamAudioDucking| are false. |
349 MockMediaConstraintFactory constraint_factory; | 324 MockMediaConstraintFactory constraint_factory; |
350 constraint_factory.AddOptional(MediaAudioConstraints::kEchoCancellation, | 325 constraint_factory.AddOptional(MediaAudioConstraints::kEchoCancellation, |
351 false); | 326 false); |
352 blink::WebMediaConstraints constraints = | 327 blink::WebMediaConstraints constraints = |
353 constraint_factory.CreateWebMediaConstraints(); | 328 constraint_factory.CreateWebMediaConstraints(); |
354 MediaAudioConstraints audio_constraints(constraints, 0); | 329 MediaAudioConstraints audio_constraints(constraints, 0); |
355 for (size_t i = 0; i < arraysize(kDefaultAudioConstraints); ++i) { | 330 for (size_t i = 0; i < arraysize(kDefaultAudioConstraints); ++i) { |
356 EXPECT_FALSE(audio_constraints.GetProperty(kDefaultAudioConstraints[i])); | 331 EXPECT_FALSE(audio_constraints.GetProperty(kDefaultAudioConstraints[i])); |
357 } | 332 } |
358 EXPECT_FALSE(audio_constraints.NeedsAudioProcessing()); | |
359 #if defined(OS_WIN) | 333 #if defined(OS_WIN) |
360 EXPECT_TRUE(audio_constraints.GetProperty(kMediaStreamAudioDucking)); | 334 EXPECT_TRUE(audio_constraints.GetProperty(kMediaStreamAudioDucking)); |
361 #else | 335 #else |
362 EXPECT_FALSE(audio_constraints.GetProperty(kMediaStreamAudioDucking)); | 336 EXPECT_FALSE(audio_constraints.GetProperty(kMediaStreamAudioDucking)); |
363 #endif | 337 #endif |
364 } | 338 } |
365 } | 339 } |
366 | 340 |
367 TEST_F(MediaStreamAudioProcessorTest, ValidateConstraints) { | 341 TEST_F(MediaStreamAudioProcessorTest, ValidateConstraints) { |
368 MockMediaConstraintFactory constraint_factory; | 342 MockMediaConstraintFactory constraint_factory; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 | 483 |
510 ProcessDataAndVerifyFormat(audio_processor.get(), | 484 ProcessDataAndVerifyFormat(audio_processor.get(), |
511 kAudioProcessingSampleRate, | 485 kAudioProcessingSampleRate, |
512 kAudioProcessingNumberOfChannel, | 486 kAudioProcessingNumberOfChannel, |
513 kAudioProcessingSampleRate / 100); | 487 kAudioProcessingSampleRate / 100); |
514 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives | 488 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives |
515 // |audio_processor|. | 489 // |audio_processor|. |
516 audio_processor = NULL; | 490 audio_processor = NULL; |
517 } | 491 } |
518 | 492 |
519 TEST_F(MediaStreamAudioProcessorTest, | |
520 TestWithKeyboardMicChannelWithoutProcessing) { | |
521 // Setup the audio processor with disabled flag on. | |
522 CommandLine::ForCurrentProcess()->AppendSwitch( | |
523 switches::kDisableAudioTrackProcessing); | |
524 MockMediaConstraintFactory constraint_factory; | |
525 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | |
526 new WebRtcAudioDeviceImpl()); | |
527 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | |
528 new rtc::RefCountedObject<MediaStreamAudioProcessor>( | |
529 constraint_factory.CreateWebMediaConstraints(), 0, | |
530 webrtc_audio_device.get())); | |
531 EXPECT_FALSE(audio_processor->has_audio_processing()); | |
532 | |
533 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | |
534 media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC, | |
535 48000, 16, 512); | |
536 audio_processor->OnCaptureFormatChanged(params); | |
537 | |
538 ProcessDataAndVerifyFormat( | |
539 audio_processor.get(), | |
540 params.sample_rate(), | |
541 media::ChannelLayoutToChannelCount(media::CHANNEL_LAYOUT_STEREO), | |
542 params.sample_rate() / 100); | |
543 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives | |
544 // |audio_processor|. | |
545 audio_processor = NULL; | |
546 } | |
547 | |
548 } // namespace content | 493 } // namespace content |
OLD | NEW |