Ring Daemon
Loading...
Searching...
No Matches
audiodevice.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2004-2026 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
:
kAudioDevicePropertyScopeOutput
;
43
44
AudioObjectPropertyAddress
theAddress
= {
kAudioDevicePropertySafetyOffset
,
theScope
, 0};
// channel
45
46
__Verify_noErr
(
AudioObjectGetPropertyData
(
id_
, &
theAddress
, 0,
NULL
, &
propsize
, &
safetyOffset_
));
47
48
propsize
=
sizeof
(
UInt32
);
49
theAddress
.mSelector =
kAudioDevicePropertyBufferFrameSize
;
50
51
__Verify_noErr
(
AudioObjectGetPropertyData
(
id_
, &
theAddress
, 0,
NULL
, &
propsize
, &
bufferSizeFrames_
));
52
53
propsize
=
sizeof
(
AudioStreamBasicDescription
);
54
theAddress
.mSelector =
kAudioDevicePropertyStreamFormat
;
55
56
__Verify_noErr
(
AudioObjectGetPropertyData
(
id_
, &
theAddress
, 0,
NULL
, &
propsize
, &
format_
));
57
}
58
59
bool
60
AudioDevice::valid
()
const
61
{
62
return
id_
!=
kAudioDeviceUnknown
;
63
}
64
65
void
66
AudioDevice::setBufferSize
(
UInt32
size)
67
{
68
UInt32
propsize
=
sizeof
(
UInt32
);
69
70
AudioObjectPropertyScope
theScope
=
isInput_
?
kAudioDevicePropertyScopeInput
:
kAudioDevicePropertyScopeOutput
;
71
72
AudioObjectPropertyAddress
theAddress
= {
kAudioDevicePropertyBufferFrameSize
,
theScope
, 0};
// channel
73
74
__Verify_noErr
(
AudioObjectSetPropertyData
(
id_
, &
theAddress
, 0,
NULL
,
propsize
, &size));
75
76
__Verify_noErr
(
AudioObjectGetPropertyData
(
id_
, &
theAddress
, 0,
NULL
, &
propsize
, &
bufferSizeFrames_
));
77
}
78
79
int
80
AudioDevice::countChannels()
const
81
{
82
OSStatus
err
;
83
UInt32
propSize
;
84
int
result = 0;
85
86
AudioObjectPropertyScope
theScope
=
isInput_
?
kAudioDevicePropertyScopeInput
:
kAudioDevicePropertyScopeOutput
;
87
88
AudioObjectPropertyAddress
theAddress
= {
kAudioDevicePropertyStreamConfiguration
,
theScope
, 0};
// channel
89
90
err
=
AudioObjectGetPropertyDataSize
(
id_
, &
theAddress
, 0,
NULL
, &
propSize
);
91
if
(
err
)
92
return
0;
93
94
AudioBufferList
*
buflist
= (
AudioBufferList
*)
malloc
(
propSize
);
95
err
=
AudioObjectGetPropertyData
(
id_
, &
theAddress
, 0,
NULL
, &
propSize
,
buflist
);
96
if
(!
err
) {
97
for
(
UInt32
i
= 0;
i
<
buflist
->mNumberBuffers; ++
i
) {
98
result +=
buflist
->mBuffers[
i
].mNumberChannels;
99
}
100
}
101
free
(
buflist
);
102
return
result;
103
}
104
105
std::string
106
AudioDevice::getName()
const
107
{
108
char
buf
[256];
109
UInt32
maxlen
=
sizeof
(
buf
) - 1;
110
111
AudioObjectPropertyScope
theScope
=
isInput_
?
kAudioDevicePropertyScopeInput
:
kAudioDevicePropertyScopeOutput
;
112
113
AudioObjectPropertyAddress
theAddress
= {
kAudioDevicePropertyDeviceName
,
theScope
, 0};
// channel
114
115
__Verify_noErr
(
AudioObjectGetPropertyData
(
id_
, &
theAddress
, 0,
NULL
, &
maxlen
,
buf
));
116
return
buf
;
117
}
118
119
}
// namespace jami
120
121
#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:60
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:66
jami::AudioDevice::id_
AudioDeviceID id_
Definition
audiodevice.h:45
jami::AudioDevice::name_
std::string name_
Definition
audiodevice.h:46
jami
Definition
account.cpp:56
jami::emitSignal
void emitSignal(Args... args)
Definition
jami_signal.h:64
src
media
audio
coreaudio
osx
audiodevice.cpp
Generated on Fri Apr 3 2026 14:23:10 for Ring Daemon by
1.9.8