Bug 1575638 - Determine whether or not hard panning should be performed on OSX outside the audio callback. r=kinetik
authorPaul Adenot <paul@paul.cx>
Fri, 11 Oct 2019 15:45:18 +0000
changeset 497404 2097a722000f452c2a76968cd5c6777de45860d6
parent 497403 bab9dd2438e9b506ed31c583c5a0bf7d21a84a20
child 497405 a1a3a0d2a514f5736a9cdc97f33ad2543cd6af4d
push id97863
push userpadenot@mozilla.com
push dateMon, 14 Oct 2019 09:06:55 +0000
treeherderautoland@2097a722000f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1575638
milestone71.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 1575638 - Determine whether or not hard panning should be performed on OSX outside the audio callback. r=kinetik Differential Revision: https://phabricator.services.mozilla.com/D47283
dom/media/GraphDriver.cpp
dom/media/GraphDriver.h
dom/media/VideoFrameContainer.cpp
--- a/dom/media/GraphDriver.cpp
+++ b/dom/media/GraphDriver.cpp
@@ -1040,17 +1040,22 @@ void AudioCallbackDriver::PanOutputIfNee
 
 void AudioCallbackDriver::DeviceChangedCallback() {
   MOZ_ASSERT(!OnGraphThread());
   // Tell the audio engine the device has changed, it might want to reset some
   // state.
   MonitorAutoLock mon(mGraphImpl->GetMonitor());
   GraphImpl()->DeviceChanged();
 #ifdef XP_MACOSX
-  PanOutputIfNeeded(mInputChannelCount);
+  RefPtr<AudioCallbackDriver> self(this);
+  bool hasInput = mInputChannelCount;
+  NS_DispatchToBackgroundThread(NS_NewRunnableFunction(
+      "PanOutputIfNeeded", [self{std::move(self)}, hasInput]() {
+        self->PanOutputIfNeeded(hasInput);
+      }));
 #endif
 }
 
 uint32_t AudioCallbackDriver::IterationDuration() {
   MOZ_ASSERT(OnGraphThread());
   // The real fix would be to have an API in cubeb to give us the number. Short
   // of that, we approximate it here. bug 1019507
   return mIterationDurationMS;
--- a/dom/media/GraphDriver.h
+++ b/dom/media/GraphDriver.h
@@ -533,17 +533,17 @@ class AudioCallbackDriver : public Graph
   bool mShouldFallbackIfError;
   /* True if this driver was created from a driver created because of a previous
    * AudioCallbackDriver failure. */
   bool mFromFallback;
 #ifdef XP_MACOSX
   /* When using the built-in speakers on macbook pro (13 and 15, all models),
    * it's best to hard pan the audio on the right, to avoid feedback into the
    * microphone that is located next to the left speaker.  */
-  bool mNeedsPanning;
+  Atomic<bool> mNeedsPanning;
 #endif
 };
 
 class AsyncCubebTask : public Runnable {
  public:
   AsyncCubebTask(AudioCallbackDriver* aDriver, AsyncCubebOperation aOperation);
 
   nsresult Dispatch(uint32_t aFlags = NS_DISPATCH_NORMAL) {
--- a/dom/media/VideoFrameContainer.cpp
+++ b/dom/media/VideoFrameContainer.cpp
@@ -6,16 +6,17 @@
 
 #include "VideoFrameContainer.h"
 
 #ifdef MOZ_WIDGET_ANDROID
 #include "GLImages.h"  // for SurfaceTextureImage
 #endif
 #include "MediaDecoderOwner.h"
 #include "mozilla/Telemetry.h"
+#include "mozilla/AbstractThread.h"
 
 using namespace mozilla::layers;
 
 namespace mozilla {
 static LazyLogModule gVideoFrameContainerLog("VideoFrameContainer");
 #define CONTAINER_LOG(type, msg) MOZ_LOG(gVideoFrameContainerLog, type, msg)
 
 #define NS_DispatchToMainThread(...) CompileError_UseAbstractMainThreadInstead