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
37inline static constexpr qreal DefaultCaptureFrameRate = 25.f;
38
40
42{
44public:
47
48 bool open(int fd);
49
50 static bool isSupported();
51
53
54 bool setActiveInternal(bool active);
55
56protected:
57 void updateError(QPlatformSurfaceCapture::Error error, const QString &description = {});
58
59private:
60 void destroy();
61
62 void onCoreEventDone(uint32_t id, int seq);
63 void onRegistryEventGlobal(uint32_t id, uint32_t permissions, const char *type, uint32_t version, const spa_dict *props);
64 void onStateChanged(pw_stream_state old, pw_stream_state state, const char *error);
65 void onProcess();
66 void onParamChanged(uint32_t id, const struct spa_pod *param);
67
68 void updateCoreInitSeq();
69
70 void recreateStream();
71 void destroyStream(bool forceDrain);
72
73 void signalLoop(bool onProcessDone, bool err);
74
75 static QVideoFrameFormat::PixelFormat toQtPixelFormat(spa_video_format spaVideoFormat);
76 static spa_video_format toSpaVideoFormat(QVideoFrameFormat::PixelFormat pixelFormat);
77
78 QString getRequestToken();
79 int generateRequestToken();
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 QPipeWireCapture &m_capture;
93
94 QVideoFrame m_currentFrame;
95 QVideoFrameFormat m_videoFrameFormat;
96 QVideoFrameFormat::PixelFormat m_pixelFormat{};
97 QSize m_size;
98 qreal m_streamFrameRate = 0.f;
99
100 PwThreadLoopHandle m_threadLoop;
101 PwContextHandle m_context;
102
103 PwCoreConnectionHandle m_core;
104 spa_hook m_coreListener = {};
105
106 PwRegistryHandle m_registry = nullptr;
107 spa_hook m_registryListener = {};
108
109 PwStreamHandle m_stream = nullptr;
110 spa_hook m_streamListener = {};
111
112 spa_video_info m_format{};
113
114 bool m_err = false;
115 bool m_hasSource = false;
116 bool m_initDone = false;
117 bool m_ignoreStateChange = false;
118 bool m_streamPaused = false;
119 bool m_silence = false;
120 bool m_processed = false;
121
122 int m_coreInitSeq = 0;
123
124 int m_requestToken = -1;
125 QString m_requestTokenPrefix;
126 QString m_sessionHandle;
127
128 struct StreamInfo
129 {
130 quint32 nodeId;
131 quint32 sourceType;
132 QRect rect;
133 };
134 QVector<StreamInfo> m_streams;
135
136 int m_pipewireFd = -1;
137
138 std::unique_ptr<QDBusInterface> m_screenCastInterface;
139
140 enum OperationState { NoOperation, CreateSession, SelectSources, StartStream, OpenPipeWireRemote };
141 OperationState m_operationState = NoOperation;
142
143 enum State { NoState, Starting, Streaming, Stopping };
144 State m_state = NoState;
145};
146
147} // namespace QtPipeWire
148
149QT_END_NAMESPACE
150
151#endif // QPIPEWIRE_SCREENCAPTUREHELPER_P_H
void updateError(QPlatformSurfaceCapture::Error error, const QString &description={})
static constexpr qreal DefaultCaptureFrameRate
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)