Bug 987186 - respect echoCancellation constraint
***
Bug 987186 - also accept and respect mozNoiseSuppression and mozAutoGainControl
--- a/dom/media/tests/mochitest/test_getUserMedia_constraints.html
+++ b/dom/media/tests/mochitest/test_getUserMedia_constraints.html
@@ -75,17 +75,17 @@ var mustSupport = [
// http://fluffy.github.io/w3c-screen-share/#screen-based-video-constraints
// OBE by http://w3c.github.io/mediacapture-screen-share
'mediaSource',
// Experimental https://bugzilla.mozilla.org/show_bug.cgi?id=1131568#c3
'browserWindow', 'scrollWithPage',
'viewportOffsetX', 'viewportOffsetY', 'viewportWidth', 'viewportHeight',
- 'echoCancellation'
+ 'echoCancellation', 'mozNoiseSuppression', 'mozAutoGainControl'
];
var mustFailWith = (msg, reason, constraint, f) =>
f().then(() => ok(false, msg + " must fail"), e => {
is(e.name, reason, msg + " must fail: " + e.message);
if (constraint !== undefined) {
is(e.constraint, constraint, msg + " must fail w/correct constraint.");
}
--- a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
+++ b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
@@ -247,27 +247,33 @@ MediaEngineWebRTCMicrophoneSource::Alloc
return Restart(aConstraints, aPrefs, aDeviceId);
}
nsresult
MediaEngineWebRTCMicrophoneSource::Restart(const dom::MediaTrackConstraints& aConstraints,
const MediaEnginePrefs &aPrefs,
const nsString& aDeviceId)
{
- LOG(("Audio config: aec: %d, agc: %d, noise: %d",
- aPrefs.mAecOn ? aPrefs.mAec : -1,
- aPrefs.mAgcOn ? aPrefs.mAgc : -1,
- aPrefs.mNoiseOn ? aPrefs.mNoise : -1));
+ FlattenedConstraints c(aConstraints);
+
+ bool aec_on = c.mEchoCancellation.Get(aPrefs.mAecOn);
+ bool agc_on = c.mMozAutoGainControl.Get(aPrefs.mAgcOn);
+ bool noise_on = c.mMozNoiseSuppression.Get(aPrefs.mNoiseOn);
- bool update_echo = (mEchoOn != aPrefs.mAecOn);
- bool update_agc = (mAgcOn != aPrefs.mAgcOn);
- bool update_noise = (mNoiseOn != aPrefs.mNoiseOn);
- mEchoOn = aPrefs.mAecOn;
- mAgcOn = aPrefs.mAgcOn;
- mNoiseOn = aPrefs.mNoiseOn;
+ LOG(("Audio config: aec: %d, agc: %d, noise: %d",
+ aec_on ? aPrefs.mAec : -1,
+ agc_on ? aPrefs.mAgc : -1,
+ noise_on ? aPrefs.mNoise : -1));
+
+ bool update_echo = (mEchoOn != aec_on);
+ bool update_agc = (mAgcOn != agc_on);
+ bool update_noise = (mNoiseOn != noise_on);
+ mEchoOn = aec_on;
+ mAgcOn = agc_on;
+ mNoiseOn = noise_on;
mPlayoutDelay = aPrefs.mPlayoutDelay;
if ((webrtc::EcModes) aPrefs.mAec != webrtc::kEcUnchanged) {
if (mEchoCancel != (webrtc::EcModes) aPrefs.mAec) {
update_echo = true;
mEchoCancel = (webrtc::EcModes) aPrefs.mAec;
}
}
--- a/dom/media/webrtc/MediaTrackConstraints.cpp
+++ b/dom/media/webrtc/MediaTrackConstraints.cpp
@@ -56,32 +56,63 @@ NormalizedConstraintSet::DoubleRange::Do
} else {
mIdeal.Construct(aOther.GetAsDouble());
}
} else {
SetFrom(aOther.GetAsConstrainDoubleRange());
}
}
+NormalizedConstraintSet::BooleanRange::BooleanRange(
+ const dom::OwningBooleanOrConstrainBooleanParameters& aOther, bool advanced)
+: Range<bool>(false, true)
+{
+ if (aOther.IsBoolean()) {
+ if (advanced) {
+ mMin = mMax = aOther.GetAsBoolean();
+ } else {
+ mIdeal.Construct(aOther.GetAsBoolean());
+ }
+ } else {
+ const ConstrainBooleanParameters& r = aOther.GetAsConstrainBooleanParameters();
+ if (r.mIdeal.WasPassed()) {
+ mIdeal.Construct(r.mIdeal.Value());
+ }
+ if (r.mExact.WasPassed()) {
+ mMin = r.mExact.Value();
+ mMax = r.mExact.Value();
+ }
+ }
+}
+
FlattenedConstraints::FlattenedConstraints(const dom::MediaTrackConstraints& aOther)
: NormalizedConstraintSet(aOther, false)
{
if (aOther.mAdvanced.WasPassed()) {
const auto& advanced = aOther.mAdvanced.Value();
for (size_t i = 0; i < advanced.Length(); i++) {
NormalizedConstraintSet set(advanced[i], true);
// Must only apply compatible i.e. inherently non-overconstraining sets
// This rule is pretty much why this code is centralized here.
if (mWidth.Intersects(set.mWidth) &&
mHeight.Intersects(set.mHeight) &&
mFrameRate.Intersects(set.mFrameRate)) {
mWidth.Intersect(set.mWidth);
mHeight.Intersect(set.mHeight);
mFrameRate.Intersect(set.mFrameRate);
}
+ if (mEchoCancellation.Intersects(set.mEchoCancellation)) {
+ mEchoCancellation.Intersect(set.mEchoCancellation);
+ }
+ if (mMozNoiseSuppression.Intersects(set.mMozNoiseSuppression)) {
+ mMozNoiseSuppression.Intersect(set.mMozNoiseSuppression);
+ }
+ if (mMozAutoGainControl.Intersects(set.mMozAutoGainControl)) {
+ mMozAutoGainControl.Intersect(set.mMozAutoGainControl);
+ }
}
}
}
// MediaEngine helper
//
// The full algorithm for all devices. Sources that don't list capabilities
// need to fake it and hardcode some by populating mHardcodedCapabilities above.
--- a/dom/media/webrtc/MediaTrackConstraints.h
+++ b/dom/media/webrtc/MediaTrackConstraints.h
@@ -67,30 +67,40 @@ struct NormalizedConstraintSet
};
struct DoubleRange : public Range<double>
{
DoubleRange(const dom::OwningDoubleOrConstrainDoubleRange& aOther,
bool advanced);
};
+ struct BooleanRange : public Range<bool>
+ {
+ BooleanRange(const dom::OwningBooleanOrConstrainBooleanParameters& aOther,
+ bool advanced);
+ };
+
// Do you need to add your constraint here? Only if your code uses flattening
LongRange mWidth, mHeight;
DoubleRange mFrameRate;
LongRange mViewportOffsetX, mViewportOffsetY, mViewportWidth, mViewportHeight;
+ BooleanRange mEchoCancellation, mMozNoiseSuppression, mMozAutoGainControl;
NormalizedConstraintSet(const dom::MediaTrackConstraintSet& aOther,
bool advanced)
: mWidth(aOther.mWidth, advanced)
, mHeight(aOther.mHeight, advanced)
, mFrameRate(aOther.mFrameRate, advanced)
, mViewportOffsetX(aOther.mViewportOffsetX, advanced)
, mViewportOffsetY(aOther.mViewportOffsetY, advanced)
, mViewportWidth(aOther.mViewportWidth, advanced)
- , mViewportHeight(aOther.mViewportHeight, advanced) {}
+ , mViewportHeight(aOther.mViewportHeight, advanced)
+ , mEchoCancellation(aOther.mEchoCancellation, advanced)
+ , mMozNoiseSuppression(aOther.mMozNoiseSuppression, advanced)
+ , mMozAutoGainControl(aOther.mMozAutoGainControl, advanced) {}
};
struct FlattenedConstraints : public NormalizedConstraintSet
{
explicit FlattenedConstraints(const dom::MediaTrackConstraints& aOther);
};
// A helper class for MediaEngines
--- a/dom/webidl/MediaStreamTrack.webidl
+++ b/dom/webidl/MediaStreamTrack.webidl
@@ -50,16 +50,18 @@ dictionary MediaTrackConstraintSet {
long long browserWindow;
boolean scrollWithPage;
ConstrainDOMString deviceId;
ConstrainLong viewportOffsetX;
ConstrainLong viewportOffsetY;
ConstrainLong viewportWidth;
ConstrainLong viewportHeight;
ConstrainBoolean echoCancellation;
+ ConstrainBoolean mozNoiseSuppression;
+ ConstrainBoolean mozAutoGainControl;
};
dictionary MediaTrackConstraints : MediaTrackConstraintSet {
sequence<MediaTrackConstraintSet> advanced;
};
[Exposed=Window]
interface MediaStreamTrack : EventTarget {
--- a/dom/webidl/MediaTrackSupportedConstraints.webidl
+++ b/dom/webidl/MediaTrackSupportedConstraints.webidl
@@ -12,16 +12,18 @@ dictionary MediaTrackSupportedConstraint
boolean height = true;
boolean aspectRatio; // to be supported
boolean frameRate = true;
boolean facingMode = true;
boolean volume; // to be supported
boolean sampleRate; // to be supported
boolean sampleSize; // to be supported
boolean echoCancellation = true;
+ boolean mozNoiseSuppression = true;
+ boolean mozAutoGainControl = true;
boolean latency; // to be supported
boolean deviceId = true;
boolean groupId; // to be supported
// Mozilla-specific extensions:
// http://fluffy.github.io/w3c-screen-share/#screen-based-video-constraints
// OBE by http://w3c.github.io/mediacapture-screen-share