diff options
author | Timur Pocheptsov <timur.pocheptsov@qt.io> | 2017-06-26 17:00:38 +0200 |
---|---|---|
committer | Timur Pocheptsov <timur.pocheptsov@qt.io> | 2017-06-27 10:16:08 +0000 |
commit | 6ac5b9fb591b1c45ff61a633bbbfebd63f34b9f7 (patch) | |
tree | 356ba0c4070a8b089b13e52b4813919c1fc8b5ba | |
parent | e8e9f40ebc0d822fe639bed75d185800ff16b452 (diff) | |
download | qtmultimedia-6ac5b9fb591b1c45ff61a633bbbfebd63f34b9f7.tar.gz |
AVFoundation: Make AVFImageCaptureControl work without a preview
We only need to wait for a new viewfinder frame if we have a
videorenderer control. If there's no videorender control, then there's
no preview set and we can therefore just save the capture image
immediately.
Task-number: QTBUG-60329
Change-Id: I9ba34919f7cd82258482507c65db6367e330e231
Reviewed-by: Christian Stromme <christian.stromme@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
-rw-r--r-- | src/plugins/avfoundation/camera/avfimagecapturecontrol.h | 1 | ||||
-rw-r--r-- | src/plugins/avfoundation/camera/avfimagecapturecontrol.mm | 7 |
2 files changed, 5 insertions, 3 deletions
diff --git a/src/plugins/avfoundation/camera/avfimagecapturecontrol.h b/src/plugins/avfoundation/camera/avfimagecapturecontrol.h index 0671034e3..2cdf0e5f3 100644 --- a/src/plugins/avfoundation/camera/avfimagecapturecontrol.h +++ b/src/plugins/avfoundation/camera/avfimagecapturecontrol.h @@ -80,6 +80,7 @@ private Q_SLOTS: private: void makeCapturePreview(CaptureRequest request, const QVideoFrame &frame, int rotation); + AVFCameraService *m_service; AVFCameraSession *m_session; AVFCameraControl *m_cameraControl; bool m_ready; diff --git a/src/plugins/avfoundation/camera/avfimagecapturecontrol.mm b/src/plugins/avfoundation/camera/avfimagecapturecontrol.mm index 2a654c94f..bad1b362b 100644 --- a/src/plugins/avfoundation/camera/avfimagecapturecontrol.mm +++ b/src/plugins/avfoundation/camera/avfimagecapturecontrol.mm @@ -54,6 +54,7 @@ QT_USE_NAMESPACE AVFImageCaptureControl::AVFImageCaptureControl(AVFCameraService *service, QObject *parent) : QCameraImageCaptureControl(parent) + , m_service(service) , m_session(service->session()) , m_cameraControl(service->cameraControl()) , m_ready(false) @@ -68,7 +69,6 @@ AVFImageCaptureControl::AVFImageCaptureControl(AVFCameraService *service, QObjec [m_stillImageOutput setOutputSettings:outputSettings]; [outputSettings release]; - connect(m_cameraControl, SIGNAL(captureModeChanged(QCamera::CaptureModes)), SLOT(updateReadyStatus())); connect(m_cameraControl, SIGNAL(statusChanged(QCamera::Status)), SLOT(updateReadyStatus())); @@ -143,7 +143,8 @@ int AVFImageCaptureControl::capture(const QString &fileName) return; } - // Wait for the preview to be generated before saving the JPEG. + // Wait for the preview to be generated before saving the JPEG (but only + // if we have AVFCameraRendererControl attached). // It is possible to stop camera immediately after trying to capture an // image; this can result in a blocked callback's thread, waiting for a // new viewfinder's frame to arrive/semaphore to be released. It is also @@ -151,7 +152,7 @@ int AVFImageCaptureControl::capture(const QString &fileName) // not the same thread that initiated a capture and stopped the camera), // so we cannot reliably check the camera's status. Instead, we wait // with a timeout and treat a failure to acquire a semaphore as an error. - if (request.previewReady->tryAcquire(1, 1000)) { + if (!m_service->videoOutput() || request.previewReady->tryAcquire(1, 1000)) { qDebugCamera() << "Image capture completed:" << actualFileName; NSData *nsJpgData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]; |