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
20
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
39
41{
43public:
46
47 bool open(int fd);
48
49 static bool isSupported();
50
52
53 bool setActiveInternal(bool active);
54
55protected:
56 void updateError(QPlatformSurfaceCapture::Error error, const QString &description = {});
57
58private:
59 void destroy();
60
61 void onCoreEventDone(uint32_t id, int seq);
62 void onRegistryEventGlobal(uint32_t id, uint32_t permissions, const char *type, uint32_t version, const spa_dict *props);
63 void onStateChanged(pw_stream_state old, pw_stream_state state, const char *error);
64 void onProcess();
65 void onParamChanged(uint32_t id, const struct spa_pod *param);
66
67 void updateCoreInitSeq();
68
69 void recreateStream();
70 void destroyStream(bool forceDrain);
71
72 void signalLoop(bool onProcessDone, bool err);
73
74 static QVideoFrameFormat::PixelFormat toQtPixelFormat(spa_video_format spaVideoFormat);
75 static spa_video_format toSpaVideoFormat(QVideoFrameFormat::PixelFormat pixelFormat);
76
77 QString getRequestToken();
78 int generateRequestToken();
79 void createInterface();
80 void createSession();
81 void selectSources(const QString &sessionHandle);
82 void startStream();
83 void updateStreams(const QDBusArgument &streamsInfo);
84 void openPipeWireRemote();
85
86private Q_SLOTS:
88
89private:
90 std::shared_ptr<QPipeWireInstance> m_instance;
91 QPipeWireCapture &m_capture;
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
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
void updateError(QPlatformSurfaceCapture::Error error, const QString &description={})
std::unique_ptr< pw_core, PwCoreConnectionDeleter > PwCoreConnectionHandle