Bug 1286096 - Remove fakeTracks constraint. r=drno,smaug
authorJan-Ivar Bruaroey <jib@mozilla.com>
Mon, 11 Jul 2016 19:27:43 -0400
changeset 347082 54d171fd763aa31c241ceb4bee9b47f98fdb070a
parent 347081 8a75cd08366e262e6fe6ffe871375de3332dc833
child 347083 3b9c5f9d8a429e7b97ba54165934c46bdb777f49
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdrno, smaug
bugs1286096
milestone50.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 1286096 - Remove fakeTracks constraint. r=drno,smaug MozReview-Commit-ID: I9ZsufufRYg
dom/media/MediaManager.cpp
dom/media/MediaManager.h
dom/media/test/test_multiple_mediastreamtracks.html
dom/media/webrtc/MediaEngine.h
dom/media/webrtc/MediaEngineDefault.cpp
dom/media/webrtc/MediaEngineDefault.h
dom/webidl/MediaStream.webidl
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -1613,17 +1613,17 @@ private:
  * EnumerateRawDevices - Enumerate a list of audio & video devices that
  * satisfy passed-in constraints. List contains raw id's.
  */
 
 already_AddRefed<MediaManager::PledgeSourceSet>
 MediaManager::EnumerateRawDevices(uint64_t aWindowId,
                                   MediaSourceEnum aVideoType,
                                   MediaSourceEnum aAudioType,
-                                  bool aFake, bool aFakeTracks)
+                                  bool aFake)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aVideoType != MediaSourceEnum::Other ||
              aAudioType != MediaSourceEnum::Other);
   RefPtr<PledgeSourceSet> p = new PledgeSourceSet();
   uint32_t id = mOutstandingPledges.Append(*p);
 
   nsAdoptingCString audioLoopDev, videoLoopDev;
