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 bool subscribeToRequestResponse(const QString &handleToken);
71 void unsubscribeFromRequestResponse();
72 void createInterface();
73 void createSession();
74 void selectSources(const QDBusObjectPath &sessionHandle);
75 void startStream();
76 void updateStreams(const QDBusArgument &streamsInfo);
77 void openPipeWireRemote();
78 void closeSession();
79
80private Q_SLOTS:
82 void sessionClosed();
83
84private:
85 const std::shared_ptr<QPipeWireInstance> m_pwInstance;
86
87 QVideoFrame m_currentFrame;
88 QVideoFrameFormat m_videoFrameFormat;
89 QVideoFrameFormat::PixelFormat m_pixelFormat{};
90 QSize m_size;
91
92 PwCoreConnectionHandle m_core;
93
94 PwRegistryHandle m_registry = nullptr;
95
96 PwStreamHandle m_stream = nullptr;
97 spa_hook m_streamListener = {};
98
99 spa_video_info m_format{};
100
101 bool m_err = false;
102 bool m_ignoreStateChange = false;
103 pw_stream_state m_streamState{}; // guarded by pw event loop lock
104 bool m_processed = false;
105
106 QString m_pendingRequestPath;
107 QDBusObjectPath m_sessionHandle;
108 std::unique_ptr<QDBusInterface> m_sessionInterface;
109
110 struct StreamInfo
111 {
112 quint32 nodeId;
113 quint32 sourceType;
114 QRect rect;
115 };
116 QVector<StreamInfo> m_streams;
117
118 std::unique_ptr<QDBusInterface> m_screenCastInterface;
119
120 enum OperationState { NoOperation, CreateSession, SelectSources, StartStream, OpenPipeWireRemote };
121 OperationState m_operationState = NoOperation;
122
123 enum State { NoState, Starting, Streaming, Stopping };
124 State m_state = NoState;
125};
126
127} // namespace QtPipeWire
128
129QT_END_NAMESPACE
130
131#endif // QPIPEWIRE_SCREENCAPTUREHELPER_P_H
constexpr qreal DefaultCaptureFrameRate
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)