| 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/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/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 #include "content/common/media/media_stream_options.h" | 20 #include "content/common/media/media_stream_options.h" |
| 21 #include "content/renderer/media/media_stream_source.h" | 21 #include "content/renderer/media/media_stream_source.h" |
| 22 #include "content/renderer/media/rtc_media_constraints.h" | |
| 23 #include "media/audio/audio_parameters.h" | 22 #include "media/audio/audio_parameters.h" |
| 24 #include "third_party/webrtc/modules/audio_processing/include/audio_processing.h
" | 23 #include "third_party/webrtc/modules/audio_processing/include/audio_processing.h
" |
| 25 #include "third_party/webrtc/modules/audio_processing/typing_detection.h" | 24 #include "third_party/webrtc/modules/audio_processing/typing_detection.h" |
| 26 | 25 |
| 27 namespace content { | 26 namespace content { |
| 28 | 27 |
| 29 const char MediaAudioConstraints::kEchoCancellation[] = "echoCancellation"; | 28 const char MediaAudioConstraints::kEchoCancellation[] = "echoCancellation"; |
| 30 const char MediaAudioConstraints::kGoogEchoCancellation[] = | 29 const char MediaAudioConstraints::kGoogEchoCancellation[] = |
| 31 "googEchoCancellation"; | 30 "googEchoCancellation"; |
| 32 const char MediaAudioConstraints::kGoogExperimentalEchoCancellation[] = | 31 const char MediaAudioConstraints::kGoogExperimentalEchoCancellation[] = |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 } | 129 } |
| 131 for (const auto& advanced_constraint : constraints.advanced()) { | 130 for (const auto& advanced_constraint : constraints.advanced()) { |
| 132 const auto& the_field = advanced_constraint.*picker; | 131 const auto& the_field = advanced_constraint.*picker; |
| 133 if (the_field.hasExact()) { | 132 if (the_field.hasExact()) { |
| 134 return the_field.exact(); | 133 return the_field.exact(); |
| 135 } | 134 } |
| 136 } | 135 } |
| 137 return the_default; | 136 return the_default; |
| 138 } | 137 } |
| 139 | 138 |
| 139 void SetIfNotSet(rtc::Optional<bool>* field, bool value) { |
| 140 if (!*field) { |
| 141 *field = rtc::Optional<bool>(value); |
| 142 } |
| 143 } |
| 144 |
| 140 } // namespace | 145 } // namespace |
| 141 | 146 |
| 142 // TODO(xians): Remove this method after the APM in WebRtc is deprecated. | 147 // TODO(xians): Remove this method after the APM in WebRtc is deprecated. |
| 143 void MediaAudioConstraints::ApplyFixedAudioConstraints( | 148 void MediaAudioConstraints::ApplyFixedAudioConstraints( |
| 144 RTCMediaConstraints* constraints) { | 149 cricket::AudioOptions* options) { |
| 145 for (size_t i = 0; i < arraysize(kDefaultAudioConstraints); ++i) { | 150 SetIfNotSet(&options->echo_cancellation, true); |
| 146 bool already_set_value; | 151 #if defined(OS_ANDROID) || defined(OS_IOS) |
| 147 if (!webrtc::FindConstraint(constraints, kDefaultAudioConstraints[i].key, | 152 SetIfNotSet(&options->extended_filter_aec, false); |
| 148 &already_set_value, NULL)) { | 153 #else |
| 149 const std::string value = kDefaultAudioConstraints[i].value ? | 154 // Enable the extended filter mode AEC on all non-mobile platforms. |
| 150 webrtc::MediaConstraintsInterface::kValueTrue : | 155 SetIfNotSet(&options->extended_filter_aec, true); |
| 151 webrtc::MediaConstraintsInterface::kValueFalse; | 156 #endif |
| 152 constraints->AddOptional(kDefaultAudioConstraints[i].key, value, false); | 157 SetIfNotSet(&options->auto_gain_control, true); |
| 153 } else { | 158 SetIfNotSet(&options->experimental_agc, true); |
| 154 DVLOG(1) << "Constraint " << kDefaultAudioConstraints[i].key | 159 SetIfNotSet(&options->noise_suppression, true); |
| 155 << " already set to " << already_set_value; | 160 SetIfNotSet(&options->highpass_filter, true); |
| 156 } | 161 SetIfNotSet(&options->typing_detection, true); |
| 157 } | 162 SetIfNotSet(&options->experimental_ns, true); |
| 158 } | 163 } |
| 159 | 164 |
| 160 MediaAudioConstraints::MediaAudioConstraints( | 165 MediaAudioConstraints::MediaAudioConstraints( |
| 161 const blink::WebMediaConstraints& constraints, int effects) | 166 const blink::WebMediaConstraints& constraints, int effects) |
| 162 : constraints_(constraints), | 167 : constraints_(constraints), |
| 163 effects_(effects), | 168 effects_(effects), |
| 164 default_audio_processing_constraint_value_(true) { | 169 default_audio_processing_constraint_value_(true) { |
| 165 // The default audio processing constraints are turned off when | 170 // The default audio processing constraints are turned off when |
| 166 // - gUM has a specific kMediaStreamSource, which is used by tab capture | 171 // - gUM has a specific kMediaStreamSource, which is used by tab capture |
| 167 // and screen capture. | 172 // and screen capture. |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 | 467 |
| 463 // Give preference to the audio constraint over the device-supplied mic | 468 // Give preference to the audio constraint over the device-supplied mic |
| 464 // positions. This is mainly for testing purposes. | 469 // positions. This is mainly for testing purposes. |
| 465 return WebrtcPointsFromMediaPoints( | 470 return WebrtcPointsFromMediaPoints( |
| 466 constraints_geometry.empty() | 471 constraints_geometry.empty() |
| 467 ? input_params.mic_positions | 472 ? input_params.mic_positions |
| 468 : media::ParsePointsFromString(constraints_geometry)); | 473 : media::ParsePointsFromString(constraints_geometry)); |
| 469 } | 474 } |
| 470 | 475 |
| 471 } // namespace content | 476 } // namespace content |
| OLD | NEW |