Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qpipewire_audiodevice.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 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
5
6#include <QtCore/qdebug.h>
7#include <QtMultimedia/private/qaudioformat_p.h>
8
10
11namespace QtPipeWire {
12
13namespace {
14
15QAudioFormat::SampleFormat toSampleFormat(spa_audio_format fmt)
16{
17 switch (fmt) {
18 case SPA_AUDIO_FORMAT_S16:
19 return QAudioFormat::Int16;
20 case SPA_AUDIO_FORMAT_S32:
21 return QAudioFormat::Int32;
22 case SPA_AUDIO_FORMAT_U8:
23 return QAudioFormat::UInt8;
24 case SPA_AUDIO_FORMAT_F32:
25 return QAudioFormat::Float;
26 default:
27 return QAudioFormat::Unknown;
28 }
29}
30
31QByteArray inferDeviceId(const PwPropertyDict &properties)
32{
33 auto nodeName = getNodeName(properties);
34 Q_ASSERT(nodeName);
35 if (nodeName)
36 return QByteArray{ *nodeName };
37 return {};
38}
39
40template <typename Lhs, typename Rhs>
41bool channelPositionsEqual(const Lhs &lhs, const Rhs &rhs)
42{
43 return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
44}
45
46} // namespace
47
54 mode,
56 }
57{
58 static const QList allSampleFormats = {
63 };
64
66 this->isDefault = isDefault;
67
70
73
76
77 std::visit([&](const auto &arg) {
79 }, formats.rates);
80
81 std::visit([&](const auto &arg) {
84
87
108 } else {
109 // now we need to guess
112 }
113 } else {
114 // we again need to guess
117 }
118
121}
122
124
126{
128}
129
131{
132 constexpr int defaultPipewireSamplingRate = 48000;
133
136}
137
139{
141}
142
144{
146 if (fmt == QAudioFormat::Unknown) {
147 qWarning() << "No sample format supported found for device" << nodeName();
148 return;
149 }
150
152}
153
155{
157
158 // technically iec958 would be 20 or 24 bit PCM, but pipewire will do software mixing, so float
159 // is our preferred option here
161}
162
164{
165 for (spa_audio_format f : fmt.values()) {
166 auto qtFormat = toSampleFormat(f);
169 }
170
174 } else {
177 else
178 qWarning() << "No sample format supported found for device" << nodeName();
179 }
180}
181
182} // namespace QtPipeWire
183
184QT_END_NAMESPACE