Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qplatformsurfacecapture.cpp
Go to the documentation of this file.
1
// Copyright (C) 2022 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
#
include
"qplatformsurfacecapture_p.h"
5
6
#
include
<
QtMultimedia
/
qvideoframe
.
h
>
7
#
include
<
QtGui
/
qguiapplication
.
h
>
8
#
include
<
QtCore
/
qdebug
.
h
>
9
10
QT_BEGIN_NAMESPACE
11
12
QPlatformSurfaceCapture::QPlatformSurfaceCapture(Source initialSource) : m_source(initialSource)
13
{
14
Q_ASSERT(std::visit([](
const
auto
&source) {
15
return
source ==
decltype
(source){};
16
}, initialSource));
17
qRegisterMetaType<QVideoFrame>();
18
}
19
20
void
QPlatformSurfaceCapture::setActive(
bool
active)
21
{
22
if
(m_active == active)
23
return
;
24
25
if
(!setActiveInternal(active))
26
return
;
27
28
m_active = active;
29
Q_EMIT activeChanged(active);
30
}
31
32
bool
QPlatformSurfaceCapture::isActive()
const
33
{
34
return
m_active;
35
}
36
37
void
QPlatformSurfaceCapture::setSource(Source source)
38
{
39
Q_ASSERT(source.index() == m_source.index());
40
41
if
(m_source == source)
42
return
;
43
44
if
(!m_active) {
45
m_source = std::move(source);
46
}
else
if
(
const
std::optional<SourceSwitchResult> result = switchActiveSource(source)) {
47
m_source = std::move(source);
48
49
if
(!*result) {
50
setActiveInternal(
false
);
51
updateError(result->error().error, result->error().description);
52
m_active =
false
;
53
Q_EMIT activeChanged(
false
);
54
}
55
}
else
{
56
// Switching is not supported, so restart the stream with the new source.
57
setActiveInternal(
false
);
58
59
m_source = std::move(source);
60
61
if
(!setActiveInternal(
true
)) {
62
m_active =
false
;
63
Q_EMIT activeChanged(
false
);
64
}
65
}
66
67
std::visit([
this
](
const
auto
&source) {
68
Q_EMIT sourceChanged(source);
69
}, m_source);
70
}
71
72
std::optional<QPlatformSurfaceCapture::SourceSwitchResult>
73
QPlatformSurfaceCapture::switchActiveSource(
const
Source &)
74
{
75
return
std::nullopt;
76
}
77
78
QPlatformSurfaceCapture::Error QPlatformSurfaceCapture::error()
const
79
{
80
return
m_error.code();
81
}
82
83
QString QPlatformSurfaceCapture::errorString()
const
84
{
85
return
m_error.description();
86
}
87
88
void
QPlatformSurfaceCapture::setFrameRate(std::optional<qreal> frameRate)
89
{
90
if
(m_frameRate == frameRate)
91
return
;
92
93
m_frameRate = frameRate;
94
Q_EMIT frameRateChanged(m_frameRate);
95
}
96
97
std::optional<qreal> QPlatformSurfaceCapture::frameRate()
const
98
{
99
return
m_frameRate;
100
}
101
102
void
QPlatformSurfaceCapture::setIgnoreCursor(
bool
ignore)
103
{
104
m_ignoreCursor = ignore;
105
}
106
107
bool
QPlatformSurfaceCapture::ignoreCursor()
const
108
{
109
return
m_ignoreCursor;
110
}
111
112
void
QPlatformSurfaceCapture::updateError(Error error,
const
QString &errorString)
113
{
114
m_error.setAndNotify(error, errorString, *
this
);
115
}
116
117
bool
QPlatformSurfaceCapture::checkScreenWithError(ScreenSource &screen)
118
{
119
if
(!screen)
120
screen = QGuiApplication::primaryScreen();
121
122
if
(screen)
123
return
true
;
124
125
updateError(Error::NotFound, QLatin1String(
"No screens found"
));
126
return
false
;
127
}
128
129
QT_END_NAMESPACE
130
131
#
include
"moc_qplatformsurfacecapture_p.cpp"
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtmultimedia
src
multimedia
platform
qplatformsurfacecapture.cpp
Generated on
for Qt by
1.18.0