Bug 1534313 - Remove direct calls to GetDeviceCollection method. r=padenot
☠☠ backed out by 4f9968338e4e ☠ ☠
authorAlex Chronopoulos <achronop@gmail.com>
Thu, 14 Mar 2019 16:31:48 +0000
changeset 464787 fc232edfe6e8a4756fcb1661e76a52ff410a0c56
parent 464786 eae4a9ff0b9b4236d3de5614e1231047478cd9f2
child 464788 fe17244230e8248cf9cbd64cce03317d3c401d20
push id35727
push userdvarga@mozilla.com
push dateTue, 19 Mar 2019 09:48:59 +0000
treeherdermozilla-central@70baa37ae1eb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1534313
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1534313 - Remove direct calls to GetDeviceCollection method. r=padenot Differential Revision: https://phabricator.services.mozilla.com/D22988
dom/base/nsDOMWindowUtils.cpp
dom/media/GraphDriver.cpp
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -23,17 +23,17 @@
 #include "mozilla/dom/Touch.h"
 #include "mozilla/PendingAnimationTracker.h"
 #include "nsIObjectLoadingContent.h"
 #include "nsFrame.h"
 #include "mozilla/layers/ShadowLayers.h"
 #include "mozilla/layers/APZCCallbackHelper.h"
 #include "ClientLayerManager.h"
 #include "nsQueryObject.h"
-#include "CubebUtils.h"
+#include "CubebDeviceEnumerator.h"
 
 #include "nsIScrollableFrame.h"
 
 #include "nsContentUtils.h"
 
 #include "nsIFrame.h"
 #include "nsIWidget.h"
 #include "nsCharsetSource.h"
@@ -2144,20 +2144,24 @@ nsDOMWindowUtils::AudioDevices(uint16_t 
   NS_ENSURE_ARG((aSide == AUDIO_INPUT) || (aSide == AUDIO_OUTPUT));
   *aDevices = nullptr;
 
   nsresult rv = NS_OK;
   nsCOMPtr<nsIMutableArray> devices =
       do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
+  RefPtr<CubebDeviceEnumerator> enumerator = Enumerator::GetInstance();
   nsTArray<RefPtr<AudioDeviceInfo>> collection;
-  CubebUtils::GetDeviceCollection(collection, aSide == AUDIO_INPUT
-                                                  ? CubebUtils::Side::Input
-                                                  : CubebUtils::Side::Output);
+  if (aSide == AUDIO_INPUT) {
+    enumerator->EnumerateAudioInputDevices(collection);
+  } else {
+    enumerator->EnumerateAudioOutputDevices(collection);
+  }
+
   for (auto device : collection) {
     devices->AppendElement(device);
   }
 
   devices.forget(aDevices);
 
   return NS_OK;
 }
--- a/dom/media/GraphDriver.cpp
+++ b/dom/media/GraphDriver.cpp
@@ -6,17 +6,17 @@
 
 #include <MediaStreamGraphImpl.h>
 #include "mozilla/dom/AudioContext.h"
 #include "mozilla/dom/AudioDeviceInfo.h"
 #include "mozilla/dom/WorkletThread.h"
 #include "mozilla/SharedThreadPool.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "mozilla/Unused.h"
-#include "CubebUtils.h"
+#include "CubebDeviceEnumerator.h"
 #include "Tracing.h"
 
 #ifdef MOZ_WEBRTC
 #  include "webrtc/MediaEngineWebRTC.h"
 #endif
 
 #ifdef XP_MACOSX
 #  include <sys/sysctl.h>
@@ -573,25 +573,21 @@ bool AudioCallbackDriver::Init() {
     FallbackToSystemClockDriver();
     return true;
   }
 
   CubebUtils::AudioDeviceID forcedOutputDeviceId = nullptr;
 
   char* forcedOutputDeviceName = CubebUtils::GetForcedOutputDevice();
   if (forcedOutputDeviceName) {
-    nsTArray<RefPtr<AudioDeviceInfo>> deviceInfos;
-    GetDeviceCollection(deviceInfos, CubebUtils::Output);
-    for (const auto& device : deviceInfos) {
-      const nsString& name = device->Name();
-      if (name.Equals(NS_ConvertUTF8toUTF16(forcedOutputDeviceName))) {
-        if (device->DeviceID()) {
-          forcedOutputDeviceId = device->DeviceID();
-        }
-      }
+    RefPtr<CubebDeviceEnumerator> enumerator = Enumerator::GetInstance();
+    RefPtr<AudioDeviceInfo> device = enumerator->DeviceInfoFromName(
+        NS_ConvertUTF8toUTF16(forcedOutputDeviceName), EnumeratorSide::OUTPUT);
+    if (device->DeviceID()) {
+      forcedOutputDeviceId = device->DeviceID();
     }
   }
 
   mBuffer = AudioCallbackBufferWrapper<AudioDataValue>(mOutputChannels);
   mScratchBuffer =
       SpillBuffer<AudioDataValue, WEBAUDIO_BLOCK_SIZE * 2>(mOutputChannels);
 
   output.channels = mOutputChannels;