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 <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/message_loop/message_loop.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/test/scoped_feature_list.h" | |
| 17 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 19 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 20 #include "content/common/media/media_stream_options.h" | 21 #include "content/common/media/media_stream_options.h" |
| 22 #include "content/public/common/content_features.h" | |
| 21 #include "content/public/common/media_stream_request.h" | 23 #include "content/public/common/media_stream_request.h" |
| 22 #include "content/renderer/media/media_stream_audio_processor.h" | 24 #include "content/renderer/media/media_stream_audio_processor.h" |
| 23 #include "content/renderer/media/media_stream_audio_processor_options.h" | 25 #include "content/renderer/media/media_stream_audio_processor_options.h" |
| 24 #include "content/renderer/media/mock_constraint_factory.h" | 26 #include "content/renderer/media/mock_constraint_factory.h" |
| 25 #include "media/base/audio_bus.h" | 27 #include "media/base/audio_bus.h" |
| 26 #include "media/base/audio_parameters.h" | 28 #include "media/base/audio_parameters.h" |
| 27 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 29 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 31 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| 30 #include "third_party/webrtc/api/mediastreaminterface.h" | 32 #include "third_party/webrtc/api/mediastreaminterface.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 .Append(FILE_PATH_LITERAL("test")) | 69 .Append(FILE_PATH_LITERAL("test")) |
| 68 .Append(FILE_PATH_LITERAL("data")) | 70 .Append(FILE_PATH_LITERAL("data")) |
| 69 .Append(FILE_PATH_LITERAL("speech_16b_stereo_48kHz.raw")); | 71 .Append(FILE_PATH_LITERAL("speech_16b_stereo_48kHz.raw")); |
| 70 DCHECK(base::PathExists(file)); | 72 DCHECK(base::PathExists(file)); |
| 71 int64_t data_file_size64 = 0; | 73 int64_t data_file_size64 = 0; |
| 72 DCHECK(base::GetFileSize(file, &data_file_size64)); | 74 DCHECK(base::GetFileSize(file, &data_file_size64)); |
| 73 EXPECT_EQ(length, base::ReadFile(file, data, length)); | 75 EXPECT_EQ(length, base::ReadFile(file, data, length)); |
| 74 DCHECK(data_file_size64 > length); | 76 DCHECK(data_file_size64 > length); |
| 75 } | 77 } |
| 76 | 78 |
| 79 void DisableDefaultAudioProcessingProperties( | |
| 80 AudioProcessingProperties* properties) { | |
| 81 properties->enable_sw_echo_cancellation = false; | |
| 82 properties->goog_experimental_echo_cancellation = false; | |
| 83 properties->goog_auto_gain_control = false; | |
| 84 properties->goog_experimental_auto_gain_control = false; | |
| 85 properties->goog_noise_suppression = false; | |
| 86 properties->goog_noise_suppression = false; | |
|
hbos_chromium
2017/06/16 17:27:14
nit: disabled twice
Guido Urdaneta
2017/06/19 11:56:48
Fixed.
| |
| 87 properties->goog_highpass_filter = false; | |
| 88 properties->goog_typing_noise_detection = false; | |
| 89 properties->goog_experimental_noise_suppression = false; | |
| 90 properties->goog_beamforming = false; | |
| 91 } | |
| 92 | |
| 77 } // namespace | 93 } // namespace |
| 78 | 94 |
| 79 class MediaStreamAudioProcessorTest : public ::testing::Test { | 95 class MediaStreamAudioProcessorTest : public ::testing::Test { |
| 80 public: | 96 public: |
| 81 MediaStreamAudioProcessorTest() | 97 MediaStreamAudioProcessorTest() |
| 82 : params_(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 98 : params_(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 83 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 512) { | 99 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 512) { |
| 100 // This file includes tests for MediaStreamAudioProcessor, but also for | |
| 101 // the old constraints algorithm. The MediaStreamAudioProcessor tests are | |
| 102 // insensitive to the constraints algorithm, but the constraints tests | |
| 103 // require that the old constraints algorithm be enabled. | |
| 104 scoped_feature_list_.InitAndEnableFeature( | |
| 105 features::kMediaStreamOldAudioConstraints); | |
| 84 } | 106 } |
| 85 | 107 |
| 86 protected: | 108 protected: |
| 87 // Helper method to save duplicated code. | 109 // Helper method to save duplicated code. |
| 88 void ProcessDataAndVerifyFormat(MediaStreamAudioProcessor* audio_processor, | 110 void ProcessDataAndVerifyFormat(MediaStreamAudioProcessor* audio_processor, |
| 89 int expected_output_sample_rate, | 111 int expected_output_sample_rate, |
| 90 int expected_output_channels, | 112 int expected_output_channels, |
| 91 int expected_output_buffer_size) { | 113 int expected_output_buffer_size) { |
| 92 // Read the audio data from a file. | 114 // Read the audio data from a file. |
| 93 const media::AudioParameters& params = audio_processor->InputFormat(); | 115 const media::AudioParameters& params = audio_processor->InputFormat(); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 ADD_FAILURE() << "AudioProcessing object missing where it shouldn't be"; | 227 ADD_FAILURE() << "AudioProcessing object missing where it shouldn't be"; |
| 206 return false; | 228 return false; |
| 207 } | 229 } |
| 208 return audio_processor->audio_processing_->GetConfig() | 230 return audio_processor->audio_processing_->GetConfig() |
| 209 .echo_canceller3.enabled; | 231 .echo_canceller3.enabled; |
| 210 } | 232 } |
| 211 | 233 |
| 212 base::MessageLoop main_thread_message_loop_; | 234 base::MessageLoop main_thread_message_loop_; |
| 213 media::AudioParameters params_; | 235 media::AudioParameters params_; |
| 214 MediaStreamDevice::AudioDeviceParameters input_device_params_; | 236 MediaStreamDevice::AudioDeviceParameters input_device_params_; |
| 237 | |
| 238 // TODO(guidou): Remove this field. http://crbug.com/706408 | |
| 239 base::test::ScopedFeatureList scoped_feature_list_; | |
| 215 }; | 240 }; |
| 216 | 241 |
| 217 // Test crashing with ASAN on Android. crbug.com/468762 | 242 // Test crashing with ASAN on Android. crbug.com/468762 |
| 218 #if defined(OS_ANDROID) && defined(ADDRESS_SANITIZER) | 243 #if defined(OS_ANDROID) && defined(ADDRESS_SANITIZER) |
| 219 #define MAYBE_WithAudioProcessing DISABLED_WithAudioProcessing | 244 #define MAYBE_WithAudioProcessing DISABLED_WithAudioProcessing |
| 220 #else | 245 #else |
| 221 #define MAYBE_WithAudioProcessing WithAudioProcessing | 246 #define MAYBE_WithAudioProcessing WithAudioProcessing |
| 222 #endif | 247 #endif |
| 223 TEST_F(MediaStreamAudioProcessorTest, MAYBE_WithAudioProcessing) { | 248 TEST_F(MediaStreamAudioProcessorTest, MAYBE_WithAudioProcessing) { |
| 224 MockConstraintFactory constraint_factory; | |
| 225 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | 249 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
| 226 new WebRtcAudioDeviceImpl()); | 250 new WebRtcAudioDeviceImpl()); |
| 251 AudioProcessingProperties properties; | |
| 227 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | 252 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
| 228 new rtc::RefCountedObject<MediaStreamAudioProcessor>( | 253 new rtc::RefCountedObject<MediaStreamAudioProcessor>( |
| 229 constraint_factory.CreateWebMediaConstraints(), input_device_params_, | 254 properties, webrtc_audio_device.get())); |
| 230 webrtc_audio_device.get())); | |
| 231 EXPECT_TRUE(audio_processor->has_audio_processing()); | 255 EXPECT_TRUE(audio_processor->has_audio_processing()); |
| 232 audio_processor->OnCaptureFormatChanged(params_); | 256 audio_processor->OnCaptureFormatChanged(params_); |
| 233 VerifyDefaultComponents(audio_processor.get()); | 257 VerifyDefaultComponents(audio_processor.get()); |
| 234 | 258 |
| 235 ProcessDataAndVerifyFormat(audio_processor.get(), | 259 ProcessDataAndVerifyFormat(audio_processor.get(), |
| 236 kAudioProcessingSampleRate, | 260 kAudioProcessingSampleRate, |
| 237 kAudioProcessingNumberOfChannel, | 261 kAudioProcessingNumberOfChannel, |
| 238 kAudioProcessingSampleRate / 100); | 262 kAudioProcessingSampleRate / 100); |
| 239 | 263 |
| 240 // Stop |audio_processor| so that it removes itself from | 264 // Stop |audio_processor| so that it removes itself from |
| 241 // |webrtc_audio_device| and clears its pointer to it. | 265 // |webrtc_audio_device| and clears its pointer to it. |
| 242 audio_processor->Stop(); | 266 audio_processor->Stop(); |
| 243 } | 267 } |
| 244 | 268 |
| 245 TEST_F(MediaStreamAudioProcessorTest, VerifyTabCaptureWithoutAudioProcessing) { | |
| 246 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | |
| 247 new WebRtcAudioDeviceImpl()); | |
| 248 // Create MediaStreamAudioProcessor instance for kMediaStreamSourceTab source. | |
| 249 MockConstraintFactory tab_constraint_factory; | |
| 250 const std::string tab_string = kMediaStreamSourceTab; | |
| 251 tab_constraint_factory.basic().media_stream_source.SetExact( | |
| 252 blink::WebString::FromUTF8(tab_string)); | |
| 253 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | |
| 254 new rtc::RefCountedObject<MediaStreamAudioProcessor>( | |
| 255 tab_constraint_factory.CreateWebMediaConstraints(), | |
| 256 input_device_params_, webrtc_audio_device.get())); | |
| 257 EXPECT_FALSE(audio_processor->has_audio_processing()); | |
| 258 audio_processor->OnCaptureFormatChanged(params_); | |
| 259 | |
| 260 ProcessDataAndVerifyFormat(audio_processor.get(), | |
| 261 params_.sample_rate(), | |
| 262 params_.channels(), | |
| 263 params_.sample_rate() / 100); | |
| 264 | |
| 265 // Create MediaStreamAudioProcessor instance for kMediaStreamSourceSystem | |
| 266 // source. | |
| 267 MockConstraintFactory system_constraint_factory; | |
| 268 const std::string system_string = kMediaStreamSourceSystem; | |
| 269 system_constraint_factory.basic().media_stream_source.SetExact( | |
| 270 blink::WebString::FromUTF8(system_string)); | |
| 271 audio_processor = new rtc::RefCountedObject<MediaStreamAudioProcessor>( | |
| 272 system_constraint_factory.CreateWebMediaConstraints(), | |
| 273 input_device_params_, webrtc_audio_device.get()); | |
| 274 EXPECT_FALSE(audio_processor->has_audio_processing()); | |
| 275 | |
| 276 // Stop |audio_processor| so that it removes itself from | |
| 277 // |webrtc_audio_device| and clears its pointer to it. | |
| 278 audio_processor->Stop(); | |
| 279 } | |
| 280 | |
| 281 TEST_F(MediaStreamAudioProcessorTest, TurnOffDefaultConstraints) { | 269 TEST_F(MediaStreamAudioProcessorTest, TurnOffDefaultConstraints) { |
| 270 AudioProcessingProperties properties; | |
| 282 // Turn off the default constraints and pass it to MediaStreamAudioProcessor. | 271 // Turn off the default constraints and pass it to MediaStreamAudioProcessor. |
| 283 MockConstraintFactory constraint_factory; | 272 DisableDefaultAudioProcessingProperties(&properties); |
| 284 constraint_factory.DisableDefaultAudioConstraints(); | |
| 285 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | 273 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
| 286 new WebRtcAudioDeviceImpl()); | 274 new WebRtcAudioDeviceImpl()); |
| 287 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | 275 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
| 288 new rtc::RefCountedObject<MediaStreamAudioProcessor>( | 276 new rtc::RefCountedObject<MediaStreamAudioProcessor>( |
| 289 constraint_factory.CreateWebMediaConstraints(), input_device_params_, | 277 properties, webrtc_audio_device.get())); |
| 290 webrtc_audio_device.get())); | |
| 291 EXPECT_FALSE(audio_processor->has_audio_processing()); | 278 EXPECT_FALSE(audio_processor->has_audio_processing()); |
| 292 audio_processor->OnCaptureFormatChanged(params_); | 279 audio_processor->OnCaptureFormatChanged(params_); |
| 293 | 280 |
| 294 ProcessDataAndVerifyFormat(audio_processor.get(), | 281 ProcessDataAndVerifyFormat(audio_processor.get(), |
| 295 params_.sample_rate(), | 282 params_.sample_rate(), |
| 296 params_.channels(), | 283 params_.channels(), |
| 297 params_.sample_rate() / 100); | 284 params_.sample_rate() / 100); |
| 298 | 285 |
| 299 // Stop |audio_processor| so that it removes itself from | 286 // Stop |audio_processor| so that it removes itself from |
| 300 // |webrtc_audio_device| and clears its pointer to it. | 287 // |webrtc_audio_device| and clears its pointer to it. |
| 301 audio_processor->Stop(); | 288 audio_processor->Stop(); |
| 302 } | 289 } |
| 303 | 290 |
| 291 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 304 TEST_F(MediaStreamAudioProcessorTest, VerifyConstraints) { | 292 TEST_F(MediaStreamAudioProcessorTest, VerifyConstraints) { |
| 305 { | 293 { |
| 306 // Verify that echo cancellation is off when platform aec effect is on. | 294 // Verify that echo cancellation is off when platform aec effect is on. |
| 307 MockConstraintFactory constraint_factory; | 295 MockConstraintFactory constraint_factory; |
| 308 MediaAudioConstraints audio_constraints( | 296 MediaAudioConstraints audio_constraints( |
| 309 constraint_factory.CreateWebMediaConstraints(), | 297 constraint_factory.CreateWebMediaConstraints(), |
| 310 media::AudioParameters::ECHO_CANCELLER); | 298 media::AudioParameters::ECHO_CANCELLER); |
| 311 EXPECT_FALSE(audio_constraints.GetEchoCancellationProperty()); | 299 EXPECT_FALSE(audio_constraints.GetEchoCancellationProperty()); |
| 312 } | 300 } |
| 313 | 301 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 333 // When |kEchoCancellation| is explicitly set to false, the default values | 321 // When |kEchoCancellation| is explicitly set to false, the default values |
| 334 // for all the constraints are false. | 322 // for all the constraints are false. |
| 335 MockConstraintFactory constraint_factory; | 323 MockConstraintFactory constraint_factory; |
| 336 constraint_factory.AddAdvanced().echo_cancellation.SetExact(false); | 324 constraint_factory.AddAdvanced().echo_cancellation.SetExact(false); |
| 337 blink::WebMediaConstraints constraints = | 325 blink::WebMediaConstraints constraints = |
| 338 constraint_factory.CreateWebMediaConstraints(); | 326 constraint_factory.CreateWebMediaConstraints(); |
| 339 MediaAudioConstraints audio_constraints(constraints, 0); | 327 MediaAudioConstraints audio_constraints(constraints, 0); |
| 340 } | 328 } |
| 341 } | 329 } |
| 342 | 330 |
| 331 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 343 TEST_F(MediaStreamAudioProcessorTest, ValidateBadConstraints) { | 332 TEST_F(MediaStreamAudioProcessorTest, ValidateBadConstraints) { |
| 344 MockConstraintFactory constraint_factory; | 333 MockConstraintFactory constraint_factory; |
| 345 // Add a constraint that is not valid for audio. | 334 // Add a constraint that is not valid for audio. |
| 346 constraint_factory.basic().width.SetExact(240); | 335 constraint_factory.basic().width.SetExact(240); |
| 347 MediaAudioConstraints audio_constraints( | 336 MediaAudioConstraints audio_constraints( |
| 348 constraint_factory.CreateWebMediaConstraints(), 0); | 337 constraint_factory.CreateWebMediaConstraints(), 0); |
| 349 EXPECT_FALSE(audio_constraints.IsValid()); | 338 EXPECT_FALSE(audio_constraints.IsValid()); |
| 350 } | 339 } |
| 351 | 340 |
| 341 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 352 TEST_F(MediaStreamAudioProcessorTest, ValidateGoodConstraints) { | 342 TEST_F(MediaStreamAudioProcessorTest, ValidateGoodConstraints) { |
| 353 MockConstraintFactory constraint_factory; | 343 MockConstraintFactory constraint_factory; |
| 354 // Check that the renderToAssociatedSink constraint is considered valid. | 344 // Check that the renderToAssociatedSink constraint is considered valid. |
| 355 constraint_factory.basic().render_to_associated_sink.SetExact(true); | 345 constraint_factory.basic().render_to_associated_sink.SetExact(true); |
| 356 MediaAudioConstraints audio_constraints( | 346 MediaAudioConstraints audio_constraints( |
| 357 constraint_factory.CreateWebMediaConstraints(), 0); | 347 constraint_factory.CreateWebMediaConstraints(), 0); |
| 358 EXPECT_TRUE(audio_constraints.IsValid()); | 348 EXPECT_TRUE(audio_constraints.IsValid()); |
| 359 } | 349 } |
| 360 | 350 |
| 351 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 361 TEST_F(MediaStreamAudioProcessorTest, NoEchoTurnsOffProcessing) { | 352 TEST_F(MediaStreamAudioProcessorTest, NoEchoTurnsOffProcessing) { |
| 362 { | 353 { |
| 363 MockConstraintFactory constraint_factory; | 354 MockConstraintFactory constraint_factory; |
| 364 MediaAudioConstraints audio_constraints( | 355 MediaAudioConstraints audio_constraints( |
| 365 constraint_factory.CreateWebMediaConstraints(), 0); | 356 constraint_factory.CreateWebMediaConstraints(), 0); |
| 366 // The default value for echo cancellation is true, except when all | 357 // The default value for echo cancellation is true, except when all |
| 367 // audio processing has been turned off. | 358 // audio processing has been turned off. |
| 368 EXPECT_TRUE(audio_constraints.default_audio_processing_constraint_value()); | 359 EXPECT_TRUE(audio_constraints.default_audio_processing_constraint_value()); |
| 369 } | 360 } |
| 370 // Turning off audio processing via a mandatory constraint. | 361 // Turning off audio processing via a mandatory constraint. |
| 371 { | 362 { |
| 372 MockConstraintFactory constraint_factory; | 363 MockConstraintFactory constraint_factory; |
| 373 constraint_factory.basic().echo_cancellation.SetExact(false); | 364 constraint_factory.basic().echo_cancellation.SetExact(false); |
| 374 MediaAudioConstraints audio_constraints( | 365 MediaAudioConstraints audio_constraints( |
| 375 constraint_factory.CreateWebMediaConstraints(), 0); | 366 constraint_factory.CreateWebMediaConstraints(), 0); |
| 376 // The default value for echo cancellation is true, except when all | 367 // The default value for echo cancellation is true, except when all |
| 377 // audio processing has been turned off. | 368 // audio processing has been turned off. |
| 378 EXPECT_FALSE(audio_constraints.default_audio_processing_constraint_value()); | 369 EXPECT_FALSE(audio_constraints.default_audio_processing_constraint_value()); |
| 379 } | 370 } |
| 380 // Turning off audio processing via an optional constraint. | 371 // Turning off audio processing via an optional constraint. |
| 381 { | 372 { |
| 382 MockConstraintFactory constraint_factory; | 373 MockConstraintFactory constraint_factory; |
| 383 constraint_factory.AddAdvanced().echo_cancellation.SetExact(false); | 374 constraint_factory.AddAdvanced().echo_cancellation.SetExact(false); |
| 384 MediaAudioConstraints audio_constraints( | 375 MediaAudioConstraints audio_constraints( |
| 385 constraint_factory.CreateWebMediaConstraints(), 0); | 376 constraint_factory.CreateWebMediaConstraints(), 0); |
| 386 EXPECT_FALSE(audio_constraints.default_audio_processing_constraint_value()); | 377 EXPECT_FALSE(audio_constraints.default_audio_processing_constraint_value()); |
| 387 } | 378 } |
| 388 } | 379 } |
| 389 | 380 |
| 381 // TODO(guidou): Remove this function. http://crbug.com/706408 | |
| 390 MediaAudioConstraints MakeMediaAudioConstraints( | 382 MediaAudioConstraints MakeMediaAudioConstraints( |
| 391 const MockConstraintFactory& constraint_factory) { | 383 const MockConstraintFactory& constraint_factory) { |
| 392 return MediaAudioConstraints(constraint_factory.CreateWebMediaConstraints(), | 384 return MediaAudioConstraints(constraint_factory.CreateWebMediaConstraints(), |
| 393 AudioParameters::NO_EFFECTS); | 385 AudioParameters::NO_EFFECTS); |
| 394 } | 386 } |
| 395 | 387 |
| 388 // TODO(guidou): Remove this test. http://crbug.com/706408 | |
| 396 TEST_F(MediaStreamAudioProcessorTest, SelectsConstraintsArrayGeometryIfExists) { | 389 TEST_F(MediaStreamAudioProcessorTest, SelectsConstraintsArrayGeometryIfExists) { |
| 397 std::vector<webrtc::Point> constraints_geometry(1, | 390 std::vector<media::Point> constraints_geometry(1, media::Point(-0.02f, 0, 0)); |
| 398 webrtc::Point(-0.02f, 0, 0)); | 391 constraints_geometry.push_back(media::Point(0.02f, 0, 0)); |
| 399 constraints_geometry.push_back(webrtc::Point(0.02f, 0, 0)); | |
| 400 | 392 |
| 401 std::vector<webrtc::Point> input_device_geometry(1, webrtc::Point(0, 0, 0)); | 393 std::vector<media::Point> input_device_geometry(1, media::Point(0, 0, 0)); |
| 402 input_device_geometry.push_back(webrtc::Point(0, 0.05f, 0)); | 394 input_device_geometry.push_back(media::Point(0, 0.05f, 0)); |
| 403 | 395 |
| 404 { | 396 { |
| 405 // Both geometries empty. | 397 // Both geometries empty. |
| 406 MockConstraintFactory constraint_factory; | 398 MockConstraintFactory constraint_factory; |
| 407 MediaStreamDevice::AudioDeviceParameters input_params; | 399 MediaStreamDevice::AudioDeviceParameters input_params; |
| 408 | 400 |
| 409 const auto& actual_geometry = GetArrayGeometryPreferringConstraints( | 401 const auto& actual_geometry = GetArrayGeometryPreferringConstraints( |
| 410 MakeMediaAudioConstraints(constraint_factory), input_params); | 402 MakeMediaAudioConstraints(constraint_factory), input_params); |
| 411 EXPECT_EQ(std::vector<webrtc::Point>(), actual_geometry); | 403 EXPECT_EQ(std::vector<media::Point>(), actual_geometry); |
| 412 } | 404 } |
| 413 { | 405 { |
| 414 // Constraints geometry empty. | 406 // Constraints geometry empty. |
| 415 MockConstraintFactory constraint_factory; | 407 MockConstraintFactory constraint_factory; |
| 416 MediaStreamDevice::AudioDeviceParameters input_params; | 408 MediaStreamDevice::AudioDeviceParameters input_params; |
| 417 input_params.mic_positions.push_back(media::Point(0, 0, 0)); | 409 input_params.mic_positions.push_back(media::Point(0, 0, 0)); |
| 418 input_params.mic_positions.push_back(media::Point(0, 0.05f, 0)); | 410 input_params.mic_positions.push_back(media::Point(0, 0.05f, 0)); |
| 419 | 411 |
| 420 const auto& actual_geometry = GetArrayGeometryPreferringConstraints( | 412 const auto& actual_geometry = GetArrayGeometryPreferringConstraints( |
| 421 MakeMediaAudioConstraints(constraint_factory), input_params); | 413 MakeMediaAudioConstraints(constraint_factory), input_params); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 448 } | 440 } |
| 449 } | 441 } |
| 450 | 442 |
| 451 // Test crashing with ASAN on Android. crbug.com/468762 | 443 // Test crashing with ASAN on Android. crbug.com/468762 |
| 452 #if defined(OS_ANDROID) && defined(ADDRESS_SANITIZER) | 444 #if defined(OS_ANDROID) && defined(ADDRESS_SANITIZER) |
| 453 #define MAYBE_TestAllSampleRates DISABLED_TestAllSampleRates | 445 #define MAYBE_TestAllSampleRates DISABLED_TestAllSampleRates |
| 454 #else | 446 #else |
| 455 #define MAYBE_TestAllSampleRates TestAllSampleRates | 447 #define MAYBE_TestAllSampleRates TestAllSampleRates |
| 456 #endif | 448 #endif |
| 457 TEST_F(MediaStreamAudioProcessorTest, MAYBE_TestAllSampleRates) { | 449 TEST_F(MediaStreamAudioProcessorTest, MAYBE_TestAllSampleRates) { |
| 458 MockConstraintFactory constraint_factory; | |
| 459 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | 450 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
| 460 new WebRtcAudioDeviceImpl()); | 451 new WebRtcAudioDeviceImpl()); |
| 452 AudioProcessingProperties properties; | |
| 461 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | 453 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
| 462 new rtc::RefCountedObject<MediaStreamAudioProcessor>( | 454 new rtc::RefCountedObject<MediaStreamAudioProcessor>( |
| 463 constraint_factory.CreateWebMediaConstraints(), input_device_params_, | 455 properties, webrtc_audio_device.get())); |
| 464 webrtc_audio_device.get())); | |
| 465 EXPECT_TRUE(audio_processor->has_audio_processing()); | 456 EXPECT_TRUE(audio_processor->has_audio_processing()); |
| 466 | 457 |
| 467 static const int kSupportedSampleRates[] = | 458 static const int kSupportedSampleRates[] = |
| 468 { 8000, 16000, 22050, 32000, 44100, 48000 }; | 459 { 8000, 16000, 22050, 32000, 44100, 48000 }; |
| 469 for (size_t i = 0; i < arraysize(kSupportedSampleRates); ++i) { | 460 for (size_t i = 0; i < arraysize(kSupportedSampleRates); ++i) { |
| 470 int buffer_size = (kSupportedSampleRates[i] / 100) < 128 ? | 461 int buffer_size = (kSupportedSampleRates[i] / 100) < 128 ? |
| 471 kSupportedSampleRates[i] / 100 : 128; | 462 kSupportedSampleRates[i] / 100 : 128; |
| 472 media::AudioParameters params( | 463 media::AudioParameters params( |
| 473 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 464 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 474 media::CHANNEL_LAYOUT_STEREO, kSupportedSampleRates[i], 16, | 465 media::CHANNEL_LAYOUT_STEREO, kSupportedSampleRates[i], 16, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 488 } | 479 } |
| 489 | 480 |
| 490 // Test that if we have an AEC dump message filter created, we are getting it | 481 // Test that if we have an AEC dump message filter created, we are getting it |
| 491 // correctly in MSAP. Any IPC messages will be deleted since no sender in the | 482 // correctly in MSAP. Any IPC messages will be deleted since no sender in the |
| 492 // filter will be created. | 483 // filter will be created. |
| 493 TEST_F(MediaStreamAudioProcessorTest, GetAecDumpMessageFilter) { | 484 TEST_F(MediaStreamAudioProcessorTest, GetAecDumpMessageFilter) { |
| 494 scoped_refptr<AecDumpMessageFilter> aec_dump_message_filter_( | 485 scoped_refptr<AecDumpMessageFilter> aec_dump_message_filter_( |
| 495 new AecDumpMessageFilter(base::ThreadTaskRunnerHandle::Get(), | 486 new AecDumpMessageFilter(base::ThreadTaskRunnerHandle::Get(), |
| 496 base::ThreadTaskRunnerHandle::Get())); | 487 base::ThreadTaskRunnerHandle::Get())); |
| 497 | 488 |
| 498 MockConstraintFactory constraint_factory; | |
| 499 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | 489 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
| 500 new WebRtcAudioDeviceImpl()); | 490 new WebRtcAudioDeviceImpl()); |
| 491 AudioProcessingProperties properties; | |
| 501 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | 492 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
| 502 new rtc::RefCountedObject<MediaStreamAudioProcessor>( | 493 new rtc::RefCountedObject<MediaStreamAudioProcessor>( |
| 503 constraint_factory.CreateWebMediaConstraints(), input_device_params_, | 494 properties, webrtc_audio_device.get())); |
| 504 webrtc_audio_device.get())); | |
| 505 | 495 |
| 506 EXPECT_TRUE(audio_processor->aec_dump_message_filter_.get()); | 496 EXPECT_TRUE(audio_processor->aec_dump_message_filter_.get()); |
| 507 | 497 |
| 508 // Stop |audio_processor| so that it removes itself from | 498 // Stop |audio_processor| so that it removes itself from |
| 509 // |webrtc_audio_device| and clears its pointer to it. | 499 // |webrtc_audio_device| and clears its pointer to it. |
| 510 audio_processor->Stop(); | 500 audio_processor->Stop(); |
| 511 } | 501 } |
| 512 | 502 |
| 513 TEST_F(MediaStreamAudioProcessorTest, TestStereoAudio) { | 503 TEST_F(MediaStreamAudioProcessorTest, TestStereoAudio) { |
| 514 // Set up the correct constraints to turn off the audio processing and turn | |
| 515 // on the stereo channels mirroring. | |
| 516 MockConstraintFactory constraint_factory; | |
| 517 constraint_factory.basic().echo_cancellation.SetExact(false); | |
| 518 constraint_factory.basic().goog_audio_mirroring.SetExact(true); | |
| 519 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | 504 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
| 520 new WebRtcAudioDeviceImpl()); | 505 new WebRtcAudioDeviceImpl()); |
| 506 AudioProcessingProperties properties; | |
| 507 // Turn off the audio processing and turn on the stereo channels mirroring. | |
| 508 DisableDefaultAudioProcessingProperties(&properties); | |
|
hbos_chromium
2017/06/16 17:27:14
Before, only echo cancellation was disabled and mi
Guido Urdaneta
2017/06/19 11:56:48
The old test was disabling all audio-processing co
hbos_chromium
2017/06/19 15:14:41
Acknowledged.
| |
| 509 properties.goog_audio_mirroring = true; | |
| 521 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | 510 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
| 522 new rtc::RefCountedObject<MediaStreamAudioProcessor>( | 511 new rtc::RefCountedObject<MediaStreamAudioProcessor>( |
| 523 constraint_factory.CreateWebMediaConstraints(), input_device_params_, | 512 properties, webrtc_audio_device.get())); |
| 524 webrtc_audio_device.get())); | |
| 525 EXPECT_FALSE(audio_processor->has_audio_processing()); | 513 EXPECT_FALSE(audio_processor->has_audio_processing()); |
| 526 const media::AudioParameters source_params( | 514 const media::AudioParameters source_params( |
| 527 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 515 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 528 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 480); | 516 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 480); |
| 529 audio_processor->OnCaptureFormatChanged(source_params); | 517 audio_processor->OnCaptureFormatChanged(source_params); |
| 530 // There's no sense in continuing if this fails. | 518 // There's no sense in continuing if this fails. |
| 531 ASSERT_EQ(2, audio_processor->OutputFormat().channels()); | 519 ASSERT_EQ(2, audio_processor->OutputFormat().channels()); |
| 532 | 520 |
| 533 // Construct left and right channels, and assign different values to the | 521 // Construct left and right channels, and assign different values to the |
| 534 // first data of the left channel and right channel. | 522 // first data of the left channel and right channel. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 570 audio_processor->Stop(); | 558 audio_processor->Stop(); |
| 571 } | 559 } |
| 572 | 560 |
| 573 // Disabled on android clang builds due to crbug.com/470499 | 561 // Disabled on android clang builds due to crbug.com/470499 |
| 574 #if defined(__clang__) && defined(OS_ANDROID) | 562 #if defined(__clang__) && defined(OS_ANDROID) |
| 575 #define MAYBE_TestWithKeyboardMicChannel DISABLED_TestWithKeyboardMicChannel | 563 #define MAYBE_TestWithKeyboardMicChannel DISABLED_TestWithKeyboardMicChannel |
| 576 #else | 564 #else |
| 577 #define MAYBE_TestWithKeyboardMicChannel TestWithKeyboardMicChannel | 565 #define MAYBE_TestWithKeyboardMicChannel TestWithKeyboardMicChannel |
| 578 #endif | 566 #endif |
| 579 TEST_F(MediaStreamAudioProcessorTest, MAYBE_TestWithKeyboardMicChannel) { | 567 TEST_F(MediaStreamAudioProcessorTest, MAYBE_TestWithKeyboardMicChannel) { |
| 580 MockConstraintFactory constraint_factory; | |
| 581 constraint_factory.basic().goog_experimental_noise_suppression.SetExact(true); | |
| 582 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | 568 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
| 583 new WebRtcAudioDeviceImpl()); | 569 new WebRtcAudioDeviceImpl()); |
| 570 AudioProcessingProperties properties; | |
|
hbos_chromium
2017/06/16 17:27:14
goog_experimental_noise_suppression is not set to
Guido Urdaneta
2017/06/19 11:56:48
The default value is true on all platforms, so it'
hbos_chromium
2017/06/19 15:14:41
Acknowledged. I'd still like a comment and/or DCHE
| |
| 584 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | 571 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
| 585 new rtc::RefCountedObject<MediaStreamAudioProcessor>( | 572 new rtc::RefCountedObject<MediaStreamAudioProcessor>( |
| 586 constraint_factory.CreateWebMediaConstraints(), input_device_params_, | 573 properties, webrtc_audio_device.get())); |
| 587 webrtc_audio_device.get())); | |
| 588 EXPECT_TRUE(audio_processor->has_audio_processing()); | 574 EXPECT_TRUE(audio_processor->has_audio_processing()); |
| 589 | 575 |
| 590 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 576 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 591 media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC, | 577 media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC, |
| 592 48000, 16, 512); | 578 48000, 16, 512); |
| 593 audio_processor->OnCaptureFormatChanged(params); | 579 audio_processor->OnCaptureFormatChanged(params); |
| 594 | 580 |
| 595 ProcessDataAndVerifyFormat(audio_processor.get(), | 581 ProcessDataAndVerifyFormat(audio_processor.get(), |
| 596 kAudioProcessingSampleRate, | 582 kAudioProcessingSampleRate, |
| 597 kAudioProcessingNumberOfChannel, | 583 kAudioProcessingNumberOfChannel, |
| 598 kAudioProcessingSampleRate / 100); | 584 kAudioProcessingSampleRate / 100); |
| 599 | 585 |
| 600 // Stop |audio_processor| so that it removes itself from | 586 // Stop |audio_processor| so that it removes itself from |
| 601 // |webrtc_audio_device| and clears its pointer to it. | 587 // |webrtc_audio_device| and clears its pointer to it. |
| 602 audio_processor->Stop(); | 588 audio_processor->Stop(); |
| 603 } | 589 } |
| 604 | 590 |
| 605 // Test that the OnAec3Enable method has the desired effect on the APM config. | 591 // Test that the OnAec3Enable method has the desired effect on the APM config. |
| 606 TEST_F(MediaStreamAudioProcessorTest, TestAec3Switch) { | 592 TEST_F(MediaStreamAudioProcessorTest, TestAec3Switch) { |
| 607 MockConstraintFactory constraint_factory; | |
| 608 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | 593 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
| 609 new WebRtcAudioDeviceImpl()); | 594 new WebRtcAudioDeviceImpl()); |
| 595 AudioProcessingProperties properties; | |
| 610 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | 596 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
| 611 new rtc::RefCountedObject<MediaStreamAudioProcessor>( | 597 new rtc::RefCountedObject<MediaStreamAudioProcessor>( |
| 612 constraint_factory.CreateWebMediaConstraints(), input_device_params_, | 598 properties, webrtc_audio_device.get())); |
| 613 webrtc_audio_device.get())); | |
| 614 | 599 |
| 615 audio_processor->OnAec3Enable(true); | 600 audio_processor->OnAec3Enable(true); |
| 616 EXPECT_TRUE(GetAec3ConfigState(audio_processor.get())); | 601 EXPECT_TRUE(GetAec3ConfigState(audio_processor.get())); |
| 617 | 602 |
| 618 audio_processor->OnAec3Enable(false); | 603 audio_processor->OnAec3Enable(false); |
| 619 EXPECT_FALSE(GetAec3ConfigState(audio_processor.get())); | 604 EXPECT_FALSE(GetAec3ConfigState(audio_processor.get())); |
| 620 | 605 |
| 621 // Stop |audio_processor| so that it removes itself from | 606 // Stop |audio_processor| so that it removes itself from |
| 622 // |webrtc_audio_device| and clears its pointer to it. | 607 // |webrtc_audio_device| and clears its pointer to it. |
| 623 audio_processor->Stop(); | 608 audio_processor->Stop(); |
| 624 } | 609 } |
| 625 | 610 |
| 626 // Same test as above, but when AEC is disabled in the constrants. The expected | 611 // Same test as above, but when AEC is disabled in the constrants. The expected |
| 627 // outcome is that AEC3 should be disabled in all cases. | 612 // outcome is that AEC3 should be disabled in all cases. |
| 628 TEST_F(MediaStreamAudioProcessorTest, TestAec3Switch_AecOff) { | 613 TEST_F(MediaStreamAudioProcessorTest, TestAec3Switch_AecOff) { |
| 629 MockConstraintFactory constraint_factory; | |
| 630 // Disable the AEC. | |
| 631 constraint_factory.DisableAecAudioConstraints(); | |
| 632 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | 614 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
| 633 new WebRtcAudioDeviceImpl()); | 615 new WebRtcAudioDeviceImpl()); |
| 616 AudioProcessingProperties properties; | |
| 617 // Disable the AEC. | |
| 618 properties.enable_sw_echo_cancellation = false; | |
| 634 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | 619 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
| 635 new rtc::RefCountedObject<MediaStreamAudioProcessor>( | 620 new rtc::RefCountedObject<MediaStreamAudioProcessor>( |
| 636 constraint_factory.CreateWebMediaConstraints(), input_device_params_, | 621 properties, webrtc_audio_device.get())); |
| 637 webrtc_audio_device.get())); | |
| 638 | 622 |
| 639 EXPECT_FALSE(GetAec3ConfigState(audio_processor.get())); | 623 EXPECT_FALSE(GetAec3ConfigState(audio_processor.get())); |
| 640 | 624 |
| 641 audio_processor->OnAec3Enable(true); | 625 audio_processor->OnAec3Enable(true); |
| 642 EXPECT_FALSE(GetAec3ConfigState(audio_processor.get())); | 626 EXPECT_FALSE(GetAec3ConfigState(audio_processor.get())); |
| 643 | 627 |
| 644 audio_processor->OnAec3Enable(false); | 628 audio_processor->OnAec3Enable(false); |
| 645 EXPECT_FALSE(GetAec3ConfigState(audio_processor.get())); | 629 EXPECT_FALSE(GetAec3ConfigState(audio_processor.get())); |
| 646 | 630 |
| 647 // Stop |audio_processor| so that it removes itself from | 631 // Stop |audio_processor| so that it removes itself from |
| 648 // |webrtc_audio_device| and clears its pointer to it. | 632 // |webrtc_audio_device| and clears its pointer to it. |
| 649 audio_processor->Stop(); | 633 audio_processor->Stop(); |
| 650 } | 634 } |
| 651 | 635 |
| 652 } // namespace content | 636 } // namespace content |
| OLD | NEW |