From bd5e81267988a106954f74d4a315ad2c760bb045 Mon Sep 17 00:00:00 2001 From: Jan-Ivar Bruaroey Date: Wed, 15 Jun 2016 19:25:07 -0400 Subject: [PATCH] Bug 1213517 - Report correct constraint in OverconstrainedError when constraints conflict directly. r=padenot MozReview-Commit-ID: 2bVaSvntc8g --HG-- extra : rebase_source : cf1724b5db8852ca05248b67380899e4a16c7725 --- dom/media/MediaManager.cpp | 28 +++-- dom/media/MediaManager.h | 6 +- dom/media/webrtc/MediaEngine.h | 6 +- dom/media/webrtc/MediaEngineDefault.cpp | 12 +- dom/media/webrtc/MediaEngineDefault.h | 12 +- .../webrtc/MediaEngineRemoteVideoSource.cpp | 12 +- .../webrtc/MediaEngineRemoteVideoSource.h | 6 +- .../webrtc/MediaEngineTabVideoSource.cpp | 8 +- dom/media/webrtc/MediaEngineTabVideoSource.h | 6 +- dom/media/webrtc/MediaEngineWebRTC.h | 12 +- dom/media/webrtc/MediaEngineWebRTCAudio.cpp | 11 +- dom/media/webrtc/MediaTrackConstraints.cpp | 107 +++++++++++++----- dom/media/webrtc/MediaTrackConstraints.h | 17 +-- 13 files changed, 159 insertions(+), 84 deletions(-) diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index 00230f9e69e8..df82221c7052 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -888,14 +888,18 @@ AudioDevice::GetSource() nsresult MediaDevice::Allocate(const dom::MediaTrackConstraints &aConstraints, const MediaEnginePrefs &aPrefs, - const nsACString& aOrigin) { + const nsACString& aOrigin, + const char** aOutBadConstraint) { return GetSource()->Allocate(aConstraints, aPrefs, mID, aOrigin, - getter_AddRefs(mAllocationHandle)); + getter_AddRefs(mAllocationHandle), + aOutBadConstraint); } nsresult MediaDevice::Restart(const dom::MediaTrackConstraints &aConstraints, - const MediaEnginePrefs &aPrefs) { - return GetSource()->Restart(mAllocationHandle, aConstraints, aPrefs, mID); + const MediaEnginePrefs &aPrefs, + const char** aOutBadConstraint) { + return GetSource()->Restart(mAllocationHandle, aConstraints, aPrefs, mID, + aOutBadConstraint); } nsresult MediaDevice::Deallocate() { @@ -1428,10 +1432,10 @@ public: if (mAudioDevice) { auto& constraints = GetInvariant(mConstraints.mAudio); - rv = mAudioDevice->Allocate(constraints, mPrefs, mOrigin); + rv = mAudioDevice->Allocate(constraints, mPrefs, mOrigin, &badConstraint); if (NS_FAILED(rv)) { errorMsg = "Failed to allocate audiosource"; - if (rv == NS_ERROR_NOT_AVAILABLE) { + if (rv == NS_ERROR_NOT_AVAILABLE && !badConstraint) { nsTArray> audios; audios.AppendElement(mAudioDevice); badConstraint = MediaConstraintsHelper::SelectSettings(constraints, @@ -1441,10 +1445,10 @@ public: } if (!errorMsg && mVideoDevice) { auto& constraints = GetInvariant(mConstraints.mVideo); - rv = mVideoDevice->Allocate(constraints, mPrefs, mOrigin); + rv = mVideoDevice->Allocate(constraints, mPrefs, mOrigin, &badConstraint); if (NS_FAILED(rv)) { errorMsg = "Failed to allocate videosource"; - if (rv == NS_ERROR_NOT_AVAILABLE) { + if (rv == NS_ERROR_NOT_AVAILABLE && !badConstraint) { nsTArray> videos; videos.AppendElement(mVideoDevice); badConstraint = MediaConstraintsHelper::SelectSettings(constraints, @@ -3435,16 +3439,16 @@ GetUserMediaCallbackMediaStreamListener::ApplyConstraintsToTrack( nsresult rv = NS_OK; if (audioDevice) { - rv = audioDevice->Restart(aConstraints, mgr->mPrefs); - if (rv == NS_ERROR_NOT_AVAILABLE) { + rv = audioDevice->Restart(aConstraints, mgr->mPrefs, &badConstraint); + if (rv == NS_ERROR_NOT_AVAILABLE && !badConstraint) { nsTArray> audios; audios.AppendElement(audioDevice); badConstraint = MediaConstraintsHelper::SelectSettings(aConstraints, audios); } } else { - rv = videoDevice->Restart(aConstraints, mgr->mPrefs); - if (rv == NS_ERROR_NOT_AVAILABLE) { + rv = videoDevice->Restart(aConstraints, mgr->mPrefs, &badConstraint); + if (rv == NS_ERROR_NOT_AVAILABLE && !badConstraint) { nsTArray> videos; videos.AppendElement(videoDevice); badConstraint = MediaConstraintsHelper::SelectSettings(aConstraints, diff --git a/dom/media/MediaManager.h b/dom/media/MediaManager.h index 1b0856e604bb..4022e6404c53 100644 --- a/dom/media/MediaManager.h +++ b/dom/media/MediaManager.h @@ -74,9 +74,11 @@ public: virtual Source* GetSource() = 0; nsresult Allocate(const dom::MediaTrackConstraints &aConstraints, const MediaEnginePrefs &aPrefs, - const nsACString& aOrigin); + const nsACString& aOrigin, + const char** aOutBadConstraint); nsresult Restart(const dom::MediaTrackConstraints &aConstraints, - const MediaEnginePrefs &aPrefs); + const MediaEnginePrefs &aPrefs, + const char** aOutBadConstraint); nsresult Deallocate(); protected: virtual ~MediaDevice() {} diff --git a/dom/media/webrtc/MediaEngine.h b/dom/media/webrtc/MediaEngine.h index 8101e6f19802..4e01a1978ac9 100644 --- a/dom/media/webrtc/MediaEngine.h +++ b/dom/media/webrtc/MediaEngine.h @@ -152,7 +152,8 @@ public: virtual nsresult Restart(BaseAllocationHandle* aHandle, const dom::MediaTrackConstraints& aConstraints, const MediaEnginePrefs &aPrefs, - const nsString& aDeviceId) = 0; + const nsString& aDeviceId, + const char** aOutBadConstraint) = 0; /* Returns true if a source represents a fake capture device and * false otherwise @@ -189,7 +190,8 @@ public: const MediaEnginePrefs &aPrefs, const nsString& aDeviceId, const nsACString& aOrigin, - BaseAllocationHandle** aOutHandle) = 0; + BaseAllocationHandle** aOutHandle, + const char** aOutBadConstraint) = 0; virtual uint32_t GetBestFitnessDistance( const nsTArray& aConstraintSets, diff --git a/dom/media/webrtc/MediaEngineDefault.cpp b/dom/media/webrtc/MediaEngineDefault.cpp index d5df2dd3734b..5837bf386a99 100644 --- a/dom/media/webrtc/MediaEngineDefault.cpp +++ b/dom/media/webrtc/MediaEngineDefault.cpp @@ -90,7 +90,8 @@ MediaEngineDefaultVideoSource::Allocate(const dom::MediaTrackConstraints &aConst const MediaEnginePrefs &aPrefs, const nsString& aDeviceId, const nsACString& aOrigin, - BaseAllocationHandle** aOutHandle) + BaseAllocationHandle** aOutHandle, + const char** aOutBadConstraint) { if (mState != kReleased) { return NS_ERROR_FAILURE; @@ -221,7 +222,8 @@ MediaEngineDefaultVideoSource::Restart( BaseAllocationHandle* aHandle, const dom::MediaTrackConstraints& aConstraints, const MediaEnginePrefs &aPrefs, - const nsString& aDeviceId) + const nsString& aDeviceId, + const char** aOutBadConstraint) { return NS_OK; } @@ -416,7 +418,8 @@ MediaEngineDefaultAudioSource::Allocate(const dom::MediaTrackConstraints &aConst const MediaEnginePrefs &aPrefs, const nsString& aDeviceId, const nsACString& aOrigin, - BaseAllocationHandle** aOutHandle) + BaseAllocationHandle** aOutHandle, + const char** aOutBadConstraint) { if (mState != kReleased) { return NS_ERROR_FAILURE; @@ -530,7 +533,8 @@ nsresult MediaEngineDefaultAudioSource::Restart(BaseAllocationHandle* aHandle, const dom::MediaTrackConstraints& aConstraints, const MediaEnginePrefs &aPrefs, - const nsString& aDeviceId) + const nsString& aDeviceId, + const char** aOutBadConstraint) { return NS_OK; } diff --git a/dom/media/webrtc/MediaEngineDefault.h b/dom/media/webrtc/MediaEngineDefault.h index 36c4094641b7..3c27d4da192d 100644 --- a/dom/media/webrtc/MediaEngineDefault.h +++ b/dom/media/webrtc/MediaEngineDefault.h @@ -48,14 +48,16 @@ public: const MediaEnginePrefs &aPrefs, const nsString& aDeviceId, const nsACString& aOrigin, - BaseAllocationHandle** aOutHandle) override; + BaseAllocationHandle** aOutHandle, + const char** aOutBadConstraint) override; nsresult Deallocate(BaseAllocationHandle* aHandle) override; nsresult Start(SourceMediaStream*, TrackID, const PrincipalHandle&) override; nsresult Stop(SourceMediaStream*, TrackID) override; nsresult Restart(BaseAllocationHandle* aHandle, const dom::MediaTrackConstraints& aConstraints, const MediaEnginePrefs &aPrefs, - const nsString& aDeviceId) override; + const nsString& aDeviceId, + const char** aOutBadConstraint) override; void SetDirectListeners(bool aHasDirectListeners) override {}; void NotifyPull(MediaStreamGraph* aGraph, SourceMediaStream *aSource, @@ -121,14 +123,16 @@ public: const MediaEnginePrefs &aPrefs, const nsString& aDeviceId, const nsACString& aOrigin, - BaseAllocationHandle** aOutHandle) override; + BaseAllocationHandle** aOutHandle, + const char** aOutBadConstraint) override; nsresult Deallocate(BaseAllocationHandle* aHandle) override; nsresult Start(SourceMediaStream*, TrackID, const PrincipalHandle&) override; nsresult Stop(SourceMediaStream*, TrackID) override; nsresult Restart(BaseAllocationHandle* aHandle, const dom::MediaTrackConstraints& aConstraints, const MediaEnginePrefs &aPrefs, - const nsString& aDeviceId) override; + const nsString& aDeviceId, + const char** aOutBadConstraint) override; void SetDirectListeners(bool aHasDirectListeners) override {}; void AppendToSegment(AudioSegment& aSegment, TrackTicks aSamples); diff --git a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp index 9850c5fba947..fc9e037fa73b 100644 --- a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp +++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp @@ -103,7 +103,8 @@ MediaEngineRemoteVideoSource::Allocate( const MediaEnginePrefs& aPrefs, const nsString& aDeviceId, const nsACString& aOrigin, - BaseAllocationHandle** aOutHandle) + BaseAllocationHandle** aOutHandle, + const char** aOutBadConstraint) { LOG((__PRETTY_FUNCTION__)); AssertIsOnOwningThread(); @@ -121,7 +122,8 @@ MediaEngineRemoteVideoSource::Allocate( allConstraints.AppendElement(&handle->mConstraints); NormalizedConstraints netConstraints(allConstraints); - if (netConstraints.mOverconstrained) { + if (netConstraints.mBadConstraint) { + *aOutBadConstraint = netConstraints.mBadConstraint; return NS_ERROR_NOT_AVAILABLE; } @@ -283,7 +285,8 @@ nsresult MediaEngineRemoteVideoSource::Restart(BaseAllocationHandle* aHandle, const dom::MediaTrackConstraints& aConstraints, const MediaEnginePrefs& aPrefs, - const nsString& aDeviceId) + const nsString& aDeviceId, + const char** aOutBadConstraint) { AssertIsOnOwningThread(); if (!mInitDone) { @@ -305,7 +308,8 @@ MediaEngineRemoteVideoSource::Restart(BaseAllocationHandle* aHandle, allConstraints.AppendElement(&temp->mConstraints); NormalizedConstraints netConstraints(allConstraints); - if (netConstraints.mOverconstrained) { + if (netConstraints.mBadConstraint) { + *aOutBadConstraint = netConstraints.mBadConstraint; return NS_ERROR_FAILURE; } diff --git a/dom/media/webrtc/MediaEngineRemoteVideoSource.h b/dom/media/webrtc/MediaEngineRemoteVideoSource.h index 342208a8b0a4..247467bf4621 100644 --- a/dom/media/webrtc/MediaEngineRemoteVideoSource.h +++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.h @@ -86,14 +86,16 @@ public: const MediaEnginePrefs& aPrefs, const nsString& aDeviceId, const nsACString& aOrigin, - BaseAllocationHandle** aOutHandle) override; + BaseAllocationHandle** aOutHandle, + const char** aOutBadConstraint) override; nsresult Deallocate(BaseAllocationHandle* aHandle) override; nsresult Start(SourceMediaStream*, TrackID, const PrincipalHandle&) override; nsresult Stop(SourceMediaStream*, TrackID) override; nsresult Restart(BaseAllocationHandle* aHandle, const dom::MediaTrackConstraints& aConstraints, const MediaEnginePrefs &aPrefs, - const nsString& aDeviceId) override; + const nsString& aDeviceId, + const char** aOutBadConstraint) override; void NotifyPull(MediaStreamGraph* aGraph, SourceMediaStream* aSource, TrackID aId, diff --git a/dom/media/webrtc/MediaEngineTabVideoSource.cpp b/dom/media/webrtc/MediaEngineTabVideoSource.cpp index c4fd95d8042d..9e7d9b7bdd6e 100644 --- a/dom/media/webrtc/MediaEngineTabVideoSource.cpp +++ b/dom/media/webrtc/MediaEngineTabVideoSource.cpp @@ -140,7 +140,8 @@ MediaEngineTabVideoSource::Allocate(const dom::MediaTrackConstraints& aConstrain const MediaEnginePrefs& aPrefs, const nsString& aDeviceId, const nsACString& aOrigin, - BaseAllocationHandle** aOutHandle) + BaseAllocationHandle** aOutHandle, + const char** aOutBadConstraint) { // windowId is not a proper constraint, so just read it. // It has no well-defined behavior in advanced, so ignore it there. @@ -148,14 +149,15 @@ MediaEngineTabVideoSource::Allocate(const dom::MediaTrackConstraints& aConstrain mWindowId = aConstraints.mBrowserWindow.WasPassed() ? aConstraints.mBrowserWindow.Value() : -1; aOutHandle = nullptr; - return Restart(nullptr, aConstraints, aPrefs, aDeviceId); + return Restart(nullptr, aConstraints, aPrefs, aDeviceId, aOutBadConstraint); } nsresult MediaEngineTabVideoSource::Restart(BaseAllocationHandle* aHandle, const dom::MediaTrackConstraints& aConstraints, const mozilla::MediaEnginePrefs& aPrefs, - const nsString& aDeviceId) + const nsString& aDeviceId, + const char** aOutBadConstraint) { MOZ_ASSERT(!aHandle); diff --git a/dom/media/webrtc/MediaEngineTabVideoSource.h b/dom/media/webrtc/MediaEngineTabVideoSource.h index fbc410de7e41..51214824d56a 100644 --- a/dom/media/webrtc/MediaEngineTabVideoSource.h +++ b/dom/media/webrtc/MediaEngineTabVideoSource.h @@ -26,7 +26,8 @@ class MediaEngineTabVideoSource : public MediaEngineVideoSource, nsIDOMEventList const mozilla::MediaEnginePrefs&, const nsString& aDeviceId, const nsACString& aOrigin, - BaseAllocationHandle** aOutHandle) override; + BaseAllocationHandle** aOutHandle, + const char** aOutBadConstraint) override; nsresult Deallocate(BaseAllocationHandle* aHandle) override; nsresult Start(mozilla::SourceMediaStream*, mozilla::TrackID, const mozilla::PrincipalHandle&) override; void SetDirectListeners(bool aHasDirectListeners) override {}; @@ -35,7 +36,8 @@ class MediaEngineTabVideoSource : public MediaEngineVideoSource, nsIDOMEventList nsresult Restart(BaseAllocationHandle* aHandle, const dom::MediaTrackConstraints& aConstraints, const mozilla::MediaEnginePrefs& aPrefs, - const nsString& aDeviceId) override; + const nsString& aDeviceId, + const char** aOutBadConstraint) override; bool IsFake() override; dom::MediaSourceEnum GetMediaSource() const override { return dom::MediaSourceEnum::Browser; diff --git a/dom/media/webrtc/MediaEngineWebRTC.h b/dom/media/webrtc/MediaEngineWebRTC.h index 20dab6794440..9ed1b34eec21 100644 --- a/dom/media/webrtc/MediaEngineWebRTC.h +++ b/dom/media/webrtc/MediaEngineWebRTC.h @@ -78,7 +78,8 @@ public: const MediaEnginePrefs& aPrefs, const nsString& aDeviceId, const nsACString& aOrigin, - BaseAllocationHandle** aOutHandle) override + BaseAllocationHandle** aOutHandle, + const char** aOutBadConstraint) override { // Nothing to do here, everything is managed in MediaManager.cpp aOutHandle = nullptr; @@ -101,7 +102,8 @@ public: nsresult Restart(BaseAllocationHandle* aHandle, const dom::MediaTrackConstraints& aConstraints, const MediaEnginePrefs &aPrefs, - const nsString& aDeviceId) override; + const nsString& aDeviceId, + const char** aOutBadConstraint) override; void SetDirectListeners(bool aDirect) override {} void NotifyOutputData(MediaStreamGraph* aGraph, @@ -456,7 +458,8 @@ public: const MediaEnginePrefs& aPrefs, const nsString& aDeviceId, const nsACString& aOrigin, - BaseAllocationHandle** aOutHandle) override; + BaseAllocationHandle** aOutHandle, + const char** aOutBadConstraint) override; nsresult Deallocate(BaseAllocationHandle* aHandle) override; nsresult Start(SourceMediaStream* aStream, TrackID aID, @@ -465,7 +468,8 @@ public: nsresult Restart(BaseAllocationHandle* aHandle, const dom::MediaTrackConstraints& aConstraints, const MediaEnginePrefs &aPrefs, - const nsString& aDeviceId) override; + const nsString& aDeviceId, + const char** aOutBadConstraint) override; void SetDirectListeners(bool aHasDirectListeners) override {}; void NotifyPull(MediaStreamGraph* aGraph, diff --git a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp index 9df8b9fe6700..7fcf6e87dcb2 100644 --- a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp +++ b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp @@ -223,7 +223,8 @@ MediaEngineWebRTCMicrophoneSource::Allocate(const dom::MediaTrackConstraints &aC const MediaEnginePrefs &aPrefs, const nsString& aDeviceId, const nsACString& aOrigin, - BaseAllocationHandle** aOutHandle) + BaseAllocationHandle** aOutHandle, + const char** aOutBadConstraint) { AssertIsOnOwningThread(); if (mState == kReleased) { @@ -260,14 +261,15 @@ MediaEngineWebRTCMicrophoneSource::Allocate(const dom::MediaTrackConstraints &aC } ++mNrAllocations; aOutHandle = nullptr; - return Restart(nullptr, aConstraints, aPrefs, aDeviceId); + return Restart(nullptr, aConstraints, aPrefs, aDeviceId, aOutBadConstraint); } nsresult MediaEngineWebRTCMicrophoneSource::Restart(BaseAllocationHandle* aHandle, const dom::MediaTrackConstraints& aConstraints, const MediaEnginePrefs &aPrefs, - const nsString& aDeviceId) + const nsString& aDeviceId, + const char** aOutBadConstraint) { MOZ_ASSERT(!aHandle); FlattenedConstraints c(aConstraints); @@ -848,7 +850,8 @@ MediaEngineWebRTCAudioCaptureSource::Restart( BaseAllocationHandle* aHandle, const dom::MediaTrackConstraints& aConstraints, const MediaEnginePrefs &aPrefs, - const nsString& aDeviceId) + const nsString& aDeviceId, + const char** aOutBadConstraint) { MOZ_ASSERT(!aHandle); return NS_OK; diff --git a/dom/media/webrtc/MediaTrackConstraints.cpp b/dom/media/webrtc/MediaTrackConstraints.cpp index 36bff13a7d66..7d8361caf103 100644 --- a/dom/media/webrtc/MediaTrackConstraints.cpp +++ b/dom/media/webrtc/MediaTrackConstraints.cpp @@ -6,6 +6,8 @@ #include "MediaTrackConstraints.h" #include +#include +#include namespace mozilla { @@ -200,12 +202,12 @@ NormalizedConstraintSet::StringRange::Intersects(const StringRange& aOther) cons if (!mExact.size() || !aOther.mExact.size()) { return true; } - for (auto& entry : aOther.mExact) { - if (mExact.find(entry) != mExact.end()) { - return true; - } - } - return false; + + ValueType intersection; + set_intersection(mExact.begin(), mExact.end(), + aOther.mExact.begin(), aOther.mExact.end(), + std::inserter(intersection, intersection.begin())); + return !!intersection.size(); } void @@ -214,15 +216,32 @@ NormalizedConstraintSet::StringRange::Intersect(const StringRange& aOther) if (!aOther.mExact.size()) { return; } - for (auto& entry : mExact) { - if (aOther.mExact.find(entry) == aOther.mExact.end()) { - mExact.erase(entry); - } + + ValueType intersection; + set_intersection(mExact.begin(), mExact.end(), + aOther.mExact.begin(), aOther.mExact.end(), + std::inserter(intersection, intersection.begin())); + mExact = intersection; +} + +bool +NormalizedConstraintSet::StringRange::Merge(const StringRange& aOther) +{ + if (!Intersects(aOther)) { + return false; } + Intersect(aOther); + + ValueType unioned; + set_union(mIdeal.begin(), mIdeal.end(), + aOther.mIdeal.begin(), aOther.mIdeal.end(), + std::inserter(unioned, unioned.begin())); + mIdeal = unioned; + return true; } NormalizedConstraints::NormalizedConstraints(const dom::MediaTrackConstraints& aOther) -: NormalizedConstraintSet(aOther, false), mOverconstrained(false) +: NormalizedConstraintSet(aOther, false), mBadConstraint(nullptr) { if (aOther.mAdvanced.WasPassed()) { for (auto& entry : aOther.mAdvanced.Value()) { @@ -236,27 +255,63 @@ NormalizedConstraints::NormalizedConstraints(const dom::MediaTrackConstraints& a NormalizedConstraints::NormalizedConstraints( const nsTArray& aOthers) : NormalizedConstraintSet(*aOthers[0]) - , mOverconstrained(false) + , mBadConstraint(nullptr) { // Do intersection of all required constraints, and average of ideals. for (uint32_t i = 1; i < aOthers.Length(); i++) { auto& set = *aOthers[i]; - if (!mWidth.Merge(set.mWidth) || - !mHeight.Merge(set.mHeight) || - !mFrameRate.Merge(set.mFrameRate) || - !mFacingMode.Merge(set.mFacingMode) || - mMediaSource != set.mMediaSource || - mBrowserWindow != set.mBrowserWindow || - !mViewportOffsetX.Merge(set.mViewportOffsetX) || - !mViewportOffsetY.Merge(set.mViewportOffsetY) || - !mViewportWidth.Merge(set.mViewportWidth) || - !mViewportHeight.Merge(set.mViewportHeight) || - !mEchoCancellation.Merge(set.mEchoCancellation) || - !mMozNoiseSuppression.Merge(set.mMozNoiseSuppression) || - !mMozAutoGainControl.Merge(set.mMozAutoGainControl)) { - mOverconstrained = true; + if (!mWidth.Merge(set.mWidth)) { + mBadConstraint = "width"; + return; + } + if (!mHeight.Merge(set.mHeight)) { + mBadConstraint = "height"; + return; + } + if (!mFrameRate.Merge(set.mFrameRate)) { + mBadConstraint = "frameRate"; + return; + } + if (!mFacingMode.Merge(set.mFacingMode)) { + mBadConstraint = "facingMode"; + return; + } + if (mMediaSource != set.mMediaSource) { + mBadConstraint = "mediaSource"; + return; + } + if (mBrowserWindow != set.mBrowserWindow) { + mBadConstraint = "browserWindow"; + return; + } + if (!mViewportOffsetX.Merge(set.mViewportOffsetX)) { + mBadConstraint = "viewportOffsetX"; + return; + } + if (!mViewportOffsetY.Merge(set.mViewportOffsetY)) { + mBadConstraint = "viewportOffsetY"; + return; + } + if (!mViewportWidth.Merge(set.mViewportWidth)) { + mBadConstraint = "viewportWidth"; + return; + } + if (!mViewportHeight.Merge(set.mViewportHeight)) { + mBadConstraint = "viewportHeight"; + return; + } + if (!mEchoCancellation.Merge(set.mEchoCancellation)) { + mBadConstraint = "echoCancellation"; + return; + } + if (!mMozNoiseSuppression.Merge(set.mMozNoiseSuppression)) { + mBadConstraint = "mozNoiseSuppression"; + return; + } + if (!mMozAutoGainControl.Merge(set.mMozAutoGainControl)) { + mBadConstraint = "mozAutoGainControl"; return; } diff --git a/dom/media/webrtc/MediaTrackConstraints.h b/dom/media/webrtc/MediaTrackConstraints.h index df4eb3219284..5977c607b602 100644 --- a/dom/media/webrtc/MediaTrackConstraints.h +++ b/dom/media/webrtc/MediaTrackConstraints.h @@ -123,20 +123,7 @@ struct NormalizedConstraintSet } bool Intersects(const StringRange& aOther) const; void Intersect(const StringRange& aOther); - bool Merge(const StringRange& aOther) - { - if (!Intersects(aOther)) { - return false; - } - Intersect(aOther); - - for (auto& entry : aOther.mIdeal) { - if (mIdeal.find(entry) == mIdeal.end()) { - mIdeal.insert(entry); - } - } - return true; - } + bool Merge(const StringRange& aOther); void FinalizeMerge() {} }; @@ -183,7 +170,7 @@ struct NormalizedConstraints : public NormalizedConstraintSet const nsTArray& aOthers); nsTArray mAdvanced; - bool mOverconstrained; + const char* mBadConstraint; }; // Flattened version is used in low-level code with orthogonal constraints only.