| 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 "content/renderer/media/media_stream_audio_processor_options.h" | 5 #include "content/renderer/media/media_stream_audio_processor_options.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/feature_list.h" |
| 10 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 11 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
| 17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.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/renderer/media/media_stream_constraints_util.h" | 23 #include "content/renderer/media/media_stream_constraints_util.h" |
| 22 #include "content/renderer/media/media_stream_source.h" | 24 #include "content/renderer/media/media_stream_source.h" |
| 23 #include "media/base/audio_parameters.h" | 25 #include "media/base/audio_parameters.h" |
| 24 #include "third_party/webrtc/modules/audio_processing/include/audio_processing.h
" | 26 #include "third_party/webrtc/modules/audio_processing/include/audio_processing.h
" |
| 25 #include "third_party/webrtc/modules/audio_processing/typing_detection.h" | 27 #include "third_party/webrtc/modules/audio_processing/typing_detection.h" |
| 26 | 28 |
| 27 namespace content { | 29 namespace content { |
| 28 | 30 |
| 29 const char MediaAudioConstraints::kEchoCancellation[] = "echoCancellation"; | 31 const char MediaAudioConstraints::kEchoCancellation[] = "echoCancellation"; |
| 30 const char MediaAudioConstraints::kGoogEchoCancellation[] = | 32 const char MediaAudioConstraints::kGoogEchoCancellation[] = |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 if (delay_frequency < 0) | 102 if (delay_frequency < 0) |
| 101 return DELAY_BASED_ECHO_QUALITY_INVALID; | 103 return DELAY_BASED_ECHO_QUALITY_INVALID; |
| 102 else if (delay_frequency <= kEchoDelayFrequencyLowerLimit) | 104 else if (delay_frequency <= kEchoDelayFrequencyLowerLimit) |
| 103 return DELAY_BASED_ECHO_QUALITY_GOOD; | 105 return DELAY_BASED_ECHO_QUALITY_GOOD; |
| 104 else if (delay_frequency < kEchoDelayFrequencyUpperLimit) | 106 else if (delay_frequency < kEchoDelayFrequencyUpperLimit) |
| 105 return DELAY_BASED_ECHO_QUALITY_SPURIOUS; | 107 return DELAY_BASED_ECHO_QUALITY_SPURIOUS; |
| 106 else | 108 else |
| 107 return DELAY_BASED_ECHO_QUALITY_BAD; | 109 return DELAY_BASED_ECHO_QUALITY_BAD; |
| 108 } | 110 } |
| 109 | 111 |
| 110 webrtc::Point WebrtcPointFromMediaPoint(const media::Point& point) { | |
| 111 return webrtc::Point(point.x(), point.y(), point.z()); | |
| 112 } | |
| 113 | |
| 114 std::vector<webrtc::Point> WebrtcPointsFromMediaPoints( | |
| 115 const std::vector<media::Point>& points) { | |
| 116 std::vector<webrtc::Point> webrtc_points; | |
| 117 webrtc_points.reserve(webrtc_points.size()); | |
| 118 for (const auto& point : points) | |
| 119 webrtc_points.push_back(WebrtcPointFromMediaPoint(point)); | |
| 120 return webrtc_points; | |
| 121 } | |
| 122 | |
| 123 // Scan the basic and advanced constraints until a value is found. | 112 // Scan the basic and advanced constraints until a value is found. |
| 124 // If nothing is found, the default is returned. | 113 // If nothing is found, the default is returned. |
| 125 // Argument 2 is a pointer to class data member. | 114 // Argument 2 is a pointer to class data member. |
| 126 bool ScanConstraintsForBoolean( | 115 bool ScanConstraintsForBoolean( |
| 127 const blink::WebMediaConstraints& constraints, | 116 const blink::WebMediaConstraints& constraints, |
| 128 blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker, | 117 blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker, |
| 129 bool the_default) { | 118 bool the_default) { |
| 130 bool value; | 119 bool value; |
| 131 if (GetConstraintValueAsBoolean(constraints, picker, &value)) { | 120 if (GetConstraintValueAsBoolean(constraints, picker, &value)) { |
| 132 return value; | 121 return value; |
| 133 } | 122 } |
| 134 return the_default; | 123 return the_default; |
| 135 } | 124 } |
| 136 | 125 |
| 137 } // namespace | 126 } // namespace |
| 138 | 127 |
| 139 MediaAudioConstraints::MediaAudioConstraints( | 128 MediaAudioConstraints::MediaAudioConstraints( |
| 140 const blink::WebMediaConstraints& constraints, int effects) | 129 const blink::WebMediaConstraints& constraints, int effects) |
| 141 : constraints_(constraints), | 130 : constraints_(constraints), |
| 142 effects_(effects), | 131 effects_(effects), |
| 143 default_audio_processing_constraint_value_(true) { | 132 default_audio_processing_constraint_value_(true) { |
| 133 DCHECK(IsOldAudioConstraints()); |
| 144 // The default audio processing constraints are turned off when | 134 // The default audio processing constraints are turned off when |
| 145 // - gUM has a specific kMediaStreamSource, which is used by tab capture | 135 // - gUM has a specific kMediaStreamSource, which is used by tab capture |
| 146 // and screen capture. | 136 // and screen capture. |
| 147 // - |kEchoCancellation| is explicitly set to false. | 137 // - |kEchoCancellation| is explicitly set to false. |
| 148 bool echo_constraint; | 138 bool echo_constraint; |
| 149 std::string source_string; | 139 std::string source_string; |
| 150 if (GetConstraintValueAsString( | 140 if (GetConstraintValueAsString( |
| 151 constraints, &blink::WebMediaTrackConstraintSet::media_stream_source, | 141 constraints, &blink::WebMediaTrackConstraintSet::media_stream_source, |
| 152 &source_string) || | 142 &source_string) || |
| 153 (GetConstraintValueAsBoolean( | 143 (GetConstraintValueAsBoolean( |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 AudioProcessingProperties::AudioProcessingProperties( | 269 AudioProcessingProperties::AudioProcessingProperties( |
| 280 const AudioProcessingProperties& other) = default; | 270 const AudioProcessingProperties& other) = default; |
| 281 AudioProcessingProperties& AudioProcessingProperties::operator=( | 271 AudioProcessingProperties& AudioProcessingProperties::operator=( |
| 282 const AudioProcessingProperties& other) = default; | 272 const AudioProcessingProperties& other) = default; |
| 283 AudioProcessingProperties::AudioProcessingProperties( | 273 AudioProcessingProperties::AudioProcessingProperties( |
| 284 AudioProcessingProperties&& other) = default; | 274 AudioProcessingProperties&& other) = default; |
| 285 AudioProcessingProperties& AudioProcessingProperties::operator=( | 275 AudioProcessingProperties& AudioProcessingProperties::operator=( |
| 286 AudioProcessingProperties&& other) = default; | 276 AudioProcessingProperties&& other) = default; |
| 287 AudioProcessingProperties::~AudioProcessingProperties() = default; | 277 AudioProcessingProperties::~AudioProcessingProperties() = default; |
| 288 | 278 |
| 279 void AudioProcessingProperties::DisableDefaultPropertiesForTesting() { |
| 280 enable_sw_echo_cancellation = false; |
| 281 goog_auto_gain_control = false; |
| 282 goog_experimental_echo_cancellation = false; |
| 283 goog_typing_noise_detection = false; |
| 284 goog_noise_suppression = false; |
| 285 goog_experimental_noise_suppression = false; |
| 286 goog_beamforming = false; |
| 287 goog_highpass_filter = false; |
| 288 goog_experimental_auto_gain_control = false; |
| 289 } |
| 290 |
| 291 // static |
| 292 AudioProcessingProperties AudioProcessingProperties::FromConstraints( |
| 293 const blink::WebMediaConstraints& constraints, |
| 294 const MediaStreamDevice::AudioDeviceParameters& input_params) { |
| 295 DCHECK(IsOldAudioConstraints()); |
| 296 MediaAudioConstraints audio_constraints(constraints, input_params.effects); |
| 297 AudioProcessingProperties properties; |
| 298 properties.enable_sw_echo_cancellation = |
| 299 audio_constraints.GetEchoCancellationProperty(); |
| 300 // |properties.disable_hw_echo_cancellation| is not used when |
| 301 // IsOldAudioConstraints() is true. |
| 302 properties.goog_audio_mirroring = audio_constraints.GetGoogAudioMirroring(); |
| 303 properties.goog_auto_gain_control = |
| 304 audio_constraints.GetGoogAutoGainControl(); |
| 305 properties.goog_experimental_echo_cancellation = |
| 306 audio_constraints.GetGoogExperimentalEchoCancellation(); |
| 307 properties.goog_typing_noise_detection = |
| 308 audio_constraints.GetGoogTypingNoiseDetection(); |
| 309 properties.goog_noise_suppression = |
| 310 audio_constraints.GetGoogNoiseSuppression(); |
| 311 properties.goog_experimental_noise_suppression = |
| 312 audio_constraints.GetGoogExperimentalNoiseSuppression(); |
| 313 properties.goog_beamforming = audio_constraints.GetGoogBeamforming(); |
| 314 properties.goog_highpass_filter = audio_constraints.GetGoogHighpassFilter(); |
| 315 properties.goog_experimental_auto_gain_control = |
| 316 audio_constraints.GetGoogExperimentalAutoGainControl(); |
| 317 properties.goog_array_geometry = |
| 318 GetArrayGeometryPreferringConstraints(audio_constraints, input_params); |
| 319 |
| 320 return properties; |
| 321 } |
| 322 |
| 289 EchoInformation::EchoInformation() | 323 EchoInformation::EchoInformation() |
| 290 : delay_stats_time_ms_(0), | 324 : delay_stats_time_ms_(0), |
| 291 echo_frames_received_(false), | 325 echo_frames_received_(false), |
| 292 divergent_filter_stats_time_ms_(0), | 326 divergent_filter_stats_time_ms_(0), |
| 293 num_divergent_filter_fraction_(0), | 327 num_divergent_filter_fraction_(0), |
| 294 num_non_zero_divergent_filter_fraction_(0) {} | 328 num_non_zero_divergent_filter_fraction_(0) {} |
| 295 | 329 |
| 296 EchoInformation::~EchoInformation() { | 330 EchoInformation::~EchoInformation() { |
| 297 DCHECK(thread_checker_.CalledOnValidThread()); | 331 DCHECK(thread_checker_.CalledOnValidThread()); |
| 298 ReportAndResetAecDivergentFilterStats(); | 332 ReportAndResetAecDivergentFilterStats(); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 stats->aec_divergent_filter_fraction = apm_stats.divergent_filter_fraction; | 509 stats->aec_divergent_filter_fraction = apm_stats.divergent_filter_fraction; |
| 476 | 510 |
| 477 stats->echo_delay_median_ms = apm_stats.delay_median; | 511 stats->echo_delay_median_ms = apm_stats.delay_median; |
| 478 stats->echo_delay_std_ms = apm_stats.delay_standard_deviation; | 512 stats->echo_delay_std_ms = apm_stats.delay_standard_deviation; |
| 479 | 513 |
| 480 stats->residual_echo_likelihood = apm_stats.residual_echo_likelihood; | 514 stats->residual_echo_likelihood = apm_stats.residual_echo_likelihood; |
| 481 stats->residual_echo_likelihood_recent_max = | 515 stats->residual_echo_likelihood_recent_max = |
| 482 apm_stats.residual_echo_likelihood_recent_max; | 516 apm_stats.residual_echo_likelihood_recent_max; |
| 483 } | 517 } |
| 484 | 518 |
| 485 std::vector<webrtc::Point> GetArrayGeometryPreferringConstraints( | 519 std::vector<media::Point> GetArrayGeometryPreferringConstraints( |
| 486 const MediaAudioConstraints& audio_constraints, | 520 const MediaAudioConstraints& audio_constraints, |
| 487 const MediaStreamDevice::AudioDeviceParameters& input_params) { | 521 const MediaStreamDevice::AudioDeviceParameters& input_params) { |
| 488 const std::string constraints_geometry = | 522 const std::string constraints_geometry = |
| 489 audio_constraints.GetGoogArrayGeometry(); | 523 audio_constraints.GetGoogArrayGeometry(); |
| 490 | 524 |
| 491 // Give preference to the audio constraint over the device-supplied mic | 525 // Give preference to the audio constraint over the device-supplied mic |
| 492 // positions. This is mainly for testing purposes. | 526 // positions. This is mainly for testing purposes. |
| 493 return WebrtcPointsFromMediaPoints( | 527 return constraints_geometry.empty() |
| 494 constraints_geometry.empty() | 528 ? input_params.mic_positions |
| 495 ? input_params.mic_positions | 529 : media::ParsePointsFromString(constraints_geometry); |
| 496 : media::ParsePointsFromString(constraints_geometry)); | 530 } |
| 531 |
| 532 bool IsOldAudioConstraints() { |
| 533 return base::FeatureList::IsEnabled( |
| 534 features::kMediaStreamOldAudioConstraints); |
| 497 } | 535 } |
| 498 | 536 |
| 499 } // namespace content | 537 } // namespace content |
| OLD | NEW |