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 <QtMultimedia/private/qaudio_platform_implementation_support_p.h>
19#include <QtMultimedia/private/qaudiosystem_p.h>
20#include <QtMultimedia/private/qaudiosystem_platform_stream_support_p.h>
21#include <QtMultimedia/private/qpipewire_audiostream_p.h>
22#include <QtCore/qsemaphore.h>
23#include <QtCore/qtclasshelpermacros.h>
24
25QT_BEGIN_NAMESPACE
26
27namespace QtPipeWire {
28
29using namespace QtMultimediaPrivate;
30
31class QPipewireAudioSource;
32
33////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
34
35// LATER:
36// ideally the ringbuffer should fill a buffer that can grow via a worker thread on which we can
37// allocate.
39{
40 using SourceType = QPipewireAudioSource;
42
43 QPipewireAudioSourceStream(QAudioDevice, const QAudioFormat &,
44 std::optional<qsizetype> ringbufferSize,
45 QPipewireAudioSource *parent, float volume,
46 std::optional<int32_t> hardwareBufferFrames);
49
50 bool open() { return true; }
51 bool start(QIODevice *device);
53 bool start(AudioCallback &&);
54 void stop(ShutdownPolicy);
55
61
62 void updateStreamIdle(bool idle) override;
63
64private:
65 void createStream(QPipewireAudioStream::StreamType);
66 std::optional<ObjectSerial> findSourceNodeSerial();
67
69
70 // QPipewireAudioSourceStream overrides
74 void stateChanged(pw_stream_state old, pw_stream_state state, const char *error) override;
76
77 void disconnectStream();
78
79 QSemaphore m_streamDisconnected;
80
81 // xrun detection
82 void xrunOccurred(int /*xrunCount*/) override { m_xrunOccurred.set(); }
83 QtPrivate::QAutoResetEvent m_xrunOccurred;
84 QMetaObject::Connection m_xrunNotification;
85
86 std::optional<AudioCallback> m_audioCallback;
87
88 QPipewireAudioSource *m_parent;
89};
90
91////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
92
93class QPipewireAudioSource final
94 : public QPlatformAudioSourceImplementationWithCallback<QPipewireAudioSourceStream,
95 QPipewireAudioSource>
96{
97 using BaseClass = QPlatformAudioSourceImplementationWithCallback<QPipewireAudioSourceStream,
98 QPipewireAudioSource>;
99
100public:
101 QPipewireAudioSource(QAudioDevice, const QAudioFormat &, QObject *parent);
103
104 void reportXRuns(int);
105};
106
107} // namespace QtPipeWire
108
109QT_END_NAMESPACE
110
111#endif
QPipewireAudioSource(QAudioDevice, const QAudioFormat &, QObject *parent)
Combined button and popup list for selecting options.
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