Bug 1152401 - Augment AudioDeviceInfo with a cubeb device id. r=padenot
authorPaul Adenot <paul@paul.cx>
Wed, 18 Jul 2018 10:38:34 +0200
changeset 427383 908a5b574b39ecdacbf5a9017202a9fd38c9b3db
parent 427382 ffa412239e2aea3dd8e041569addf611410bcde8
child 427384 ecb39ca5568bc5756fce258896d51a2b27b0f2eb
push id34303
push usertoros@mozilla.com
push dateFri, 20 Jul 2018 09:55:38 +0000
treeherdermozilla-central@47f713574cb2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1152401
milestone63.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 1152401 - Augment AudioDeviceInfo with a cubeb device id. r=padenot MozReview-Commit-ID: 7QOcM5ITrxv
dom/media/AudioDeviceInfo.cpp
dom/media/AudioDeviceInfo.h
dom/media/CubebUtils.cpp
dom/media/CubebUtils.h
dom/media/webrtc/MediaEngineWebRTC.h
--- a/dom/media/AudioDeviceInfo.cpp
+++ b/dom/media/AudioDeviceInfo.cpp
@@ -2,31 +2,56 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "AudioDeviceInfo.h"
 
 NS_IMPL_ISUPPORTS(AudioDeviceInfo, nsIAudioDeviceInfo)
 
-AudioDeviceInfo::AudioDeviceInfo(const nsAString& aName,
+using namespace mozilla;
+using namespace mozilla::CubebUtils;
+
+AudioDeviceInfo::AudioDeviceInfo(cubeb_device_info* aInfo)
+:AudioDeviceInfo(aInfo->devid,
+                 NS_ConvertUTF8toUTF16(aInfo->friendly_name),
+                 NS_ConvertUTF8toUTF16(aInfo->group_id),
+                 NS_ConvertUTF8toUTF16(aInfo->vendor_name),
+                 aInfo->type,
+                 aInfo->state,
+                 aInfo->preferred,
+                 aInfo->format,
+                 aInfo->default_format,
+                 aInfo->max_channels,
+                 aInfo->default_rate,
+                 aInfo->max_rate,
+                 aInfo->min_rate,
+                 aInfo->latency_lo,
+                 aInfo->latency_hi)
+{
+}
+
+
+AudioDeviceInfo::AudioDeviceInfo(AudioDeviceID aID,
+                                 const nsAString& aName,
                                  const nsAString& aGroupId,
                                  const nsAString& aVendor,
                                  uint16_t aType,
                                  uint16_t aState,
                                  uint16_t aPreferred,
                                  uint16_t aSupportedFormat,
                                  uint16_t aDefaultFormat,
                                  uint32_t aMaxChannels,
                                  uint32_t aDefaultRate,
                                  uint32_t aMaxRate,
                                  uint32_t aMinRate,
                                  uint32_t aMaxLatency,
-				 uint32_t aMinLatency)
-  : mName(aName)
+                                 uint32_t aMinLatency)
+  : mDeviceId(aID)
+  , mName(aName)
   , mGroupId(aGroupId)
   , mVendor(aVendor)
   , mType(aType)
   , mState(aState)
   , mPreferred(aPreferred)
   , mSupportedFormat(aSupportedFormat)
   , mDefaultFormat(aDefaultFormat)
   , mMaxChannels(aMaxChannels)
@@ -49,16 +74,42 @@ AudioDeviceInfo::AudioDeviceInfo(const n
   MOZ_ASSERT(mSupportedFormat & (FMT_S16LE | FMT_S16BE | FMT_F32LE | FMT_F32BE),
              "Wrong supported format");
   MOZ_ASSERT(mDefaultFormat == FMT_S16LE ||
              mDefaultFormat == FMT_S16BE ||
              mDefaultFormat == FMT_F32LE ||
              mDefaultFormat == FMT_F32BE, "Wrong default format");
 }
 
+Maybe<AudioDeviceID>
+AudioDeviceInfo::GetDeviceID()
+{
+  if (mDeviceId) {
+    return Some(mDeviceId);
+  }
+  return Nothing();
+}
+
+const nsString& AudioDeviceInfo::FriendlyName()
+{
+  return mName;
+}
+uint32_t AudioDeviceInfo::MaxChannels()
+{
+  return mMaxChannels;
+}
+uint32_t AudioDeviceInfo::Type()
+{
+  return mType;
+}
+uint32_t AudioDeviceInfo::State()
+{
+  return mState;
+}
+
 /* readonly attribute DOMString name; */
 NS_IMETHODIMP
 AudioDeviceInfo::GetName(nsAString& aName)
 {
   aName = mName;
   return NS_OK;
 }
 
--- a/dom/media/AudioDeviceInfo.h
+++ b/dom/media/AudioDeviceInfo.h
@@ -2,52 +2,66 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_AudioDeviceInfo_H
 #define MOZILLA_AudioDeviceInfo_H
 
 #include "nsIAudioDeviceInfo.h"
+#include "CubebUtils.h"
 #include "nsString.h"
