1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #include "AudioDeviceInfo.h"
7 
8 NS_IMPL_ISUPPORTS(AudioDeviceInfo, nsIAudioDeviceInfo)
9 
10 using namespace mozilla;
11 using namespace mozilla::CubebUtils;
12 
AudioDeviceInfo(cubeb_device_info * aInfo)13 AudioDeviceInfo::AudioDeviceInfo(cubeb_device_info* aInfo)
14     : AudioDeviceInfo(aInfo->devid, NS_ConvertUTF8toUTF16(aInfo->friendly_name),
15                       NS_ConvertUTF8toUTF16(aInfo->group_id),
16                       NS_ConvertUTF8toUTF16(aInfo->vendor_name), aInfo->type,
17                       aInfo->state, aInfo->preferred, aInfo->format,
18                       aInfo->default_format, aInfo->max_channels,
19                       aInfo->default_rate, aInfo->max_rate, aInfo->min_rate,
20                       aInfo->latency_lo, aInfo->latency_hi) {}
21 
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)22 AudioDeviceInfo::AudioDeviceInfo(
23     AudioDeviceID aID, const nsAString& aName, const nsAString& aGroupId,
24     const nsAString& aVendor, uint16_t aType, uint16_t aState,
25     uint16_t aPreferred, uint16_t aSupportedFormat, uint16_t aDefaultFormat,
26     uint32_t aMaxChannels, uint32_t aDefaultRate, uint32_t aMaxRate,
27     uint32_t aMinRate, uint32_t aMaxLatency, uint32_t aMinLatency)
28     : mDeviceId(aID),
29       mName(aName),
30       mGroupId(aGroupId),
31       mVendor(aVendor),
32       mType(aType),
33       mState(aState),
34       mPreferred(aPreferred),
35       mSupportedFormat(aSupportedFormat),
36       mDefaultFormat(aDefaultFormat),
37       mMaxChannels(aMaxChannels),
38       mDefaultRate(aDefaultRate),
39       mMaxRate(aMaxRate),
40       mMinRate(aMinRate),
41       mMaxLatency(aMaxLatency),
42       mMinLatency(aMinLatency) {
43   MOZ_ASSERT(
44       mType == TYPE_UNKNOWN || mType == TYPE_INPUT || mType == TYPE_OUTPUT,
45       "Wrong type");
46   MOZ_ASSERT(mState == STATE_DISABLED || mState == STATE_UNPLUGGED ||
47                  mState == STATE_ENABLED,
48              "Wrong state");
49   MOZ_ASSERT(
50       mPreferred == PREF_NONE || mPreferred == PREF_ALL ||
51           mPreferred & (PREF_MULTIMEDIA | PREF_VOICE | PREF_NOTIFICATION),
52       "Wrong preferred value");
53   MOZ_ASSERT(mSupportedFormat & (FMT_S16LE | FMT_S16BE | FMT_F32LE | FMT_F32BE),
54              "Wrong supported format");
55   MOZ_ASSERT(mDefaultFormat == FMT_S16LE || mDefaultFormat == FMT_S16BE ||
56                  mDefaultFormat == FMT_F32LE || mDefaultFormat == FMT_F32BE,
57              "Wrong default format");
58 }
59 
DeviceID() const60 AudioDeviceID AudioDeviceInfo::DeviceID() const { return mDeviceId; }
Name() const61 const nsString& AudioDeviceInfo::Name() const { return mName; }
MaxChannels() const62 uint32_t AudioDeviceInfo::MaxChannels() const { return mMaxChannels; }
Type() const63 uint32_t AudioDeviceInfo::Type() const { return mType; }
State() const64 uint32_t AudioDeviceInfo::State() const { return mState; }
GroupID() const65 const nsString& AudioDeviceInfo::GroupID() const { return mGroupId; }
66 
Preferred() const67 bool AudioDeviceInfo::Preferred() const { return mPreferred; }
68 
69 /* readonly attribute DOMString name; */
70 NS_IMETHODIMP
GetName(nsAString & aName)71 AudioDeviceInfo::GetName(nsAString& aName) {
72   aName = mName;
73   return NS_OK;
74 }
75 
76 /* readonly attribute DOMString groupId; */
77 NS_IMETHODIMP
GetGroupId(nsAString & aGroupId)78 AudioDeviceInfo::GetGroupId(nsAString& aGroupId) {
79   aGroupId = mGroupId;
80   return NS_OK;
81 }
82 
83 /* readonly attribute DOMString vendor; */
84 NS_IMETHODIMP
GetVendor(nsAString & aVendor)85 AudioDeviceInfo::GetVendor(nsAString& aVendor) {
86   aVendor = mVendor;
87   return NS_OK;
88 }
89 
90 /* readonly attribute unsigned short type; */
91 NS_IMETHODIMP
GetType(uint16_t * aType)92 AudioDeviceInfo::GetType(uint16_t* aType) {
93   *aType = mType;
94   return NS_OK;
95 }
96 
97 /* readonly attribute unsigned short state; */
98 NS_IMETHODIMP
GetState(uint16_t * aState)99 AudioDeviceInfo::GetState(uint16_t* aState) {
100   *aState = mState;
101   return NS_OK;
102 }
103 
104 /* readonly attribute unsigned short preferred; */
105 NS_IMETHODIMP
GetPreferred(uint16_t * aPreferred)106 AudioDeviceInfo::GetPreferred(uint16_t* aPreferred) {
107   *aPreferred = mPreferred;
108   return NS_OK;
109 }
110 
111 /* readonly attribute unsigned short supportedFormat; */
112 NS_IMETHODIMP
GetSupportedFormat(uint16_t * aSupportedFormat)113 AudioDeviceInfo::GetSupportedFormat(uint16_t* aSupportedFormat) {
114   *aSupportedFormat = mSupportedFormat;
115   return NS_OK;
116 }
117 
118 /* readonly attribute unsigned short defaultFormat; */
119 NS_IMETHODIMP
GetDefaultFormat(uint16_t * aDefaultFormat)120 AudioDeviceInfo::GetDefaultFormat(uint16_t* aDefaultFormat) {
121   *aDefaultFormat = mDefaultFormat;
122   return NS_OK;
123 }
124 
125 /* readonly attribute unsigned long maxChannels; */
126 NS_IMETHODIMP
GetMaxChannels(uint32_t * aMaxChannels)127 AudioDeviceInfo::GetMaxChannels(uint32_t* aMaxChannels) {
128   *aMaxChannels = mMaxChannels;
129   return NS_OK;
130 }
131 
132 /* readonly attribute unsigned long defaultRate; */
133 NS_IMETHODIMP
GetDefaultRate(uint32_t * aDefaultRate)134 AudioDeviceInfo::GetDefaultRate(uint32_t* aDefaultRate) {
135   *aDefaultRate = mDefaultRate;
136   return NS_OK;
137 }
138 
139 /* readonly attribute unsigned long maxRate; */
140 NS_IMETHODIMP
GetMaxRate(uint32_t * aMaxRate)141 AudioDeviceInfo::GetMaxRate(uint32_t* aMaxRate) {
142   *aMaxRate = mMaxRate;
143   return NS_OK;
144 }
145 
146 /* readonly attribute unsigned long minRate; */
147 NS_IMETHODIMP
GetMinRate(uint32_t * aMinRate)148 AudioDeviceInfo::GetMinRate(uint32_t* aMinRate) {
149   *aMinRate = mMinRate;
150   return NS_OK;
151 }
152 
153 /* readonly attribute unsigned long maxLatency; */
154 NS_IMETHODIMP
GetMaxLatency(uint32_t * aMaxLatency)155 AudioDeviceInfo::GetMaxLatency(uint32_t* aMaxLatency) {
156   *aMaxLatency = mMaxLatency;
157   return NS_OK;
158 }
159 
160 /* readonly attribute unsigned long minLatency; */
161 NS_IMETHODIMP
GetMinLatency(uint32_t * aMinLatency)162 AudioDeviceInfo::GetMinLatency(uint32_t* aMinLatency) {
163   *aMinLatency = mMinLatency;
164   return NS_OK;
165 }
166