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