Chromium Code Reviews| 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..5065eea73aa7501948a8dfa17681d7e40c3f6365 100644 |
| --- a/content/renderer/media/media_stream_audio_processor_options.cc |
| +++ b/content/renderer/media/media_stream_audio_processor_options.cc |
| @@ -7,57 +7,81 @@ |
| #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 }, |
| + { content::kMediaStreamAudioDucking, true }, |
|
tommi (sloooow) - chröme
2014/04/08 10:49:30
remove content:: prefix here and in the line below
no longer working on chromium
2014/04/11 08:56:30
Done.
|
| +#else |
| + { content::kMediaStreamAudioDucking, false }, |
|
tommi (sloooow) - chröme
2014/04/08 10:49:30
why adding this?
no longer working on chromium
2014/04/11 08:56:30
I think it is good to explicitly define the defaul
|
| #endif |
| }; |
| +bool GetDefaultValueForConstraint(const std::string& key, |
| + MediaStreamType type) { |
|
perkj_chrome
2014/04/08 10:28:12
You can read the type from the original constrains
no longer working on chromium
2014/04/11 08:56:30
Done.
|
| + // Audio processing is false for gUM of non-MEDIA_DEVICE_AUDIO_CAPTURE. |
| + if (type != MEDIA_DEVICE_AUDIO_CAPTURE) |
|
tommi (sloooow) - chröme
2014/04/08 10:49:30
the name of the function is GetDefaultValueForCons
no longer working on chromium
2014/04/11 08:56:30
Per pointed out that we should be able to get the
|
| + return false; |
| + |
| + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) { |
| + if (kDefaultAudioConstraints[i].key == key) |
| + return kDefaultAudioConstraints[i].value; |
| + } |
| + |
| + return false; |
|
tommi (sloooow) - chröme
2014/04/08 10:49:30
I'm a bit wary of this sort of implementation. I'
no longer working on chromium
2014/04/11 08:56:30
Done.
|
| +} |
| + |
| } // namespace |
| +// TODO(xians): Remove this method after the APM in WebRtc is deprecated. |
| void ApplyFixedAudioConstraints(RTCMediaConstraints* constraints) { |
|
no longer working on chromium
2014/04/08 10:02:53
These two methods are still used in WebRtcAudioCap
|
| 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); |
| + base::IntToString(kDefaultAudioConstraints[i].value), false); |
|
tommi (sloooow) - chröme
2014/04/08 10:49:30
ugh, isn't this is a big change in functionality?
no longer working on chromium
2014/04/11 08:56:30
Right, we have to keep using the webrtc::MediaCons
tommi (sloooow) - chröme
2014/04/11 12:51:16
I don't think you understand my comments. You're
|
| } else { |
| DVLOG(1) << "Constraint " << kDefaultAudioConstraints[i].key |
| << " already set to " << already_set_value; |
| @@ -65,21 +89,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); |
| - } |
| + int effects, MediaStreamType type) { |
| 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, type)) { |
| return true; |
| } |
| } |
| @@ -87,10 +103,21 @@ bool NeedsAudioProcessing(const blink::WebMediaConstraints& constraints, |
| return false; |
| } |
| -bool GetPropertyFromConstraints(const MediaConstraintsInterface* constraints, |
| - const std::string& key) { |
| - bool value = false; |
| - return webrtc::FindConstraint(constraints, key, &value, NULL) && value; |
| +bool GetPropertyFromConstraints(const blink::WebMediaConstraints& constraints, |
| + const std::string& key, |
| + int effects, |
| + MediaStreamType type) { |
| + if (effects & media::AudioParameters::ECHO_CANCELLER && |
|
tommi (sloooow) - chröme
2014/04/08 10:49:30
Please get Andrew to review this.
The name of thi
no longer working on chromium
2014/04/11 08:56:30
Will do.
|
| + key == kGoogEchoCancellation) { |
| + // If platform echo canceller is enabled, disable the software AEC. |
| + return false; |
|
perkj_chrome
2014/04/08 10:28:12
What does this mean? Can echo cancellation on/off
no longer working on chromium
2014/04/11 08:56:30
Yes, when the effect is on, we need to disable the
|
| + } |
| + |
| + // Return the value if the constraint is specified in |constraints|, |
| + // otherwise return the default value. |
| + bool value = GetDefaultValueForConstraint(key, type); |
|
tommi (sloooow) - chröme
2014/04/08 10:49:30
better to do:
if (!GetConstraintValue(constraints
no longer working on chromium
2014/04/11 08:56:30
Done.
|
| + GetConstraintValue(constraints, key, &value); |
| + return value; |
| } |
| void EnableEchoCancellation(AudioProcessing* audio_processing) { |