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/. */
6 #include "AudioDeviceInfo.h"
8 NS_IMPL_ISUPPORTS(AudioDeviceInfo
, nsIAudioDeviceInfo
)
10 using namespace mozilla
;
11 using namespace mozilla::CubebUtils
;
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
) {}
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
)
34 mPreferred(aPreferred
),
35 mSupportedFormat(aSupportedFormat
),
36 mDefaultFormat(aDefaultFormat
),
37 mMaxChannels(aMaxChannels
),
38 mDefaultRate(aDefaultRate
),
41 mMaxLatency(aMaxLatency
),
42 mMinLatency(aMinLatency
) {
44 mType
== TYPE_UNKNOWN
|| mType
== TYPE_INPUT
|| mType
== TYPE_OUTPUT
,
46 MOZ_ASSERT(mState
== STATE_DISABLED
|| mState
== STATE_UNPLUGGED
||
47 mState
== STATE_ENABLED
,
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");
60 AudioDeviceID
AudioDeviceInfo::DeviceID() const { return mDeviceId
; }
61 const nsString
& AudioDeviceInfo::Name() const { return mName
; }
62 uint32_t AudioDeviceInfo::MaxChannels() const { return mMaxChannels
; }
63 uint32_t AudioDeviceInfo::Type() const { return mType
; }
64 uint32_t AudioDeviceInfo::State() const { return mState
; }
65 const nsString
& AudioDeviceInfo::GroupID() const { return mGroupId
; }
67 bool AudioDeviceInfo::Preferred() const { return mPreferred
; }
69 /* readonly attribute DOMString name; */
71 AudioDeviceInfo::GetName(nsAString
& aName
) {
76 /* readonly attribute DOMString groupId; */
78 AudioDeviceInfo::GetGroupId(nsAString
& aGroupId
) {
83 /* readonly attribute DOMString vendor; */
85 AudioDeviceInfo::GetVendor(nsAString
& aVendor
) {
90 /* readonly attribute unsigned short type; */
92 AudioDeviceInfo::GetType(uint16_t* aType
) {
97 /* readonly attribute unsigned short state; */
99 AudioDeviceInfo::GetState(uint16_t* aState
) {
104 /* readonly attribute unsigned short preferred; */
106 AudioDeviceInfo::GetPreferred(uint16_t* aPreferred
) {
107 *aPreferred
= mPreferred
;
111 /* readonly attribute unsigned short supportedFormat; */
113 AudioDeviceInfo::GetSupportedFormat(uint16_t* aSupportedFormat
) {
114 *aSupportedFormat
= mSupportedFormat
;
118 /* readonly attribute unsigned short defaultFormat; */
120 AudioDeviceInfo::GetDefaultFormat(uint16_t* aDefaultFormat
) {
121 *aDefaultFormat
= mDefaultFormat
;
125 /* readonly attribute unsigned long maxChannels; */
127 AudioDeviceInfo::GetMaxChannels(uint32_t* aMaxChannels
) {
128 *aMaxChannels
= mMaxChannels
;
132 /* readonly attribute unsigned long defaultRate; */
134 AudioDeviceInfo::GetDefaultRate(uint32_t* aDefaultRate
) {
135 *aDefaultRate
= mDefaultRate
;
139 /* readonly attribute unsigned long maxRate; */
141 AudioDeviceInfo::GetMaxRate(uint32_t* aMaxRate
) {
142 *aMaxRate
= mMaxRate
;
146 /* readonly attribute unsigned long minRate; */
148 AudioDeviceInfo::GetMinRate(uint32_t* aMinRate
) {
149 *aMinRate
= mMinRate
;
153 /* readonly attribute unsigned long maxLatency; */
155 AudioDeviceInfo::GetMaxLatency(uint32_t* aMaxLatency
) {
156 *aMaxLatency
= mMaxLatency
;
160 /* readonly attribute unsigned long minLatency; */
162 AudioDeviceInfo::GetMinLatency(uint32_t* aMinLatency
) {
163 *aMinLatency
= mMinLatency
;