Bug 1571667 - Lift constraint checking of deviceId and groupId out of MediaEngineSources. r=jib
authorAndreas Pehrson <apehrson@mozilla.com>
Wed, 28 Aug 2019 08:39:57 +0000
changeset 554085 40bce1ab227e027ce5e06d190cb57a3972479da9
parent 554084 e7d03b7c3b68da1b191e1f82ef19e2e9f59eef34
child 554086 face7b46b2530de3127b0d476edb268afdd62103
push id2165
push userffxbld-merge
push dateMon, 14 Oct 2019 16:30:58 +0000
treeherdermozilla-release@0eae18af659f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib
bugs1571667
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1571667 - Lift constraint checking of deviceId and groupId out of MediaEngineSources. r=jib Before this patch, it was unclear who was responsible for checking deviceId and groupId constraints for devices. MediaManager was doing it through one path for getUserMedia, with the help of the devices, as part of selecting the best-fitting device. However, Reconfigure() took another path where the regular backends for camera and microphone were implemented correctly, but fake devices were left out so automated tests for applyConstraints were failing. This patch lifts the responsibility for checking deviceId and groupId constraints out of the MediaEngineSources into MediaDevice, which already is the owner of the anonymized ids that MediaEngineSources are unaware of. This makes constraints checking a two-staged approached where deviceId and groupid goes first. If they satisfy the constraints, the underlying device is queried for whether the constraints fit. As a bonus, this unclutters a lot of the MediaEngineSource interface. Differential Revision: https://phabricator.services.mozilla.com/D40834
dom/media/MediaManager.cpp
dom/media/MediaManager.h
dom/media/gtest/TestGroupId.cpp
dom/media/webrtc/MediaEngineDefault.cpp
dom/media/webrtc/MediaEngineDefault.h
dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
dom/media/webrtc/MediaEngineRemoteVideoSource.h
dom/media/webrtc/MediaEngineSource.h
dom/media/webrtc/MediaEngineTabVideoSource.cpp
dom/media/webrtc/MediaEngineTabVideoSource.h
dom/media/webrtc/MediaEngineWebRTCAudio.cpp
dom/media/webrtc/MediaEngineWebRTCAudio.h
dom/media/webrtc/MediaTrackConstraints.cpp
dom/media/webrtc/MediaTrackConstraints.h
testing/web-platform/meta/mediacapture-streams/MediaStreamTrack-applyConstraints.https.html.ini
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -843,16 +843,17 @@ MediaDevice::MediaDevice(const RefPtr<Me
                          const nsString& aName, const nsString& aID,
                          const nsString& aGroupID, const nsString& aRawID)
     : mSource(aSource),
       mSinkInfo(nullptr),
       mKind((mSource && MediaEngineSource::IsVideo(mSource->GetMediaSource()))
                 ? MediaDeviceKind::Videoinput
                 : MediaDeviceKind::Audioinput),
       mScary(mSource->GetScary()),
+      mIsFake(mSource->IsFake()),
       mType(NS_ConvertUTF8toUTF16(
           dom::MediaDeviceKindValues::strings[uint32_t(mKind)].value)),
       mName(aName),
       mID(aID),
       mGroupID(aGroupID),
       mRawID(aRawID) {
   MOZ_ASSERT(mSource);
 }
@@ -861,16 +862,17 @@ MediaDevice::MediaDevice(const RefPtr<Au
                          const nsString& aID, const nsString& aGroupID,
                          const nsString& aRawID)
     : mSource(nullptr),
       mSinkInfo(aAudioDeviceInfo),
       mKind(mSinkInfo->Type() == AudioDeviceInfo::TYPE_INPUT
                 ? MediaDeviceKind::Audioinput
                 : MediaDeviceKind::Audiooutput),
       mScary(false),
