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 e1474c029b37ddcf15c6b99892c8b9fa021dcbc9..6c29986781d4104f1236380f117520eab6a135f0 100644 |
--- a/content/renderer/media/media_stream_audio_processor_options.cc |
+++ b/content/renderer/media/media_stream_audio_processor_options.cc |
@@ -8,57 +8,78 @@ |
#include "base/logging.h" |
#include "base/metrics/field_trial.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/media_stream_source.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 MediaAudioConstraints::kEchoCancellation[] = "echoCancellation"; |
+const char MediaAudioConstraints::kGoogEchoCancellation[] = |
+ "googEchoCancellation"; |
+const char MediaAudioConstraints::kGoogExperimentalEchoCancellation[] = |
+ "googEchoCancellation2"; |
+const char MediaAudioConstraints::kGoogAutoGainControl[] = |
+ "googAutoGainControl"; |
+const char MediaAudioConstraints::kGoogExperimentalAutoGainControl[] = |
+ "googAutoGainControl2"; |
+const char MediaAudioConstraints::kGoogNoiseSuppression[] = |
+ "googNoiseSuppression"; |
+const char MediaAudioConstraints::kGoogExperimentalNoiseSuppression[] = |
+ "googNoiseSuppression2"; |
+const char MediaAudioConstraints::kGoogHighpassFilter[] = "googHighpassFilter"; |
+const char MediaAudioConstraints::kGoogTypingNoiseDetection[] = |
+ "googTypingNoiseDetection"; |
+const char MediaAudioConstraints::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 }, |
+ { MediaAudioConstraints::kEchoCancellation, true }, |
+ { MediaAudioConstraints::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 }, |
+ { MediaAudioConstraints::kGoogExperimentalEchoCancellation, true }, |
+#else |
+ { MediaAudioConstraints::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 }, |
+ { MediaAudioConstraints::kGoogAutoGainControl, true }, |
+ { MediaAudioConstraints::kGoogExperimentalAutoGainControl, true }, |
+ { MediaAudioConstraints::kGoogNoiseSuppression, true }, |
+ { MediaAudioConstraints::kGoogHighpassFilter, true }, |
+ { MediaAudioConstraints::kGoogTypingNoiseDetection, true }, |
+ { MediaAudioConstraints::kGoogExperimentalNoiseSuppression, false }, |
#if defined(OS_WIN) |
- { content::kMediaStreamAudioDucking, |
- webrtc::MediaConstraintsInterface::kValueTrue }, |
+ { kMediaStreamAudioDucking, true }, |
+#else |
+ { kMediaStreamAudioDucking, false }, |
#endif |
}; |
} // namespace |
-void ApplyFixedAudioConstraints(RTCMediaConstraints* constraints) { |
+// TODO(xians): Remove this method after the APM in WebRtc is deprecated. |
+void MediaAudioConstraints::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; |
@@ -66,21 +87,40 @@ void ApplyFixedAudioConstraints(RTCMediaConstraints* constraints) { |
} |
} |
-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); |
+MediaAudioConstraints::MediaAudioConstraints( |
+ const blink::WebMediaConstraints& constraints, int effects) |
+ : constraints_(constraints), |
+ effects_(effects), |
+ turn_off_constraints_as_default_(false) { |
+ // The default audio processing constraints are turned off when |
+ // - gUM has a specific kMediaStreamSource, which is used by tab capture |
+ // and screen capture. |
+ // - |kEchoCancellation| is explicitly set to false. |
+ std::string value_str; |
+ bool value_bool = false; |
+ if ((GetConstraintValueAsString(constraints, kMediaStreamSource, |
+ &value_str)) || |
+ (GetConstraintValueAsBoolean(constraints_, kEchoCancellation, |
+ &value_bool) && !value_bool)) { |
+ turn_off_constraints_as_default_ = true; |
tommi (sloooow) - chröme
2014/05/07 14:19:45
this applies only to the audio-processing-module,
no longer working on chromium
2014/05/07 15:45:00
how about simply default_constraint_value_?
tommi (sloooow) - chröme
2014/05/07 17:01:06
That name is technically not correct. See the fir
no longer working on chromium
2014/05/12 14:39:09
ah, right, I was trying to avoid the long name, ob
|
} |
+} |
+ |
+MediaAudioConstraints::~MediaAudioConstraints() {} |
+ |
+// TODO(xians): Remove this method after the APM in WebRtc is deprecated. |
+bool MediaAudioConstraints::NeedsAudioProcessing() { |
+ if (GetEchoCancellationProperty()) |
+ return 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) { |
+ // |kMediaStreamAudioDucking| does not require audio processing. |
+ // |kEchoCancellation| and |kGoogEchoCancellation| have been convered by |
+ // GetEchoCancellationProperty(). |
+ if (kDefaultAudioConstraints[i].key != kMediaStreamAudioDucking && |
+ kDefaultAudioConstraints[i].key != kEchoCancellation && |
+ kDefaultAudioConstraints[i].key != kGoogEchoCancellation && |
+ GetProperty(kDefaultAudioConstraints[i].key)) { |
return true; |
} |
} |
@@ -88,10 +128,73 @@ bool NeedsAudioProcessing(const blink::WebMediaConstraints& constraints, |
return false; |
} |
-bool GetPropertyFromConstraints(const MediaConstraintsInterface* constraints, |
- const std::string& key) { |
+bool MediaAudioConstraints::GetProperty(const std::string& key) { |
+ // 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 (!GetConstraintValueAsBoolean(constraints_, key, &value)) |
+ value = GetDefaultValueForConstraint(constraints_, key); |
+ |
+ return value; |
+} |
+ |
+bool MediaAudioConstraints::GetEchoCancellationProperty() { |
+ // If platform echo canceller is enabled, disable the software AEC. |
+ if (effects_ & media::AudioParameters::ECHO_CANCELLER) |
+ return false; |
+ |
+ // If |kEchoCancellation| is specified in the constraints, it will |
+ // overwrite the value of |kGoogEchoCancellation|. |
tommi (sloooow) - chröme
2014/05/07 14:19:45
nit: s/overwrite/override
no longer working on chromium
2014/05/07 15:45:00
Done.
|
+ bool value = false; |
+ if (GetConstraintValueAsBoolean(constraints_, kEchoCancellation, &value)) |
+ return value; |
+ |
+ return GetProperty(kGoogEchoCancellation); |
+} |
+ |
+bool MediaAudioConstraints::IsValid() { |
+ blink::WebVector<blink::WebMediaConstraint> mandatory; |
+ constraints_.getMandatoryConstraints(mandatory); |
+ for (size_t i = 0; i < mandatory.size(); ++i) { |
+ const std::string key = mandatory[i].m_name.utf8(); |
+ if (key == kMediaStreamSource || key == kMediaStreamSourceId || |
+ key == MediaStreamSource::kSourceId) { |
+ // Ignore Chrome specific Tab capture and |kSourceId| constraints. |
+ continue; |
+ } |
+ |
+ bool valid = false; |
+ for (size_t j = 0; j < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++j) { |
+ if (key == kDefaultAudioConstraints[j].key) { |
+ valid = true; |
+ break; |
+ } |
+ } |
+ |
+ if (!valid) { |
+ DLOG(ERROR) << "Invalid MediaStream constraint. Name: " << key; |
+ return false; |
+ } |
+ } |
+ |
+ return true; |
+} |
+ |
tommi (sloooow) - chröme
2014/05/07 14:19:45
one empty line
no longer working on chromium
2014/05/07 15:45:00
Done.
|
+ |
+bool MediaAudioConstraints::GetDefaultValueForConstraint( |
+ const blink::WebMediaConstraints& constraints, const std::string& key) { |
+ // |kMediaStreamAudioDucking| is not restricted by |
+ // |turn_off_constraints_as_default_| since it does not require audio |
+ // processing. |
+ if (turn_off_constraints_as_default_ && key != kMediaStreamAudioDucking) |
tommi (sloooow) - chröme
2014/05/07 14:19:45
I wonder if it's worth it now to factor the second
no longer working on chromium
2014/05/07 15:45:00
Done.
|
+ return false; |
+ |
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { |
+ if (kDefaultAudioConstraints[i].key == key) |
+ return kDefaultAudioConstraints[i].value; |
+ } |
+ |
+ return false; |
} |
void EnableEchoCancellation(AudioProcessing* audio_processing) { |