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
qplatformcamera.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 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
"qplatformcamera_p.h"
5
6
#
include
<
QtMultimedia
/
private
/
qcameradevice_p
.
h
>
7
#
include
<
QtMultimedia
/
private
/
qmultimedia_ranges_p
.
h
>
8
9
QT_BEGIN_NAMESPACE
10
11
namespace
ranges = QtMultimediaPrivate::ranges;
12
13
QPlatformCamera::QPlatformCamera(QObject *parent)
14
: QPlatformVideoSource(parent), m_camera(qobject_cast<QCamera *>(parent))
15
{
16
// TODO: create QPlatformGStreamerElement and use it instead of QPlatformCamera
17
// Then, uncomment the assert
18
Q_ASSERT(parent);
19
qRegisterMetaType<QVideoFrame>();
20
}
21
22
QCameraFormat QPlatformCamera::findBestCameraFormat(
const
QCameraDevice &camera)
const
23
{
24
// check if fmt is better. We try to find the highest resolution that offers
25
// at least 30 FPS
26
// we use 29 FPS to compare against as some cameras report 29.97 FPS...
27
28
auto
makeCriteria = [
this
](
const
QCameraFormat &fmt) {
29
constexpr
float
MinSufficientFrameRate = 29.f;
30
31
const
auto
isValid = fmt.pixelFormat() != QVideoFrameFormat::Format_Invalid;
32
const
auto
resolution = fmt.resolution();
33
const
auto
sufficientFrameRate = std::min(fmt.maxFrameRate(), MinSufficientFrameRate);
34
const
auto
pixelFormatScore =
35
cameraPixelFormatScore(fmt.pixelFormat(), QCameraFormatPrivate::getColorRange(fmt));
36
37
return
std::make_tuple(
38
isValid,
// 1st: ensure valid formats
39
sufficientFrameRate,
// 2nd: ensure the highest frame rate in the range [0; 29]*/
40
resolution.width() * resolution.height(),
// 3rd: ensure the highest resolution
41
pixelFormatScore,
// 4th: eshure the best pixel format
42
fmt.maxFrameRate());
// 5th: ensure the highest framerate in the whole range
43
};
44
45
const
auto
formats = camera.videoFormats();
46
if
(formats.empty())
47
return
QCameraFormat{};
48
49
const
auto
found =
50
ranges::max(formats, [&](
const
QCameraFormat &fmtA,
const
QCameraFormat &fmtB) {
51
return
makeCriteria(fmtA) < makeCriteria(fmtB);
52
});
53
54
return
found;
55
}
56
57
QVideoFrameFormat QPlatformCamera::frameFormat()
const
58
{
59
QVideoFrameFormat result(m_cameraFormat.resolution(),
60
m_framePixelFormat == QVideoFrameFormat::Format_Invalid
61
? m_cameraFormat.pixelFormat()
62
: m_framePixelFormat);
63
result.setStreamFrameRate(m_cameraFormat.maxFrameRate());
64
return
result;
65
}
66
67
void
QPlatformCamera::supportedFeaturesChanged(QCamera::Features f)
68
{
69
if
(m_supportedFeatures == f)
70
return
;
71
m_supportedFeatures = f;
72
Q_EMIT m_camera->supportedFeaturesChanged();
73
}
74
75
void
QPlatformCamera::minimumZoomFactorChanged(
float
factor)
76
{
77
if
(m_minZoom == factor)
78
return
;
79
m_minZoom = factor;
80
Q_EMIT m_camera->minimumZoomFactorChanged(factor);
81
}
82
83
void
QPlatformCamera::maximumZoomFactorChanged(
float
factor)
84
{
85
if
(m_maxZoom == factor)
86
return
;
87
m_maxZoom = factor;
88
Q_EMIT m_camera->maximumZoomFactorChanged(factor);
89
}
90
91
void
QPlatformCamera::focusModeChanged(QCamera::FocusMode mode)
92
{
93
if
(m_focusMode == mode)
94
return
;
95
m_focusMode = mode;
96
Q_EMIT m_camera->focusModeChanged();
97
}
98
99
void
QPlatformCamera::customFocusPointChanged(
const
QPointF &point)
100
{
101
if
(m_customFocusPoint == point)
102
return
;
103
m_customFocusPoint = point;
104
Q_EMIT m_camera->customFocusPointChanged();
105
}
106
107
108
void
QPlatformCamera::zoomFactorChanged(
float
zoom)
109
{
110
if
(m_zoomFactor == zoom)
111
return
;
112
m_zoomFactor = zoom;
113
Q_EMIT m_camera->zoomFactorChanged(zoom);
114
}
115
116
117
void
QPlatformCamera::focusDistanceChanged(
float
d)
118
{
119
if
(m_focusDistance == d)
120
return
;
121
m_focusDistance = d;
122
Q_EMIT m_camera->focusDistanceChanged(m_focusDistance);
123
}
124
125
126
void
QPlatformCamera::flashReadyChanged(
bool
ready)
127
{
128
if
(m_flashReady == ready)
129
return
;
130
m_flashReady = ready;
131
Q_EMIT m_camera->flashReady(m_flashReady);
132
}
133
134
void
QPlatformCamera::flashModeChanged(QCamera::FlashMode mode)
135
{
136
if
(m_flashMode == mode)
137
return
;
138
m_flashMode = mode;
139
Q_EMIT m_camera->flashModeChanged();
140
}
141
142
void
QPlatformCamera::torchModeChanged(QCamera::TorchMode mode)
143
{
144
if
(m_torchMode == mode)
145
return
;
146
m_torchMode = mode;
147
Q_EMIT m_camera->torchModeChanged();
148
}
149
150
void
QPlatformCamera::exposureModeChanged(QCamera::ExposureMode mode)
151
{
152
if
(m_exposureMode == mode)
153
return
;
154
m_exposureMode = mode;
155
Q_EMIT m_camera->exposureModeChanged();
156
}
157
158
void
QPlatformCamera::exposureCompensationChanged(
float
compensation)
159
{
160
if
(m_exposureCompensation == compensation)
161
return
;
162
m_exposureCompensation = compensation;
163
Q_EMIT m_camera->exposureCompensationChanged(compensation);
164
}
165
166
void
QPlatformCamera::exposureCompensationRangeChanged(
float
min,
float
max)
167
{
168
if
(m_minExposureCompensation == min && m_maxExposureCompensation == max)
169
return
;
170
m_minExposureCompensation = min;
171
m_maxExposureCompensation = max;
172
// tell frontend
173
}
174
175
void
QPlatformCamera::isoSensitivityChanged(
int
iso)
176
{
177
if
(m_iso == iso)
178
return
;
179
m_iso = iso;
180
Q_EMIT m_camera->isoSensitivityChanged(iso);
181
}
182
183
void
QPlatformCamera::exposureTimeChanged(
float
speed)
184
{
185
if
(m_exposureTime == speed)
186
return
;
187
m_exposureTime = speed;
188
Q_EMIT m_camera->exposureTimeChanged(speed);
189
}
190
191
void
QPlatformCamera::whiteBalanceModeChanged(QCamera::WhiteBalanceMode mode)
192
{
193
if
(m_whiteBalance == mode)
194
return
;
195
m_whiteBalance = mode;
196
Q_EMIT m_camera->whiteBalanceModeChanged();
197
}
198
199
void
QPlatformCamera::colorTemperatureChanged(
int
temperature)
200
{
201
Q_ASSERT(temperature >= 0);
202
Q_ASSERT((temperature > 0 && whiteBalanceMode() == QCamera::WhiteBalanceManual) ||
203
(temperature == 0 && whiteBalanceMode() == QCamera::WhiteBalanceAuto));
204
if
(m_colorTemperature == temperature)
205
return
;
206
m_colorTemperature = temperature;
207
Q_EMIT m_camera->colorTemperatureChanged();
208
}
209
210
int
QPlatformCamera::colorTemperatureForWhiteBalance(QCamera::WhiteBalanceMode mode)
211
{
212
switch
(mode) {
213
case
QCamera::WhiteBalanceAuto:
214
break
;
215
case
QCamera::WhiteBalanceManual:
216
case
QCamera::WhiteBalanceSunlight:
217
return
5600;
218
case
QCamera::WhiteBalanceCloudy:
219
return
6000;
220
case
QCamera::WhiteBalanceShade:
221
return
7000;
222
case
QCamera::WhiteBalanceTungsten:
223
return
3200;
224
case
QCamera::WhiteBalanceFluorescent:
225
return
4000;
226
case
QCamera::WhiteBalanceFlash:
227
return
5500;
228
case
QCamera::WhiteBalanceSunset:
229
return
3000;
230
}
231
return
0;
232
}
233
234
void
QPlatformCamera::updateError(QCamera::Error error,
const
QString &errorString)
235
{
236
QMetaObject::invokeMethod(
this
, [
this
, error, errorString]() {
237
m_error.setAndNotify(error, errorString, *
this
);
238
});
239
}
240
241
QT_END_NAMESPACE
242
243
#
include
"moc_qplatformcamera_p.cpp"
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtmultimedia
src
multimedia
platform
qplatformcamera.cpp
Generated on
for Qt by
1.18.0