Bug 1670917 - Add a pref to allow using raw WASAPI streams. Make it default to input-only raw streams. r=kinetik

Differential Revision: https://phabricator.services.mozilla.com/D93363
This commit is contained in:
Paul Adenot 2020-10-20 20:03:26 +00:00
parent f667ac98ae
commit 0ddc112415
5 changed files with 27 additions and 9 deletions

View File

@ -286,7 +286,7 @@ nsresult AudioStream::Init(uint32_t aNumChannels,
params.channels = mOutChannels;
params.layout = static_cast<uint32_t>(aChannelMap);
params.format = ToCubebFormat<AUDIO_OUTPUT_FORMAT>::value;
params.prefs = CubebUtils::GetDefaultStreamPrefs();
params.prefs = CubebUtils::GetDefaultStreamPrefs(CUBEB_DEVICE_TYPE_OUTPUT);
// This is noop if MOZ_DUMP_AUDIO is not set.
mDumpFile.Open("AudioStream", mOutChannels, aRate);

View File

@ -39,6 +39,7 @@
#include <cmath>
#include <thread>
#include "AudioThreadRegistry.h"
#include "mozilla/StaticPrefs_media.h"
#define AUDIOIPC_POOL_SIZE_DEFAULT 1
#define AUDIOIPC_STACK_SIZE_DEFAULT (64 * 4096)
@ -695,16 +696,20 @@ char* GetForcedOutputDevice() {
return sCubebOutputDeviceName;
}
cubeb_stream_prefs GetDefaultStreamPrefs() {
cubeb_stream_prefs GetDefaultStreamPrefs(cubeb_device_type aType) {
cubeb_stream_prefs prefs = CUBEB_STREAM_PREF_NONE;
#ifdef XP_WIN
// Investigation for bug 1427011 - if we're in E10S mode, rely on the
// AudioNotification IPC to detect device changes.
if (sCubebDisableDeviceSwitching &&
(XRE_IsE10sParentProcess() || XRE_IsContentProcess())) {
return CUBEB_STREAM_PREF_DISABLE_DEVICE_SWITCHING;
prefs |= CUBEB_STREAM_PREF_DISABLE_DEVICE_SWITCHING;
}
if (StaticPrefs::media_cubeb_wasapi_raw() & static_cast<uint32_t>(aType)) {
prefs |= CUBEB_STREAM_PREF_RAW;
}
#endif
return CUBEB_STREAM_PREF_NONE;
return prefs;
}
bool RouteOutputAsVoice() { return sRouteOutputAsVoice; }
@ -735,7 +740,7 @@ bool EstimatedRoundTripLatencyDefaultDevices(double* aMean, double* aStdDev) {
output_params.rate = rate;
output_params.channels = 2;
output_params.layout = CUBEB_LAYOUT_UNDEFINED;
output_params.prefs = GetDefaultStreamPrefs();
output_params.prefs = GetDefaultStreamPrefs(CUBEB_DEVICE_TYPE_OUTPUT);
latencyFrames = GetCubebMTGLatencyInFrames(&output_params);
@ -744,7 +749,7 @@ bool EstimatedRoundTripLatencyDefaultDevices(double* aMean, double* aStdDev) {
input_params.rate = rate;
input_params.channels = 1;
input_params.layout = CUBEB_LAYOUT_UNDEFINED;
input_params.prefs = GetDefaultStreamPrefs();
input_params.prefs = GetDefaultStreamPrefs(CUBEB_DEVICE_TYPE_INPUT);
cubeb_stream* stm;
rv = cubeb_stream_init(GetCubebContext(), &stm,

View File

@ -54,7 +54,7 @@ uint32_t GetCubebPlaybackLatencyInMilliseconds();
uint32_t GetCubebMTGLatencyInFrames(cubeb_stream_params* params);
bool CubebLatencyPrefSet();
void GetCurrentBackend(nsAString& aBackend);
cubeb_stream_prefs GetDefaultStreamPrefs();
cubeb_stream_prefs GetDefaultStreamPrefs(cubeb_device_type aType);
char* GetForcedOutputDevice();
// No-op on all platforms but Android, where it tells the device's AudioManager
// to switch to "communication mode", which might change audio routing,

View File

@ -636,7 +636,7 @@ void AudioCallbackDriver::Init() {
AudioConfig::ChannelLayout(mOutputChannelCount).Map();
output.layout = static_cast<uint32_t>(channelMap);
output.prefs = CubebUtils::GetDefaultStreamPrefs();
output.prefs = CubebUtils::GetDefaultStreamPrefs(CUBEB_DEVICE_TYPE_OUTPUT);
if (mInputDevicePreference == CUBEB_DEVICE_PREF_VOICE &&
CubebUtils::RouteOutputAsVoice()) {
output.prefs |= static_cast<cubeb_stream_prefs>(CUBEB_STREAM_PREF_VOICE);
@ -666,7 +666,7 @@ void AudioCallbackDriver::Init() {
input = output;
input.channels = mInputChannelCount;
input.layout = CUBEB_LAYOUT_UNDEFINED;
input.prefs = CubebUtils::GetDefaultStreamPrefs();
input.prefs = CubebUtils::GetDefaultStreamPrefs(CUBEB_DEVICE_TYPE_INPUT);
if (mInputDevicePreference == CUBEB_DEVICE_PREF_VOICE) {
input.prefs |= static_cast<cubeb_stream_prefs>(CUBEB_STREAM_PREF_VOICE);
}

View File

@ -6829,6 +6829,19 @@
value: false
#endif
# Whether or not to pass AUDCLNT_STREAMOPTIONS_RAW when initializing audio
# streams when using WASAPI.
# 0 - don't use RAW streams
# 1 - use RAW streams for input streams only
# 2 - use RAW streams for output streams only
# 3 - use RAW streams for input and output streams
#if defined (XP_WIN)
- name: media.cubeb.wasapi-raw
type: RelaxedAtomicUint32
mirror: always
value: 1
#endif // XP_WIN
# ClockDrift desired buffering in milliseconds
- name: media.clockdrift.buffering
type: int32_t