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