Bug 694814: Patch 6 - Change gUM prefs to media.getusermedia.*, groundwork for in-call changes r=jib
☠☠ backed out by df77827fc918 ☠ ☠
authorRandell Jesup <rjesup@jesup.org>
Wed, 02 Apr 2014 13:58:20 -0400
changeset 195793 1cf98d1c6b75e0c7b78e57befd9538d5e26f33b6
parent 195792 6dc08e9fc7e89104ff27237cf81df5c8082fb81a
child 195794 daf5df0306b2f314992d551ad19c5c720c2c2408
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib
bugs694814
milestone31.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 694814: Patch 6 - Change gUM prefs to media.getusermedia.*, groundwork for in-call changes r=jib
dom/media/MediaManager.cpp
modules/libpref/src/init/all.js
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -395,23 +395,40 @@ MediaDevice::GetSource()
 /**
  * A subclass that we only use to stash internal pointers to MediaStreamGraph objects
  * that need to be cleaned up.
  */
 class nsDOMUserMediaStream : public DOMLocalMediaStream
 {
 public:
   static already_AddRefed<nsDOMUserMediaStream>
-  CreateTrackUnionStream(nsIDOMWindow* aWindow, uint32_t aHintContents)
+  CreateTrackUnionStream(nsIDOMWindow* aWindow,
+                         MediaEngineSource *aAudioSource,
+                         MediaEngineSource *aVideoSource)
   {
-    nsRefPtr<nsDOMUserMediaStream> stream = new nsDOMUserMediaStream();
-    stream->InitTrackUnionStream(aWindow, aHintContents);
+    DOMMediaStream::TrackTypeHints hints =
+      (aAudioSource ? DOMMediaStream::HINT_CONTENTS_AUDIO : 0) |
+      (aVideoSource ? DOMMediaStream::HINT_CONTENTS_VIDEO : 0);
+
+    nsRefPtr<nsDOMUserMediaStream> stream = new nsDOMUserMediaStream(aAudioSource);
+    stream->InitTrackUnionStream(aWindow, hints);
     return stream.forget();
   }
 
+  nsDOMUserMediaStream(MediaEngineSource *aAudioSource) :
+    mAudioSource(aAudioSource),
+    mEchoOn(true),
+    mAgcOn(false),
+    mNoiseOn(true),
+    mEcho(webrtc::kEcDefault),
+    mAgc(webrtc::kAgcDefault),
+    mNoise(webrtc::kNsDefault),
+    mPlayoutDelay(20)
+  {}
+
   virtual ~nsDOMUserMediaStream()
   {
     Stop();
 
     if (mPort) {
       mPort->Destroy();
     }
     if (mSourceStream) {
@@ -431,16 +448,31 @@ public:
   {
     if (mSourceStream) {
       mSourceStream->AddDirectListener(aListener);
       return true; // application should ignore NotifyQueuedTrackData
     }
     return false;
   }
 
+  virtual void
+  AudioConfig(bool aEchoOn, uint32_t aEcho,
+              bool aAgcOn, uint32_t aAgc,
+              bool aNoiseOn, uint32_t aNoise,
+              int32_t aPlayoutDelay)
+  {
+    mEchoOn = aEchoOn;
+    mEcho = aEcho;
+    mAgcOn = aAgcOn;
+    mAgc = aAgc;
+    mNoiseOn = aNoiseOn;
+    mNoise = aNoise;
+    mPlayoutDelay = aPlayoutDelay;
+  }
+
   virtual void RemoveDirectListener(MediaStreamDirectListener *aListener) MOZ_OVERRIDE
   {
     if (mSourceStream) {
       mSourceStream->RemoveDirectListener(aListener);
     }
   }
 
   // let us intervene for direct listeners when someone does track.enabled = false
@@ -453,16 +485,24 @@ public:
     // forward the request to the source and translate the ID
     GetStream()->AsProcessedStream()->ForwardTrackEnabled(aID, aEnabled);
   }
 
   // The actual MediaStream is a TrackUnionStream. But these resources need to be
   // explicitly destroyed too.
   nsRefPtr<SourceMediaStream> mSourceStream;
   nsRefPtr<MediaInputPort> mPort;
+  nsRefPtr<MediaEngineSource> mAudioSource; // so we can turn on AEC
+  bool mEchoOn;
+  bool mAgcOn;
+  bool mNoiseOn;
+  uint32_t mEcho;
+  uint32_t mAgc;
+  uint32_t mNoise;
+  uint32_t mPlayoutDelay;
 };
 
 /**
  * Creates a MediaStream, attaches a listener and fires off a success callback
  * to the DOM with the stream. We also pass in the error callback so it can
  * be released correctly.
  *
  * All of this must be done on the main thread!
@@ -533,41 +573,67 @@ public:
     // the desired tracks in the MediaStreamGraph) or when
     // DOMMediaStream::NotifyMediaStreamGraphShutdown is called.
     nsRefPtr<DOMMediaStream> mStream;
   };
 
   NS_IMETHOD
   Run()
   {
+    int32_t aec = (int32_t) webrtc::kEcUnchanged;
+    int32_t agc = (int32_t) webrtc::kAgcUnchanged;
+    int32_t noise = (int32_t) webrtc::kNsUnchanged;
+    bool aec_on = false, agc_on = false, noise_on = false;
+    int32_t playout_delay = 0;
+
     NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
     nsPIDOMWindow *window = static_cast<nsPIDOMWindow*>
       (nsGlobalWindow::GetInnerWindowWithId(mWindowID));
 
     // We're on main-thread, and the windowlist can only
     // be invalidated from the main-thread (see OnNavigation)
     StreamListeners* listeners = mManager->GetWindowListeners(mWindowID);
     if (!listeners || !window || !window->GetExtantDoc()) {
       // This window is no longer live.  mListener has already been removed
       return NS_OK;
     }
 
+#ifdef MOZ_WEBRTC
+    // Right now these configs are only of use if webrtc is available
+    nsresult rv;
+    nsCOMPtr<nsIPrefService> prefs = do_GetService("@mozilla.org/preferences-service;1", &rv);
+    if (NS_SUCCEEDED(rv)) {
+      nsCOMPtr<nsIPrefBranch> branch = do_QueryInterface(prefs);
+
+      if (branch) {
+        branch->GetBoolPref("media.getusermedia.aec_enabled", &aec_on);
+        branch->GetIntPref("media.getusermedia.aec", &aec);
+        branch->GetBoolPref("media.getusermedia.agc_enabled", &agc_on);
+        branch->GetIntPref("media.getusermedia.agc", &agc);
+        branch->GetBoolPref("media.getusermedia.noise_enabled", &noise_on);
+        branch->GetIntPref("media.getusermedia.noise", &noise);
+        branch->GetIntPref("media.getusermedia.playout_delay", &playout_delay);
+      }
+    }
+#endif
     // Create a media stream.
-    DOMMediaStream::TrackTypeHints hints =
-      (mAudioSource ? DOMMediaStream::HINT_CONTENTS_AUDIO : 0) |
-      (mVideoSource ? DOMMediaStream::HINT_CONTENTS_VIDEO : 0);
-
     nsRefPtr<nsDOMUserMediaStream> trackunion =
-      nsDOMUserMediaStream::CreateTrackUnionStream(window, hints);
+      nsDOMUserMediaStream::CreateTrackUnionStream(window, mAudioSource,
+                                                   mVideoSource);
     if (!trackunion) {
       nsCOMPtr<nsIDOMGetUserMediaErrorCallback> error = mError.forget();
       LOG(("Returning error for getUserMedia() - no stream"));
       error->OnError(NS_LITERAL_STRING("NO_STREAM"));
       return NS_OK;
     }
+    trackunion->AudioConfig(aec_on, (uint32_t) aec,
+                            agc_on, (uint32_t) agc,
+                            noise_on, (uint32_t) noise,
+                            playout_delay);
+
 
     MediaStreamGraph* gm = MediaStreamGraph::GetInstance();
     nsRefPtr<SourceMediaStream> stream = gm->CreateSourceStream(nullptr);
 
     // connect the source stream to the track union stream to avoid us blocking
     trackunion->GetStream()->AsProcessedStream()->SetAutofinish(true);
     nsRefPtr<MediaInputPort> port = trackunion->GetStream()->AsProcessedStream()->
       AllocateInputPort(stream, MediaInputPort::FLAG_BLOCK_OUTPUT);
@@ -588,43 +654,20 @@ public:
     // when the page is invalidated (on navigation or close).
     mListener->Activate(stream.forget(), mAudioSource, mVideoSource);
 
     // Note: includes JS callbacks; must be released on MainThread
     TracksAvailableCallback* tracksAvailableCallback =
       new TracksAvailableCallback(mManager, mSuccess, mWindowID, trackunion);
 
 #ifdef MOZ_WEBRTC
-    // Right now these configs are only of use if webrtc is available
-    nsresult rv;
-    nsCOMPtr<nsIPrefService> prefs = do_GetService("@mozilla.org/preferences-service;1", &rv);
-    if (NS_SUCCEEDED(rv)) {
-      nsCOMPtr<nsIPrefBranch> branch = do_QueryInterface(prefs);
-
-      if (branch) {
-        int32_t aec = (int32_t) webrtc::kEcUnchanged;
-        int32_t agc = (int32_t) webrtc::kAgcUnchanged;
-        int32_t noise = (int32_t) webrtc::kNsUnchanged;
-        bool aec_on = false, agc_on = false, noise_on = false;
-        int32_t playout_delay = 0;
-
-        branch->GetBoolPref("media.peerconnection.aec_enabled", &aec_on);
-        branch->GetIntPref("media.peerconnection.aec", &aec);
-        branch->GetBoolPref("media.peerconnection.agc_enabled", &agc_on);
-        branch->GetIntPref("media.peerconnection.agc", &agc);
-        branch->GetBoolPref("media.peerconnection.noise_enabled", &noise_on);
-        branch->GetIntPref("media.peerconnection.noise", &noise);
-        branch->GetIntPref("media.peerconnection.playout_delay", &playout_delay);
-
-        mListener->AudioConfig(aec_on, (uint32_t) aec,
-                               agc_on, (uint32_t) agc,
-                               noise_on, (uint32_t) noise,
-                               playout_delay);
-      }
-    }
+    mListener->AudioConfig(aec_on, (uint32_t) aec,
+                           agc_on, (uint32_t) agc,
+                           noise_on, (uint32_t) noise,
+                           playout_delay);
 #endif
 
     // Dispatch to the media thread to ask it to start the sources,
     // because that can take a while.
     // Pass ownership of trackunion to the MediaOperationRunnable
     // to ensure it's kept alive until the MediaOperationRunnable runs (at least).
     nsIThread *mediaThread = MediaManager::GetThread();
     nsRefPtr<MediaOperationRunnable> runnable(
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -259,37 +259,43 @@ pref("media.peerconnection.use_document_
 // Do not enable identity before fixing domain comparison: see Bug 958741
 // Do not enable identity before fixing origin spoofing: see Bug 968335
 pref("media.peerconnection.identity.enabled", false);
 pref("media.peerconnection.identity.timeout", 5000);
 // These values (aec, agc, and noice) are from media/webrtc/trunk/webrtc/common_types.h
 // kXxxUnchanged = 0, kXxxDefault = 1, and higher values are specific to each 
 // setting (for Xxx = Ec, Agc, or Ns).  Defaults are all set to kXxxDefault here.
 pref("media.peerconnection.turn.disable", false);
-pref("media.peerconnection.aec_enabled", true);
-pref("media.peerconnection.aec", 1);
-pref("media.peerconnection.agc_enabled", false);
-pref("media.peerconnection.agc", 1);
-pref("media.peerconnection.noise_enabled", false);
-pref("media.peerconnection.noise", 1);
-// Adjustments for OS mediastream+output+OS+input delay (lower bound)
+pref("media.getusermedia.aec_enabled", true);
+pref("media.getusermedia.aec", 1);
+pref("media.getusermedia.agc_enabled", false);
+pref("media.getusermedia.agc", 1);
+pref("media.getusermedia.noise_enabled", true);
+pref("media.getusermedia.noise", 1);
+// Adjustments for OS-specific input delay (lower bound)
+// Adjustments for OS-specific AudioStream+cubeb+output delay (lower bound)
 #if defined(XP_MACOSX)
 pref("media.peerconnection.capture_delay", 50);
+pref("media.getusermedia.playout_delay", 10);
 #elif defined(XP_WIN)
 pref("media.peerconnection.capture_delay", 50);
+pref("media.getusermedia.playout_delay", 40);
 #elif defined(ANDROID)
 pref("media.peerconnection.capture_delay", 100);
+pref("media.getusermedia.playout_delay", 100);
 // Whether to enable Webrtc Hardware acceleration support
 pref("media.navigator.hardware.vp8_encode.acceleration_enabled", false);
 pref("media.navigator.hardware.vp8_decode.acceleration_enabled", false);
 #elif defined(XP_LINUX)
 pref("media.peerconnection.capture_delay", 70);
+pref("media.getusermedia.playout_delay", 50);
 #else
 // *BSD, others - merely a guess for now
 pref("media.peerconnection.capture_delay", 50);
+pref("media.getusermedia.playout_delay", 50);
 #endif
 #else
 #ifdef ANDROID
 pref("media.navigator.enabled", true);
 #endif
 #endif
 
 pref("media.tabstreaming.width", 320);