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
qpulsehelpers_p.h
Go to the documentation of this file.
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
22#include <QtMultimedia/private/qsharedhandle_p.h>
23
24#include <QtCore/qdebug.h>
25#include <QtCore/qloggingcategory.h>
26
27QT_BEGIN_NAMESPACE
28
29Q_DECLARE_LOGGING_CATEGORY(qLcPulseAudioOut)
30Q_DECLARE_LOGGING_CATEGORY(qLcPulseAudioIn)
31Q_DECLARE_LOGGING_CATEGORY(qLcPulseAudioEngine)
32
33namespace QPulseAudioInternal
34{
35
36template <typename TypeArg, TypeArg *(*RefFn)(TypeArg *), void (*UnrefFn)(TypeArg *)>
37struct PaHandleTraits
38{
39 using Type = TypeArg *;
40 static constexpr Type invalidValue() noexcept { return nullptr; }
41
42 static Type ref(Type handle)
43 {
44 Type ret = (*RefFn)(handle);
45 return ret;
46 }
47 static bool unref(Type handle)
48 {
49 (*UnrefFn)(handle);
50 return true;
51 }
52};
53
54using PAOperationHandleTraits = PaHandleTraits<pa_operation, pa_operation_ref, pa_operation_unref>;
55using PAContextHandleTraits = PaHandleTraits<pa_context, pa_context_ref, pa_context_unref>;
56using PAStreamHandleTraits = PaHandleTraits<pa_stream, pa_stream_ref, pa_stream_unref>;
57
58using PAOperationHandle = QtPrivate::QSharedHandle<PAOperationHandleTraits>;
59using PAContextHandle = QtPrivate::QSharedHandle<PAContextHandleTraits>;
60using PAStreamHandle = QtPrivate::QSharedHandle<PAStreamHandleTraits>;
61
62struct PAProplistDeleter
63{
64 void operator()(pa_proplist *propList) { pa_proplist_free(propList); }
65};
66
67using PAProplistHandle = std::unique_ptr<pa_proplist, PAProplistDeleter>;
68
69struct PaMainLoopDeleter
70{
71 void operator()(pa_threaded_mainloop *m) const { pa_threaded_mainloop_free(m); }
72};
73
74pa_sample_spec audioFormatToSampleSpec(const QAudioFormat &format);
75QAudioFormat sampleSpecToAudioFormat(const pa_sample_spec &spec);
76pa_channel_map channelMapForAudioFormat(const QAudioFormat &format);
77QAudioFormat::ChannelConfig channelConfigFromMap(const pa_channel_map &map);
78
79QUtf8StringView currentError(const pa_context *);
80QUtf8StringView currentError(const pa_stream *);
81
82[[nodiscard]] PAOperationHandle streamCork(const PAStreamHandle &, bool);
83
84} // namespace QPulseAudioInternal
85
86QDebug operator<<(QDebug, pa_stream_state_t);
87QDebug operator<<(QDebug, pa_sample_format);
88QDebug operator<<(QDebug, pa_context_state_t);
89
90QT_END_NAMESPACE
91
92#endif
The QAudioFormat class stores audio stream parameter information.
constexpr SampleFormat sampleFormat() const noexcept
Returns the current sample format.
constexpr void setChannelCount(int channelCount) noexcept
Sets the channel count to channels.
constexpr void setSampleFormat(SampleFormat f) noexcept
Sets the sample format to format.
constexpr bool isValid() const noexcept
Returns true if all of the parameters are valid.
SampleFormat
Qt will always expect and use samples in the endianness of the host platform.
constexpr void setSampleRate(int sampleRate) noexcept
Sets the sample rate to samplerate in Hertz.
ChannelConfig
\variable QAudioFormat::NChannelPositions
void wait(const PAOperationHandle &op)
QByteArray defaultDevice(QAudioDevice::Mode mode) const
static QPulseAudioContextManager * instance()
bool waitForAsyncOperation(const PAOperationHandle &)
bool waitForAsyncOperation(pa_operation *op)
QList< QAudioDevice > availableDevices(QAudioDevice::Mode mode) const
QPulseAudioContextManager(QObject *parent=nullptr)
static bool updateDevicesMap(QReadWriteLock &lock, const QByteArray &defaultDeviceId, QMap< int, QAudioDevice > &devices, QAudioDevice::Mode mode, const Info &info)
Q_GLOBAL_STATIC(QPulseAudioContextManager, pulseEngine)
static std::unique_ptr< QAudioDevicePrivate > makeQAudioDevicePrivate(const char *device, const char *desc, bool isDef, QAudioDevice::Mode mode, const pa_channel_map &map, const pa_sample_spec &spec)
static bool updateDevicesMap(QReadWriteLock &lock, const QByteArray &defaultDeviceId, QMap< int, QAudioDevice > &devices)
QDebug operator<<(QDebug dbg, pa_sample_format format)
QDebug operator<<(QDebug dbg, pa_context_state_t state)