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
qpulseaudiosink_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 QPULSEAUDIOSINK_P_H
5#define QPULSEAUDIOSINK_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/qtclasshelpermacros.h>
19
20#include <QtMultimedia/qaudio.h>
21#include <QtMultimedia/qaudiodevice.h>
22#include <QtMultimedia/private/qaudio_platform_implementation_support_p.h>
23#include <QtMultimedia/private/qaudiosystem_p.h>
24#include <QtMultimedia/private/qpulsehelpers_p.h>
25
27
28namespace QPulseAudioInternal {
29
30using namespace QtMultimediaPrivate;
31class QPulseAudioSink;
32
33struct QPulseAudioSinkStream final : QPlatformAudioSinkStream
34{
35 using SinkType = QPulseAudioSink;
36
37 QPulseAudioSinkStream(QAudioDevice, const QAudioFormat &format,
38 std::optional<qsizetype> ringbufferSize, QPulseAudioSink *parent,
39 float volume, std::optional<int32_t> hardwareBufferSize,
40 AudioEndpointRole);
42
43 using QPlatformAudioSinkStream::bytesFree;
44 using QPlatformAudioSinkStream::processedDuration;
45 using QPlatformAudioSinkStream::ringbufferSizeInBytes;
46 using QPlatformAudioSinkStream::setVolume;
47
48 bool start(QIODevice *device);
49 bool start(AudioCallback &&);
51 void stop(ShutdownPolicy);
52 void stop() { stop(ShutdownPolicy::DrainRingbuffer); }
53 void reset() { stop(ShutdownPolicy::DiscardRingbuffer); }
54 void suspend();
55 void resume();
56
57 bool open() const;
58
59private:
60 enum class StreamType : uint8_t
61 {
62 Ringbuffer,
63 Callback,
64 };
65
66 void installCallbacks(StreamType);
67 void uninstallCallbacks();
68
69 bool startStream(StreamType);
70
71 void updateStreamIdle(bool) override;
72
73 // PulseAudio callbacks
74 void underflowCallback() { }
75 void overflowCallback() { }
76 void stateCallback() { }
77 void writeCallbackRingbuffer(size_t requestedBytes);
78 void writeCallbackAudioCallback(size_t requestedBytes);
79 void latencyUpdateCallback() { }
80
81 QPulseAudioSink *m_parent;
82 PAStreamHandle m_stream;
83
84 std::optional<AudioCallback> m_audioCallback;
85};
86
87////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
88
89class QPulseAudioSink final
90 : public QPlatformAudioSinkImplementation<QPulseAudioSinkStream, QPulseAudioSink>
91{
92 using BaseClass = QPlatformAudioSinkImplementation<QPulseAudioSinkStream, QPulseAudioSink>;
93
94public:
95 QPulseAudioSink(QAudioDevice, const QAudioFormat &, QObject *parent);
96
97 void start(QIODevice *device) override;
98 QIODevice *start() override;
99 void start(AudioCallback &&) override;
100
101private:
102 bool validatePulseaudio();
103};
104
105} // namespace QPulseAudioInternal
106
107QT_END_NAMESPACE
108
109#endif // QPULSEAUDIOSINK_P_H
The QAudioFormat class stores audio stream parameter information.
QList< QAudioDevice > findAudioOutputs() const override
QList< QAudioDevice > findAudioInputs() const override
QLatin1String backendName() const override
QPlatformAudioSink * createAudioSink(const QAudioDevice &, const QAudioFormat &, QObject *parent) override
QPlatformAudioSource * createAudioSource(const QAudioDevice &, const QAudioFormat &, QObject *parent) override
void start(QIODevice *device) override
void start(AudioCallback &&) override
void start(QIODevice *device) override
void start(AudioCallback &&) override