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
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#include "private/qcameradevice_p.h"
6
8
10{
11 qRegisterMetaType<QVideoFrame>();
12}
13
15{
16 // check if fmt is better. We try to find the highest resolution that offers
17 // at least 30 FPS
18 // we use 29 FPS to compare against as some cameras report 29.97 FPS...
19
20 auto makeCriteria = [this](const QCameraFormat &fmt) {
21 constexpr float MinSufficientFrameRate = 29.f;
22
23 const auto isValid = fmt.pixelFormat() != QVideoFrameFormat::Format_Invalid;
24 const auto resolution = fmt.resolution();
25 const auto sufficientFrameRate = std::min(fmt.maxFrameRate(), MinSufficientFrameRate);
26 const auto pixelFormatScore =
28
29 return std::make_tuple(
30 isValid, // 1st: ensure valid formats
31 sufficientFrameRate, // 2nd: ensure the highest frame rate in the range [0; 29]*/
32 resolution.width() * resolution.height(), // 3rd: ensure the highest resolution
33 pixelFormatScore, // 4th: eshure the best pixel format
34 fmt.maxFrameRate()); // 5th: ensure the highest framerate in the whole range
35 };
36
37 const auto formats = camera.videoFormats();
38 const auto found =
39 std::max_element(formats.begin(), formats.end(),
40 [makeCriteria](const QCameraFormat &fmtA, const QCameraFormat &fmtB) {
41 return makeCriteria(fmtA) < makeCriteria(fmtB);
42 });
43
44 return found == formats.end() ? QCameraFormat{} : *found;
45}
46
56
58{
59 if (m_supportedFeatures == f)
60 return;
61 m_supportedFeatures = f;
63}
64
66{
67 if (m_minZoom == factor)
68 return;
69 m_minZoom = factor;
70 emit m_camera->minimumZoomFactorChanged(factor);
71}
72
74{
75 if (m_maxZoom == factor)
76 return;
77 m_maxZoom = factor;
78 emit m_camera->maximumZoomFactorChanged(factor);
79}
80
82{
83 if (m_focusMode == mode)
84 return;
85 m_focusMode = mode;
86 emit m_camera->focusModeChanged();
87}
88
90{
91 if (m_customFocusPoint == point)
92 return;
93 m_customFocusPoint = point;
94 emit m_camera->customFocusPointChanged();
95}
96
97
99{
100 if (m_zoomFactor == zoom)
101 return;
102 m_zoomFactor = zoom;
103 emit m_camera->zoomFactorChanged(zoom);
104}
105
106
108{
109 if (m_focusDistance == d)
110 return;
111 m_focusDistance = d;
112 emit m_camera->focusDistanceChanged(m_focusDistance);
113}
114
115
117{
118 if (m_flashReady == ready)
119 return;
120 m_flashReady = ready;
121 emit m_camera->flashReady(m_flashReady);
122}
123
125{
126 if (m_flashMode == mode)
127 return;
128 m_flashMode = mode;
129 emit m_camera->flashModeChanged();
130}
131
133{
134 if (m_torchMode == mode)
135 return;
136 m_torchMode = mode;
137 emit m_camera->torchModeChanged();
138}
139
141{
142 if (m_exposureMode == mode)
143 return;
144 m_exposureMode = mode;
145 emit m_camera->exposureModeChanged();
146}
147
149{
150 if (m_exposureCompensation == compensation)
151 return;
152 m_exposureCompensation = compensation;
153 emit m_camera->exposureCompensationChanged(compensation);
154}
155
157{
158 if (m_minExposureCompensation == min && m_maxExposureCompensation == max)
159 return;
160 m_minExposureCompensation = min;
161 m_maxExposureCompensation = max;
162 // tell frontend
163}
164
166{
167 if (m_iso == iso)
168 return;
169 m_iso = iso;
170 emit m_camera->isoSensitivityChanged(iso);
171}
172
174{
175 if (m_exposureTime == speed)
176 return;
177 m_exposureTime = speed;
178 emit m_camera->exposureTimeChanged(speed);
179}
180
182{
183 if (m_whiteBalance == mode)
184 return;
185 m_whiteBalance = mode;
186 emit m_camera->whiteBalanceModeChanged();
187}
188
190{
191 Q_ASSERT(temperature >= 0);
192 Q_ASSERT((temperature > 0 && whiteBalanceMode() == QCamera::WhiteBalanceManual) ||
193 (temperature == 0 && whiteBalanceMode() == QCamera::WhiteBalanceAuto));
194 if (m_colorTemperature == temperature)
195 return;
196 m_colorTemperature = temperature;
197 emit m_camera->colorTemperatureChanged();
198}
199
201{
202 switch (mode) {
204 break;
207 return 5600;
209 return 6000;
211 return 7000;
213 return 3200;
215 return 4000;
217 return 5500;
219 return 3000;
220 }
221 return 0;
222}
223
225{
227 m_error.setAndNotify(error, errorString, *this);
228 });
229}
230
232
233#include "moc_qplatformcamera_p.cpp"
The QCameraDevice class provides general information about camera devices.
static QVideoFrameFormat::ColorRange getColorRange(const QCameraFormat &format)
The QCameraFormat class describes a video format supported by a camera device. \inmodule QtMultimedia...
QSize resolution
\qmlproperty size QtMultimedia::cameraFormat::resolution
QVideoFrameFormat::PixelFormat pixelFormat
\qmlproperty enumeration QtMultimedia::cameraFormat::pixelFormat
float maxFrameRate
\qmlproperty real QtMultimedia::cameraFormat::maxFrameRate
The QCamera class provides interface for system camera devices.
Definition qcamera.h:28
WhiteBalanceMode
\value WhiteBalanceAuto Auto white balance mode.
Definition qcamera.h:112
@ WhiteBalanceShade
Definition qcamera.h:117
@ WhiteBalanceCloudy
Definition qcamera.h:116
@ WhiteBalanceSunset
Definition qcamera.h:121
@ WhiteBalanceManual
Definition qcamera.h:114
@ WhiteBalanceSunlight
Definition qcamera.h:115
@ WhiteBalanceFlash
Definition qcamera.h:120
@ WhiteBalanceTungsten
Definition qcamera.h:118
@ WhiteBalanceFluorescent
Definition qcamera.h:119
@ WhiteBalanceAuto
Definition qcamera.h:113
TorchMode
\value TorchOff Torch is Off.
Definition qcamera.h:84
void exposureModeChanged()
void focusDistanceChanged(float)
FocusMode
\value FocusModeAuto Continuous auto focus mode.
Definition qcamera.h:67
void customFocusPointChanged()
void maximumZoomFactorChanged(float)
void flashModeChanged()
void exposureCompensationChanged(float)
Signal emitted when the exposure compensation changes to value.
void exposureTimeChanged(float speed)
Signals that a camera's exposure speed has changed.
void supportedFeaturesChanged()
void focusModeChanged()
Signals when the focusMode changes.
void colorTemperatureChanged() QT6_ONLY(const)
void whiteBalanceModeChanged() QT6_ONLY(const)
void minimumZoomFactorChanged(float)
FlashMode
\value FlashOff Flash is Off.
Definition qcamera.h:77
void torchModeChanged()
ExposureMode
\value ExposureAuto Automatic mode.
Definition qcamera.h:91
void zoomFactorChanged(float)
bool flashReady
\qmlproperty bool QtMultimedia::Camera::flashReady
Definition qcamera.h:51
Error
This enum holds the last error code.
Definition qcamera.h:61
void isoSensitivityChanged(int)
Signal emitted when sensitivity changes to value.
void setAndNotify(ErrorCode code, QString description, Notifier &notifier)
QVideoFrameFormat::PixelFormat m_framePixelFormat
QCameraFormat findBestCameraFormat(const QCameraDevice &camera) const
void isoSensitivityChanged(int iso)
void updateError(QCamera::Error error, const QString &errorString)
void torchModeChanged(QCamera::TorchMode mode)
QString errorString() const final
void flashReadyChanged(bool)
QCamera::WhiteBalanceMode whiteBalanceMode() const
void focusModeChanged(QCamera::FocusMode mode)
void exposureCompensationChanged(float compensation)
void whiteBalanceModeChanged(QCamera::WhiteBalanceMode mode)
void focusDistanceChanged(float d)
static int colorTemperatureForWhiteBalance(QCamera::WhiteBalanceMode mode)
void maximumZoomFactorChanged(float)
void customFocusPointChanged(const QPointF &point)
void flashModeChanged(QCamera::FlashMode mode)
void zoomFactorChanged(float zoom)
void colorTemperatureChanged(int temperature)
QVideoFrameFormat frameFormat() const override
virtual int cameraPixelFormatScore(QVideoFrameFormat::PixelFormat, QVideoFrameFormat::ColorRange) const
QPlatformCamera(QCamera *parent)
void exposureModeChanged(QCamera::ExposureMode mode)
void supportedFeaturesChanged(QCamera::Features)
void minimumZoomFactorChanged(float factor)
QCamera::Error error() const
void exposureCompensationRangeChanged(float min, float max)
QCameraFormat m_cameraFormat
void exposureTimeChanged(float speed)
\inmodule QtCore\reentrant
Definition qpoint.h:217
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QVideoFrameFormat class specifies the stream format of a video presentation surface.
void setStreamFrameRate(qreal rate)
Sets the frame rate of a video stream in frames per second.
QCamera * camera
Definition camera.cpp:19
EGLint EGLint * formats
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
GLenum mode
GLfloat GLfloat f
GLuint64EXT * result
[6]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define emit
QVideoFrameFormat::PixelFormat fmt
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(nullptr), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
\threadsafe This is an overloaded member function, provided for convenience. It differs from the abov...