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 PaMainLoopDeleter
63{
64 void operator()(pa_threaded_mainloop *m) const { pa_threaded_mainloop_free(m); }
65};
66
67pa_sample_spec audioFormatToSampleSpec(const QAudioFormat &format);
68QAudioFormat sampleSpecToAudioFormat(const pa_sample_spec &spec);
69pa_channel_map channelMapForAudioFormat(const QAudioFormat &format);
70QAudioFormat::ChannelConfig channelConfigFromMap(const pa_channel_map &map);
71
72QUtf8StringView currentError(const pa_context *);
73QUtf8StringView currentError(const pa_stream *);
74
75} // namespace QPulseAudioInternal
76
77QDebug operator<<(QDebug, pa_stream_state_t);
78QDebug operator<<(QDebug, pa_sample_format);
79QDebug operator<<(QDebug, pa_context_state_t);
80
81QT_END_NAMESPACE
82
83#endif
84

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