Chromium Code Reviews| 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" | 5 #include "base/command_line.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "content/public/common/content_switches.h" | 11 #include "content/public/common/content_switches.h" |
| 12 #include "content/public/common/media_stream_request.h" | 12 #include "content/public/common/media_stream_request.h" |
| 13 #include "content/renderer/media/media_stream_audio_processor.h" | 13 #include "content/renderer/media/media_stream_audio_processor.h" |
| 14 #include "content/renderer/media/media_stream_audio_processor_options.h" | |
| 14 #include "content/renderer/media/mock_media_constraint_factory.h" | 15 #include "content/renderer/media/mock_media_constraint_factory.h" |
| 15 #include "media/audio/audio_parameters.h" | 16 #include "media/audio/audio_parameters.h" |
| 16 #include "media/base/audio_bus.h" | 17 #include "media/base/audio_bus.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 20 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| 20 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" | 21 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" |
| 21 | 22 |
| 22 using ::testing::_; | 23 using ::testing::_; |
| 23 using ::testing::AnyNumber; | 24 using ::testing::AnyNumber; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 EXPECT_TRUE(audio_processing->voice_detection()->likelihood() == | 147 EXPECT_TRUE(audio_processing->voice_detection()->likelihood() == |
| 147 webrtc::VoiceDetection::kVeryLowLikelihood); | 148 webrtc::VoiceDetection::kVeryLowLikelihood); |
| 148 #endif | 149 #endif |
| 149 } | 150 } |
| 150 | 151 |
| 151 media::AudioParameters params_; | 152 media::AudioParameters params_; |
| 152 }; | 153 }; |
| 153 | 154 |
| 154 TEST_F(MediaStreamAudioProcessorTest, WithoutAudioProcessing) { | 155 TEST_F(MediaStreamAudioProcessorTest, WithoutAudioProcessing) { |
| 155 // Setup the audio processor without enabling the flag. | 156 // Setup the audio processor without enabling the flag. |
| 156 blink::WebMediaConstraints constraints; | 157 MockMediaConstraintFactory constraint_factory; |
| 157 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | 158 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
| 158 new WebRtcAudioDeviceImpl()); | 159 new WebRtcAudioDeviceImpl()); |
| 159 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | 160 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
| 160 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( | 161 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( |
| 161 constraints, 0, MEDIA_DEVICE_AUDIO_CAPTURE, | 162 constraint_factory.CreateWebMediaConstraints(), 0, |
| 162 webrtc_audio_device.get())); | 163 MEDIA_DEVICE_AUDIO_CAPTURE, webrtc_audio_device.get())); |
| 163 EXPECT_FALSE(audio_processor->has_audio_processing()); | 164 EXPECT_FALSE(audio_processor->has_audio_processing()); |
| 164 audio_processor->OnCaptureFormatChanged(params_); | 165 audio_processor->OnCaptureFormatChanged(params_); |
| 165 | 166 |
| 166 ProcessDataAndVerifyFormat(audio_processor, | 167 ProcessDataAndVerifyFormat(audio_processor, |
| 167 params_.sample_rate(), | 168 params_.sample_rate(), |
| 168 params_.channels(), | 169 params_.channels(), |
| 169 params_.sample_rate() / 100); | 170 params_.sample_rate() / 100); |
| 170 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives | 171 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives |
| 171 // |audio_processor|. | 172 // |audio_processor|. |
| 172 audio_processor = NULL; | 173 audio_processor = NULL; |
| 173 } | 174 } |
| 174 | 175 |
| 175 TEST_F(MediaStreamAudioProcessorTest, WithAudioProcessing) { | 176 TEST_F(MediaStreamAudioProcessorTest, WithAudioProcessing) { |
| 176 // Setup the audio processor with the flag enabled. | 177 // Setup the audio processor with the flag enabled. |
| 177 CommandLine::ForCurrentProcess()->AppendSwitch( | 178 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 178 switches::kEnableAudioTrackProcessing); | 179 switches::kEnableAudioTrackProcessing); |
| 179 blink::WebMediaConstraints constraints; | 180 MockMediaConstraintFactory constraint_factory; |
| 180 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | 181 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
| 181 new WebRtcAudioDeviceImpl()); | 182 new WebRtcAudioDeviceImpl()); |
| 182 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | 183 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
| 183 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( | 184 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( |
| 184 constraints, 0, MEDIA_DEVICE_AUDIO_CAPTURE, | 185 constraint_factory.CreateWebMediaConstraints(), 0, |
| 185 webrtc_audio_device.get())); | 186 MEDIA_DEVICE_AUDIO_CAPTURE, webrtc_audio_device.get())); |
| 186 EXPECT_TRUE(audio_processor->has_audio_processing()); | 187 EXPECT_TRUE(audio_processor->has_audio_processing()); |
| 187 audio_processor->OnCaptureFormatChanged(params_); | 188 audio_processor->OnCaptureFormatChanged(params_); |
| 188 VerifyDefaultComponents(audio_processor); | 189 VerifyDefaultComponents(audio_processor); |
| 189 | 190 |
| 190 ProcessDataAndVerifyFormat(audio_processor, | 191 ProcessDataAndVerifyFormat(audio_processor, |
| 191 kAudioProcessingSampleRate, | 192 kAudioProcessingSampleRate, |
| 192 kAudioProcessingNumberOfChannel, | 193 kAudioProcessingNumberOfChannel, |
| 193 kAudioProcessingSampleRate / 100); | 194 kAudioProcessingSampleRate / 100); |
| 194 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives | 195 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives |
| 195 // |audio_processor|. | 196 // |audio_processor|. |
| 196 audio_processor = NULL; | 197 audio_processor = NULL; |
| 197 } | 198 } |
| 198 | 199 |
| 199 TEST_F(MediaStreamAudioProcessorTest, VerifyTabCaptureWithoutAudioProcessing) { | 200 TEST_F(MediaStreamAudioProcessorTest, VerifyTabCaptureWithoutAudioProcessing) { |
| 200 // Setup the audio processor with enabling the flag. | 201 // Setup the audio processor with enabling the flag. |
| 201 CommandLine::ForCurrentProcess()->AppendSwitch( | 202 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 202 switches::kEnableAudioTrackProcessing); | 203 switches::kEnableAudioTrackProcessing); |
| 203 blink::WebMediaConstraints constraints; | 204 MockMediaConstraintFactory constraint_factory; |
| 204 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | 205 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
| 205 new WebRtcAudioDeviceImpl()); | 206 new WebRtcAudioDeviceImpl()); |
| 206 // Create MediaStreamAudioProcessor instance for MEDIA_TAB_AUDIO_CAPTURE type. | 207 // Create MediaStreamAudioProcessor instance for MEDIA_TAB_AUDIO_CAPTURE type. |
| 207 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | 208 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
| 208 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( | 209 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( |
| 209 constraints, 0, MEDIA_TAB_AUDIO_CAPTURE, | 210 constraint_factory.CreateWebMediaConstraints(), 0, |
| 210 webrtc_audio_device.get())); | 211 MEDIA_TAB_AUDIO_CAPTURE, webrtc_audio_device.get())); |
| 211 EXPECT_FALSE(audio_processor->has_audio_processing()); | 212 EXPECT_FALSE(audio_processor->has_audio_processing()); |
| 212 audio_processor->OnCaptureFormatChanged(params_); | 213 audio_processor->OnCaptureFormatChanged(params_); |
| 213 | 214 |
| 214 ProcessDataAndVerifyFormat(audio_processor, | 215 ProcessDataAndVerifyFormat(audio_processor, |
| 215 params_.sample_rate(), | 216 params_.sample_rate(), |
| 216 params_.channels(), | 217 params_.channels(), |
| 217 params_.sample_rate() / 100); | 218 params_.sample_rate() / 100); |
| 218 | 219 |
| 219 // Create MediaStreamAudioProcessor instance for MEDIA_LOOPBACK_AUDIO_CAPTURE. | 220 // Create MediaStreamAudioProcessor instance for MEDIA_LOOPBACK_AUDIO_CAPTURE. |
| 220 audio_processor = | 221 audio_processor = |
| 221 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( | 222 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( |
| 222 constraints, 0, MEDIA_LOOPBACK_AUDIO_CAPTURE, | 223 constraint_factory.CreateWebMediaConstraints(), 0, |
| 223 webrtc_audio_device.get()); | 224 MEDIA_LOOPBACK_AUDIO_CAPTURE, webrtc_audio_device.get()); |
| 224 EXPECT_FALSE(audio_processor->has_audio_processing()); | 225 EXPECT_FALSE(audio_processor->has_audio_processing()); |
| 225 | 226 |
| 226 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives | 227 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives |
| 227 // |audio_processor|. | 228 // |audio_processor|. |
| 228 audio_processor = NULL; | 229 audio_processor = NULL; |
| 229 } | 230 } |
| 230 | 231 |
| 231 TEST_F(MediaStreamAudioProcessorTest, TurnOffDefaultConstraints) { | 232 TEST_F(MediaStreamAudioProcessorTest, TurnOffDefaultConstraints) { |
| 232 // Setup the audio processor with enabling the flag. | 233 // Setup the audio processor with enabling the flag. |
| 233 CommandLine::ForCurrentProcess()->AppendSwitch( | 234 CommandLine::ForCurrentProcess()->AppendSwitch( |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 247 | 248 |
| 248 ProcessDataAndVerifyFormat(audio_processor, | 249 ProcessDataAndVerifyFormat(audio_processor, |
| 249 params_.sample_rate(), | 250 params_.sample_rate(), |
| 250 params_.channels(), | 251 params_.channels(), |
| 251 params_.sample_rate() / 100); | 252 params_.sample_rate() / 100); |
| 252 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives | 253 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives |
| 253 // |audio_processor|. | 254 // |audio_processor|. |
| 254 audio_processor = NULL; | 255 audio_processor = NULL; |
| 255 } | 256 } |
| 256 | 257 |
| 258 TEST_F(MediaStreamAudioProcessorTest, VerifyConstraints) { | |
| 259 // Setup the audio processor with enabling the flag. | |
| 260 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 261 switches::kEnableAudioTrackProcessing); | |
| 262 | |
| 263 static const char* kDefaultAudioConstraints[] = { | |
| 264 kEchoCancellation, | |
|
tommi (sloooow) - chröme
2014/04/08 10:49:30
fix indent
no longer working on chromium
2014/04/11 08:56:30
Done.
| |
| 265 kGoogEchoCancellation, | |
| 266 kGoogExperimentalEchoCancellation, | |
| 267 kGoogAutoGainControl, | |
| 268 kGoogExperimentalAutoGainControl, | |
| 269 kGoogNoiseSuppression, | |
| 270 kGoogExperimentalNoiseSuppression, | |
| 271 kGoogHighpassFilter, | |
| 272 kGoogTypingNoiseDetection, | |
| 273 kGoogAudioMirroring | |
| 274 }; | |
| 275 | |
| 276 // Verify mandatory constraints. | |
| 277 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { | |
| 278 MockMediaConstraintFactory constraint_factory; | |
| 279 constraint_factory.AddMandatory(kDefaultAudioConstraints[i], false); | |
|
tommi (sloooow) - chröme
2014/04/08 10:49:30
looks like you're exchanging bool for what used to
no longer working on chromium
2014/04/11 08:56:30
MockMediaConstraintFactory::AddMandatory takes int
| |
| 280 blink::WebMediaConstraints constraints = | |
| 281 constraint_factory.CreateWebMediaConstraints(); | |
| 282 EXPECT_FALSE(GetPropertyFromConstraints(constraints, | |
| 283 kDefaultAudioConstraints[i], | |
| 284 0, MEDIA_DEVICE_AUDIO_CAPTURE)); | |
| 285 } | |
| 286 | |
| 287 // Verify optional constraints. | |
| 288 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { | |
| 289 MockMediaConstraintFactory constraint_factory; | |
| 290 constraint_factory.AddOptional(kDefaultAudioConstraints[i], false); | |
| 291 blink::WebMediaConstraints constraints = | |
| 292 constraint_factory.CreateWebMediaConstraints(); | |
| 293 EXPECT_FALSE(GetPropertyFromConstraints(constraints, | |
| 294 kDefaultAudioConstraints[i], | |
| 295 0, MEDIA_DEVICE_AUDIO_CAPTURE)); | |
| 296 } | |
| 297 | |
| 298 // Verify echo cancellation is off when platform aec effect is on. | |
| 299 MockMediaConstraintFactory constraint_factory; | |
| 300 EXPECT_FALSE(GetPropertyFromConstraints( | |
| 301 constraint_factory.CreateWebMediaConstraints(), | |
| 302 kGoogEchoCancellation, | |
| 303 media::AudioParameters::ECHO_CANCELLER, MEDIA_DEVICE_AUDIO_CAPTURE)); | |
| 304 } | |
| 305 | |
|
perkj_chrome
2014/04/08 10:28:12
Add test to see that gum fail if an unsupported ma
no longer working on chromium
2014/04/11 08:56:30
Done.
| |
| 257 } // namespace content | 306 } // namespace content |
| OLD | NEW |