| 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 "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 bool IsAudioProcessingConstraint(const std::string& key) { | 71 bool IsAudioProcessingConstraint(const std::string& key) { |
| 72 // |kMediaStreamAudioDucking| does not require audio processing. | 72 // |kMediaStreamAudioDucking| does not require audio processing. |
| 73 return key != kMediaStreamAudioDucking; | 73 return key != kMediaStreamAudioDucking; |
| 74 } | 74 } |
| 75 | 75 |
| 76 } // namespace | 76 } // namespace |
| 77 | 77 |
| 78 // TODO(xians): Remove this method after the APM in WebRtc is deprecated. | 78 // TODO(xians): Remove this method after the APM in WebRtc is deprecated. |
| 79 void MediaAudioConstraints::ApplyFixedAudioConstraints( | 79 void MediaAudioConstraints::ApplyFixedAudioConstraints( |
| 80 RTCMediaConstraints* constraints) { | 80 RTCMediaConstraints* constraints) { |
| 81 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { | 81 for (size_t i = 0; i < arraysize(kDefaultAudioConstraints); ++i) { |
| 82 bool already_set_value; | 82 bool already_set_value; |
| 83 if (!webrtc::FindConstraint(constraints, kDefaultAudioConstraints[i].key, | 83 if (!webrtc::FindConstraint(constraints, kDefaultAudioConstraints[i].key, |
| 84 &already_set_value, NULL)) { | 84 &already_set_value, NULL)) { |
| 85 const std::string value = kDefaultAudioConstraints[i].value ? | 85 const std::string value = kDefaultAudioConstraints[i].value ? |
| 86 webrtc::MediaConstraintsInterface::kValueTrue : | 86 webrtc::MediaConstraintsInterface::kValueTrue : |
| 87 webrtc::MediaConstraintsInterface::kValueFalse; | 87 webrtc::MediaConstraintsInterface::kValueFalse; |
| 88 constraints->AddOptional(kDefaultAudioConstraints[i].key, value, false); | 88 constraints->AddOptional(kDefaultAudioConstraints[i].key, value, false); |
| 89 } else { | 89 } else { |
| 90 DVLOG(1) << "Constraint " << kDefaultAudioConstraints[i].key | 90 DVLOG(1) << "Constraint " << kDefaultAudioConstraints[i].key |
| 91 << " already set to " << already_set_value; | 91 << " already set to " << already_set_value; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 | 114 |
| 115 MediaAudioConstraints::~MediaAudioConstraints() {} | 115 MediaAudioConstraints::~MediaAudioConstraints() {} |
| 116 | 116 |
| 117 // TODO(xians): Remove this method after the APM in WebRtc is deprecated. | 117 // TODO(xians): Remove this method after the APM in WebRtc is deprecated. |
| 118 bool MediaAudioConstraints::NeedsAudioProcessing() { | 118 bool MediaAudioConstraints::NeedsAudioProcessing() { |
| 119 if (GetEchoCancellationProperty()) | 119 if (GetEchoCancellationProperty()) |
| 120 return true; | 120 return true; |
| 121 | 121 |
| 122 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { | 122 for (size_t i = 0; i < arraysize(kDefaultAudioConstraints); ++i) { |
| 123 // |kEchoCancellation| and |kGoogEchoCancellation| have been convered by | 123 // |kEchoCancellation| and |kGoogEchoCancellation| have been convered by |
| 124 // GetEchoCancellationProperty(). | 124 // GetEchoCancellationProperty(). |
| 125 if (kDefaultAudioConstraints[i].key != kEchoCancellation && | 125 if (kDefaultAudioConstraints[i].key != kEchoCancellation && |
| 126 kDefaultAudioConstraints[i].key != kGoogEchoCancellation && | 126 kDefaultAudioConstraints[i].key != kGoogEchoCancellation && |
| 127 IsAudioProcessingConstraint(kDefaultAudioConstraints[i].key) && | 127 IsAudioProcessingConstraint(kDefaultAudioConstraints[i].key) && |
| 128 GetProperty(kDefaultAudioConstraints[i].key)) { | 128 GetProperty(kDefaultAudioConstraints[i].key)) { |
| 129 return true; | 129 return true; |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 162 constraints_.getMandatoryConstraints(mandatory); | 162 constraints_.getMandatoryConstraints(mandatory); |
| 163 for (size_t i = 0; i < mandatory.size(); ++i) { | 163 for (size_t i = 0; i < mandatory.size(); ++i) { |
| 164 const std::string key = mandatory[i].m_name.utf8(); | 164 const std::string key = mandatory[i].m_name.utf8(); |
| 165 if (key == kMediaStreamSource || key == kMediaStreamSourceId || | 165 if (key == kMediaStreamSource || key == kMediaStreamSourceId || |
| 166 key == MediaStreamSource::kSourceId) { | 166 key == MediaStreamSource::kSourceId) { |
| 167 // Ignore Chrome specific Tab capture and |kSourceId| constraints. | 167 // Ignore Chrome specific Tab capture and |kSourceId| constraints. |
| 168 continue; | 168 continue; |
| 169 } | 169 } |
| 170 | 170 |
| 171 bool valid = false; | 171 bool valid = false; |
| 172 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++j) { | 172 for (size_t j = 0; j < arraysize(kDefaultAudioConstraints); ++j) { |
| 173 if (key == kDefaultAudioConstraints[j].key) { | 173 if (key == kDefaultAudioConstraints[j].key) { |
| 174 bool value = false; | 174 bool value = false; |
| 175 valid = GetMandatoryConstraintValueAsBoolean(constraints_, key, &value); | 175 valid = GetMandatoryConstraintValueAsBoolean(constraints_, key, &value); |
| 176 break; | 176 break; |
| 177 } | 177 } |
| 178 } | 178 } |
| 179 | 179 |
| 180 if (!valid) { | 180 if (!valid) { |
| 181 DLOG(ERROR) << "Invalid MediaStream constraint. Name: " << key; | 181 DLOG(ERROR) << "Invalid MediaStream constraint. Name: " << key; |
| 182 return false; | 182 return false; |
| 183 } | 183 } |
| 184 } | 184 } |
| 185 | 185 |
| 186 return true; | 186 return true; |
| 187 } | 187 } |
| 188 | 188 |
| 189 bool MediaAudioConstraints::GetDefaultValueForConstraint( | 189 bool MediaAudioConstraints::GetDefaultValueForConstraint( |
| 190 const blink::WebMediaConstraints& constraints, const std::string& key) { | 190 const blink::WebMediaConstraints& constraints, const std::string& key) { |
| 191 // |kMediaStreamAudioDucking| is not restricted by | 191 // |kMediaStreamAudioDucking| is not restricted by |
| 192 // |default_audio_processing_constraint_value_| since it does not require | 192 // |default_audio_processing_constraint_value_| since it does not require |
| 193 // audio processing. | 193 // audio processing. |
| 194 if (!default_audio_processing_constraint_value_ && | 194 if (!default_audio_processing_constraint_value_ && |
| 195 IsAudioProcessingConstraint(key)) | 195 IsAudioProcessingConstraint(key)) |
| 196 return false; | 196 return false; |
| 197 | 197 |
| 198 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { | 198 for (size_t i = 0; i < arraysize(kDefaultAudioConstraints); ++i) { |
| 199 if (kDefaultAudioConstraints[i].key == key) | 199 if (kDefaultAudioConstraints[i].key == key) |
| 200 return kDefaultAudioConstraints[i].value; | 200 return kDefaultAudioConstraints[i].value; |
| 201 } | 201 } |
| 202 | 202 |
| 203 return false; | 203 return false; |
| 204 } | 204 } |
| 205 | 205 |
| 206 void EnableEchoCancellation(AudioProcessing* audio_processing) { | 206 void EnableEchoCancellation(AudioProcessing* audio_processing) { |
| 207 #if defined(OS_ANDROID) || defined(OS_IOS) | 207 #if defined(OS_ANDROID) || defined(OS_IOS) |
| 208 const std::string group_name = | 208 const std::string group_name = |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 } | 311 } |
| 312 | 312 |
| 313 int median = 0, std = 0; | 313 int median = 0, std = 0; |
| 314 if (!audio_processing->echo_cancellation()->GetDelayMetrics(&median, &std)) { | 314 if (!audio_processing->echo_cancellation()->GetDelayMetrics(&median, &std)) { |
| 315 stats->echo_delay_median_ms = median; | 315 stats->echo_delay_median_ms = median; |
| 316 stats->echo_delay_std_ms = std; | 316 stats->echo_delay_std_ms = std; |
| 317 } | 317 } |
| 318 } | 318 } |
| 319 | 319 |
| 320 } // namespace content | 320 } // namespace content |
| OLD | NEW |