Bug 1550695 - Wrap cubeb_init in EnsureMTA to handle being called from threads where COM is uninitialized. r=achronop
authorMatthew Gregan <kinetik@flim.org>
Tue, 28 May 2019 09:53:04 +0000
changeset 475974 546170ac7ca95ecacf73efeef9c1f53bb4b2fefc
parent 475973 4a88deceba11c2dae458a4130e2ed9f0e7c81dd8
child 475975 158f25256022be3aebd1e1649cc059e633e7842e
push id36080
push usernerli@mozilla.com
push dateWed, 29 May 2019 09:48:47 +0000
treeherdermozilla-central@d78adc84bde8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersachronop
bugs1550695
milestone69.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 1550695 - Wrap cubeb_init in EnsureMTA to handle being called from threads where COM is uninitialized. r=achronop Depends on D32654 Differential Revision: https://phabricator.services.mozilla.com/D32655
dom/media/CubebUtils.cpp
--- a/dom/media/CubebUtils.cpp
+++ b/dom/media/CubebUtils.cpp
@@ -27,16 +27,19 @@
 #include "nsString.h"
 #include "nsThreadUtils.h"
 #include "prdtoa.h"
 #include <algorithm>
 #include <stdint.h>
 #ifdef MOZ_WIDGET_ANDROID
 #  include "GeneratedJNIWrappers.h"
 #endif
+#ifdef XP_WIN
+#  include "mozilla/mscom/EnsureMTA.h"
+#endif
 
 #define AUDIOIPC_POOL_SIZE_DEFAULT 2
 #define AUDIOIPC_STACK_SIZE_DEFAULT (64 * 4096)
 
 #define PREF_VOLUME_SCALE "media.volume_scale"
 #define PREF_CUBEB_BACKEND "media.cubeb.backend"
 #define PREF_CUBEB_OUTPUT_DEVICE "media.cubeb.output_device"
 #define PREF_CUBEB_LATENCY_PLAYBACK "media.cubeb_latency_playback_ms"
@@ -486,17 +489,23 @@ cubeb* GetCubebContextUnlocked() {
     MOZ_LOG(gCubebLog, LogLevel::Debug,
             ("%s: %d", PREF_AUDIOIPC_POOL_SIZE, (int)initParams.mPoolSize));
     MOZ_LOG(gCubebLog, LogLevel::Debug,
             ("%s: %d", PREF_AUDIOIPC_STACK_SIZE, (int)initParams.mStackSize));
 
     rv = audioipc_client_init(&sCubebContext, sBrandName, &initParams);
   } else {
 #endif  // MOZ_CUBEB_REMOTING
-    rv = cubeb_init(&sCubebContext, sBrandName, sCubebBackendName.get());
+#ifdef XP_WIN
+    mozilla::mscom::EnsureMTA([&]() -> void {
+#endif
+      rv = cubeb_init(&sCubebContext, sBrandName, sCubebBackendName.get());
+#ifdef XP_WIN
+    });
+#endif
 #ifdef MOZ_CUBEB_REMOTING
   }
   sIPCConnection = nullptr;
 #endif  // MOZ_CUBEB_REMOTING
   NS_WARNING_ASSERTION(rv == CUBEB_OK, "Could not get a cubeb context.");
   sCubebState =
       (rv == CUBEB_OK) ? CubebState::Initialized : CubebState::Uninitialized;