+#include "mozilla/Maybe.h"
 
 // This is mapped to the cubeb_device_info.
 class AudioDeviceInfo final : public nsIAudioDeviceInfo
 {
 public:
-  NS_DECL_ISUPPORTS
+  NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIAUDIODEVICEINFO
 
-  explicit AudioDeviceInfo(const nsAString& aName,
-                           const nsAString& aGroupId,
-                           const nsAString& aVendor,
-                           uint16_t aType,
-                           uint16_t aState,
-                           uint16_t aPreferred,
-                           uint16_t aSupportedFormat,
-                           uint16_t aDefaultFormat,
-                           uint32_t aMaxChannels,
-                           uint32_t aDefaultRate,
-                           uint32_t aMaxRate,
-                           uint32_t aMinRate,
-                           uint32_t aMaxLatency,
-                           uint32_t aMinLatency);
+  using AudioDeviceID = mozilla::CubebUtils::AudioDeviceID;
 
+  AudioDeviceInfo(const AudioDeviceID aID,
+                  const nsAString& aName,
+                  const nsAString& aGroupId,
+                  const nsAString& aVendor,
+                  uint16_t aType,
+                  uint16_t aState,
+                  uint16_t aPreferred,
+                  uint16_t aSupportedFormat,
+                  uint16_t aDefaultFormat,
+                  uint32_t aMaxChannels,
+                  uint32_t aDefaultRate,
+                  uint32_t aMaxRate,
+                  uint32_t aMinRate,
+                  uint32_t aMaxLatency,
+                  uint32_t aMinLatency);
+
+  explicit AudioDeviceInfo(cubeb_device_info* aInfo);
+  // It is possible to not know the device identifier here. It depends on which
+  // ctor this instance has been constructed with.
+  mozilla::Maybe<AudioDeviceID> GetDeviceID();
+  const nsString& FriendlyName();
+  uint32_t MaxChannels();
+  uint32_t Type();
+  uint32_t State();
 private:
   virtual ~AudioDeviceInfo() = default;
 
-  nsString mName;
-  nsString mGroupId;
-  nsString mVendor;
-  uint16_t mType;
-  uint16_t mState;
-  uint16_t mPreferred;
-  uint16_t mSupportedFormat;
-  uint16_t mDefaultFormat;
-  uint32_t mMaxChannels;
-  uint32_t mDefaultRate;
-  uint32_t mMaxRate;
-  uint32_t mMinRate;
-  uint32_t mMaxLatency;
-  uint32_t mMinLatency;
+  const AudioDeviceID mDeviceId;
+  const nsString mName;
+  const nsString mGroupId;
+  const nsString mVendor;
+  const uint16_t mType;
+  const uint16_t mState;
+  const uint16_t mPreferred;
+  const uint16_t mSupportedFormat;
+  const uint16_t mDefaultFormat;
+  const uint32_t mMaxChannels;
+  const uint32_t mDefaultRate;
+  const uint32_t mMaxRate;
+  const uint32_t mMinRate;
+  const uint32_t mMaxLatency;
+  const uint32_t mMinLatency;
 };
 
 #endif // MOZILLA_AudioDeviceInfo_H
--- a/dom/media/CubebUtils.cpp
+++ b/dom/media/CubebUtils.cpp
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "CubebUtils.h"
 
 #include "MediaInfo.h"
 #include "mozilla/AbstractThread.h"
 #include "mozilla/dom/ContentChild.h"
+#include "mozilla/dom/AudioDeviceInfo.h"
 #include "mozilla/ipc/FileDescriptor.h"
 #include "mozilla/Logging.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include "mozilla/Sprintf.h"
 #include "mozilla/StaticMutex.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/Telemetry.h"
@@ -679,17 +680,18 @@ void GetDeviceCollection(nsTArray<RefPtr
     cubeb_device_collection collection = { nullptr, 0 };
     if (cubeb_enumerate_devices(context,
                                 aSide == Input ? CUBEB_DEVICE_TYPE_INPUT :
                                                  CUBEB_DEVICE_TYPE_OUTPUT,
                                 &collection) == CUBEB_OK) {
       for (unsigned int i = 0; i < collection.count; ++i) {
         auto device = collection.device[i];
         RefPtr<AudioDeviceInfo> info =
-          new AudioDeviceInfo(NS_ConvertUTF8toUTF16(device.friendly_name),
+          new AudioDeviceInfo(device.devid,
+                              NS_ConvertUTF8toUTF16(device.friendly_name),
                               NS_ConvertUTF8toUTF16(device.group_id),
                               NS_ConvertUTF8toUTF16(device.vendor_name),
                               ConvertCubebType(device.type),
                               ConvertCubebState(device.state),
                               ConvertCubebPreferred(device.preferred),
                               ConvertCubebFormat(device.format),
                               ConvertCubebFormat(device.default_format),
                               device.max_channels,
--- a/dom/media/CubebUtils.h
+++ b/dom/media/CubebUtils.h
@@ -3,19 +3,22 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #if !defined(CubebUtils_h_)
 #define CubebUtils_h_
 
 #include "cubeb/cubeb.h"
-#include "mozilla/dom/AudioDeviceInfo.h"
+#include "nsString.h"
+#include "mozilla/RefPtr.h"
 #include "mozilla/Maybe.h"
 
+class AudioDeviceInfo;
+
 namespace mozilla {
 namespace CubebUtils {
 
 typedef cubeb_devid AudioDeviceID;
 
 // Initialize Audio Library. Some Audio backends require initializing the
 // library before using it.
 void InitLibrary();
--- a/dom/media/webrtc/MediaEngineWebRTC.h
+++ b/dom/media/webrtc/MediaEngineWebRTC.h
@@ -2,16 +2,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MEDIAENGINEWEBRTC_H_
 #define MEDIAENGINEWEBRTC_H_
 
 #include "AudioPacketizer.h"
 #include "AudioSegment.h"
+#include "AudioDeviceInfo.h"
 #include "CamerasChild.h"
 #include "cubeb/cubeb.h"
 #include "CubebUtils.h"
 #include "DOMMediaStream.h"
 #include "ipc/IPCMessageUtils.h"
 #include "MediaEngine.h"
 #include "MediaEnginePrefs.h"
 #include "MediaEngineSource.h"