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 "qcameradevice_p.h"
5
6#include "qcamera_p.h"
7
8QT_BEGIN_NAMESPACE
9
10
11/*!
12 \class QCameraFormat
13 \since 6.2
14 \brief The QCameraFormat class describes a video format supported by a camera device.
15 \inmodule QtMultimedia
16 \ingroup multimedia
17 \ingroup multimedia_camera
18
19 QCameraFormat represents a certain video format supported by a camera device.
20
21 The format is a combination of a
22 \l{QVideoFrameFormat::PixelFormat}{pixel format}, resolution and a range of frame
23 rates.
24
25 QCameraFormat objects can be queried from QCameraDevice to inspect the set of
26 supported video formats.
27
28 \sa QCameraDevice, QCamera
29*/
30
31/*!
32 \qmlvaluetype cameraFormat
33 \ingroup qmlvaluetypes
34 \inqmlmodule QtMultimedia
35 \since 6.2
36 //! \instantiates QCameraFormat
37 \brief Describes a video format supported by a camera device.
38 \ingroup multimedia_qml
39 \ingroup multimedia_video_qml
40
41 cameraFormat represents a certain video format supported by a camera device.
42
43 The format is a combination of a
44 \l{pixel format}{QVideoFrameFormat::PixelFormat}, resolution and a range of frame
45 rates.
46
47 cameraFormat objects can be queried from \l cameraDevice to inspect the set of
48 supported video formats.
49
50 \sa cameraDevice, Camera
51*/
52
53/*!
54 Constructs a null camera format.
55
56 \sa isNull()
57*/
58QCameraFormat::QCameraFormat() noexcept = default;
59
60/*!
61 Copy constructs a camera format from the \a other format.
62*/
63QCameraFormat::QCameraFormat(const QCameraFormat &other) noexcept = default;
64
65/*!
66 Assign \a other to this.
67*/
68QCameraFormat &QCameraFormat::operator=(const QCameraFormat &other) noexcept = default;
69
70/*!
71 Destructs the camera format object.
72*/
73QCameraFormat::~QCameraFormat() = default;
74
75/*! \fn bool QCameraFormat::isNull() const noexcept
76
77 Returns true if this is a default constructed QCameraFormat.
78*/
79
80/*!
81 \qmlproperty enumeration QtMultimedia::cameraFormat::pixelFormat
82
83 Holds the pixel format.
84
85 Most commonly this is either QVideoFrameFormat::Format_Jpeg or QVideoFrameFormat::Format_YUVY
86 but other formats could also be supported by the camera.
87
88 \sa QVideoFrameFormat::PixelFormat
89*/
90
91/*!
92 \property QCameraFormat::pixelFormat
93
94 Returns the pixel format.
95
96 Most commonly this is either QVideoFrameFormat::Format_Jpeg or QVideoFrameFormat::Format_YUVY
97 but other formats could also be supported by the camera.
98
99 \sa QVideoFrameFormat::PixelFormat
100*/
101QVideoFrameFormat::PixelFormat QCameraFormat::pixelFormat() const noexcept
102{
103 return d ? d->pixelFormat : QVideoFrameFormat::Format_Invalid;
104}
105
106/*!
107 \qmlproperty size QtMultimedia::cameraFormat::resolution
108
109 Returns the resolution.
110*/
111
112/*!
113 \property QCameraFormat::resolution
114
115 Returns the resolution.
116*/
117QSize QCameraFormat::resolution() const noexcept
118{
119 return d ? d->resolution : QSize();
120}
121
122/*!
123 \qmlproperty real QtMultimedia::cameraFormat::minFrameRate
124
125 Returns the lowest frame rate defined by this format.
126*/
127
128/*!
129 \property QCameraFormat::minFrameRate
130
131 Returns the lowest frame rate defined by this format.
132*/
133float QCameraFormat::minFrameRate() const noexcept
134{
135 return d ? d->minFrameRate : 0;
136}
137
138/*!
139 \qmlproperty real QtMultimedia::cameraFormat::maxFrameRate
140
141 Returns the highest frame rate defined by this format.
142
143 In 6.2, the camera will always try to use the maximum frame rate supported by a
144 certain video format.
145*/
146
147/*!
148 \property QCameraFormat::maxFrameRate
149
150 Returns the highest frame rate defined by this format.
151
152 In 6.2, the camera will always try to use the highest frame rate supported by a
153 certain video format.
154*/
155float QCameraFormat::maxFrameRate() const noexcept
156{
157 return d ? d->maxFrameRate : 0;
158}
159
160/*!
161 \internal
162*/
163QCameraFormat::QCameraFormat(QCameraFormatPrivate *p)
164 : d(p)
165{
166}
167
168/*!
169 Returns \c true if the \a other format is equal to this camera format, otherwise \c false.
170*/
171bool QCameraFormat::operator==(const QCameraFormat &other) const
172{
173 if (d == other.d)
174 return true;
175 if (!d || !other.d)
176 return false;
177 return d->pixelFormat == other.d->pixelFormat &&
178 d->minFrameRate == other.d->minFrameRate &&
179 d->maxFrameRate == other.d->maxFrameRate &&
180 d->resolution == other.d->resolution;
181}
182
183/*!
184 \fn bool QCameraFormat::operator!=(const QCameraFormat &other) const
185
186 Returns \c false if the \a other format is equal to this camera format, otherwise \c true.
187*/
188
189/*!
190 \class QCameraDevice
191 \brief The QCameraDevice class provides general information about camera devices.
192 \inmodule QtMultimedia
193 \ingroup multimedia
194 \ingroup multimedia_camera
195
196 QCameraDevice represents a physical camera device and its properties.
197
198 You can discover what cameras are available on a system using the
199 availableCameras() and defaultCamera() functions. These are contained within
200 QtMultimedia::MediaDevices.
201
202 This example prints the name of all available cameras:
203
204 \snippet multimedia-snippets/camera.cpp Camera listing
205
206 A QCameraDevice can be used to construct a QCamera. The following example
207 instantiates a QCamera whose camera device is named \c {mycamera}:
208
209 \snippet multimedia-snippets/camera.cpp Camera selection
210
211 You can also use QCameraDevice to get general information about a camera
212 device such as description and physical position on the system.
213
214 \snippet multimedia-snippets/camera.cpp Camera info
215
216 \sa QCamera
217*/
218
219/*!
220 \qmlvaluetype cameraDevice
221 \ingroup qmlvaluetypes
222 \inqmlmodule QtMultimedia
223 \since 6.2
224 //! \instantiates QCameraDevice
225 \brief Describes a camera device.
226 \ingroup multimedia_qml
227 \ingroup multimedia_video_qml
228
229 The cameraDevice value type describes the properties of a camera device that
230 is connected to the system.
231
232 The list of camera devices can be queried from the \l{MediaDevices}
233 type. To select a certain camera device set it as the device
234 on \l{Camera}.
235
236 \qml
237 CaptureSession {
238 camera: Camera {
239 cameraDevice: mediaDevices.defaultVideoInput
240 }
241 }
242 MediaDevices {
243 id: mediaDevices
244 }
245 \endqml
246*/
247
248/*!
249 Constructs a null camera device
250*/
251QCameraDevice::QCameraDevice() = default;
252
253/*!
254 Constructs a copy of \a other.
255*/
256QCameraDevice::QCameraDevice(const QCameraDevice &other) = default;
257
258/*!
259 Destroys the QCameraDevice.
260*/
261QCameraDevice::~QCameraDevice() = default;
262
263/*!
264 Returns true if this QCameraDevice is equal to \a other.
265*/
266bool QCameraDevice::operator==(const QCameraDevice &other) const
267{
268 if (d == other.d)
269 return true;
270
271 if (!d || ! other.d)
272 return false;
273
274 return (d->id == other.d->id
275 && d->description == other.d->description
276 && d->position == other.d->position);
277}
278
279/*!
280 Returns true if this QCameraDevice is null or invalid.
281*/
282bool QCameraDevice::isNull() const
283{
284 return !d;
285}
286
287/*!
288 \qmlproperty string QtMultimedia::cameraDevice::id
289
290 Holds he device id of the camera
291
292 This is a unique ID to identify the camera and may not be human-readable.
293*/
294
295/*!
296 \property QCameraDevice::id
297
298 Returns the device id of the camera
299
300 This is a unique ID to identify the camera and may not be human-readable.
301*/
302QByteArray QCameraDevice::id() const
303{
304 return d ? d->id : QByteArray();
305}
306
307/*!
308 \qmlproperty bool QtMultimedia::cameraDevice::isDefault
309
310 Is true if this is the default camera device.
311*/
312
313/*!
314 \property QCameraDevice::isDefault
315
316 Returns true if this is the default camera device.
317*/
318bool QCameraDevice::isDefault() const
319{
320 return d ? d->isDefault : false;
321}
322
323/*!
324 \qmlproperty string QtMultimedia::cameraDevice::description
325
326 Holds a human readable name of the camera.
327
328 Use this string to present the device to the user.
329*/
330
331/*!
332 \property QCameraDevice::description
333
334 Returns the human-readable description of the camera.
335
336 Use this string to present the device to the user.
337*/
338QString QCameraDevice::description() const
339{
340 return d ? d->description : QString();
341}
342
343/*!
344 \enum QCameraDevice::Position
345
346 This enum specifies the physical position of the camera on the system hardware.
347
348 \value UnspecifiedPosition The camera position is unspecified or unknown.
349 \value BackFace The camera is on the back face of the system hardware. For example on a
350 mobile device, it means it is on the opposite side to that of the screen.
351 \value FrontFace The camera is on the front face of the system hardware. For example on a
352 mobile device, it means it is on the same side as that of the screen.
353
354 \sa position()
355*/
356
357/*!
358 \qmlproperty enumeration QtMultimedia::cameraDevice::position
359
360 Returns the physical position of the camera on the hardware system.
361
362 The returned value can be one of the following:
363
364 \value cameraDevice.UnspecifiedPosition The camera position is unspecified or unknown.
365 \value cameraDevice.BackFace The camera is on the back face of the system hardware. For example on a
366 mobile device, it means it is on the opposite side to that of the screen.
367 \value cameraDevice.FrontFace The camera is on the front face of the system hardware. For example on a
368 mobile device, it means it is on the same side as that of the screen.
369*/
370
371/*!
372 \property QCameraDevice::position
373
374 Returns the physical position of the camera on the hardware system.
375*/
376QCameraDevice::Position QCameraDevice::position() const
377{
378 return d ? d->position : QCameraDevice::UnspecifiedPosition;
379}
380
381/*!
382 Returns a list of resolutions that the camera can use to
383 capture still images.
384
385 \sa QImageCapture
386 */
387QList<QSize> QCameraDevice::photoResolutions() const
388{
389 return d ? d->photoResolutions : QList<QSize>{};
390}
391
392/*!
393 \qmlproperty CameraFormat QtMultimedia::cameraDevice::videoFormats
394
395 Holds the video formats supported by the camera.
396*/
397
398/*!
399 \property QCameraDevice::videoFormats
400
401 Returns the video formats supported by the camera.
402*/
403QList<QCameraFormat> QCameraDevice::videoFormats() const
404{
405 return d ? d->videoFormats : QList<QCameraFormat>{};
406}
407
408QCameraDevice::QCameraDevice(QCameraDevicePrivate *p)
409 : d(p)
410{}
411
412/*!
413 Sets the QCameraDevice object to be equal to \a other.
414*/
415QCameraDevice& QCameraDevice::operator=(const QCameraDevice& other) = default;
416
417/*!
418 \fn QCameraDevice::operator!=(const QCameraDevice &other) const
419
420 Returns true if this QCameraDevice is different from \a other.
421*/
422
423#ifndef QT_NO_DEBUG_STREAM
424QDebug operator<<(QDebug d, const QCameraDevice &camera)
425{
426 d.maybeSpace() << QStringLiteral("QCameraDevice(name=%1, position=%2, orientation=%3)")
427 .arg(a: camera.description())
428 .arg(a: QString::fromLatin1(ba: QCamera::staticMetaObject.enumerator(index: QCamera::staticMetaObject.indexOfEnumerator(name: "Position"))
429 .valueToKey(value: camera.position())));
430 return d.space();
431}
432#endif
433
434QT_END_NAMESPACE
435
436#include "moc_qcameradevice.cpp"
437

source code of qtmultimedia/src/multimedia/camera/qcameradevice.cpp