Bug 1447982 - Pass GraphImpl into ApplySettings. r?padenot draft
authorAndreas Pehrson <pehrsons@mozilla.com>
Mon, 26 Mar 2018 12:18:35 +0200
changeset 781070 28e8885e97ff560b926f17cf754371880d47b954
parent 781069 c47ba651e3de2ba1687b28b2256934e6d46addaf
child 781071 d515517731a94cc7dfc42d5855d19df132f61a62
push id106197
push userbmo:apehrson@mozilla.com
push dateThu, 12 Apr 2018 13:32:52 +0000
reviewerspadenot
bugs1447982
milestone61.0a1
Bug 1447982 - Pass GraphImpl into ApplySettings. r?padenot MozReview-Commit-ID: GQlRUB3O1em
dom/media/webrtc/MediaEngineWebRTC.h
dom/media/webrtc/MediaEngineWebRTCAudio.cpp
--- a/dom/media/webrtc/MediaEngineWebRTC.h
+++ b/dom/media/webrtc/MediaEngineWebRTC.h
@@ -528,17 +528,18 @@ 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 ApplySettings(const MediaEnginePrefs& aPrefs);
+  void ApplySettings(const MediaEnginePrefs& aPrefs,
+                     RefPtr<MediaStreamGraphImpl> aGraph);
 
   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
@@ -243,17 +243,19 @@ MediaEngineWebRTCMicrophoneSource::Recon
     nsAutoCString name;
     GetErrorName(rv, name);
     LOG(("Mic source %p Reconfigure() failed unexpectedly. rv=%s",
          this, name.Data()));
     Stop(aHandle);
     return NS_ERROR_UNEXPECTED;
   }
 
-  ApplySettings(mLastPrefs);
+  size_t i = mAllocations.IndexOf(aHandle, 0, AllocationHandleComparator());
+  MOZ_DIAGNOSTIC_ASSERT(i != mAllocations.NoIndex);
+  ApplySettings(mLastPrefs, mAllocations[i].mStream->GraphImpl());
 
   return NS_OK;
 }
 
 bool operator == (const MediaEnginePrefs& a, const MediaEnginePrefs& b)
 {
   return !memcmp(&a, &b, sizeof(MediaEnginePrefs));
 };
@@ -523,30 +525,24 @@ MediaEngineWebRTCMicrophoneSource::Updat
   }
   mLastPrefs = prefs;
   return NS_OK;
 }
 
 #undef HANDLE_APM_ERROR
 
 void
-MediaEngineWebRTCMicrophoneSource::ApplySettings(const MediaEnginePrefs& aPrefs)
+MediaEngineWebRTCMicrophoneSource::ApplySettings(const MediaEnginePrefs& aPrefs,
+                                                 RefPtr<MediaStreamGraphImpl> aGraph)
 {
   AssertIsOnOwningThread();
+  MOZ_DIAGNOSTIC_ASSERT(aGraph);
 
   RefPtr<MediaEngineWebRTCMicrophoneSource> that = this;
-  RefPtr<MediaStreamGraphImpl> graph;
-  for (const Allocation& allocation : mAllocations) {
-    if (allocation.mStream && allocation.mStream->GraphImpl()) {
-      graph = allocation.mStream->GraphImpl();
-      break;
-    }
-  }
-  MOZ_DIAGNOSTIC_ASSERT(graph);
-  NS_DispatchToMainThread(media::NewRunnableFrom([that, graph, aPrefs]() mutable {
+  NS_DispatchToMainThread(media::NewRunnableFrom([that, graph = Move(aGraph), 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:
       Message(MediaEngineWebRTCMicrophoneSource* aSource,
@@ -729,17 +725,17 @@ 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);
+  ApplySettings(mNetPrefs, allocation.mStream->GraphImpl());
 
   return NS_OK;
 }
 
 nsresult
 MediaEngineWebRTCMicrophoneSource::Stop(const RefPtr<const AllocationHandle>& aHandle)
 {
   AssertIsOnOwningThread();