1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 #include <experimental/qstillimagecapture.h> |
|
42 #include <experimental/qimagecapturecontrol.h> |
|
43 #include <qmediaencodersettings.h> |
|
44 |
|
45 #include <qimageencodercontrol.h> |
|
46 #include <qmediaobject_p.h> |
|
47 #include <qmediaservice.h> |
|
48 #include <QtCore/qdebug.h> |
|
49 #include <QtCore/qurl.h> |
|
50 #include <QtCore/qstringlist.h> |
|
51 #include <QtCore/qmetaobject.h> |
|
52 |
|
53 QTM_BEGIN_NAMESPACE |
|
54 |
|
55 /*! |
|
56 \class QStillImageCapture |
|
57 \ingroup multimedia |
|
58 |
|
59 \preliminary |
|
60 \brief The QStillImageCapture class is used for the recording of media content. |
|
61 |
|
62 The QStillImageCapture class is a high level images recording class. |
|
63 It's not intended to be used alone but for accessing the media |
|
64 recording functions of other media objects, like QCamera. |
|
65 |
|
66 \code |
|
67 camera = new QCamera; |
|
68 viewFinder = new QVideoWidget(camera); |
|
69 viewFinder->show(); |
|
70 |
|
71 imageCapture = new QStillImageCapture(camera); |
|
72 |
|
73 camera->start(); |
|
74 |
|
75 imageCapture->capture(fileName); |
|
76 \endcode |
|
77 |
|
78 \sa QCamera |
|
79 */ |
|
80 |
|
81 namespace |
|
82 { |
|
83 class MediaRecorderRegisterMetaTypes |
|
84 { |
|
85 public: |
|
86 MediaRecorderRegisterMetaTypes() |
|
87 { |
|
88 qRegisterMetaType<QStillImageCapture::Error>("QStillImageCapture::Error"); |
|
89 } |
|
90 } _registerRecorderMetaTypes; |
|
91 } |
|
92 |
|
93 |
|
94 class QStillImageCapturePrivate : public QMediaObjectPrivate |
|
95 { |
|
96 Q_DECLARE_NON_CONST_PUBLIC(QStillImageCapture) |
|
97 |
|
98 public: |
|
99 QStillImageCapturePrivate(); |
|
100 void initControls(); |
|
101 |
|
102 QImageCaptureControl *control; |
|
103 QImageEncoderControl *encoderControl; |
|
104 QStillImageCapture::Error error; |
|
105 QString errorString; |
|
106 |
|
107 void _q_error(int error, const QString &errorString); |
|
108 |
|
109 void unsetError() { error = QStillImageCapture::NoError; errorString.clear(); } |
|
110 }; |
|
111 |
|
112 QStillImageCapturePrivate::QStillImageCapturePrivate(): |
|
113 control(0), |
|
114 error(QStillImageCapture::NoError) |
|
115 { |
|
116 } |
|
117 |
|
118 void QStillImageCapturePrivate::initControls() |
|
119 { |
|
120 Q_Q(QStillImageCapture); |
|
121 |
|
122 if (!service) |
|
123 return; |
|
124 |
|
125 control = qobject_cast<QImageCaptureControl*>(service->control(QImageCaptureControl_iid)); |
|
126 encoderControl = qobject_cast<QImageEncoderControl *>(service->control(QImageEncoderControl_iid)); |
|
127 |
|
128 if (control) { |
|
129 q->connect(control, SIGNAL(imageCaptured(QString,QImage)), |
|
130 q, SIGNAL(imageCaptured(QString,QImage))); |
|
131 q->connect(control, SIGNAL(imageSaved(QString)), |
|
132 q, SIGNAL(imageSaved(QString))); |
|
133 q->connect(control, SIGNAL(readyForCaptureChanged(bool)), |
|
134 q, SIGNAL(readyForCaptureChanged(bool))); |
|
135 q->connect(control, SIGNAL(error(int,QString)), |
|
136 q, SLOT(_q_error(int,QString))); |
|
137 } |
|
138 |
|
139 } |
|
140 |
|
141 void QStillImageCapturePrivate::_q_error(int error, const QString &errorString) |
|
142 { |
|
143 Q_Q(QStillImageCapture); |
|
144 |
|
145 this->error = QStillImageCapture::Error(error); |
|
146 this->errorString = errorString; |
|
147 |
|
148 emit q->error(this->error); |
|
149 } |
|
150 |
|
151 |
|
152 /*! |
|
153 Constructs a media recorder which records the media produced by \a mediaObject. |
|
154 |
|
155 The \a parent is passed to QMediaObject. |
|
156 */ |
|
157 |
|
158 QStillImageCapture::QStillImageCapture(QMediaObject *mediaObject, QObject *parent): |
|
159 QMediaObject(*new QStillImageCapturePrivate, parent, mediaObject->service()) |
|
160 { |
|
161 Q_D(QStillImageCapture); |
|
162 |
|
163 d->initControls(); |
|
164 } |
|
165 |
|
166 /*! |
|
167 Destroys images capture object. |
|
168 */ |
|
169 |
|
170 QStillImageCapture::~QStillImageCapture() |
|
171 { |
|
172 } |
|
173 |
|
174 /*! |
|
175 Returns true if the images capture service ready to use. |
|
176 */ |
|
177 bool QStillImageCapture::isAvailable() const |
|
178 { |
|
179 if (d_func()->control != NULL) |
|
180 return true; |
|
181 else |
|
182 return false; |
|
183 } |
|
184 |
|
185 /*! |
|
186 Returns the availability error code. |
|
187 */ |
|
188 QtMedia::AvailabilityError QStillImageCapture::availabilityError() const |
|
189 { |
|
190 if (d_func()->control != NULL) |
|
191 return QtMedia::NoError; |
|
192 else |
|
193 return QtMedia::ServiceMissingError; |
|
194 } |
|
195 |
|
196 /*! |
|
197 Returns the current error state. |
|
198 |
|
199 \sa errorString() |
|
200 */ |
|
201 |
|
202 QStillImageCapture::Error QStillImageCapture::error() const |
|
203 { |
|
204 return d_func()->error; |
|
205 } |
|
206 |
|
207 /*! |
|
208 Returns a string describing the current error state. |
|
209 |
|
210 \sa error() |
|
211 */ |
|
212 |
|
213 QString QStillImageCapture::errorString() const |
|
214 { |
|
215 return d_func()->errorString; |
|
216 } |
|
217 |
|
218 |
|
219 /*! |
|
220 Returns a list of supported image codecs. |
|
221 */ |
|
222 QStringList QStillImageCapture::supportedImageCodecs() const |
|
223 { |
|
224 return d_func()->encoderControl ? |
|
225 d_func()->encoderControl->supportedImageCodecs() : QStringList(); |
|
226 } |
|
227 |
|
228 /*! |
|
229 Returns a description of an image \a codec. |
|
230 */ |
|
231 QString QStillImageCapture::imageCodecDescription(const QString &codec) const |
|
232 { |
|
233 return d_func()->encoderControl ? |
|
234 d_func()->encoderControl->imageCodecDescription(codec) : QString(); |
|
235 } |
|
236 |
|
237 /*! |
|
238 Returns a list of resolutions images can be encoded at. |
|
239 |
|
240 If non null image \a settings parameter is passed, |
|
241 the returned list is reduced to resolution supported with partial settings like image codec or quality applied. |
|
242 |
|
243 If the encoder supports arbitrary resolutions within the supported range, |
|
244 *\a continuous is set to true, otherwise *\a continuous is set to false. |
|
245 |
|
246 \sa QImageEncoderSettings::resolution() |
|
247 */ |
|
248 QList<QSize> QStillImageCapture::supportedResolutions(const QImageEncoderSettings &settings, bool *continuous) const |
|
249 { |
|
250 if (continuous) |
|
251 *continuous = false; |
|
252 |
|
253 return d_func()->encoderControl ? |
|
254 d_func()->encoderControl->supportedResolutions(settings, continuous) : QList<QSize>(); |
|
255 } |
|
256 |
|
257 /*! |
|
258 Returns the image encoder settings being used. |
|
259 |
|
260 \sa setEncodingSettings() |
|
261 */ |
|
262 |
|
263 QImageEncoderSettings QStillImageCapture::encodingSettings() const |
|
264 { |
|
265 return d_func()->encoderControl ? |
|
266 d_func()->encoderControl->imageSettings() : QImageEncoderSettings(); |
|
267 } |
|
268 |
|
269 /*! |
|
270 Sets the image encodeing \a settings. |
|
271 |
|
272 If some parameters are not specified, or null settings are passed, |
|
273 the encoder choose the default encoding parameters. |
|
274 |
|
275 \sa encodingSettings() |
|
276 */ |
|
277 |
|
278 void QStillImageCapture::setEncodingSettings(const QImageEncoderSettings &settings) |
|
279 { |
|
280 Q_D(QStillImageCapture); |
|
281 |
|
282 if (d->encoderControl) |
|
283 d->encoderControl->setImageSettings(settings); |
|
284 } |
|
285 |
|
286 /*! |
|
287 \property QStillImageCapture::readyForCapture |
|
288 Indicates the service is ready to capture an image immediately. |
|
289 */ |
|
290 |
|
291 bool QStillImageCapture::isReadyForCapture() const |
|
292 { |
|
293 return d_func()->control ? d_func()->control->isReadyForCapture() : false; |
|
294 } |
|
295 |
|
296 /*! |
|
297 \fn QStillImageCapture::readyForCaptureChanged(bool ready) |
|
298 |
|
299 Signals that a camera's \a ready for capture state has changed. |
|
300 */ |
|
301 |
|
302 /*! |
|
303 Capture the image and save it to \a file. |
|
304 This operation is asynchronous in majority of cases, |
|
305 followed by signals QStillImageCapture::imageCaptured(), QStillImageCapture::imageSaved() |
|
306 or QStillImageCapture::error() |
|
307 */ |
|
308 void QStillImageCapture::capture(const QString &file) |
|
309 { |
|
310 Q_D(QStillImageCapture); |
|
311 |
|
312 d->unsetError(); |
|
313 |
|
314 if (d->control) { |
|
315 d->control->capture(file); |
|
316 } else { |
|
317 d->error = NotSupportedFeatureError; |
|
318 d->errorString = tr("Device does not support images capture."); |
|
319 |
|
320 emit error(d->error); |
|
321 } |
|
322 } |
|
323 |
|
324 |
|
325 /*! |
|
326 \enum QStillImageCapture::Error |
|
327 |
|
328 \value NoError No Errors. |
|
329 \value NotReadyError The service is not ready for capture yet. |
|
330 \value ResourceError Device is not ready or not available. |
|
331 \value NotSupportedFeatureError Device does not support stillimages capture. |
|
332 \value FormatError Current format is not supported. |
|
333 */ |
|
334 |
|
335 /*! |
|
336 \fn QStillImageCapture::error(QStillImageCapture::Error error) |
|
337 |
|
338 Signals that an \a error has occurred. |
|
339 */ |
|
340 |
|
341 |
|
342 #include "moc_qstillimagecapture.cpp" |
|
343 QTM_END_NAMESPACE |
|
344 |
|