Bug 1219711 - Let fake stream take precedence in testing. r=jib
authorAndreas Pehrson <pehrsons@gmail.com>
Mon, 09 Nov 2015 23:17:42 +0800
changeset 308040 7b8755f0ccf56966d17e47bbabd6d35deea41cbc
parent 308039 07dce87de29b2238d7fe855165e6adca26d55d56
child 308041 9267c84ef58c101ab41c3d662249043e8af707f8
push id7422
push userpehrsons@gmail.com
push dateWed, 11 Nov 2015 04:19:53 +0000
reviewersjib
bugs1219711
milestone45.0a1
Bug 1219711 - Let fake stream take precedence in testing. r=jib TL;DR requesting a fake stream always gives you a fake stream. No magic. The gUMConstraint `fake: true` should take precedence and if set always use MediaEngineDefault. If it is set the state of `faketracks` is passed on to MediaEngineDefault. If it is not set, but (any of) audio/video loopback devices are set, the device enumeration will filter out only those.
dom/media/MediaManager.cpp
dom/media/tests/mochitest/test_getUserMedia_basicScreenshare.html
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -1410,37 +1410,34 @@ MediaManager::EnumerateRawDevices(uint64
                                   MediaSourceEnum aVideoType,
                                   MediaSourceEnum aAudioType,
                                   bool aFake, bool aFakeTracks)
 {
   MOZ_ASSERT(NS_IsMainThread());
   RefPtr<PledgeSourceSet> p = new PledgeSourceSet();
   uint32_t id = mOutstandingPledges.Append(*p);
 
-  // Check if the preference for using audio/video loopback devices is
-  // enabled. This is currently used for automated media tests only.
-  //
-  // If present (and we're doing non-exotic cameras and microphones) use them
-  // instead of our built-in fake devices, except if fake tracks are requested
-  // (a feature of the built-in ones only).
-
   nsAdoptingCString audioLoopDev, videoLoopDev;
-  if (!aFakeTracks) {
-    if (aVideoType == dom::MediaSourceEnum::Camera) {
-      audioLoopDev = Preferences::GetCString("media.audio_loopback_dev");
+  if (!aFake) {
+    // Fake stream not requested. The entire device stack is available.
+    // Loop in loopback devices if they are set, and their respective type is
+    // requested. This is currently used for automated media tests only.
+    if (aVideoType == MediaSourceEnum::Camera) {
       videoLoopDev = Preferences::GetCString("media.video_loopback_dev");
-
-      if (aFake && !audioLoopDev.IsEmpty() && !videoLoopDev.IsEmpty()) {
-        aFake = false;
-      }
-    } else {
-      aFake = false;
+    }
+    if (aAudioType == MediaSourceEnum::Microphone) {
+      audioLoopDev = Preferences::GetCString("media.audio_loopback_dev");
     }
   }
 
+  if (!aFake) {
+    // Fake tracks only make sense when we have a fake stream.
+    aFakeTracks = false;
+  }
+
   MediaManager::PostTask(FROM_HERE, NewTaskFrom([id, aWindowId, audioLoopDev,
                                                  videoLoopDev, aVideoType,
                                                  aAudioType, aFake,
                                                  aFakeTracks]() mutable {
     RefPtr<MediaEngine> backend;
     if (aFake) {
       backend = new MediaEngineDefault(aFakeTracks);
     } else {
--- a/dom/media/tests/mochitest/test_getUserMedia_basicScreenshare.html
+++ b/dom/media/tests/mochitest/test_getUserMedia_basicScreenshare.html
@@ -54,17 +54,17 @@
           max: '10'
         }
       }
     ];
     return getUserMedia(constraints).then(stream => {
       var playback = new LocalMediaStreamPlayback(testVideo, stream);
         return playback.playMediaWithDeprecatedStreamStop(false);
       })
-      .then(() => getUserMedia({video: videoConstraints[0]}))
+      .then(() => getUserMedia({video: videoConstraints[0], fake: false}))
       .then(stream => {
         var playback = new LocalMediaStreamPlayback(testVideo, stream);
         playback.startMedia(false);
         return playback.verifyPlaying()
           .then(() => Promise.all([
             () => testVideo.srcObject.getVideoTracks()[0].applyConstraints(videoConstraints[1]),
             () => listenUntil(testVideo, "resize", () => true)
           ]))