Ring Daemon
16.0.0
Loading...
Searching...
No Matches
audiodevice.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2004-2025 Savoir-faire Linux Inc.
3
*
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16
*/
17
18
#include "
audiodevice.h
"
19
20
#if !TARGET_OS_IPHONE
21
22
namespace
jami
{
23
24
AudioDevice::AudioDevice
(
AudioDeviceID
devid
,
bool
isInput
)
25
{
26
init
(
devid
,
isInput
);
27
}
28
29
void
30
AudioDevice::init
(
AudioDeviceID
devid
,
bool
isInput
)
31
{
32
id_
=
devid
;
33
isInput_
=
isInput
;
34
if
(
id_
==
kAudioDeviceUnknown
)
35
return
;
36
37
name_
= getName();
38
channels_
= countChannels();
39
40
UInt32
propsize
=
sizeof
(
Float32
);
41
42
AudioObjectPropertyScope
theScope
=
isInput_
?
kAudioDevicePropertyScopeInput
43
:
kAudioDevicePropertyScopeOutput
;
44
45
AudioObjectPropertyAddress
theAddress
= {
kAudioDevicePropertySafetyOffset
,
46
theScope
,
47
0};
// channel
48
49
__Verify_noErr
(
AudioObjectGetPropertyData
(
id_
, &
theAddress
, 0,
NULL
, &
propsize
, &
safetyOffset_
));
50
51
propsize
=
sizeof
(
UInt32
);
52
theAddress
.mSelector =
kAudioDevicePropertyBufferFrameSize
;
53
54
__Verify_noErr
(
55
AudioObjectGetPropertyData
(
id_
, &
theAddress
, 0,
NULL
, &
propsize
, &
bufferSizeFrames_
));
56
57
propsize
=
sizeof
(
AudioStreamBasicDescription
);
58
theAddress
.mSelector =
kAudioDevicePropertyStreamFormat
;
59
60
__Verify_noErr
(
AudioObjectGetPropertyData
(
id_
, &
theAddress
, 0,
NULL
, &
propsize
, &
format_
));
61
}
62
63
bool
64
AudioDevice::valid
()
const
65
{
66
return
id_
!=
kAudioDeviceUnknown
;
67
}
68
69
void
70
AudioDevice::setBufferSize
(
UInt32
size)
71
{
72
UInt32
propsize
=
sizeof
(
UInt32
);
73
74
AudioObjectPropertyScope
theScope
=
isInput_
?
kAudioDevicePropertyScopeInput
75
:
kAudioDevicePropertyScopeOutput
;
76
77
AudioObjectPropertyAddress
theAddress
= {
kAudioDevicePropertyBufferFrameSize
,
78
theScope
,
79
0};
// channel
80
81
__Verify_noErr
(
AudioObjectSetPropertyData
(
id_
, &
theAddress
, 0,
NULL
,
propsize
, &size));
82
83
__Verify_noErr
(
84
AudioObjectGetPropertyData
(
id_
, &
theAddress
, 0,
NULL
, &
propsize
, &
bufferSizeFrames_
));
85
}
86
87
int
88
AudioDevice::countChannels()
const
89
{
90
OSStatus
err
;
91
UInt32
propSize
;
92
int
result = 0;
93
94
AudioObjectPropertyScope
theScope
=
isInput_
?
kAudioDevicePropertyScopeInput
95
:
kAudioDevicePropertyScopeOutput
;
96
97
AudioObjectPropertyAddress
theAddress
= {
kAudioDevicePropertyStreamConfiguration
,
98
theScope
,
99
0};
// channel
100
101
err
=
AudioObjectGetPropertyDataSize
(
id_
, &
theAddress
, 0,
NULL
, &
propSize
);
102
if
(
err
)
103
return
0;
104
105
AudioBufferList
*
buflist
= (
AudioBufferList
*)
malloc
(
propSize
);
106
err
=
AudioObjectGetPropertyData
(
id_
, &
theAddress
, 0,
NULL
, &
propSize
,
buflist
);
107
if
(!
err
) {
108
for
(
UInt32
i
= 0;
i
<
buflist
->mNumberBuffers; ++
i
) {
109
result +=
buflist
->mBuffers[
i
].mNumberChannels;
110
}
111
}
112
free
(
buflist
);
113
return
result;
114
}
115
116
std::string
117
AudioDevice::getName()
const
118
{
119
char
buf
[256];
120
UInt32
maxlen
=
sizeof
(
buf
) - 1;
121
122
AudioObjectPropertyScope
theScope
=
isInput_
?
kAudioDevicePropertyScopeInput
123
:
kAudioDevicePropertyScopeOutput
;
124
125
AudioObjectPropertyAddress
theAddress
= {
kAudioDevicePropertyDeviceName
,
theScope
, 0};
// channel
126
127
__Verify_noErr
(
AudioObjectGetPropertyData
(
id_
, &
theAddress
, 0,
NULL
, &
maxlen
,
buf
));
128
return
buf
;
129
}
130
131
}
// namespace jami
132
133
#endif
// TARGET_OS_IPHONE
audiodevice.h
jami::AudioDevice::isInput_
bool isInput_
Definition
audiodevice.h:47
jami::AudioDevice::bufferSizeFrames_
UInt32 bufferSizeFrames_
Definition
audiodevice.h:50
jami::AudioDevice::init
void init(AudioDeviceID devid, bool isInput)
Definition
audiodevice.cpp:30
jami::AudioDevice::safetyOffset_
UInt32 safetyOffset_
Definition
audiodevice.h:49
jami::AudioDevice::AudioDevice
AudioDevice()
Definition
audiodevice.h:36
jami::AudioDevice::valid
bool valid() const
Definition
audiodevice.cpp:64
jami::AudioDevice::channels_
int channels_
Definition
audiodevice.h:48
jami::AudioDevice::format_
AudioStreamBasicDescription format_
Definition
audiodevice.h:51
jami::AudioDevice::setBufferSize
void setBufferSize(UInt32 size)
Definition
audiodevice.cpp:70
jami::AudioDevice::id_
AudioDeviceID id_
Definition
audiodevice.h:45
jami::AudioDevice::name_
std::string name_
Definition
audiodevice.h:46
jami
Definition
account.cpp:61
jami::emitSignal
void emitSignal(Args... args)
Definition
ring_signal.h:64
src
media
audio
coreaudio
osx
audiodevice.cpp
Generated on Thu Jun 19 2025 15:50:37 for Ring Daemon by
1.9.8