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_audiosource_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_AUDIOSOURCE_P_H
5#define QPIPEWIRE_AUDIOSOURCE_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 QPipewireAudioSource;
33
34////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
35
36// LATER:
37// ideally the ringbuffer should fill a buffer that can grow via a worker thread on which we can
38// allocate.
40{
41 using SourceType = QPipewireAudioSource;
43
44 QPipewireAudioSourceStream(QAudioDevice, const QAudioFormat &,
45 std::optional<qsizetype> ringbufferSize,
46 QPipewireAudioSource *parent, float volume,
47 std::optional<int32_t> hardwareBufferFrames);
50
51 bool open() { return true; }
52 bool start(QIODevice *device);
54 bool start(AudioCallback &&);
55 void stop(ShutdownPolicy);
56
62
63 void updateStreamIdle(bool idle) override;
64
65private:
66 void createStream(QPipewireAudioStream::StreamType);
67 std::optional<ObjectSerial> findSourceNodeSerial();
68
70
74
75 void stateChanged(pw_stream_state old, pw_stream_state state, const char *error) override;
76 void disconnectStream();
77
78 QSemaphore m_streamDisconnected;
79
80 // xrun detection
81 void xrunOccurred(int /*xrunCount*/) override { m_xrunOccurred.set(); }
82 QtPrivate::QAutoResetEvent m_xrunOccurred;
83 QMetaObject::Connection m_xrunNotification;
84
85 std::optional<AudioCallback> m_audioCallback;
86
87 QPipewireAudioSource *m_parent;
88};
89
90////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
91
92class QPipewireAudioSource final
93 : public QPlatformAudioSourceImplementationWithCallback<QPipewireAudioSourceStream,
94 QPipewireAudioSource>
95{
96 using BaseClass = QPlatformAudioSourceImplementationWithCallback<QPipewireAudioSourceStream,
97 QPipewireAudioSource>;
98
99public:
100 QPipewireAudioSource(QAudioDevice, const QAudioFormat &, QObject *parent);
101 void reportXRuns(int);
102};
103
104} // namespace QtPipeWire
105
106QT_END_NAMESPACE
107
108#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)
QPipewireAudioSource(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
QPipewireAudioSourceStream(QAudioDevice, const QAudioFormat &, std::optional< qsizetype > ringbufferSize, QPipewireAudioSource *parent, float volume, std::optional< int32_t > hardwareBufferFrames)
void stateChanged(pw_stream_state old, pw_stream_state state, const char *error) override
void processCallback() noexcept QT_MM_NONBLOCKING override
void processRingbuffer() noexcept QT_MM_NONBLOCKING override