Bug 1449178 - MediaEngineWebRTC now clears device indicies while updating before checking cubeb. r?padenot
Stop us potentially keeping a stale device list when updating if we can't get a
cubeb context.
MozReview-Commit-ID: H6GdeNXObWV
--- a/dom/media/webrtc/MediaEngineWebRTC.cpp
+++ b/dom/media/webrtc/MediaEngineWebRTC.cpp
@@ -39,34 +39,36 @@ bool AudioInputCubeb::mAnyInUse = false;
StaticMutex AudioInputCubeb::sMutex;
uint32_t AudioInputCubeb::sUserChannelCount = 0;
// AudioDeviceID is an annoying opaque value that's really a string
// pointer, and is freed when the cubeb_device_collection is destroyed
void AudioInputCubeb::UpdateDeviceList()
{
+ // We keep all the device names, but wipe the mappings and rebuild them.
+ // Do this first so that if cubeb has failed we've unmapped our devices
+ // before we early return. Otherwise we'd keep the old list.
+ for (auto& device_index : (*mDeviceIndexes)) {
+ device_index = -1; // unmapped
+ }
+
cubeb* cubebContext = CubebUtils::GetCubebContext();
if (!cubebContext) {
return;
}
cubeb_device_collection devices = { nullptr, 0 };
if (CUBEB_OK != cubeb_enumerate_devices(cubebContext,
CUBEB_DEVICE_TYPE_INPUT,
&devices)) {
return;
}
- for (auto& device_index : (*mDeviceIndexes)) {
- device_index = -1; // unmapped
- }
- // We keep all the device names, but wipe the mappings and rebuild them
-
// Calculate translation from existing mDevices to new devices. Note we
// never end up with less devices than before, since people have
// stashed indexes.
// For some reason the "fake" device for automation is marked as DISABLED,
// so white-list it.
mDefaultDevice = -1;
for (uint32_t i = 0; i < devices.count; i++) {
LOG(("Cubeb device %u: type 0x%x, state 0x%x, name %s, id %p",