Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qsyntheticpipewirevideosource_p.h
Go to the documentation of this file.
1
// Copyright (C) 2026 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4
#
ifndef
QSYNTHETICPIPEWIREVIDEOSOURCE_P_H
5
#
define
QSYNTHETICPIPEWIREVIDEOSOURCE_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
/
qpipewire_support_p
.
h
>
19
#
include
<
QtCore
/
qobject
.
h
>
20
#
include
<
QtCore
/
qstring
.
h
>
21
#
include
<
QtCore
/
private
/
qexpected_p
.
h
>
22
23
#
include
<
private
/
qsyntheticvideoscene_p
.
h
>
24
25
#
include
<
memory
>
26
27
QT_BEGIN_NAMESPACE
28
29
/*!
30
\internal
31
Identity of a synthetic source: what it advertises to the PipeWire graph.
32
33
media.role is load-bearing, not cosmetic. It is how the source decides which
34
consumers are meant for it -- see QSyntheticPipeWireVideoSource.
35
*/
36
struct
QSyntheticPipeWireVideoSourceConfig
37
{
38
QByteArray loopName = QByteArrayLiteral(
"qt-fake-sc"
);
39
QByteArray nodeName = QByteArrayLiteral(
"qt-fake-screencast"
);
40
QByteArray nodeDescription = QByteArrayLiteral(
"Qt Multimedia synthetic screen cast source"
);
41
QByteArray mediaClass = QByteArrayLiteral(
"Stream/Output/Video"
);
42
QByteArray mediaRole = QByteArrayLiteral(
"Screen"
);
43
QByteArray mediaCategory = QByteArrayLiteral(
"Capture"
);
44
45
//! A screen-cast source, as xdg-desktop-portal's ScreenCast interface hands out.
46
[[nodiscard]]
static
QSyntheticPipeWireVideoSourceConfig screenCast();
47
48
/*!
49
A camera source, as the Camera interface hands out: media.class Video/Source
50
plus media.role Camera. device.api is deliberately left unset, so that a
51
client identifying cameras exercises the media.role branch -- the one a real
52
camera portal hits -- rather than the v4l2/libcamera hardware fallback.
53
*/
54
[[nodiscard]]
static
QSyntheticPipeWireVideoSourceConfig camera(
int
index = 0);
55
};
56
57
/*!
58
\internal
59
60
A synthetic PipeWire video source: an output pw_stream advertising
61
\c {media.class = Stream/Output/Video} that publishes frames rendered by
62
paintSyntheticVideoScene(). It stands in for a compositor's screen-cast stream,
63
so QPipeWireCaptureHelper can be exercised without a real desktop portal.
64
65
The pixel format is fixed to SPA_VIDEO_FORMAT_BGRx, which maps to
66
QVideoFrameFormat::Format_BGRX8888 on the consuming side and is byte-identical
67
to QImage::Format_RGB32 on little-endian, avoiding a pixel format conversion.
68
69
The source also acts as its own session manager: when it is used against a
70
private pipewire daemon there is no WirePlumber, so nothing honours
71
PW_STREAM_FLAG_AUTOCONNECT and the consumer would sit in "paused" forever.
72
The source therefore links itself, via the link-factory, to consumers meant
73
for it.
74
75
Which consumers are "meant for it" is determined by matching media.role, not
76
by the target passed to pw_stream_connect(): PipeWire consumes that target
77
internally, and the resulting consumer node advertises neither target.object
78
nor node.target. media.role is the one property a consumer does advertise --
79
QPipeWireCaptureHelper sets Screen, a camera client sets Camera -- so the
80
source links only consumer nodes whose media.role matches its own. This
81
matters as soon as one graph holds both a screen-cast and a camera source:
82
matching by media.role is what keeps camera frames from being linked to a
83
screen-capture client.
84
*/
85
class
QSyntheticPipeWireVideoSource
86
{
87
public
:
88
QSyntheticPipeWireVideoSource
();
89
~
QSyntheticPipeWireVideoSource
();
90
91
Q_DISABLE_COPY_MOVE
(
QSyntheticPipeWireVideoSource
)
92
93
/*!
94
Connects to the PipeWire daemon and publishes the source. Blocks until the
95
node id is known, so that nodeId() is usable as soon as this returns.
96
*/
97
q23
::
expected
<
void
,
QString
>
start
(
const
SyntheticVideoScene
&
scene
,
98
const
QSyntheticPipeWireVideoSourceConfig
&
config
=
99
QSyntheticPipeWireVideoSourceConfig
::
screenCast
());
100
void
stop
();
101
102
//! The PipeWire node id to hand to a consumer. Valid only after a successful start().
103
[[nodiscard]]
QtPipeWire
::
ObjectId
nodeId
()
const
;
104
105
//! Replaces the published content. Safe to call from any thread.
106
void
setScene
(
const
SyntheticVideoScene &scene);
107
108
//! Renders and publishes the next frame. Safe to call from any thread.
109
void
renderNextFrame
();
110
111
private
:
112
class
Private
;
113
std::unique_ptr<Private> d;
114
};
115
116
QT_END_NAMESPACE
117
118
#
endif
// QSYNTHETICPIPEWIREVIDEOSOURCE_P_H
QSyntheticPipeWireVideoSource::Private
Definition
qsyntheticpipewirevideosource.cpp:63
QSyntheticPipeWireVideoSource::Private::streamListener
spa_hook streamListener
Definition
qsyntheticpipewirevideosource.cpp:86
QSyntheticPipeWireVideoSource::Private::config
QSyntheticPipeWireVideoSourceConfig config
Definition
qsyntheticpipewirevideosource.cpp:78
QSyntheticPipeWireVideoSource::Private::tick
unsigned tick
Definition
qsyntheticpipewirevideosource.cpp:102
QSyntheticPipeWireVideoSource::Private::nodeId
ObjectId nodeId
Definition
qsyntheticpipewirevideosource.cpp:88
QSyntheticPipeWireVideoSource::Private::registryListener
spa_hook registryListener
Definition
qsyntheticpipewirevideosource.cpp:84
QSyntheticPipeWireVideoSource::Private::links
std::vector< QtPipeWire::PwProxyHandle > links
Definition
qsyntheticpipewirevideosource.cpp:97
QSyntheticPipeWireVideoSource::Private::mismatchWarned
std::unordered_set< uint32_t > mismatchWarned
Definition
qsyntheticpipewirevideosource.cpp:96
QSyntheticPipeWireVideoSource::Private::scene
SyntheticVideoScene scene
Definition
qsyntheticpipewirevideosource.cpp:100
QSyntheticPipeWireVideoSource::Private::started
bool started
Definition
qsyntheticpipewirevideosource.cpp:104
QSyntheticPipeWireVideoSource::Private::onStateChanged
static void onStateChanged(void *userData, pw_stream_state, pw_stream_state state, const char *error)
Definition
qsyntheticpipewirevideosource.cpp:107
QSyntheticPipeWireVideoSource::Private::core
QtPipeWire::PwCoreConnectionHandle core
Definition
qsyntheticpipewirevideosource.cpp:82
QSyntheticPipeWireVideoSource::Private::sceneMutex
QMutex sceneMutex
Definition
qsyntheticpipewirevideosource.cpp:99
QSyntheticPipeWireVideoSource::Private::onParamChanged
static void onParamChanged(void *userData, uint32_t id, const spa_pod *param)
Definition
qsyntheticpipewirevideosource.cpp:126
QSyntheticPipeWireVideoSource::Private::context
QtPipeWire::PwContextHandle context
Definition
qsyntheticpipewirevideosource.cpp:81
QSyntheticPipeWireVideoSource::Private::frame
QImage frame
Definition
qsyntheticpipewirevideosource.cpp:101
QSyntheticPipeWireVideoSource::Private::stream
QtPipeWire::PwStreamHandle stream
Definition
qsyntheticpipewirevideosource.cpp:85
QSyntheticPipeWireVideoSource::Private::considerPort
void considerPort(ObjectId port, uint32_t consumerNode)
Decides whether port, belonging to consumerNode, is meant for us, and links it if so.
Definition
qsyntheticpipewirevideosource.cpp:226
QSyntheticPipeWireVideoSource::Private::registry
QtPipeWire::PwRegistryHandle registry
Definition
qsyntheticpipewirevideosource.cpp:83
QSyntheticPipeWireVideoSource::Private::outputPort
ObjectId outputPort
Definition
qsyntheticpipewirevideosource.cpp:89
QSyntheticPipeWireVideoSource::Private::linkTo
void linkTo(ObjectId inputPort)
Definition
qsyntheticpipewirevideosource.cpp:195
QSyntheticPipeWireVideoSource::Private::consumerRoles
QHash< uint32_t, QByteArray > consumerRoles
Definition
qsyntheticpipewirevideosource.cpp:95
QSyntheticPipeWireVideoSource::Private::onRegistryGlobal
static void onRegistryGlobal(void *userData, uint32_t id, uint32_t permissions, const char *type, uint32_t version, const spa_dict *props)
Definition
qsyntheticpipewirevideosource.cpp:243
QSyntheticPipeWireVideoSource::Private::threadLoop
std::optional< QtPipeWire::PWThreadedEventLoop > threadLoop
Definition
qsyntheticpipewirevideosource.cpp:80
QSyntheticPipeWireVideoSource::Private::onProcess
static void onProcess(void *userData)
Definition
qsyntheticpipewirevideosource.cpp:157
QSyntheticPipeWireVideoSource
Definition
qsyntheticpipewirevideosource_p.h:86
QSyntheticPipeWireVideoSource::nodeId
QtPipeWire::ObjectId nodeId() const
The PipeWire node id to hand to a consumer. Valid only after a successful start().
Definition
qsyntheticpipewirevideosource.cpp:438
QSyntheticPipeWireVideoSource::QSyntheticPipeWireVideoSource
QSyntheticPipeWireVideoSource()
Definition
qsyntheticpipewirevideosource.cpp:299
QSyntheticPipeWireVideoSource::stop
void stop()
Definition
qsyntheticpipewirevideosource.cpp:416
QSyntheticPipeWireVideoSource::~QSyntheticPipeWireVideoSource
~QSyntheticPipeWireVideoSource()
Definition
qsyntheticpipewirevideosource.cpp:301
QSyntheticPipeWireVideoSource::setScene
void setScene(const SyntheticVideoScene &scene)
Replaces the published content. Safe to call from any thread.
Definition
qsyntheticpipewirevideosource.cpp:443
QSyntheticPipeWireVideoSource::renderNextFrame
void renderNextFrame()
Renders and publishes the next frame. Safe to call from any thread.
Definition
qsyntheticpipewirevideosource.cpp:451
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qtmultimedia
src
multimediatestlib
qsyntheticpipewirevideosource_p.h
Generated on
for Qt by
1.18.0