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 QPULSEAUDIOENGINE_H
5#define QPULSEAUDIOENGINE_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>
22#include "qpulsehelpers_p.h"
23#include <qaudioformat.h>
24
25QT_BEGIN_NAMESPACE
26
27class QPulseAudioEngine : public QObject
28{
29 Q_OBJECT
30
31public:
32 QPulseAudioEngine(QObject *parent = 0);
33 ~QPulseAudioEngine();
34
35 static QPulseAudioEngine *instance();
36 pa_threaded_mainloop *mainloop() { return m_mainLoop; }
37 pa_context *context() { return m_context; }
38
39 inline void lock()
40 {
41 if (m_mainLoop)
42 pa_threaded_mainloop_lock(m: m_mainLoop);
43 }
44
45 inline void unlock()
46 {
47 if (m_mainLoop)
48 pa_threaded_mainloop_unlock(m: m_mainLoop);
49 }
50
51 inline void wait(pa_operation *op)
52 {
53 while (m_mainLoop && pa_operation_get_state(o: op) == PA_OPERATION_RUNNING)
54 pa_threaded_mainloop_wait(m: m_mainLoop);
55 }
56
57 QList<QAudioDevice> availableDevices(QAudioDevice::Mode mode) const;
58 QByteArray defaultDevice(QAudioDevice::Mode mode) const;
59
60Q_SIGNALS:
61 void contextFailed();
62 void audioInputsChanged();
63 void audioOutputsChanged();
64
65private Q_SLOTS:
66 void prepare();
67 void onContextFailed();
68
69private:
70 void updateDevices();
71 void release();
72
73public:
74 QMap<int, QAudioDevice> m_sinks;
75 QMap<int, QAudioDevice> m_sources;
76
77 QByteArray m_defaultSink;
78 QByteArray m_defaultSource;
79
80 mutable QReadWriteLock m_sinkLock;
81 mutable QReadWriteLock m_sourceLock;
82 mutable QReadWriteLock m_serverLock;
83
84private:
85 pa_mainloop_api *m_mainLoopApi;
86 pa_threaded_mainloop *m_mainLoop;
87 pa_context *m_context;
88 bool m_prepared;
89 };
90
91QT_END_NAMESPACE
92
93#endif
94

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