Bug 1446233 - P3: Add prefs to control audioipc client thread pool. r=kinetik

MozReview-Commit-ID: I4BL7Ad2xtI

--HG--
extra : rebase_source : 984378bf2fbca347762b3096f75069b7721c97be
This commit is contained in:
Dan Glastonbury 2018-03-22 15:33:25 +10:00
Родитель af50bb4391
Коммит ac696a0587
2 изменённых файлов: 43 добавлений и 4 удалений

Просмотреть файл

@ -29,6 +29,9 @@
#include "GeneratedJNIWrappers.h" #include "GeneratedJNIWrappers.h"
#endif #endif
#define AUDIOIPC_POOL_SIZE_DEFAULT 1
#define AUDIOIPC_STACK_SIZE_DEFAULT (64*1024)
#define PREF_VOLUME_SCALE "media.volume_scale" #define PREF_VOLUME_SCALE "media.volume_scale"
#define PREF_CUBEB_BACKEND "media.cubeb.backend" #define PREF_CUBEB_BACKEND "media.cubeb.backend"
#define PREF_CUBEB_LATENCY_PLAYBACK "media.cubeb_latency_playback_ms" #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_FORCE_SAMPLE_RATE "media.cubeb.force_sample_rate"
#define PREF_CUBEB_LOGGING_LEVEL "media.cubeb.logging_level" #define PREF_CUBEB_LOGGING_LEVEL "media.cubeb.logging_level"
#define PREF_CUBEB_SANDBOX "media.cubeb.sandbox" #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 (1 << AudioConfig::CHANNEL_MONO)
#define MASK_MONO_LFE (MASK_MONO | (1 << AudioConfig::CHANNEL_LFE)) #define MASK_MONO_LFE (MASK_MONO | (1 << AudioConfig::CHANNEL_LFE))
@ -61,12 +66,19 @@
#endif #endif
extern "C" { extern "C" {
struct AudioIpcInitParams {
int mServerConnection;
size_t mPoolSize;
size_t mStackSize;
};
// These functions are provided by audioipc-server crate // These functions are provided by audioipc-server crate
extern void* audioipc_server_start(); extern void* audioipc_server_start();
extern mozilla::ipc::FileDescriptor::PlatformHandleType audioipc_server_new_client(void*); extern mozilla::ipc::FileDescriptor::PlatformHandleType audioipc_server_new_client(void*);
extern void audioipc_server_stop(void*); extern void audioipc_server_stop(void*);
// These functions are provided by audioipc-client crate // 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 { namespace mozilla {
@ -133,7 +145,9 @@ bool sCubebPlaybackLatencyPrefSet = false;
bool sCubebMSGLatencyPrefSet = false; bool sCubebMSGLatencyPrefSet = false;
bool sAudioStreamInitEverSucceeded = false; bool sAudioStreamInitEverSucceeded = false;
#ifdef MOZ_CUBEB_REMOTING #ifdef MOZ_CUBEB_REMOTING
bool sCubebSandbox; bool sCubebSandbox = false;
size_t sAudioIPCPoolSize;
size_t sAudioIPCStackSize;
#endif #endif
StaticAutoPtr<char> sBrandName; StaticAutoPtr<char> sBrandName;
StaticAutoPtr<char> sCubebBackendName; StaticAutoPtr<char> sCubebBackendName;
@ -283,6 +297,16 @@ void PrefChanged(const char* aPref, void* aClosure)
StartSoundServer(); 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 #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")); MOZ_LOG(gCubebLog, LogLevel::Info, ("%s: %s", PREF_CUBEB_SANDBOX, sCubebSandbox ? "true" : "false"));
int rv = sCubebSandbox int rv = sCubebSandbox
? audioipc_client_init(&sCubebContext, sBrandName, ? audioipc_client_init(&sCubebContext, sBrandName, &initParams)
sIPCConnection->ClonePlatformHandle().release())
: cubeb_init(&sCubebContext, sBrandName, sCubebBackendName.get()); : cubeb_init(&sCubebContext, sBrandName, sCubebBackendName.get());
sIPCConnection = nullptr; sIPCConnection = nullptr;
#else // !MOZ_CUBEB_REMOTING #else // !MOZ_CUBEB_REMOTING
@ -579,6 +609,8 @@ void InitLibrary()
Preferences::RegisterCallback(PrefChanged, PREF_CUBEB_FORCE_SAMPLE_RATE); Preferences::RegisterCallback(PrefChanged, PREF_CUBEB_FORCE_SAMPLE_RATE);
Preferences::RegisterCallbackAndCall(PrefChanged, PREF_CUBEB_BACKEND); Preferences::RegisterCallbackAndCall(PrefChanged, PREF_CUBEB_BACKEND);
Preferences::RegisterCallbackAndCall(PrefChanged, PREF_CUBEB_SANDBOX); 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)) { if (MOZ_LOG_TEST(gCubebLog, LogLevel::Verbose)) {
cubeb_set_log_callback(CUBEB_LOG_VERBOSE, CubebLogCallback); cubeb_set_log_callback(CUBEB_LOG_VERBOSE, CubebLogCallback);
} else if (MOZ_LOG_TEST(gCubebLog, LogLevel::Error)) { } else if (MOZ_LOG_TEST(gCubebLog, LogLevel::Error)) {
@ -603,6 +635,8 @@ void InitLibrary()
void ShutdownLibrary() void ShutdownLibrary()
{ {
Preferences::UnregisterCallback(PrefChanged, PREF_VOLUME_SCALE); 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_SANDBOX);
Preferences::UnregisterCallback(PrefChanged, PREF_CUBEB_BACKEND); Preferences::UnregisterCallback(PrefChanged, PREF_CUBEB_BACKEND);
Preferences::UnregisterCallback(PrefChanged, PREF_CUBEB_LATENCY_PLAYBACK); Preferences::UnregisterCallback(PrefChanged, PREF_CUBEB_LATENCY_PLAYBACK);

Просмотреть файл

@ -666,6 +666,11 @@ pref("media.cubeb.logging_level", "");
// Cubeb sandbox (remoting) control // Cubeb sandbox (remoting) control
#ifdef XP_LINUX #ifdef XP_LINUX
pref("media.cubeb.sandbox", true); 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 #else
pref("media.cubeb.sandbox", false); pref("media.cubeb.sandbox", false);
#endif #endif