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
qpipewire_audiosink_p.h
Go to the documentation of this file.
1// Copyright (C) 2025 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 QPIPEWIRE_AUDIOSINK_P_H
5#define QPIPEWIRE_AUDIOSINK_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/qsemaphore.h>
19#include <QtCore/qtclasshelpermacros.h>
20
21#include <QtMultimedia/private/qaudio_platform_implementation_support_p.h>
22#include <QtMultimedia/private/qaudiosystem_p.h>
23#include <QtMultimedia/private/qaudiosystem_platform_stream_support_p.h>
24#include <QtMultimedia/private/qpipewire_audiostream_p.h>
25
27
28namespace QtPipeWire {
29
30using namespace QtMultimediaPrivate;
31
32class QPipewireAudioSink;
33
34////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
35
37{
39 using SinkType = QPipewireAudioSink;
40
41 QPipewireAudioSinkStream(QAudioDevice, const QAudioFormat &,
42 std::optional<qsizetype> ringbufferSize, QPipewireAudioSink *parent,
43 float volume, std::optional<int32_t> hardwareBufferFrames,
47
48 bool open();
49
54
55 bool start(QIODevice *device);
57 bool start(AudioCallback);
58
59 void stop(ShutdownPolicy);
60
61 void updateStreamIdle(bool idle) override;
62
63private:
64 void createStream(QPipewireAudioStream::StreamType);
65 std::optional<ObjectSerial> findSinkNodeSerial();
66
68
69 // QPipewireAudioStream overrides
73 template <typename Functor>
74 void processHelper(Functor &&f);
75
76 void stateChanged(pw_stream_state /*old*/, pw_stream_state state,
77 const char * /*error*/) override;
78
79 void disconnectStream();
80 QSemaphore m_disconnectSemaphore;
81
82 std::atomic<ShutdownPolicy> m_shutdownPolicy{ ShutdownPolicy::DiscardRingbuffer };
83 QAutoResetEvent m_ringbufferDrained;
84
85 // process helpers
86 void queueBuffer(struct pw_buffer *b, uint64_t samplesWritten) noexcept QT_MM_NONBLOCKING;
87
88 // xrun detection
89 void xrunOccurred(int /*xrunCount*/) override { m_xrunOccurred.set(); }
90 QtPrivate::QAutoResetEvent m_xrunOccurred;
91 QMetaObject::Connection m_xrunNotification;
92
93 [[maybe_unused]] static void fakeXRun();
94
95 AudioEndpointRole m_role;
96 std::optional<AudioCallback> m_audioCallback;
97
98 QPipewireAudioSink *m_parent;
99};
100
101////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
102
103class QPipewireAudioSink final
104 : public QPlatformAudioSinkImplementation<QPipewireAudioSinkStream, QPipewireAudioSink>
105{
106 using BaseClass =
107 QPlatformAudioSinkImplementation<QPipewireAudioSinkStream, QPipewireAudioSink>;
108
109public:
110 QPipewireAudioSink(QAudioDevice, const QAudioFormat &, QObject *parent);
111
112 void reportXRuns(int);
113};
114
115////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
116
117} // namespace QtPipeWire
118
119QT_END_NAMESPACE
120
121#endif
DeviceLists getDeviceLists(bool verifyThreading=true)
QPlatformAudioSink * createAudioSink(const QAudioDevice &, const QAudioFormat &, QObject *parent) override
~QAudioDevices() override=default
QPlatformAudioSource * createAudioSource(const QAudioDevice &, const QAudioFormat &, QObject *parent) override
QList< QAudioDevice > findAudioOutputs() const override
QList< QAudioDevice > findAudioInputs() const override
QLatin1String backendName() const override
QPipewireAudioSink(QAudioDevice, const QAudioFormat &, QObject *parent)
StrongIdType< uint64_t, ObjectSerialTag > ObjectSerial
QPipewireAudioSinkStream(QAudioDevice, const QAudioFormat &, std::optional< qsizetype > ringbufferSize, QPipewireAudioSink *parent, float volume, std::optional< int32_t > hardwareBufferFrames, AudioEndpointRole)
void processRingbuffer() noexcept QT_MM_NONBLOCKING override
void stateChanged(pw_stream_state, pw_stream_state state, const char *) override
void processCallback() noexcept QT_MM_NONBLOCKING override