Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qmacosaudiodatautils_p.h
Go to the documentation of this file.
1
// Copyright (C) 2021 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
#
ifndef
QMACOSAUDIODATAUTILS_P_H
5
#
define
QMACOSAUDIODATAUTILS_P_H
6
7
//
8
// W A R N I N G
9
// -------------
10
//
11
// This file is not part of the Qt API. It exists purely as an
12
// implementation detail. This header file may change from version to
13
// version without notice, or even be removed.
14
//
15
// We mean it.
16
//
17
18
#
include
<
CoreAudio
/
AudioHardware
.
h
>
19
20
#
include
<
QtMultimedia
/
qaudiodevice
.
h
>
21
#
include
<
QtMultimedia
/
private
/
qcoreaudioutils_p
.
h
>
22
#
include
<
QtCore
/
qdebug
.
h
>
23
#
include
<
QtCore
/
qspan
.
h
>
24
#
include
<
QtCore
/
private
/
qcore_mac_p
.
h
>
25
26
#
include
<
optional
>
27
#
include
<
vector
>
28
29
QT_BEGIN_NAMESPACE
30
31
namespace
QCoreAudioUtils
32
{
33
34
// coreaudio string helpers
35
QStringView
audioPropertySelectorToString
(
AudioObjectPropertySelector
);
36
QStringView
audioPropertyScopeToString
(
AudioObjectPropertyScope
);
37
QStringView
audioPropertyElementToString
(
AudioObjectPropertyElement
);
38
39
[[
nodiscard
]]
QByteArray
readPersistentDeviceId
(
40
AudioDeviceID
,
41
QAudioDevice
::
Mode
);
42
43
[[
nodiscard
]]
std
::
optional
<
AudioDeviceID
>
findAudioDeviceId
(
44
const
QByteArray &id,
45
QAudioDevice
::
Mode
);
46
47
[[
nodiscard
]]
std
::
optional
<
AudioDeviceID
>
findAudioDeviceId
(
const
QAudioDevice &device);
48
49
template
<
typename
... Args>
50
void
printUnableToReadWarning
(AudioObjectID objectID,
const
AudioObjectPropertyAddress &address, Args &&...args)
51
{
52
using
namespace
QCoreAudioUtils
;
53
auto
warn = qWarning();
54
warn <<
"Unable to read property"
<< QCoreAudioUtils::audioPropertySelectorToString(address.mSelector)
55
<<
"for object"
<< objectID <<
", scope"
<< QCoreAudioUtils::audioPropertyScopeToString(address.mScope) <<
";"
;
56
(warn << ... << args);
57
warn <<
"\n If the warning is unexpected use test_audio_config to get comprehensive audio info and report a bug"
;
58
}
59
60
61
[[
nodiscard
]]
AudioObjectPropertyAddress
makePropertyAddress
(
62
AudioObjectPropertySelector selector,
63
QAudioDevice::Mode mode,
64
AudioObjectPropertyElement element =
kAudioObjectPropertyElementMain
);
65
66
[[
nodiscard
]]
bool
getAudioPropertyRaw
(
67
AudioObjectID objectID,
68
const
AudioObjectPropertyAddress &address,
69
QSpan<std::byte> destination,
70
bool
warnIfMissing =
true
);
71
72
template
<
typename
T>
73
std
::
optional
<
std
::
vector
<
T
>>
getAudioPropertyList
(AudioObjectID objectID,
74
const
AudioObjectPropertyAddress &address,
75
bool
warnIfMissing =
true
)
76
{
77
static_assert
(
std
::is_trivial_v<T>,
"A trivial type is expected"
);
78
79
UInt32 size = 0;
80
const
auto
res = AudioObjectGetPropertyDataSize(objectID, &address, 0,
nullptr
, &size);
81
82
if
(res != noErr) {
83
if
(warnIfMissing)
84
printUnableToReadWarning(objectID, address,
85
"AudioObjectGetPropertyDataSize failed, Err:"
, res);
86
}
else
{
87
std::vector<T> data(size /
sizeof
(T));
88
if
(getAudioPropertyRaw(objectID, address, as_writable_bytes(QSpan{data})))
89
return
data;
90
}
91
92
return
{};
93
}
94
95
template
<
typename
T>
96
std
::optional<T>
getAudioProperty
(AudioObjectID objectID,
const
AudioObjectPropertyAddress &address,
97
bool
warnIfMissing =
false
)
98
{
99
if
constexpr
(std::is_same_v<T, QCFString>) {
100
const
std::optional<CFStringRef> string = getAudioProperty<CFStringRef>(
101
objectID, address, warnIfMissing);
102
if
(string)
103
return
QCFString{*string};
104
105
return
{};
106
}
else
{
107
static_assert
(
std
::is_trivial_v<T>,
"A trivial type is expected"
);
108
109
T object{};
110
if
(getAudioPropertyRaw(objectID, address, as_writable_bytes(QSpan(&object, 1)), warnIfMissing))
111
return
object;
112
113
return
{};
114
}
115
}
116
117
template
<
typename
T>
118
std
::
unique_ptr
<
T
,
QCoreAudioUtils
::
QFreeDeleter
>
119
getAudioPropertyWithFlexibleArrayMember
(AudioObjectID objectID,
const
AudioObjectPropertyAddress &address,
120
bool
warnIfMissing =
false
)
121
{
122
static_assert
(
std
::is_trivial_v<T>,
"A trivial type is expected"
);
123
124
UInt32 size = 0;
125
const
auto
res = AudioObjectGetPropertyDataSize(objectID, &address, 0,
nullptr
, &size);
126
if
(res != noErr) {
127
if
(warnIfMissing)
128
printUnableToReadWarning(objectID, address,
129
"AudioObjectGetPropertyDataSize failed, Err:"
, res);
130
return
nullptr
;
131
}
132
if
(size <
sizeof
(T)) {
133
printUnableToReadWarning(objectID, address,
"Data size is too small:"
, size,
"VS"
,
134
sizeof
(T),
"bytes"
);
135
return
nullptr
;
136
}
137
138
using
QCoreAudioUtils
::QFreeDeleter;
139
std::unique_ptr<std::byte, QFreeDeleter> region {
140
reinterpret_cast
<std::byte*>(::malloc(size))
141
};
142
143
if
(getAudioPropertyRaw(objectID, address,
144
QSpan(region.get(), size), warnIfMissing))
145
return
std::unique_ptr<T, QFreeDeleter>{
146
reinterpret_cast
<T*>(region.release())
147
};
148
149
return
{};
150
}
151
152
}
// namespace QCoreAudioUtils
153
154
155
156
QT_END_NAMESPACE
157
158
#
endif
// QMACOSAUDIODATAUTILS_P_H
QCoreAudioUtils
Definition
qcoreaudiodevices.mm:277
QCoreAudioUtils::getAudioPropertyWithFlexibleArrayMember
std::unique_ptr< T, QCoreAudioUtils::QFreeDeleter > getAudioPropertyWithFlexibleArrayMember(AudioObjectID objectID, const AudioObjectPropertyAddress &address, bool warnIfMissing=false)
Definition
qmacosaudiodatautils_p.h:119
QCoreAudioUtils::getAudioProperty
std::optional< T > getAudioProperty(AudioObjectID objectID, const AudioObjectPropertyAddress &address, bool warnIfMissing=false)
Definition
qmacosaudiodatautils_p.h:96
QCoreAudioUtils::findAudioDeviceId
std::optional< AudioDeviceID > findAudioDeviceId(const QAudioDevice &device)
Definition
qmacosaudiodatautils.cpp:198
QCoreAudioUtils::audioPropertySelectorToString
QStringView audioPropertySelectorToString(AudioObjectPropertySelector selector)
Definition
qmacosaudiodatautils.cpp:16
QCoreAudioUtils::audioPropertyElementToString
QStringView audioPropertyElementToString(AudioObjectPropertyElement element)
Definition
qmacosaudiodatautils.cpp:101
QCoreAudioUtils::printUnableToReadWarning
void printUnableToReadWarning(AudioObjectID objectID, const AudioObjectPropertyAddress &address, Args &&...args)
Definition
qmacosaudiodatautils_p.h:50
QCoreAudioUtils::makePropertyAddress
AudioObjectPropertyAddress makePropertyAddress(AudioObjectPropertySelector selector, QAudioDevice::Mode mode, AudioObjectPropertyElement element=kAudioObjectPropertyElementMain)
Definition
qmacosaudiodatautils.cpp:117
QCoreAudioUtils::readPersistentDeviceId
QByteArray readPersistentDeviceId(AudioDeviceID, QAudioDevice::Mode)
Definition
qmacosaudiodatautils.cpp:149
QCoreAudioUtils::getAudioPropertyList
std::optional< std::vector< T > > getAudioPropertyList(AudioObjectID objectID, const AudioObjectPropertyAddress &address, bool warnIfMissing=true)
Definition
qmacosaudiodatautils_p.h:73
QCoreAudioUtils::getAudioPropertyRaw
bool getAudioPropertyRaw(AudioObjectID objectID, const AudioObjectPropertyAddress &address, QSpan< std::byte > destination, bool warnIfMissing=true)
Definition
qmacosaudiodatautils.cpp:128
QCoreAudioUtils::findAudioDeviceId
std::optional< AudioDeviceID > findAudioDeviceId(const QByteArray &id, QAudioDevice::Mode)
Definition
qmacosaudiodatautils.cpp:164
QCoreAudioUtils::audioPropertyScopeToString
QStringView audioPropertyScopeToString(AudioObjectPropertyScope scope)
Definition
qmacosaudiodatautils.cpp:88
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
ENUM_CASE
#define ENUM_CASE(NAME)
Definition
qmacosaudiodatautils.cpp:11
DUPLICATE_ENUM_CASE
#define DUPLICATE_ENUM_CASE(NAME)
Definition
qmacosaudiodatautils.cpp:14
qtmultimedia
src
multimedia
coreaudio
qmacosaudiodatautils_p.h
Generated on
for Qt by
1.18.0