| 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 | |
| 27 | QT_BEGIN_NAMESPACE |
| 28 | |
| 29 | Q_DECLARE_LOGGING_CATEGORY(qLcPulseAudioOut) |
| 30 | Q_DECLARE_LOGGING_CATEGORY(qLcPulseAudioIn) |
| 31 | Q_DECLARE_LOGGING_CATEGORY(qLcPulseAudioEngine) |
| 32 | |
| 33 | namespace QPulseAudioInternal |
| 34 | { |
| 35 | |
| 36 | template <typename TypeArg, TypeArg *(*RefFn)(TypeArg *), void (*UnrefFn)(TypeArg *)> |
| 37 | struct 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 | |
| 54 | using PAOperationHandleTraits = PaHandleTraits<pa_operation, pa_operation_ref, pa_operation_unref>; |
| 55 | using PAContextHandleTraits = PaHandleTraits<pa_context, pa_context_ref, pa_context_unref>; |
| 56 | using PAStreamHandleTraits = PaHandleTraits<pa_stream, pa_stream_ref, pa_stream_unref>; |
| 57 | |
| 58 | using PAOperationHandle = QtPrivate::QSharedHandle<PAOperationHandleTraits>; |
| 59 | using PAContextHandle = QtPrivate::QSharedHandle<PAContextHandleTraits>; |
| 60 | using PAStreamHandle = QtPrivate::QSharedHandle<PAStreamHandleTraits>; |
| 61 | |
| 62 | struct PAProplistDeleter |
| 63 | { |
| 64 | void operator()(pa_proplist *propList) { pa_proplist_free(p: propList); } |
| 65 | }; |
| 66 | |
| 67 | using PAProplistHandle = std::unique_ptr<pa_proplist, PAProplistDeleter>; |
| 68 | |
| 69 | struct PaMainLoopDeleter |
| 70 | { |
| 71 | void operator()(pa_threaded_mainloop *m) const { pa_threaded_mainloop_free(m); } |
| 72 | }; |
| 73 | |
| 74 | pa_sample_spec audioFormatToSampleSpec(const QAudioFormat &format); |
| 75 | QAudioFormat sampleSpecToAudioFormat(const pa_sample_spec &spec); |
| 76 | pa_channel_map channelMapForAudioFormat(const QAudioFormat &format); |
| 77 | QAudioFormat::ChannelConfig channelConfigFromMap(const pa_channel_map &map); |
| 78 | |
| 79 | QUtf8StringView currentError(const pa_context *); |
| 80 | QUtf8StringView currentError(const pa_stream *); |
| 81 | |
| 82 | } // namespace QPulseAudioInternal |
| 83 | |
| 84 | QDebug operator<<(QDebug, pa_stream_state_t); |
| 85 | QDebug operator<<(QDebug, pa_sample_format); |
| 86 | QDebug operator<<(QDebug, pa_context_state_t); |
| 87 | |
| 88 | QT_END_NAMESPACE |
| 89 | |
| 90 | #endif |
| 91 | |