diff options
author | Lars Knoll <lars.knoll@qt.io> | 2021-03-05 11:16:53 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2021-03-16 12:58:22 +0000 |
commit | c93b4b54c44ca28e34fe7e12cc2fb279f3e84b54 (patch) | |
tree | 74dcff9f6fca1d5a7706b242b0a9bae8c9bd38fc /src/imports | |
parent | 4c7a93115a6346d318c4a23f70cf858781ec4591 (diff) |
Make QMediaCaptureSession the new central class for media capturing
You now need to instantiate a capture session and hook up
camera, image capture and recording to it.
This gives a cleaner architecture for the whole capturing process.
Change-Id: I7c7f6c4a841512b038834f4653ef7ab790c43f8f
Reviewed-by: Doris Verria <doris.verria@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/imports')
7 files changed, 14 insertions, 80 deletions
diff --git a/src/imports/multimedia/qdeclarativecamera.cpp b/src/imports/multimedia/qdeclarativecamera.cpp index 481c2f055..9e4f775a8 100644 --- a/src/imports/multimedia/qdeclarativecamera.cpp +++ b/src/imports/multimedia/qdeclarativecamera.cpp @@ -171,8 +171,8 @@ QDeclarativeCamera::QDeclarativeCamera(QObject *parent) : m_currentCameraInfo = QMediaDeviceManager::defaultVideoInput(); m_camera = new QCamera(m_currentCameraInfo); - m_imageCapture = new QDeclarativeCameraCapture(m_camera); - m_videoRecorder = new QDeclarativeCameraRecorder(m_camera); + m_imageCapture = new QDeclarativeCameraCapture(&captureSession); + m_videoRecorder = new QDeclarativeCameraRecorder(&captureSession); m_exposure = new QDeclarativeCameraExposure(m_camera); m_flash = new QDeclarativeCameraFlash(m_camera); m_torch = new QDeclarativeTorch(m_camera); diff --git a/src/imports/multimedia/qdeclarativecamera_p.h b/src/imports/multimedia/qdeclarativecamera_p.h index ebe7b4d2a..c06df6c42 100644 --- a/src/imports/multimedia/qdeclarativecamera_p.h +++ b/src/imports/multimedia/qdeclarativecamera_p.h @@ -58,6 +58,7 @@ #include <qcamerainfo.h> #include <qcameraimageprocessing.h> #include <qcameraimagecapture.h> +#include <qmediacapturesession.h> #include <QtCore/qbasictimer.h> #include <QtCore/qdatetime.h> @@ -246,6 +247,7 @@ private: Q_DISABLE_COPY(QDeclarativeCamera) void setupDevice(const QString &deviceName); + QMediaCaptureSession captureSession; QCamera *m_camera; QCameraInfo m_currentCameraInfo; diff --git a/src/imports/multimedia/qdeclarativecameracapture.cpp b/src/imports/multimedia/qdeclarativecameracapture.cpp index 59267e792..3360cc319 100644 --- a/src/imports/multimedia/qdeclarativecameracapture.cpp +++ b/src/imports/multimedia/qdeclarativecameracapture.cpp @@ -95,11 +95,10 @@ QT_BEGIN_NAMESPACE */ -QDeclarativeCameraCapture::QDeclarativeCameraCapture(QCamera *camera) - : QObject(camera), - m_camera(camera) +QDeclarativeCameraCapture::QDeclarativeCameraCapture(QMediaCaptureSession *captureSession) + : QObject(captureSession) { - m_capture = new QCameraImageCapture(camera); + m_capture = new QCameraImageCapture(captureSession); connect(m_capture, SIGNAL(readyForCaptureChanged(bool)), this, SIGNAL(readyForCaptureChanged(bool))); connect(m_capture, SIGNAL(imageExposed(int)), this, SIGNAL(imageExposed(int))); @@ -109,9 +108,6 @@ QDeclarativeCameraCapture::QDeclarativeCameraCapture(QCamera *camera) connect(m_capture, SIGNAL(imageSaved(int,QString)), this, SLOT(_q_imageSaved(int,QString))); connect(m_capture, SIGNAL(error(int,QCameraImageCapture::Error,QString)), this, SLOT(_q_captureFailed(int,QCameraImageCapture::Error,QString))); - - connect(m_camera, SIGNAL(statusChanged(QCamera::Status)), - this, SLOT(_q_cameraStatusChanged(QCamera::Status))); } QDeclarativeCameraCapture::~QDeclarativeCameraCapture() = default; @@ -230,44 +226,12 @@ void QDeclarativeCameraCapture::_q_captureFailed(int id, QCameraImageCapture::Er emit captureFailed(id, message); } -void QDeclarativeCameraCapture::_q_cameraStatusChanged(QCamera::Status status) -{ - if (status != QCamera::InactiveStatus && status != QCamera::ActiveStatus) - return; - - emit supportedResolutionsChanged(); -} /*! \property QDeclarativeCameraCapture::resolution This property holds the resolution/size of the image to be captured. If empty, the system chooses the appropriate resolution. */ - -/*! - \qmlproperty size QtMultimedia::CameraCapture::resolution - - This property holds the resolution/size of the image to be captured. - If empty, the system chooses the appropriate resolution. - - \sa supportedResolutions -*/ - -QSize QDeclarativeCameraCapture::resolution() -{ - return m_imageSettings.resolution(); -} - -void QDeclarativeCameraCapture::setResolution(const QSize &captureResolution) -{ - m_imageSettings = m_capture->encodingSettings(); - if (captureResolution != resolution()) { - m_imageSettings.setResolution(captureResolution); - m_capture->setEncodingSettings(m_imageSettings); - emit resolutionChanged(captureResolution); - } -} - QCameraImageCapture::Error QDeclarativeCameraCapture::error() const { return m_capture->error(); @@ -289,29 +253,6 @@ QString QDeclarativeCameraCapture::errorString() const } /*! - \qmlproperty list<size> QtMultimedia::CameraCapture::supportedResolutions - - This property holds a list of resolutions which are supported for capturing. - The information can be used to set a valid \e resolution. If the camera isn't - loaded, the list will be empty. - - \since 5.9 - \sa resolution - */ -QVariantList QDeclarativeCameraCapture::supportedResolutions() -{ - QVariantList supportedResolutions; - - if (m_camera) { - auto resolutions = m_camera->cameraInfo().photoResolutions(); - for (const auto &r : resolutions) - supportedResolutions.append(r); - } - - return supportedResolutions; -} - -/*! \qmlmethod QtMultimedia::CameraCapture::setMetadata(key, value) diff --git a/src/imports/multimedia/qdeclarativecameracapture_p.h b/src/imports/multimedia/qdeclarativecameracapture_p.h index aa6aa8fc6..055b16b1d 100644 --- a/src/imports/multimedia/qdeclarativecameracapture_p.h +++ b/src/imports/multimedia/qdeclarativecameracapture_p.h @@ -67,28 +67,22 @@ class QDeclarativeCameraCapture : public QObject Q_OBJECT Q_PROPERTY(bool ready READ isReadyForCapture NOTIFY readyForCaptureChanged) Q_PROPERTY(QString capturedImagePath READ capturedImagePath NOTIFY imageSaved) - Q_PROPERTY(QSize resolution READ resolution WRITE setResolution NOTIFY resolutionChanged) Q_PROPERTY(QString errorString READ errorString NOTIFY captureFailed) - Q_PROPERTY(QVariantList supportedResolutions READ supportedResolutions NOTIFY supportedResolutionsChanged REVISION 1) public: ~QDeclarativeCameraCapture(); bool isReadyForCapture() const; - QSize resolution(); - QString capturedImagePath() const; QCameraImageCapture::Error error() const; QString errorString() const; - QVariantList supportedResolutions(); public Q_SLOTS: int capture(); int captureToLocation(const QString &location); void cancelCapture(); - void setResolution(const QSize &resolution); void setMetadata(QMediaMetaData::Key key, const QVariant &value); Q_SIGNALS: @@ -100,20 +94,15 @@ Q_SIGNALS: void imageSaved(int requestId, const QString &path); void captureFailed(int requestId, const QString &message); - void resolutionChanged(const QSize &); - void supportedResolutionsChanged(); - private slots: void _q_imageCaptured(int, const QImage&); void _q_imageSaved(int, const QString&); void _q_captureFailed(int, QCameraImageCapture::Error, const QString&); - void _q_cameraStatusChanged(QCamera::Status status); private: friend class QDeclarativeCamera; - QDeclarativeCameraCapture(QCamera *camera); + QDeclarativeCameraCapture(QMediaCaptureSession *captureSession); - QCamera *m_camera; QCameraImageCapture *m_capture; QImageEncoderSettings m_imageSettings; QString m_capturedImagePath; diff --git a/src/imports/multimedia/qdeclarativecamerarecorder.cpp b/src/imports/multimedia/qdeclarativecamerarecorder.cpp index 39d218373..d5e49b6cf 100644 --- a/src/imports/multimedia/qdeclarativecamerarecorder.cpp +++ b/src/imports/multimedia/qdeclarativecamerarecorder.cpp @@ -75,10 +75,11 @@ QT_BEGIN_NAMESPACE \sa QAudioEncoderSettings, QVideoEncoderSettings */ -QDeclarativeCameraRecorder::QDeclarativeCameraRecorder(QCamera *camera, QObject *parent) : +QDeclarativeCameraRecorder::QDeclarativeCameraRecorder(QMediaCaptureSession *session, QObject *parent) : QObject(parent) { - m_recorder = new QMediaRecorder(camera, this); + m_recorder = new QMediaRecorder(this); + session->setRecorder(m_recorder); connect(m_recorder, SIGNAL(stateChanged(QMediaRecorder::State)), SLOT(updateRecorderState(QMediaRecorder::State))); connect(m_recorder, SIGNAL(statusChanged(QMediaRecorder::Status)), diff --git a/src/imports/multimedia/qdeclarativecamerarecorder_p.h b/src/imports/multimedia/qdeclarativecamerarecorder_p.h index 613d00cb6..48a35703a 100644 --- a/src/imports/multimedia/qdeclarativecamerarecorder_p.h +++ b/src/imports/multimedia/qdeclarativecamerarecorder_p.h @@ -209,7 +209,7 @@ private slots: private: friend class QDeclarativeCamera; - QDeclarativeCameraRecorder(QCamera *camera, QObject *parent = 0); + QDeclarativeCameraRecorder(QMediaCaptureSession *session, QObject *parent = 0); QMediaRecorder *m_recorder = nullptr; QDeclarativeMediaMetaData *m_metaData = nullptr; diff --git a/src/imports/multimedia/qdeclarativetorch.cpp b/src/imports/multimedia/qdeclarativetorch.cpp index 66f2105f4..d0fabe099 100644 --- a/src/imports/multimedia/qdeclarativetorch.cpp +++ b/src/imports/multimedia/qdeclarativetorch.cpp @@ -40,6 +40,7 @@ #include <QDebug> #include <private/qplatformmediacapture_p.h> #include <private/qplatformcamera_p.h> +#include <qmediacapturesession.h> #include "qdeclarativetorch_p.h" @@ -73,7 +74,7 @@ QDeclarativeTorch::QDeclarativeTorch(QCamera *camera) { if (!camera) return; - auto *service = m_camera->captureInterface(); + auto *service = m_camera->captureSession()->platformSession(); m_exposure = service->cameraControl()->exposureControl(); if (m_exposure) |