From 32d217338fc1e1ee1a4e6660f64c3495e52db86c Mon Sep 17 00:00:00 2001 From: Paul Adenot Date: Tue, 12 May 2020 08:31:58 +0000 Subject: [PATCH] Bug 1626081 - Add a pref to disable the audio output stream routing on Android. r=achronop Differential Revision: https://phabricator.services.mozilla.com/D74274 --- dom/media/CubebUtils.cpp | 11 +++++++++++ dom/media/CubebUtils.h | 4 ++++ dom/media/GraphDriver.cpp | 7 ++++++- modules/libpref/init/all.js | 2 ++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/dom/media/CubebUtils.cpp b/dom/media/CubebUtils.cpp index 36d7680e415e..509eab885346 100644 --- a/dom/media/CubebUtils.cpp +++ b/dom/media/CubebUtils.cpp @@ -52,6 +52,7 @@ #define PREF_CUBEB_LOGGING_LEVEL "media.cubeb.logging_level" // Hidden pref used by tests to force failure to obtain cubeb context #define PREF_CUBEB_FORCE_NULL_CONTEXT "media.cubeb.force_null_context" +#define PREF_CUBEB_OUTPUT_VOICE_ROUTING "media.cubeb.output_voice_routing" // Hidden pref to disable BMO 1427011 experiment; can be removed once proven. #define PREF_CUBEB_DISABLE_DEVICE_SWITCHING \ "media.cubeb.disable_device_switching" @@ -100,6 +101,7 @@ bool sCubebMTGLatencyPrefSet = false; bool sAudioStreamInitEverSucceeded = false; bool sCubebForceNullContext = false; bool sCubebDisableDeviceSwitching = true; +bool sRouteOutputAsVoice = false; #ifdef MOZ_CUBEB_REMOTING bool sCubebSandbox = false; size_t sAudioIPCPoolSize; @@ -267,6 +269,13 @@ void PrefChanged(const char* aPref, void* aClosure) { AUDIOIPC_STACK_SIZE_DEFAULT); } #endif + else if (strcmp(aPref, PREF_CUBEB_OUTPUT_VOICE_ROUTING) == 0) { + StaticMutexAutoLock lock(sMutex); + sRouteOutputAsVoice = Preferences::GetBool(aPref); + MOZ_LOG(gCubebLog, LogLevel::Verbose, + ("%s: %s", PREF_CUBEB_OUTPUT_VOICE_ROUTING, + sRouteOutputAsVoice ? "true" : "false")); + } } bool GetFirstStream() { @@ -676,6 +685,8 @@ cubeb_stream_prefs GetDefaultStreamPrefs() { return CUBEB_STREAM_PREF_NONE; } +bool RouteOutputAsVoice() { return sRouteOutputAsVoice; } + #ifdef MOZ_WIDGET_ANDROID uint32_t AndroidGetAudioOutputSampleRate() { int32_t sample_rate = java::GeckoAppShell::GetAudioOutputSampleRate(); diff --git a/dom/media/CubebUtils.h b/dom/media/CubebUtils.h index 1affdc7f96a3..fd0de084ea1b 100644 --- a/dom/media/CubebUtils.h +++ b/dom/media/CubebUtils.h @@ -51,6 +51,10 @@ char* GetForcedOutputDevice(); // to switch to "communication mode", which might change audio routing, // bluetooth communication type, etc. void SetInCommunication(bool aInCommunication); +// Returns true if the output streams should be routed like a stream containing +// voice data, and not generic audio. This can influence audio processing and +// device selection. +bool RouteOutputAsVoice(); # ifdef MOZ_WIDGET_ANDROID uint32_t AndroidGetAudioOutputSampleRate(); diff --git a/dom/media/GraphDriver.cpp b/dom/media/GraphDriver.cpp index a7cfb2744f32..07d2a6ddcaa6 100644 --- a/dom/media/GraphDriver.cpp +++ b/dom/media/GraphDriver.cpp @@ -642,7 +642,8 @@ void AudioCallbackDriver::Init() { output.layout = static_cast(channelMap); output.prefs = CubebUtils::GetDefaultStreamPrefs(); #if !defined(XP_WIN) - if (mInputDevicePreference == CUBEB_DEVICE_PREF_VOICE) { + if (mInputDevicePreference == CUBEB_DEVICE_PREF_VOICE && + CubebUtils::RouteOutputAsVoice()) { output.prefs |= static_cast(CUBEB_STREAM_PREF_VOICE); } #endif @@ -671,6 +672,10 @@ void AudioCallbackDriver::Init() { input = output; input.channels = mInputChannelCount; input.layout = CUBEB_LAYOUT_UNDEFINED; + input.prefs = CubebUtils::GetDefaultStreamPrefs(); + if (mInputDevicePreference == CUBEB_DEVICE_PREF_VOICE) { + input.prefs |= static_cast(CUBEB_STREAM_PREF_VOICE); + } cubeb_stream* stream = nullptr; bool inputWanted = mInputChannelCount > 0; diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 96b357301626..cd34d77d16c5 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -583,6 +583,8 @@ pref("media.cubeb.logging_level", ""); pref("media.cubeb.backend", "audiounit-rust"); #endif +pref("media.cubeb.output_voice_routing", true); + // GraphRunner (fixed MediaTrackGraph thread) control pref("media.audiograph.single_thread.enabled", true);