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