@@ -1634,34 +1634,28 @@ MediaManager::EnumerateRawDevices(uint64
     if (aVideoType == MediaSourceEnum::Camera) {
       videoLoopDev = Preferences::GetCString("media.video_loopback_dev");
     }
     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(NewTaskFrom([id, aWindowId, audioLoopDev,
                                       videoLoopDev, aVideoType,
-                                      aAudioType, aFake,
-                                      aFakeTracks]() mutable {
+                                      aAudioType, aFake]() mutable {
     // 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(aFakeTracks);
+      fakeBackend = new MediaEngineDefault();
     }
     if ((!fakeCams && hasVideo) || (!fakeMics && hasAudio)) {
       RefPtr<MediaManager> manager = MediaManager_GetInstance();
       realBackend = manager->GetBackend(aWindowId);
     }
 
     auto result = MakeUnique<SourceSet>();
 
@@ -2340,24 +2334,21 @@ MediaManager::GetUserMedia(nsPIDOMWindow
 
   nsString callID;
   rv = GenerateUUID(callID);
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool fake = c.mFake.WasPassed()? c.mFake.Value() :
       Preferences::GetBool("media.navigator.streams.fake");
 
-  bool fakeTracks = c.mFakeTracks.WasPassed()? c.mFakeTracks.Value() : false;
-
   bool askPermission = !privileged &&
       (!fake || Preferences::GetBool("media.navigator.permission.fake"));
 
   RefPtr<PledgeSourceSet> p = EnumerateDevicesImpl(windowID, videoType,
-                                                   audioType, fake,
-                                                   fakeTracks);
+                                                   audioType, fake);
   p->Then([this, onSuccess, onFailure, windowID, c, listener, askPermission,
            prefs, isHTTPS, callID, origin](SourceSet*& aDevices) mutable {
 
     RefPtr<Refcountable<UniquePtr<SourceSet>>> devices(
          new Refcountable<UniquePtr<SourceSet>>(aDevices)); // grab result
 
     // Ensure that the captured 'this' pointer and our windowID are still good.
     if (!MediaManager::Exists() ||
@@ -2534,17 +2525,17 @@ MediaManager::ToJSArray(SourceSet& aDevi
   }
   return var.forget();
 }
 
 already_AddRefed<MediaManager::PledgeSourceSet>
 MediaManager::EnumerateDevicesImpl(uint64_t aWindowId,
                                    MediaSourceEnum aVideoType,
                                    MediaSourceEnum aAudioType,
-                                   bool aFake, bool aFakeTracks)
+                                   bool aFake)
 {
   MOZ_ASSERT(NS_IsMainThread());
   nsPIDOMWindowInner* window =
     nsGlobalWindow::GetInnerWindowWithId(aWindowId)->AsInner();
 
   // This function returns a pledge, a promise-like object with the future result
   RefPtr<PledgeSourceSet> pledge = new PledgeSourceSet();
   uint32_t id = mOutstandingPledges.Append(*pledge);
@@ -2563,23 +2554,22 @@ MediaManager::EnumerateDevicesImpl(uint6
   // GetOriginKey is an async API that returns a pledge (a promise-like
   // pattern). We use .Then() to pass in a lambda to run back on this same
   // thread later once GetOriginKey resolves. Needed variables are "captured"
   // (passed by value) safely into the lambda.
 
   RefPtr<Pledge<nsCString>> p = media::GetOriginKey(origin, privateBrowsing,
                                                       persist);
   p->Then([id, aWindowId, aVideoType, aAudioType,
-           aFake, aFakeTracks](const nsCString& aOriginKey) mutable {
+           aFake](const nsCString& aOriginKey) mutable {
     MOZ_ASSERT(NS_IsMainThread());
     RefPtr<MediaManager> mgr = MediaManager_GetInstance();
 
-    RefPtr<PledgeSourceSet> p = mgr->EnumerateRawDevices(aWindowId,
-                                                         aVideoType, aAudioType,
-                                                         aFake, aFakeTracks);
+    RefPtr<PledgeSourceSet> p = mgr->EnumerateRawDevices(aWindowId, aVideoType,
+                                                         aAudioType, aFake);
     p->Then([id, aWindowId, aOriginKey](SourceSet*& aDevices) mutable {
       UniquePtr<SourceSet> devices(aDevices); // secondary result
 
       // Only run if window is still on our active list.
       RefPtr<MediaManager> mgr = MediaManager_GetInstance();
       if (!mgr) {
         return NS_OK;
       }
--- a/dom/media/MediaManager.h
+++ b/dom/media/MediaManager.h
@@ -268,22 +268,22 @@ private:
 public: // TODO: make private once we upgrade to GCC 4.8+ on linux.
   static void AnonymizeDevices(SourceSet& aDevices, const nsACString& aOriginKey);
   static already_AddRefed<nsIWritableVariant> ToJSArray(SourceSet& aDevices);
 private:
   already_AddRefed<PledgeSourceSet>
   EnumerateRawDevices(uint64_t aWindowId,
                       dom::MediaSourceEnum aVideoType,
                       dom::MediaSourceEnum aAudioType,
-                      bool aFake, bool aFakeTracks);
+                      bool aFake);
   already_AddRefed<PledgeSourceSet>
   EnumerateDevicesImpl(uint64_t aWindowId,
                        dom::MediaSourceEnum aVideoSrcType,
                        dom::MediaSourceEnum aAudioSrcType,
-                       bool aFake = false, bool aFakeTracks = false);
+                       bool aFake = false);
   already_AddRefed<PledgeChar>
   SelectSettings(
       dom::MediaStreamConstraints& aConstraints,
       RefPtr<media::Refcountable<UniquePtr<SourceSet>>>& aSources);
 
   StreamListeners* AddWindowID(uint64_t aWindowId);
   WindowTable *GetActiveWindows() {
     MOZ_ASSERT(NS_IsMainThread());
--- a/dom/media/test/test_multiple_mediastreamtracks.html
+++ b/dom/media/test/test_multiple_mediastreamtracks.html
@@ -5,28 +5,30 @@
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
   <script type="text/javascript" src="manifest.js"></script>
 </head>
 <body>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 function startTest() {
-  navigator.mediaDevices.getUserMedia({audio:true, video:true, fake:true, fakeTracks:true})
-  .then(function(stream) {
+  navigator.mediaDevices.getUserMedia({audio:true, video:true, fake:true})
+  .then(function(orgStream) {
+    var a = orgStream.getAudioTracks()[0];
+    var v = orgStream.getVideoTracks()[0];
+    var stream = new MediaStream([a, a, a, a, v, v, v].map(track => track.clone()));
     var element = document.createElement("video");
 
     element.onloadedmetadata = function() {
       is(stream.getAudioTracks().length, 4, 'Length of audio tracks should be 4.');
       is(stream.getVideoTracks().length, 3, 'Length of vudio tracks should be 3.');
       SimpleTest.finish();
     };
 
-    mStream = stream;
-    element.srcObject = mStream;
+    element.srcObject = stream;
     element.play();
   })
   .catch(function(reason) {
     ok(false, "unexpected error = " + reason.message);
     SimpleTest.finish();
   });
 }
 
--- a/dom/media/webrtc/MediaEngine.h
+++ b/dom/media/webrtc/MediaEngine.h
@@ -176,20 +176,16 @@ public:
     } else {
       return true;
     }
   }
 
   /* It is an error to call Start() before an Allocate(), and Stop() before
    * a Start(). Only Allocate() may be called after a Deallocate(). */
 
-  void SetHasFakeTracks(bool aHasFakeTracks) {
-    mHasFakeTracks = aHasFakeTracks;
-  }
-
   /* This call reserves but does not start the device. */
   virtual nsresult Allocate(const dom::MediaTrackConstraints &aConstraints,
                             const MediaEnginePrefs &aPrefs,
                             const nsString& aDeviceId,
                             const nsACString& aOrigin,
                             BaseAllocationHandle** aOutHandle,
                             const char** aOutBadConstraint) = 0;
 
@@ -205,29 +201,27 @@ public:
 
 protected:
   // Only class' own members can be initialized in constructor initializer list.
   explicit MediaEngineSource(MediaEngineState aState)
     : mState(aState)
 #ifdef DEBUG
     , mOwningThread(PR_GetCurrentThread())
 #endif
-    , mHasFakeTracks(false)
   {}
 
   void AssertIsOnOwningThread()
   {
     MOZ_ASSERT(PR_GetCurrentThread() == mOwningThread);
   }
 
   MediaEngineState mState;
 #ifdef DEBUG
   PRThread* mOwningThread;
 #endif
-  bool mHasFakeTracks;
   // Main-thread only:
   dom::MediaTrackSettings mSettings;
 };
 
 /**
  * Video source and friends.
  */
 class MediaEnginePrefs {
--- a/dom/media/webrtc/MediaEngineDefault.cpp
+++ b/dom/media/webrtc/MediaEngineDefault.cpp
@@ -27,21 +27,16 @@
 #endif
 
 #define AUDIO_RATE mozilla::MediaEngine::DEFAULT_SAMPLE_RATE
 #define DEFAULT_AUDIO_TIMER_MS 10
 namespace mozilla {
 
 using namespace mozilla::gfx;
 
-// Enable the testing flag fakeTracks and fake in MediaStreamConstraints, will
-// return you a MediaStream with additional fake video tracks and audio tracks.
-static const int kFakeVideoTrackCount = 2;
-static const int kFakeAudioTrackCount = 3;
-
 NS_IMPL_ISUPPORTS(MediaEngineDefaultVideoSource, nsITimerCallback)
 /**
  * Default video source.
  */
 
 MediaEngineDefaultVideoSource::MediaEngineDefaultVideoSource()
   : MediaEngineCameraVideoSource("FakeVideo.Monitor")
   , mTimer(nullptr)
@@ -170,22 +165,16 @@ MediaEngineDefaultVideoSource::Start(Sou
 
   mTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
   if (!mTimer) {
     return NS_ERROR_FAILURE;
   }
 
   aStream->AddTrack(aID, 0, new VideoSegment(), SourceMediaStream::ADDTRACK_QUEUED);
 
-  if (mHasFakeTracks) {
-    for (int i = 0; i < kFakeVideoTrackCount; ++i) {
-      aStream->AddTrack(kTrackCount + i, 0, new VideoSegment(), SourceMediaStream::ADDTRACK_QUEUED);
-    }
-  }
-
   // Remember TrackID so we can end it later
   mTrackID = aID;
 
   // Start timer for subsequent frames
 #if defined(MOZ_WIDGET_GONK) && defined(DEBUG)
 // B2G emulator debug is very, very slow and has problems dealing with realtime audio inputs
   mTimer->InitWithCallback(this, (1000 / mOpts.mFPS)*10, nsITimer::TYPE_REPEATING_SLACK);
 #else
@@ -205,21 +194,16 @@ MediaEngineDefaultVideoSource::Stop(Sour
   if (!mTimer) {
     return NS_ERROR_FAILURE;
   }
 
   mTimer->Cancel();
   mTimer = nullptr;
 
   aSource->EndTrack(aID);
-  if (mHasFakeTracks) {
-    for (int i = 0; i < kFakeVideoTrackCount; ++i) {
-      aSource->EndTrack(kTrackCount + i);
-    }
-  }
 
   mState = kStopped;
   mImage = nullptr;
   return NS_OK;
 }
 
 nsresult
 MediaEngineDefaultVideoSource::Restart(
@@ -309,24 +293,16 @@ MediaEngineDefaultVideoSource::NotifyPul
 
   if (delta > 0) {
     // nullptr images are allowed
     IntSize size(image ? mOpts.mWidth : 0, image ? mOpts.mHeight : 0);
     segment.AppendFrame(image.forget(), delta, size, aPrincipalHandle);
     // This can fail if either a) we haven't added the track yet, or b)
     // we've removed or finished the track.
     aSource->AppendToTrack(aID, &segment);
-    // Generate null data for fake tracks.
-    if (mHasFakeTracks) {
-      for (int i = 0; i < kFakeVideoTrackCount; ++i) {
-        VideoSegment nullSegment;
-        nullSegment.AppendNullData(delta);
-        aSource->AppendToTrack(kTrackCount + i, &nullSegment);
-      }
-    }
   }
 }
 
 // generate 1k sine wave per second
 class SineWaveGenerator
 {
 public:
   static const int bytesPerSample = 2;
@@ -473,25 +449,16 @@ MediaEngineDefaultAudioSource::Start(Sou
   // Make it two timer intervals to try to avoid underruns.
   mBufferSize = 2 * (AUDIO_RATE * DEFAULT_AUDIO_TIMER_MS) / 1000;
 
   // AddTrack will take ownership of segment
   AudioSegment* segment = new AudioSegment();
   AppendToSegment(*segment, mBufferSize);
   mSource->AddAudioTrack(aID, AUDIO_RATE, 0, segment, SourceMediaStream::ADDTRACK_QUEUED);
 
-  if (mHasFakeTracks) {
-    for (int i = 0; i < kFakeAudioTrackCount; ++i) {
-      segment = new AudioSegment();
-      segment->AppendNullData(mBufferSize);
-      mSource->AddAudioTrack(kTrackCount + kFakeVideoTrackCount+i,
-                             AUDIO_RATE, 0, segment, SourceMediaStream::ADDTRACK_QUEUED);
-    }
-  }
-
   // Remember TrackID so we can finish later
   mTrackID = aID;
 
   // Remember PrincipalHandle since we don't append in NotifyPull.
   mPrincipalHandle = aPrincipalHandle;
 
   mLastNotify = TimeStamp::Now();
 
@@ -518,21 +485,16 @@ MediaEngineDefaultAudioSource::Stop(Sour
   if (!mTimer) {
     return NS_ERROR_FAILURE;
   }
 
   mTimer->Cancel();
   mTimer = nullptr;
 
   aSource->EndTrack(aID);
-  if (mHasFakeTracks) {
-    for (int i = 0; i < kFakeAudioTrackCount; ++i) {
-      aSource->EndTrack(kTrackCount + kFakeVideoTrackCount+i);
-    }
-  }
 
   mState = kStopped;
   return NS_OK;
 }
 
 nsresult
 MediaEngineDefaultAudioSource::Restart(BaseAllocationHandle* aHandle,
                                        const dom::MediaTrackConstraints& aConstraints,
@@ -569,24 +531,16 @@ MediaEngineDefaultAudioSource::Notify(ns
   // have underrun and the MSG had to append silence while waiting for us
   // to push more data. In this case we reset to mBufferSize again.
   TrackTicks samplesToAppend = std::min(samplesSinceLastNotify, mBufferSize);
 
   AudioSegment segment;
   AppendToSegment(segment, samplesToAppend);
   mSource->AppendToTrack(mTrackID, &segment);
 
-  // Generate null data for fake tracks.
-  if (mHasFakeTracks) {
-    for (int i = 0; i < kFakeAudioTrackCount; ++i) {
-      AudioSegment nullSegment;
-      nullSegment.AppendNullData(samplesToAppend);
-      mSource->AppendToTrack(kTrackCount + kFakeVideoTrackCount+i, &nullSegment);
-    }
-  }
   return NS_OK;
 }
 
 void
 MediaEngineDefault::EnumerateVideoDevices(dom::MediaSourceEnum aMediaSource,
                                           nsTArray<RefPtr<MediaEngineVideoSource> >* aVSources) {
   MutexAutoLock lock(mMutex);
 
@@ -594,17 +548,16 @@ MediaEngineDefault::EnumerateVideoDevice
   if (aMediaSource != dom::MediaSourceEnum::Camera) {
     return;
   }
 
   // We once had code here to find a VideoSource with the same settings and re-use that.
   // This no longer is possible since the resolution is being set in Allocate().
 
   RefPtr<MediaEngineVideoSource> newSource = new MediaEngineDefaultVideoSource();
-  newSource->SetHasFakeTracks(mHasFakeTracks);
   mVSources.AppendElement(newSource);
   aVSources->AppendElement(newSource);
 
   return;
 }
 
 void
 MediaEngineDefault::EnumerateAudioDevices(dom::MediaSourceEnum aMediaSource,
@@ -620,16 +573,15 @@ MediaEngineDefault::EnumerateAudioDevice
       aASources->AppendElement(source);
     }
   }
 
   // All streams are currently busy, just make a new one.
   if (aASources->Length() == 0) {
     RefPtr<MediaEngineAudioSource> newSource =
       new MediaEngineDefaultAudioSource();
-    newSource->SetHasFakeTracks(mHasFakeTracks);
     mASources.AppendElement(newSource);
     aASources->AppendElement(newSource);
   }
   return;
 }
 
 } // namespace mozilla
--- a/dom/media/webrtc/MediaEngineDefault.h
+++ b/dom/media/webrtc/MediaEngineDefault.h
@@ -193,35 +193,29 @@ protected:
   SourceMediaStream* mSource;
   nsAutoPtr<SineWaveGenerator> mSineGenerator;
 };
 
 
 class MediaEngineDefault : public MediaEngine
 {
 public:
-  explicit MediaEngineDefault(bool aHasFakeTracks = false)
-    : mHasFakeTracks(aHasFakeTracks)
-    , mMutex("mozilla::MediaEngineDefault")
-  {}
+  explicit MediaEngineDefault() : mMutex("mozilla::MediaEngineDefault") {}
 
   void EnumerateVideoDevices(dom::MediaSourceEnum,
                              nsTArray<RefPtr<MediaEngineVideoSource> >*) override;
   void EnumerateAudioDevices(dom::MediaSourceEnum,
                              nsTArray<RefPtr<MediaEngineAudioSource> >*) override;
   void Shutdown() override {
     MutexAutoLock lock(mMutex);
 
     mVSources.Clear();
     mASources.Clear();
   };
 
-protected:
-  bool mHasFakeTracks;
-
 private:
   ~MediaEngineDefault() {
     Shutdown();
   }
 
   Mutex mMutex;
   // protected with mMutex:
 
--- a/dom/webidl/MediaStream.webidl
+++ b/dom/webidl/MediaStream.webidl
@@ -15,20 +15,16 @@
 
 dictionary MediaStreamConstraints {
     (boolean or MediaTrackConstraints) audio = false;
     (boolean or MediaTrackConstraints) video = false;
     boolean picture = false; // Mozilla legacy
     boolean fake;       // For testing purpose. Generates frames of solid
                         // colors if video is enabled, and sound of 1Khz sine
                         // wave if audio is enabled.
-    boolean fakeTracks; // For testing purpose, works only if fake is
-                        // enabled. Enable fakeTracks returns a stream
-                        // with two extra empty video tracks and three
-                        // extra empty audio tracks.
     DOMString? peerIdentity = null;
 };
 
 [Exposed=Window,
  Constructor,
  Constructor (MediaStream stream),
  Constructor (sequence<MediaStreamTrack> tracks)]
 interface MediaStream : EventTarget {