Bug 1447982 - Squashed fixes for Firefox 60. r=padenot, a=jcristau
authorAndreas Pehrson <pehrsons@mozilla.com>
Thu, 12 Apr 2018 16:43:58 +0200
changeset 460824 9e8eacca6e47f0b0a515260c85b5a691a391c8e4
parent 460823 9c8731ec8be68c4ad2786a257b32efec783b2ddd
child 460825 15079c3a4d0f9ca29cf4d737c7b112cbb409e741
push id9066
push userryanvm@gmail.com
push dateMon, 16 Apr 2018 16:39:10 +0000
treeherdermozilla-beta@9f8ac6bbbd47 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot, jcristau
bugs1447982
milestone60.0
Bug 1447982 - Squashed fixes for Firefox 60. r=padenot, a=jcristau This patch includes the following patches rebased and squashed: Cover channel count changes also when mic source is stopped (muted). r=padenot https://hg.mozilla.org/mozilla-central/rev/5ce4dd0d0ca5 Mic source's ApplySettings shouldn't have weird side effects. r=padenot https://hg.mozilla.org/mozilla-central/rev/5180d718e5a5 Apply and update mic source settings on Reconfigure. r=padenot https://hg.mozilla.org/mozilla-central/rev/e87afd1fda35 Pass GraphImpl into ApplySettings. r=padenot https://hg.mozilla.org/mozilla-central/rev/19e183125269 Rename mLastPrefs to mNetPrefs and update comment for clarity. r=padenot https://hg.mozilla.org/mozilla-central/rev/a67e5015e456
dom/media/webrtc/MediaEngineWebRTC.h
dom/media/webrtc/MediaEngineWebRTCAudio.cpp
--- a/dom/media/webrtc/MediaEngineWebRTC.h
+++ b/dom/media/webrtc/MediaEngineWebRTC.h
@@ -526,17 +526,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);
 
@@ -596,19 +597,21 @@ private:
   uint64_t mLastLogFrames;
 
   // mSkipProcessing is true if none of the processing passes are enabled,
   // because of prefs or constraints. This allows simply copying the audio into
   // the MSG, skipping resampling and the whole webrtc.org code.
   // This is read and written to only on the MSG thread.
   bool mSkipProcessing;
 
-  // To only update microphone when needed, we keep track of previous settings.
+  // To only update microphone when needed, we keep track of the prefs
+  // representing the currently applied settings for this source. This is the
+  // net result of the prefs across all allocations.
   // Owning thread only.
-  MediaEnginePrefs mLastPrefs;
+  MediaEnginePrefs mNetPrefs;
 
   // Stores the mixed audio output for the reverse-stream of the AEC.
   AlignedFloatBuffer mOutputBuffer;
 
   AlignedFloatBuffer mInputBuffer;
   AlignedFloatBuffer mDeinterleavedBuffer;
   AlignedFloatBuffer mInputDownmixBuffer;
 };
--- a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
+++ b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp
@@ -227,18 +227,24 @@ MediaEngineWebRTCMicrophoneSource::Recon
                                                const char** aOutBadConstraint)
 {
   AssertIsOnOwningThread();
   MOZ_ASSERT(aHandle);
 
   LOG(("Mic source %p allocation %p Reconfigure()", this, aHandle.get()));
 
   NormalizedConstraints constraints(aConstraints);
-  return ReevaluateAllocation(aHandle, &constraints, aPrefs, aDeviceId,
-                              aOutBadConstraint);
+  nsresult rv = ReevaluateAllocation(aHandle, &constraints, aPrefs, aDeviceId,
+                                     aOutBadConstraint);
+
+  size_t i = mAllocations.IndexOf(aHandle, 0, AllocationHandleComparator());
+  MOZ_DIAGNOSTIC_ASSERT(i != mAllocations.NoIndex);
+  ApplySettings(mNetPrefs, mAllocations[i].mStream->GraphImpl());
+
+  return rv;
 }
 
 bool operator == (const MediaEnginePrefs& a, const MediaEnginePrefs& b)
 {
   return !memcmp(&a, &b, sizeof(MediaEnginePrefs));
 };
 
 // This does an early return in case of error.
@@ -446,39 +452,40 @@ MediaEngineWebRTCMicrophoneSource::Updat
         uint32_t channelCount = 0;
         mAudioInput->GetChannelCount(channelCount);
         MOZ_ASSERT(channelCount > 0);
         prefs.mChannels = channelCount;
       }
       break;
 
     case kStarted:
-      if (prefs == mLastPrefs) {
+    case kStopped:
+      if (prefs == mNetPrefs) {
         return NS_OK;
       }
 
-      if (prefs.mChannels != mLastPrefs.mChannels) {
+      if (prefs.mChannels != mNetPrefs.mChannels) {
         // If the channel count changed, tell the MSG to open a new driver with
         // the correct channel count.
         MOZ_ASSERT(!mAllocations.IsEmpty());
         RefPtr<SourceMediaStream> stream;
         for (const Allocation& allocation : mAllocations) {
           if (allocation.mStream) {
             stream = allocation.mStream;
             break;
           }
         }
         MOZ_ASSERT(stream);
 
         mAudioInput->SetUserChannelCount(prefs.mChannels);
         // Get validated number of channel
         uint32_t channelCount = 0;
         mAudioInput->GetChannelCount(channelCount);
-        MOZ_ASSERT(channelCount > 0 && mLastPrefs.mChannels > 0);
-        if (mLastPrefs.mChannels != prefs.mChannels &&
+        MOZ_ASSERT(channelCount > 0 && mNetPrefs.mChannels > 0);
+        if (mNetPrefs.mChannels != prefs.mChannels &&
             !stream->OpenNewAudioCallbackDriver(mListener)) {
           MOZ_LOG(GetMediaManagerLog(), LogLevel::Error, ("Could not open a new AudioCallbackDriver for input"));
           return NS_ERROR_FAILURE;
         }
       }
 
       if (MOZ_LOG_TEST(GetMediaManagerLog(), LogLevel::Debug)) {
         if (mAllocations.IsEmpty()) {
@@ -499,39 +506,31 @@ 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);
   }
-  mLastPrefs = prefs;
+  mNetPrefs = prefs;
   return NS_OK;
 }
 
 #undef HANDLE_APM_ERROR
 
 void
-MediaEngineWebRTCMicrophoneSource::ApplySettings(const MediaEnginePrefs& aPrefs)
+MediaEngineWebRTCMicrophoneSource::ApplySettings(const MediaEnginePrefs& aPrefs,
+                                                 RefPtr<MediaStreamGraphImpl> aGraph)
 {
   AssertIsOnOwningThread();
-
-  mLastPrefs = aPrefs;
+  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,
@@ -714,17 +713,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();