Bug 1404977 - Part 17 - Re-implement the workaround for the lack of input device enumeration on Android. r=pehrsons

MozReview-Commit-ID: 5EiQ6a3OaIR

--HG--
extra : rebase_source : d39706b5c09438f55ef1d26b3e0fb127ac05cfa6
This commit is contained in:
Paul Adenot 2018-07-04 18:00:57 +02:00
parent c270650bfe
commit fc57da928f
3 changed files with 52 additions and 9 deletions

View File

@ -130,6 +130,9 @@ public:
int EnumerateDevices(cubeb_device_type aType,
cubeb_device_collection* collection)
{
#ifdef ANDROID
EXPECT_TRUE(false) << "This is not to be called on Android.";
#endif
size_t count = 0;
if (aType & CUBEB_DEVICE_TYPE_INPUT) {
count += mInputDevices.Length();
@ -514,6 +517,7 @@ TestEnumeration(MockCubeb* aMock,
}
}
#ifndef ANDROID
TEST(CubebDeviceEnumerator, EnumerateSimple)
{
// It looks like we're leaking this object, but in fact it will be freed by
@ -552,3 +556,19 @@ TEST(CubebDeviceEnumerator, EnumerateSimple)
}
}
}
#else // building for Android, which has no device enumeration support
TEST(CubebDeviceEnumerator, EnumerateAndroid)
{
MockCubeb* mock = new MockCubeb();
mozilla::CubebUtils::ForceSetCubebContext(mock->AsCubebContext());
CubebDeviceEnumerator enumerator;
nsTArray<RefPtr<AudioDeviceInfo>> inputDevices;
enumerator.EnumerateAudioInputDevices(inputDevices);
EXPECT_EQ(inputDevices.Length(), 1u) << "Android always exposes a single input device.";
EXPECT_EQ(inputDevices[0]->MaxChannels(), 1u) << "With a single channel.";
EXPECT_EQ(inputDevices[0]->DeviceID(), nullptr) << "It's always the default device.";
EXPECT_TRUE(inputDevices[0]->Preferred()) << "it's always the prefered device.";
}
#endif

View File

@ -194,7 +194,9 @@ MediaEngineWebRTC::EnumerateMicrophoneDevices(uint64_t aWindowId,
DebugOnly<bool> foundPreferredDevice = false;
for (uint32_t i = 0; i < devices.Length(); i++) {
#ifndef ANDROID
MOZ_ASSERT(devices[i]->DeviceID());
#endif
LOG(("Cubeb device %u: type 0x%x, state 0x%x, name %s, id %p",
i,
devices[i]->Type(),
@ -387,6 +389,32 @@ CubebDeviceEnumerator::~CubebDeviceEnumerator()
void
CubebDeviceEnumerator::EnumerateAudioInputDevices(nsTArray<RefPtr<AudioDeviceInfo>>& aOutDevices)
{
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) {
@ -400,8 +428,8 @@ CubebDeviceEnumerator::EnumerateAudioInputDevices(nsTArray<RefPtr<AudioDeviceInf
CubebUtils::GetDeviceCollection(mDevices, CubebUtils::Input);
}
aOutDevices.Clear();
aOutDevices.AppendElements(mDevices);
#endif
}
already_AddRefed<AudioDeviceInfo>

View File

@ -52,7 +52,7 @@ LogModule* AudioLogModule() {
}
void
WebRTCAudioDataListener::NotifyOutputData(MediaStreamGraph* aGraph,
WebRTCAudioDataListener::NotifyOutputData(MediaStreamGraphImpl* aGraph,
AudioDataValue* aBuffer,
size_t aFrames,
TrackRate aRate,
@ -145,7 +145,9 @@ MediaEngineWebRTCMicrophoneSource::MediaEngineWebRTCMicrophoneSource(
, mSkipProcessing(false)
, mInputDownmixBuffer(MAX_SAMPLING_FREQ * MAX_CHANNELS / 100)
{
#ifndef ANDROID
MOZ_ASSERT(mDeviceInfo->DeviceID());
#endif
// We'll init lazily as needed
mSettings->mEchoCancellation.Construct(0);
@ -1302,13 +1304,6 @@ MediaEngineWebRTCMicrophoneSource::Shutdown()
{
AssertIsOnOwningThread();
if (mListener) {
// breaks a cycle, since the WebRTCAudioDataListener has a RefPtr to us
mListener->Shutdown();
// Don't release the webrtc.org pointers yet until the Listener is (async) shutdown
mListener = nullptr;
}
if (mState == kStarted) {
for (const Allocation& allocation : mAllocations) {
if (allocation.mEnabled) {