Bug 1449178 - MediaEngineWebRTC now clears device indicies while updating before checking cubeb. r?padenot draft
authorBryce Van Dyk <bvandyk@mozilla.com>
Mon, 26 Mar 2018 14:14:47 -0400
changeset 773158 83f4b6bf946e4f0b6d04fcdcd4492baeb535ac95
parent 772574 7b9da7139d94951431a148dcaf8a388640c91b27
push id104151
push userbvandyk@mozilla.com
push dateTue, 27 Mar 2018 14:06:53 +0000
reviewerspadenot
bugs1449178
milestone61.0a1
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
dom/media/webrtc/MediaEngineWebRTC.cpp
--- 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",