Bug 1422875 - Fix fake constraint to not apply to screensharing for media.navigator.permission.device codepath (aka Android) r=pehrsons
authorJan-Ivar Bruaroey <jib@mozilla.com>
Mon, 04 Dec 2017 11:25:50 -0500
changeset 394975 ba4cd2e93fec96898e55a1c4d23ed2a077c17d84
parent 394974 d4e6ca9ed4da23167a30da7fb0ca5a1f19f14636
child 394976 525f2f1623850d9de7f0b1995f0c68fe1a14e0cc
push id97987
push usernerli@mozilla.com
push dateTue, 05 Dec 2017 13:52:50 +0000
treeherdermozilla-inbound@8842dba7396b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspehrsons
bugs1422875
milestone59.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 1422875 - Fix fake constraint to not apply to screensharing for media.navigator.permission.device codepath (aka Android) r=pehrsons MozReview-Commit-ID: L9IIalMuFoC
dom/media/MediaManager.cpp
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -1697,30 +1697,32 @@ MediaManager::EnumerateRawDevices(uint64
     if (aVideoType == MediaSourceEnum::Camera) {
       Preferences::GetCString("media.video_loopback_dev", videoLoopDev);
     }
     if (aAudioType == MediaSourceEnum::Microphone) {
       Preferences::GetCString("media.audio_loopback_dev", audioLoopDev);
     }
   }
 
+  bool hasVideo = aVideoType != MediaSourceEnum::Other;
+  bool hasAudio = aAudioType != MediaSourceEnum::Other;
+  bool fakeCams = aFake && aVideoType == MediaSourceEnum::Camera;
+  bool fakeMics = aFake && aAudioType == MediaSourceEnum::Microphone;
+  bool realDevicesRequested = (!fakeCams && hasVideo) || (!fakeMics && hasAudio);
+
   RefPtr<Runnable> task = NewTaskFrom([id, aWindowId, audioLoopDev,
                                        videoLoopDev, aVideoType,
-                                       aAudioType, aFake]() mutable {
+                                       aAudioType, hasVideo, hasAudio,
+                                       fakeCams, fakeMics, realDevicesRequested]() {
     // Only enumerate what's asked for, and only fake cams and mics.
-    bool hasVideo = aVideoType != MediaSourceEnum::Other;
-    bool hasAudio = aAudioType != MediaSourceEnum::Other;
-    bool fakeCams = aFake && aVideoType == MediaSourceEnum::Camera;
-    bool fakeMics = aFake && aAudioType == MediaSourceEnum::Microphone;
-
     RefPtr<MediaEngine> fakeBackend, realBackend;
     if (fakeCams || fakeMics) {
       fakeBackend = new MediaEngineDefault();
     }
-    if ((!fakeCams && hasVideo) || (!fakeMics && hasAudio)) {
+    if (realDevicesRequested) {
       MediaManager* manager = MediaManager::GetIfExists();
       MOZ_RELEASE_ASSERT(manager); // Must exist while media thread is alive
       realBackend = manager->GetBackend(aWindowId);
       // We need to listen to this event even JS didn't listen to it.
       realBackend->AddDeviceChangeCallback(manager);
     }
 
     auto result = MakeUnique<SourceSet>();
@@ -1753,19 +1755,17 @@ MediaManager::EnumerateRawDevices(uint64
       RefPtr<PledgeSourceSet> p = mgr->mOutstandingPledges.Remove(id);
       if (p) {
         p->Resolve(result.release());
       }
       return NS_OK;
     }));
   });
 
-  if (!aFake &&
-      (aVideoType == MediaSourceEnum::Camera ||
-       aAudioType == MediaSourceEnum::Microphone) &&
+  if (realDevicesRequested &&
       Preferences::GetBool("media.navigator.permission.device", false)) {
     // Need to ask permission to retrieve list of all devices;
     // notify frontend observer and wait for callback notification to post task.
     const char16_t* const type =
       (aVideoType != MediaSourceEnum::Camera)     ? u"audio" :
       (aAudioType != MediaSourceEnum::Microphone) ? u"video" :
                                                     u"all";
     nsCOMPtr<nsIObserverService> obs = services::GetObserverService();