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_screencapturehelper_p.h
Go to the documentation of this file.
1// Copyright (C) 2024 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_SCREENCAPTUREHELPER_P_H
5#define QPIPEWIRE_SCREENCAPTUREHELPER_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/qvideoframe.h>
19#include <QtMultimedia/private/qpipewire_screencapture_p.h>
20#include <QtMultimedia/private/qsurfacecapturegrabber_p.h>
21#include <QtMultimedia/private/qpipewire_support_p.h>
22#include <QtDBus/qdbusextratypes.h>
23
24#include <pipewire/pipewire.h>
25#include <spa/param/video/format.h>
26#include <spa/utils/dict.h>
27
28#include <memory>
29
30QT_BEGIN_NAMESPACE
31
32class QDBusArgument;
33class QDBusInterface;
34class QDBusUnixFileDescriptor;
35
36namespace QtPipeWire {
37
38inline constexpr qreal DefaultCaptureFrameRate = 25.f;
39
41
43{
45public:
48
49 bool open(QDBusUnixFileDescriptor);
50
52
53protected:
54 QVideoFrame grabFrame() override;
57
58private:
59 void destroy();
60
61 void onStateChanged(pw_stream_state old, pw_stream_state state, const char *error);
62 void onProcess();
63 void onParamChanged(uint32_t id, const struct spa_pod *param);
64
65 void recreateStream();
66 void destroyStream(bool waitForStreamEnd);
67
68 void signalLoop(bool onProcessDone, bool err);
69
70 QString allocateToken();
71 bool subscribeToRequestResponse(const QString &handleToken);
72 void unsubscribeFromRequestResponse();
73 void createInterface();
74 void createSession();
75 void selectSources(const QDBusObjectPath &sessionHandle);
76 void startStream();
77 void updateStreams(const QDBusArgument &streamsInfo);
78 void openPipeWireRemote();
79 void closeSession();
80
81private Q_SLOTS:
83 void sessionClosed();
84
85private:
86 const std::shared_ptr<QPipeWireInstance> m_pwInstance;
87
88 QVideoFrame m_currentFrame;
89 QVideoFrameFormat m_videoFrameFormat;
90 QVideoFrameFormat::PixelFormat m_pixelFormat{};
91 QSize m_size;
92
93 PwCoreConnectionHandle m_core;
94
95 PwRegistryHandle m_registry = nullptr;
96
97 PwStreamHandle m_stream = nullptr;
98 spa_hook m_streamListener = {};
99
100 spa_video_info m_format{};
101
102 bool m_err = false;
103 bool m_ignoreStateChange = false;
104 pw_stream_state m_streamState{}; // guarded by pw event loop lock
105 bool m_processed = false;
106
107 const QString m_requestTokenPrefix;
108 quint64 m_tokenCounter = 0;
109 QString m_pendingRequestPath;
110 QDBusObjectPath m_sessionHandle;
111 std::unique_ptr<QDBusInterface> m_sessionInterface;
112
113 struct StreamInfo
114 {
115 quint32 nodeId;
116 quint32 sourceType;
117 QRect rect;
118 };
119 QVector<StreamInfo> m_streams;
120
121 std::unique_ptr<QDBusInterface> m_screenCastInterface;
122
123 enum OperationState { NoOperation, CreateSession, SelectSources, StartStream, OpenPipeWireRemote };
124 OperationState m_operationState = NoOperation;
125
126 enum State { NoState, Starting, Streaming, Stopping };
127 State m_state = NoState;
128};
129
130} // namespace QtPipeWire
131
132QT_END_NAMESPACE
133
134#endif // QPIPEWIRE_SCREENCAPTUREHELPER_P_H
constexpr qreal DefaultCaptureFrameRate
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)