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
qplatformcamera_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 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 QPLATFORMCAMERA_H
5#define QPLATFORMCAMERA_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 <QtMultimedia/private/qerrorinfo_p.h>
19#include <QtMultimedia/private/qplatformvideosource_p.h>
20#include <QtMultimedia/qcamera.h>
21
22// NOLINTBEGIN (bugprone-reserved-identifier)
23typedef struct _GstElement GstElement;
24// NOLINTEND (bugprone-reserved-identifier)
25
27
28class Q_MULTIMEDIA_EXPORT QPlatformCamera : public QPlatformVideoSource
29{
30 Q_OBJECT
31
32public:
33 // If the new camera-device is the same as the old camera-device,
34 // do nothing.
35 //
36 // The implementation needs to handle other camera properties during a successful
37 // camera-device-change. This should be done for every property, i.e focusMode,
38 // flashMode, focusDistance, zoom etc.
39 //
40 // The properties should be handled in the following way:
41 // - If property is supported on new device, apply the property to the device immediately.
42 // - If property is supported on new device, but range of valid values has changed,
43 // clamp the property and apply it to the camera-device.
44 // - If property is NOT supported on new device, reset the value to default and do
45 // nothing to the camera-device.
46 //
47 // TODO: There is currently no rules on the order of how each signal should be triggered.
48 // In the future we might want to add a rule that requires the implementation
49 // to update all properties at once, then trigger all relevant signals.
50 //
51 // TODO: There are currently no rules in the public API on how we should handle
52 // devices being disconnected or the user passing in an invalid device-id.
53 virtual void setCamera(const QCameraDevice &camera) = 0;
54 virtual bool setCameraFormat(const QCameraFormat &/*format*/) { return false; }
55 QCameraFormat cameraFormat() const { return m_cameraFormat; }
56
57 // FocusModeManual should only be reported as supported if the camera
58 // backend is also able to apply the focusDistance setting.
59 // This effectively means the backend should also report Feature::FocusDistance
60 // as supported if this is the case.
61 virtual bool isFocusModeSupported(QCamera::FocusMode mode) const { return mode == QCamera::FocusModeAuto; }
62
63 // If the focusMode is the same as the current, ignore the function call.
64 //
65 // If the new focusMode is reported as unsupported, send a warning
66 // and do nothing.
67 //
68 // FocusModeAuto should map to continuous autofocus mode in the backend.
69 // FocusModeManual should be treated as fixed lens position
70 // in the backend.
71 //
72 // If the new mode is FocusModeManual, apply the focusDistance setting.
73 //
74 // This function should call QPlatformCamera::focusModeChanged if
75 // successful.
76 virtual void setFocusMode(QCamera::FocusMode /*mode*/) {}
77
78 virtual void setCustomFocusPoint(const QPointF &/*point*/) {}
79
80 // If the new distance is the same as previous, ignore the function call.
81 //
82 // If supportedFeatures does not include the FocusDistance flag,
83 // send a warning and do nothing.
84 //
85 // If the incoming value is out of bounds (outside [0,1]),
86 // send a warning and do nothing.
87 //
88 // If focusMode is set to Manual, apply this focusDistance to the camera.
89 // If not, accept the value but don't apply it to the camera.
90 //
91 // The value 0 maps to the distance closest to the camera.
92 // The value 1 maps to the distance furthest away from the camera.
93 //
94 // This function should call QPlatformCamera::focusDistanceChanged()
95 // if successful.
96 virtual void setFocusDistance(float) {}
97
98 // smaller 0: zoom instantly, rate in power-of-two/sec
99 virtual void zoomTo(float /*newZoomFactor*/, float /*rate*/ = -1.) {}
100
101 virtual void setFlashMode(QCamera::FlashMode /*mode*/) {}
102 virtual bool isFlashModeSupported(QCamera::FlashMode mode) const { return mode == QCamera::FlashOff; }
103 virtual bool isFlashReady() const { return false; }
104
105 virtual void setTorchMode(QCamera::TorchMode /*mode*/) {}
106 virtual bool isTorchModeSupported(QCamera::TorchMode mode) const { return mode == QCamera::TorchOff; }
107
108 virtual void setExposureMode(QCamera::ExposureMode) {}
109 virtual bool isExposureModeSupported(QCamera::ExposureMode mode) const { return mode == QCamera::ExposureAuto; }
110 virtual void setExposureCompensation(float) {}
111 virtual int isoSensitivity() const { return 100; }
112 virtual void setManualIsoSensitivity(int) {}
113 virtual void setManualExposureTime(float) {}
114 virtual float exposureTime() const { return -1.; }
115
116 virtual bool isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const { return mode == QCamera::WhiteBalanceAuto; }
117 virtual void setWhiteBalanceMode(QCamera::WhiteBalanceMode /*mode*/) {}
118 virtual void setColorTemperature(int /*temperature*/) {}
119
120#if QT_CONFIG(gstreamer_qt_api)
121 virtual GstElement *rawGstElement() const { return nullptr; }
122#endif
123
124 QVideoFrameFormat frameFormat() const override;
125
126 // Note: Because FocusModeManual effectively cannot function without
127 // being able to set FocusDistance, this feature flag is redundant.
128 // Should be considered for deprecation in the future.
129 QCamera::Features supportedFeatures() const { return m_supportedFeatures; }
130
131 QCamera::FocusMode focusMode() const { return m_focusMode; }
132 QPointF focusPoint() const { return m_customFocusPoint; }
133
134 float minZoomFactor() const { return m_minZoom; }
135 float maxZoomFactor() const { return m_maxZoom; }
136 float zoomFactor() const { return m_zoomFactor; }
137 QPointF customFocusPoint() const { return m_customFocusPoint; }
138 float focusDistance() const { return m_focusDistance; }
139
140 QCamera::FlashMode flashMode() const { return m_flashMode; }
141 QCamera::TorchMode torchMode() const { return m_torchMode; }
142
143 QCamera::ExposureMode exposureMode() const { return m_exposureMode; }
144 float exposureCompensation() const { return m_exposureCompensation; }
145 int manualIsoSensitivity() const { return m_iso; }
146 int minIso() const { return m_minIso; }
147 int maxIso() const { return m_maxIso; }
148 float manualExposureTime() const { return m_exposureTime; }
149 float minExposureTime() const { return m_minExposureTime; }
150 float maxExposureTime() const { return m_maxExposureTime; }
151 QCamera::WhiteBalanceMode whiteBalanceMode() const { return m_whiteBalance; }
152 int colorTemperature() const { return m_colorTemperature; }
153
154 void supportedFeaturesChanged(QCamera::Features);
155 void minimumZoomFactorChanged(float factor);
156 void maximumZoomFactorChanged(float);
157 void focusModeChanged(QCamera::FocusMode mode);
158 void customFocusPointChanged(const QPointF &point);
159 void focusDistanceChanged(float d);
160 void zoomFactorChanged(float zoom);
161 void flashReadyChanged(bool);
162 void flashModeChanged(QCamera::FlashMode mode);
163 void torchModeChanged(QCamera::TorchMode mode);
164 void exposureModeChanged(QCamera::ExposureMode mode);
165 void exposureCompensationChanged(float compensation);
166 void exposureCompensationRangeChanged(float min, float max);
167 void isoSensitivityChanged(int iso);
168 void minIsoChanged(int iso) { m_minIso = iso; }
169 void maxIsoChanged(int iso) { m_maxIso = iso; }
170 void exposureTimeChanged(float speed);
171 void minExposureTimeChanged(float secs) { m_minExposureTime = secs; }
172 void maxExposureTimeChanged(float secs) { m_maxExposureTime = secs; }
173 void whiteBalanceModeChanged(QCamera::WhiteBalanceMode mode);
174 void colorTemperatureChanged(int temperature);
175
176 static int colorTemperatureForWhiteBalance(QCamera::WhiteBalanceMode mode);
177
178 QCamera::Error error() const { return m_error.code(); }
179 QString errorString() const final { return m_error.description(); }
180
181 void updateError(QCamera::Error error, const QString &errorString);
182
183Q_SIGNALS:
184 void errorOccurred(QCamera::Error error, const QString &errorString);
185
186protected:
187 explicit QPlatformCamera(QObject *parent);
188
189 virtual int cameraPixelFormatScore(QVideoFrameFormat::PixelFormat /*format*/,
190 QVideoFrameFormat::ColorRange /*colorRange*/) const
191 {
192 return 0;
193 }
194
195 QCameraFormat findBestCameraFormat(const QCameraDevice &camera) const;
196 QCameraFormat m_cameraFormat;
197 QVideoFrameFormat::PixelFormat m_framePixelFormat = QVideoFrameFormat::Format_Invalid;
198
199 // Helper functions to allow backends to reset properties to default values.
200 // i.e using focusModeChanged(defaultFocusMode());
201 static constexpr int defaultColorTemperature() { return 0; }
202 static constexpr QPointF defaultCustomFocusPoint() { return { -1, -1 }; }
203 static constexpr float defaultExposureCompensation() { return 0.f; }
204 static constexpr QCamera::ExposureMode defaultExposureMode() { return QCamera::ExposureAuto; }
205 static constexpr float defaultExposureTime() { return -1.f; }
206 static constexpr QCamera::FlashMode defaultFlashMode() { return QCamera::FlashOff; }
207 static constexpr bool defaultFlashReady() { return false; }
208 static constexpr float defaultFocusDistance() { return 1.f; }
209 static constexpr QCamera::FocusMode defaultFocusMode() { return QCamera::FocusModeAuto; }
210 static constexpr int defaultIso() { return -1; }
211 static constexpr QCamera::TorchMode defaultTorchMode() { return QCamera::TorchOff; }
212 static constexpr QCamera::WhiteBalanceMode defaultWhiteBalanceMode() { return QCamera::WhiteBalanceAuto; }
213 static constexpr float defaultZoomFactor() { return 1.f; }
214
215private:
216 QCamera *m_camera = nullptr;
217 QCamera::Features m_supportedFeatures = {};
218 QCamera::FocusMode m_focusMode = defaultFocusMode();
219 float m_minZoom = 1.;
220 float m_maxZoom = 1.;
221 float m_zoomFactor = defaultZoomFactor();
222 float m_focusDistance = defaultFocusDistance();
223 QPointF m_customFocusPoint = defaultCustomFocusPoint();
224 bool m_flashReady = defaultFlashReady();
225 QCamera::FlashMode m_flashMode = defaultFlashMode();
226 QCamera::TorchMode m_torchMode = defaultTorchMode();
227 QCamera::ExposureMode m_exposureMode = defaultExposureMode();
228 float m_exposureCompensation = defaultExposureCompensation();
229 float m_minExposureCompensation = 0.;
230 float m_maxExposureCompensation = 0.;
231 int m_iso = defaultIso();
232 int m_minIso = -1;
233 int m_maxIso = -1;
234 float m_exposureTime = defaultExposureTime();
235 float m_minExposureTime = -1.;
236 float m_maxExposureTime = -1.;
237 QCamera::WhiteBalanceMode m_whiteBalance = defaultWhiteBalanceMode();
238 int m_colorTemperature = defaultColorTemperature();
239 QErrorInfo<QCamera::Error> m_error;
240};
241
242QT_END_NAMESPACE
243
244
245#endif // QPLATFORMCAMERA_H
Combined button and popup list for selecting options.