Bug 1481957 - Make input device enumeration for Android similar to other platforms when cubeb is disabled. r=padenot

In the case that cubeb is disabled we do not need to offer the dummy device on android because will leave gUM request thinking that everything is good, which will create other side effects. Also the special handling for android increases the complexity.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alex Chronopoulos 2018-08-13 08:25:38 +00:00
parent f0ee1746ef
commit 0a6ae381d4
3 changed files with 34 additions and 44 deletions

View File

@ -572,3 +572,13 @@ TEST(CubebDeviceEnumerator, EnumerateAndroid)
EXPECT_TRUE(inputDevices[0]->Preferred()) << "it's always the prefered device.";
}
#endif
TEST(CubebDeviceEnumerator, ForceNullCubebContext)
{
mozilla::CubebUtils::ForceSetCubebContext(nullptr);
CubebDeviceEnumerator enumerator;
nsTArray<RefPtr<AudioDeviceInfo>> inputDevices;
enumerator.EnumerateAudioInputDevices(inputDevices);
EXPECT_EQ(inputDevices.Length(), 0u) << "Enumeration must fail device list must be empty.";
}

View File

@ -20,34 +20,16 @@
await pushPrefs(["media.cubeb.force_null_context", true],
["media.navigator.streams.fake", false]);
// Android has its own codepath which means it works even when cubeb is
// disabled. For examples see MediaEngineWebRTC::GetNumOfRecordingDevices and
// MediaEngineWebRTC::GetRecordingDeviceName.
let isAndroid = navigator.appVersion.includes("Android");
// We're on android we expect to get an audio stream, create an elem for it
let testAudio = createMediaElement('audio', 'testAudio');
// Request audio only, to avoid cams
let constraints = {audio: true, video: false};
let stream;
try {
stream = await getUserMedia(constraints);
} catch (e) {
if (isAndroid) {
ok(false, `getUserMedia expected to succeed on android, even with null cubeb context, but got ${e}`);
return;
}
// !isAndroid
// We've got no audio backend, so we expect gUM to fail.
ok(e.name == "NotFoundError", "Expected NotFoundError due to no audio tracks!");
return;
}
if (isAndroid) {
ok(stream, "getUserMedia expected to return a stream on Android even when cubeb context null!");
let playback = new LocalMediaStreamPlayback(testAudio, stream);
return playback.playMedia(false);
}
// !isAndroid
// If we're not on android we should not have gotten a stream without a cubeb context!
ok(false, "getUserMedia not expected to succeed when cubeb is disabled, but it did!");
});

View File

@ -391,45 +391,43 @@ CubebDeviceEnumerator::EnumerateAudioInputDevices(nsTArray<RefPtr<AudioDeviceInf
{
aOutDevices.Clear();
#ifdef ANDROID
// Bug 1473346: enumerating devices is not supported on Android in cubeb,
// simply state that there is a single mic, that it is the default, and has a
// single channel. All the other values are made up and are not to be used.
RefPtr<AudioDeviceInfo> info = new AudioDeviceInfo(nullptr,
NS_ConvertUTF8toUTF16(""),
NS_ConvertUTF8toUTF16(""),
NS_ConvertUTF8toUTF16(""),
CUBEB_DEVICE_TYPE_INPUT,
CUBEB_DEVICE_STATE_ENABLED,
CUBEB_DEVICE_PREF_ALL,
CUBEB_DEVICE_FMT_ALL,
CUBEB_DEVICE_FMT_S16NE,
1,
44100,
44100,
41000,
410,
128);
if (mDevices.IsEmpty()) {
mDevices.AppendElement(info);
}
aOutDevices.AppendElements(mDevices);
#else
cubeb* context = GetCubebContext();
if (!context) {
return;
}
MutexAutoLock lock(mMutex);
#ifdef ANDROID
if (mDevices.IsEmpty()) {
// Bug 1473346: enumerating devices is not supported on Android in cubeb,
// simply state that there is a single mic, that it is the default, and has a
// single channel. All the other values are made up and are not to be used.
RefPtr<AudioDeviceInfo> info = new AudioDeviceInfo(nullptr,
NS_ConvertUTF8toUTF16(""),
NS_ConvertUTF8toUTF16(""),
NS_ConvertUTF8toUTF16(""),
CUBEB_DEVICE_TYPE_INPUT,
CUBEB_DEVICE_STATE_ENABLED,
CUBEB_DEVICE_PREF_ALL,
CUBEB_DEVICE_FMT_ALL,
CUBEB_DEVICE_FMT_S16NE,
1,
44100,
44100,
41000,
410,
128);
mDevices.AppendElement(info);
}
#else
if (mDevices.IsEmpty() || mManualInvalidation) {
mDevices.Clear();
CubebUtils::GetDeviceCollection(mDevices, CubebUtils::Input);
}
#endif
aOutDevices.AppendElements(mDevices);
#endif
}
already_AddRefed<AudioDeviceInfo>