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
71 // QPipewireAudioSourceStream overrides
75 void stateChanged(pw_stream_state old, pw_stream_state state, const char *error) override;
77
78 void disconnectStream();
79
80 QSemaphore m_streamDisconnected;
81
82 // xrun detection
83 void xrunOccurred(int /*xrunCount*/) override { m_xrunOccurred.set(); }
84 QtPrivate::QAutoResetEvent m_xrunOccurred;
85 QMetaObject::Connection m_xrunNotification;
86
87 std::optional<AudioCallback> m_audioCallback;
88
89 QPipewireAudioSource *m_parent;
90};
91
92////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
93
94class QPipewireAudioSource final
95 : public QPlatformAudioSourceImplementationWithCallback<QPipewireAudioSourceStream,
96 QPipewireAudioSource>
97{
98 using BaseClass = QPlatformAudioSourceImplementationWithCallback<QPipewireAudioSourceStream,
99 QPipewireAudioSource>;
100
101public:
102 QPipewireAudioSource(QAudioDevice, const QAudioFormat &, QObject *parent);
104
105 void reportXRuns(int);
106};
107
108} // namespace QtPipeWire
109
110QT_END_NAMESPACE
111
112#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)
Combined button and popup list for selecting options.
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