From 442ee9bf5098876c020153dbeaed70270ba98cad Mon Sep 17 00:00:00 2001 From: Randell Jesup Date: Wed, 2 Apr 2014 13:58:20 -0400 Subject: [PATCH] Bug 694814: Patch 6 - Change gUM prefs to media.getusermedia.*, groundwork for in-call changes r=jib --- dom/media/MediaManager.cpp | 113 ++++++++++++++++++++++---------- modules/libpref/src/init/all.js | 20 ++++-- 2 files changed, 91 insertions(+), 42 deletions(-) diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index 50478d1027e..287dfc00575 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -400,13 +400,30 @@ class nsDOMUserMediaStream : public DOMLocalMediaStream { public: static already_AddRefed - CreateTrackUnionStream(nsIDOMWindow* aWindow, uint32_t aHintContents) + CreateTrackUnionStream(nsIDOMWindow* aWindow, + MediaEngineSource *aAudioSource, + MediaEngineSource *aVideoSource) { - nsRefPtr stream = new nsDOMUserMediaStream(); - stream->InitTrackUnionStream(aWindow, aHintContents); + DOMMediaStream::TrackTypeHints hints = + (aAudioSource ? DOMMediaStream::HINT_CONTENTS_AUDIO : 0) | + (aVideoSource ? DOMMediaStream::HINT_CONTENTS_VIDEO : 0); + + nsRefPtr 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(); @@ -436,6 +453,21 @@ public: 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) { @@ -458,6 +490,14 @@ public: // explicitly destroyed too. nsRefPtr mSourceStream; nsRefPtr mPort; + nsRefPtr 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; }; /** @@ -538,6 +578,12 @@ public: 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 (nsGlobalWindow::GetInnerWindowWithId(mWindowID)); @@ -550,19 +596,39 @@ public: return NS_OK; } - // Create a media stream. - DOMMediaStream::TrackTypeHints hints = - (mAudioSource ? DOMMediaStream::HINT_CONTENTS_AUDIO : 0) | - (mVideoSource ? DOMMediaStream::HINT_CONTENTS_VIDEO : 0); +#ifdef MOZ_WEBRTC + // Right now these configs are only of use if webrtc is available + nsresult rv; + nsCOMPtr prefs = do_GetService("@mozilla.org/preferences-service;1", &rv); + if (NS_SUCCEEDED(rv)) { + nsCOMPtr 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. nsRefPtr trackunion = - nsDOMUserMediaStream::CreateTrackUnionStream(window, hints); + nsDOMUserMediaStream::CreateTrackUnionStream(window, mAudioSource, + mVideoSource); if (!trackunion) { nsCOMPtr 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 stream = gm->CreateSourceStream(nullptr); @@ -593,33 +659,10 @@ public: new TracksAvailableCallback(mManager, mSuccess, mWindowID, trackunion); #ifdef MOZ_WEBRTC - // Right now these configs are only of use if webrtc is available - nsresult rv; - nsCOMPtr prefs = do_GetService("@mozilla.org/preferences-service;1", &rv); - if (NS_SUCCEEDED(rv)) { - nsCOMPtr 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, diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js index 79e3cf4b587..58af5c3971f 100644 --- a/modules/libpref/src/init/all.js +++ b/modules/libpref/src/init/all.js @@ -264,27 +264,33 @@ pref("media.peerconnection.identity.timeout", 5000); // 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