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 QCAMERAIMAGECAPTURE_H
41#define QCAMERAIMAGECAPTURE_H
42
43#include <QtMultimedia/qmediaobject.h>
44#include <QtMultimedia/qmediaencodersettings.h>
45#include <QtMultimedia/qmediabindableinterface.h>
46#include <QtMultimedia/qvideoframe.h>
47
48#include <QtMultimedia/qmediaenumdebug.h>
49
50QT_BEGIN_NAMESPACE
51
52class QSize;
53QT_END_NAMESPACE
54
55QT_BEGIN_NAMESPACE
56
57class QImageEncoderSettings;
58
59class QCameraImageCapturePrivate;
60class Q_MULTIMEDIA_EXPORT QCameraImageCapture : public QObject, public QMediaBindableInterface
61{
62 Q_OBJECT
63 Q_INTERFACES(QMediaBindableInterface)
64 Q_ENUMS(Error)
65 Q_ENUMS(CaptureDestination)
66 Q_PROPERTY(bool readyForCapture READ isReadyForCapture NOTIFY readyForCaptureChanged)
67public:
68 enum Error
69 {
70 NoError,
71 NotReadyError,
72 ResourceError,
73 OutOfSpaceError,
74 NotSupportedFeatureError,
75 FormatError
76 };
77
78 enum DriveMode
79 {
80 SingleImageCapture
81 };
82
83 enum CaptureDestination
84 {
85 CaptureToFile = 0x01,
86 CaptureToBuffer = 0x02
87 };
88 Q_DECLARE_FLAGS(CaptureDestinations, CaptureDestination)
89
90 explicit QCameraImageCapture(QMediaObject *mediaObject, QObject *parent = nullptr);
91 ~QCameraImageCapture();
92
93 bool isAvailable() const;
94 QMultimedia::AvailabilityStatus availability() const;
95
96 QMediaObject *mediaObject() const override;
97
98 Error error() const;
99 QString errorString() const;
100
101 bool isReadyForCapture() const;
102
103 QStringList supportedImageCodecs() const;
104 QString imageCodecDescription(const QString &codecName) const;
105
106 QList<QSize> supportedResolutions(const QImageEncoderSettings &settings = QImageEncoderSettings(),
107 bool *continuous = nullptr) const;
108
109 QImageEncoderSettings encodingSettings() const;
110 void setEncodingSettings(const QImageEncoderSettings& settings);
111
112 QList<QVideoFrame::PixelFormat> supportedBufferFormats() const;
113 QVideoFrame::PixelFormat bufferFormat() const;
114 void setBufferFormat(const QVideoFrame::PixelFormat format);
115
116 bool isCaptureDestinationSupported(CaptureDestinations destination) const;
117 CaptureDestinations captureDestination() const;
118 void setCaptureDestination(CaptureDestinations destination);
119
120public Q_SLOTS:
121 int capture(const QString &location = QString());
122 void cancelCapture();
123
124Q_SIGNALS:
125 void error(int id, QCameraImageCapture::Error error, const QString &errorString);
126
127 void readyForCaptureChanged(bool ready);
128 void bufferFormatChanged(QVideoFrame::PixelFormat format);
129 void captureDestinationChanged(QCameraImageCapture::CaptureDestinations destination);
130
131 void imageExposed(int id);
132 void imageCaptured(int id, const QImage &preview);
133 void imageMetadataAvailable(int id, const QString &key, const QVariant &value);
134 void imageAvailable(int id, const QVideoFrame &frame);
135 void imageSaved(int id, const QString &fileName);
136
137protected:
138 bool setMediaObject(QMediaObject *) override;
139
140 QCameraImageCapturePrivate *d_ptr;
141private:
142 Q_DISABLE_COPY(QCameraImageCapture)
143 Q_DECLARE_PRIVATE(QCameraImageCapture)
144 Q_PRIVATE_SLOT(d_func(), void _q_error(int, int, const QString &))
145 Q_PRIVATE_SLOT(d_func(), void _q_readyChanged(bool))
146 Q_PRIVATE_SLOT(d_func(), void _q_serviceDestroyed())
147};
148
149Q_DECLARE_OPERATORS_FOR_FLAGS(QCameraImageCapture::CaptureDestinations)
150
151QT_END_NAMESPACE
152
153Q_DECLARE_METATYPE(QCameraImageCapture::Error)
154Q_DECLARE_METATYPE(QCameraImageCapture::CaptureDestination)
155Q_DECLARE_METATYPE(QCameraImageCapture::CaptureDestinations)
156
157Q_MEDIA_ENUM_DEBUG(QCameraImageCapture, Error)
158Q_MEDIA_ENUM_DEBUG(QCameraImageCapture, CaptureDestination)
159
160#endif
161
162

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