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
qpulseaudio_contextmanager_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 QPULSEAUDIO_CONTEXTMANAGER_P_H
5#define QPULSEAUDIO_CONTEXTMANAGER_P_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 <QtCore/qmap.h>
19#include <QtCore/qbytearray.h>
20#include <QtCore/qreadwritelock.h>
21#include <pulse/pulseaudio.h>
23#include <qaudioformat.h>
24
26
28{
30
33
34public:
35 explicit QPulseAudioContextManager(QObject *parent = nullptr);
37
39 pa_threaded_mainloop *mainloop() { return m_mainLoop.get(); }
40 pa_context *context() { return m_context.get(); }
41
42 void lock()
43 {
44 if (m_mainLoop)
45 pa_threaded_mainloop_lock(m_mainLoop.get());
46 }
47
48 void unlock()
49 {
50 if (m_mainLoop)
51 pa_threaded_mainloop_unlock(m_mainLoop.get());
52 }
53
54 void wait(const PAOperationHandle &op)
55 {
56 while (m_mainLoop && pa_operation_get_state(op.get()) == PA_OPERATION_RUNNING)
57 pa_threaded_mainloop_wait(m_mainLoop.get());
58 }
59
60 bool waitForAsyncOperation(pa_operation *op);
61 bool waitForAsyncOperation(const PAOperationHandle &);
62
63 bool isInMainLoop() const
64 {
65 return m_mainLoop && pa_threaded_mainloop_in_thread(m_mainLoop.get());
66 }
67
68 QList<QAudioDevice> availableDevices(QAudioDevice::Mode mode) const;
69 QByteArray defaultDevice(QAudioDevice::Mode mode) const;
70
71 pa_context_state_t getContextState();
72 bool contextIsGood();
73
75
79
80private Q_SLOTS:
81 void prepare();
82 void onContextFailed();
83
84private:
85 static void serverInfoCallback(pa_context *context, const pa_server_info *info, void *userdata);
86 static void sinkInfoCallback(pa_context *context, const pa_sink_info *info, int isLast,
87 void *userdata);
88 static void sourceInfoCallback(pa_context *context, const pa_source_info *info, int isLast,
89 void *userdata);
90 static void eventCallback(pa_context *context, pa_subscription_event_type_t t, uint32_t index,
91 void *userdata);
92 static void contextStateCallbackInit(pa_context *context, void *userdata);
93 static void contextStateCallback(pa_context *c, void *userdata);
94
95 void updateDevices();
96 void release();
97
98 QMap<int, QAudioDevice> m_sinks;
99 QMap<int, QAudioDevice> m_sources;
100
101 QByteArray m_defaultSink;
102 QByteArray m_defaultSource;
103
104 mutable QReadWriteLock m_sinkLock;
105 mutable QReadWriteLock m_sourceLock;
106 mutable QReadWriteLock m_serverLock;
107
108 pa_mainloop_api *m_mainLoopApi{};
109 std::unique_ptr<pa_threaded_mainloop, QPulseAudioInternal::PaMainLoopDeleter> m_mainLoop;
110 PAContextHandle m_context;
111 bool m_prepared{};
112
113 QString m_serverName;
114 };
115
116QT_END_NAMESPACE
117
118#endif // QPULSEAUDIO_CONTEXTMANAGER_P_H
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)