Bug 1429847 - Promote audio threads to real-time priority before locking down the sandbox. r=kinetik
authorPaul Adenot <paul@paul.cx>
Fri, 21 Jun 2019 19:49:10 +0000
changeset 542671 f058271e55d9e9dcd472b310d2bc92048545ff72
parent 542670 6ccf1ede2479f53aadcaa244967d641804a2d11c
child 542672 6014d0868436f7d4a5620521acaed13da036cd04
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1429847
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 1429847 - Promote audio threads to real-time priority before locking down the sandbox. r=kinetik Differential Revision: https://phabricator.services.mozilla.com/D34888
dom/ipc/ContentChild.cpp
dom/media/CubebUtils.cpp
dom/media/CubebUtils.h
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -99,16 +99,17 @@
 #include "mozilla/net/HttpChannelChild.h"
 #include "nsQueryObject.h"
 #include "imgLoader.h"
 #include "GMPServiceChild.h"
 #include "nsISimpleEnumerator.h"
 #include "nsIStringBundle.h"
 #include "nsIWorkerDebuggerManager.h"
 #include "nsGeolocation.h"
+#include "audio_thread_priority.h"
 
 #if !defined(XP_WIN)
 #  include "mozilla/Omnijar.h"
 #endif
 
 #ifdef MOZ_GECKO_PROFILER
 #  include "ChildProfilerController.h"
 #endif
@@ -1713,16 +1714,21 @@ mozilla::ipc::IPCResult ContentChild::Re
   // On Linux, we have to support systems that can't use any sandboxing.
   if (!SandboxInfo::Get().CanSandboxContent()) {
     sandboxEnabled = false;
   } else {
     // Pre-start audio before sandboxing; see bug 1443612.
     if (!Preferences::GetBool("media.cubeb.sandbox")) {
       Unused << CubebUtils::GetCubebContext();
     }
+#    if defined(XP_LINUX)
+    else {
+      CubebUtils::InitAudioThreads();
+    }
+#    endif
   }
 
   if (sandboxEnabled) {
     sandboxEnabled = SetContentProcessSandbox(
         ContentProcessSandboxParams::ForThisProcess(aBroker));
   }
 #  elif defined(XP_WIN)
   mozilla::SandboxTarget::Instance()->StartSandbox();
--- a/dom/media/CubebUtils.cpp
+++ b/dom/media/CubebUtils.cpp
@@ -76,16 +76,19 @@ struct AudioIpcInitParams {
 // These functions are provided by audioipc-server crate
 extern void* audioipc_server_start();
 extern mozilla::ipc::FileDescriptor::PlatformHandleType
 audioipc_server_new_client(void*);
 extern void audioipc_server_stop(void*);
 // These functions are provided by audioipc-client crate
 extern int audioipc_client_init(cubeb**, const char*,
                                 const AudioIpcInitParams*);
+#ifdef XP_LINUX
+extern void audioipc_init_threads(const AudioIpcInitParams*);
+#endif
 }
 
 namespace mozilla {
 
 namespace {
 
 #ifdef MOZ_CUBEB_REMOTING
 ////////////////////////////////////////////////////////////////////////////////
@@ -436,16 +439,28 @@ ipc::FileDescriptor CreateAudioIPCConnec
   close(rawFD);
 #  endif
   return fd;
 #else
   return ipc::FileDescriptor();
 #endif
 }
 
+#if defined(XP_LINUX) && !defined(MOZ_WIDGET_ANDROID)
+void InitAudioThreads() {
+  AudioIpcInitParams initParams;
+  initParams.mPoolSize = sAudioIPCPoolSize;
+  initParams.mStackSize = sAudioIPCStackSize;
+  initParams.mThreadCreateCallback = [](const char* aName) {
+    PROFILER_REGISTER_THREAD(aName);
+  };
+  audioipc_init_threads(&initParams);
+}
+#endif
+
 cubeb* GetCubebContextUnlocked() {
   sMutex.AssertCurrentThreadOwns();
   if (sCubebForceNullContext) {
     // Pref set such that we should return a null context
     MOZ_LOG(gCubebLog, LogLevel::Debug,
             ("%s: returning null context due to %s!", __func__,
              PREF_CUBEB_FORCE_NULL_CONTEXT));
     return nullptr;
--- a/dom/media/CubebUtils.h
+++ b/dom/media/CubebUtils.h
@@ -18,16 +18,19 @@ MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(cu
 namespace mozilla {
 namespace CubebUtils {
 
 typedef cubeb_devid AudioDeviceID;
 
 // Initialize Audio Library. Some Audio backends require initializing the
 // library before using it.
 void InitLibrary();
+#  ifdef XP_LINUX
+void InitAudioThreads();
+#  endif
 
 // Shutdown Audio Library. Some Audio backends require shutting down the
 // library after using it.
 void ShutdownLibrary();
 
 // Returns the maximum number of channels supported by the audio hardware.
 uint32_t MaxNumberOfChannels();