diff options
Diffstat (limited to 'src/plugins')
6 files changed, 163 insertions, 8 deletions
diff --git a/src/plugins/avfoundation/camera/avfcameraservice.h b/src/plugins/avfoundation/camera/avfcameraservice.h index ec2884217..1397a7dee 100644 --- a/src/plugins/avfoundation/camera/avfcameraservice.h +++ b/src/plugins/avfoundation/camera/avfcameraservice.h @@ -71,6 +71,7 @@ class AVFAudioEncoderSettingsControl; class AVFVideoEncoderSettingsControl; class AVFMediaContainerControl; class AVFCameraWindowControl; +class AVFCaptureDestinationControl; class AVFCameraService : public QMediaService { @@ -100,6 +101,7 @@ public: AVFAudioEncoderSettingsControl *audioEncoderSettingsControl() const { return m_audioEncoderSettingsControl; } AVFVideoEncoderSettingsControl *videoEncoderSettingsControl() const {return m_videoEncoderSettingsControl; } AVFMediaContainerControl *mediaContainerControl() const { return m_mediaContainerControl; } + AVFCaptureDestinationControl *captureDestinationControl() const { return m_captureDestinationControl; } private: AVFCameraSession *m_session; @@ -122,6 +124,7 @@ private: AVFVideoEncoderSettingsControl *m_videoEncoderSettingsControl; AVFMediaContainerControl *m_mediaContainerControl; AVFCameraWindowControl *m_captureWindowControl; + AVFCaptureDestinationControl *m_captureDestinationControl; }; QT_END_NAMESPACE diff --git a/src/plugins/avfoundation/camera/avfcameraservice.mm b/src/plugins/avfoundation/camera/avfcameraservice.mm index 627ecf67c..79bf73910 100644 --- a/src/plugins/avfoundation/camera/avfcameraservice.mm +++ b/src/plugins/avfoundation/camera/avfcameraservice.mm @@ -61,6 +61,7 @@ #include "avfaudioencodersettingscontrol.h" #include "avfvideoencodersettingscontrol.h" #include "avfmediacontainercontrol.h" +#include "avfcapturedestinationcontrol.h" #include "avfcamerawindowcontrol.h" #ifdef Q_OS_IOS @@ -111,6 +112,7 @@ AVFCameraService::AVFCameraService(QObject *parent): m_audioEncoderSettingsControl = new AVFAudioEncoderSettingsControl(this); m_videoEncoderSettingsControl = new AVFVideoEncoderSettingsControl(this); m_mediaContainerControl = new AVFMediaContainerControl(this); + m_captureDestinationControl = new AVFCaptureDestinationControl; } AVFCameraService::~AVFCameraService() @@ -151,6 +153,7 @@ AVFCameraService::~AVFCameraService() delete m_audioEncoderSettingsControl; delete m_videoEncoderSettingsControl; delete m_mediaContainerControl; + delete m_captureDestinationControl; delete m_session; } @@ -218,6 +221,9 @@ QMediaControl *AVFCameraService::requestControl(const char *name) return m_cameraZoomControl; #endif + if (qstrcmp(name, QCameraCaptureDestinationControl_iid) == 0) + return m_captureDestinationControl; + if (!m_captureWindowControl) { if (qstrcmp(name, QVideoWindowControl_iid) == 0) { m_captureWindowControl = new AVFCameraWindowControl(this); diff --git a/src/plugins/avfoundation/camera/avfcapturedestinationcontrol.h b/src/plugins/avfoundation/camera/avfcapturedestinationcontrol.h new file mode 100644 index 000000000..04493437e --- /dev/null +++ b/src/plugins/avfoundation/camera/avfcapturedestinationcontrol.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef AVFCAPTUREDESTINATIONCONTROL_H +#define AVFCAPTUREDESTINATIONCONTROL_H + +#include <qcameracapturedestinationcontrol.h> + +QT_BEGIN_NAMESPACE + +class AVFCaptureDestinationControl : public QCameraCaptureDestinationControl +{ +public: + AVFCaptureDestinationControl() = default; + ~AVFCaptureDestinationControl() = default; + + bool isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const override; + QCameraImageCapture::CaptureDestinations captureDestination() const override; + void setCaptureDestination(QCameraImageCapture::CaptureDestinations destination) override; + +private: + QCameraImageCapture::CaptureDestinations m_destination = QCameraImageCapture::CaptureToFile; +}; + +QT_END_NAMESPACE + +#endif // AVFCAPTUREDESTINATIONCONTROL_H diff --git a/src/plugins/avfoundation/camera/avfcapturedestinationcontrol.mm b/src/plugins/avfoundation/camera/avfcapturedestinationcontrol.mm new file mode 100644 index 000000000..d0700d69d --- /dev/null +++ b/src/plugins/avfoundation/camera/avfcapturedestinationcontrol.mm @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "avfcapturedestinationcontrol.h" + +QT_BEGIN_NAMESPACE + +bool AVFCaptureDestinationControl::isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const +{ + return destination & (QCameraImageCapture::CaptureToFile | QCameraImageCapture::CaptureToBuffer); +} + +QCameraImageCapture::CaptureDestinations AVFCaptureDestinationControl::captureDestination() const +{ + return m_destination; +} + +void AVFCaptureDestinationControl::setCaptureDestination(QCameraImageCapture::CaptureDestinations destination) +{ + if (m_destination != destination) { + m_destination = destination; + Q_EMIT captureDestinationChanged(m_destination); + } +} + +QT_END_NAMESPACE diff --git a/src/plugins/avfoundation/camera/avfimagecapturecontrol.mm b/src/plugins/avfoundation/camera/avfimagecapturecontrol.mm index 58d42bcaf..f2c019fdc 100644 --- a/src/plugins/avfoundation/camera/avfimagecapturecontrol.mm +++ b/src/plugins/avfoundation/camera/avfimagecapturecontrol.mm @@ -42,6 +42,8 @@ #include "avfcameraservice.h" #include "avfcamerautility.h" #include "avfcameracontrol.h" +#include "avfcapturedestinationcontrol.h" +#include <private/qmemoryvideobuffer_p.h> #include <QtCore/qurl.h> #include <QtCore/qfile.h> @@ -111,12 +113,16 @@ int AVFImageCaptureControl::capture(const QString &fileName) return m_lastCaptureId; } - QString actualFileName = m_storageLocation.generateFileName(fileName, - QCamera::CaptureStillImage, - QLatin1String("img_"), - QLatin1String("jpg")); + auto destination = m_service->captureDestinationControl()->captureDestination(); + QString actualFileName; + if (destination & QCameraImageCapture::CaptureToFile) { + actualFileName = m_storageLocation.generateFileName(fileName, + QCamera::CaptureStillImage, + QLatin1String("img_"), + QLatin1String("jpg")); - qDebugCamera() << "Capture image to" << actualFileName; + qDebugCamera() << "Capture image to" << actualFileName; + } CaptureRequest request = { m_lastCaptureId, QSharedPointer<QSemaphore>::create()}; m_requestsMutex.lock(); @@ -152,11 +158,24 @@ int AVFImageCaptureControl::capture(const QString &fileName) // 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 (!m_service->videoOutput() || request.previewReady->tryAcquire(1, 1000)) { - qDebugCamera() << "Image capture completed:" << actualFileName; + qDebugCamera() << "Image capture completed"; NSData *nsJpgData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]; QByteArray jpgData = QByteArray::fromRawData((const char *)[nsJpgData bytes], [nsJpgData length]); + if (destination & QCameraImageCapture::CaptureToBuffer) { + QBuffer data(&jpgData); + QImageReader reader(&data, "JPEG"); + QSize size = reader.size(); + QVideoFrame frame(new QMemoryVideoBuffer(QByteArray(jpgData.constData(), jpgData.size()), -1), size, QVideoFrame::Format_Jpeg); + QMetaObject::invokeMethod(this, "imageAvailable", Qt::QueuedConnection, + Q_ARG(int, request.captureId), + Q_ARG(QVideoFrame, frame)); + } + + if (!(destination & QCameraImageCapture::CaptureToFile)) + return; + QFile f(actualFileName); if (f.open(QFile::WriteOnly)) { if (f.write(jpgData) != -1) { diff --git a/src/plugins/avfoundation/camera/camera.pro b/src/plugins/avfoundation/camera/camera.pro index 70caf7536..76aa8af85 100644 --- a/src/plugins/avfoundation/camera/camera.pro +++ b/src/plugins/avfoundation/camera/camera.pro @@ -43,7 +43,8 @@ HEADERS += \ avfvideoencodersettingscontrol.h \ avfmediacontainercontrol.h \ avfaudioencodersettingscontrol.h \ - avfcamerawindowcontrol.h + avfcamerawindowcontrol.h \ + avfcapturedestinationcontrol.h OBJECTIVE_SOURCES += \ avfcameraserviceplugin.mm \ @@ -67,7 +68,8 @@ OBJECTIVE_SOURCES += \ avfvideoencodersettingscontrol.mm \ avfmediacontainercontrol.mm \ avfaudioencodersettingscontrol.mm \ - avfcamerawindowcontrol.mm + avfcamerawindowcontrol.mm \ + avfcapturedestinationcontrol.mm osx { |