Bug 1440169 - Properly apply microphone capture settings. r?padenot draft
authorAndreas Pehrson <pehrsons@mozilla.com>
Wed, 28 Feb 2018 22:41:15 +0100
changeset 761284 2d7b2dff50b9f0321bdcfa05eace71c5ca180856
parent 761283 e49769fe6abee9b373105be3c1fca2ae595f6854
child 761285 1e2c0767e0fbf3b9d5eafa0b19dc83ec0662410b
push id100927
push userbmo:apehrson@mozilla.com
push dateWed, 28 Feb 2018 21:53:44 +0000
reviewerspadenot
bugs1440169
milestone60.0a1
Bug 1440169 - Properly apply microphone capture settings. r?padenot MozReview-Commit-ID: FDVPwTIzDIX
dom/media/webrtc/MediaEngineWebRTC.h
dom/media/webrtc/MediaEngineWebRTCAudio.cpp
--- a/dom/media/webrtc/MediaEngineWebRTC.h
+++ b/dom/media/webrtc/MediaEngineWebRTC.h
@@ -516,17 +516,17 @@ private:
                               const nsString& aDeviceId,
                               const char** aOutBadConstraint);
 
 
   void UpdateAECSettingsIfNeeded(bool aEnable, webrtc::EcModes aMode);
   void UpdateAGCSettingsIfNeeded(bool aEnable, webrtc::AgcModes aMode);
   void UpdateNSSettingsIfNeeded(bool aEnable, webrtc::NsModes aMode);
 
-  void SetLastPrefs(const MediaEnginePrefs& aPrefs);
+  void ApplySettings(const MediaEnginePrefs& aPrefs);
 
   bool HasEnabledTrack() const;
 
   template<typename T>
   void InsertInGraph(const T* aBuffer,
                      size_t aFrames,
                      uint32_t aChannels);
 
--- a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
+++ b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
@@ -509,37 +509,38 @@ MediaEngineWebRTCMicrophoneSource::Updat
     UpdateNSSettingsIfNeeded(prefs.mNoiseOn, static_cast<NsModes>(prefs.mNoise));
     UpdateAECSettingsIfNeeded(prefs.mAecOn, static_cast<EcModes>(prefs.mAec));
 
     webrtc::Config config;
     config.Set<webrtc::ExtendedFilter>(new webrtc::ExtendedFilter(mExtendedFilter));
     config.Set<webrtc::DelayAgnostic>(new webrtc::DelayAgnostic(mDelayAgnostic));
     mAudioProcessing->SetExtraOptions(config);
   }
-  SetLastPrefs(prefs);
+  mLastPrefs = prefs;
   return NS_OK;
 }
 
 #undef HANDLE_APM_ERROR
 
 void
-MediaEngineWebRTCMicrophoneSource::SetLastPrefs(const MediaEnginePrefs& aPrefs)
+MediaEngineWebRTCMicrophoneSource::ApplySettings(const MediaEnginePrefs& aPrefs)
 {
   AssertIsOnOwningThread();
 
   mLastPrefs = aPrefs;
 
   RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
   RefPtr<MediaStreamGraphImpl> graph;
   for (const Allocation& allocation : mAllocations) {
     if (allocation.mStream) {
       graph = allocation.mStream->GraphImpl();
       break;
     }
   }
+  MOZ_DIAGNOSTIC_ASSERT(graph);
   NS_DispatchToMainThread(media::NewRunnableFrom([that, graph, aPrefs]() mutable {
     that->mSettings->mEchoCancellation.Value() = aPrefs.mAecOn;
     that->mSettings->mAutoGainControl.Value() = aPrefs.mAgcOn;
     that->mSettings->mNoiseSuppression.Value() = aPrefs.mNoiseOn;
     that->mSettings->mChannelCount.Value() = aPrefs.mChannels;
 
     class Message : public ControlMessage {
     public:
@@ -706,16 +707,18 @@ MediaEngineWebRTCMicrophoneSource::Start
 
     // Must be *before* StartSend() so it will notice we selected external input (full_duplex)
     mAudioInput->StartRecording(allocation.mStream, mListener);
 
     MOZ_ASSERT(mState != kReleased);
     mState = kStarted;
   }
 
+  ApplySettings(mLastPrefs);
+
   return NS_OK;
 }
 
 nsresult
 MediaEngineWebRTCMicrophoneSource::Stop(const RefPtr<const AllocationHandle>& aHandle)
 {
   AssertIsOnOwningThread();