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#ifndef QPULSEHELPER_H
5#define QPULSEHELPER_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 "qaudiodevice.h"
19#include <qaudioformat.h>
20#include <pulse/pulseaudio.h>
21#include <QtCore/QLoggingCategory>
22
23QT_BEGIN_NAMESPACE
24
25Q_DECLARE_LOGGING_CATEGORY(qLcPulseAudioOut)
26
27struct PAOperationDeleter
28{
29 void operator()(pa_operation *op) const { pa_operation_unref(o: op); }
30};
31
32using PAOperationUPtr = std::unique_ptr<pa_operation, PAOperationDeleter>;
33
34namespace QPulseAudioInternal
35{
36pa_sample_spec audioFormatToSampleSpec(const QAudioFormat &format);
37QAudioFormat sampleSpecToAudioFormat(const pa_sample_spec &spec);
38pa_channel_map channelMapForAudioFormat(const QAudioFormat &format);
39QAudioFormat::ChannelConfig channelConfigFromMap(const pa_channel_map &map);
40
41static inline QString stateToQString(pa_stream_state_t state)
42{
43 using namespace Qt::StringLiterals;
44 switch (state)
45 {
46 case PA_STREAM_UNCONNECTED: return "Unconnected"_L1;
47 case PA_STREAM_CREATING: return "Creating"_L1;
48 case PA_STREAM_READY: return "Ready"_L1;
49 case PA_STREAM_FAILED: return "Failed"_L1;
50 case PA_STREAM_TERMINATED: return "Terminated"_L1;
51 }
52
53 return u"Unknown state: %0"_s.arg(a: int(state));
54}
55
56static inline QString sampleFormatToQString(pa_sample_format format)
57{
58 using namespace Qt::StringLiterals;
59 switch (format)
60 {
61 case PA_SAMPLE_U8: return "Unsigned 8 Bit PCM."_L1;
62 case PA_SAMPLE_ALAW: return "8 Bit a-Law "_L1;
63 case PA_SAMPLE_ULAW: return "8 Bit mu-Law"_L1;
64 case PA_SAMPLE_S16LE: return "Signed 16 Bit PCM, little endian (PC)."_L1;
65 case PA_SAMPLE_S16BE: return "Signed 16 Bit PCM, big endian."_L1;
66 case PA_SAMPLE_FLOAT32LE: return "32 Bit IEEE floating point, little endian (PC), range -1.0 to 1.0"_L1;
67 case PA_SAMPLE_FLOAT32BE: return "32 Bit IEEE floating point, big endian, range -1.0 to 1.0"_L1;
68 case PA_SAMPLE_S32LE: return "Signed 32 Bit PCM, little endian (PC)."_L1;
69 case PA_SAMPLE_S32BE: return "Signed 32 Bit PCM, big endian."_L1;
70 case PA_SAMPLE_S24LE: return "Signed 24 Bit PCM packed, little endian (PC)."_L1;
71 case PA_SAMPLE_S24BE: return "Signed 24 Bit PCM packed, big endian."_L1;
72 case PA_SAMPLE_S24_32LE: return "Signed 24 Bit PCM in LSB of 32 Bit words, little endian (PC)."_L1;
73 case PA_SAMPLE_S24_32BE: return "Signed 24 Bit PCM in LSB of 32 Bit words, big endian."_L1;
74 case PA_SAMPLE_MAX: return "Upper limit of valid sample types."_L1;
75 case PA_SAMPLE_INVALID: return "Invalid sample format"_L1;
76 }
77
78 return u"Invalid value: %0"_s.arg(a: int(format));
79}
80
81static inline QString stateToQString(pa_context_state_t state)
82{
83 using namespace Qt::StringLiterals;
84 switch (state)
85 {
86 case PA_CONTEXT_UNCONNECTED: return "Unconnected"_L1;
87 case PA_CONTEXT_CONNECTING: return "Connecting"_L1;
88 case PA_CONTEXT_AUTHORIZING: return "Authorizing"_L1;
89 case PA_CONTEXT_SETTING_NAME: return "Setting Name"_L1;
90 case PA_CONTEXT_READY: return "Ready"_L1;
91 case PA_CONTEXT_FAILED: return "Failed"_L1;
92 case PA_CONTEXT_TERMINATED: return "Terminated"_L1;
93 }
94
95 return u"Unknown state: %0"_s.arg(a: int(state));
96}
97}
98
99QT_END_NAMESPACE
100
101#endif
102

source code of qtmultimedia/src/multimedia/pulseaudio/qpulsehelpers_p.h