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/private/qpipewire_screencapture_p.h>
19#include <QtMultimedia/private/qsurfacecapturegrabber_p.h>
20#include <QtMultimedia/private/qpipewire_support_p.h>
21#include <QtMultimedia/qvideoframe.h>
22
23#include <pipewire/pipewire.h>
24#include <spa/debug/types.h>
25#include <spa/utils/dict.h>
26#include <spa/param/video/format-utils.h>
27#include <spa/param/video/type-info.h>
28
29#include <memory>
30
31QT_BEGIN_NAMESPACE
32
33class QDBusArgument;
34class QDBusInterface;
35
36namespace QtPipeWire {
37
38inline constexpr qreal DefaultCaptureFrameRate = 25.f;
39
41
43{
45public:
48
49 bool open(int fd);
50
51 static bool isSupported();
52
54
55protected:
56 QVideoFrame grabFrame() override;
59
60private:
61 void destroy();
62
63 void onCoreEventDone(uint32_t id, int seq);
64 void onRegistryEventGlobal(uint32_t id, uint32_t permissions, const char *type, uint32_t version, const spa_dict *props);
65 void onStateChanged(pw_stream_state old, pw_stream_state state, const char *error);
66 void onProcess();
67 void onParamChanged(uint32_t id, const struct spa_pod *param);
68
69 void updateCoreInitSeq();
70
71 void recreateStream();
72 void destroyStream(bool forceDrain);
73
74 void signalLoop(bool onProcessDone, bool err);
75
76 static QVideoFrameFormat::PixelFormat toQtPixelFormat(spa_video_format spaVideoFormat);
77 static spa_video_format toSpaVideoFormat(QVideoFrameFormat::PixelFormat pixelFormat);
78
79 QString getRequestToken();
80 void createInterface();
81 void createSession();
82 void selectSources(const QString &sessionHandle);
83 void startStream();
84 void updateStreams(const QDBusArgument &streamsInfo);
85 void openPipeWireRemote();
86
87private Q_SLOTS:
89
90private:
91 std::shared_ptr<QPipeWireInstance> m_instance;
92
93 QVideoFrame m_currentFrame;
94 QVideoFrameFormat m_videoFrameFormat;
95 QVideoFrameFormat::PixelFormat m_pixelFormat{};
96 QSize m_size;
97
98 PwThreadLoopHandle m_threadLoop;
99 PwContextHandle m_context;
100
101 PwCoreConnectionHandle m_core;
102 spa_hook m_coreListener = {};
103
104 PwRegistryHandle m_registry = nullptr;
105 spa_hook m_registryListener = {};
106
107 PwStreamHandle m_stream = nullptr;
108 spa_hook m_streamListener = {};
109
110 spa_video_info m_format{};
111
112 bool m_err = false;
113 bool m_hasSource = false;
114 bool m_initDone = false;
115 bool m_ignoreStateChange = false;
116 bool m_streamPaused = false;
117 bool m_silence = false;
118 bool m_processed = false;
119
120 int m_coreInitSeq = 0;
121
122 int m_requestToken = -1;
123 QString m_requestTokenPrefix;
124 QString m_sessionHandle;
125
126 struct StreamInfo
127 {
128 quint32 nodeId;
129 quint32 sourceType;
130 QRect rect;
131 };
132 QVector<StreamInfo> m_streams;
133
134 int m_pipewireFd = -1;
135
136 std::unique_ptr<QDBusInterface> m_screenCastInterface;
137
138 enum OperationState { NoOperation, CreateSession, SelectSources, StartStream, OpenPipeWireRemote };
139 OperationState m_operationState = NoOperation;
140
141 enum State { NoState, Starting, Streaming, Stopping };
142 State m_state = NoState;
143};
144
145} // namespace QtPipeWire
146
147QT_END_NAMESPACE
148
149#endif // QPIPEWIRE_SCREENCAPTUREHELPER_P_H
constexpr qreal DefaultCaptureFrameRate
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)