From ac696a05876c15f9f0430c3b79f089564b8831e3 Mon Sep 17 00:00:00 2001 From: Dan Glastonbury Date: Thu, 22 Mar 2018 15:33:25 +1000 Subject: [PATCH] Bug 1446233 - P3: Add prefs to control audioipc client thread pool. r=kinetik MozReview-Commit-ID: I4BL7Ad2xtI --HG-- extra : rebase_source : 984378bf2fbca347762b3096f75069b7721c97be --- dom/media/CubebUtils.cpp | 42 +++++++++++++++++++++++++++++++++---- modules/libpref/init/all.js | 5 +++++ 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/dom/media/CubebUtils.cpp b/dom/media/CubebUtils.cpp index 8bc4c6cd8a0b..51a780f915f9 100644 --- a/dom/media/CubebUtils.cpp +++ b/dom/media/CubebUtils.cpp @@ -29,6 +29,9 @@ #include "GeneratedJNIWrappers.h" #endif +#define AUDIOIPC_POOL_SIZE_DEFAULT 1 +#define AUDIOIPC_STACK_SIZE_DEFAULT (64*1024) + #define PREF_VOLUME_SCALE "media.volume_scale" #define PREF_CUBEB_BACKEND "media.cubeb.backend" #define PREF_CUBEB_LATENCY_PLAYBACK "media.cubeb_latency_playback_ms" @@ -38,6 +41,8 @@ #define PREF_CUBEB_FORCE_SAMPLE_RATE "media.cubeb.force_sample_rate" #define PREF_CUBEB_LOGGING_LEVEL "media.cubeb.logging_level" #define PREF_CUBEB_SANDBOX "media.cubeb.sandbox" +#define PREF_AUDIOIPC_POOL_SIZE "media.audioipc.pool_size" +#define PREF_AUDIOIPC_STACK_SIZE "media.audioipc.stack_size" #define MASK_MONO (1 << AudioConfig::CHANNEL_MONO) #define MASK_MONO_LFE (MASK_MONO | (1 << AudioConfig::CHANNEL_LFE)) @@ -61,12 +66,19 @@ #endif extern "C" { + +struct AudioIpcInitParams { + int mServerConnection; + size_t mPoolSize; + size_t mStackSize; +}; + // 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*, int); +extern int audioipc_client_init(cubeb**, const char*, const AudioIpcInitParams*); } namespace mozilla { @@ -133,7 +145,9 @@ bool sCubebPlaybackLatencyPrefSet = false; bool sCubebMSGLatencyPrefSet = false; bool sAudioStreamInitEverSucceeded = false; #ifdef MOZ_CUBEB_REMOTING -bool sCubebSandbox; +bool sCubebSandbox = false; +size_t sAudioIPCPoolSize; +size_t sAudioIPCStackSize; #endif StaticAutoPtr sBrandName; StaticAutoPtr sCubebBackendName; @@ -283,6 +297,16 @@ void PrefChanged(const char* aPref, void* aClosure) StartSoundServer(); } } + else if (strcmp(aPref, PREF_AUDIOIPC_POOL_SIZE) == 0) { + StaticMutexAutoLock lock(sMutex); + sAudioIPCPoolSize = Preferences::GetUint(PREF_AUDIOIPC_POOL_SIZE, + AUDIOIPC_POOL_SIZE_DEFAULT); + } + else if (strcmp(aPref, PREF_AUDIOIPC_STACK_SIZE) == 0) { + StaticMutexAutoLock lock(sMutex); + sAudioIPCStackSize = Preferences::GetUint(PREF_AUDIOIPC_STACK_SIZE, + AUDIOIPC_STACK_SIZE_DEFAULT); + } #endif } @@ -480,11 +504,17 @@ cubeb* GetCubebContextUnlocked() } } + AudioIpcInitParams initParams; + initParams.mPoolSize = sAudioIPCPoolSize; + initParams.mStackSize = sAudioIPCStackSize; + initParams.mServerConnection = sIPCConnection->ClonePlatformHandle().release(); + + 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)); MOZ_LOG(gCubebLog, LogLevel::Info, ("%s: %s", PREF_CUBEB_SANDBOX, sCubebSandbox ? "true" : "false")); int rv = sCubebSandbox - ? audioipc_client_init(&sCubebContext, sBrandName, - sIPCConnection->ClonePlatformHandle().release()) + ? audioipc_client_init(&sCubebContext, sBrandName, &initParams) : cubeb_init(&sCubebContext, sBrandName, sCubebBackendName.get()); sIPCConnection = nullptr; #else // !MOZ_CUBEB_REMOTING @@ -579,6 +609,8 @@ void InitLibrary() Preferences::RegisterCallback(PrefChanged, PREF_CUBEB_FORCE_SAMPLE_RATE); Preferences::RegisterCallbackAndCall(PrefChanged, PREF_CUBEB_BACKEND); Preferences::RegisterCallbackAndCall(PrefChanged, PREF_CUBEB_SANDBOX); + Preferences::RegisterCallbackAndCall(PrefChanged, PREF_AUDIOIPC_POOL_SIZE); + Preferences::RegisterCallbackAndCall(PrefChanged, PREF_AUDIOIPC_STACK_SIZE); if (MOZ_LOG_TEST(gCubebLog, LogLevel::Verbose)) { cubeb_set_log_callback(CUBEB_LOG_VERBOSE, CubebLogCallback); } else if (MOZ_LOG_TEST(gCubebLog, LogLevel::Error)) { @@ -603,6 +635,8 @@ void InitLibrary() void ShutdownLibrary() { Preferences::UnregisterCallback(PrefChanged, PREF_VOLUME_SCALE); + Preferences::UnregisterCallback(PrefChanged, PREF_AUDIOIPC_STACK_SIZE); + Preferences::UnregisterCallback(PrefChanged, PREF_AUDIOIPC_POOL_SIZE); Preferences::UnregisterCallback(PrefChanged, PREF_CUBEB_SANDBOX); Preferences::UnregisterCallback(PrefChanged, PREF_CUBEB_BACKEND); Preferences::UnregisterCallback(PrefChanged, PREF_CUBEB_LATENCY_PLAYBACK); diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 10d15af4d4d5..f71376a991ad 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -666,6 +666,11 @@ pref("media.cubeb.logging_level", ""); // Cubeb sandbox (remoting) control #ifdef XP_LINUX pref("media.cubeb.sandbox", true); +// The cubeb pulse audio backend effectively serializes callbacks so +// only 1 thread is required. +pref("media.audioipc.pool_size", 1); +// 64 kB stack per pool thread. +pref("media.audioipc.stack_size", 65536); #else pref("media.cubeb.sandbox", false); #endif