1// Copyright (C) 2016 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#include "qpulseaudiodevice_p.h"
5#include "qaudioengine_pulse_p.h"
6#include "qpulsehelpers_p.h"
7
8QT_BEGIN_NAMESPACE
9
10QPulseAudioDeviceInfo::QPulseAudioDeviceInfo(const char *device, const char *desc, bool isDef, QAudioDevice::Mode mode)
11 : QAudioDevicePrivate(device, mode)
12{
13 description = QString::fromUtf8(utf8: desc);
14 isDefault = isDef;
15
16 minimumChannelCount = 1;
17 maximumChannelCount = PA_CHANNELS_MAX;
18 minimumSampleRate = 1;
19 maximumSampleRate = PA_RATE_MAX;
20
21 constexpr bool isBigEndian = QSysInfo::ByteOrder == QSysInfo::BigEndian;
22
23 const struct {
24 pa_sample_format pa_fmt;
25 QAudioFormat::SampleFormat qt_fmt;
26 } formatMap[] = {
27 { PA_SAMPLE_U8, .qt_fmt: QAudioFormat::UInt8 },
28 { .pa_fmt: isBigEndian ? PA_SAMPLE_S16BE : PA_SAMPLE_S16LE, .qt_fmt: QAudioFormat::Int16 },
29 { .pa_fmt: isBigEndian ? PA_SAMPLE_S32BE : PA_SAMPLE_S32LE, .qt_fmt: QAudioFormat::Int32 },
30 { .pa_fmt: isBigEndian ? PA_SAMPLE_FLOAT32BE : PA_SAMPLE_FLOAT32LE, .qt_fmt: QAudioFormat::Float },
31 };
32
33 for (const auto &f : formatMap) {
34 if (pa_sample_format_valid(format: f.pa_fmt) != 0)
35 supportedSampleFormats.append(t: f.qt_fmt);
36 }
37
38 preferredFormat.setChannelCount(2);
39 preferredFormat.setSampleRate(48000);
40 QAudioFormat::SampleFormat f = QAudioFormat::Int16;
41 if (!supportedSampleFormats.contains(t: f))
42 f = supportedSampleFormats.value(i: 0, defaultValue: QAudioFormat::Unknown);
43 preferredFormat.setSampleFormat(f);
44}
45
46QT_END_NAMESPACE
47

source code of qtmultimedia/src/multimedia/pulseaudio/qpulseaudiodevice.cpp