1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QCAMERA_H
41#define QCAMERA_H
42
43#include <QtCore/qstringlist.h>
44#include <QtCore/qpair.h>
45#include <QtCore/qsize.h>
46#include <QtCore/qpoint.h>
47#include <QtCore/qrect.h>
48
49#include <QtMultimedia/qmediacontrol.h>
50#include <QtMultimedia/qmediaobject.h>
51#include <QtMultimedia/qmediaservice.h>
52
53#include <QtMultimedia/qcameraexposure.h>
54#include <QtMultimedia/qcamerafocus.h>
55#include <QtMultimedia/qcameraimageprocessing.h>
56#include <QtMultimedia/qcameraviewfindersettings.h>
57
58#include <QtMultimedia/qmediaenumdebug.h>
59
60QT_BEGIN_NAMESPACE
61
62
63class QAbstractVideoSurface;
64class QVideoWidget;
65class QGraphicsVideoItem;
66class QCameraInfo;
67
68class QCameraPrivate;
69class Q_MULTIMEDIA_EXPORT QCamera : public QMediaObject
70{
71 Q_OBJECT
72 Q_PROPERTY(QCamera::State state READ state NOTIFY stateChanged)
73 Q_PROPERTY(QCamera::Status status READ status NOTIFY statusChanged)
74 Q_PROPERTY(QCamera::CaptureModes captureMode READ captureMode WRITE setCaptureMode NOTIFY captureModeChanged)
75 Q_PROPERTY(QCamera::LockStatus lockStatus READ lockStatus NOTIFY lockStatusChanged)
76
77 Q_ENUMS(Status)
78 Q_ENUMS(State)
79 Q_ENUMS(CaptureMode)
80 Q_ENUMS(Error)
81 Q_ENUMS(LockStatus)
82 Q_ENUMS(LockChangeReason)
83 Q_ENUMS(LockType)
84 Q_ENUMS(Position)
85public:
86 struct FrameRateRange
87 {
88 Q_DECL_CONSTEXPR FrameRateRange() Q_DECL_NOTHROW
89 : minimumFrameRate(0)
90 , maximumFrameRate(0)
91 { }
92
93 Q_DECL_CONSTEXPR FrameRateRange(qreal minimum, qreal maximum) Q_DECL_NOTHROW
94 : minimumFrameRate(minimum)
95 , maximumFrameRate(maximum)
96 { }
97
98 qreal minimumFrameRate;
99 qreal maximumFrameRate;
100 };
101
102 enum Status {
103 UnavailableStatus,
104 UnloadedStatus,
105 LoadingStatus,
106 UnloadingStatus,
107 LoadedStatus,
108 StandbyStatus,
109 StartingStatus,
110 StoppingStatus,
111 ActiveStatus
112 };
113
114 enum State {
115 UnloadedState,
116 LoadedState,
117 ActiveState
118 };
119
120 enum CaptureMode
121 {
122 CaptureViewfinder = 0,
123 CaptureStillImage = 0x01,
124 CaptureVideo = 0x02
125 };
126 Q_DECLARE_FLAGS(CaptureModes, CaptureMode)
127
128 enum Error
129 {
130 NoError,
131 CameraError,
132 InvalidRequestError,
133 ServiceMissingError,
134 NotSupportedFeatureError
135 };
136
137 enum LockStatus
138 {
139 Unlocked,
140 Searching,
141 Locked
142 };
143
144 enum LockChangeReason {
145 UserRequest,
146 LockAcquired,
147 LockFailed,
148 LockLost,
149 LockTemporaryLost
150 };
151
152 enum LockType
153 {
154 NoLock = 0,
155 LockExposure = 0x01,
156 LockWhiteBalance = 0x02,
157 LockFocus = 0x04
158 };
159 Q_DECLARE_FLAGS(LockTypes, LockType)
160
161 enum Position
162 {
163 UnspecifiedPosition,
164 BackFace,
165 FrontFace
166 };
167
168 explicit QCamera(QObject *parent = nullptr);
169 explicit QCamera(const QByteArray& deviceName, QObject *parent = nullptr);
170 explicit QCamera(const QCameraInfo& cameraInfo, QObject *parent = nullptr);
171 explicit QCamera(QCamera::Position position, QObject *parent = nullptr);
172 ~QCamera();
173
174#if QT_DEPRECATED_SINCE(5, 3)
175 QT_DEPRECATED static QList<QByteArray> availableDevices();
176 QT_DEPRECATED static QString deviceDescription(const QByteArray &device);
177#endif
178
179 QMultimedia::AvailabilityStatus availability() const override;
180
181 State state() const;
182 Status status() const;
183
184 CaptureModes captureMode() const;
185 bool isCaptureModeSupported(CaptureModes mode) const;
186
187 QCameraExposure *exposure() const;
188 QCameraFocus *focus() const;
189 QCameraImageProcessing *imageProcessing() const;
190
191 void setViewfinder(QVideoWidget *viewfinder);
192 void setViewfinder(QGraphicsVideoItem *viewfinder);
193 void setViewfinder(QAbstractVideoSurface *surface);
194
195 QCameraViewfinderSettings viewfinderSettings() const;
196 void setViewfinderSettings(const QCameraViewfinderSettings &settings);
197
198 QList<QCameraViewfinderSettings> supportedViewfinderSettings(
199 const QCameraViewfinderSettings &settings = QCameraViewfinderSettings()) const;
200
201 QList<QSize> supportedViewfinderResolutions(
202 const QCameraViewfinderSettings &settings = QCameraViewfinderSettings()) const;
203
204 QList<FrameRateRange> supportedViewfinderFrameRateRanges(
205 const QCameraViewfinderSettings &settings = QCameraViewfinderSettings()) const;
206
207 QList<QVideoFrame::PixelFormat> supportedViewfinderPixelFormats(
208 const QCameraViewfinderSettings &settings = QCameraViewfinderSettings()) const;
209
210 Error error() const;
211 QString errorString() const;
212
213 QCamera::LockTypes supportedLocks() const;
214 QCamera::LockTypes requestedLocks() const;
215
216 QCamera::LockStatus lockStatus() const;
217 QCamera::LockStatus lockStatus(QCamera::LockType lock) const;
218
219public Q_SLOTS:
220 void setCaptureMode(QCamera::CaptureModes mode);
221
222 void load();
223 void unload();
224
225 void start();
226 void stop();
227
228 void searchAndLock();
229 void unlock();
230
231 void searchAndLock(QCamera::LockTypes locks);
232 void unlock(QCamera::LockTypes locks);
233
234Q_SIGNALS:
235 void stateChanged(QCamera::State state);
236 void captureModeChanged(QCamera::CaptureModes);
237 void statusChanged(QCamera::Status status);
238
239 void locked();
240 void lockFailed();
241
242 void lockStatusChanged(QCamera::LockStatus status, QCamera::LockChangeReason reason);
243 void lockStatusChanged(QCamera::LockType lock, QCamera::LockStatus status, QCamera::LockChangeReason reason);
244
245#if QT_DEPRECATED_SINCE(5,15)
246 void error(QCamera::Error);
247#endif
248 void errorOccurred(QCamera::Error);
249
250private:
251 Q_DISABLE_COPY(QCamera)
252 Q_DECLARE_PRIVATE(QCamera)
253 Q_PRIVATE_SLOT(d_func(), void _q_preparePropertyChange(int))
254 Q_PRIVATE_SLOT(d_func(), void _q_restartCamera())
255 Q_PRIVATE_SLOT(d_func(), void _q_error(int, const QString &))
256 Q_PRIVATE_SLOT(d_func(), void _q_updateLockStatus(QCamera::LockType, QCamera::LockStatus, QCamera::LockChangeReason))
257 Q_PRIVATE_SLOT(d_func(), void _q_updateState(QCamera::State))
258 friend class QCameraInfo;
259};
260
261Q_DECLARE_OPERATORS_FOR_FLAGS(QCamera::LockTypes)
262
263QT_WARNING_PUSH
264QT_WARNING_DISABLE_CLANG("-Wfloat-equal")
265QT_WARNING_DISABLE_GCC("-Wfloat-equal")
266
267Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator==(const QCamera::FrameRateRange &r1, const QCamera::FrameRateRange &r2) Q_DECL_NOTHROW
268{
269 return qFuzzyCompare(p1: r1.minimumFrameRate, p2: r2.minimumFrameRate)
270 && qFuzzyCompare(p1: r1.maximumFrameRate, p2: r2.maximumFrameRate);
271}
272
273QT_WARNING_POP
274
275Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator!=(const QCamera::FrameRateRange &r1, const QCamera::FrameRateRange &r2) Q_DECL_NOTHROW
276{ return !(r1 == r2); }
277
278Q_DECLARE_TYPEINFO(QCamera::FrameRateRange, Q_PRIMITIVE_TYPE);
279
280QT_END_NAMESPACE
281
282Q_DECLARE_METATYPE(QCamera::State)
283Q_DECLARE_METATYPE(QCamera::Status)
284Q_DECLARE_METATYPE(QCamera::Error)
285Q_DECLARE_METATYPE(QCamera::CaptureMode)
286Q_DECLARE_METATYPE(QCamera::CaptureModes)
287Q_DECLARE_METATYPE(QCamera::LockType)
288Q_DECLARE_METATYPE(QCamera::LockStatus)
289Q_DECLARE_METATYPE(QCamera::LockChangeReason)
290Q_DECLARE_METATYPE(QCamera::Position)
291
292Q_MEDIA_ENUM_DEBUG(QCamera, State)
293Q_MEDIA_ENUM_DEBUG(QCamera, Status)
294Q_MEDIA_ENUM_DEBUG(QCamera, Error)
295Q_MEDIA_ENUM_DEBUG(QCamera, CaptureMode)
296Q_MEDIA_ENUM_DEBUG(QCamera, LockType)
297Q_MEDIA_ENUM_DEBUG(QCamera, LockStatus)
298Q_MEDIA_ENUM_DEBUG(QCamera, LockChangeReason)
299Q_MEDIA_ENUM_DEBUG(QCamera, Position)
300
301#endif // QCAMERA_H
302

source code of qtmultimedia/src/multimedia/camera/qcamera.h