Bug 1531833 - When the input is voice, activate the global communication mode. r=pehrsons

Differential Revision: https://phabricator.services.mozilla.com/D21738

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Paul Adenot 2019-04-16 15:42:42 +00:00
Родитель b1c0df1177
Коммит 784704534a
4 изменённых файлов: 41 добавлений и 1 удалений

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

@ -147,6 +147,14 @@ size_t sAudioIPCStackSize;
StaticAutoPtr<char> sBrandName;
StaticAutoPtr<char> sCubebBackendName;
StaticAutoPtr<char> sCubebOutputDeviceName;
#ifdef MOZ_WIDGET_ANDROID
// Counts the number of time a request for switching to global "communication
// mode" has been received. If this is > 0, global communication mode is to be
// enabled. If it is 0, the global communication mode is to be disabled.
// This allows to correctly track the global behaviour to adopt accross
// asynchronous GraphDriver changes, on Android.
int sInCommunicationCount = 0;
#endif
const char kBrandBundleURL[] = "chrome://branding/locale/brand.properties";
@ -311,7 +319,19 @@ void ForceSetCubebContext(cubeb* aCubebContext) {
void SetInCommunication(bool aInCommunication) {
#ifdef MOZ_WIDGET_ANDROID
java::GeckoAppShell::SetCommunicationAudioModeOn(aInCommunication);
StaticMutexAutoLock lock(sMutex);
if (aInCommunication) {
sInCommunicationCount++;
} else {
MOZ_ASSERT(sInCommunicationCount > 0);
sInCommunicationCount--;
}
if (sInCommunicationCount == 1) {
java::GeckoAppShell::SetCommunicationAudioModeOn(true);
} else if (sInCommunicationCount == 0) {
java::GeckoAppShell::SetCommunicationAudioModeOn(false);
}
#endif
}

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

@ -13,6 +13,8 @@
class AudioDeviceInfo;
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(cubeb_stream_prefs)
namespace mozilla {
namespace CubebUtils {

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

@ -495,6 +495,13 @@ AudioCallbackDriver::AudioCallbackDriver(MediaStreamGraphImpl* aGraphImpl,
audio::AudioNotificationReceiver::Register(this);
}
#endif
if (aAudioInputType == AudioInputType::Voice) {
LOG(LogLevel::Debug, ("VOICE."));
mInputDevicePreference = CUBEB_DEVICE_PREF_VOICE;
CubebUtils::SetInCommunication(true);
} else {
mInputDevicePreference = CUBEB_DEVICE_PREF_ALL;
}
}
AudioCallbackDriver::~AudioCallbackDriver() {
@ -505,6 +512,9 @@ AudioCallbackDriver::~AudioCallbackDriver() {
audio::AudioNotificationReceiver::Unregister(this);
}
#endif
if (mInputDevicePreference == CUBEB_DEVICE_PREF_VOICE) {
CubebUtils::SetInCommunication(false);
}
}
bool IsMacbookOrMacbookAir() {
@ -590,6 +600,9 @@ bool AudioCallbackDriver::Init() {
output.channels = mOutputChannels;
output.layout = CUBEB_LAYOUT_UNDEFINED;
output.prefs = CubebUtils::GetDefaultStreamPrefs();
if (mInputDevicePreference == CUBEB_DEVICE_PREF_VOICE) {
output.prefs |= static_cast<cubeb_stream_prefs>(CUBEB_STREAM_PREF_VOICE);
}
uint32_t latency_frames = CubebUtils::GetCubebMSGLatencyInFrames(&output);

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

@ -180,9 +180,14 @@ void MediaEngineWebRTC::EnumerateMicrophoneDevices(
if (!foundPreferredDevice) {
foundPreferredDevice = true;
} else {
// This is possible on windows, there is a default communication
// device, and a default device:
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1542739
#ifndef XP_WIN
MOZ_ASSERT(!foundPreferredDevice,
"Found more than one preferred audio input device"
"while enumerating");
#endif
}
#endif
aDevices->InsertElementAt(0, device);