Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qpipewirecapturehelper_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 PIPEWIREAPTUREHELPER_P_H
5#define PIPEWIREAPTUREHELPER_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 "qpipewirecapture_p.h"
19
20#include <qvideoframe.h>
21
22#include <spa/debug/types.h>
23#include <spa/utils/dict.h>
24#include <spa/param/video/format-utils.h>
25#include <spa/param/video/type-info.h>
26
27#include <pipewire/pipewire.h>
28
29#include <mutex>
30#include <memory>
31
33
34class QDBusArgument;
35class QDBusInterface;
36namespace QtPipeWire {
37 class Pipewire;
38}
39
41{
43public:
45 ~QPipeWireCaptureHelper() override;
46
47 bool open(int fd);
48
49 static bool isSupported();
50
52
53 bool setActiveInternal(bool active);
54
55 void initPipeWire();
56 void deinitPipeWire();
57
58protected:
59 void updateError(QPlatformSurfaceCapture::Error error, const QString &description = {});
60
61private:
62 void destroy();
63
64 void onCoreEventDone(uint32_t id, int seq);
65 void onRegistryEventGlobal(uint32_t id, uint32_t permissions, const char *type, uint32_t version, const spa_dict *props);
66 void onStateChanged(pw_stream_state old, pw_stream_state state, const char *error);
67 void onProcess();
68 void onParamChanged(uint32_t id, const struct spa_pod *param);
69
70 void updateCoreInitSeq();
71
72 void recreateStream();
73 void destroyStream(bool forceDrain);
74
75 void signalLoop(bool onProcessDone, bool err);
76
77 static QVideoFrameFormat::PixelFormat toQtPixelFormat(spa_video_format spaVideoFormat);
78 static spa_video_format toSpaVideoFormat(QVideoFrameFormat::PixelFormat pixelFormat);
79
80 QString getRequestToken();
81 int generateRequestToken();
82 void createInterface();
83 void createSession();
84 void selectSources(const QString &sessionHandle);
85 void startStream();
86 void updateStreams(const QDBusArgument &streamsInfo);
87 void openPipeWireRemote();
88
89private Q_SLOTS:
90 void gotRequestResponse(uint result, const QVariantMap &map);
91
92private:
93 QPipeWireCapture &m_capture;
94 std::shared_ptr<QtPipeWire::Pipewire> m_pipewire;
95
96 QVideoFrame m_currentFrame;
97 QVideoFrameFormat m_videoFrameFormat;
99 QSize m_size;
100
101 pw_thread_loop *m_threadLoop = nullptr;
102 pw_context *m_context = nullptr;
103
104 pw_core *m_core = nullptr;
105 spa_hook m_coreListener = {};
106
107 pw_registry *m_registry = nullptr;
108 spa_hook m_registryListener = {};
109
110 pw_stream *m_stream = nullptr;
111 spa_hook m_streamListener = {};
112
113 spa_video_info m_format;
114
115 bool m_err = false;
116 bool m_hasSource = false;
117 bool m_initDone = false;
118 bool m_ignoreStateChange = false;
119 bool m_streamPaused = false;
120 bool m_silence = false;
121 bool m_processed = false;
122
123 int m_coreInitSeq = 0;
124
125 int m_requestToken = -1;
126 QString m_requestTokenPrefix;
127 QString m_sessionHandle = {};
128
129 struct StreamInfo
130 {
131 quint32 nodeId;
132 quint32 sourceType;
133 QRect rect;
134 };
135 QVector<StreamInfo> m_streams = {};
136
137 int m_pipewireFd = -1;
138
139 std::unique_ptr<QDBusInterface> m_screenCastInterface;
140
141 enum OperationState { NoOperation, CreateSession, SelectSources, StartStream, OpenPipeWireRemote };
142 OperationState m_operationState = NoOperation;
143
144 enum State { NoState, Starting, Streaming, Stopping };
145 State m_state = NoState;
146};
147
149
150#endif // PIPEWIREAPTUREHELPER_P_H
\inmodule QtDBus
\inmodule QtDBus
\inmodule QtCore
Definition qobject.h:103
QVideoFrameFormat frameFormat() const
QPipeWireCaptureHelper(QPipeWireCapture &capture)
void updateError(QPlatformSurfaceCapture::Error error, const QString &description={})
\inmodule QtCore\reentrant
Definition qrect.h:30
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QVideoFrameFormat class specifies the stream format of a video presentation surface.
PixelFormat
Enumerates video data types.
The QVideoFrame class represents a frame of video data.
Definition qvideoframe.h:27
QMap< QString, QString > map
[6]
else opt state
[0]
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
GLenum type
GLenum GLuint GLsizei const GLenum * props
GLenum const GLint * param
GLuint64 GLenum GLint fd
GLuint64EXT * result
[6]
#define Q_OBJECT
#define Q_SLOTS
unsigned int quint32
Definition qtypes.h:50
unsigned int uint
Definition qtypes.h:34