Chromium Code Reviews| 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/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/strings/string_number_conversions.h" | |
| 10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 11 #include "content/common/media/media_stream_options.h" | 12 #include "content/common/media/media_stream_options.h" |
| 13 #include "content/renderer/media/media_stream_constraints_util.h" | |
| 12 #include "content/renderer/media/rtc_media_constraints.h" | 14 #include "content/renderer/media/rtc_media_constraints.h" |
| 13 #include "media/audio/audio_parameters.h" | 15 #include "media/audio/audio_parameters.h" |
| 14 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 16 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| 15 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface .h" | |
| 16 #include "third_party/webrtc/modules/audio_processing/include/audio_processing.h " | 17 #include "third_party/webrtc/modules/audio_processing/include/audio_processing.h " |
| 17 #include "third_party/webrtc/modules/audio_processing/typing_detection.h" | 18 #include "third_party/webrtc/modules/audio_processing/typing_detection.h" |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 | 21 |
| 22 const char kEchoCancellation[] = "echoCancellation"; | |
| 23 const char kGoogEchoCancellation[] = "googEchoCancellation"; | |
| 24 const char kGoogExperimentalEchoCancellation[] = "googEchoCancellation2"; | |
| 25 const char kGoogAutoGainControl[] = "googAutoGainControl"; | |
| 26 const char kGoogExperimentalAutoGainControl[] = "googAutoGainControl2"; | |
| 27 const char kGoogNoiseSuppression[] = "googNoiseSuppression"; | |
| 28 const char kGoogExperimentalNoiseSuppression[] = "googNoiseSuppression2"; | |
| 29 const char kGoogHighpassFilter[] = "googHighpassFilter"; | |
| 30 const char kGoogTypingNoiseDetection[] = "googTypingNoiseDetection"; | |
| 31 const char kGoogAudioMirroring[] = "googAudioMirroring"; | |
| 32 | |
| 21 namespace { | 33 namespace { |
| 22 | 34 |
| 23 // Constant constraint keys which enables default audio constraints on | 35 // Constant constraint keys which enables default audio constraints on |
| 24 // mediastreams with audio. | 36 // mediastreams with audio. |
| 25 struct { | 37 struct { |
| 26 const char* key; | 38 const char* key; |
| 27 const char* value; | 39 bool value; |
| 28 } const kDefaultAudioConstraints[] = { | 40 } const kDefaultAudioConstraints[] = { |
| 29 { webrtc::MediaConstraintsInterface::kEchoCancellation, | 41 { kEchoCancellation, true }, |
| 30 webrtc::MediaConstraintsInterface::kValueTrue }, | 42 { kGoogEchoCancellation, true }, |
| 31 #if defined(OS_CHROMEOS) || defined(OS_MACOSX) | 43 #if defined(OS_CHROMEOS) || defined(OS_MACOSX) |
| 32 // Enable the extended filter mode AEC on platforms with known echo issues. | 44 // Enable the extended filter mode AEC on platforms with known echo issues. |
| 33 { webrtc::MediaConstraintsInterface::kExperimentalEchoCancellation, | 45 { kGoogExperimentalEchoCancellation, true }, |
| 34 webrtc::MediaConstraintsInterface::kValueTrue }, | 46 #else |
| 47 { kGoogExperimentalEchoCancellation, false }, | |
| 35 #endif | 48 #endif |
| 36 { webrtc::MediaConstraintsInterface::kAutoGainControl, | 49 { kGoogAutoGainControl, true }, |
| 37 webrtc::MediaConstraintsInterface::kValueTrue }, | 50 { kGoogExperimentalAutoGainControl, true }, |
| 38 { webrtc::MediaConstraintsInterface::kExperimentalAutoGainControl, | 51 { kGoogNoiseSuppression, true }, |
| 39 webrtc::MediaConstraintsInterface::kValueTrue }, | 52 { kGoogHighpassFilter, true }, |
| 40 { webrtc::MediaConstraintsInterface::kNoiseSuppression, | 53 { kGoogTypingNoiseDetection, true }, |
| 41 webrtc::MediaConstraintsInterface::kValueTrue }, | |
| 42 { webrtc::MediaConstraintsInterface::kHighpassFilter, | |
| 43 webrtc::MediaConstraintsInterface::kValueTrue }, | |
| 44 { webrtc::MediaConstraintsInterface::kTypingNoiseDetection, | |
| 45 webrtc::MediaConstraintsInterface::kValueTrue }, | |
| 46 #if defined(OS_WIN) | 54 #if defined(OS_WIN) |
| 47 { content::kMediaStreamAudioDucking, | 55 { kMediaStreamAudioDucking, true }, |
| 48 webrtc::MediaConstraintsInterface::kValueTrue }, | 56 #else |
| 57 { kMediaStreamAudioDucking, false }, | |
| 49 #endif | 58 #endif |
| 50 }; | 59 }; |
| 51 | 60 |
| 61 bool GetDefaultValueForConstraint(const blink::WebMediaConstraints& constraints, | |
| 62 const std::string& key) { | |
| 63 // Audio processing is false for gUM of non-default kMediaStreamSource. | |
|
perkj_chrome
2014/04/11 11:45:04
? of non-default ? isn't kMediaStreamSource always
no longer working on chromium
2014/04/11 16:47:05
changed the comment to
// The default audio proces
perkj_chrome
2014/04/14 12:15:19
Please explain what kMediaStreamSource is. The na
| |
| 64 std::string value; | |
| 65 if (GetConstraintValue(constraints, kMediaStreamSource, &value)) | |
| 66 return false; | |
| 67 | |
| 68 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { | |
| 69 if (kDefaultAudioConstraints[i].key == key) | |
| 70 return kDefaultAudioConstraints[i].value; | |
| 71 } | |
| 72 | |
| 73 return false; | |
| 74 } | |
| 75 | |
| 52 } // namespace | 76 } // namespace |
| 53 | 77 |
| 78 // TODO(xians): Remove this method after the APM in WebRtc is deprecated. | |
| 54 void ApplyFixedAudioConstraints(RTCMediaConstraints* constraints) { | 79 void ApplyFixedAudioConstraints(RTCMediaConstraints* constraints) { |
| 55 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { | 80 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { |
| 56 bool already_set_value; | 81 bool already_set_value; |
| 57 if (!webrtc::FindConstraint(constraints, kDefaultAudioConstraints[i].key, | 82 if (!webrtc::FindConstraint(constraints, kDefaultAudioConstraints[i].key, |
| 58 &already_set_value, NULL)) { | 83 &already_set_value, NULL)) { |
| 59 constraints->AddOptional(kDefaultAudioConstraints[i].key, | 84 const std::string value = kDefaultAudioConstraints[i].value ? |
| 60 kDefaultAudioConstraints[i].value, false); | 85 webrtc::MediaConstraintsInterface::kValueTrue : |
| 86 webrtc::MediaConstraintsInterface::kValueFalse; | |
| 87 constraints->AddOptional(kDefaultAudioConstraints[i].key, value, false); | |
| 61 } else { | 88 } else { |
| 62 DVLOG(1) << "Constraint " << kDefaultAudioConstraints[i].key | 89 DVLOG(1) << "Constraint " << kDefaultAudioConstraints[i].key |
| 63 << " already set to " << already_set_value; | 90 << " already set to " << already_set_value; |
| 64 } | 91 } |
| 65 } | 92 } |
| 66 } | 93 } |
| 67 | 94 |
| 95 // TODO(xians): Remove this method after the APM in WebRtc is deprecated. | |
| 68 bool NeedsAudioProcessing(const blink::WebMediaConstraints& constraints, | 96 bool NeedsAudioProcessing(const blink::WebMediaConstraints& constraints, |
| 69 int effects) { | 97 int effects) { |
| 70 RTCMediaConstraints native_constraints(constraints); | |
| 71 ApplyFixedAudioConstraints(&native_constraints); | |
| 72 if (effects & media::AudioParameters::ECHO_CANCELLER) { | |
| 73 // If platform echo canceller is enabled, disable the software AEC. | |
| 74 native_constraints.AddOptional( | |
| 75 MediaConstraintsInterface::kEchoCancellation, | |
| 76 MediaConstraintsInterface::kValueFalse, true); | |
| 77 } | |
| 78 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { | 98 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { |
| 79 bool value = false; | 99 if (GetPropertyFromConstraints(constraints, |
| 80 if (webrtc::FindConstraint(&native_constraints, | 100 kDefaultAudioConstraints[i].key, |
| 81 kDefaultAudioConstraints[i].key, &value, NULL) && | 101 effects)) { |
| 82 value) { | |
| 83 return true; | 102 return true; |
| 84 } | 103 } |
| 85 } | 104 } |
| 86 | 105 |
| 87 return false; | 106 return false; |
| 88 } | 107 } |
| 89 | 108 |
| 90 bool GetPropertyFromConstraints(const MediaConstraintsInterface* constraints, | 109 bool GetPropertyFromConstraints(const blink::WebMediaConstraints& constraints, |
| 91 const std::string& key) { | 110 const std::string& key, |
| 111 int effects) { | |
| 112 if (effects & media::AudioParameters::ECHO_CANCELLER && | |
| 113 key == kGoogEchoCancellation) { | |
| 114 // If platform echo canceller is enabled, disable the software AEC. | |
| 115 return false; | |
|
no longer working on chromium
2014/04/11 08:56:30
Andrew, could you please take a look at this?
Pre
perkj_chrome
2014/04/11 11:45:04
Forgot to add Andrew?
no longer working on chromium
2014/04/11 16:47:05
Thanks.
| |
| 116 } | |
| 117 | |
| 118 // Return the value if the constraint is specified in |constraints|, | |
| 119 // otherwise return the default value. | |
| 92 bool value = false; | 120 bool value = false; |
| 93 return webrtc::FindConstraint(constraints, key, &value, NULL) && value; | 121 if (!GetConstraintValue(constraints, key, &value)) |
| 122 value = GetDefaultValueForConstraint(constraints, key); | |
| 123 | |
| 124 return value; | |
| 125 } | |
| 126 | |
| 127 bool IsValid(const blink::WebMediaConstraints& constraints) { | |
| 128 blink::WebVector<blink::WebMediaConstraint> mandatory; | |
| 129 constraints.getMandatoryConstraints(mandatory); | |
| 130 for (size_t i = 0; i < mandatory.size(); ++i) { | |
| 131 if (mandatory[i].m_name.utf8() == kMediaStreamSource) | |
| 132 continue; | |
| 133 | |
| 134 bool valid = false; | |
| 135 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++j) { | |
| 136 if (mandatory[i].m_name.utf8() == kDefaultAudioConstraints[j].key) { | |
| 137 valid = true; | |
| 138 break; | |
| 139 } | |
| 140 } | |
| 141 | |
| 142 if (!valid) { | |
| 143 DLOG(ERROR) << "Invalid MediaStream constraint. Name:" | |
| 144 << mandatory[i].m_name.utf8(); | |
| 145 return false; | |
| 146 } | |
| 147 } | |
| 148 | |
| 149 return true; | |
| 94 } | 150 } |
| 95 | 151 |
| 96 void EnableEchoCancellation(AudioProcessing* audio_processing) { | 152 void EnableEchoCancellation(AudioProcessing* audio_processing) { |
| 97 #if defined(OS_ANDROID) | 153 #if defined(OS_ANDROID) |
| 98 // Mobile devices are using AECM. | 154 // Mobile devices are using AECM. |
| 99 int err = audio_processing->echo_control_mobile()->set_routing_mode( | 155 int err = audio_processing->echo_control_mobile()->set_routing_mode( |
| 100 webrtc::EchoControlMobile::kSpeakerphone); | 156 webrtc::EchoControlMobile::kSpeakerphone); |
| 101 err |= audio_processing->echo_control_mobile()->Enable(true); | 157 err |= audio_processing->echo_control_mobile()->Enable(true); |
| 102 CHECK_EQ(err, 0); | 158 CHECK_EQ(err, 0); |
| 103 #else | 159 #else |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 } | 263 } |
| 208 | 264 |
| 209 int median = 0, std = 0; | 265 int median = 0, std = 0; |
| 210 if (!audio_processing->echo_cancellation()->GetDelayMetrics(&median, &std)) { | 266 if (!audio_processing->echo_cancellation()->GetDelayMetrics(&median, &std)) { |
| 211 stats->echo_delay_median_ms = median; | 267 stats->echo_delay_median_ms = median; |
| 212 stats->echo_delay_std_ms = std; | 268 stats->echo_delay_std_ms = std; |
| 213 } | 269 } |
| 214 } | 270 } |
| 215 | 271 |
| 216 } // namespace content | 272 } // namespace content |
| OLD | NEW |