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
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
5
6#include <QtMultimedia/qvideoframe.h>
7#include <QtGui/qguiapplication.h>
8#include <QtCore/qdebug.h>
9
11
12QPlatformSurfaceCapture::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
20void 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
32bool QPlatformSurfaceCapture::isActive() const
33{
34 return m_active;
35}
36
37void 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
72std::optional<QPlatformSurfaceCapture::SourceSwitchResult>
73QPlatformSurfaceCapture::switchActiveSource(const Source &)
74{
75 return std::nullopt;
76}
77
78QPlatformSurfaceCapture::Error QPlatformSurfaceCapture::error() const
79{
80 return m_error.code();
81}
82
83QString QPlatformSurfaceCapture::errorString() const
84{
85 return m_error.description();
86}
87
88void 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
97std::optional<qreal> QPlatformSurfaceCapture::frameRate() const
98{
99 return m_frameRate;
100}
101
102void QPlatformSurfaceCapture::setIgnoreCursor(bool ignore)
103{
104 m_ignoreCursor = ignore;
105}
106
107bool QPlatformSurfaceCapture::ignoreCursor() const
108{
109 return m_ignoreCursor;
110}
111
112void QPlatformSurfaceCapture::updateError(Error error, const QString &errorString)
113{
114 m_error.setAndNotify(error, errorString, *this);
115}
116
117bool 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
129QT_END_NAMESPACE
130
131#include "moc_qplatformsurfacecapture_p.cpp"
Combined button and popup list for selecting options.