diff options
author | Lars Knoll <lars.knoll@qt.io> | 2021-05-18 09:29:01 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2021-05-19 18:11:48 +0000 |
commit | 0c40d337ae107d5ab2fde5da022c071c64c67e0e (patch) | |
tree | 5c2a84a1bd708cbcbb20c92fdb679e06caa0d17f | |
parent | 743fb1e2a85fc2b0f9de09c100f2188ce53b1178 (diff) | |
download | qtmultimedia-0c40d337ae107d5ab2fde5da022c071c64c67e0e.tar.gz |
Move QPlatformCameraExposure API into QPlatformCamera
Clean up the internal API while we're at it and get rid of the
multiplexing API. Instead have virtual methods for each
property.
Change-Id: I62cb178ff8360edbd11abb3fc5a0cfd7d8abdb2b
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Doris Verria <doris.verria@qt.io>
36 files changed, 1249 insertions, 2943 deletions
diff --git a/src/multimedia/CMakeLists.txt b/src/multimedia/CMakeLists.txt index a8097ca4e..7994ed945 100644 --- a/src/multimedia/CMakeLists.txt +++ b/src/multimedia/CMakeLists.txt @@ -31,7 +31,6 @@ qt_internal_add_module(Multimedia camera/qcamerainfo.cpp camera/qcamerainfo.h camera/qcamerainfo_p.h platform/qplatformaudiodecoder.cpp platform/qplatformaudiodecoder_p.h platform/qplatformcamera.cpp platform/qplatformcamera_p.h - platform/qplatformcameraexposure.cpp platform/qplatformcameraexposure_p.h platform/qplatformcameraimagecapture.cpp platform/qplatformcameraimagecapture_p.h platform/qplatformcameraimageprocessing.cpp platform/qplatformcameraimageprocessing_p.h platform/qplatformmediacapture.cpp platform/qplatformmediacapture_p.h @@ -153,8 +152,6 @@ qt_internal_extend_target(Multimedia CONDITION WIN32 platform/windows/player/mfvideorenderercontrol.cpp platform/windows/player/mfvideorenderercontrol_p.h platform/windows/player/samplegrabber.cpp platform/windows/player/samplegrabber_p.h platform/windows/mediacapture/qwindowscamera.cpp - platform/windows/mediacapture/qwindowscameraexposure.cpp - platform/windows/mediacapture/qwindowscameraexposure_p.h platform/windows/mediacapture/qwindowscameraimagecapture.cpp platform/windows/mediacapture/qwindowscameraimagecapture_p.h platform/windows/mediacapture/qwindowscameraimageprocessing.cpp @@ -232,7 +229,6 @@ qt_internal_extend_target(Multimedia CONDITION QT_FEATURE_gstreamer platform/gstreamer/qgstreamerintegration.cpp platform/gstreamer/qgstreamerintegration_p.h platform/gstreamer/mediacapture/qgstreamercamera.cpp platform/gstreamer/mediacapture/qgstreamercamera_p.h platform/gstreamer/mediacapture/qgstreamercameraimageprocessing.cpp platform/gstreamer/mediacapture/qgstreamercameraimageprocessing_p.h - platform/gstreamer/mediacapture/qgstreamercameraexposure.cpp platform/gstreamer/mediacapture/qgstreamercameraexposure_p.h platform/gstreamer/mediacapture/qgstreamermediacapture.cpp platform/gstreamer/mediacapture/qgstreamermediacapture_p.h platform/gstreamer/mediacapture/qgstreamercameraimagecapture.cpp platform/gstreamer/mediacapture/qgstreamercameraimagecapture_p.h platform/gstreamer/mediacapture/qgstreamermediaencoder.cpp platform/gstreamer/mediacapture/qgstreamermediaencoder_p.h @@ -311,7 +307,6 @@ qt_internal_extend_target(Multimedia CONDITION ANDROID platform/android/common/qandroidmultimediautils.cpp platform/android/common/qandroidmultimediautils_p.h platform/android/common/qandroidvideooutput.cpp platform/android/common/qandroidvideooutput_p.h platform/android/mediacapture/qandroidcameracontrol.cpp platform/android/mediacapture/qandroidcameracontrol_p.h - platform/android/mediacapture/qandroidcameraexposurecontrol.cpp platform/android/mediacapture/qandroidcameraexposurecontrol_p.h platform/android/mediacapture/qandroidcameraimagecapturecontrol.cpp platform/android/mediacapture/qandroidcameraimagecapturecontrol_p.h platform/android/mediacapture/qandroidcameraimageprocessingcontrol.cpp platform/android/mediacapture/qandroidcameraimageprocessingcontrol_p.h platform/android/mediacapture/qandroidcamerasession.cpp platform/android/mediacapture/qandroidcamerasession_p.h @@ -404,7 +399,6 @@ qt_internal_extend_target(Multimedia CONDITION APPLE AND NOT TVOS AND NOT WATCHO SOURCES platform/darwin/camera/avfcamera.mm platform/darwin/camera/avfcamera_p.h platform/darwin/camera/avfcameradebug_p.h - platform/darwin/camera/avfcameraexposure.mm platform/darwin/camera/avfcameraexposure_p.h platform/darwin/camera/avfcameraimageprocessing.mm platform/darwin/camera/avfcameraimageprocessing_p.h platform/darwin/camera/avfcamerarenderer.mm platform/darwin/camera/avfcamerarenderer_p.h platform/darwin/camera/avfcameraservice.mm platform/darwin/camera/avfcameraservice_p.h diff --git a/src/multimedia/camera/qcamera.cpp b/src/multimedia/camera/qcamera.cpp index 8202248d5..e69155666 100644 --- a/src/multimedia/camera/qcamera.cpp +++ b/src/multimedia/camera/qcamera.cpp @@ -42,7 +42,6 @@ #include <qcamerainfo.h> #include <private/qplatformcamera_p.h> -#include <private/qplatformcameraexposure_p.h> #include <private/qplatformcameraimageprocessing_p.h> #include <private/qplatformcameraimagecapture_p.h> #include <private/qplatformmediaintegration_p.h> @@ -127,15 +126,6 @@ void QCameraPrivate::init() q->connect(control, SIGNAL(activeChanged(bool)), q, SIGNAL(activeChanged(bool))); q->connect(control, SIGNAL(error(int,QString)), q, SLOT(_q_error(int,QString))); - exposureControl = control->exposureControl(); - if (exposureControl) { - q->connect(exposureControl, SIGNAL(actualValueChanged(int)), - q, SLOT(_q_exposureParameterChanged(int))); - q->connect(exposureControl, SIGNAL(parameterRangeChanged(int)), - q, SLOT(_q_exposureParameterRangeChanged(int))); - q->connect(exposureControl, SIGNAL(flashReady(bool)), q, SIGNAL(flashReady(bool))); - } - imageControl = control->imageProcessingControl(); } @@ -651,71 +641,6 @@ void QCamera::zoomTo(float factor, float rate) like capture mode or resolution. */ - -template<typename T> -T QCameraPrivate::actualExposureParameter(QPlatformCameraExposure::ExposureParameter parameter, const T &defaultValue) const -{ - QVariant value = exposureControl ? exposureControl->actualValue(parameter) : QVariant(); - - return value.isValid() ? value.value<T>() : defaultValue; -} - -template<typename T> -T QCameraPrivate::requestedExposureParameter(QPlatformCameraExposure::ExposureParameter parameter, const T &defaultValue) const -{ - QVariant value = exposureControl ? exposureControl->requestedValue(parameter) : QVariant(); - - return value.isValid() ? value.value<T>() : defaultValue; -} - -template<typename T> -void QCameraPrivate::setExposureParameter(QPlatformCameraExposure::ExposureParameter parameter, const T &value) -{ - if (exposureControl) - exposureControl->setValue(parameter, QVariant::fromValue<T>(value)); -} - -void QCameraPrivate::resetExposureParameter(QPlatformCameraExposure::ExposureParameter parameter) -{ - if (exposureControl) - exposureControl->setValue(parameter, QVariant()); -} - - -void QCameraPrivate::_q_exposureParameterChanged(int parameter) -{ - Q_Q(QCamera); - -#if DEBUG_EXPOSURE_CHANGES - qDebug() << "Exposure parameter changed:" - << QPlatformCameraExposure::ExposureParameter(parameter) - << exposureControl->actualValue(QPlatformCameraExposure::ExposureParameter(parameter)); -#endif - - switch (parameter) { - case QPlatformCameraExposure::ISO: - emit q->isoSensitivityChanged(q->isoSensitivity()); - break; - case QPlatformCameraExposure::ShutterSpeed: - emit q->shutterSpeedChanged(q->shutterSpeed()); - break; - case QPlatformCameraExposure::ExposureCompensation: - emit q->exposureCompensationChanged(q->exposureCompensation()); - break; - } -} - -void QCameraPrivate::_q_exposureParameterRangeChanged(int parameter) -{ - Q_Q(QCamera); - - switch (parameter) { - case QPlatformCameraExposure::ShutterSpeed: - emit q->shutterSpeedRangeChanged(); - break; - } -} - /*! \property QCamera::flashMode \brief The flash mode being used. @@ -726,13 +651,15 @@ void QCameraPrivate::_q_exposureParameterRangeChanged(int parameter) */ QCamera::FlashMode QCamera::flashMode() const { - return d_func()->exposureControl ? d_func()->exposureControl->flashMode() : QCamera::FlashOff; + Q_D(const QCamera); + return d->control ? d->control->flashMode() : QCamera::FlashOff; } void QCamera::setFlashMode(QCamera::FlashMode mode) { - if (d_func()->exposureControl) - d_func()->exposureControl->setFlashMode(mode); + Q_D(QCamera); + if (d->control) + d->control->setFlashMode(mode); } /*! @@ -741,7 +668,8 @@ void QCamera::setFlashMode(QCamera::FlashMode mode) bool QCamera::isFlashModeSupported(QCamera::FlashMode mode) const { - return d_func()->exposureControl ? d_func()->exposureControl->isFlashModeSupported(mode) : (mode == FlashOff); + Q_D(const QCamera); + return d->control ? d->control->isFlashModeSupported(mode) : (mode == FlashOff); } /*! @@ -750,7 +678,8 @@ bool QCamera::isFlashModeSupported(QCamera::FlashMode mode) const bool QCamera::isFlashReady() const { - return d_func()->exposureControl ? d_func()->exposureControl->isFlashReady() : false; + Q_D(const QCamera); + return d->control ? d->control->isFlashReady() : false; } /*! @@ -764,13 +693,15 @@ bool QCamera::isFlashReady() const */ QCamera::TorchMode QCamera::torchMode() const { - return d_func()->exposureControl ? d_func()->exposureControl->torchMode() : TorchOff; + Q_D(const QCamera); + return d->control ? d->control->torchMode() : TorchOff; } void QCamera::setTorchMode(QCamera::TorchMode mode) { - if (d_func()->exposureControl) - d_func()->exposureControl->setTorchMode(mode); + Q_D(QCamera); + if (d->control) + d->control->setTorchMode(mode); } /*! @@ -778,7 +709,8 @@ void QCamera::setTorchMode(QCamera::TorchMode mode) */ bool QCamera::isTorchModeSupported(QCamera::TorchMode mode) const { - return d_func()->exposureControl ? d_func()->exposureControl->isTorchModeSupported(mode) : (mode == TorchOff); + Q_D(const QCamera); + return d->control ? d->control->isTorchModeSupported(mode) : (mode == TorchOff); } /*! @@ -790,12 +722,15 @@ bool QCamera::isTorchModeSupported(QCamera::TorchMode mode) const QCamera::ExposureMode QCamera::exposureMode() const { - return d_func()->actualExposureParameter<QCamera::ExposureMode>(QPlatformCameraExposure::ExposureMode, QCamera::ExposureAuto); + Q_D(const QCamera); + return d->control ? d->control->exposureMode() : QCamera::ExposureAuto; } void QCamera::setExposureMode(QCamera::ExposureMode mode) { - d_func()->setExposureParameter<QCamera::ExposureMode>(QPlatformCameraExposure::ExposureMode, mode); + Q_D(QCamera); + if (d->control) + d->control->setExposureMode(mode); } /*! @@ -804,12 +739,11 @@ void QCamera::setExposureMode(QCamera::ExposureMode mode) bool QCamera::isExposureModeSupported(QCamera::ExposureMode mode) const { - if (!d_func()->exposureControl) + Q_D(const QCamera); + if (!d->control) return false; - bool continuous = false; - return d_func()->exposureControl->supportedParameterRange(QPlatformCameraExposure::ExposureMode, &continuous) - .contains(QVariant::fromValue<QCamera::ExposureMode>(mode)); + return d->control->isExposureModeSupported(mode); } /*! @@ -821,57 +755,21 @@ bool QCamera::isExposureModeSupported(QCamera::ExposureMode mode) const qreal QCamera::exposureCompensation() const { - return d_func()->actualExposureParameter<qreal>(QPlatformCameraExposure::ExposureCompensation, 0.0); + Q_D(const QCamera); + return d->control ? d->control->exposureCompensation() : 0.; } void QCamera::setExposureCompensation(qreal ev) { - d_func()->setExposureParameter<qreal>(QPlatformCameraExposure::ExposureCompensation, ev); + Q_D(QCamera); + if (d->control) + d->control->setExposureCompensation(ev); } int QCamera::isoSensitivity() const { - return d_func()->actualExposureParameter<int>(QPlatformCameraExposure::ISO, -1); -} - -/*! - Returns the requested ISO sensitivity - or -1 if automatic ISO is turned on. -*/ -int QCamera::requestedIsoSensitivity() const -{ - return d_func()->requestedExposureParameter<int>(QPlatformCameraExposure::ISO, -1); -} - -/*! - Returns the list of ISO senitivities camera supports. - - If the camera supports arbitrary ISO sensitivities within the supported range, - *\a continuous is set to true, otherwise *\a continuous is set to false. -*/ -QList<int> QCamera::supportedIsoSensitivities(bool *continuous) const -{ - QList<int> res; - QPlatformCameraExposure *control = d_func()->exposureControl; - - bool tmp = false; - if (!continuous) - continuous = &tmp; - - if (!control) - return res; - - const auto range = control->supportedParameterRange(QPlatformCameraExposure::ISO, continuous); - for (const QVariant &value : range) { - bool ok = false; - int intValue = value.toInt(&ok); - if (ok) - res.append(intValue); - else - qWarning() << "Incompatible ISO value type, int is expected"; - } - - return res; + Q_D(const QCamera); + return d->control ? d->control->isoSensitivity() : -1; } /*! @@ -881,7 +779,17 @@ QList<int> QCamera::supportedIsoSensitivities(bool *continuous) const void QCamera::setManualIsoSensitivity(int iso) { - d_func()->setExposureParameter<int>(QPlatformCameraExposure::ISO, iso); + Q_D(QCamera); + if (iso <= 0) + iso = -1; + if (d->control) + d->control->setManualIsoSensitivity(iso); +} + +int QCamera::manualIsoSensitivity() const +{ + Q_D(const QCamera); + return d->control ? d->control->manualIsoSensitivity() : 100; } /*! @@ -891,7 +799,33 @@ void QCamera::setManualIsoSensitivity(int iso) void QCamera::setAutoIsoSensitivity() { - d_func()->resetExposureParameter(QPlatformCameraExposure::ISO); + Q_D(QCamera); + if (d->control) + d->control->setManualIsoSensitivity(-1); +} + +int QCamera::minimumIsoSensitivity() const +{ + Q_D(const QCamera); + return d->control ? d->control->minIso() : -1; +} + +int QCamera::maximumIsoSensitivity() const +{ + Q_D(const QCamera); + return d->control ? d->control->maxIso() : -1; +} + +float QCamera::minimumShutterSpeed() const +{ + Q_D(const QCamera); + return d->control ? d->control->minShutterSpeed() : -1.; +} + +float QCamera::maximumShutterSpeed() const +{ + Q_D(const QCamera); + return d->control ? d->control->maxShutterSpeed() : -1.; } /*! @@ -918,58 +852,27 @@ void QCamera::setAutoIsoSensitivity() Returns the current shutter speed in seconds. */ -qreal QCamera::shutterSpeed() const +float QCamera::shutterSpeed() const { - return d_func()->actualExposureParameter<qreal>(QPlatformCameraExposure::ShutterSpeed, -1.0); + Q_D(const QCamera); + return d->control ? d->control->shutterSpeed() : -1; } /*! - Returns the requested manual shutter speed in seconds - or -1.0 if automatic shutter speed is turned on. + Set the manual shutter speed to \a seconds */ -qreal QCamera::requestedShutterSpeed() const -{ - return d_func()->requestedExposureParameter<qreal>(QPlatformCameraExposure::ShutterSpeed, -1.0); -} -/*! - Returns the list of shutter speed values in seconds camera supports. - - If the camera supports arbitrary shutter speed values within the supported range, - *\a continuous is set to true, otherwise *\a continuous is set to false. -*/ -QList<qreal> QCamera::supportedShutterSpeeds(bool *continuous) const +void QCamera::setManualShutterSpeed(float seconds) { - QList<qreal> res; - QPlatformCameraExposure *control = d_func()->exposureControl; - - bool tmp = false; - if (!continuous) - continuous = &tmp; - - if (!control) - return res; - - const auto range = control->supportedParameterRange(QPlatformCameraExposure::ShutterSpeed, continuous); - for (const QVariant &value : range) { - bool ok = false; - qreal realValue = value.toReal(&ok); - if (ok) - res.append(realValue); - else - qWarning() << "Incompatible shutter speed value type, qreal is expected"; - } - - return res; + Q_D(QCamera); + if (d->control) + d->control->setManualShutterSpeed(seconds); } -/*! - Set the manual shutter speed to \a seconds -*/ - -void QCamera::setManualShutterSpeed(qreal seconds) +float QCamera::manualShutterSpeed() const { - d_func()->setExposureParameter<qreal>(QPlatformCameraExposure::ShutterSpeed, seconds); + Q_D(const QCamera); + return d->control ? d->control->manualShutterSpeed() : -1; } /*! @@ -978,7 +881,9 @@ void QCamera::setManualShutterSpeed(qreal seconds) void QCamera::setAutoShutterSpeed() { - d_func()->resetExposureParameter(QPlatformCameraExposure::ShutterSpeed); + Q_D(QCamera); + if (d->control) + d->control->setManualShutterSpeed(-1); } diff --git a/src/multimedia/camera/qcamera.h b/src/multimedia/camera/qcamera.h index 1d01f75f1..a7c959124 100644 --- a/src/multimedia/camera/qcamera.h +++ b/src/multimedia/camera/qcamera.h @@ -80,10 +80,10 @@ class Q_MULTIMEDIA_EXPORT QCamera : public QObject Q_PROPERTY(qreal shutterSpeed READ shutterSpeed NOTIFY shutterSpeedChanged) Q_PROPERTY(int isoSensitivity READ isoSensitivity NOTIFY isoSensitivityChanged) Q_PROPERTY(qreal exposureCompensation READ exposureCompensation WRITE setExposureCompensation NOTIFY exposureCompensationChanged) + Q_PROPERTY(QCamera::ExposureMode exposureMode READ exposureMode WRITE setExposureMode NOTIFY exposureModeChanged) Q_PROPERTY(bool flashReady READ isFlashReady NOTIFY flashReady) - Q_PROPERTY(QCamera::FlashMode flashMode READ flashMode WRITE setFlashMode) - Q_PROPERTY(QCamera::TorchMode torchMode READ torchMode WRITE setTorchMode) - Q_PROPERTY(QCamera::ExposureMode exposureMode READ exposureMode WRITE setExposureMode) + Q_PROPERTY(QCamera::FlashMode flashMode READ flashMode WRITE setFlashMode NOTIFY flashModeChanged) + Q_PROPERTY(QCamera::TorchMode torchMode READ torchMode WRITE setTorchMode NOTIFY torchModeChanged) Q_PROPERTY(WhiteBalanceMode whiteBalanceMode READ whiteBalanceMode WRITE setWhiteBalanceMode NOTIFY whiteBalanceModeChanged) Q_PROPERTY(qreal manualWhiteBalance READ manualWhiteBalance WRITE setManualWhiteBalance NOTIFY manualWhiteBalanceChanged) @@ -222,13 +222,16 @@ public: qreal exposureCompensation() const; int isoSensitivity() const; - qreal shutterSpeed() const; + int manualIsoSensitivity() const; - int requestedIsoSensitivity() const; - qreal requestedShutterSpeed() const; + float shutterSpeed() const; + float manualShutterSpeed() const; - QList<int> supportedIsoSensitivities(bool *continuous = nullptr) const; - QList<qreal> supportedShutterSpeeds(bool *continuous = nullptr) const; + int minimumIsoSensitivity() const; + int maximumIsoSensitivity() const; + + float minimumShutterSpeed() const; + float maximumShutterSpeed() const; WhiteBalanceMode whiteBalanceMode() const; Q_INVOKABLE bool isWhiteBalanceModeSupported(WhiteBalanceMode mode) const; @@ -256,7 +259,7 @@ public Q_SLOTS: void setManualIsoSensitivity(int iso); void setAutoIsoSensitivity(); - void setManualShutterSpeed(qreal seconds); + void setManualShutterSpeed(float seconds); void setAutoShutterSpeed(); void setWhiteBalanceMode(WhiteBalanceMode mode); @@ -283,11 +286,13 @@ Q_SIGNALS: void customFocusPointChanged(); void flashReady(bool); + void flashModeChanged(); + void torchModeChanged(); void shutterSpeedChanged(qreal speed); - void shutterSpeedRangeChanged(); void isoSensitivityChanged(int); void exposureCompensationChanged(qreal); + void exposureModeChanged(); void whiteBalanceModeChanged() const; void manualWhiteBalanceChanged() const; diff --git a/src/multimedia/camera/qcamera_p.h b/src/multimedia/camera/qcamera_p.h index 61f4dfe1b..add658454 100644 --- a/src/multimedia/camera/qcamera_p.h +++ b/src/multimedia/camera/qcamera_p.h @@ -54,12 +54,10 @@ #include "private/qobject_p.h" #include "qcamera.h" #include "qcamerainfo.h" -#include <private/qplatformcameraexposure_p.h> QT_BEGIN_NAMESPACE class QPlatformCamera; -class QPlatformCameraExposure; class QPlatformCameraImageProcessing; class QPlatformMediaCaptureSession; @@ -85,8 +83,6 @@ public: QCameraInfo cameraInfo; QCameraFormat cameraFormat; - QPlatformCameraExposure *exposureControl = nullptr; - QPlatformCameraImageProcessing *imageControl = nullptr; QCamera::WhiteBalanceMode whiteBalance = QCamera::WhiteBalanceAuto; @@ -96,14 +92,6 @@ public: qreal saturation = 0; qreal hue = 0; - template<typename T> T actualExposureParameter(QPlatformCameraExposure::ExposureParameter parameter, const T &defaultValue) const; - template<typename T> T requestedExposureParameter(QPlatformCameraExposure::ExposureParameter parameter, const T &defaultValue) const; - template<typename T> void setExposureParameter(QPlatformCameraExposure::ExposureParameter parameter, const T &value); - void resetExposureParameter(QPlatformCameraExposure::ExposureParameter parameter); - - void _q_exposureParameterChanged(int parameter); - void _q_exposureParameterRangeChanged(int parameter); - void _q_error(int error, const QString &errorString); void unsetError() { error = QCamera::NoError; errorString.clear(); } }; diff --git a/src/multimedia/platform/android/mediacapture/qandroidcameracontrol.cpp b/src/multimedia/platform/android/mediacapture/qandroidcameracontrol.cpp index a8eb9ec16..4e8414381 100644 --- a/src/multimedia/platform/android/mediacapture/qandroidcameracontrol.cpp +++ b/src/multimedia/platform/android/mediacapture/qandroidcameracontrol.cpp @@ -39,7 +39,6 @@ #include "qandroidcameracontrol_p.h" #include "qandroidcamerasession_p.h" -#include "qandroidcameraexposurecontrol_p.h" #include "qandroidcameraimageprocessingcontrol_p.h" #include "qandroidcameravideorenderercontrol_p.h" #include "qandroidcaptureservice_p.h" @@ -119,11 +118,6 @@ void QAndroidCameraControl::setCaptureSession(QPlatformMediaCaptureSession *sess } -QPlatformCameraExposure *QAndroidCameraControl::exposureControl() -{ - return m_cameraSession->exposureControl(); -} - QPlatformCameraImageProcessing *QAndroidCameraControl::imageProcessingControl() { return m_cameraSession->imageProcessingControl(); @@ -226,20 +220,86 @@ void QAndroidCameraControl::onCameraOpened() m_zoomRatios.clear(); m_maximumZoom = 1.0; } + + m_minExposureCompensationIndex = m_cameraSession->camera()->getMinExposureCompensation(); + m_maxExposureCompensationIndex = m_cameraSession->camera()->getMaxExposureCompensation(); + m_exposureCompensationStep = m_cameraSession->camera()->getExposureCompensationStep(); + exposureCompensationRangeChanged(m_minExposureCompensationIndex*m_exposureCompensationStep, + m_maxExposureCompensationIndex*m_exposureCompensationStep); + + m_supportedExposureModes.clear(); + QStringList sceneModes = m_cameraSession->camera()->getSupportedSceneModes(); + if (!sceneModes.isEmpty()) { + for (int i = 0; i < sceneModes.size(); ++i) { + const QString &sceneMode = sceneModes.at(i); + if (sceneMode == QLatin1String("auto")) + m_supportedExposureModes << QCamera::ExposureAuto; + else if (sceneMode == QLatin1String("beach")) + m_supportedExposureModes << QCamera::ExposureBeach; + else if (sceneMode == QLatin1String("night")) + m_supportedExposureModes << QCamera::ExposureNight; + else if (sceneMode == QLatin1String("portrait")) + m_supportedExposureModes << QCamera::ExposurePortrait; + else if (sceneMode == QLatin1String("snow")) + m_supportedExposureModes << QCamera::ExposureSnow; + else if (sceneMode == QLatin1String("sports")) + m_supportedExposureModes << QCamera::ExposureSports; + else if (sceneMode == QLatin1String("action")) + m_supportedExposureModes << QCamera::ExposureAction; + else if (sceneMode == QLatin1String("landscape")) + m_supportedExposureModes << QCamera::ExposureLandscape; + else if (sceneMode == QLatin1String("night-portrait")) + m_supportedExposureModes << QCamera::ExposureNightPortrait; + else if (sceneMode == QLatin1String("theatre")) + m_supportedExposureModes << QCamera::ExposureTheatre; + else if (sceneMode == QLatin1String("sunset")) + m_supportedExposureModes << QCamera::ExposureSunset; + else if (sceneMode == QLatin1String("steadyphoto")) + m_supportedExposureModes << QCamera::ExposureSteadyPhoto; + else if (sceneMode == QLatin1String("fireworks")) + m_supportedExposureModes << QCamera::ExposureFireworks; + else if (sceneMode == QLatin1String("party")) + m_supportedExposureModes << QCamera::ExposureParty; + else if (sceneMode == QLatin1String("candlelight")) + m_supportedExposureModes << QCamera::ExposureCandlelight; + else if (sceneMode == QLatin1String("barcode")) + m_supportedExposureModes << QCamera::ExposureBarcode; + } + } + + setExposureCompensation(exposureCompensation()); + setExposureMode(exposureMode()); + + isFlashSupported = false; + isFlashAutoSupported = false; + isTorchSupported = false; + + QStringList flashModes = m_cameraSession->camera()->getSupportedFlashModes(); + for (int i = 0; i < flashModes.size(); ++i) { + const QString &flashMode = flashModes.at(i); + if (flashMode == QLatin1String("auto")) + isFlashAutoSupported = true; + else if (flashMode == QLatin1String("on")) + isFlashSupported = true; + else if (flashMode == QLatin1String("torch")) + isTorchSupported = true; + } + + setFlashMode(flashMode()); } //void QAndroidCameraFocusControl::onCameraCaptureModeChanged() //{ -// if (m_session->camera() && m_focusMode == QCamera::FocusModeAudio) { +// if (m_cameraSession->camera() && m_focusMode == QCamera::FocusModeAudio) { // QString focusMode; -// if ((m_session->captureMode().testFlag(QCamera::CaptureVideo) && m_continuousVideoFocusSupported) +// if ((m_cameraSession->captureMode().testFlag(QCamera::CaptureVideo) && m_continuousVideoFocusSupported) // || !m_continuousPictureFocusSupported) { // focusMode = QLatin1String("continuous-video"); // } else { // focusMode = QLatin1String("continuous-picture"); // } -// m_session->camera()->setFocusMode(focusMode); -// m_session->camera()->cancelAutoFocus(); +// m_cameraSession->camera()->setFocusMode(focusMode); +// m_cameraSession->camera()->cancelAutoFocus(); // } //} @@ -300,4 +360,162 @@ void QAndroidCameraControl::zoomTo(float factor, float rate) zoomFactorChanged(newZoom); } +void QAndroidCameraControl::setFlashMode(QCamera::FlashMode mode) +{ + if (!m_cameraSession->camera()) + return; + + if (!isFlashModeSupported(mode)) + return; + + QString flashMode; + if (mode == QCamera::FlashAuto) + flashMode = QLatin1String("auto"); + else if (mode == QCamera::FlashOn) + flashMode = QLatin1String("on"); + else // FlashOff + flashMode = QLatin1String("off"); + + m_cameraSession->camera()->setFlashMode(flashMode); + flashModeChanged(mode); +} + +bool QAndroidCameraControl::isFlashModeSupported(QCamera::FlashMode mode) const +{ + if (!m_cameraSession->camera()) + return false; + switch (mode) { + case QCamera::FlashOff: + return true; + case QCamera::FlashOn: + return isFlashSupported; + case QCamera::FlashAuto: + return isFlashAutoSupported; + } +} + +bool QAndroidCameraControl::isFlashReady() const +{ + // Android doesn't have an API for that + return true; +} + +void QAndroidCameraControl::setTorchMode(QCamera::TorchMode mode) +{ + auto *camera = m_cameraSession->camera(); + if (!camera || !isTorchSupported || mode == QCamera::TorchAuto) + return; + + if (mode == QCamera::TorchOn) { + camera->setFlashMode(QLatin1String("torch")); + } else if (mode == QCamera::TorchOff) { + // if torch was enabled, it first needs to be turned off before restoring the flash mode + camera->setFlashMode(QLatin1String("off")); + setFlashMode(flashMode()); + } + torchModeChanged(mode); +} + +bool QAndroidCameraControl::isTorchModeSupported(QCamera::TorchMode mode) const +{ + if (!m_cameraSession->camera()) + return false; + switch (mode) { + case QCamera::TorchOff: + return true; + case QCamera::TorchOn: + return isTorchSupported; + case QCamera::TorchAuto: + return false; + } +} + +void QAndroidCameraControl::setExposureMode(QCamera::ExposureMode mode) +{ + if (exposureMode() == mode) + return; + + if (!m_cameraSession->camera()) + return; + + if (!m_supportedExposureModes.contains(mode)) + return; + + QString sceneMode; + switch (mode) { + case QCamera::ExposureAuto: + sceneMode = QLatin1String("auto"); + break; + case QCamera::ExposureSports: + sceneMode = QLatin1String("sports"); + break; + case QCamera::ExposurePortrait: + sceneMode = QLatin1String("portrait"); + break; + case QCamera::ExposureBeach: + sceneMode = QLatin1String("beach"); + break; + case QCamera::ExposureSnow: + sceneMode = QLatin1String("snow"); + break; + case QCamera::ExposureNight: + sceneMode = QLatin1String("night"); + break; + case QCamera::ExposureAction: + sceneMode = QLatin1String("action"); + break; + case QCamera::ExposureLandscape: + sceneMode = QLatin1String("landscape"); + break; + case QCamera::ExposureNightPortrait: + sceneMode = QLatin1String("night-portrait"); + break; + case QCamera::ExposureTheatre: + sceneMode = QLatin1String("theatre"); + break; + case QCamera::ExposureSunset: + sceneMode = QLatin1String("sunset"); + break; + case QCamera::ExposureSteadyPhoto: + sceneMode = QLatin1String("steadyphoto"); + break; + case QCamera::ExposureFireworks: + sceneMode = QLatin1String("fireworks"); + break; + case QCamera::ExposureParty: + sceneMode = QLatin1String("party"); + break; + case QCamera::ExposureCandlelight: + sceneMode = QLatin1String("candlelight"); + break; + case QCamera::ExposureBarcode: + sceneMode = QLatin1String("barcode"); + break; + default: + sceneMode = QLatin1String("auto"); + mode = QCamera::ExposureAuto; + break; + } + + m_cameraSession->camera()->setSceneMode(sceneMode); + exposureModeChanged(mode); +} + +bool QAndroidCameraControl::isExposureModeSupported(QCamera::ExposureMode mode) const +{ + return m_supportedExposureModes.contains(mode); +} + +void QAndroidCameraControl::setExposureCompensation(float bias) +{ + if (exposureCompensation() == bias || !m_cameraSession->camera()) + return; + + int biasIndex = qRound(bias / m_exposureCompensationStep); + biasIndex = qBound(m_minExposureCompensationIndex, biasIndex, m_maxExposureCompensationIndex); + float comp = biasIndex * m_exposureCompensationStep; + m_cameraSession->camera()->setExposureCompensation(biasIndex); + exposureCompensationChanged(comp); +} + QT_END_NAMESPACE diff --git a/src/multimedia/platform/android/mediacapture/qandroidcameracontrol_p.h b/src/multimedia/platform/android/mediacapture/qandroidcameracontrol_p.h index 1c9927dc2..86a685a60 100644 --- a/src/multimedia/platform/android/mediacapture/qandroidcameracontrol_p.h +++ b/src/multimedia/platform/android/mediacapture/qandroidcameracontrol_p.h @@ -76,7 +76,6 @@ public: void setCaptureSession(QPlatformMediaCaptureSession *session) override; - QPlatformCameraExposure *exposureControl() override; QPlatformCameraImageProcessing *imageProcessingControl() override; void setFocusMode(QCamera::FocusMode mode) override; @@ -84,6 +83,18 @@ public: void zoomTo(float factor, float rate) override; + void setFlashMode(QCamera::FlashMode mode) override; + bool isFlashModeSupported(QCamera::FlashMode mode) const override; + bool isFlashReady() const override; + + void setTorchMode(QCamera::TorchMode mode) override; + bool isTorchModeSupported(QCamera::TorchMode mode) const override; + + void setExposureMode(QCamera::ExposureMode mode) override; + bool isExposureModeSupported(QCamera::ExposureMode mode) const override; + + void setExposureCompensation(float bias) override; + private Q_SLOTS: void onCameraOpened(); void setCameraFocusArea(); @@ -100,6 +111,15 @@ private: float m_maximumZoom; QList<int> m_zoomRatios; + + QList<QCamera::ExposureMode> m_supportedExposureModes; + int m_minExposureCompensationIndex; + int m_maxExposureCompensationIndex; + qreal m_exposureCompensationStep; + + bool isFlashSupported = false; + bool isFlashAutoSupported = false; + bool isTorchSupported = false; }; diff --git a/src/multimedia/platform/android/mediacapture/qandroidcameraexposurecontrol.cpp b/src/multimedia/platform/android/mediacapture/qandroidcameraexposurecontrol.cpp deleted file mode 100644 index fc78330af..000000000 --- a/src/multimedia/platform/android/mediacapture/qandroidcameraexposurecontrol.cpp +++ /dev/null @@ -1,377 +0,0 @@ -/**************************************************************************** -** -** 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 "qandroidcameraexposurecontrol_p.h" - -#include "qandroidcamerasession_p.h" -#include "androidcamera_p.h" - -QT_BEGIN_NAMESPACE - -QAndroidCameraExposureControl::QAndroidCameraExposureControl(QAndroidCameraSession *session) - : QPlatformCameraExposure() - , m_session(session) - , m_minExposureCompensationIndex(0) - , m_maxExposureCompensationIndex(0) - , m_exposureCompensationStep(0.0) - , m_requestedExposureCompensation(0.0) - , m_actualExposureCompensation(0.0) - , m_requestedExposureMode(QCamera::ExposureAuto) - , m_actualExposureMode(QCamera::ExposureAuto) -{ - connect(m_session, SIGNAL(opened()), - this, SLOT(onCameraOpened())); -} - -bool QAndroidCameraExposureControl::isParameterSupported(ExposureParameter parameter) const -{ - if (!m_session->camera()) - return false; - - switch (parameter) { - case QPlatformCameraExposure::ISO: - return false; - case QPlatformCameraExposure::ShutterSpeed: - return false; - case QPlatformCameraExposure::ExposureCompensation: - return !m_supportedExposureCompensations.isEmpty(); - case QPlatformCameraExposure::TorchPower: - return false; - case QPlatformCameraExposure::ExposureMode: - return !m_supportedExposureModes.isEmpty(); - default: - return false; - } -} - -QVariantList QAndroidCameraExposureControl::supportedParameterRange(ExposureParameter parameter, bool *continuous) const -{ - if (!m_session->camera()) - return QVariantList(); - - if (continuous) - *continuous = false; - - if (parameter == QPlatformCameraExposure::ExposureCompensation) - return m_supportedExposureCompensations; - else if (parameter == QPlatformCameraExposure::ExposureMode) - return m_supportedExposureModes; - - return QVariantList(); -} - -QVariant QAndroidCameraExposureControl::requestedValue(ExposureParameter parameter) const -{ - if (parameter == QPlatformCameraExposure::ExposureCompensation) - return QVariant::fromValue(m_requestedExposureCompensation); - else if (parameter == QPlatformCameraExposure::ExposureMode) - return QVariant::fromValue(m_requestedExposureMode); - - return QVariant(); -} - -QVariant QAndroidCameraExposureControl::actualValue(ExposureParameter parameter) const -{ - if (parameter == QPlatformCameraExposure::ExposureCompensation) - return QVariant::fromValue(m_actualExposureCompensation); - else if (parameter == QPlatformCameraExposure::ExposureMode) - return QVariant::fromValue(m_actualExposureMode); - - return QVariant(); -} - -bool QAndroidCameraExposureControl::setValue(ExposureParameter parameter, const QVariant& value) -{ - if (!value.isValid()) - return false; - - if (parameter == QPlatformCameraExposure::ExposureCompensation) { - qreal expComp = value.toReal(); - if (!qFuzzyCompare(m_requestedExposureCompensation, expComp)) { - m_requestedExposureCompensation = expComp; - emit requestedValueChanged(QPlatformCameraExposure::ExposureCompensation); - } - - if (!m_session->camera()) - return true; - - int expCompIndex = qRound(m_requestedExposureCompensation / m_exposureCompensationStep); - if (expCompIndex >= m_minExposureCompensationIndex - && expCompIndex <= m_maxExposureCompensationIndex) { - qreal comp = expCompIndex * m_exposureCompensationStep; - m_session->camera()->setExposureCompensation(expCompIndex); - if (!qFuzzyCompare(m_actualExposureCompensation, comp)) { - m_actualExposureCompensation = expCompIndex * m_exposureCompensationStep; - emit actualValueChanged(QPlatformCameraExposure::ExposureCompensation); - } - - return true; - } - - } else if (parameter == QPlatformCameraExposure::ExposureMode) { - QCamera::ExposureMode expMode = value.value<QCamera::ExposureMode>(); - if (m_requestedExposureMode != expMode) { - m_requestedExposureMode = expMode; - emit requestedValueChanged(QPlatformCameraExposure::ExposureMode); - } - - if (!m_session->camera()) - return true; - - if (!m_supportedExposureModes.isEmpty()) { - m_actualExposureMode = m_requestedExposureMode; - - QString sceneMode; - switch (m_requestedExposureMode) { - case QCamera::ExposureAuto: - sceneMode = QLatin1String("auto"); - break; - case QCamera::ExposureSports: - sceneMode = QLatin1String("sports"); - break; - case QCamera::ExposurePortrait: - sceneMode = QLatin1String("portrait"); - break; - case QCamera::ExposureBeach: - sceneMode = QLatin1String("beach"); - break; - case QCamera::ExposureSnow: - sceneMode = QLatin1String("snow"); - break; - case QCamera::ExposureNight: - sceneMode = QLatin1String("night"); - break; - case QCamera::ExposureAction: - sceneMode = QLatin1String("action"); - break; - case QCamera::ExposureLandscape: - sceneMode = QLatin1String("landscape"); - break; - case QCamera::ExposureNightPortrait: - sceneMode = QLatin1String("night-portrait"); - break; - case QCamera::ExposureTheatre: - sceneMode = QLatin1String("theatre"); - break; - case QCamera::ExposureSunset: - sceneMode = QLatin1String("sunset"); - break; - case QCamera::ExposureSteadyPhoto: - sceneMode = QLatin1String("steadyphoto"); - break; - case QCamera::ExposureFireworks: - sceneMode = QLatin1String("fireworks"); - break; - case QCamera::ExposureParty: - sceneMode = QLatin1String("party"); - break; - case QCamera::ExposureCandlelight: - sceneMode = QLatin1String("candlelight"); - break; - case QCamera::ExposureBarcode: - sceneMode = QLatin1String("barcode"); - break; - default: - sceneMode = QLatin1String("auto"); - m_actualExposureMode = QCamera::ExposureAuto; - break; - } - - m_session->camera()->setSceneMode(sceneMode); - emit actualValueChanged(QPlatformCameraExposure::ExposureMode); - - return true; - } - } - - return false; -} - -void QAndroidCameraExposureControl::onCameraOpened() -{ - m_supportedExposureCompensations.clear(); - m_minExposureCompensationIndex = m_session->camera()->getMinExposureCompensation(); - m_maxExposureCompensationIndex = m_session->camera()->getMaxExposureCompensation(); - m_exposureCompensationStep = m_session->camera()->getExposureCompensationStep(); - if (m_minExposureCompensationIndex != 0 || m_maxExposureCompensationIndex != 0) { - for (int i = m_minExposureCompensationIndex; i <= m_maxExposureCompensationIndex; ++i) - m_supportedExposureCompensations.append(i * m_exposureCompensationStep); - emit parameterRangeChanged(QPlatformCameraExposure::ExposureCompensation); - } - - m_supportedExposureModes.clear(); - QStringList sceneModes = m_session->camera()->getSupportedSceneModes(); - if (!sceneModes.isEmpty()) { - for (int i = 0; i < sceneModes.size(); ++i) { - const QString &sceneMode = sceneModes.at(i); - if (sceneMode == QLatin1String("auto")) - m_supportedExposureModes << QVariant::fromValue(QCamera::ExposureAuto); - else if (sceneMode == QLatin1String("beach")) - m_supportedExposureModes << QVariant::fromValue(QCamera::ExposureBeach); - else if (sceneMode == QLatin1String("night")) - m_supportedExposureModes << QVariant::fromValue(QCamera::ExposureNight); - else if (sceneMode == QLatin1String("portrait")) - m_supportedExposureModes << QVariant::fromValue(QCamera::ExposurePortrait); - else if (sceneMode == QLatin1String("snow")) - m_supportedExposureModes << QVariant::fromValue(QCamera::ExposureSnow); - else if (sceneMode == QLatin1String("sports")) - m_supportedExposureModes << QVariant::fromValue(QCamera::ExposureSports); - else if (sceneMode == QLatin1String("action")) - m_supportedExposureModes << QVariant::fromValue(QCamera::ExposureAction); - else if (sceneMode == QLatin1String("landscape")) - m_supportedExposureModes << QVariant::fromValue(QCamera::ExposureLandscape); - else if (sceneMode == QLatin1String("night-portrait")) - m_supportedExposureModes << QVariant::fromValue(QCamera::ExposureNightPortrait); - else if (sceneMode == QLatin1String("theatre")) - m_supportedExposureModes << QVariant::fromValue(QCamera::ExposureTheatre); - else if (sceneMode == QLatin1String("sunset")) - m_supportedExposureModes << QVariant::fromValue(QCamera::ExposureSunset); - else if (sceneMode == QLatin1String("steadyphoto")) - m_supportedExposureModes << QVariant::fromValue(QCamera::ExposureSteadyPhoto); - else if (sceneMode == QLatin1String("fireworks")) - m_supportedExposureModes << QVariant::fromValue(QCamera::ExposureFireworks); - else if (sceneMode == QLatin1String("party")) - m_supportedExposureModes << QVariant::fromValue(QCamera::ExposureParty); - else if (sceneMode == QLatin1String("candlelight")) - m_supportedExposureModes << QVariant::fromValue(QCamera::ExposureCandlelight); - else if (sceneMode == QLatin1String("barcode")) - m_supportedExposureModes << QVariant::fromValue(QCamera::ExposureBarcode); - } - emit parameterRangeChanged(QPlatformCameraExposure::ExposureMode); - } - - setValue(QPlatformCameraExposure::ExposureCompensation, QVariant::fromValue(m_requestedExposureCompensation)); - setValue(QPlatformCameraExposure::ExposureMode, QVariant::fromValue(m_requestedExposureMode)); - - m_supportedFlashModes.clear(); - torchModeSupported = false; - - QStringList flashModes = m_session->camera()->getSupportedFlashModes(); - for (int i = 0; i < flashModes.size(); ++i) { - const QString &flashMode = flashModes.at(i); - if (flashMode == QLatin1String("off")) - m_supportedFlashModes << QCamera::FlashOff; - else if (flashMode == QLatin1String("auto")) - m_supportedFlashModes << QCamera::FlashAuto; - else if (flashMode == QLatin1String("on")) - m_supportedFlashModes << QCamera::FlashOn; - else if (flashMode == QLatin1String("torch")) - torchModeSupported = true; - } - - if (!m_supportedFlashModes.contains(m_flashMode)) - m_flashMode = QCamera::FlashOff; - - setFlashMode(m_flashMode); -} - - -QCamera::FlashMode QAndroidCameraExposureControl::flashMode() const -{ - return m_flashMode; -} - -void QAndroidCameraExposureControl::setFlashMode(QCamera::FlashMode mode) -{ - if (!m_session->camera()) { - m_flashMode = QCamera::FlashOff; - return; - } - - if (!isFlashModeSupported(mode)) - return; - - - m_flashMode = mode; - - QString flashMode; - if (mode == QCamera::FlashAuto) - flashMode = QLatin1String("auto"); - else if (mode == QCamera::FlashOn) - flashMode = QLatin1String("on"); - else // FlashOff - flashMode = QLatin1String("off"); - - m_session->camera()->setFlashMode(flashMode); -} - -bool QAndroidCameraExposureControl::isFlashModeSupported(QCamera::FlashMode mode) const -{ - return m_session->camera() ? m_supportedFlashModes.contains(mode) : false; -} - -bool QAndroidCameraExposureControl::isFlashReady() const -{ - // Android doesn't have an API for that - return true; -} - -QCamera::TorchMode QAndroidCameraExposureControl::torchMode() const -{ - return torchEnabled ? QCamera::TorchOn : QCamera::TorchOff; -} - -void QAndroidCameraExposureControl::setTorchMode(QCamera::TorchMode mode) -{ - auto *camera = m_session->camera(); - if (!camera || !torchModeSupported) - return; - - if (mode == QCamera::TorchOn) { - camera->setFlashMode(QLatin1String("torch")); - torchEnabled = true; - } else if (mode == QCamera::TorchOff) { - // if torch was enabled, it first needs to be turned off before restoring the flash mode - camera->setFlashMode(QLatin1String("off")); - setFlashMode(m_flashMode); - torchEnabled = false; - } -} - -bool QAndroidCameraExposureControl::isTorchModeSupported(QCamera::TorchMode mode) const -{ - if (mode == QCamera::TorchAuto) - return false; - else if (mode == QCamera::TorchOn) - return torchModeSupported; - else - return true; -} - -QT_END_NAMESPACE diff --git a/src/multimedia/platform/android/mediacapture/qandroidcameraexposurecontrol_p.h b/src/multimedia/platform/android/mediacapture/qandroidcameraexposurecontrol_p.h deleted file mode 100644 index 510a9a764..000000000 --- a/src/multimedia/platform/android/mediacapture/qandroidcameraexposurecontrol_p.h +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** -** -** 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 QANDROIDCAMERAEXPOSURECONTROL_H -#define QANDROIDCAMERAEXPOSURECONTROL_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <private/qplatformcameraexposure_p.h> - -QT_BEGIN_NAMESPACE - -class QAndroidCameraSession; - -class QAndroidCameraExposureControl : public QPlatformCameraExposure -{ - Q_OBJECT -public: - explicit QAndroidCameraExposureControl(QAndroidCameraSession *session); - - bool isParameterSupported(ExposureParameter parameter) const override; - QVariantList supportedParameterRange(ExposureParameter parameter, bool *continuous) const override; - - QVariant requestedValue(ExposureParameter parameter) const override; - QVariant actualValue(ExposureParameter parameter) const override; - bool setValue(ExposureParameter parameter, const QVariant& value) override; - - QCamera::FlashMode flashMode() const override; - void setFlashMode(QCamera::FlashMode mode) override; - bool isFlashModeSupported(QCamera::FlashMode mode) const override; - bool isFlashReady() const override; - - QCamera::TorchMode torchMode() const override; - void setTorchMode(QCamera::TorchMode mode) override; - bool isTorchModeSupported(QCamera::TorchMode mode) const override; - -private Q_SLOTS: - void onCameraOpened(); - -private: - QAndroidCameraSession *m_session; - - QVariantList m_supportedExposureCompensations; - QVariantList m_supportedExposureModes; - - int m_minExposureCompensationIndex; - int m_maxExposureCompensationIndex; - qreal m_exposureCompensationStep; - - qreal m_requestedExposureCompensation; - qreal m_actualExposureCompensation; - QCamera::ExposureMode m_requestedExposureMode; - QCamera::ExposureMode m_actualExposureMode; - - QList<QCamera::FlashMode> m_supportedFlashModes; - QCamera::FlashMode m_flashMode; - - bool torchModeSupported = false; - bool torchEnabled = false; -}; - -QT_END_NAMESPACE - -#endif // QANDROIDCAMERAEXPOSURECONTROL_H diff --git a/src/multimedia/platform/android/mediacapture/qandroidcamerasession.cpp b/src/multimedia/platform/android/mediacapture/qandroidcamerasession.cpp index 81e208a2a..369c7ed10 100644 --- a/src/multimedia/platform/android/mediacapture/qandroidcamerasession.cpp +++ b/src/multimedia/platform/android/mediacapture/qandroidcamerasession.cpp @@ -45,7 +45,6 @@ #include "qandroidvideooutput_p.h" #include "qandroidmultimediautils_p.h" #include "qandroidcameravideorenderercontrol_p.h" -#include "qandroidcameraexposurecontrol_p.h" #include "qandroidcameraimageprocessingcontrol_p.h" #include <qvideosink.h> #include <QtConcurrent/qtconcurrentrun.h> @@ -79,7 +78,6 @@ QAndroidCameraSession::QAndroidCameraSession(QObject *parent) QMediaStorageLocation::Pictures, AndroidMultimediaUtils::getDefaultMediaDirectory(AndroidMultimediaUtils::DCIM)); - m_cameraExposureControl = new QAndroidCameraExposureControl(this); m_cameraImageProcessingControl = new QAndroidCameraImageProcessingControl(this); if (qApp) { @@ -90,7 +88,6 @@ QAndroidCameraSession::QAndroidCameraSession(QObject *parent) QAndroidCameraSession::~QAndroidCameraSession() { - delete m_cameraExposureControl; delete m_cameraImageProcessingControl; delete m_renderer; diff --git a/src/multimedia/platform/android/mediacapture/qandroidcamerasession_p.h b/src/multimedia/platform/android/mediacapture/qandroidcamerasession_p.h index 69a2d8864..9f88bd76d 100644 --- a/src/multimedia/platform/android/mediacapture/qandroidcamerasession_p.h +++ b/src/multimedia/platform/android/mediacapture/qandroidcamerasession_p.h @@ -63,7 +63,6 @@ QT_BEGIN_NAMESPACE class QAndroidVideoOutput; -class QAndroidCameraExposureControl; class QAndroidCameraImageProcessingControl; class QAndroidCameraVideoRendererControl; class QVideoSink; @@ -112,7 +111,6 @@ public: void setPreviewCallback(PreviewCallback *callback); bool requestRecordingPermission(); - QAndroidCameraExposureControl *exposureControl() { return m_cameraExposureControl; } QAndroidCameraImageProcessingControl *imageProcessingControl() { return m_cameraImageProcessingControl; } void setVideoSink(QVideoSink *surface); @@ -180,7 +178,6 @@ private: QAndroidCameraVideoRendererControl *m_renderer = nullptr; - QAndroidCameraExposureControl *m_cameraExposureControl; QAndroidCameraImageProcessingControl *m_cameraImageProcessingControl; QImageEncoderSettings m_requestedImageSettings; diff --git a/src/multimedia/platform/darwin/camera/avfcamera.mm b/src/multimedia/platform/darwin/camera/avfcamera.mm index b780e207a..65688ba11 100644 --- a/src/multimedia/platform/darwin/camera/avfcamera.mm +++ b/src/multimedia/platform/darwin/camera/avfcamera.mm @@ -43,12 +43,119 @@ #include "avfcameraservice_p.h" #include "avfcamerautility_p.h" #include "avfcamerarenderer_p.h" -#include "avfcameraexposure_p.h" #include "avfcameraimageprocessing_p.h" #include <qmediacapturesession.h> QT_USE_NAMESPACE + +namespace { + +// All these methods to work with exposure/ISO/SS in custom mode do not support macOS. + +#ifdef Q_OS_IOS + +// Misc. helpers to check values/ranges: + +bool qt_check_ISO_conversion(float isoValue) +{ + if (isoValue >= std::numeric_limits<int>::max()) + return false; + if (isoValue <= std::numeric_limits<int>::min()) + return false; + return true; +} + +bool qt_check_ISO_range(AVCaptureDeviceFormat *format) +{ + // Qt is using int for ISO, AVFoundation - float. It looks like the ISO range + // at the moment can be represented by int (it's max - min > 100, etc.). + Q_ASSERT(format); + if (format.maxISO - format.minISO < 1.) { + // ISO is in some strange units? + return false; + } + + return qt_check_ISO_conversion(format.minISO) + && qt_check_ISO_conversion(format.maxISO); +} + +bool qt_check_exposure_duration(AVCaptureDevice *captureDevice, CMTime duration) +{ + Q_ASSERT(captureDevice); + + AVCaptureDeviceFormat *activeFormat = captureDevice.activeFormat; + if (!activeFormat) { + qDebugCamera() << Q_FUNC_INFO << "failed to obtain capture device format"; + return false; + } + + return CMTimeCompare(duration, activeFormat.minExposureDuration) != -1 + && CMTimeCompare(activeFormat.maxExposureDuration, duration) != -1; +} + +bool qt_check_ISO_value(AVCaptureDevice *captureDevice, int newISO) +{ + Q_ASSERT(captureDevice); + + AVCaptureDeviceFormat *activeFormat = captureDevice.activeFormat; + if (!activeFormat) { + qDebugCamera() << Q_FUNC_INFO << "failed to obtain capture device format"; + return false; + } + + return !(newISO < activeFormat.minISO || newISO > activeFormat.maxISO); +} + +bool qt_exposure_duration_equal(AVCaptureDevice *captureDevice, qreal qDuration) +{ + Q_ASSERT(captureDevice); + const CMTime avDuration = CMTimeMakeWithSeconds(qDuration, captureDevice.exposureDuration.timescale); + return !CMTimeCompare(avDuration, captureDevice.exposureDuration); +} + +bool qt_iso_equal(AVCaptureDevice *captureDevice, int iso) +{ + Q_ASSERT(captureDevice); + return qFuzzyCompare(float(iso), captureDevice.ISO); +} + +bool qt_exposure_bias_equal(AVCaptureDevice *captureDevice, qreal bias) +{ + Q_ASSERT(captureDevice); + return qFuzzyCompare(bias, qreal(captureDevice.exposureTargetBias)); +} + +// Converters: + +bool qt_convert_exposure_mode(AVCaptureDevice *captureDevice, QCamera::ExposureMode mode, + AVCaptureExposureMode &avMode) +{ + // Test if mode supported and convert. + Q_ASSERT(captureDevice); + + if (mode == QCamera::ExposureAuto) { + if ([captureDevice isExposureModeSupported:AVCaptureExposureModeContinuousAutoExposure]) { + avMode = AVCaptureExposureModeContinuousAutoExposure; + return true; + } + } + + if (mode == QCamera::ExposureManual) { + if ([captureDevice isExposureModeSupported:AVCaptureExposureModeCustom]) { + avMode = AVCaptureExposureModeCustom; + return true; + } + } + + return false; +} + +#endif // defined(Q_OS_IOS) + +} // Unnamed namespace. + + AVFCamera::AVFCamera(QCamera *camera) : QPlatformCamera(camera) , m_active(false) @@ -57,15 +164,10 @@ AVFCamera::AVFCamera(QCamera *camera) Q_ASSERT(camera); m_cameraImageProcessingControl = new AVFCameraImageProcessing(this); - m_cameraExposureControl = nullptr; -#ifdef Q_OS_IOS - m_cameraExposureControl = new AVFCameraExposure(this); -#endif } AVFCamera::~AVFCamera() { - delete m_cameraExposureControl; delete m_cameraImageProcessingControl; } @@ -165,11 +267,6 @@ AVCaptureDevice *AVFCamera::device() const return device; } -QPlatformCameraExposure *AVFCamera::exposureControl() -{ - return m_cameraExposureControl; -} - QPlatformCameraImageProcessing *AVFCamera::imageProcessingControl() { return m_cameraImageProcessingControl; @@ -369,7 +466,84 @@ void AVFCamera::updateCameraConfiguration() maximumZoomFactorChanged(captureDevice.maxAvailableVideoZoomFactor); captureDevice.videoZoomFactor = m_zoomFactor; + + CMTime newDuration = AVCaptureExposureDurationCurrent; + bool setCustomMode = false; + + float shutterSpeed = manualShutterSpeed(); + if (shutterSpeed > 0 + && !qt_exposure_duration_equal(captureDevice, shutterSpeed)) { + newDuration = CMTimeMakeWithSeconds(shutterSpeed, captureDevice.exposureDuration.timescale); + if (!qt_check_exposure_duration(captureDevice, newDuration)) { + qDebugCamera() << Q_FUNC_INFO << "requested exposure duration is out of range"; + return; + } + setCustomMode = true; + } + + float newISO = AVCaptureISOCurrent; + int iso = manualIsoSensitivity(); + if (iso > 0 && !qt_iso_equal(captureDevice, iso)) { + newISO = iso; + if (!qt_check_ISO_value(captureDevice, newISO)) { + qDebugCamera() << Q_FUNC_INFO << "requested ISO value is out of range"; + return; + } + setCustomMode = true; + } + + float bias = exposureCompensation(); + if (!bias != 0 + && !qt_exposure_bias_equal(captureDevice, bias)) { + // TODO: mixed fpns. + if (bias < captureDevice.minExposureTargetBias || bias > captureDevice.maxExposureTargetBias) { + qDebugCamera() << Q_FUNC_INFO << "exposure compensation value is" + << "out of range"; + return; + } + [captureDevice setExposureTargetBias:bias completionHandler:nil]; + } + + // Setting shutter speed (exposure duration) or ISO values + // also reset exposure mode into Custom. With this settings + // we ignore any attempts to set exposure mode. + + if (setCustomMode) { + [captureDevice setExposureModeCustomWithDuration:newDuration + ISO:newISO + completionHandler:nil]; + return; + } + + QCamera::ExposureMode qtMode = exposureMode(); + AVCaptureExposureMode avMode = AVCaptureExposureModeContinuousAutoExposure; + if (!qt_convert_exposure_mode(captureDevice, qtMode, avMode)) { + qDebugCamera() << Q_FUNC_INFO << "requested exposure mode is not supported"; + return; + } + + captureDevice.exposureMode = avMode; #endif + + isFlashSupported = isFlashAutoSupported = false; + isTorchSupported = isTorchAutoSupported = false; + + if (captureDevice.hasFlash) { + if ([captureDevice isFlashModeSupported:AVCaptureFlashModeOn]) + isFlashSupported = true; + if ([captureDevice isFlashModeSupported:AVCaptureFlashModeAuto]) + isFlashAutoSupported = true; + } + + if (captureDevice.hasTorch) { + if ([captureDevice isTorchModeSupported:AVCaptureTorchModeOn]) + isTorchSupported = true; + if ([captureDevice isTorchModeSupported:AVCaptureTorchModeAuto]) + isTorchAutoSupported = true; + } + + applyFlashSettings(); + flashReadyChanged(isFlashSupported); } void AVFCamera::zoomTo(float factor, float rate) @@ -400,4 +574,301 @@ void AVFCamera::zoomTo(float factor, float rate) #endif } +void AVFCamera::setFlashMode(QCamera::FlashMode mode) +{ + if (flashMode() == mode) + return; + + if (isActive() && !isFlashModeSupported(mode)) { + qDebugCamera() << Q_FUNC_INFO << "unsupported mode" << mode; + return; + } + + flashModeChanged(mode); + + if (!isActive()) + return; + + applyFlashSettings(); +} + +bool AVFCamera::isFlashModeSupported(QCamera::FlashMode mode) const +{ + if (mode == QCamera::FlashOff) + return true; + else if (mode == QCamera::FlashOn) + return isFlashSupported; + else //if (mode == QCamera::FlashAuto) + return isFlashAutoSupported; +} + +bool AVFCamera::isFlashReady() const +{ + if (!isActive()) + return false; + + AVCaptureDevice *captureDevice = device(); + if (!captureDevice) + return false; + + if (!captureDevice.hasFlash) + return false; + + if (!isFlashModeSupported(flashMode())) + return false; + +#ifdef Q_OS_IOS + // AVCaptureDevice's docs: + // "The flash may become unavailable if, for example, + // the device overheats and needs to cool off." + return [captureDevice isFlashAvailable]; +#endif + + return true; +} + +void AVFCamera::setTorchMode(QCamera::TorchMode mode) +{ + if (torchMode() == mode) + return; + + if (isActive() && !isTorchModeSupported(mode)) { + qDebugCamera() << Q_FUNC_INFO << "unsupported torch mode" << mode; + return; + } + + torchModeChanged(mode); + + if (!isActive()) + return; + + applyFlashSettings(); +} + +bool AVFCamera::isTorchModeSupported(QCamera::TorchMode mode) const +{ + if (mode == QCamera::TorchOff) + return true; + else if (mode == QCamera::TorchOn) + return isTorchSupported; + else //if (mode == QCamera::TorchAuto) + return isTorchAutoSupported; +} + +void AVFCamera::setExposureMode(QCamera::ExposureMode qtMode) +{ +#ifdef Q_OS_IOS + if (qtMode != QCamera::ExposureAuto && qtMode != QCamera::ExposureManual) { + qDebugCamera() << Q_FUNC_INFO << "exposure mode not supported"; + return; + } + + AVCaptureDevice *captureDevice = m_camera->device(); + if (!captureDevice) { + exposureModeChanged(value); + return; + } + + AVCaptureExposureMode avMode = AVCaptureExposureModeContinuousAutoExpose; + if (!qt_convert_exposure_mode(captureDevice, qtMode, avMode)) { + qDebugCamera() << Q_FUNC_INFO << "exposure mode not supported"; + return false; + } + + const AVFConfigurationLock lock(captureDevice); + if (!lock) { + qDebugCamera() << Q_FUNC_INFO << "failed to lock a capture device" + << "for configuration"; + return false; + } + + [captureDevice setExposureMode:avMode]; + exposureModeChanged(qtMode); +#else + Q_UNUSED(qtMode); +#endif +} + +bool AVFCamera::isExposureModeSupported(QCamera::ExposureMode mode) const +{ + if (mode == QCamera::ExposureAuto) + return true; + if (mode != QCamera::ExposureManual) + return false; + AVCaptureDevice *captureDevice = device(); + return captureDevice && [captureDevice isExposureModeSupported:AVCaptureExposureModeCustom]; +} + +void AVFCamera::applyFlashSettings() +{ + Q_ASSERT(isActive()); + + AVCaptureDevice *captureDevice = device(); + if (!captureDevice) { + qDebugCamera() << Q_FUNC_INFO << "no capture device found"; + return; + } + + + const AVFConfigurationLock lock(captureDevice); + + if (captureDevice.hasFlash) { + auto mode = flashMode(); + if (mode == QCamera::FlashOff) { + captureDevice.flashMode = AVCaptureFlashModeOff; + } else { +#ifdef Q_OS_IOS + if (![captureDevice isFlashAvailable]) { + qDebugCamera() << Q_FUNC_INFO << "flash is not available at the moment"; + return; + } +#endif + if (mode == QCamera::FlashOn) + captureDevice.flashMode = AVCaptureFlashModeOn; + else if (mode == QCamera::FlashAuto) + captureDevice.flashMode = AVCaptureFlashModeAuto; + } + } + + if (captureDevice.hasTorch) { + auto mode = torchMode(); + if (mode == QCamera::TorchOff) { + captureDevice.torchMode = AVCaptureTorchModeOff; + } else { +#ifdef Q_OS_IOS + if (![captureDevice isTorchAvailable]) { + qDebugCamera() << Q_FUNC_INFO << "torch is not available at the moment"; + return; + } +#endif + if (mode == QCamera::TorchOn) + captureDevice.torchMode = AVCaptureTorchModeOn; + else if (mode == QCamera::TorchAuto) + captureDevice.torchMode = AVCaptureTorchModeAuto; + } + } +} + + +void AVFCamera::setExposureCompensation(float bias) +{ +#ifdef Q_OS_IOS + AVCaptureDevice *captureDevice = device(); + if (!captureDevice) { + exposureCompensationChanged(bias); + return; + } + + bias = qBound(captureDevice.minExposureTargetBias, bias, captureDevice.maxExposureTargetBias); + + const AVFConfigurationLock lock(captureDevice); + if (!lock) { + qDebugCamera() << Q_FUNC_INFO << "failed to lock for configuration"; + return false; + } + + [captureDevice setExposureTargetBias:bias completionHandler:nil]; + exposureCompensationChanged(bias); +#else + Q_UNUSED(bias); +#endif +} + +void AVFCamera::setManualShutterSpeed(float value) +{ +#ifdef Q_OS_IOS + if (value < 0) { + setExposureMode(QCamera::ExposureAuto); + return; + } + + AVCaptureDevice *captureDevice = device(); + if (!captureDevice) { + manualShutterSpeedChanged(value); + return; + } + + const CMTime newDuration = CMTimeMakeWithSeconds(value, captureDevice.exposureDuration.timescale); + if (!qt_check_exposure_duration(captureDevice, newDuration)) { + qDebugCamera() << Q_FUNC_INFO << "shutter speed value is out of range"; + return; + } + + const AVFConfigurationLock lock(captureDevice); + if (!lock) { + qDebugCamera() << Q_FUNC_INFO << "failed to lock for configuration"; + return; + } + + // Setting the shutter speed (exposure duration in Apple's terms, + // since there is no shutter actually) will also reset + // exposure mode into custom mode. + [captureDevice setExposureModeCustomWithDuration:newDuration + ISO:AVCaptureISOCurrent + completionHandler:nil]; + + manualShutterSpeedChanged(value); + +#else + Q_UNUSED(value); +#endif +} + +float AVFCamera::shutterSpeed() const +{ +#ifdef Q_OS_IOS + AVCaptureDevice *captureDevice = device(); + if (!captureDevice) + return -1.; + auto duration = captureDevice.exposureDuration; + return CMTimeGetSeconds(duration); +#else + return -1; +#endif +} + +void AVFCamera::setManualIsoSensitivity(int value) +{ +#ifdef Q_OS_IOS + if (value < 0) { + setExposureMode(QCamera::ExposureAuto); + return; + } + + AVCaptureDevice *captureDevice = device(); + if (!captureDevice) { + manualIsoSensitivityChanged(value); + return; + } + + if (!qt_check_ISO_value(captureDevice, value.toInt())) { + qDebugCamera() << Q_FUNC_INFO << "ISO value is out of range"; + return false; + } + + const AVFConfigurationLock lock(captureDevice); + if (!lock) { + qDebugCamera() << Q_FUNC_INFO << "failed to lock a capture device" + << "for configuration"; + return false; + } + + // Setting the ISO will also reset + // exposure mode to the custom mode. + [captureDevice setExposureModeCustomWithDuration:AVCaptureExposureDurationCurrent + ISO:value + completionHandler:nil]; + + manualIsoSensitivityChanged(value); +#else + Q_UNUSED(value); +#endif +} + +int AVFCamera::isoSensitivity() const +{ + return manualIsoSensitivity(); +} + + #include "moc_avfcamera_p.cpp" diff --git a/src/multimedia/platform/darwin/camera/avfcamera_p.h b/src/multimedia/platform/darwin/camera/avfcamera_p.h index 710cd8038..8d2feb658 100644 --- a/src/multimedia/platform/darwin/camera/avfcamera_p.h +++ b/src/multimedia/platform/darwin/camera/avfcamera_p.h @@ -60,7 +60,6 @@ QT_BEGIN_NAMESPACE class AVFCameraSession; class AVFCameraService; class AVFCameraSession; -class AVFCameraExposure; class AVFCameraImageProcessing; Q_FORWARD_DECLARE_OBJC_CLASS(AVCaptureDeviceFormat); @@ -84,7 +83,6 @@ public: void setCaptureSession(QPlatformMediaCaptureSession *) override; - QPlatformCameraExposure *exposureControl() override; QPlatformCameraImageProcessing *imageProcessingControl() override; void setFocusMode(QCamera::FocusMode mode) override; @@ -96,6 +94,22 @@ public: void setFocusDistance(float d) override; void zoomTo(float factor, float rate) override; + void setFlashMode(QCamera::FlashMode mode) override; + bool isFlashModeSupported(QCamera::FlashMode mode) const override; + bool isFlashReady() const override; + + void setTorchMode(QCamera::TorchMode mode) override; + bool isTorchModeSupported(QCamera::TorchMode mode) const override; + + void setExposureMode(QCamera::ExposureMode) override; + bool isExposureModeSupported(QCamera::ExposureMode mode) const override; + + void setExposureCompensation(float bias) override; + void setManualIsoSensitivity(int value) override; + virtual int isoSensitivity() const override; + void setManualShutterSpeed(float value) override; + virtual float shutterSpeed() const override; + AVCaptureConnection *videoConnection() const; AVCaptureDevice *device() const; @@ -104,18 +118,23 @@ private Q_SLOTS: private: void updateCameraConfiguration(); + void applyFlashSettings(); friend class AVFCameraSession; AVFCameraService *m_service = nullptr; AVFCameraSession *m_session = nullptr; AVFCameraImageProcessing *m_cameraImageProcessingControl; - AVFCameraExposure *m_cameraExposureControl; QCameraInfo m_cameraInfo; bool m_active; QCamera::Status m_lastStatus; + + bool isFlashSupported = false; + bool isFlashAutoSupported = false; + bool isTorchSupported = false; + bool isTorchAutoSupported = false; }; QT_END_NAMESPACE diff --git a/src/multimedia/platform/darwin/camera/avfcameraexposure.mm b/src/multimedia/platform/darwin/camera/avfcameraexposure.mm deleted file mode 100644 index 53499aa1f..000000000 --- a/src/multimedia/platform/darwin/camera/avfcameraexposure.mm +++ /dev/null @@ -1,833 +0,0 @@ -/**************************************************************************** -** -** 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 "avfcameraexposure_p.h" -#include "avfcamerautility_p.h" -#include "avfcamera_p.h" -#include "avfcameradebug_p.h" - -#include <QtCore/qvariant.h> -#include <QtCore/qpointer.h> -#include <QtCore/qdebug.h> -#include <QtCore/qpair.h> - -#include <AVFoundation/AVFoundation.h> - -#include <limits> - -QT_BEGIN_NAMESPACE - -namespace { - -// All these methods to work with exposure/ISO/SS in custom mode do not support macOS. - -#ifdef Q_OS_IOS - -// Misc. helpers to check values/ranges: - -bool qt_check_ISO_conversion(float isoValue) -{ - if (isoValue >= std::numeric_limits<int>::max()) - return false; - if (isoValue <= std::numeric_limits<int>::min()) - return false; - return true; -} - -bool qt_check_ISO_range(AVCaptureDeviceFormat *format) -{ - // Qt is using int for ISO, AVFoundation - float. It looks like the ISO range - // at the moment can be represented by int (it's max - min > 100, etc.). - Q_ASSERT(format); - if (format.maxISO - format.minISO < 1.) { - // ISO is in some strange units? - return false; - } - - return qt_check_ISO_conversion(format.minISO) - && qt_check_ISO_conversion(format.maxISO); -} - -bool qt_check_exposure_duration(AVCaptureDevice *captureDevice, CMTime duration) -{ - Q_ASSERT(captureDevice); - - AVCaptureDeviceFormat *activeFormat = captureDevice.activeFormat; - if (!activeFormat) { - qDebugCamera() << Q_FUNC_INFO << "failed to obtain capture device format"; - return false; - } - - return CMTimeCompare(duration, activeFormat.minExposureDuration) != -1 - && CMTimeCompare(activeFormat.maxExposureDuration, duration) != -1; -} - -bool qt_check_ISO_value(AVCaptureDevice *captureDevice, int newISO) -{ - Q_ASSERT(captureDevice); - - AVCaptureDeviceFormat *activeFormat = captureDevice.activeFormat; - if (!activeFormat) { - qDebugCamera() << Q_FUNC_INFO << "failed to obtain capture device format"; - return false; - } - - return !(newISO < activeFormat.minISO || newISO > activeFormat.maxISO); -} - -bool qt_exposure_duration_equal(AVCaptureDevice *captureDevice, qreal qDuration) -{ - Q_ASSERT(captureDevice); - const CMTime avDuration = CMTimeMakeWithSeconds(qDuration, captureDevice.exposureDuration.timescale); - return !CMTimeCompare(avDuration, captureDevice.exposureDuration); -} - -bool qt_iso_equal(AVCaptureDevice *captureDevice, int iso) -{ - Q_ASSERT(captureDevice); - return qFuzzyCompare(float(iso), captureDevice.ISO); -} - -bool qt_exposure_bias_equal(AVCaptureDevice *captureDevice, qreal bias) -{ - Q_ASSERT(captureDevice); - return qFuzzyCompare(bias, qreal(captureDevice.exposureTargetBias)); -} - -// Converters: - -bool qt_convert_exposure_mode(AVCaptureDevice *captureDevice, QCamera::ExposureMode mode, - AVCaptureExposureMode &avMode) -{ - // Test if mode supported and convert. - Q_ASSERT(captureDevice); - - if (mode == QCamera::ExposureAuto) { - if ([captureDevice isExposureModeSupported:AVCaptureExposureModeContinuousAutoExposure]) { - avMode = AVCaptureExposureModeContinuousAutoExposure; - return true; - } - } - - if (mode == QCamera::ExposureManual) { - if ([captureDevice isExposureModeSupported:AVCaptureExposureModeCustom]) { - avMode = AVCaptureExposureModeCustom; - return true; - } - } - - return false; -} - -// We set ISO/exposure duration with completion handlers, completion handlers try -// to avoid dangling pointers (thus QPointer for QObjects) and not to create -// a reference loop (in case we have ARC). - -void qt_set_exposure_bias(QPointer<AVFCamera> camera, QPointer<AVFCameraExposure> control, - AVCaptureDevice *captureDevice, float bias) -{ - Q_ASSERT(captureDevice); - - __block AVCaptureDevice *device = captureDevice; //For ARC. - - void (^completionHandler)(CMTime syncTime) = ^(CMTime) { - // Test that camera control is still alive and that - // capture device is our device, if yes - emit actual value changed. - if (camera) { - if (control) { - if (camera->device() == device) - Q_EMIT control->actualValueChanged(int(QPlatformCameraExposure::ExposureCompensation)); - } - } - device = nil; - }; - - [captureDevice setExposureTargetBias:bias completionHandler:completionHandler]; -} - -void qt_set_duration_iso(QPointer<AVFCamera> camera, QPointer<AVFCameraExposure> control, - AVCaptureDevice *captureDevice, CMTime duration, float iso) -{ - Q_ASSERT(captureDevice); - - __block AVCaptureDevice *device = captureDevice; //For ARC. - const bool setDuration = CMTimeCompare(duration, AVCaptureExposureDurationCurrent); - const bool setISO = !qFuzzyCompare(iso, AVCaptureISOCurrent); - - void (^completionHandler)(CMTime syncTime) = ^(CMTime) { - // Test that camera control is still alive and that - // capture device is our device, if yes - emit actual value changed. - if (camera) { - if (control) { - if (camera->device() == device) { - if (setDuration) - Q_EMIT control->actualValueChanged(int(QPlatformCameraExposure::ShutterSpeed)); - if (setISO) - Q_EMIT control->actualValueChanged(int(QPlatformCameraExposure::ISO)); - } - } - } - device = nil; - }; - - [captureDevice setExposureModeCustomWithDuration:duration - ISO:iso - completionHandler:completionHandler]; -} - -#endif // defined(Q_OS_IOS) - -} // Unnamed namespace. - -AVFCameraExposure::AVFCameraExposure(AVFCamera *camera) - : QPlatformCameraExposure(camera), - m_camera(camera) -{ - Q_ASSERT(m_camera); - - connect(m_camera, SIGNAL(activeChanged(bool)), SLOT(cameraActiveChanged(bool))); -} - -bool AVFCameraExposure::isParameterSupported(ExposureParameter parameter) const -{ -#ifdef Q_OS_IOS - AVCaptureDevice *captureDevice = m_camera->device(); - if (!captureDevice) - return false; - - // These are the parameters we have an API to support: - return parameter == QPlatformCameraExposure::ISO - || parameter == QPlatformCameraExposure::ShutterSpeed - || parameter == QPlatformCameraExposure::ExposureCompensation - || parameter == QPlatformCameraExposure::ExposureMode; -#else - Q_UNUSED(parameter); - return false; -#endif -} - -QVariantList AVFCameraExposure::supportedParameterRange(ExposureParameter parameter, - bool *continuous) const -{ - QVariantList parameterRange; -#ifdef Q_OS_IOS - - AVCaptureDevice *captureDevice = m_camera->device(); - if (!captureDevice || !isParameterSupported(parameter)) { - qDebugCamera() << Q_FUNC_INFO << "parameter not supported"; - return parameterRange; - } - - if (continuous) - *continuous = false; - - AVCaptureDeviceFormat *activeFormat = captureDevice.activeFormat; - - if (parameter == QPlatformCameraExposure::ISO) { - if (!activeFormat) { - qDebugCamera() << Q_FUNC_INFO << "failed to obtain capture device format"; - return parameterRange; - } - - if (!qt_check_ISO_range(activeFormat)) { - qDebugCamera() << Q_FUNC_INFO << "ISO range can not be represented as int"; - return parameterRange; - } - - parameterRange << QVariant(int(activeFormat.minISO)); - parameterRange << QVariant(int(activeFormat.maxISO)); - if (continuous) - *continuous = true; - } else if (parameter == QPlatformCameraExposure::ExposureCompensation) { - parameterRange << captureDevice.minExposureTargetBias; - parameterRange << captureDevice.maxExposureTargetBias; - if (continuous) - *continuous = true; - } else if (parameter == QPlatformCameraExposure::ShutterSpeed) { - if (!activeFormat) { - qDebugCamera() << Q_FUNC_INFO << "failed to obtain capture device format"; - return parameterRange; - } - - // CMTimeGetSeconds returns Float64, test the conversion below, if it's valid? - parameterRange << qreal(CMTimeGetSeconds(activeFormat.minExposureDuration)); - parameterRange << qreal(CMTimeGetSeconds(activeFormat.maxExposureDuration)); - - if (continuous) - *continuous = true; - } else if (parameter == QPlatformCameraExposure::ExposureMode) { - if ([captureDevice isExposureModeSupported:AVCaptureExposureModeCustom]) - parameterRange << QVariant::fromValue(QCamera::ExposureManual); - - if ([captureDevice isExposureModeSupported:AVCaptureExposureModeContinuousAutoExposure]) - parameterRange << QVariant::fromValue(QCamera::ExposureAuto); - } -#else - Q_UNUSED(parameter); - Q_UNUSED(continuous); -#endif - return parameterRange; -} - -QVariant AVFCameraExposure::requestedValue(ExposureParameter parameter) const -{ - if (!isParameterSupported(parameter)) { - qDebugCamera() << Q_FUNC_INFO << "parameter not supported"; - return QVariant(); - } - - if (parameter == QPlatformCameraExposure::ExposureMode) - return m_requestedMode; - - if (parameter == QPlatformCameraExposure::ExposureCompensation) - return m_requestedCompensation; - - if (parameter == QPlatformCameraExposure::ShutterSpeed) - return m_requestedShutterSpeed; - - if (parameter == QPlatformCameraExposure::ISO) - return m_requestedISO; - - return QVariant(); -} - -QVariant AVFCameraExposure::actualValue(ExposureParameter parameter) const -{ -#ifdef Q_OS_IOS - AVCaptureDevice *captureDevice = m_camera->device(); - if (!captureDevice || !isParameterSupported(parameter)) { - // Actually, at the moment !captiredevice => !isParameterSupported. - qDebugCamera() << Q_FUNC_INFO << "parameter not supported"; - return QVariant(); - } - - if (parameter == QPlatformCameraExposure::ExposureMode) { - // This code expects exposureMode to be continuous by default ... - if (captureDevice.exposureMode == AVCaptureExposureModeContinuousAutoExposure) - return QVariant::fromValue(QCamera::ExposureAuto); - return QVariant::fromValue(QCamera::ExposureManual); - } - - if (parameter == QPlatformCameraExposure::ExposureCompensation) - return captureDevice.exposureTargetBias; - - if (parameter == QPlatformCameraExposure::ShutterSpeed) - return qreal(CMTimeGetSeconds(captureDevice.exposureDuration)); - - if (parameter == QPlatformCameraExposure::ISO) { - if (captureDevice.activeFormat && qt_check_ISO_range(captureDevice.activeFormat) - && qt_check_ISO_conversion(captureDevice.ISO)) { - // Can be represented as int ... - return int(captureDevice.ISO); - } else { - qDebugCamera() << Q_FUNC_INFO << "ISO can not be represented as int"; - return QVariant(); - } - } -#else - Q_UNUSED(parameter); -#endif - return QVariant(); -} - -bool AVFCameraExposure::setValue(ExposureParameter parameter, const QVariant &value) -{ - if (parameter == QPlatformCameraExposure::ExposureMode) - return setExposureMode(value); - else if (parameter == QPlatformCameraExposure::ExposureCompensation) - return setExposureCompensation(value); - else if (parameter == QPlatformCameraExposure::ShutterSpeed) - return setShutterSpeed(value); - else if (parameter == QPlatformCameraExposure::ISO) - return setISO(value); - - return false; -} - -bool AVFCameraExposure::setExposureMode(const QVariant &value) -{ -#ifdef Q_OS_IOS - if (!value.canConvert<QCamera::ExposureMode>()) { - qDebugCamera() << Q_FUNC_INFO << "invalid exposure mode value," - << "QCamera::ExposureMode expected"; - return false; - } - - const QCamera::ExposureMode qtMode = value.value<QCamera::ExposureMode>(); - if (qtMode != QCamera::ExposureAuto && qtMode != QCamera::ExposureManual) { - qDebugCamera() << Q_FUNC_INFO << "exposure mode not supported"; - return false; - } - - AVCaptureDevice *captureDevice = m_camera->device(); - if (!captureDevice) { - m_requestedMode = value; - Q_EMIT requestedValueChanged(int(QPlatformCameraExposure::ExposureMode)); - return true; - } - - AVCaptureExposureMode avMode = AVCaptureExposureModeAutoExpose; - if (!qt_convert_exposure_mode(captureDevice, qtMode, avMode)) { - qDebugCamera() << Q_FUNC_INFO << "exposure mode not supported"; - return false; - } - - const AVFConfigurationLock lock(captureDevice); - if (!lock) { - qDebugCamera() << Q_FUNC_INFO << "failed to lock a capture device" - << "for configuration"; - return false; - } - - m_requestedMode = value; - [captureDevice setExposureMode:avMode]; - Q_EMIT requestedValueChanged(int(QPlatformCameraExposure::ExposureMode)); - Q_EMIT actualValueChanged(int(QPlatformCameraExposure::ExposureMode)); - - return true; -#else - Q_UNUSED(value); - return false; -#endif -} - -bool AVFCameraExposure::setExposureCompensation(const QVariant &value) -{ -#ifdef Q_OS_IOS - if (!value.canConvert<qreal>()) { - qDebugCamera() << Q_FUNC_INFO << "invalid exposure compensation" - <<"value, floating point number expected"; - return false; - } - - const qreal bias = value.toReal(); - AVCaptureDevice *captureDevice = m_camera->device(); - if (!captureDevice) { - m_requestedCompensation = value; - Q_EMIT requestedValueChanged(int(QPlatformCameraExposure::ExposureCompensation)); - return true; - } - - if (bias < captureDevice.minExposureTargetBias || bias > captureDevice.maxExposureTargetBias) { - // TODO: mixed fp types! - qDebugCamera() << Q_FUNC_INFO << "exposure compenstation value is" - << "out of range"; - return false; - } - - const AVFConfigurationLock lock(captureDevice); - if (!lock) { - qDebugCamera() << Q_FUNC_INFO << "failed to lock for configuration"; - return false; - } - - qt_set_exposure_bias(m_camera, this, captureDevice, bias); - m_requestedCompensation = value; - Q_EMIT requestedValueChanged(int(QPlatformCameraExposure::ExposureCompensation)); - - return true; -#else - Q_UNUSED(value); - return false; -#endif -} - -bool AVFCameraExposure::setShutterSpeed(const QVariant &value) -{ -#ifdef Q_OS_IOS - if (value.isNull()) - return setExposureMode(QVariant::fromValue(QCamera::ExposureAuto)); - - if (!value.canConvert<qreal>()) { - qDebugCamera() << Q_FUNC_INFO << "invalid shutter speed" - << "value, floating point number expected"; - return false; - } - - AVCaptureDevice *captureDevice = m_camera->device(); - if (!captureDevice) { - m_requestedShutterSpeed = value; - Q_EMIT requestedValueChanged(int(QPlatformCameraExposure::ShutterSpeed)); - return true; - } - - const CMTime newDuration = CMTimeMakeWithSeconds(value.toReal(), - captureDevice.exposureDuration.timescale); - if (!qt_check_exposure_duration(captureDevice, newDuration)) { - qDebugCamera() << Q_FUNC_INFO << "shutter speed value is out of range"; - return false; - } - - const AVFConfigurationLock lock(captureDevice); - if (!lock) { - qDebugCamera() << Q_FUNC_INFO << "failed to lock for configuration"; - return false; - } - - // Setting the shutter speed (exposure duration in Apple's terms, - // since there is no shutter actually) will also reset - // exposure mode into custom mode. - qt_set_duration_iso(m_camera, this, captureDevice, newDuration, AVCaptureISOCurrent); - - m_requestedShutterSpeed = value; - Q_EMIT requestedValueChanged(int(QPlatformCameraExposure::ShutterSpeed)); - - return true; -#else - Q_UNUSED(value); - return false; -#endif -} - -bool AVFCameraExposure::setISO(const QVariant &value) -{ -#ifdef Q_OS_IOS - if (value.isNull()) - return setExposureMode(QVariant::fromValue(QCamera::ExposureAuto)); - - if (!value.canConvert<int>()) { - qDebugCamera() << Q_FUNC_INFO << "invalid ISO value, int expected"; - return false; - } - - AVCaptureDevice *captureDevice = m_camera->device(); - if (!captureDevice) { - m_requestedISO = value; - Q_EMIT requestedValueChanged(int(QPlatformCameraExposure::ISO)); - return true; - } - - if (!qt_check_ISO_value(captureDevice, value.toInt())) { - qDebugCamera() << Q_FUNC_INFO << "ISO value is out of range"; - return false; - } - - const AVFConfigurationLock lock(captureDevice); - if (!lock) { - qDebugCamera() << Q_FUNC_INFO << "failed to lock a capture device" - << "for configuration"; - return false; - } - - // Setting the ISO will also reset - // exposure mode to the custom mode. - qt_set_duration_iso(m_camera, this, captureDevice, AVCaptureExposureDurationCurrent, value.toInt()); - - m_requestedISO = value; - Q_EMIT requestedValueChanged(int(QPlatformCameraExposure::ISO)); - - return true; -#else - Q_UNUSED(value); - return false; -#endif -} - -void AVFCameraExposure::cameraActiveChanged(bool active) -{ -#ifdef Q_OS_IOS - if (!m_camera->isActive()) - return; - - AVCaptureDevice *captureDevice = m_camera->device(); - if (!captureDevice) { - qDebugCamera() << Q_FUNC_INFO << "capture device is nil, but the camera" - << "is 'active'"; - return; - } - - Q_EMIT parameterRangeChanged(int(QPlatformCameraExposure::ExposureCompensation)); - Q_EMIT parameterRangeChanged(int(QPlatformCameraExposure::ExposureMode)); - Q_EMIT parameterRangeChanged(int(QPlatformCameraExposure::ShutterSpeed)); - Q_EMIT parameterRangeChanged(int(QPlatformCameraExposure::ISO)); - - const AVFConfigurationLock lock(captureDevice); - - CMTime newDuration = AVCaptureExposureDurationCurrent; - bool setCustomMode = false; - - if (!m_requestedShutterSpeed.isNull() - && !qt_exposure_duration_equal(captureDevice, m_requestedShutterSpeed.toReal())) { - newDuration = CMTimeMakeWithSeconds(m_requestedShutterSpeed.toReal(), - captureDevice.exposureDuration.timescale); - if (!qt_check_exposure_duration(captureDevice, newDuration)) { - qDebugCamera() << Q_FUNC_INFO << "requested exposure duration is out of range"; - return; - } - setCustomMode = true; - } - - float newISO = AVCaptureISOCurrent; - if (!m_requestedISO.isNull() && !qt_iso_equal(captureDevice, m_requestedISO.toInt())) { - newISO = m_requestedISO.toInt(); - if (!qt_check_ISO_value(captureDevice, newISO)) { - qDebugCamera() << Q_FUNC_INFO << "requested ISO value is out of range"; - return; - } - setCustomMode = true; - } - - if (!m_requestedCompensation.isNull() - && !qt_exposure_bias_equal(captureDevice, m_requestedCompensation.toReal())) { - // TODO: mixed fpns. - const qreal bias = m_requestedCompensation.toReal(); - if (bias < captureDevice.minExposureTargetBias || bias > captureDevice.maxExposureTargetBias) { - qDebugCamera() << Q_FUNC_INFO << "exposure compenstation value is" - << "out of range"; - return; - } - if (!lock) { - qDebugCamera() << Q_FUNC_INFO << "failed to lock for configuration"; - return; - } - qt_set_exposure_bias(m_camera, this, captureDevice, bias); - } - - // Setting shutter speed (exposure duration) or ISO values - // also reset exposure mode into Custom. With this settings - // we ignore any attempts to set exposure mode. - - if (setCustomMode) { - if (!lock) - qDebugCamera() << Q_FUNC_INFO << "failed to lock for configuration"; - else - qt_set_duration_iso(m_camera, this, captureDevice, newDuration, newISO); - return; - } - - if (!m_requestedMode.isNull()) { - QCamera::ExposureMode qtMode = m_requestedMode.value<QCamera::ExposureMode>(); - AVCaptureExposureMode avMode = AVCaptureExposureModeContinuousAutoExposure; - if (!qt_convert_exposure_mode(captureDevice, qtMode, avMode)) { - qDebugCamera() << Q_FUNC_INFO << "requested exposure mode is not supported"; - return; - } - - if (avMode == captureDevice.exposureMode) - return; - - if (!lock) { - qDebugCamera() << Q_FUNC_INFO << "failed to lock for configuration"; - return; - } - - [captureDevice setExposureMode:avMode]; - Q_EMIT actualValueChanged(int(QPlatformCameraExposure::ExposureMode)); - } -#endif - - isFlashSupported = isFlashAutoSupported = false; - isTorchSupported = isTorchAutoSupported = false; - if (!active) { - Q_EMIT flashReady(false); - } else { - AVCaptureDevice *captureDevice = m_camera->device(); - if (!captureDevice) { - qDebugCamera() << Q_FUNC_INFO << "no capture device in 'Active' state"; - Q_EMIT flashReady(false); - return; - } - - if (captureDevice.hasFlash) { - if ([captureDevice isFlashModeSupported:AVCaptureFlashModeOn]) - isFlashSupported = true; - if ([captureDevice isFlashModeSupported:AVCaptureFlashModeAuto]) - isFlashAutoSupported = true; - } - - if (captureDevice.hasTorch) { - if ([captureDevice isTorchModeSupported:AVCaptureTorchModeOn]) - isTorchSupported = true; - if ([captureDevice isTorchModeSupported:AVCaptureTorchModeAuto]) - isTorchAutoSupported = true; - } - - applyFlashSettings(); - Q_EMIT flashReady(isFlashSupported); - } -} - - - -QCamera::FlashMode AVFCameraExposure::flashMode() const -{ - return m_flashMode; -} - -void AVFCameraExposure::setFlashMode(QCamera::FlashMode mode) -{ - if (m_flashMode == mode) - return; - - if (m_camera->isActive() && !isFlashModeSupported(mode)) { - qDebugCamera() << Q_FUNC_INFO << "unsupported mode" << mode; - return; - } - - m_flashMode = mode; - - if (!m_camera->isActive()) - return; - - applyFlashSettings(); -} - -bool AVFCameraExposure::isFlashModeSupported(QCamera::FlashMode mode) const -{ - if (mode == QCamera::FlashOff) - return true; - else if (mode == QCamera::FlashOn) - return isFlashSupported; - else //if (mode == QCamera::FlashAuto) - return isFlashAutoSupported; -} - -bool AVFCameraExposure::isFlashReady() const -{ - if (!m_camera->isActive()) - return false; - - AVCaptureDevice *captureDevice = m_camera->device(); - if (!captureDevice) - return false; - - if (!captureDevice.hasFlash && !captureDevice.hasTorch) - return false; - - if (!isFlashModeSupported(m_flashMode)) - return false; - -#ifdef Q_OS_IOS - // AVCaptureDevice's docs: - // "The flash may become unavailable if, for example, - // the device overheats and needs to cool off." - return [captureDevice isFlashAvailable]; -#endif - - return true; -} - -QCamera::TorchMode AVFCameraExposure::torchMode() const -{ - return m_torchMode; -} - -void AVFCameraExposure::setTorchMode(QCamera::TorchMode mode) -{ - if (m_torchMode == mode) - return; - - if (m_camera->isActive() && !isTorchModeSupported(mode)) { - qDebugCamera() << Q_FUNC_INFO << "unsupported torch mode" << mode; - return; - } - - m_torchMode = mode; - - if (!m_camera->isActive()) - return; - - applyFlashSettings(); -} - -bool AVFCameraExposure::isTorchModeSupported(QCamera::TorchMode mode) const -{ - if (mode == QCamera::TorchOff) - return true; - else if (mode == QCamera::TorchOn) - return isTorchSupported; - else //if (mode == QCamera::TorchAuto) - return isTorchAutoSupported; -} - -void AVFCameraExposure::applyFlashSettings() -{ - Q_ASSERT(m_camera->isActive()); - - AVCaptureDevice *captureDevice = m_camera->device(); - if (!captureDevice) { - qDebugCamera() << Q_FUNC_INFO << "no capture device found"; - return; - } - - if (!isFlashModeSupported(m_flashMode)) { - qDebugCamera() << Q_FUNC_INFO << "unsupported mode" << m_flashMode; - return; - } - - const AVFConfigurationLock lock(captureDevice); - - if (captureDevice.hasFlash) { - if (m_flashMode == QCamera::FlashOff) { - captureDevice.flashMode = AVCaptureFlashModeOff; - } else { -#ifdef Q_OS_IOS - if (![captureDevice isFlashAvailable]) { - qDebugCamera() << Q_FUNC_INFO << "flash is not available at the moment"; - return; - } -#endif - if (m_flashMode == QCamera::FlashOn) - captureDevice.flashMode = AVCaptureFlashModeOn; - else if (m_flashMode == QCamera::FlashAuto) - captureDevice.flashMode = AVCaptureFlashModeAuto; - } - } - - if (captureDevice.hasTorch) { - if (m_torchMode == QCamera::TorchOff) { - captureDevice.torchMode = AVCaptureTorchModeOff; - } else { -#ifdef Q_OS_IOS - if (![captureDevice isTorchAvailable]) { - qDebugCamera() << Q_FUNC_INFO << "torch is not available at the moment"; - return; - } -#endif - if (m_torchMode == QCamera::TorchOn) - captureDevice.torchMode = AVCaptureTorchModeOn; - else if (m_torchMode == QCamera::TorchAuto) - captureDevice.torchMode = AVCaptureTorchModeAuto; - } - } -} - -QT_END_NAMESPACE - -#include "moc_avfcameraexposure_p.cpp" diff --git a/src/multimedia/platform/darwin/camera/avfcameraexposure_p.h b/src/multimedia/platform/darwin/camera/avfcameraexposure_p.h deleted file mode 100644 index e432d377f..000000000 --- a/src/multimedia/platform/darwin/camera/avfcameraexposure_p.h +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** -** -** 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 AVFCAMERAEXPOSURE_H -#define AVFCAMERAEXPOSURE_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <private/qplatformcameraexposure_p.h> -#include <QtMultimedia/qcamera.h> - -#include <QtCore/qglobal.h> - -QT_BEGIN_NAMESPACE - -class AVFCamera; - -class AVFCameraExposure : public QPlatformCameraExposure -{ - Q_OBJECT - -public: - AVFCameraExposure(AVFCamera *camera); - - bool isParameterSupported(ExposureParameter parameter) const override; - QVariantList supportedParameterRange(ExposureParameter parameter, - bool *continuous) const override; - - QVariant requestedValue(ExposureParameter parameter) const override; - QVariant actualValue(ExposureParameter parameter) const override; - bool setValue(ExposureParameter parameter, const QVariant &value) override; - - QCamera::FlashMode flashMode() const override; - void setFlashMode(QCamera::FlashMode mode) override; - bool isFlashModeSupported(QCamera::FlashMode mode) const override; - bool isFlashReady() const override; - - QCamera::TorchMode torchMode() const override; - void setTorchMode(QCamera::TorchMode mode) override; - bool isTorchModeSupported(QCamera::TorchMode mode) const override; - -private Q_SLOTS: - void cameraActiveChanged(bool active); - -private: - void applyFlashSettings(); - - AVFCamera *m_camera; - - QVariant m_requestedMode; - QVariant m_requestedCompensation; - QVariant m_requestedShutterSpeed; - QVariant m_requestedISO; - - // Aux. setters: - bool setExposureMode(const QVariant &value); - bool setExposureCompensation(const QVariant &value); - bool setShutterSpeed(const QVariant &value); - bool setISO(const QVariant &value); - - // Set of bits: - bool isFlashSupported = false; - bool isFlashAutoSupported = false; - bool isTorchSupported = false; - bool isTorchAutoSupported = false; - QCamera::FlashMode m_flashMode = QCamera::FlashOff; - QCamera::TorchMode m_torchMode = QCamera::TorchOff; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/multimedia/platform/darwin/camera/avfcameraservice.mm b/src/multimedia/platform/darwin/camera/avfcameraservice.mm index 4d5021076..6a577e4fe 100644 --- a/src/multimedia/platform/darwin/camera/avfcameraservice.mm +++ b/src/multimedia/platform/darwin/camera/avfcameraservice.mm @@ -46,7 +46,6 @@ #include "avfcameraimagecapture_p.h" #include "avfcamerarenderer_p.h" #include "avfcameraimagecapture_p.h" -#include "avfcameraexposure_p.h" #include "avfcameraimageprocessing_p.h" #include "avfmediaencoder_p.h" #include <qmediadevices.h> diff --git a/src/multimedia/platform/gstreamer/mediacapture/qgstreamercamera.cpp b/src/multimedia/platform/gstreamer/mediacapture/qgstreamercamera.cpp index e31c8e6f2..9ece4a09e 100644 --- a/src/multimedia/platform/gstreamer/mediacapture/qgstreamercamera.cpp +++ b/src/multimedia/platform/gstreamer/mediacapture/qgstreamercamera.cpp @@ -43,7 +43,6 @@ #include "qgstreamercameraimagecapture_p.h" #include <private/qgstreamermediadevices_p.h> #include <private/qgstreamerintegration_p.h> -#include <private/qgstreamercameraexposure_p.h> #include <private/qgstreamercameraimageprocessing_p.h> #include <qmediacapturesession.h> @@ -189,9 +188,20 @@ QPlatformCameraImageProcessing *QGstreamerCamera::imageProcessingControl() return imageProcessing; } -QPlatformCameraExposure *QGstreamerCamera::exposureControl() +GstColorBalance *QGstreamerCamera::colorBalance() const +{ + if (!gstCamera.isNull() && GST_IS_COLOR_BALANCE(gstCamera.element())) + return GST_COLOR_BALANCE(gstCamera.element()); + // ### Add support for manual/SW color balancing using the gstreamer colorbalance element + return nullptr; +} + +#if QT_CONFIG(gstreamer_photography) +GstPhotography *QGstreamerCamera::photography() const { - return exposure; + if (!gstCamera.isNull() && GST_IS_PHOTOGRAPHY(gstCamera.element())) + return GST_PHOTOGRAPHY(gstCamera.element()); + return nullptr; } void QGstreamerCamera::setFocusMode(QCamera::FocusMode mode) @@ -199,7 +209,6 @@ void QGstreamerCamera::setFocusMode(QCamera::FocusMode mode) if (mode == focusMode()) return; -#if QT_CONFIG(gstreamer_photography) auto p = photography(); if (p) { GstPhotographyFocusMode photographyMode = GST_PHOTOGRAPHY_FOCUS_MODE_CONTINUOUS_NORMAL; @@ -227,34 +236,173 @@ void QGstreamerCamera::setFocusMode(QCamera::FocusMode mode) if (gst_photography_set_focus_mode(p, photographyMode)) focusModeChanged(mode); } -#endif } bool QGstreamerCamera::isFocusModeSupported(QCamera::FocusMode mode) const { + if (photography()) + return true; + return mode == QCamera::FocusModeAuto; +} + +void QGstreamerCamera::setFlashMode(QCamera::FlashMode mode) +{ Q_UNUSED(mode); -#if QT_CONFIG(gstreamer_photography) + if (auto *p = photography()) { + GstPhotographyFlashMode flashMode; + gst_photography_get_flash_mode(p, &flashMode); + + switch (mode) { + case QCamera::FlashAuto: + flashMode = GST_PHOTOGRAPHY_FLASH_MODE_AUTO; + break; + case QCamera::FlashOff: + flashMode = GST_PHOTOGRAPHY_FLASH_MODE_OFF; + break; + case QCamera::FlashOn: + flashMode = GST_PHOTOGRAPHY_FLASH_MODE_ON; + break; + } + + if (gst_photography_set_flash_mode(p, flashMode)) + flashModeChanged(mode); + } +} + +bool QGstreamerCamera::isFlashModeSupported(QCamera::FlashMode mode) const +{ + if (photography()) + return true; + + return mode == QCamera::FlashAuto; +} + +bool QGstreamerCamera::isFlashReady() const +{ if (photography()) return true; -#endif return false; } -GstColorBalance *QGstreamerCamera::colorBalance() const +void QGstreamerCamera::setExposureMode(QCamera::ExposureMode mode) { - if (!gstCamera.isNull() && GST_IS_COLOR_BALANCE(gstCamera.element())) - return GST_COLOR_BALANCE(gstCamera.element()); - // ### Add support for manual/SW color balancing using the gstreamer colorbalance element - return nullptr; + auto *p = photography(); + if (!p) + return; + + GstPhotographySceneMode sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_AUTO; + + switch (mode) { + case QCamera::ExposureManual: + sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_MANUAL; + break; + case QCamera::ExposurePortrait: + sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_PORTRAIT; + break; + case QCamera::ExposureSports: + sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_SPORT; + break; + case QCamera::ExposureNight: + sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_NIGHT; + break; + case QCamera::ExposureAuto: + sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_AUTO; + break; + case QCamera::ExposureLandscape: + sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_LANDSCAPE; + break; + case QCamera::ExposureSnow: + sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_SNOW; + break; + case QCamera::ExposureBeach: + sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_BEACH; + break; + case QCamera::ExposureAction: + sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_ACTION; + break; + case QCamera::ExposureNightPortrait: + sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_NIGHT_PORTRAIT; + break; + case QCamera::ExposureTheatre: + sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_THEATRE; + break; + case QCamera::ExposureSunset: + sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_SUNSET; + break; + case QCamera::ExposureSteadyPhoto: + sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_STEADY_PHOTO; + break; + case QCamera::ExposureFireworks: + sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_FIREWORKS; + break; + case QCamera::ExposureParty: + sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_PARTY; + break; + case QCamera::ExposureCandlelight: + sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_CANDLELIGHT; + break; + case QCamera::ExposureBarcode: + sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_BARCODE; + break; + default: + return; + } + + if (gst_photography_set_scene_mode(p, sceneMode)) + exposureModeChanged(mode); } -#if QT_CONFIG(gstreamer_photography) -GstPhotography *QGstreamerCamera::photography() const +bool QGstreamerCamera::isExposureModeSupported(QCamera::ExposureMode mode) const { - if (!gstCamera.isNull() && GST_IS_PHOTOGRAPHY(gstCamera.element())) - return GST_PHOTOGRAPHY(gstCamera.element()); - return nullptr; + if (photography()) + return true; + + return mode == QCamera::ExposureAuto; +} + +void QGstreamerCamera::setExposureCompensation(float compensation) +{ + if (auto *p = photography()) { + if (gst_photography_set_ev_compensation(p, compensation)) + exposureCompensationChanged(compensation); + } +} + +void QGstreamerCamera::setManualIsoSensitivity(int iso) +{ + if (auto *p = photography()) { + if (gst_photography_set_iso_speed(p, iso)) + isoSensitivityChanged(iso); + } +} + +int QGstreamerCamera::isoSensitivity() const +{ + if (auto *p = photography()) { + guint speed = 0; + if (gst_photography_get_iso_speed(p, &speed)) + return speed; + } + return 100; +} + +void QGstreamerCamera::setManualShutterSpeed(float secs) +{ + if (auto *p = photography()) { + if (gst_photography_set_exposure(p, guint(secs*1000000))) + shutterSpeedChanged(secs); + } +} + +float QGstreamerCamera::shutterSpeed() const +{ + if (auto *p = photography()) { + guint32 exposure = 0; + if (gst_photography_get_exposure(p, &exposure)) + return exposure/1000000.; + } + return -1; } #endif diff --git a/src/multimedia/platform/gstreamer/mediacapture/qgstreamercamera_p.h b/src/multimedia/platform/gstreamer/mediacapture/qgstreamercamera_p.h index 0714bc10a..2397cfa84 100644 --- a/src/multimedia/platform/gstreamer/mediacapture/qgstreamercamera_p.h +++ b/src/multimedia/platform/gstreamer/mediacapture/qgstreamercamera_p.h @@ -59,7 +59,6 @@ #include <gst/video/colorbalance.h> QT_BEGIN_NAMESPACE -class QGstreamerCameraExposure; class QGstreamerImageProcessing; class QGstreamerCamera : public QPlatformCamera @@ -82,14 +81,26 @@ public: void setPipeline(const QGstPipeline &pipeline) { gstPipeline = pipeline; } QPlatformCameraImageProcessing *imageProcessingControl() override; - QPlatformCameraExposure *exposureControl() override; + +#if QT_CONFIG(gstreamer_photography) + GstPhotography *photography() const; void setFocusMode(QCamera::FocusMode mode) override; bool isFocusModeSupported(QCamera::FocusMode mode) const override; -#if QT_CONFIG(gstreamer_photography) - GstPhotography *photography() const; + void setFlashMode(QCamera::FlashMode mode) override; + bool isFlashModeSupported(QCamera::FlashMode mode) const override; + bool isFlashReady() const override; + + void setExposureMode(QCamera::ExposureMode) override; + bool isExposureModeSupported(QCamera::ExposureMode mode) const override; + void setExposureCompensation(float) override; + void setManualIsoSensitivity(int) override; + int isoSensitivity() const override; + void setManualShutterSpeed(float) override; + float shutterSpeed() const override; #endif + QString v4l2Device() const { return m_v4l2Device; } bool isV4L2Camera() const { return !m_v4l2Device.isEmpty(); } @@ -98,7 +109,6 @@ public: private: QGstreamerMediaCapture *m_session = nullptr; - QGstreamerCameraExposure *exposure = nullptr; QGstreamerImageProcessing *imageProcessing = nullptr; QCameraInfo m_cameraInfo; diff --git a/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraexposure.cpp b/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraexposure.cpp deleted file mode 100644 index bf36ba502..000000000 --- a/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraexposure.cpp +++ /dev/null @@ -1,372 +0,0 @@ -/**************************************************************************** -** -** 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 "qgstreamercameraexposure_p.h" -#include "qgstreamercamera_p.h" -#include <private/qgst_p.h> -#include <QDebug> - -QT_BEGIN_NAMESPACE - -QGstreamerCameraExposure::QGstreamerCameraExposure(QGstreamerCamera *session) - :QPlatformCameraExposure(session), - m_camera(session) -{ -#if QT_CONFIG(gstreamer_photography) - hasPhotography = m_camera->photography() != nullptr; -#endif -} - -QGstreamerCameraExposure::~QGstreamerCameraExposure() -{ -} - -bool QGstreamerCameraExposure::isParameterSupported(ExposureParameter parameter) const -{ -#if QT_CONFIG(gstreamer_photography) - if (hasPhotography) { - switch (parameter) { - case QPlatformCameraExposure::ExposureCompensation: - case QPlatformCameraExposure::ISO: - case QPlatformCameraExposure::ShutterSpeed: - return true; - default: - break; - } - } -#else - Q_UNUSED(parameter); -#endif - return false; -} - -QVariantList QGstreamerCameraExposure::supportedParameterRange(ExposureParameter parameter, - bool *continuous) const -{ - QVariantList res; - -#if QT_CONFIG(gstreamer_photography) - if (hasPhotography) { - if (continuous) - *continuous = false; - - switch (parameter) { - case QPlatformCameraExposure::ExposureCompensation: - if (continuous) - *continuous = true; - res << -2.0 << 2.0; - break; - case QPlatformCameraExposure::ISO: - res << 100 << 200 << 400; - break; - default: - break; - } - } -#else - Q_UNUSED(parameter); - Q_UNUSED(continuous); -#endif - - return res; -} - -QVariant QGstreamerCameraExposure::requestedValue(ExposureParameter parameter) const -{ - return m_requestedValues.value(parameter); -} - -QVariant QGstreamerCameraExposure::actualValue(ExposureParameter parameter) const -{ -#if QT_CONFIG(gstreamer_photography) - if (hasPhotography) { - switch (parameter) { - case QPlatformCameraExposure::ExposureCompensation: - { - gfloat ev; - gst_photography_get_ev_compensation(m_camera->photography(), &ev); - return QVariant(ev); - } - case QPlatformCameraExposure::ISO: - { - guint isoSpeed = 0; - gst_photography_get_iso_speed(m_camera->photography(), &isoSpeed); - return QVariant(isoSpeed); - } - case QPlatformCameraExposure::ShutterSpeed: - { - guint32 shutterSpeed = 0; - gst_photography_get_exposure(m_camera->photography(), &shutterSpeed); - - return QVariant(shutterSpeed/1000000.0); - } - case QPlatformCameraExposure::ExposureMode: - { - GstPhotographySceneMode sceneMode; - gst_photography_get_scene_mode(m_camera->photography(), &sceneMode); - - switch (sceneMode) { - case GST_PHOTOGRAPHY_SCENE_MODE_PORTRAIT: - return QVariant::fromValue(QCamera::ExposurePortrait); - case GST_PHOTOGRAPHY_SCENE_MODE_SPORT: - return QVariant::fromValue(QCamera::ExposureSports); - case GST_PHOTOGRAPHY_SCENE_MODE_NIGHT: - return QVariant::fromValue(QCamera::ExposureNight); - case GST_PHOTOGRAPHY_SCENE_MODE_MANUAL: - return QVariant::fromValue(QCamera::ExposureManual); - case GST_PHOTOGRAPHY_SCENE_MODE_LANDSCAPE: - return QVariant::fromValue(QCamera::ExposureLandscape); - case GST_PHOTOGRAPHY_SCENE_MODE_SNOW: - return QVariant::fromValue(QCamera::ExposureSnow); - case GST_PHOTOGRAPHY_SCENE_MODE_BEACH: - return QVariant::fromValue(QCamera::ExposureBeach); - case GST_PHOTOGRAPHY_SCENE_MODE_ACTION: - return QVariant::fromValue(QCamera::ExposureAction); - case GST_PHOTOGRAPHY_SCENE_MODE_NIGHT_PORTRAIT: - return QVariant::fromValue(QCamera::ExposureNightPortrait); - case GST_PHOTOGRAPHY_SCENE_MODE_THEATRE: - return QVariant::fromValue(QCamera::ExposureTheatre); - case GST_PHOTOGRAPHY_SCENE_MODE_SUNSET: - return QVariant::fromValue(QCamera::ExposureSunset); - case GST_PHOTOGRAPHY_SCENE_MODE_STEADY_PHOTO: - return QVariant::fromValue(QCamera::ExposureSteadyPhoto); - case GST_PHOTOGRAPHY_SCENE_MODE_FIREWORKS: - return QVariant::fromValue(QCamera::ExposureFireworks); - case GST_PHOTOGRAPHY_SCENE_MODE_PARTY: - return QVariant::fromValue(QCamera::ExposureParty); - case GST_PHOTOGRAPHY_SCENE_MODE_CANDLELIGHT: - return QVariant::fromValue(QCamera::ExposureCandlelight); - case GST_PHOTOGRAPHY_SCENE_MODE_BARCODE: - return QVariant::fromValue(QCamera::ExposureBarcode); - //no direct mapping available so mapping to auto mode - case GST_PHOTOGRAPHY_SCENE_MODE_CLOSEUP: - case GST_PHOTOGRAPHY_SCENE_MODE_AUTO: - default: - return QVariant::fromValue(QCamera::ExposureAuto); - } - } - default: - break; - } - } -#else - Q_UNUSED(parameter); -#endif - return QVariant(); -} - -bool QGstreamerCameraExposure::setValue(ExposureParameter parameter, const QVariant& value) -{ - -#if QT_CONFIG(gstreamer_photography) - if (hasPhotography) { - QVariant oldValue = actualValue(parameter); - - switch (parameter) { - case QPlatformCameraExposure::ExposureCompensation: - gst_photography_set_ev_compensation(m_camera->photography(), value.toReal()); - break; - case QPlatformCameraExposure::ISO: - gst_photography_set_iso_speed(m_camera->photography(), value.toInt()); - break; - case QPlatformCameraExposure::ShutterSpeed: - gst_photography_set_exposure(m_camera->photography(), guint(value.toReal()*1000000)); - break; - case QPlatformCameraExposure::ExposureMode: - { - QCamera::ExposureMode mode = value.value<QCamera::ExposureMode>(); - GstPhotographySceneMode sceneMode; - - gst_photography_get_scene_mode(m_camera->photography(), &sceneMode); - - switch (mode) { - case QCamera::ExposureManual: - sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_MANUAL; - break; - case QCamera::ExposurePortrait: - sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_PORTRAIT; - break; - case QCamera::ExposureSports: - sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_SPORT; - break; - case QCamera::ExposureNight: - sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_NIGHT; - break; - case QCamera::ExposureAuto: - sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_AUTO; - break; - case QCamera::ExposureLandscape: - sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_LANDSCAPE; - break; - case QCamera::ExposureSnow: - sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_SNOW; - break; - case QCamera::ExposureBeach: - sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_BEACH; - break; - case QCamera::ExposureAction: - sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_ACTION; - break; - case QCamera::ExposureNightPortrait: - sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_NIGHT_PORTRAIT; - break; - case QCamera::ExposureTheatre: - sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_THEATRE; - break; - case QCamera::ExposureSunset: - sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_SUNSET; - break; - case QCamera::ExposureSteadyPhoto: - sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_STEADY_PHOTO; - break; - case QCamera::ExposureFireworks: - sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_FIREWORKS; - break; - case QCamera::ExposureParty: - sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_PARTY; - break; - case QCamera::ExposureCandlelight: - sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_CANDLELIGHT; - break; - case QCamera::ExposureBarcode: - sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_BARCODE; - break; - default: - break; - } - - gst_photography_set_scene_mode(m_camera->photography(), sceneMode); - break; - } - default: - return false; - } - - if (!qFuzzyCompare(m_requestedValues.value(parameter).toReal(), value.toReal())) { - m_requestedValues[parameter] = value; - emit requestedValueChanged(parameter); - } - - QVariant newValue = actualValue(parameter); - if (!qFuzzyCompare(oldValue.toReal(), newValue.toReal())) - emit actualValueChanged(parameter); - - return true; - } -#else - Q_UNUSED(parameter); - Q_UNUSED(value); -#endif - - return false; -} - -QCamera::FlashMode QGstreamerCameraExposure::flashMode() const -{ -#if QT_CONFIG(gstreamer_photography) - if (hasPhotography) { - GstPhotographyFlashMode flashMode; - gst_photography_get_flash_mode(m_camera->photography(), &flashMode); - - QCamera::FlashMode mode; - switch (flashMode) { - default: - case GST_PHOTOGRAPHY_FLASH_MODE_AUTO: - mode = QCamera::FlashAuto; - break; - case GST_PHOTOGRAPHY_FLASH_MODE_OFF: - mode = QCamera::FlashOff; - break; - case GST_PHOTOGRAPHY_FLASH_MODE_ON: - mode = QCamera::FlashOn; - break; - } - return mode; - } -#endif - return QCamera::FlashAuto; -} - -void QGstreamerCameraExposure::setFlashMode(QCamera::FlashMode mode) -{ - Q_UNUSED(mode); - -#if QT_CONFIG(gstreamer_photography) - if (hasPhotography) { - GstPhotographyFlashMode flashMode; - gst_photography_get_flash_mode(m_camera->photography(), &flashMode); - - switch (mode) { - case QCamera::FlashAuto: - flashMode = GST_PHOTOGRAPHY_FLASH_MODE_AUTO; - break; - case QCamera::FlashOff: - flashMode = GST_PHOTOGRAPHY_FLASH_MODE_OFF; - break; - case QCamera::FlashOn: - flashMode = GST_PHOTOGRAPHY_FLASH_MODE_ON; - break; - } - - gst_photography_set_flash_mode(m_camera->photography(), flashMode); - } -#endif -} - -bool QGstreamerCameraExposure::isFlashModeSupported(QCamera::FlashMode mode) const -{ -#if QT_CONFIG(gstreamer_photography) - if (hasPhotography) - return true; -#endif - - return mode == QCamera::FlashAuto; -} - -bool QGstreamerCameraExposure::isFlashReady() const -{ -#if QT_CONFIG(gstreamer_photography) - if (hasPhotography) - return true; -#endif - - return false; -} - -QT_END_NAMESPACE diff --git a/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraexposure_p.h b/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraexposure_p.h deleted file mode 100644 index ecbd72e77..000000000 --- a/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraexposure_p.h +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** 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 CAMERABINEXPOSURECONTROL_H -#define CAMERABINEXPOSURECONTROL_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <private/qplatformcameraexposure_p.h> - -QT_BEGIN_NAMESPACE - -class QGstreamerCamera; - -class QGstreamerCameraExposure : public QPlatformCameraExposure -{ - Q_OBJECT - -public: - QGstreamerCameraExposure(QGstreamerCamera *session); - virtual ~QGstreamerCameraExposure(); - - bool isParameterSupported(ExposureParameter parameter) const override; - QVariantList supportedParameterRange(ExposureParameter parameter, bool *continuous) const override; - - QVariant requestedValue(ExposureParameter parameter) const override; - QVariant actualValue(ExposureParameter parameter) const override; - bool setValue(ExposureParameter parameter, const QVariant &value) override; - - QCamera::FlashMode flashMode() const override; - void setFlashMode(QCamera::FlashMode mode) override; - bool isFlashModeSupported(QCamera::FlashMode mode) const override; - - bool isFlashReady() const override; - -private: - bool hasPhotography = false; - QGstreamerCamera *m_camera; - QHash<ExposureParameter, QVariant> m_requestedValues; -}; - -QT_END_NAMESPACE - -#endif // CAMERABINEXPOSURECONTROL_H diff --git a/src/multimedia/platform/qplatformcamera.cpp b/src/multimedia/platform/qplatformcamera.cpp index cf2170fa0..e1a6baac2 100644 --- a/src/multimedia/platform/qplatformcamera.cpp +++ b/src/multimedia/platform/qplatformcamera.cpp @@ -216,6 +216,73 @@ void QPlatformCamera::focusDistanceChanged(float d) } +void QPlatformCamera::flashReadyChanged(bool ready) +{ + if (m_flashReady == ready) + return; + m_flashReady = ready; + emit m_camera->flashReady(m_flashReady); +} + +void QPlatformCamera::flashModeChanged(QCamera::FlashMode mode) +{ + if (m_flashMode == mode) + return; + m_flashMode = mode; + emit m_camera->flashModeChanged(); +} + +void QPlatformCamera::torchModeChanged(QCamera::TorchMode mode) +{ + if (m_torchMode == mode) + return; + m_torchMode = mode; + emit m_camera->torchModeChanged(); +} + +void QPlatformCamera::exposureModeChanged(QCamera::ExposureMode mode) +{ + if (m_exposureMode == mode) + return; + m_exposureMode = mode; + emit m_camera->exposureModeChanged(); +} + +void QPlatformCamera::exposureCompensationChanged(float compensation) +{ + if (m_exposureCompensation == compensation) + return; + m_exposureCompensation = compensation; + emit m_camera->exposureCompensationChanged(compensation); +} + +void QPlatformCamera::exposureCompensationRangeChanged(float min, float max) +{ + if (m_minExposureCompensation == min && m_maxExposureCompensation == max) + return; + m_minExposureCompensation = min; + m_maxExposureCompensation = max; + // tell frontend +} + +void QPlatformCamera::isoSensitivityChanged(int iso) +{ + if (m_iso == iso) + return; + m_iso = iso; + emit m_camera->isoSensitivityChanged(iso); +} + +void QPlatformCamera::shutterSpeedChanged(float speed) +{ + if (m_shutterSpeed == speed) + return; + m_shutterSpeed = speed; + emit m_camera->shutterSpeedChanged(speed); +} + + + QT_END_NAMESPACE #include "moc_qplatformcamera_p.cpp" diff --git a/src/multimedia/platform/qplatformcamera_p.h b/src/multimedia/platform/qplatformcamera_p.h index d5d3721f9..df9c0d4aa 100644 --- a/src/multimedia/platform/qplatformcamera_p.h +++ b/src/multimedia/platform/qplatformcamera_p.h @@ -90,6 +90,21 @@ public: // smaller 0: zoom instantly, rate in power-of-two/sec virtual void zoomTo(float /*newZoomFactor*/, float /*rate*/ = -1.) {} + virtual void setFlashMode(QCamera::FlashMode /*mode*/) {} + virtual bool isFlashModeSupported(QCamera::FlashMode mode) const { return mode == QCamera::FlashOff; } + virtual bool isFlashReady() const { return false; } + + virtual void setTorchMode(QCamera::TorchMode /*mode*/) {} + virtual bool isTorchModeSupported(QCamera::TorchMode mode) const { return mode == QCamera::TorchOff; } + + virtual void setExposureMode(QCamera::ExposureMode) {} + virtual bool isExposureModeSupported(QCamera::ExposureMode mode) const { return mode == QCamera::ExposureAuto; } + virtual void setExposureCompensation(float) {} + virtual int isoSensitivity() const { return 100; } + virtual void setManualIsoSensitivity(int) {} + virtual void setManualShutterSpeed(float) {} + virtual float shutterSpeed() const { return -1.; } + QCamera::FocusMode focusMode() const { return m_focusMode; } QPointF focusPoint() const { return m_customFocusPoint; } @@ -99,6 +114,18 @@ public: QPointF customFocusPoint() const { return m_customFocusPoint; } float focusDistance() const { return m_focusDistance; } + QCamera::FlashMode flashMode() const { return m_flashMode; } + QCamera::TorchMode torchMode() const { return m_torchMode; } + + QCamera::ExposureMode exposureMode() const { return m_exposureMode; } + float exposureCompensation() const { return m_exposureCompensation; } + int manualIsoSensitivity() const { return m_iso; } + int minIso() const { return m_minIso; } + int maxIso() const { return m_maxIso; } + float manualShutterSpeed() const { return m_shutterSpeed; } + float minShutterSpeed() const { return m_minShutterSpeed; } + float maxShutterSpeed() const { return m_maxShutterSpeed; } + void statusChanged(QCamera::Status); void minimumZoomFactorChanged(float factor); void maximumZoomFactorChanged(float); @@ -106,6 +133,18 @@ public: void customFocusPointChanged(const QPointF &point); void focusDistanceChanged(float d); void zoomFactorChanged(float zoom); + void flashReadyChanged(bool); + void flashModeChanged(QCamera::FlashMode mode); + void torchModeChanged(QCamera::TorchMode mode); + void exposureModeChanged(QCamera::ExposureMode mode); + void exposureCompensationChanged(float compensation); + void exposureCompensationRangeChanged(float min, float max); + void isoSensitivityChanged(int iso); + void minIsoChanged(int iso) { m_minIso = iso; } + void maxIsoChanged(int iso) { m_maxIso = iso; } + void shutterSpeedChanged(float speed); + void minShutterSpeedChanged(float secs) { m_minShutterSpeed = secs; } + void maxShutterSpeedChanged(float secs) { m_maxShutterSpeed = secs; } Q_SIGNALS: void activeChanged(bool); @@ -123,7 +162,20 @@ private: float m_maxZoom = 1.; float m_zoomFactor = 1.; float m_focusDistance = 1.; - QPointF m_customFocusPoint{.5, .5}; + QPointF m_customFocusPoint{-1, -1}; + bool m_flashReady = false; + QCamera::FlashMode m_flashMode = QCamera::FlashOff; + QCamera::TorchMode m_torchMode = QCamera::TorchOff; + QCamera::ExposureMode m_exposureMode = QCamera::ExposureAuto; + float m_exposureCompensation = 0.; + float m_minExposureCompensation = 0.; + float m_maxExposureCompensation = 0.; + int m_iso = -1; + int m_minIso = -1; + int m_maxIso = -1; + float m_shutterSpeed = -1.; + float m_minShutterSpeed = -1.; + float m_maxShutterSpeed = -1.; }; QT_END_NAMESPACE diff --git a/src/multimedia/platform/qplatformcameraexposure.cpp b/src/multimedia/platform/qplatformcameraexposure.cpp deleted file mode 100644 index ca9b9ea16..000000000 --- a/src/multimedia/platform/qplatformcameraexposure.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/**************************************************************************** -** -** 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 "qplatformcameraexposure_p.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QPlatformCameraExposure - \obsolete - - \brief The QPlatformCameraExposure class allows controlling camera exposure parameters. - - \inmodule QtMultimedia - - \ingroup multimedia_control - - The QCameraExposure class is the usual method of adjusting exposure related parameters - when using camera functionality. This class provides a more complete but less easy - to use interface, and also forms the interface to implement when writing a new - implementation of QCamera functionality. - - You can adjust a number of parameters that will affect images and video taken with - the corresponding QCamera object - see the \l {QPlatformCameraExposure::ExposureParameter}{ExposureParameter} enumeration. - - \sa QCameraExposure, QCamera -*/ - -/*! - Constructs a camera exposure control object with \a parent. -*/ -QPlatformCameraExposure::QPlatformCameraExposure(QObject *parent) - : QObject(parent) -{ -} - -/*! - \enum QPlatformCameraExposure::ExposureParameter - \value ISO - Camera ISO sensitivity, specified as integer value. - \value ShutterSpeed - Shutter speed in seconds, specified as qreal. - \value ExposureCompensation - Exposure compensation, specified as qreal EV value. - \value TorchPower - Manual torch power, specified as qreal value. - Accepted power range is [0..1.0], - with 0 value means no light and 1.0 corresponds to full torch power. - - This value is only used in the \l{QCamera::FlashVideolight}{torch flash mode}. - \value ExposureMode - Camera exposure mode. -*/ - -/*! - \fn QPlatformCameraExposure::isParameterSupported(ExposureParameter parameter) const - - Returns true is exposure \a parameter is supported by backend. - \since 5.0 -*/ - -/*! - \fn QPlatformCameraExposure::requestedValue(ExposureParameter parameter) const - - Returns the requested exposure \a parameter value. - - \since 5.0 -*/ - -/*! - \fn QPlatformCameraExposure::actualValue(ExposureParameter parameter) const - - Returns the actual exposure \a parameter value, or invalid QVariant() if the value is unknown or not supported. - - The actual parameter value may differ for the requested one if automatic mode is selected or - camera supports only limited set of values within the supported range. - \since 5.0 -*/ - - -/*! - \fn QPlatformCameraExposure::supportedParameterRange(ExposureParameter parameter, bool *continuous = 0) const - - Returns the list of supported \a parameter values; - - If the camera supports arbitrary exposure parameter value within the supported range, - *\a continuous is set to true, otherwise *\a continuous is set to false. - - \since 5.0 -*/ - -/*! - \fn bool QPlatformCameraExposure::setValue(ExposureParameter parameter, const QVariant& value) - - Set the exposure \a parameter to \a value. - If a null or invalid QVariant is passed, backend should choose the value automatically, - and if possible report the actual value to user with QPlatformCameraExposure::actualValue(). - - Returns true if parameter is supported and value is correct. - \since 5.0 -*/ - -/*! - \fn void QPlatformCameraExposure::requestedValueChanged(int parameter) - - Signal emitted when the requested exposure \a parameter value has changed, - usually in result of setValue() call. - \since 5.0 -*/ - -/*! - \fn void QPlatformCameraExposure::actualValueChanged(int parameter) - - Signal emitted when the actual exposure \a parameter value has changed, - usually in result of auto exposure algorithms or manual exposure parameter applied. - - \since 5.0 -*/ - -/*! - \fn void QPlatformCameraExposure::parameterRangeChanged(int parameter) - - Signal emitted when the supported range of exposure \a parameter values has changed. - - \since 5.0 -*/ - -QT_END_NAMESPACE - -#include "moc_qplatformcameraexposure_p.cpp" diff --git a/src/multimedia/platform/qplatformcameraexposure_p.h b/src/multimedia/platform/qplatformcameraexposure_p.h deleted file mode 100644 index 3cdc33754..000000000 --- a/src/multimedia/platform/qplatformcameraexposure_p.h +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** 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 QCAMERAEXPOSURECONTROL_H -#define QCAMERAEXPOSURECONTROL_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtCore/qobject.h> -#include <QtMultimedia/qtmultimediaglobal.h> - -#include <QtMultimedia/qcamera.h> -#include <QtMultimedia/qmediaenumdebug.h> - -QT_BEGIN_NAMESPACE - -// Required for QDoc workaround -class QString; - -class Q_MULTIMEDIA_EXPORT QPlatformCameraExposure : public QObject -{ - Q_OBJECT - Q_ENUMS(ExposureParameter) - -public: - enum ExposureParameter { - ISO, - ShutterSpeed, - ExposureCompensation, - TorchPower, - ExposureMode - }; - - virtual bool isParameterSupported(ExposureParameter parameter) const = 0; - virtual QVariantList supportedParameterRange(ExposureParameter parameter, bool *continuous) const = 0; - - virtual QVariant requestedValue(ExposureParameter parameter) const = 0; - virtual QVariant actualValue(ExposureParameter parameter) const = 0; - virtual bool setValue(ExposureParameter parameter, const QVariant& value) = 0; - - virtual QCamera::FlashMode flashMode() const = 0; - virtual void setFlashMode(QCamera::FlashMode mode) = 0; - virtual bool isFlashModeSupported(QCamera::FlashMode mode) const = 0; - - virtual QCamera::TorchMode torchMode() const { return QCamera::TorchOff; } - virtual void setTorchMode(QCamera::TorchMode /*mode*/) {} - virtual bool isTorchModeSupported(QCamera::TorchMode mode) const { return mode == QCamera::TorchOff; } - - virtual bool isFlashReady() const = 0; - -Q_SIGNALS: - void flashReady(bool); - void requestedValueChanged(int parameter); - void actualValueChanged(int parameter); - void parameterRangeChanged(int parameter); - -protected: - explicit QPlatformCameraExposure(QObject *parent = nullptr); -}; - -QT_END_NAMESPACE - -Q_MEDIA_ENUM_DEBUG(QPlatformCameraExposure, ExposureParameter) - - -#endif // QCAMERAEXPOSURECONTROL_H - diff --git a/src/multimedia/platform/windows/mediacapture/qwindowscamera.cpp b/src/multimedia/platform/windows/mediacapture/qwindowscamera.cpp index 6475dccf0..a6cd0e6cc 100644 --- a/src/multimedia/platform/windows/mediacapture/qwindowscamera.cpp +++ b/src/multimedia/platform/windows/mediacapture/qwindowscamera.cpp @@ -40,7 +40,6 @@ #include "qwindowscamera_p.h" #include "qwindowscamerasession_p.h" -#include "qwindowscameraexposure_p.h" #include "qwindowscameraimageprocessing_p.h" #include "qwindowsmediacapture_p.h" #include <qcamerainfo.h> @@ -122,13 +121,6 @@ void QWindowsCamera::setCaptureSession(QPlatformMediaCaptureSession *session) m_cameraSession->setActiveCamera(m_cameraInfo); } -QPlatformCameraExposure *QWindowsCamera::exposureControl() -{ - if (!m_cameraSession) - return nullptr; - return m_cameraSession->exposureControl(); -} - QPlatformCameraImageProcessing *QWindowsCamera::imageProcessingControl() { if (!m_cameraSession) diff --git a/src/multimedia/platform/windows/mediacapture/qwindowscamera_p.h b/src/multimedia/platform/windows/mediacapture/qwindowscamera_p.h index 29df07130..63b9ff84c 100644 --- a/src/multimedia/platform/windows/mediacapture/qwindowscamera_p.h +++ b/src/multimedia/platform/windows/mediacapture/qwindowscamera_p.h @@ -74,7 +74,6 @@ public: void setCaptureSession(QPlatformMediaCaptureSession *) override; - QPlatformCameraExposure *exposureControl() override; QPlatformCameraImageProcessing *imageProcessingControl() override; private Q_SLOTS: diff --git a/src/multimedia/platform/windows/mediacapture/qwindowscameraexposure.cpp b/src/multimedia/platform/windows/mediacapture/qwindowscameraexposure.cpp deleted file mode 100644 index e5ec4cf83..000000000 --- a/src/multimedia/platform/windows/mediacapture/qwindowscameraexposure.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2021 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 "qwindowscameraexposure_p.h" - -#include "qwindowscamerasession_p.h" - -QT_BEGIN_NAMESPACE - -QWindowsCameraExposure::QWindowsCameraExposure(QWindowsCameraSession *session) - : QPlatformCameraExposure() - , m_session(session) -{ - Q_ASSERT(m_session); -} - -bool QWindowsCameraExposure::isParameterSupported(ExposureParameter parameter) const -{ - return false; -} - -QVariantList QWindowsCameraExposure::supportedParameterRange(ExposureParameter parameter, bool *continuous) const -{ - return QVariantList(); -} - -QVariant QWindowsCameraExposure::requestedValue(ExposureParameter parameter) const -{ - return QVariant(); -} - -QVariant QWindowsCameraExposure::actualValue(ExposureParameter parameter) const -{ - return QVariant(); -} - -bool QWindowsCameraExposure::setValue(ExposureParameter parameter, const QVariant& value) -{ - if (!value.isValid()) - return false; - - return false; -} - -QCamera::FlashMode QWindowsCameraExposure::flashMode() const -{ - return QCamera::FlashOff; -} - -void QWindowsCameraExposure::setFlashMode(QCamera::FlashMode mode) -{ -} - -bool QWindowsCameraExposure::isFlashModeSupported(QCamera::FlashMode mode) const -{ - return false; -} - -bool QWindowsCameraExposure::isFlashReady() const -{ - return false; -} - -QCamera::TorchMode QWindowsCameraExposure::torchMode() const -{ - return QCamera::TorchOff; -} - -void QWindowsCameraExposure::setTorchMode(QCamera::TorchMode mode) -{ -} - -bool QWindowsCameraExposure::isTorchModeSupported(QCamera::TorchMode mode) const -{ - return false; -} - -QT_END_NAMESPACE diff --git a/src/multimedia/platform/windows/mediacapture/qwindowscameraexposure_p.h b/src/multimedia/platform/windows/mediacapture/qwindowscameraexposure_p.h deleted file mode 100644 index aa2b4c421..000000000 --- a/src/multimedia/platform/windows/mediacapture/qwindowscameraexposure_p.h +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2021 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 QWINDOWSCAMERAEXPOSURE_H -#define QWINDOWSCAMERAEXPOSURE_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <private/qplatformcameraexposure_p.h> - -QT_BEGIN_NAMESPACE - -class QWindowsCameraSession; - -class QWindowsCameraExposure : public QPlatformCameraExposure -{ - Q_OBJECT -public: - explicit QWindowsCameraExposure(QWindowsCameraSession *session); - - bool isParameterSupported(ExposureParameter parameter) const override; - QVariantList supportedParameterRange(ExposureParameter parameter, bool *continuous) const override; - - QVariant requestedValue(ExposureParameter parameter) const override; - QVariant actualValue(ExposureParameter parameter) const override; - bool setValue(ExposureParameter parameter, const QVariant& value) override; - - QCamera::FlashMode flashMode() const override; - void setFlashMode(QCamera::FlashMode mode) override; - bool isFlashModeSupported(QCamera::FlashMode mode) const override; - bool isFlashReady() const override; - - QCamera::TorchMode torchMode() const override; - void setTorchMode(QCamera::TorchMode mode) override; - bool isTorchModeSupported(QCamera::TorchMode mode) const override; - -private: - QWindowsCameraSession *m_session; -}; - -QT_END_NAMESPACE - -#endif // QWINDOWSCAMERAEXPOSURE_H diff --git a/src/multimedia/platform/windows/mediacapture/qwindowscamerasession.cpp b/src/multimedia/platform/windows/mediacapture/qwindowscamerasession.cpp index 87f8742a9..2177e6c5f 100644 --- a/src/multimedia/platform/windows/mediacapture/qwindowscamerasession.cpp +++ b/src/multimedia/platform/windows/mediacapture/qwindowscamerasession.cpp @@ -40,7 +40,6 @@ #include "qwindowscamerasession_p.h" #include "qwindowscamerareader_p.h" -#include "qwindowscameraexposure_p.h" #include "qwindowscameraimageprocessing_p.h" #include "qwindowsmultimediautils_p.h" #include <qvideosink.h> @@ -52,7 +51,6 @@ QWindowsCameraSession::QWindowsCameraSession(QObject *parent) : QObject(parent) { m_cameraReader = new QWindowsCameraReader(this); - m_cameraExposure = new QWindowsCameraExposure(this); m_cameraImageProcessing = new QWindowsCameraImageProcessing(this); connect(m_cameraReader, SIGNAL(streamingStarted()), this, SLOT(handleStreamingStarted())); connect(m_cameraReader, SIGNAL(streamingStopped()), this, SLOT(handleStreamingStopped())); @@ -64,7 +62,6 @@ QWindowsCameraSession::QWindowsCameraSession(QObject *parent) QWindowsCameraSession::~QWindowsCameraSession() { delete m_cameraImageProcessing; - delete m_cameraExposure; delete m_cameraReader; } @@ -127,11 +124,6 @@ void QWindowsCameraSession::setVideoSink(QVideoSink *surface) m_cameraReader->setSurface(surface); } -QWindowsCameraExposure *QWindowsCameraSession::exposureControl() -{ - return m_cameraExposure; -} - QWindowsCameraImageProcessing *QWindowsCameraSession::imageProcessingControl() { return m_cameraImageProcessing; diff --git a/src/multimedia/platform/windows/mediacapture/qwindowscamerasession_p.h b/src/multimedia/platform/windows/mediacapture/qwindowscamerasession_p.h index 893036dd8..ca4e31cd2 100644 --- a/src/multimedia/platform/windows/mediacapture/qwindowscamerasession_p.h +++ b/src/multimedia/platform/windows/mediacapture/qwindowscamerasession_p.h @@ -60,7 +60,6 @@ QT_BEGIN_NAMESPACE class QVideoSink; class QWindowsCameraReader; -class QWindowsCameraExposure; class QWindowsCameraImageProcessing; class QWindowsCameraSession : public QObject @@ -85,7 +84,6 @@ public: void setVideoSink(QVideoSink *surface); - QWindowsCameraExposure *exposureControl(); QWindowsCameraImageProcessing *imageProcessingControl(); QMediaEncoderSettings videoSettings() const; @@ -114,7 +112,6 @@ private: bool m_readyForCapture = false; QCameraInfo m_activeCameraInfo; QWindowsCameraReader *m_cameraReader = nullptr; - QWindowsCameraExposure *m_cameraExposure = nullptr; QWindowsCameraImageProcessing *m_cameraImageProcessing = nullptr; QImageEncoderSettings m_imageEncoderSettings; QMediaEncoderSettings m_mediaEncoderSettings; diff --git a/tests/auto/integration/qcamerabackend/tst_qcamerabackend.cpp b/tests/auto/integration/qcamerabackend/tst_qcamerabackend.cpp index b13bfe3a4..3d1b970b5 100644 --- a/tests/auto/integration/qcamerabackend/tst_qcamerabackend.cpp +++ b/tests/auto/integration/qcamerabackend/tst_qcamerabackend.cpp @@ -33,7 +33,6 @@ #include <QDebug> #include <private/qplatformcamera_p.h> -#include <private/qplatformcameraexposure_p.h> #include <private/qplatformcameraimagecapture_p.h> #include <private/qplatformcameraimageprocessing_p.h> #include <qcamera.h> diff --git a/tests/auto/unit/mockbackend/CMakeLists.txt b/tests/auto/unit/mockbackend/CMakeLists.txt index 8def1a078..0c471e7f1 100644 --- a/tests/auto/unit/mockbackend/CMakeLists.txt +++ b/tests/auto/unit/mockbackend/CMakeLists.txt @@ -15,7 +15,6 @@ target_link_libraries(QtMultimediaMockBackend INTERFACE target_sources(QtMultimediaMockBackend INTERFACE qmockaudiodecoder.h qmockcamera.h - qmockcameraexposure.h qmockcameraimageprocessing.h qmockimagecapture.h qmockimagecapture.cpp qmockmediaplayer.h diff --git a/tests/auto/unit/mockbackend/qmockcamera.h b/tests/auto/unit/mockbackend/qmockcamera.h index 9a8a6549f..5ccf79e2f 100644 --- a/tests/auto/unit/mockbackend/qmockcamera.h +++ b/tests/auto/unit/mockbackend/qmockcamera.h @@ -32,7 +32,6 @@ #include "private/qplatformcamera_p.h" #include "qcamerainfo.h" #include "qmockcameraimageprocessing.h" -#include "qmockcameraexposure.h" #include <qtimer.h> class QMockCamera : public QPlatformCamera @@ -54,8 +53,14 @@ public: m_propertyChangesSupported(false) { if (!simpleCamera) { - mockExposure = new QMockCameraExposure(this); mockImageProcessing = new QMockCameraImageProcessing(this); + minIsoChanged(100); + maxIsoChanged(800); + minShutterSpeedChanged(.001); + maxShutterSpeedChanged(1); + exposureCompensationRangeChanged(-2, 2); + maximumZoomFactorChanged(4.); + setFlashMode(QCamera::FlashAuto); } } @@ -90,17 +95,75 @@ public: m_camera = camera; } - void setFocusMode(QCamera::FocusMode mode) override { focusModeChanged(mode); } - bool isFocusModeSupported(QCamera::FocusMode /*mode*/) const override { return true; } + void setFocusMode(QCamera::FocusMode mode) override + { + if (isFocusModeSupported(mode)) + focusModeChanged(mode); + } + bool isFocusModeSupported(QCamera::FocusMode mode) const override + { return simpleCamera ? mode == QCamera::FocusModeAuto : mode != QCamera::FocusModeInfinity; } - bool isCustomFocusPointSupported() const override { return true; } - void setCustomFocusPoint(const QPointF &point) override { customFocusPointChanged(point); } + bool isCustomFocusPointSupported() const override { return !simpleCamera; } + void setCustomFocusPoint(const QPointF &point) override + { + if (!simpleCamera) + customFocusPointChanged(point); + } - void setFocusDistance(float d) override { focusDistanceChanged(d); } + void setFocusDistance(float d) override + { + if (!simpleCamera) + focusDistanceChanged(d); + } void zoomTo(float newZoomFactor, float /*rate*/) override { zoomFactorChanged(newZoomFactor); } - QPlatformCameraExposure *exposureControl() override { return mockExposure; } + void setFlashMode(QCamera::FlashMode mode) override + { + if (!simpleCamera) + flashModeChanged(mode); + flashReadyChanged(mode != QCamera::FlashOff); + } + bool isFlashModeSupported(QCamera::FlashMode mode) const override { return simpleCamera ? mode == QCamera::FlashOff : true; } + bool isFlashReady() const override { return flashMode() != QCamera::FlashOff; } + + void setExposureMode(QCamera::ExposureMode mode) override + { + if (!simpleCamera && isExposureModeSupported(mode)) + exposureModeChanged(mode); + } + bool isExposureModeSupported(QCamera::ExposureMode mode) const override + { + return simpleCamera ? mode == QCamera::ExposureAuto : mode <= QCamera::ExposureBeach; + } + void setExposureCompensation(float c) override + { + if (!simpleCamera) + exposureCompensationChanged(qBound(-2., c, 2.)); + } + int isoSensitivity() const override + { + if (simpleCamera) + return -1; + return manualIsoSensitivity() > 0 ? manualIsoSensitivity() : 100; + } + void setManualIsoSensitivity(int iso) override + { + if (!simpleCamera) + isoSensitivityChanged(qBound(100, iso, 800)); + } + void setManualShutterSpeed(float secs) override + { + if (!simpleCamera) + shutterSpeedChanged(qBound(0.001, secs, 1.)); + } + float shutterSpeed() const override + { + if (simpleCamera) + return -1.; + return manualShutterSpeed() > 0 ? manualShutterSpeed() : .05; + } + QPlatformCameraImageProcessing *imageProcessingControl() override { return mockImageProcessing; } bool m_active = false; @@ -108,7 +171,6 @@ public: QCameraInfo m_camera; bool m_propertyChangesSupported; - QMockCameraExposure *mockExposure = nullptr; QMockCameraImageProcessing *mockImageProcessing = nullptr; }; diff --git a/tests/auto/unit/mockbackend/qmockcameraexposure.h b/tests/auto/unit/mockbackend/qmockcameraexposure.h deleted file mode 100644 index 61d5104b1..000000000 --- a/tests/auto/unit/mockbackend/qmockcameraexposure.h +++ /dev/null @@ -1,238 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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 General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** 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-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef MOCKCAMERAEXPOSURECONTROL_H -#define MOCKCAMERAEXPOSURECONTROL_H - -#include "private/qplatformcameraexposure_p.h" - -class QMockCameraExposure : public QPlatformCameraExposure -{ - Q_OBJECT -public: - QMockCameraExposure(QObject *parent = 0): - QPlatformCameraExposure(parent), - m_shutterSpeed(0.01), - m_isoSensitivity(100), - m_exposureCompensation(0), - m_exposureMode(QCamera::ExposureAuto), - m_flashMode(QCamera::FlashAuto) - { - m_isoRanges << 100 << 200 << 400 << 800; - m_shutterRanges << 0.001 << 0.01 << 0.1 << 1.0; - m_exposureRanges << -2.0 << 2.0; - - const QCamera::ExposureMode exposureModes[] = { - QCamera::ExposureAuto, - QCamera::ExposureManual, - QCamera::ExposureNight, - QCamera::ExposureSports, - QCamera::ExposureSnow, - QCamera::ExposurePortrait, - QCamera::ExposureBeach - }; - - for (QCamera::ExposureMode mode : exposureModes) - m_exposureModes << QVariant::fromValue<QCamera::ExposureMode>(mode); - } - - ~QMockCameraExposure() {} - - bool isParameterSupported(ExposureParameter parameter) const - { - switch (parameter) { - case QPlatformCameraExposure::ExposureMode: - case QPlatformCameraExposure::ExposureCompensation: - case QPlatformCameraExposure::ISO: - case QPlatformCameraExposure::ShutterSpeed: - return true; - default: - return false; - } - } - - QVariant requestedValue(ExposureParameter param) const - { - return m_requestedParameters.value(param); - } - - QVariant actualValue(ExposureParameter param) const - { - switch (param) { - case QPlatformCameraExposure::ExposureMode: - return QVariant::fromValue<QCamera::ExposureMode>(m_exposureMode); - case QPlatformCameraExposure::ExposureCompensation: - return QVariant(m_exposureCompensation); - case QPlatformCameraExposure::ISO: - return QVariant(m_isoSensitivity); - case QPlatformCameraExposure::ShutterSpeed: - return QVariant(m_shutterSpeed); - default: - return QVariant(); - } - } - - QVariantList supportedParameterRange(ExposureParameter parameter, bool *continuous) const - { - *continuous = false; - - QVariantList res; - switch (parameter) { - case QPlatformCameraExposure::ExposureCompensation: - *continuous = true; - return m_exposureRanges; - case QPlatformCameraExposure::ISO: - return m_isoRanges; - case QPlatformCameraExposure::ShutterSpeed: - *continuous = true; - return m_shutterRanges; - case QPlatformCameraExposure::ExposureMode: - return m_exposureModes; - default: - break; - } - - return res; - } - - // Added valueChanged and parameterRangeChanged signal - bool setValue(ExposureParameter param, const QVariant& value) - { - if (!isParameterSupported(param)) - return false; - - if (m_requestedParameters.value(param) != value) { - m_requestedParameters.insert(param, value); - emit requestedValueChanged(param); - } - - switch (param) { - case QPlatformCameraExposure::ExposureMode: - { - QCamera::ExposureMode mode = value.value<QCamera::ExposureMode>(); - if (mode != m_exposureMode && m_exposureModes.contains(value)) { - m_exposureMode = mode; - emit actualValueChanged(param); - } - } - break; - case QPlatformCameraExposure::ExposureCompensation: - { - m_res.clear(); - m_res << -4.0 << 4.0; - qreal exposureCompensationlocal = qBound<qreal>(-2.0, value.toReal(), 2.0); - if (actualValue(param).toReal() != exposureCompensationlocal) { - m_exposureCompensation = exposureCompensationlocal; - emit actualValueChanged(param); - } - - if (m_exposureRanges.last().toReal() != m_res.last().toReal()) { - m_exposureRanges.clear(); - m_exposureRanges = m_res; - emit parameterRangeChanged(param); - } - } - break; - case QPlatformCameraExposure::ISO: - { - m_res.clear(); - m_res << 20 << 50; - qreal exposureCompensationlocal = 100*qRound(qBound(100, value.toInt(), 800)/100.0); - if (actualValue(param).toReal() != exposureCompensationlocal) { - m_isoSensitivity = exposureCompensationlocal; - emit actualValueChanged(param); - } - - if (m_isoRanges.last().toInt() != m_res.last().toInt()) { - m_isoRanges.clear(); - m_isoRanges = m_res; - emit parameterRangeChanged(param); - } - } - break; - case QPlatformCameraExposure::ShutterSpeed: - { - m_res.clear(); - m_res << 0.12 << 1.0 << 2.0; - qreal exposureCompensationlocal = qBound<qreal>(0.001, value.toReal(), 1.0); - if (actualValue(param).toReal() != exposureCompensationlocal) { - m_shutterSpeed = exposureCompensationlocal; - emit actualValueChanged(param); - } - - if (m_shutterRanges.last().toReal() != m_res.last().toReal()) { - m_shutterRanges.clear(); - m_shutterRanges = m_res; - emit parameterRangeChanged(param); - } - } - break; - - default: - return false; - } - - return true; - } - - QCamera::FlashMode flashMode() const - { - return m_flashMode; - } - - void setFlashMode(QCamera::FlashMode mode) - { - if (isFlashModeSupported(mode)) { - m_flashMode = mode; - } - emit flashReady(true); - } - //Setting the values for Flash mode - - bool isFlashModeSupported(QCamera::FlashMode /*mode*/) const - { - return true; - } - - bool isFlashReady() const - { - return true; - } - -private: - qreal m_shutterSpeed; - int m_isoSensitivity; - qreal m_exposureCompensation; - QCamera::ExposureMode m_exposureMode; - QCamera::FlashMode m_flashMode; - QVariantList m_isoRanges, m_shutterRanges, m_exposureRanges, m_res, m_exposureModes; - - QMap<QPlatformCameraExposure::ExposureParameter, QVariant> m_requestedParameters; -}; - -#endif // MOCKCAMERAEXPOSURECONTROL_H diff --git a/tests/auto/unit/multimedia/qcamera/tst_qcamera.cpp b/tests/auto/unit/multimedia/qcamera/tst_qcamera.cpp index 6f5c584c5..290ed8d1f 100644 --- a/tests/auto/unit/multimedia/qcamera/tst_qcamera.cpp +++ b/tests/auto/unit/multimedia/qcamera/tst_qcamera.cpp @@ -33,7 +33,6 @@ #include <qvideosink.h> #include <private/qplatformcamera_p.h> -#include <private/qplatformcameraexposure_p.h> #include <private/qplatformcameraimagecapture_p.h> #include <private/qplatformcameraimageprocessing_p.h> #include <qcamera.h> @@ -154,7 +153,8 @@ void tst_QCamera::testSimpleCameraExposure() QMockCamera::Simple simple; QCamera camera; - QVERIFY(!camera.isExposureModeSupported(QCamera::ExposureAuto)); + QVERIFY(camera.isExposureModeSupported(QCamera::ExposureAuto)); + QVERIFY(!camera.isExposureModeSupported(QCamera::ExposureManual)); QCOMPARE(camera.exposureMode(), QCamera::ExposureAuto); camera.setExposureMode(QCamera::ExposureManual);//should be ignored QCOMPARE(camera.exposureMode(), QCamera::ExposureAuto); @@ -170,14 +170,16 @@ void tst_QCamera::testSimpleCameraExposure() QCOMPARE(camera.exposureCompensation(), 0.0); QCOMPARE(camera.isoSensitivity(), -1); - QVERIFY(camera.supportedIsoSensitivities().isEmpty()); + QCOMPARE(camera.minimumIsoSensitivity(), -1); + QCOMPARE(camera.maximumIsoSensitivity(), -1); camera.setManualIsoSensitivity(100); QCOMPARE(camera.isoSensitivity(), -1); camera.setAutoIsoSensitivity(); QCOMPARE(camera.isoSensitivity(), -1); QVERIFY(camera.shutterSpeed() < 0); - QVERIFY(camera.supportedShutterSpeeds().isEmpty()); + QCOMPARE(camera.minimumShutterSpeed(), -1.); + QCOMPARE(camera.maximumShutterSpeed(), -1.); camera.setAutoShutterSpeed(); QVERIFY(camera.shutterSpeed() < 0); camera.setManualShutterSpeed(1/128.0); @@ -190,11 +192,11 @@ void tst_QCamera::testSimpleCameraFocus() QCamera camera; - QVERIFY(!camera.isFocusModeSupported(QCamera::FocusModeAuto)); + QVERIFY(camera.isFocusModeSupported(QCamera::FocusModeAuto)); QVERIFY(!camera.isFocusModeSupported(QCamera::FocusModeInfinity)); QCOMPARE(camera.focusMode(), QCamera::FocusModeAuto); - camera.setFocusMode(QCamera::FocusModeAuto); + camera.setFocusMode(QCamera::FocusModeInfinity); QCOMPARE(camera.focusMode(), QCamera::FocusModeAuto); QCOMPARE(camera.maximumZoomFactor(), 1.0); @@ -206,7 +208,7 @@ void tst_QCamera::testSimpleCameraFocus() QCOMPARE(camera.customFocusPoint(), QPointF(-1., -1.)); camera.setCustomFocusPoint(QPointF(1.0, 1.0)); - QCOMPARE(camera.customFocusPoint(), QPointF(-1, -1)); + QCOMPARE(camera.customFocusPoint(), QPointF(-1., -1.)); } void tst_QCamera::testSimpleCameraCapture() @@ -370,28 +372,24 @@ void tst_QCamera::testCameraExposure() camera.setExposureCompensation(2.0); QCOMPARE(camera.exposureCompensation(), 2.0); - int minIso = camera.supportedIsoSensitivities().first(); - int maxIso = camera.supportedIsoSensitivities().last(); - QVERIFY(camera.isoSensitivity() > 0); - QCOMPARE(camera.requestedIsoSensitivity(), -1); + int minIso = camera.minimumIsoSensitivity(); + int maxIso = camera.maximumIsoSensitivity(); + QCOMPARE(camera.isoSensitivity(), 100); QVERIFY(minIso > 0); QVERIFY(maxIso > 0); camera.setManualIsoSensitivity(minIso); QCOMPARE(camera.isoSensitivity(), minIso); camera.setManualIsoSensitivity(maxIso*10); QCOMPARE(camera.isoSensitivity(), maxIso); - QCOMPARE(camera.requestedIsoSensitivity(), maxIso*10); camera.setManualIsoSensitivity(-10); QCOMPARE(camera.isoSensitivity(), minIso); - QCOMPARE(camera.requestedIsoSensitivity(), -10); camera.setAutoIsoSensitivity(); QCOMPARE(camera.isoSensitivity(), 100); - QCOMPARE(camera.requestedIsoSensitivity(), -1); - QCOMPARE(camera.requestedShutterSpeed(), -1.0); - qreal minShutterSpeed = camera.supportedShutterSpeeds().first(); - qreal maxShutterSpeed = camera.supportedShutterSpeeds().last(); + qreal minShutterSpeed = camera.minimumShutterSpeed(); + qreal maxShutterSpeed = camera.maximumShutterSpeed(); + qDebug() << minShutterSpeed << maxShutterSpeed; QVERIFY(minShutterSpeed > 0); QVERIFY(maxShutterSpeed > 0); QVERIFY(camera.shutterSpeed() >= minShutterSpeed); @@ -400,18 +398,14 @@ void tst_QCamera::testCameraExposure() camera.setAutoShutterSpeed(); QVERIFY(camera.shutterSpeed() >= minShutterSpeed); QVERIFY(camera.shutterSpeed() <= maxShutterSpeed); - QCOMPARE(camera.requestedShutterSpeed(), -1.0); camera.setManualShutterSpeed(0); QCOMPARE(camera.shutterSpeed(), minShutterSpeed); - QCOMPARE(camera.requestedShutterSpeed()+1.0, 1.0); camera.setManualShutterSpeed(10000); QCOMPARE(camera.shutterSpeed(), maxShutterSpeed); - QCOMPARE(camera.requestedShutterSpeed(), 10000.0); camera.setAutoShutterSpeed(); - QCOMPARE(camera.requestedShutterSpeed(), -1.0); } void tst_QCamera::testCameraFocus() @@ -424,7 +418,9 @@ void tst_QCamera::testCameraFocus() QCOMPARE(camera.focusMode(), QCamera::FocusModeAuto); camera.setFocusMode(QCamera::FocusModeManual); - QCOMPARE(camera.focusMode(), QCamera::FocusModeAuto); + QCOMPARE(camera.focusMode(), QCamera::FocusModeManual); + camera.setFocusMode(QCamera::FocusModeInfinity); + QCOMPARE(camera.focusMode(), QCamera::FocusModeManual); camera.setFocusMode(QCamera::FocusModeAuto); QCOMPARE(camera.focusMode(), QCamera::FocusModeAuto); @@ -844,15 +840,14 @@ void tst_QCamera::testFocusMode() QCamera camera; session.setCamera(&camera); - QVERIFY(!camera.isFocusModeSupported(QCamera::FocusModeHyperfocal)); - QVERIFY(!camera.isFocusModeSupported(QCamera::FocusModeAutoNear)); + QVERIFY(!camera.isFocusModeSupported(QCamera::FocusModeInfinity)); + QVERIFY(camera.isFocusModeSupported(QCamera::FocusModeAutoNear)); QCOMPARE(camera.focusMode(), QCamera::FocusModeAuto); - camera.setFocusMode(QCamera::FocusModeHyperfocal); - QVERIFY(camera.focusMode()!= QCamera::FocusModeHyperfocal); + camera.setFocusMode(QCamera::FocusModeInfinity); + QVERIFY(camera.focusMode() != QCamera::FocusModeInfinity); QCOMPARE(camera.focusMode(), QCamera::FocusModeAuto); camera.setFocusMode(QCamera::FocusModeAutoNear); - QVERIFY(camera.focusMode()!= QCamera::FocusModeAutoNear); - QCOMPARE(camera.focusMode(), QCamera::FocusModeAuto); + QVERIFY(camera.focusMode() == QCamera::FocusModeAutoNear); } void tst_QCamera::testZoomChanged() @@ -934,7 +929,6 @@ void tst_QCamera::testSignalShutterSpeedChanged() session.setCamera(&camera); QSignalSpy spySignalShutterSpeedChanged(&camera, SIGNAL(shutterSpeedChanged(qreal))); - QSignalSpy spySignalShutterSpeedRangeChanged(&camera, SIGNAL(shutterSpeedRangeChanged())); QVERIFY(spySignalShutterSpeedChanged.count() ==0); @@ -942,7 +936,6 @@ void tst_QCamera::testSignalShutterSpeedChanged() QTest::qWait(100); QVERIFY(spySignalShutterSpeedChanged.count() ==1); - QVERIFY(spySignalShutterSpeedRangeChanged.count() ==1); } void tst_QCamera::testSignalFlashReady() @@ -953,15 +946,15 @@ void tst_QCamera::testSignalFlashReady() QSignalSpy spyflashReady(&camera,SIGNAL(flashReady(bool))); - QVERIFY(spyflashReady.count() ==0); + QVERIFY(spyflashReady.count() == 0); - QVERIFY(camera.flashMode() ==QCamera::FlashAuto); + QVERIFY(camera.flashMode() == QCamera::FlashAuto); camera.setFlashMode(QCamera::FlashOff);//set theFlashMode to QCamera::FlashOff - QVERIFY(camera.flashMode() ==QCamera::FlashOff); + QVERIFY(camera.flashMode() == QCamera::FlashOff); - QVERIFY(spyflashReady.count() ==1); + QCOMPARE(spyflashReady.count(), 1); } QTEST_MAIN(tst_QCamera) diff --git a/tests/auto/unit/multimedia/qcameraimagecapture/tst_qcameraimagecapture.cpp b/tests/auto/unit/multimedia/qcameraimagecapture/tst_qcameraimagecapture.cpp index 78c1d4c99..2b11636c0 100644 --- a/tests/auto/unit/multimedia/qcameraimagecapture/tst_qcameraimagecapture.cpp +++ b/tests/auto/unit/multimedia/qcameraimagecapture/tst_qcameraimagecapture.cpp @@ -30,7 +30,6 @@ #include <QDebug> #include <private/qplatformcamera_p.h> -#include <private/qplatformcameraexposure_p.h> #include <private/qplatformcameraimagecapture_p.h> #include <private/qplatformcameraimageprocessing_p.h> #include <qcamera.h> diff --git a/tests/auto/unit/multimediawidgets/qcamerawidgets/tst_qcamerawidgets.cpp b/tests/auto/unit/multimediawidgets/qcamerawidgets/tst_qcamerawidgets.cpp index 235294779..00cfc1646 100644 --- a/tests/auto/unit/multimediawidgets/qcamerawidgets/tst_qcamerawidgets.cpp +++ b/tests/auto/unit/multimediawidgets/qcamerawidgets/tst_qcamerawidgets.cpp @@ -32,7 +32,6 @@ #include <QDebug> #include <private/qplatformcamera_p.h> -#include <private/qplatformcameraexposure_p.h> #include <private/qplatformcameraimagecapture_p.h> #include <private/qplatformcameraimageprocessing_p.h> #include <qmediacapturesession.h> |