Index: content/renderer/media/media_stream_audio_processor_options.cc |
diff --git a/content/renderer/media/media_stream_audio_processor_options.cc b/content/renderer/media/media_stream_audio_processor_options.cc |
index 320d1a6ba31d8296160a2a67b1c07523aa4d12ef..6ed371188113cf4bdbf55d1f6faf02d448b818b2 100644 |
--- a/content/renderer/media/media_stream_audio_processor_options.cc |
+++ b/content/renderer/media/media_stream_audio_processor_options.cc |
@@ -7,57 +7,84 @@ |
#include "base/files/file_path.h" |
#include "base/logging.h" |
#include "base/path_service.h" |
+#include "base/strings/string_number_conversions.h" |
#include "base/strings/utf_string_conversions.h" |
#include "content/common/media/media_stream_options.h" |
+#include "content/renderer/media/media_stream_constraints_util.h" |
#include "content/renderer/media/rtc_media_constraints.h" |
#include "media/audio/audio_parameters.h" |
#include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
-#include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface.h" |
#include "third_party/webrtc/modules/audio_processing/include/audio_processing.h" |
#include "third_party/webrtc/modules/audio_processing/typing_detection.h" |
namespace content { |
+const char kEchoCancellation[] = "echoCancellation"; |
+const char kGoogEchoCancellation[] = "googEchoCancellation"; |
+const char kGoogExperimentalEchoCancellation[] = "googEchoCancellation2"; |
+const char kGoogAutoGainControl[] = "googAutoGainControl"; |
+const char kGoogExperimentalAutoGainControl[] = "googAutoGainControl2"; |
+const char kGoogNoiseSuppression[] = "googNoiseSuppression"; |
+const char kGoogExperimentalNoiseSuppression[] = "googNoiseSuppression2"; |
+const char kGoogHighpassFilter[] = "googHighpassFilter"; |
+const char kGoogTypingNoiseDetection[] = "googTypingNoiseDetection"; |
+const char kGoogAudioMirroring[] = "googAudioMirroring"; |
+ |
namespace { |
// Constant constraint keys which enables default audio constraints on |
// mediastreams with audio. |
struct { |
const char* key; |
- const char* value; |
+ bool value; |
} const kDefaultAudioConstraints[] = { |
- { webrtc::MediaConstraintsInterface::kEchoCancellation, |
- webrtc::MediaConstraintsInterface::kValueTrue }, |
+ { kEchoCancellation, true }, |
+ { kGoogEchoCancellation, true }, |
#if defined(OS_CHROMEOS) || defined(OS_MACOSX) |
// Enable the extended filter mode AEC on platforms with known echo issues. |
- { webrtc::MediaConstraintsInterface::kExperimentalEchoCancellation, |
- webrtc::MediaConstraintsInterface::kValueTrue }, |
+ { kGoogExperimentalEchoCancellation, true }, |
+#else |
+ { kGoogExperimentalEchoCancellation, false }, |
#endif |
- { webrtc::MediaConstraintsInterface::kAutoGainControl, |
- webrtc::MediaConstraintsInterface::kValueTrue }, |
- { webrtc::MediaConstraintsInterface::kExperimentalAutoGainControl, |
- webrtc::MediaConstraintsInterface::kValueTrue }, |
- { webrtc::MediaConstraintsInterface::kNoiseSuppression, |
- webrtc::MediaConstraintsInterface::kValueTrue }, |
- { webrtc::MediaConstraintsInterface::kHighpassFilter, |
- webrtc::MediaConstraintsInterface::kValueTrue }, |
- { webrtc::MediaConstraintsInterface::kTypingNoiseDetection, |
- webrtc::MediaConstraintsInterface::kValueTrue }, |
+ { kGoogAutoGainControl, true }, |
+ { kGoogExperimentalAutoGainControl, true }, |
+ { kGoogNoiseSuppression, true }, |
+ { kGoogHighpassFilter, true }, |
+ { kGoogTypingNoiseDetection, true }, |
#if defined(OS_WIN) |
- { content::kMediaStreamAudioDucking, |
- webrtc::MediaConstraintsInterface::kValueTrue }, |
+ { kMediaStreamAudioDucking, true }, |
+#else |
+ { kMediaStreamAudioDucking, false }, |
#endif |
}; |
+bool GetDefaultValueForConstraint(const blink::WebMediaConstraints& constraints, |
+ const std::string& key) { |
+ // 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
|
+ std::string value; |
+ if (GetConstraintValue(constraints, kMediaStreamSource, &value)) |
+ return false; |
+ |
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { |
+ if (kDefaultAudioConstraints[i].key == key) |
+ return kDefaultAudioConstraints[i].value; |
+ } |
+ |
+ return false; |
+} |
+ |
} // namespace |
+// TODO(xians): Remove this method after the APM in WebRtc is deprecated. |
void ApplyFixedAudioConstraints(RTCMediaConstraints* constraints) { |
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { |
bool already_set_value; |
if (!webrtc::FindConstraint(constraints, kDefaultAudioConstraints[i].key, |
&already_set_value, NULL)) { |
- constraints->AddOptional(kDefaultAudioConstraints[i].key, |
- kDefaultAudioConstraints[i].value, false); |
+ const std::string value = kDefaultAudioConstraints[i].value ? |
+ webrtc::MediaConstraintsInterface::kValueTrue : |
+ webrtc::MediaConstraintsInterface::kValueFalse; |
+ constraints->AddOptional(kDefaultAudioConstraints[i].key, value, false); |
} else { |
DVLOG(1) << "Constraint " << kDefaultAudioConstraints[i].key |
<< " already set to " << already_set_value; |
@@ -65,21 +92,13 @@ void ApplyFixedAudioConstraints(RTCMediaConstraints* constraints) { |
} |
} |
+// TODO(xians): Remove this method after the APM in WebRtc is deprecated. |
bool NeedsAudioProcessing(const blink::WebMediaConstraints& constraints, |
int effects) { |
- RTCMediaConstraints native_constraints(constraints); |
- ApplyFixedAudioConstraints(&native_constraints); |
- if (effects & media::AudioParameters::ECHO_CANCELLER) { |
- // If platform echo canceller is enabled, disable the software AEC. |
- native_constraints.AddOptional( |
- MediaConstraintsInterface::kEchoCancellation, |
- MediaConstraintsInterface::kValueFalse, true); |
- } |
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { |
- bool value = false; |
- if (webrtc::FindConstraint(&native_constraints, |
- kDefaultAudioConstraints[i].key, &value, NULL) && |
- value) { |
+ if (GetPropertyFromConstraints(constraints, |
+ kDefaultAudioConstraints[i].key, |
+ effects)) { |
return true; |
} |
} |
@@ -87,10 +106,47 @@ bool NeedsAudioProcessing(const blink::WebMediaConstraints& constraints, |
return false; |
} |
-bool GetPropertyFromConstraints(const MediaConstraintsInterface* constraints, |
- const std::string& key) { |
+bool GetPropertyFromConstraints(const blink::WebMediaConstraints& constraints, |
+ const std::string& key, |
+ int effects) { |
+ if (effects & media::AudioParameters::ECHO_CANCELLER && |
+ key == kGoogEchoCancellation) { |
+ // If platform echo canceller is enabled, disable the software AEC. |
+ 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.
|
+ } |
+ |
+ // Return the value if the constraint is specified in |constraints|, |
+ // otherwise return the default value. |
bool value = false; |
- return webrtc::FindConstraint(constraints, key, &value, NULL) && value; |
+ if (!GetConstraintValue(constraints, key, &value)) |
+ value = GetDefaultValueForConstraint(constraints, key); |
+ |
+ return value; |
+} |
+ |
+bool IsValid(const blink::WebMediaConstraints& constraints) { |
+ blink::WebVector<blink::WebMediaConstraint> mandatory; |
+ constraints.getMandatoryConstraints(mandatory); |
+ for (size_t i = 0; i < mandatory.size(); ++i) { |
+ if (mandatory[i].m_name.utf8() == kMediaStreamSource) |
+ continue; |
+ |
+ bool valid = false; |
+ for (size_t j = 0; j < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++j) { |
+ if (mandatory[i].m_name.utf8() == kDefaultAudioConstraints[j].key) { |
+ valid = true; |
+ break; |
+ } |
+ } |
+ |
+ if (!valid) { |
+ DLOG(ERROR) << "Invalid MediaStream constraint. Name:" |
+ << mandatory[i].m_name.utf8(); |
+ return false; |
+ } |
+ } |
+ |
+ return true; |
} |
void EnableEchoCancellation(AudioProcessing* audio_processing) { |