+      mIsFake(false),
       mType(NS_ConvertUTF8toUTF16(
           dom::MediaDeviceKindValues::strings[uint32_t(mKind)].value)),
       mName(mSinkInfo->Name()),
       mID(aID),
       mGroupID(aGroupID),
       mRawID(aRawID) {
   // For now this ctor is used only for Audiooutput.
   // It could be used for Audioinput and Videoinput
@@ -881,16 +883,17 @@ MediaDevice::MediaDevice(const RefPtr<Au
 }
 
 MediaDevice::MediaDevice(const RefPtr<MediaDevice>& aOther, const nsString& aID,
                          const nsString& aGroupID, const nsString& aRawID)
     : mSource(aOther->mSource),
       mSinkInfo(aOther->mSinkInfo),
       mKind(aOther->mKind),
       mScary(aOther->mScary),
+      mIsFake(aOther->mIsFake),
       mType(aOther->mType),
       mName(aOther->mName),
       mID(aID),
       mGroupID(aGroupID),
       mRawID(aRawID) {
   MOZ_ASSERT(aOther);
 }
 
@@ -944,20 +947,34 @@ uint32_t MediaDevice::FitnessDistance(
 }
 
 uint32_t MediaDevice::GetBestFitnessDistance(
     const nsTArray<const NormalizedConstraintSet*>& aConstraintSets,
     bool aIsChrome) {
   MOZ_ASSERT(MediaManager::IsInMediaThread());
   MOZ_ASSERT(mSource);
 
-  // Forward request to underlying object to interrogate per-mode capabilities.
-  // Pass in device's origin-specific id for deviceId constraint comparison.
   const nsString& id = aIsChrome ? mRawID : mID;
-  return mSource->GetBestFitnessDistance(aConstraintSets, id, mGroupID);
+  auto type = GetMediaSource();
+  uint64_t distance = 0;
+  if (!aConstraintSets.IsEmpty()) {
+    if (type == MediaSourceEnum::Camera ||
+        type == MediaSourceEnum::Microphone) {
+      distance += uint64_t(MediaConstraintsHelper::FitnessDistance(
+                      Some(id), aConstraintSets[0]->mDeviceId)) +
+                  uint64_t(MediaConstraintsHelper::FitnessDistance(
+                      Some(mGroupID), aConstraintSets[0]->mGroupId));
+    }
+  }
+  if (distance < UINT32_MAX) {
+    // Forward request to underlying object to interrogate per-mode
+    // capabilities.
+    distance += mSource->GetBestFitnessDistance(aConstraintSets);
+  }
+  return std::min<uint64_t>(distance, UINT32_MAX);
 }
 
 NS_IMETHODIMP
 MediaDevice::GetName(nsAString& aName) {
   MOZ_ASSERT(NS_IsMainThread());
   aName.Assign(mName);
   return NS_OK;
 }
@@ -1011,17 +1028,25 @@ MediaDevice::GetMediaSource(nsAString& a
 }
 
 nsresult MediaDevice::Allocate(const MediaTrackConstraints& aConstraints,
                                const MediaEnginePrefs& aPrefs,
                                const ipc::PrincipalInfo& aPrincipalInfo,
                                const char** aOutBadConstraint) {
   MOZ_ASSERT(MediaManager::IsInMediaThread());
   MOZ_ASSERT(mSource);
-  return mSource->Allocate(aConstraints, aPrefs, mID, mGroupID, aPrincipalInfo,
+
+  // Mock failure for automated tests.
+  if (mIsFake && aConstraints.mDeviceId.WasPassed() &&
+      aConstraints.mDeviceId.Value().IsString() &&
+      aConstraints.mDeviceId.Value().GetAsString().EqualsASCII("bad device")) {
+    return NS_ERROR_FAILURE;
+  }
+
+  return mSource->Allocate(aConstraints, aPrefs, aPrincipalInfo,
                            aOutBadConstraint);
 }
 
 void MediaDevice::SetTrack(const RefPtr<SourceMediaStream>& aStream,
                            TrackID aTrackID,
                            const PrincipalHandle& aPrincipalHandle) {
   MOZ_ASSERT(MediaManager::IsInMediaThread());
   MOZ_ASSERT(mSource);
@@ -1034,18 +1059,31 @@ nsresult MediaDevice::Start() {
   return mSource->Start();
 }
 
 nsresult MediaDevice::Reconfigure(const MediaTrackConstraints& aConstraints,
                                   const MediaEnginePrefs& aPrefs,
                                   const char** aOutBadConstraint) {
   MOZ_ASSERT(MediaManager::IsInMediaThread());
   MOZ_ASSERT(mSource);
-  return mSource->Reconfigure(aConstraints, aPrefs, mID, mGroupID,
-                              aOutBadConstraint);
+  auto type = GetMediaSource();
+  if (type == MediaSourceEnum::Camera || type == MediaSourceEnum::Microphone) {
+    NormalizedConstraints c(aConstraints);
+    if (MediaConstraintsHelper::FitnessDistance(Some(mID), c.mDeviceId) ==
+        UINT32_MAX) {
+      *aOutBadConstraint = "deviceId";
+      return NS_ERROR_INVALID_ARG;
+    }
+    if (MediaConstraintsHelper::FitnessDistance(Some(mGroupID), c.mGroupId) ==
+        UINT32_MAX) {
+      *aOutBadConstraint = "groupId";
+      return NS_ERROR_INVALID_ARG;
+    }
+  }
+  return mSource->Reconfigure(aConstraints, aPrefs, aOutBadConstraint);
 }
 
 nsresult MediaDevice::FocusOnSelectedSource() {
   MOZ_ASSERT(MediaManager::IsInMediaThread());
   MOZ_ASSERT(mSource);
   return mSource->FocusOnSelectedSource();
 }
 
--- a/dom/media/MediaManager.h
+++ b/dom/media/MediaManager.h
@@ -113,16 +113,17 @@ class MediaDevice : public nsIMediaDevic
   static uint32_t FitnessDistance(
       nsString aN, const dom::ConstrainDOMStringParameters& aParams);
 
  public:
   const RefPtr<MediaEngineSource> mSource;
   const RefPtr<AudioDeviceInfo> mSinkInfo;
   const dom::MediaDeviceKind mKind;
   const bool mScary;
+  const bool mIsFake;
   const nsString mType;
   const nsString mName;
   const nsString mID;
   const nsString mGroupID;
   const nsString mRawID;
 };
 
 typedef nsRefPtrHashtable<nsUint64HashKey, GetUserMediaWindowListener>
--- a/dom/media/gtest/TestGroupId.cpp
+++ b/dom/media/gtest/TestGroupId.cpp
@@ -28,35 +28,26 @@ class MockMediaEngineSource : public Med
  public:
   MOCK_CONST_METHOD0(GetMediaSource, dom::MediaSourceEnum());
 
   /* Unused overrides */
   MOCK_CONST_METHOD0(GetName, nsString());
   MOCK_CONST_METHOD0(GetUUID, nsCString());
   MOCK_CONST_METHOD0(GetGroupId, nsString());
   MOCK_CONST_METHOD1(GetSettings, void(dom::MediaTrackSettings&));
-  MOCK_METHOD6(Allocate, nsresult(const dom::MediaTrackConstraints&,
-                                  const MediaEnginePrefs&, const nsString&,
-                                  const nsString&, const ipc::PrincipalInfo&,
-                                  const char**));
+  MOCK_METHOD4(Allocate, nsresult(const dom::MediaTrackConstraints&,
+                                  const MediaEnginePrefs&,
+                                  const ipc::PrincipalInfo&, const char**));
   MOCK_METHOD3(SetTrack, void(const RefPtr<SourceMediaStream>&, TrackID,
                               const PrincipalHandle&));
   MOCK_METHOD0(Start, nsresult());
-  MOCK_METHOD5(Reconfigure, nsresult(const dom::MediaTrackConstraints&,
-                                     const MediaEnginePrefs&, const nsString&,
-                                     const nsString&, const char**));
+  MOCK_METHOD3(Reconfigure, nsresult(const dom::MediaTrackConstraints&,
+                                     const MediaEnginePrefs&, const char**));
   MOCK_METHOD0(Stop, nsresult());
   MOCK_METHOD0(Deallocate, nsresult());
-  MOCK_CONST_METHOD3(GetBestFitnessDistance,
-                     uint32_t(const nsTArray<const NormalizedConstraintSet*>&,
-                              const nsString&, const nsString&));
-  MOCK_METHOD5(Pull,
-               void(const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
-                    StreamTime aEndOfAppendedData, StreamTime aDesiredTime,
-                    const PrincipalHandle& aPrincipalHandle));
 };
 
 RefPtr<AudioDeviceInfo> MakeAudioDeviceInfo(const nsString aName) {
   return MakeRefPtr<AudioDeviceInfo>(
       nullptr, aName, NS_LITERAL_STRING("GroupId"), NS_LITERAL_STRING("Vendor"),
       AudioDeviceInfo::TYPE_OUTPUT, AudioDeviceInfo::STATE_ENABLED,
       AudioDeviceInfo::PREF_NONE, AudioDeviceInfo::FMT_F32LE,
       AudioDeviceInfo::FMT_F32LE, 2u, 44100u, 44100u, 44100u, 0, 0);
--- a/dom/media/webrtc/MediaEngineDefault.cpp
+++ b/dom/media/webrtc/MediaEngineDefault.cpp
@@ -93,28 +93,22 @@ nsCString MediaEngineDefaultVideoSource:
   return NS_LITERAL_CSTRING("1041FCBD-3F12-4F7B-9E9B-1EC556DD5676");
 }
 
 nsString MediaEngineDefaultVideoSource::GetGroupId() const {
   return NS_LITERAL_STRING(u"Default Video Group");
 }
 
 uint32_t MediaEngineDefaultVideoSource::GetBestFitnessDistance(
-    const nsTArray<const NormalizedConstraintSet*>& aConstraintSets,
-    const nsString& aDeviceId, const nsString& aGroupId) const {
+    const nsTArray<const NormalizedConstraintSet*>& aConstraintSets) const {
   AssertIsOnOwningThread();
 
   uint64_t distance = 0;
 #ifdef MOZ_WEBRTC
   for (const auto* cs : aConstraintSets) {
-    distance +=
-        MediaConstraintsHelper::FitnessDistance(Some(aDeviceId), cs->mDeviceId);
-    distance +=
-        MediaConstraintsHelper::FitnessDistance(Some(aGroupId), cs->mGroupId);
-
     Maybe<nsString> facingMode = Nothing();
     distance +=
         MediaConstraintsHelper::FitnessDistance(facingMode, cs->mFacingMode);
 
     if (cs->mWidth.mMax < VIDEO_WIDTH_MIN ||
         cs->mWidth.mMin > VIDEO_WIDTH_MAX) {
       distance += UINT32_MAX;
     }
@@ -133,31 +127,24 @@ uint32_t MediaEngineDefaultVideoSource::
 void MediaEngineDefaultVideoSource::GetSettings(
     MediaTrackSettings& aOutSettings) const {
   MOZ_ASSERT(NS_IsMainThread());
   aOutSettings = *mSettings;
 }
 
 nsresult MediaEngineDefaultVideoSource::Allocate(
     const MediaTrackConstraints& aConstraints, const MediaEnginePrefs& aPrefs,
-    const nsString& aDeviceId, const nsString& aGroupId,
     const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
     const char** aOutBadConstraint) {
   AssertIsOnOwningThread();
 
   MOZ_ASSERT(mState == kReleased);
 
   FlattenedConstraints c(aConstraints);
 
-  // Mock failure for automated tests.
-  if (c.mDeviceId.mIdeal.find(NS_LITERAL_STRING("bad device")) !=
-      c.mDeviceId.mIdeal.end()) {
-    return NS_ERROR_FAILURE;
-  }
-
   // emulator debug is very, very slow; reduce load on it with smaller/slower
   // fake video
   mOpts = aPrefs;
   mOpts.mWidth =
       c.mWidth.Get(aPrefs.mWidth ? aPrefs.mWidth :
 #ifdef DEBUG
                                  MediaEnginePrefs::DEFAULT_43_VIDEO_WIDTH / 2
 #else
@@ -311,17 +298,16 @@ nsresult MediaEngineDefaultVideoSource::
 
   mState = kStopped;
 
   return NS_OK;
 }
 
 nsresult MediaEngineDefaultVideoSource::Reconfigure(
     const MediaTrackConstraints& aConstraints, const MediaEnginePrefs& aPrefs,
-    const nsString& aDeviceId, const nsString& aGroupId,
     const char** aOutBadConstraint) {
   return NS_OK;
 }
 
 void MediaEngineDefaultVideoSource::GenerateFrame() {
   AssertIsOnOwningThread();
 
   // Update the target color
@@ -418,55 +404,33 @@ nsString MediaEngineDefaultAudioSource::
 nsCString MediaEngineDefaultAudioSource::GetUUID() const {
   return NS_LITERAL_CSTRING("B7CBD7C1-53EF-42F9-8353-73F61C70C092");
 }
 
 nsString MediaEngineDefaultAudioSource::GetGroupId() const {
   return NS_LITERAL_STRING(u"Default Audio Group");
 }
 
-uint32_t MediaEngineDefaultAudioSource::GetBestFitnessDistance(
-    const nsTArray<const NormalizedConstraintSet*>& aConstraintSets,
-    const nsString& aDeviceId, const nsString& aGroupId) const {
-  uint32_t distance = 0;
-#ifdef MOZ_WEBRTC
-  for (const auto* cs : aConstraintSets) {
-    distance = MediaConstraintsHelper::GetMinimumFitnessDistance(*cs, aDeviceId,
-                                                                 aGroupId);
-    break;  // distance is read from first entry only
-  }
-#endif
-  return distance;
-}
-
 void MediaEngineDefaultAudioSource::GetSettings(
     MediaTrackSettings& aOutSettings) const {
   MOZ_ASSERT(NS_IsMainThread());
   aOutSettings.mAutoGainControl.Construct(false);
   aOutSettings.mEchoCancellation.Construct(false);
   aOutSettings.mNoiseSuppression.Construct(false);
   aOutSettings.mChannelCount.Construct(1);
 }
 
 nsresult MediaEngineDefaultAudioSource::Allocate(
     const MediaTrackConstraints& aConstraints, const MediaEnginePrefs& aPrefs,
-    const nsString& aDeviceId, const nsString& aGroupId,
     const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
     const char** aOutBadConstraint) {
   AssertIsOnOwningThread();
 
   MOZ_ASSERT(mState == kReleased);
 
-  // Mock failure for automated tests.
-  if (aConstraints.mDeviceId.WasPassed() &&
-      aConstraints.mDeviceId.Value().IsString() &&
-      aConstraints.mDeviceId.Value().GetAsString().EqualsASCII("bad device")) {
-    return NS_ERROR_FAILURE;
-  }
-
   mFrequency = aPrefs.mFreq ? aPrefs.mFreq : 1000;
 
   mState = kAllocated;
   return NS_OK;
 }
 
 nsresult MediaEngineDefaultAudioSource::Deallocate() {
   AssertIsOnOwningThread();
@@ -545,17 +509,16 @@ nsresult MediaEngineDefaultAudioSource::
         stream->RemoveTrackListener(listener, track);
         stream->SetPullingEnabled(track, false);
       }));
   return NS_OK;
 }
 
 nsresult MediaEngineDefaultAudioSource::Reconfigure(
     const MediaTrackConstraints& aConstraints, const MediaEnginePrefs& aPrefs,
-    const nsString& aDeviceId, const nsString& aGroupId,
     const char** aOutBadConstraint) {
   return NS_OK;
 }
 
 void AudioSourcePullListener::NotifyPull(MediaStreamGraph* aGraph,
                                          StreamTime aEndOfAppendedData,
                                          StreamTime aDesiredTime) {
   TRACE_AUDIO_CALLBACK_COMMENT("SourceMediaStream %p track %i", mStream.get(),
--- a/dom/media/webrtc/MediaEngineDefault.h
+++ b/dom/media/webrtc/MediaEngineDefault.h
@@ -38,33 +38,31 @@ class MediaEngineDefaultVideoSource : pu
  public:
   MediaEngineDefaultVideoSource();
 
   nsString GetName() const override;
   nsCString GetUUID() const override;
   nsString GetGroupId() const override;
 
   nsresult Allocate(const dom::MediaTrackConstraints& aConstraints,
-                    const MediaEnginePrefs& aPrefs, const nsString& aDeviceId,
-                    const nsString& aGroupId,
+                    const MediaEnginePrefs& aPrefs,
                     const ipc::PrincipalInfo& aPrincipalInfo,
                     const char** aOutBadConstraint) override;
   void SetTrack(const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
                 const PrincipalHandle& aPrincipal) override;
   nsresult Start() override;
   nsresult Reconfigure(const dom::MediaTrackConstraints& aConstraints,
                        const MediaEnginePrefs& aPrefs,
-                       const nsString& aDeviceId, const nsString& aGroupId,
                        const char** aOutBadConstraint) override;
   nsresult Stop() override;
   nsresult Deallocate() override;
 
   uint32_t GetBestFitnessDistance(
-      const nsTArray<const NormalizedConstraintSet*>& aConstraintSets,
-      const nsString& aDeviceId, const nsString& aGroupId) const override;
+      const nsTArray<const NormalizedConstraintSet*>& aConstraintSets)
+      const override;
   void GetSettings(dom::MediaTrackSettings& aOutSettings) const override;
 
   bool IsFake() const override { return true; }
 
   dom::MediaSourceEnum GetMediaSource() const override {
     return dom::MediaSourceEnum::Camera;
   }
 
@@ -104,39 +102,34 @@ class MediaEngineDefaultAudioSource : pu
  public:
   MediaEngineDefaultAudioSource();
 
   nsString GetName() const override;
   nsCString GetUUID() const override;
   nsString GetGroupId() const override;
 
   nsresult Allocate(const dom::MediaTrackConstraints& aConstraints,
-                    const MediaEnginePrefs& aPrefs, const nsString& aDeviceId,
-                    const nsString& aGroupId,
+                    const MediaEnginePrefs& aPrefs,
                     const ipc::PrincipalInfo& aPrincipalInfo,
                     const char** aOutBadConstraint) override;
   void SetTrack(const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
                 const PrincipalHandle& aPrincipal) override;
   nsresult Start() override;
   nsresult Reconfigure(const dom::MediaTrackConstraints& aConstraints,
                        const MediaEnginePrefs& aPrefs,
-                       const nsString& aDeviceId, const nsString& aGroupId,
                        const char** aOutBadConstraint) override;
   nsresult Stop() override;
   nsresult Deallocate() override;
 
   bool IsFake() const override { return true; }
 
   dom::MediaSourceEnum GetMediaSource() const override {
     return dom::MediaSourceEnum::Microphone;
   }
 
-  uint32_t GetBestFitnessDistance(
-      const nsTArray<const NormalizedConstraintSet*>& aConstraintSets,
-      const nsString& aDeviceId, const nsString& aGroupId) const override;
   void GetSettings(dom::MediaTrackSettings& aOutSettings) const override;
 
  protected:
   ~MediaEngineDefaultAudioSource();
 
   // Current state of this source.
   MediaEngineSourceState mState = kReleased;
   RefPtr<SourceMediaStream> mStream;
--- a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
@@ -187,36 +187,34 @@ nsString MediaEngineRemoteVideoSource::G
 
   // The remote video backend doesn't implement group id. We return the device
   // name and higher layers will correlate this with the name of audio devices.
   return mDeviceName;
 }
 
 nsresult MediaEngineRemoteVideoSource::Allocate(
     const MediaTrackConstraints& aConstraints, const MediaEnginePrefs& aPrefs,
-    const nsString& aDeviceId, const nsString& aGroupId,
     const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
     const char** aOutBadConstraint) {
   LOG("%s", __PRETTY_FUNCTION__);
   AssertIsOnOwningThread();
 
   MOZ_ASSERT(mState == kReleased);
 
   if (!mInitDone) {
     LOG("Init not done");
     return NS_ERROR_FAILURE;
   }
 
   NormalizedConstraints constraints(aConstraints);
   webrtc::CaptureCapability newCapability;
   LOG("ChooseCapability(kFitness) for mCapability (Allocate) ++");
-  if (!ChooseCapability(constraints, aPrefs, aDeviceId, aGroupId, newCapability,
-                        kFitness)) {
-    *aOutBadConstraint = MediaConstraintsHelper::FindBadConstraint(
-        constraints, this, aDeviceId, aGroupId);
+  if (!ChooseCapability(constraints, aPrefs, newCapability, kFitness)) {
+    *aOutBadConstraint =
+        MediaConstraintsHelper::FindBadConstraint(constraints, this);
     return NS_ERROR_FAILURE;
   }
   LOG("ChooseCapability(kFitness) for mCapability (Allocate) --");
 
   if (camera::GetChildAndCall(&camera::CamerasChild::AllocateCaptureDevice,
                               mCapEngine, mUniqueId.get(), kMaxUniqueIdLength,
                               mCaptureIndex, aPrincipalInfo)) {
     return NS_ERROR_FAILURE;
@@ -376,30 +374,28 @@ nsresult MediaEngineRemoteVideoSource::S
     mState = kStopped;
   }
 
   return NS_OK;
 }
 
 nsresult MediaEngineRemoteVideoSource::Reconfigure(
     const MediaTrackConstraints& aConstraints, const MediaEnginePrefs& aPrefs,
-    const nsString& aDeviceId, const nsString& aGroupId,
     const char** aOutBadConstraint) {
   LOG("%s", __PRETTY_FUNCTION__);
   AssertIsOnOwningThread();
 
   MOZ_ASSERT(mInitDone);
 
   NormalizedConstraints constraints(aConstraints);
   webrtc::CaptureCapability newCapability;
   LOG("ChooseCapability(kFitness) for mTargetCapability (Reconfigure) ++");
-  if (!ChooseCapability(constraints, aPrefs, aDeviceId, aGroupId, newCapability,
-                        kFitness)) {
-    *aOutBadConstraint = MediaConstraintsHelper::FindBadConstraint(
-        constraints, this, aDeviceId, aGroupId);
+  if (!ChooseCapability(constraints, aPrefs, newCapability, kFitness)) {
+    *aOutBadConstraint =
+        MediaConstraintsHelper::FindBadConstraint(constraints, this);
     return NS_ERROR_INVALID_ARG;
   }
   LOG("ChooseCapability(kFitness) for mTargetCapability (Reconfigure) --");
 
   if (mCapability == newCapability) {
     return NS_OK;
   }
 
@@ -627,65 +623,58 @@ int MediaEngineRemoteVideoSource::Delive
     mStream->AppendToTrack(mTrackID, &segment);
   }
 
   return 0;
 }
 
 uint32_t MediaEngineRemoteVideoSource::GetDistance(
     const webrtc::CaptureCapability& aCandidate,
-    const NormalizedConstraintSet& aConstraints, const nsString& aDeviceId,
-    const nsString& aGroupId, const DistanceCalculation aCalculate) const {
+    const NormalizedConstraintSet& aConstraints,
+    const DistanceCalculation aCalculate) const {
   if (aCalculate == kFeasibility) {
-    return GetFeasibilityDistance(aCandidate, aConstraints, aDeviceId,
-                                  aGroupId);
+    return GetFeasibilityDistance(aCandidate, aConstraints);
   }
-  return GetFitnessDistance(aCandidate, aConstraints, aDeviceId, aGroupId);
+  return GetFitnessDistance(aCandidate, aConstraints);
 }
 
 uint32_t MediaEngineRemoteVideoSource::GetFitnessDistance(
     const webrtc::CaptureCapability& aCandidate,
-    const NormalizedConstraintSet& aConstraints, const nsString& aDeviceId,
-    const nsString& aGroupId) const {
+    const NormalizedConstraintSet& aConstraints) const {
   AssertIsOnOwningThread();
 
   // Treat width|height|frameRate == 0 on capability as "can do any".
   // This allows for orthogonal capabilities that are not in discrete steps.
 
   typedef MediaConstraintsHelper H;
   uint64_t distance =
-      uint64_t(H::FitnessDistance(Some(aDeviceId), aConstraints.mDeviceId)) +
-      uint64_t(H::FitnessDistance(Some(aGroupId), aConstraints.mGroupId)) +
       uint64_t(H::FitnessDistance(mFacingMode, aConstraints.mFacingMode)) +
       uint64_t(aCandidate.width ? H::FitnessDistance(int32_t(aCandidate.width),
                                                      aConstraints.mWidth)
                                 : 0) +
       uint64_t(aCandidate.height
                    ? H::FitnessDistance(int32_t(aCandidate.height),
                                         aConstraints.mHeight)
                    : 0) +
       uint64_t(aCandidate.maxFPS ? H::FitnessDistance(double(aCandidate.maxFPS),
                                                       aConstraints.mFrameRate)
                                  : 0);
   return uint32_t(std::min(distance, uint64_t(UINT32_MAX)));
 }
 
 uint32_t MediaEngineRemoteVideoSource::GetFeasibilityDistance(
     const webrtc::CaptureCapability& aCandidate,
-    const NormalizedConstraintSet& aConstraints, const nsString& aDeviceId,
-    const nsString& aGroupId) const {
+    const NormalizedConstraintSet& aConstraints) const {
   AssertIsOnOwningThread();
 
   // Treat width|height|frameRate == 0 on capability as "can do any".
   // This allows for orthogonal capabilities that are not in discrete steps.
 
   typedef MediaConstraintsHelper H;
   uint64_t distance =
-      uint64_t(H::FitnessDistance(Some(aDeviceId), aConstraints.mDeviceId)) +
-      uint64_t(H::FitnessDistance(Some(aGroupId), aConstraints.mGroupId)) +
       uint64_t(H::FitnessDistance(mFacingMode, aConstraints.mFacingMode)) +
       uint64_t(aCandidate.width
                    ? H::FeasibilityDistance(int32_t(aCandidate.width),
                                             aConstraints.mWidth)
                    : 0) +
       uint64_t(aCandidate.height
                    ? H::FeasibilityDistance(int32_t(aCandidate.height),
                                             aConstraints.mHeight)
@@ -714,32 +703,30 @@ void MediaEngineRemoteVideoSource::TrimL
     } else {
       ++i;
     }
   }
   MOZ_ASSERT(aSet.Length());
 }
 
 uint32_t MediaEngineRemoteVideoSource::GetBestFitnessDistance(
-    const nsTArray<const NormalizedConstraintSet*>& aConstraintSets,
-    const nsString& aDeviceId, const nsString& aGroupId) const {
+    const nsTArray<const NormalizedConstraintSet*>& aConstraintSets) const {
   AssertIsOnOwningThread();
 
   size_t num = NumCapabilities();
   nsTArray<CapabilityCandidate> candidateSet;
   for (size_t i = 0; i < num; i++) {
     candidateSet.AppendElement(CapabilityCandidate(GetCapability(i)));
   }
 
   bool first = true;
   for (const NormalizedConstraintSet* ns : aConstraintSets) {
     for (size_t i = 0; i < candidateSet.Length();) {
       auto& candidate = candidateSet[i];
-      uint32_t distance =
-          GetFitnessDistance(candidate.mCapability, *ns, aDeviceId, aGroupId);
+      uint32_t distance = GetFitnessDistance(candidate.mCapability, *ns);
       if (distance == UINT32_MAX) {
         candidateSet.RemoveElementAt(i);
       } else {
         ++i;
         if (first) {
           candidate.mDistance = distance;
         }
       }
@@ -764,17 +751,16 @@ static void LogCapability(const char* aH
       aCapability.width, aCapability.height, aCapability.maxFPS,
       codec[std::min(std::max(uint32_t(0), uint32_t(aCapability.videoType)),
                      uint32_t(sizeof(codec) / sizeof(*codec) - 1))],
       aDistance);
 }
 
 bool MediaEngineRemoteVideoSource::ChooseCapability(
     const NormalizedConstraints& aConstraints, const MediaEnginePrefs& aPrefs,
-    const nsString& aDeviceId, const nsString& aGroupId,
     webrtc::CaptureCapability& aCapability,
     const DistanceCalculation aCalculate) {
   LOG("%s", __PRETTY_FUNCTION__);
   AssertIsOnOwningThread();
 
   if (MOZ_LOG_TEST(gMediaManagerLog, LogLevel::Debug)) {
     LOG("ChooseCapability: prefs: %dx%d @%dfps", aPrefs.GetWidth(),
         aPrefs.GetHeight(), aPrefs.mFPS);
@@ -863,18 +849,18 @@ bool MediaEngineRemoteVideoSource::Choos
       candidateSet.AppendElement(cap);
     }
   }
 
   // First, filter capabilities by required constraints (min, max, exact).
 
   for (size_t i = 0; i < candidateSet.Length();) {
     auto& candidate = candidateSet[i];
-    candidate.mDistance = GetDistance(candidate.mCapability, aConstraints,
-                                      aDeviceId, aGroupId, aCalculate);
+    candidate.mDistance =
+        GetDistance(candidate.mCapability, aConstraints, aCalculate);
     LogCapability("Capability", candidate.mCapability, candidate.mDistance);
     if (candidate.mDistance == UINT32_MAX) {
       candidateSet.RemoveElementAt(i);
     } else {
       ++i;
     }
   }
 
@@ -884,18 +870,18 @@ bool MediaEngineRemoteVideoSource::Choos
     return false;
   }
 
   // Filter further with all advanced constraints (that don't overconstrain).
 
   for (const auto& cs : aConstraints.mAdvanced) {
     nsTArray<CapabilityCandidate> rejects;
     for (size_t i = 0; i < candidateSet.Length();) {
-      if (GetDistance(candidateSet[i].mCapability, cs, aDeviceId, aGroupId,
-                      aCalculate) == UINT32_MAX) {
+      if (GetDistance(candidateSet[i].mCapability, cs, aCalculate) ==
+          UINT32_MAX) {
         rejects.AppendElement(candidateSet[i]);
         candidateSet.RemoveElementAt(i);
       } else {
         ++i;
       }
     }
     if (!candidateSet.Length()) {
       candidateSet.AppendElements(std::move(rejects));
@@ -915,18 +901,18 @@ bool MediaEngineRemoteVideoSource::Choos
   {
     MediaTrackConstraintSet prefs;
     prefs.mWidth.Construct().SetAsLong() = aPrefs.GetWidth();
     prefs.mHeight.Construct().SetAsLong() = aPrefs.GetHeight();
     prefs.mFrameRate.Construct().SetAsDouble() = aPrefs.mFPS;
     NormalizedConstraintSet normPrefs(prefs, false);
 
     for (auto& candidate : candidateSet) {
-      candidate.mDistance = GetDistance(candidate.mCapability, normPrefs,
-                                        aDeviceId, aGroupId, aCalculate);
+      candidate.mDistance =
+          GetDistance(candidate.mCapability, normPrefs, aCalculate);
     }
     TrimLessFitCandidates(candidateSet);
   }
 
   aCapability = candidateSet[0].mCapability;
 
   LogCapability("Chosen capability", aCapability, sameDistance);
   return true;
--- a/dom/media/webrtc/MediaEngineRemoteVideoSource.h
+++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.h
@@ -79,67 +79,60 @@ class MediaEngineRemoteVideoSource : pub
     bool Equals(const CapabilityCandidate& aCandidate,
                 const webrtc::CaptureCapability& aCapability) const {
       return aCandidate.mCapability == aCapability;
     }
   };
 
   bool ChooseCapability(const NormalizedConstraints& aConstraints,
                         const MediaEnginePrefs& aPrefs,
-                        const nsString& aDeviceId, const nsString& aGroupId,
                         webrtc::CaptureCapability& aCapability,
                         const DistanceCalculation aCalculate);
 
   uint32_t GetDistance(const webrtc::CaptureCapability& aCandidate,
                        const NormalizedConstraintSet& aConstraints,
-                       const nsString& aDeviceId, const nsString& aGroupId,
                        const DistanceCalculation aCalculate) const;
 
-  uint32_t GetFitnessDistance(const webrtc::CaptureCapability& aCandidate,
-                              const NormalizedConstraintSet& aConstraints,
-                              const nsString& aDeviceId,
-                              const nsString& aGroupId) const;
+  uint32_t GetFitnessDistance(
+      const webrtc::CaptureCapability& aCandidate,
+      const NormalizedConstraintSet& aConstraints) const;
 
-  uint32_t GetFeasibilityDistance(const webrtc::CaptureCapability& aCandidate,
-                                  const NormalizedConstraintSet& aConstraints,
-                                  const nsString& aDeviceId,
-                                  const nsString& aGroupId) const;
+  uint32_t GetFeasibilityDistance(
+      const webrtc::CaptureCapability& aCandidate,
+      const NormalizedConstraintSet& aConstraints) const;
 
   static void TrimLessFitCandidates(nsTArray<CapabilityCandidate>& aSet);
 
-  uint32_t GetBestFitnessDistance(
-      const nsTArray<const NormalizedConstraintSet*>& aConstraintSets,
-      const nsString& aDeviceId, const nsString& aGroupId) const override;
-
  public:
   MediaEngineRemoteVideoSource(int aIndex, camera::CaptureEngine aCapEngine,
                                bool aScary);
 
   // ExternalRenderer
   int DeliverFrame(uint8_t* aBuffer,
                    const camera::VideoFrameProperties& aProps) override;
 
   // MediaEngineSource
   dom::MediaSourceEnum GetMediaSource() const override;
   nsresult Allocate(const dom::MediaTrackConstraints& aConstraints,
-                    const MediaEnginePrefs& aPrefs, const nsString& aDeviceId,
-                    const nsString& aGroupId,
+                    const MediaEnginePrefs& aPrefs,
                     const ipc::PrincipalInfo& aPrincipalInfo,
                     const char** aOutBadConstraint) override;
   nsresult Deallocate() override;
   void SetTrack(const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
                 const PrincipalHandle& aPrincipal) override;
   nsresult Start() override;
   nsresult Reconfigure(const dom::MediaTrackConstraints& aConstraints,
                        const MediaEnginePrefs& aPrefs,
-                       const nsString& aDeviceId, const nsString& aGroupId,
                        const char** aOutBadConstraint) override;
   nsresult FocusOnSelectedSource() override;
   nsresult Stop() override;
 
+  uint32_t GetBestFitnessDistance(
+      const nsTArray<const NormalizedConstraintSet*>& aConstraintSets)
+      const override;
   void GetSettings(dom::MediaTrackSettings& aOutSettings) const override;
 
   void Refresh(int aIndex);
 
   void Shutdown() override;
 
   nsString GetName() const override;
   void SetName(nsString aName);
--- a/dom/media/webrtc/MediaEngineSource.h
+++ b/dom/media/webrtc/MediaEngineSource.h
@@ -106,17 +106,16 @@ class MediaEngineSourceInterface {
     return nullptr;
   }
 
   /**
    * Called by MediaEngine to allocate an instance of this source.
    */
   virtual nsresult Allocate(const dom::MediaTrackConstraints& aConstraints,
                             const MediaEnginePrefs& aPrefs,
-                            const nsString& aDeviceId, const nsString& aGroupId,
                             const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
                             const char** aOutBadConstraint) = 0;
 
   /**
    * Called by MediaEngine when a SourceMediaStream and TrackID have been
    * provided for the source to feed data to.
    *
    * This must be called before Start.
@@ -158,18 +157,16 @@ class MediaEngineSourceInterface {
    * NS_ERROR_INVALID_ARG - Couldn't find a capability fitting aConstraints.
    *                        See aBadConstraint for details.
    * NS_ERROR_UNEXPECTED  - Reconfiguring the underlying device failed
    *                        unexpectedly. This leaves the device in a stopped
    *                        state.
    */
   virtual nsresult Reconfigure(const dom::MediaTrackConstraints& aConstraints,
                                const MediaEnginePrefs& aPrefs,
-                               const nsString& aDeviceId,
-                               const nsString& aGroupId,
                                const char** aOutBadConstraint) = 0;
 
   /**
    * Called by MediaEngine to stop feeding data to the track.
    *
    * Double-stopping is allowed and will return NS_OK. This is necessary
    * sometimes during shutdown.
    *
@@ -200,18 +197,18 @@ class MediaEngineSourceInterface {
    * offer as a whole, given an accumulated number of ConstraintSets. Ideal
    * values are considered in the first ConstraintSet only. Plain values are
    * treated as Ideal in the first ConstraintSet. Plain values are treated as
    * Exact in subsequent ConstraintSets. Infinity = UINT32_MAX e.g. device
    * cannot satisfy accumulated ConstraintSets. A finite result may be used to
    * calculate this device's ranking as a choice.
    */
   virtual uint32_t GetBestFitnessDistance(
-      const nsTArray<const NormalizedConstraintSet*>& aConstraintSets,
-      const nsString& aDeviceId, const nsString& aGroupId) const = 0;
+      const nsTArray<const NormalizedConstraintSet*>& aConstraintSets)
+      const = 0;
 
   /**
    * Returns the current settings of the underlying device.
    *
    * Note that this might not be the settings of the underlying hardware.
    * In case of a camera where we intervene and scale frames to avoid
    * leaking information from other documents than the current one,
    * GetSettings() will return the scaled resolution. I.e., the
@@ -258,15 +255,22 @@ class MediaEngineSource : public MediaEn
 
   // Shutdown does nothing by default.
   void Shutdown() override;
 
   // TakePhoto returns NS_ERROR_NOT_IMPLEMENTED by default,
   // to tell the caller to fallback to other methods.
   nsresult TakePhoto(MediaEnginePhotoCallback* aCallback) override;
 
+  // Returns a default distance of 0 for devices that don't have capabilities.
+  uint32_t GetBestFitnessDistance(
+      const nsTArray<const NormalizedConstraintSet*>& aConstraintSets)
+      const override {
+    return 0;
+  }
+
  protected:
   virtual ~MediaEngineSource();
 };
 
 }  // namespace mozilla
 
 #endif /* MediaEngineSource_h */
--- a/dom/media/webrtc/MediaEngineTabVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineTabVideoSource.cpp
@@ -128,37 +128,35 @@ nsString MediaEngineTabVideoSource::GetG
 }
 
 #define DEFAULT_TABSHARE_VIDEO_MAX_WIDTH 4096
 #define DEFAULT_TABSHARE_VIDEO_MAX_HEIGHT 4096
 #define DEFAULT_TABSHARE_VIDEO_FRAMERATE 30
 
 nsresult MediaEngineTabVideoSource::Allocate(
     const dom::MediaTrackConstraints& aConstraints,
-    const MediaEnginePrefs& aPrefs, const nsString& aDeviceId,
-    const nsString& aGroupId, const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
+    const MediaEnginePrefs& aPrefs,
+    const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
     const char** aOutBadConstraint) {
   AssertIsOnOwningThread();
 
   // windowId is not a proper constraint, so just read it.
   // It has no well-defined behavior in advanced, so ignore it there.
 
   mWindowId = aConstraints.mBrowserWindow.WasPassed()
                   ? aConstraints.mBrowserWindow.Value()
                   : -1;
   mState = kAllocated;
 
-  return Reconfigure(aConstraints, aPrefs, aDeviceId, aGroupId,
-                     aOutBadConstraint);
+  return Reconfigure(aConstraints, aPrefs, aOutBadConstraint);
 }
 
 nsresult MediaEngineTabVideoSource::Reconfigure(
     const dom::MediaTrackConstraints& aConstraints,
-    const mozilla::MediaEnginePrefs& aPrefs, const nsString& aDeviceId,
-    const nsString& aGroupId, const char** aOutBadConstraint) {
+    const mozilla::MediaEnginePrefs& aPrefs, const char** aOutBadConstraint) {
   AssertIsOnOwningThread();
   MOZ_ASSERT(mState != kReleased);
 
   // scrollWithPage is not proper a constraint, so just read it.
   // It has no well-defined behavior in advanced, so ignore it there.
 
   const bool scrollWithPage = aConstraints.mScrollWithPage.WasPassed()
                                   ? aConstraints.mScrollWithPage.Value()
--- a/dom/media/webrtc/MediaEngineTabVideoSource.h
+++ b/dom/media/webrtc/MediaEngineTabVideoSource.h
@@ -25,37 +25,29 @@ class MediaEngineTabVideoSource : public
 
   bool GetScary() const override { return true; }
 
   dom::MediaSourceEnum GetMediaSource() const override {
     return dom::MediaSourceEnum::Browser;
   }
 
   nsresult Allocate(const dom::MediaTrackConstraints& aConstraints,
-                    const MediaEnginePrefs& aPrefs, const nsString& aDeviceId,
-                    const nsString& aGroupId,
+                    const MediaEnginePrefs& aPrefs,
                     const ipc::PrincipalInfo& aPrincipalInfo,
                     const char** aOutBadConstraint) override;
   nsresult Deallocate() override;
   void SetTrack(const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
                 const PrincipalHandle& aPrincipal) override;
   nsresult Start() override;
   nsresult Reconfigure(const dom::MediaTrackConstraints& aConstraints,
                        const MediaEnginePrefs& aPrefs,
-                       const nsString& aDeviceId, const nsString& aGroupId,
                        const char** aOutBadConstraint) override;
   nsresult FocusOnSelectedSource() override;
   nsresult Stop() override;
 
-  uint32_t GetBestFitnessDistance(
-      const nsTArray<const NormalizedConstraintSet*>& aConstraintSets,
-      const nsString& aDeviceId, const nsString& aGroupId) const override {
-    return 0;
-  }
-
   void GetSettings(dom::MediaTrackSettings& aOutSettings) const override;
 
   void Draw();
 
   class StartRunnable : public Runnable {
    public:
     StartRunnable(MediaEngineTabVideoSource* videoSource,
                   SourceMediaStream* aStream, TrackID aTrackID,
--- a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
+++ b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
@@ -84,37 +84,16 @@ nsString MediaEngineWebRTCMicrophoneSour
 nsCString MediaEngineWebRTCMicrophoneSource::GetUUID() const {
   return mDeviceUUID;
 }
 
 nsString MediaEngineWebRTCMicrophoneSource::GetGroupId() const {
   return mDeviceGroup;
 }
 
-// GetBestFitnessDistance returns the best distance the capture device can offer
-// as a whole, given an accumulated number of ConstraintSets.
-// Ideal values are considered in the first ConstraintSet only.
-// Plain values are treated as Ideal in the first ConstraintSet.
-// Plain values are treated as Exact in subsequent ConstraintSets.
-// Infinity = UINT32_MAX e.g. device cannot satisfy accumulated ConstraintSets.
-// A finite result may be used to calculate this device's ranking as a choice.
-
-uint32_t MediaEngineWebRTCMicrophoneSource::GetBestFitnessDistance(
-    const nsTArray<const NormalizedConstraintSet*>& aConstraintSets,
-    const nsString& aDeviceId, const nsString& aGroupId) const {
-  uint32_t distance = 0;
-
-  for (const auto* cs : aConstraintSets) {
-    distance = MediaConstraintsHelper::GetMinimumFitnessDistance(*cs, aDeviceId,
-                                                                 aGroupId);
-    break;  // distance is read from first entry only
-  }
-  return distance;
-}
-
 nsresult MediaEngineWebRTCMicrophoneSource::EvaluateSettings(
     const NormalizedConstraints& aConstraintsUpdate,
     const MediaEnginePrefs& aInPrefs, MediaEnginePrefs* aOutPrefs,
     const char** aOutBadConstraint) {
   AssertIsOnOwningThread();
 
   FlattenedConstraints c(aConstraintsUpdate);
   MediaEnginePrefs prefs = aInPrefs;
@@ -152,18 +131,17 @@ nsresult MediaEngineWebRTCMicrophoneSour
 
   *aOutPrefs = prefs;
 
   return NS_OK;
 }
 
 nsresult MediaEngineWebRTCMicrophoneSource::Reconfigure(
     const dom::MediaTrackConstraints& aConstraints,
-    const MediaEnginePrefs& aPrefs, const nsString& aDeviceId,
-    const nsString& aGroupId, const char** aOutBadConstraint) {
+    const MediaEnginePrefs& aPrefs, const char** aOutBadConstraint) {
   AssertIsOnOwningThread();
   MOZ_ASSERT(mStream);
 
   LOG("Mic source %p Reconfigure ", this);
 
   NormalizedConstraints constraints(aConstraints);
   MediaEnginePrefs outputPrefs;
   nsresult rv =
@@ -386,18 +364,17 @@ void MediaEngineWebRTCMicrophoneSource::
           graph->AppendMessage(MakeUnique<Message>(
               that->mInputProcessing, passThrough, prefs.mChannels));
         }
       }));
 }
 
 nsresult MediaEngineWebRTCMicrophoneSource::Allocate(
     const dom::MediaTrackConstraints& aConstraints,
-    const MediaEnginePrefs& aPrefs, const nsString& aDeviceId,
-    const nsString& aGroupId, const ipc::PrincipalInfo& aPrincipalInfo,
+    const MediaEnginePrefs& aPrefs, const ipc::PrincipalInfo& aPrincipalInfo,
     const char** aOutBadConstraint) {
   AssertIsOnOwningThread();
 
   mState = kAllocated;
 
   NormalizedConstraints normalized(aConstraints);
   MediaEnginePrefs outputPrefs;
   nsresult rv =
@@ -1164,28 +1141,20 @@ nsresult MediaEngineWebRTCAudioCaptureSo
 
 nsresult MediaEngineWebRTCAudioCaptureSource::Stop() {
   AssertIsOnOwningThread();
   return NS_OK;
 }
 
 nsresult MediaEngineWebRTCAudioCaptureSource::Reconfigure(
     const dom::MediaTrackConstraints& aConstraints,
-    const MediaEnginePrefs& aPrefs, const nsString& aDeviceId,
-    const nsString& aGroupId, const char** aOutBadConstraint) {
+    const MediaEnginePrefs& aPrefs, const char** aOutBadConstraint) {
   return NS_OK;
 }
 
-uint32_t MediaEngineWebRTCAudioCaptureSource::GetBestFitnessDistance(
-    const nsTArray<const NormalizedConstraintSet*>& aConstraintSets,
-    const nsString& aDeviceId, const nsString& aGroupId) const {
-  // There is only one way of capturing audio for now, and it's always adequate.
-  return 0;
-}
-
 void MediaEngineWebRTCAudioCaptureSource::GetSettings(
     dom::MediaTrackSettings& aOutSettings) const {
   aOutSettings.mAutoGainControl.Construct(false);
   aOutSettings.mEchoCancellation.Construct(false);
   aOutSettings.mNoiseSuppression.Construct(false);
   aOutSettings.mChannelCount.Construct(1);
 }
 
--- a/dom/media/webrtc/MediaEngineWebRTCAudio.h
+++ b/dom/media/webrtc/MediaEngineWebRTCAudio.h
@@ -36,48 +36,42 @@ class MediaEngineWebRTCMicrophoneSource 
                                     uint32_t aMaxChannelCount,
                                     bool aDelayAgnostic, bool aExtendedFilter);
 
   nsString GetName() const override;
   nsCString GetUUID() const override;
   nsString GetGroupId() const override;
 
   nsresult Allocate(const dom::MediaTrackConstraints& aConstraints,
-                    const MediaEnginePrefs& aPrefs, const nsString& aDeviceId,
-                    const nsString& aGroupId,
+                    const MediaEnginePrefs& aPrefs,
                     const ipc::PrincipalInfo& aPrincipalInfo,
                     const char** aOutBadConstraint) override;
   nsresult Deallocate() override;
   void SetTrack(const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
                 const PrincipalHandle& aPrincipal) override;
   nsresult Start() override;
   nsresult Stop() override;
   nsresult Reconfigure(const dom::MediaTrackConstraints& aConstraints,
                        const MediaEnginePrefs& aPrefs,
-                       const nsString& aDeviceId, const nsString& aGroupId,
                        const char** aOutBadConstraint) override;
 
   /**
    * Assigns the current settings of the capture to aOutSettings.
    * Main thread only.
    */
   void GetSettings(dom::MediaTrackSettings& aOutSettings) const override;
 
   dom::MediaSourceEnum GetMediaSource() const override {
     return dom::MediaSourceEnum::Microphone;
   }
 
   nsresult TakePhoto(MediaEnginePhotoCallback* aCallback) override {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
-  uint32_t GetBestFitnessDistance(
-      const nsTArray<const NormalizedConstraintSet*>& aConstraintSets,
-      const nsString& aDeviceId, const nsString& aGroupId) const override;
-
   void Shutdown() override;
 
  protected:
   ~MediaEngineWebRTCMicrophoneSource() = default;
 
  private:
   /**
    * From a set of constraints and about:config preferences, output the correct
@@ -282,47 +276,42 @@ class AudioInputProcessingPullListener :
 
 class MediaEngineWebRTCAudioCaptureSource : public MediaEngineSource {
  public:
   explicit MediaEngineWebRTCAudioCaptureSource(const char* aUuid) {}
   nsString GetName() const override;
   nsCString GetUUID() const override;
   nsString GetGroupId() const override;
   nsresult Allocate(const dom::MediaTrackConstraints& aConstraints,
-                    const MediaEnginePrefs& aPrefs, const nsString& aDeviceId,
-                    const nsString& aGroupId,
+                    const MediaEnginePrefs& aPrefs,
                     const ipc::PrincipalInfo& aPrincipalInfo,
                     const char** aOutBadConstraint) override {
     // Nothing to do here, everything is managed in MediaManager.cpp
     return NS_OK;
   }
   nsresult Deallocate() override {
     // Nothing to do here, everything is managed in MediaManager.cpp
     return NS_OK;
   }
   void SetTrack(const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
                 const PrincipalHandle& aPrincipal) override;
   nsresult Start() override;
   nsresult Stop() override;
   nsresult Reconfigure(const dom::MediaTrackConstraints& aConstraints,
                        const MediaEnginePrefs& aPrefs,
-                       const nsString& aDeviceId, const nsString& aGroupId,
                        const char** aOutBadConstraint) override;
 
   dom::MediaSourceEnum GetMediaSource() const override {
     return dom::MediaSourceEnum::AudioCapture;
   }
 
   nsresult TakePhoto(MediaEnginePhotoCallback* aCallback) override {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
-  uint32_t GetBestFitnessDistance(
-      const nsTArray<const NormalizedConstraintSet*>& aConstraintSets,
-      const nsString& aDeviceId, const nsString& aGroupId) const override;
   void GetSettings(dom::MediaTrackSettings& aOutSettings) const override;
 
  protected:
   virtual ~MediaEngineWebRTCAudioCaptureSource() = default;
 };
 
 }  // end namespace mozilla
 
--- a/dom/media/webrtc/MediaTrackConstraints.cpp
+++ b/dom/media/webrtc/MediaTrackConstraints.cpp
@@ -311,18 +311,17 @@ FlattenedConstraints::FlattenedConstrain
     if (mChannelCount.Intersects(set.mChannelCount)) {
       mChannelCount.Intersect(set.mChannelCount);
     }
   }
 }
 
 // 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.
+// The full algorithm for all devices.
 //
 // Fitness distance returned as integer math * 1000. Infinity = UINT32_MAX
 
 // First, all devices have a minimum distance based on their deviceId.
 // If you have no other constraints, use this one. Reused by all device types.
 
 /* static */
 bool MediaConstraintsHelper::SomeSettingsFit(
@@ -335,26 +334,16 @@ bool MediaConstraintsHelper::SomeSetting
   for (auto& device : aDevices) {
     if (device->GetBestFitnessDistance(sets, false) != UINT32_MAX) {
       return true;
     }
   }
   return false;
 }
 
-/* static */
-uint32_t MediaConstraintsHelper::GetMinimumFitnessDistance(
-    const NormalizedConstraintSet& aConstraints, const nsString& aDeviceId,
-    const nsString& aGroupId) {
-  uint64_t distance =
-      uint64_t(FitnessDistance(Some(aDeviceId), aConstraints.mDeviceId)) +
-      uint64_t(FitnessDistance(Some(aGroupId), aConstraints.mGroupId));
-  return std::min<uint64_t>(distance, UINT32_MAX);
-}
-
 template <class ValueType, class NormalizedRange>
 /* static */
 uint32_t MediaConstraintsHelper::FitnessDistance(
     ValueType aN, const NormalizedRange& aRange) {
   if (aRange.mMin > aN || aRange.mMax < aN) {
     return UINT32_MAX;
   }
   if (aN == aRange.mIdeal.valueOr(aN)) {
@@ -521,23 +510,26 @@ uint32_t MediaConstraintsHelper::Fitness
       return "facingMode";
     }
   }
   return "";
 }
 
 /* static */ const char* MediaConstraintsHelper::FindBadConstraint(
     const NormalizedConstraints& aConstraints,
-    const RefPtr<MediaEngineSource>& aMediaEngineSource,
-    const nsString& aDeviceId, const nsString& aGroupId) {
+    const RefPtr<MediaEngineSource>& aMediaEngineSource) {
+  NormalizedConstraints c(aConstraints);
+  NormalizedConstraints empty((dom::MediaTrackConstraints()));
+  c.mDeviceId = empty.mDeviceId;
+  c.mGroupId = empty.mGroupId;
   AutoTArray<RefPtr<MediaDevice>, 1> devices;
-  devices.AppendElement(
-      MakeRefPtr<MediaDevice>(aMediaEngineSource, aMediaEngineSource->GetName(),
-                              aDeviceId, aGroupId, NS_LITERAL_STRING("")));
-  return FindBadConstraint(aConstraints, devices);
+  devices.AppendElement(MakeRefPtr<MediaDevice>(
+      aMediaEngineSource, aMediaEngineSource->GetName(), NS_LITERAL_STRING(""),
+      NS_LITERAL_STRING(""), NS_LITERAL_STRING("")));
+  return FindBadConstraint(c, devices);
 }
 
 static void LogConstraintStringRange(
     const NormalizedConstraintSet::StringRange& aRange) {
   if (aRange.mExact.size() <= 1 && aRange.mIdeal.size() <= 1) {
     LOG("  %s: { exact: [%s], ideal: [%s] }", aRange.mName,
         (aRange.mExact.empty()
              ? ""
--- a/dom/media/webrtc/MediaTrackConstraints.h
+++ b/dom/media/webrtc/MediaTrackConstraints.h
@@ -335,17 +335,16 @@ class MediaConstraintsHelper {
                                     bool aIsChrome);
 
   static const char* FindBadConstraint(
       const NormalizedConstraints& aConstraints,
       const nsTArray<RefPtr<MediaDevice>>& aDevices);
 
   static const char* FindBadConstraint(
       const NormalizedConstraints& aConstraints,
-      const RefPtr<MediaEngineSource>& aMediaEngineSource,
-      const nsString& aDeviceId, const nsString& aGroupId);
+      const RefPtr<MediaEngineSource>& aMediaEngineSource);
 
   static void LogConstraints(const NormalizedConstraintSet& aConstraints);
 };
 
 }  // namespace mozilla
 
 #endif /* MEDIATRACKCONSTRAINTS_H_ */
--- a/testing/web-platform/meta/mediacapture-streams/MediaStreamTrack-applyConstraints.https.html.ini
+++ b/testing/web-platform/meta/mediacapture-streams/MediaStreamTrack-applyConstraints.https.html.ini
@@ -1,7 +1,4 @@
 [MediaStreamTrack-applyConstraints.https.html]
-  [applyConstraints rejects invalid groupID]
-    expected: FAIL
-
   [applyConstraints rejects invalid resizeMode]
     expected: FAIL