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
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
27QT_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*/
36struct 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*/
86{
87public:
90
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 */
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
111private:
112 class Private;
113 std::unique_ptr<Private> d;
114};
115
116QT_END_NAMESPACE
117
118#endif // QSYNTHETICPIPEWIREVIDEOSOURCE_P_H
std::vector< QtPipeWire::PwProxyHandle > links
static void onStateChanged(void *userData, pw_stream_state, pw_stream_state state, const char *error)
static void onParamChanged(void *userData, uint32_t id, const spa_pod *param)
void considerPort(ObjectId port, uint32_t consumerNode)
Decides whether port, belonging to consumerNode, is meant for us, and links it if so.
static void onRegistryGlobal(void *userData, uint32_t id, uint32_t permissions, const char *type, uint32_t version, const spa_dict *props)
std::optional< QtPipeWire::PWThreadedEventLoop > threadLoop
QtPipeWire::ObjectId nodeId() const
The PipeWire node id to hand to a consumer. Valid only after a successful start().
void setScene(const SyntheticVideoScene &scene)
Replaces the published content. Safe to call from any thread.
void renderNextFrame()
Renders and publishes the next frame. Safe to call from any thread.