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 // static |
| 280 AudioProcessingProperties AudioProcessingProperties::FromConstraints( |
| 281 const blink::WebMediaConstraints& constraints, |
| 282 const MediaStreamDevice::AudioDeviceParameters& input_params) { |
| 283 DCHECK(IsOldAudioConstraints()); |
| 284 MediaAudioConstraints audio_constraints(constraints, input_params.effects); |
| 285 AudioProcessingProperties properties; |
| 286 properties.enable_sw_echo_cancellation = |
| 287 audio_constraints.GetEchoCancellationProperty(); |
| 288 // |properties.disable_hw_echo_cancellation| is not used when |
| 289 // IsOldAudioConstraints() is true. |
| 290 properties.goog_audio_mirroring = audio_constraints.GetGoogAudioMirroring(); |
| 291 properties.goog_auto_gain_control = |
| 292 audio_constraints.GetGoogAutoGainControl(); |
| 293 properties.goog_experimental_echo_cancellation = |
| 294 audio_constraints.GetGoogExperimentalEchoCancellation(); |
| 295 properties.goog_typing_noise_detection = |
| 296 audio_constraints.GetGoogTypingNoiseDetection(); |
| 297 properties.goog_noise_suppression = |
| 298 audio_constraints.GetGoogNoiseSuppression(); |
| 299 properties.goog_experimental_noise_suppression = |
| 300 audio_constraints.GetGoogExperimentalNoiseSuppression(); |
| 301 properties.goog_beamforming = audio_constraints.GetGoogBeamforming(); |
| 302 properties.goog_highpass_filter = audio_constraints.GetGoogHighpassFilter(); |
| 303 properties.goog_experimental_auto_gain_control = |
| 304 audio_constraints.GetGoogExperimentalAutoGainControl(); |
| 305 properties.goog_array_geometry = |
| 306 GetArrayGeometryPreferringConstraints(audio_constraints, input_params); |
| 307 |
| 308 return properties; |
| 309 } |
| 310 |
289 EchoInformation::EchoInformation() | 311 EchoInformation::EchoInformation() |
290 : delay_stats_time_ms_(0), | 312 : delay_stats_time_ms_(0), |
291 echo_frames_received_(false), | 313 echo_frames_received_(false), |
292 divergent_filter_stats_time_ms_(0), | 314 divergent_filter_stats_time_ms_(0), |
293 num_divergent_filter_fraction_(0), | 315 num_divergent_filter_fraction_(0), |
294 num_non_zero_divergent_filter_fraction_(0) {} | 316 num_non_zero_divergent_filter_fraction_(0) {} |
295 | 317 |
296 EchoInformation::~EchoInformation() { | 318 EchoInformation::~EchoInformation() { |
297 DCHECK(thread_checker_.CalledOnValidThread()); | 319 DCHECK(thread_checker_.CalledOnValidThread()); |
298 ReportAndResetAecDivergentFilterStats(); | 320 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; | 497 stats->aec_divergent_filter_fraction = apm_stats.divergent_filter_fraction; |
476 | 498 |
477 stats->echo_delay_median_ms = apm_stats.delay_median; | 499 stats->echo_delay_median_ms = apm_stats.delay_median; |
478 stats->echo_delay_std_ms = apm_stats.delay_standard_deviation; | 500 stats->echo_delay_std_ms = apm_stats.delay_standard_deviation; |
479 | 501 |
480 stats->residual_echo_likelihood = apm_stats.residual_echo_likelihood; | 502 stats->residual_echo_likelihood = apm_stats.residual_echo_likelihood; |
481 stats->residual_echo_likelihood_recent_max = | 503 stats->residual_echo_likelihood_recent_max = |
482 apm_stats.residual_echo_likelihood_recent_max; | 504 apm_stats.residual_echo_likelihood_recent_max; |
483 } | 505 } |
484 | 506 |
485 std::vector<webrtc::Point> GetArrayGeometryPreferringConstraints( | 507 std::vector<media::Point> GetArrayGeometryPreferringConstraints( |
486 const MediaAudioConstraints& audio_constraints, | 508 const MediaAudioConstraints& audio_constraints, |
487 const MediaStreamDevice::AudioDeviceParameters& input_params) { | 509 const MediaStreamDevice::AudioDeviceParameters& input_params) { |
488 const std::string constraints_geometry = | 510 const std::string constraints_geometry = |
489 audio_constraints.GetGoogArrayGeometry(); | 511 audio_constraints.GetGoogArrayGeometry(); |
490 | 512 |
491 // Give preference to the audio constraint over the device-supplied mic | 513 // Give preference to the audio constraint over the device-supplied mic |
492 // positions. This is mainly for testing purposes. | 514 // positions. This is mainly for testing purposes. |
493 return WebrtcPointsFromMediaPoints( | 515 return constraints_geometry.empty() |
494 constraints_geometry.empty() | 516 ? input_params.mic_positions |
495 ? input_params.mic_positions | 517 : media::ParsePointsFromString(constraints_geometry); |
496 : media::ParsePointsFromString(constraints_geometry)); | 518 } |
| 519 |
| 520 bool IsOldAudioConstraints() { |
| 521 return base::FeatureList::IsEnabled( |
| 522 features::kMediaStreamOldAudioConstraints); |
497 } | 523 } |
498 | 524 |
499 } // namespace content | 525 } // namespace content |
OLD | NEW |