diff options
38 files changed, 536 insertions, 1690 deletions
diff --git a/src/imports/multimedia/qmldir b/src/imports/multimedia/qmldir index 028587088..387cb3c14 100644 --- a/src/imports/multimedia/qmldir +++ b/src/imports/multimedia/qmldir @@ -4,3 +4,4 @@ classname QMultimediaDeclarativeModule typeinfo plugins.qmltypes prefer :/qt-project.org/imports/QtMultimedia/ Video 5.0 Video.qml + diff --git a/src/multimedia/CMakeLists.txt b/src/multimedia/CMakeLists.txt index 7994ed945..98577b8e0 100644 --- a/src/multimedia/CMakeLists.txt +++ b/src/multimedia/CMakeLists.txt @@ -32,7 +32,6 @@ qt_internal_add_module(Multimedia platform/qplatformaudiodecoder.cpp platform/qplatformaudiodecoder_p.h platform/qplatformcamera.cpp platform/qplatformcamera_p.h platform/qplatformcameraimagecapture.cpp platform/qplatformcameraimagecapture_p.h - platform/qplatformcameraimageprocessing.cpp platform/qplatformcameraimageprocessing_p.h platform/qplatformmediacapture.cpp platform/qplatformmediacapture_p.h platform/qplatformmediadevices.cpp platform/qplatformmediadevices_p.h platform/qplatformmediaencoder.cpp platform/qplatformmediaencoder_p.h @@ -154,8 +153,6 @@ qt_internal_extend_target(Multimedia CONDITION WIN32 platform/windows/mediacapture/qwindowscamera.cpp platform/windows/mediacapture/qwindowscameraimagecapture.cpp platform/windows/mediacapture/qwindowscameraimagecapture_p.h - platform/windows/mediacapture/qwindowscameraimageprocessing.cpp - platform/windows/mediacapture/qwindowscameraimageprocessing_p.h platform/windows/mediacapture/qwindowscamerareader.cpp platform/windows/mediacapture/qwindowscamerareader_p.h platform/windows/mediacapture/qwindowscamerasession.cpp @@ -228,7 +225,6 @@ qt_internal_extend_target(Multimedia CONDITION QT_FEATURE_gstreamer platform/gstreamer/qgstreamerformatinfo.cpp platform/gstreamer/qgstreamerformatinfo_p.h 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/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 @@ -308,7 +304,6 @@ qt_internal_extend_target(Multimedia CONDITION ANDROID 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/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 platform/android/mediacapture/qandroidcameravideorenderercontrol.cpp platform/android/mediacapture/qandroidcameravideorenderercontrol_p.h platform/android/mediacapture/qandroidcaptureservice.cpp platform/android/mediacapture/qandroidcaptureservice_p.h @@ -399,7 +394,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/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 platform/darwin/camera/avfcamerasession.mm platform/darwin/camera/avfcamerasession_p.h diff --git a/src/multimedia/camera/qcamera.cpp b/src/multimedia/camera/qcamera.cpp index 000c591b6..116f8985e 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/qplatformcameraimageprocessing_p.h> #include <private/qplatformcameraimagecapture_p.h> #include <private/qplatformmediaintegration_p.h> #include <private/qplatformmediacapture_p.h> @@ -125,8 +124,6 @@ void QCameraPrivate::init() control->setCamera(cameraInfo); q->connect(control, SIGNAL(activeChanged(bool)), q, SIGNAL(activeChanged(bool))); q->connect(control, SIGNAL(error(int,QString)), q, SLOT(_q_error(int,QString))); - - imageControl = control->imageProcessingControl(); } /*! @@ -964,7 +961,7 @@ void QCamera::setAutoShutterSpeed() QCamera::WhiteBalanceMode QCamera::whiteBalanceMode() const { Q_D(const QCamera); - return d->whiteBalance; + return d->control ? d->control->whiteBalanceMode() : QCamera::WhiteBalanceAuto; } /*! @@ -974,14 +971,13 @@ QCamera::WhiteBalanceMode QCamera::whiteBalanceMode() const void QCamera::setWhiteBalanceMode(QCamera::WhiteBalanceMode mode) { Q_D(QCamera); - if (d->whiteBalance == mode || !isWhiteBalanceModeSupported(mode)) + if (!d->control) return; - - d->imageControl->setParameter( - QPlatformCameraImageProcessing::WhiteBalancePreset, - QVariant::fromValue<QCamera::WhiteBalanceMode>(mode)); - d->whiteBalance = mode; - emit whiteBalanceModeChanged(); + if (!d->control->isWhiteBalanceModeSupported(mode)) + return; + d->control->setWhiteBalanceMode(mode); + if (mode == QCamera::WhiteBalanceManual) + d->control->setColorTemperature(5600); } /*! @@ -991,12 +987,9 @@ void QCamera::setWhiteBalanceMode(QCamera::WhiteBalanceMode mode) bool QCamera::isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const { Q_D(const QCamera); - if (!d->imageControl) + if (!d->control) return false; - return d->imageControl->isParameterValueSupported( - QPlatformCameraImageProcessing::WhiteBalancePreset, - QVariant::fromValue<QCamera::WhiteBalanceMode>(mode)); - + return d->control->isWhiteBalanceModeSupported(mode); } /*! @@ -1005,36 +998,37 @@ bool QCamera::isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const return value is undefined. */ -qreal QCamera::manualWhiteBalance() const +int QCamera::colorTemperature() const { Q_D(const QCamera); - return d->colorTemperature; + return d->control ? d->control->colorTemperature() : 0; } /*! Sets manual white balance to \a colorTemperature. This is used when whiteBalanceMode() is set to \c WhiteBalanceManual. The units are Kelvin. + + Setting a color temperature will only have an effect if WhiteBalanceManual is + supported. In this case, setting a temperature greater 0 will automatically set the + white balance mode to WhiteBalanceManual. Setting the temperature to 0 will reset + the white balance mode to WhiteBalanceAuto. */ -void QCamera::setManualWhiteBalance(qreal colorTemperature) +void QCamera::setColorTemperature(int colorTemperature) { Q_D(QCamera); - if (!d->imageControl) - return; - if (d->colorTemperature == colorTemperature) + if (!d->control) return; + if (colorTemperature < 0) + colorTemperature = 0; if (colorTemperature == 0) { - setWhiteBalanceMode(WhiteBalanceAuto); + d->control->setWhiteBalanceMode(WhiteBalanceAuto); } else if (!isWhiteBalanceModeSupported(WhiteBalanceManual)) { return; } else { - setWhiteBalanceMode(WhiteBalanceManual); - d->imageControl->setParameter( - QPlatformCameraImageProcessing::ColorTemperature, - QVariant(colorTemperature)); + d->control->setWhiteBalanceMode(WhiteBalanceManual); } - d->colorTemperature = colorTemperature; - emit manualWhiteBalanceChanged(); + d->control->setColorTemperature(colorTemperature); } /*! @@ -1042,7 +1036,7 @@ void QCamera::setManualWhiteBalance(qreal colorTemperature) \value WhiteBalanceAuto Auto white balance mode. \value WhiteBalanceManual Manual white balance. In this mode the white balance should be set with - setManualWhiteBalance() + setColorTemperature() \value WhiteBalanceSunlight Sunlight white balance mode. \value WhiteBalanceCloudy Cloudy white balance mode. \value WhiteBalanceShade Shade white balance mode. diff --git a/src/multimedia/camera/qcamera.h b/src/multimedia/camera/qcamera.h index 7cbab533c..b84e90c36 100644 --- a/src/multimedia/camera/qcamera.h +++ b/src/multimedia/camera/qcamera.h @@ -86,7 +86,7 @@ class Q_MULTIMEDIA_EXPORT QCamera : public QObject 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) + Q_PROPERTY(int colorTemperature READ colorTemperature WRITE setColorTemperature NOTIFY colorTemperatureChanged) Q_ENUMS(Status) Q_ENUMS(Error) @@ -232,7 +232,7 @@ public: WhiteBalanceMode whiteBalanceMode() const; Q_INVOKABLE bool isWhiteBalanceModeSupported(WhiteBalanceMode mode) const; - qreal manualWhiteBalance() const; + int colorTemperature() const; public Q_SLOTS: void setActive(bool active); @@ -254,7 +254,7 @@ public Q_SLOTS: void setAutoShutterSpeed(); void setWhiteBalanceMode(WhiteBalanceMode mode); - void setManualWhiteBalance(qreal colorTemperature); + void setColorTemperature(int colorTemperature); Q_SIGNALS: void activeChanged(bool); @@ -281,7 +281,7 @@ Q_SIGNALS: void exposureModeChanged(); void whiteBalanceModeChanged() const; - void manualWhiteBalanceChanged() const; + void colorTemperatureChanged() const; void brightnessChanged(); void contrastChanged(); diff --git a/src/multimedia/camera/qcamera_p.h b/src/multimedia/camera/qcamera_p.h index eae660049..f0ace5bab 100644 --- a/src/multimedia/camera/qcamera_p.h +++ b/src/multimedia/camera/qcamera_p.h @@ -58,7 +58,6 @@ QT_BEGIN_NAMESPACE class QPlatformCamera; -class QPlatformCameraImageProcessing; class QPlatformMediaCaptureSession; class QCameraPrivate : public QObjectPrivate @@ -83,11 +82,6 @@ public: QCameraInfo cameraInfo; QCameraFormat cameraFormat; - QPlatformCameraImageProcessing *imageControl = nullptr; - - QCamera::WhiteBalanceMode whiteBalance = QCamera::WhiteBalanceAuto; - qreal colorTemperature = 0; - 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 4e8414381..e355fcd0b 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 "qandroidcameraimageprocessingcontrol_p.h" #include "qandroidcameravideorenderercontrol_p.h" #include "qandroidcaptureservice_p.h" #include <qmediadevices.h> @@ -118,12 +117,6 @@ void QAndroidCameraControl::setCaptureSession(QPlatformMediaCaptureSession *sess } -QPlatformCameraImageProcessing *QAndroidCameraControl::imageProcessingControl() -{ - return m_cameraSession->imageProcessingControl(); -} - - void QAndroidCameraControl::setFocusMode(QCamera::FocusMode mode) { if (!m_cameraSession->camera()) @@ -286,6 +279,38 @@ void QAndroidCameraControl::onCameraOpened() } setFlashMode(flashMode()); + + m_supportedWhiteBalanceModes.clear(); + QStringList whiteBalanceModes = m_cameraSession->camera()->getSupportedWhiteBalance(); + for (int i = 0; i < whiteBalanceModes.size(); ++i) { + const QString &wb = whiteBalanceModes.at(i); + if (wb == QLatin1String("auto")) { + m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceAuto, + QStringLiteral("auto")); + } else if (wb == QLatin1String("cloudy-daylight")) { + m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceCloudy, + QStringLiteral("cloudy-daylight")); + } else if (wb == QLatin1String("daylight")) { + m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceSunlight, + QStringLiteral("daylight")); + } else if (wb == QLatin1String("fluorescent")) { + m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceFluorescent, + QStringLiteral("fluorescent")); + } else if (wb == QLatin1String("incandescent")) { + m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceTungsten, + QStringLiteral("incandescent")); + } else if (wb == QLatin1String("shade")) { + m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceShade, + QStringLiteral("shade")); + } else if (wb == QLatin1String("twilight")) { + m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceSunset, + QStringLiteral("twilight")); + } else if (wb == QLatin1String("warm-fluorescent")) { + m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceFlash, + QStringLiteral("warm-fluorescent")); + } + } + } //void QAndroidCameraFocusControl::onCameraCaptureModeChanged() @@ -518,4 +543,21 @@ void QAndroidCameraControl::setExposureCompensation(float bias) exposureCompensationChanged(comp); } +bool QAndroidCameraControl::isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const +{ + return m_supportedWhiteBalanceModes.contains(mode); +} + +void QAndroidCameraControl::setWhiteBalanceMode(QCamera::WhiteBalanceMode mode) +{ + auto *camera = m_cameraSession->camera(); + if (!camera) + return; + QString wb = m_supportedWhiteBalanceModes.value(mode, QString()); + if (!wb.isEmpty()) { + camera->setWhiteBalance(wb); + whiteBalanceModeChanged(mode); + } +} + QT_END_NAMESPACE diff --git a/src/multimedia/platform/android/mediacapture/qandroidcameracontrol_p.h b/src/multimedia/platform/android/mediacapture/qandroidcameracontrol_p.h index 86a685a60..a6c1a3c75 100644 --- a/src/multimedia/platform/android/mediacapture/qandroidcameracontrol_p.h +++ b/src/multimedia/platform/android/mediacapture/qandroidcameracontrol_p.h @@ -76,8 +76,6 @@ public: void setCaptureSession(QPlatformMediaCaptureSession *session) override; - QPlatformCameraImageProcessing *imageProcessingControl() override; - void setFocusMode(QCamera::FocusMode mode) override; bool isFocusModeSupported(QCamera::FocusMode mode) const override; @@ -95,6 +93,9 @@ public: void setExposureCompensation(float bias) override; + bool isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const override; + void setWhiteBalanceMode(QCamera::WhiteBalanceMode mode) override; + private Q_SLOTS: void onCameraOpened(); void setCameraFocusArea(); @@ -120,6 +121,8 @@ private: bool isFlashSupported = false; bool isFlashAutoSupported = false; bool isTorchSupported = false; + + QMap<QCamera::WhiteBalanceMode, QString> m_supportedWhiteBalanceModes; }; diff --git a/src/multimedia/platform/android/mediacapture/qandroidcameraimageprocessingcontrol.cpp b/src/multimedia/platform/android/mediacapture/qandroidcameraimageprocessingcontrol.cpp deleted file mode 100644 index 08beb9a58..000000000 --- a/src/multimedia/platform/android/mediacapture/qandroidcameraimageprocessingcontrol.cpp +++ /dev/null @@ -1,132 +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 "qandroidcameraimageprocessingcontrol_p.h" - -#include "qandroidcamerasession_p.h" -#include "androidcamera_p.h" - -QT_BEGIN_NAMESPACE - -QAndroidCameraImageProcessingControl::QAndroidCameraImageProcessingControl(QAndroidCameraSession *session) - : QPlatformCameraImageProcessing() - , m_session(session) - , m_whiteBalanceMode(QCamera::WhiteBalanceAuto) -{ - connect(m_session, SIGNAL(opened()), - this, SLOT(onCameraOpened())); -} - -bool QAndroidCameraImageProcessingControl::isParameterSupported(ProcessingParameter parameter) const -{ - return parameter == QPlatformCameraImageProcessing::WhiteBalancePreset - && m_session->camera() - && !m_supportedWhiteBalanceModes.isEmpty(); -} - -bool QAndroidCameraImageProcessingControl::isParameterValueSupported(ProcessingParameter parameter, - const QVariant &value) const -{ - return parameter == QPlatformCameraImageProcessing::WhiteBalancePreset - && m_session->camera() - && m_supportedWhiteBalanceModes.contains(value.value<QCamera::WhiteBalanceMode>()); -} - -void QAndroidCameraImageProcessingControl::setParameter(ProcessingParameter parameter, const QVariant &value) -{ - if (parameter != QPlatformCameraImageProcessing::WhiteBalancePreset) - return; - - QCamera::WhiteBalanceMode mode = value.value<QCamera::WhiteBalanceMode>(); - - if (m_session->camera()) - setWhiteBalanceModeHelper(mode); - else - m_whiteBalanceMode = mode; -} - -void QAndroidCameraImageProcessingControl::setWhiteBalanceModeHelper(QCamera::WhiteBalanceMode mode) -{ - QString wb = m_supportedWhiteBalanceModes.value(mode, QString()); - if (!wb.isEmpty()) { - m_session->camera()->setWhiteBalance(wb); - m_whiteBalanceMode = mode; - } -} - -void QAndroidCameraImageProcessingControl::onCameraOpened() -{ - m_supportedWhiteBalanceModes.clear(); - QStringList whiteBalanceModes = m_session->camera()->getSupportedWhiteBalance(); - for (int i = 0; i < whiteBalanceModes.size(); ++i) { - const QString &wb = whiteBalanceModes.at(i); - if (wb == QLatin1String("auto")) { - m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceAuto, - QStringLiteral("auto")); - } else if (wb == QLatin1String("cloudy-daylight")) { - m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceCloudy, - QStringLiteral("cloudy-daylight")); - } else if (wb == QLatin1String("daylight")) { - m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceSunlight, - QStringLiteral("daylight")); - } else if (wb == QLatin1String("fluorescent")) { - m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceFluorescent, - QStringLiteral("fluorescent")); - } else if (wb == QLatin1String("incandescent")) { - m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceTungsten, - QStringLiteral("incandescent")); - } else if (wb == QLatin1String("shade")) { - m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceShade, - QStringLiteral("shade")); - } else if (wb == QLatin1String("twilight")) { - m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceSunset, - QStringLiteral("twilight")); - } else if (wb == QLatin1String("warm-fluorescent")) { - m_supportedWhiteBalanceModes.insert(QCamera::WhiteBalanceFlash, - QStringLiteral("warm-fluorescent")); - } - } - - if (!m_supportedWhiteBalanceModes.contains(m_whiteBalanceMode)) - m_whiteBalanceMode = QCamera::WhiteBalanceAuto; - - setWhiteBalanceModeHelper(m_whiteBalanceMode); -} - -QT_END_NAMESPACE diff --git a/src/multimedia/platform/android/mediacapture/qandroidcameraimageprocessingcontrol_p.h b/src/multimedia/platform/android/mediacapture/qandroidcameraimageprocessingcontrol_p.h deleted file mode 100644 index a7820c1c6..000000000 --- a/src/multimedia/platform/android/mediacapture/qandroidcameraimageprocessingcontrol_p.h +++ /dev/null @@ -1,85 +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 QANDROIDCAMERAIMAGEPROCESSINGCONTROL_H -#define QANDROIDCAMERAIMAGEPROCESSINGCONTROL_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/qplatformcameraimageprocessing_p.h> - -QT_BEGIN_NAMESPACE - -class QAndroidCameraSession; - -class QAndroidCameraImageProcessingControl : public QPlatformCameraImageProcessing -{ - Q_OBJECT -public: - explicit QAndroidCameraImageProcessingControl(QAndroidCameraSession *session); - - bool isParameterSupported(ProcessingParameter) const override; - bool isParameterValueSupported(ProcessingParameter parameter, const QVariant &value) const override; - void setParameter(ProcessingParameter parameter, const QVariant &value) override; - -private Q_SLOTS: - void onCameraOpened(); - -private: - void setWhiteBalanceModeHelper(QCamera::WhiteBalanceMode mode); - - QAndroidCameraSession *m_session; - - QCamera::WhiteBalanceMode m_whiteBalanceMode; - - QMap<QCamera::WhiteBalanceMode, QString> m_supportedWhiteBalanceModes; -}; - -QT_END_NAMESPACE - -#endif // QANDROIDCAMERAIMAGEPROCESSINGCONTROL_H diff --git a/src/multimedia/platform/android/mediacapture/qandroidcamerasession.cpp b/src/multimedia/platform/android/mediacapture/qandroidcamerasession.cpp index 369c7ed10..803988f65 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 "qandroidcameraimageprocessingcontrol_p.h" #include <qvideosink.h> #include <QtConcurrent/qtconcurrentrun.h> #include <qfile.h> @@ -78,8 +77,6 @@ QAndroidCameraSession::QAndroidCameraSession(QObject *parent) QMediaStorageLocation::Pictures, AndroidMultimediaUtils::getDefaultMediaDirectory(AndroidMultimediaUtils::DCIM)); - m_cameraImageProcessingControl = new QAndroidCameraImageProcessingControl(this); - if (qApp) { connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(onApplicationStateChanged(Qt::ApplicationState))); @@ -88,7 +85,6 @@ QAndroidCameraSession::QAndroidCameraSession(QObject *parent) QAndroidCameraSession::~QAndroidCameraSession() { - delete m_cameraImageProcessingControl; delete m_renderer; close(); diff --git a/src/multimedia/platform/android/mediacapture/qandroidcamerasession_p.h b/src/multimedia/platform/android/mediacapture/qandroidcamerasession_p.h index 9f88bd76d..9f642ac3d 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 QAndroidCameraImageProcessingControl; class QAndroidCameraVideoRendererControl; class QVideoSink; @@ -111,8 +110,6 @@ public: void setPreviewCallback(PreviewCallback *callback); bool requestRecordingPermission(); - QAndroidCameraImageProcessingControl *imageProcessingControl() { return m_cameraImageProcessingControl; } - void setVideoSink(QVideoSink *surface); Q_SIGNALS: @@ -178,8 +175,6 @@ private: QAndroidCameraVideoRendererControl *m_renderer = nullptr; - QAndroidCameraImageProcessingControl *m_cameraImageProcessingControl; - QImageEncoderSettings m_requestedImageSettings; QImageEncoderSettings m_actualImageSettings; int m_lastImageCaptureId; diff --git a/src/multimedia/platform/darwin/camera/avfcamera.mm b/src/multimedia/platform/darwin/camera/avfcamera.mm index 65688ba11..a2be7a3e5 100644 --- a/src/multimedia/platform/darwin/camera/avfcamera.mm +++ b/src/multimedia/platform/darwin/camera/avfcamera.mm @@ -43,7 +43,6 @@ #include "avfcameraservice_p.h" #include "avfcamerautility_p.h" #include "avfcamerarenderer_p.h" -#include "avfcameraimageprocessing_p.h" #include <qmediacapturesession.h> QT_USE_NAMESPACE @@ -162,13 +161,10 @@ AVFCamera::AVFCamera(QCamera *camera) , m_lastStatus(QCamera::InactiveStatus) { Q_ASSERT(camera); - - m_cameraImageProcessingControl = new AVFCameraImageProcessing(this); } AVFCamera::~AVFCamera() { - delete m_cameraImageProcessingControl; } bool AVFCamera::isActive() const @@ -267,11 +263,6 @@ AVCaptureDevice *AVFCamera::device() const return device; } -QPlatformCameraImageProcessing *AVFCamera::imageProcessingControl() -{ - return m_cameraImageProcessingControl; -} - #ifdef Q_OS_IOS namespace { @@ -827,6 +818,136 @@ float AVFCamera::shutterSpeed() const #endif } +#ifdef Q_OS_IOS +namespace { + +void avf_convert_white_balance_mode(QCamera::WhiteBalanceMode qtMode, + AVCaptureWhiteBalanceMode &avMode) +{ + if (qtMode == QCamera::WhiteBalanceAuto) + avMode = AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance; + else + avMode = AVCaptureWhiteBalanceModeLocked; +} + +bool avf_set_white_balance_mode(AVCaptureDevice *captureDevice, + AVCaptureWhiteBalanceMode avMode) +{ + Q_ASSERT(captureDevice); + + const bool lock = [captureDevice lockForConfiguration:nil]; + if (!lock) { + qDebug() << "Failed to lock a capture device for configuration\n"; + return false; + } + + captureDevice.whiteBalanceMode = avMode; + [captureDevice unlockForConfiguration]; + return true; +} + +bool avf_convert_temp_and_tint_to_wb_gains(AVCaptureDevice *captureDevice, + float temp, float tint, AVCaptureWhiteBalanceGains &wbGains) +{ + Q_ASSERT(captureDevice); + + AVCaptureWhiteBalanceTemperatureAndTintValues wbTTValues = { + .temperature = temp, + .tint = tint + }; + wbGains = [captureDevice deviceWhiteBalanceGainsForTemperatureAndTintValues:wbTTValues]; + + if (wbGains.redGain >= 1.0 && wbGains.redGain <= captureDevice.maxWhiteBalanceGain + && wbGains.greenGain >= 1.0 && wbGains.greenGain <= captureDevice.maxWhiteBalanceGain + && wbGains.blueGain >= 1.0 && wbGains.blueGain <= captureDevice.maxWhiteBalanceGain) + return true; + + return false; +} + +bool avf_set_white_balance_gains(AVCaptureDevice *captureDevice, + AVCaptureWhiteBalanceGains wbGains) +{ + const bool lock = [captureDevice lockForConfiguration:nil]; + if (!lock) { + qDebug() << "Failed to lock a capture device for configuration\n"; + return false; + } + + [captureDevice setWhiteBalanceModeLockedWithDeviceWhiteBalanceGains:wbGains + completionHandler:nil]; + [captureDevice unlockForConfiguration]; + return true; +} + +} + +bool AVFCamera::isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const +{ + if (mode == QCamera::WhiteBalanceAuto) + return true; + AVCaptureDevice *captureDevice = m_camera->device(); + if (!device) + return false; + return [captureDevice isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeLocked]; +} + +void AVFCamera::setWhiteBalanceMode(QCamera::WhiteBalanceMode) +{ + if (!isWhiteBalanceModeSupported(mode)) + return false; + + AVCaptureDevice *captureDevice = m_camera->device(); + Q_ASSERT(captureDevice); + + const AVFConfigurationLock lock(captureDevice); + if (!lock) { + qDebugCamera() << Q_FUNC_INFO << "failed to lock a capture device" + << "for configuration"; + return; + } + + AVCaptureWhiteBalanceMode avMode; + avf_convert_white_balance_mode(mode, avMode); + avf_set_white_balance_mode(captureDevice, avMode); + + if (mode == QCamera::WhiteBalanceAuto || mode == QCamera::WhiteBalanceManual) { + whiteBalanceModeChanged(mode); + return; + } + + const int colorTemp = colorTemperatureForWhiteBalance(mode); + AVCaptureWhiteBalanceGains wbGains; + if (avf_convert_temp_and_tint_to_wb_gains(captureDevice, colorTemp, 0., wbGains) + && avf_set_white_balance_gains(captureDevice, wbGains)) + whiteBalanceModeChanged(mode); +} + +void AVFCamera::setColorTemperature(int colorTemp) +{ + if (colorTemp == 0) { + colorTemperatureChanged(colorTemp); + return; + } + + AVCaptureDevice *captureDevice = m_camera->device(); + if (!device || ![captureDevice isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeLocked]) + return false; + + const AVFConfigurationLock lock(captureDevice); + if (!lock) { + qDebugCamera() << Q_FUNC_INFO << "failed to lock a capture device" + << "for configuration"; + return; + } + + AVCaptureWhiteBalanceGains wbGains; + if (avf_convert_temp_and_tint_to_wb_gains(captureDevice, colorTemp, 0., wbGains) + && avf_set_white_balance_gains(captureDevice, wbGains)) + colorTemperatureChanged(colorTemp); +} +#endif + void AVFCamera::setManualIsoSensitivity(int value) { #ifdef Q_OS_IOS diff --git a/src/multimedia/platform/darwin/camera/avfcamera_p.h b/src/multimedia/platform/darwin/camera/avfcamera_p.h index 8d2feb658..75b52abb5 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 AVFCameraImageProcessing; Q_FORWARD_DECLARE_OBJC_CLASS(AVCaptureDeviceFormat); Q_FORWARD_DECLARE_OBJC_CLASS(AVCaptureConnection); @@ -83,8 +82,6 @@ public: void setCaptureSession(QPlatformMediaCaptureSession *) override; - QPlatformCameraImageProcessing *imageProcessingControl() override; - void setFocusMode(QCamera::FocusMode mode) override; bool isFocusModeSupported(QCamera::FocusMode mode) const override; @@ -110,6 +107,13 @@ public: void setManualShutterSpeed(float value) override; virtual float shutterSpeed() const override; +#ifdef Q_OS_IOS + // not supported on macOS + bool isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const override; + void setWhiteBalanceMode(QCamera::WhiteBalanceMode /*mode*/) override; + void setColorTemperature(int /*temperature*/) override; +#endif + AVCaptureConnection *videoConnection() const; AVCaptureDevice *device() const; @@ -124,8 +128,6 @@ private: AVFCameraService *m_service = nullptr; AVFCameraSession *m_session = nullptr; - AVFCameraImageProcessing *m_cameraImageProcessingControl; - QCameraInfo m_cameraInfo; bool m_active; diff --git a/src/multimedia/platform/darwin/camera/avfcameraimageprocessing.mm b/src/multimedia/platform/darwin/camera/avfcameraimageprocessing.mm deleted file mode 100644 index 4dc613c88..000000000 --- a/src/multimedia/platform/darwin/camera/avfcameraimageprocessing.mm +++ /dev/null @@ -1,309 +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 <QtMultimedia/private/qtmultimediaglobal_p.h> -#include <QtCore/qdebug.h> - -#include "avfcameraimageprocessing_p.h" -#include "avfcamera_p.h" - -#include <AVFoundation/AVFoundation.h> - -QT_BEGIN_NAMESPACE - -namespace { - -void avf_convert_white_balance_mode(QCamera::WhiteBalanceMode qtMode, - AVCaptureWhiteBalanceMode &avMode) -{ - if (qtMode == QCamera::WhiteBalanceAuto) - avMode = AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance; - else - avMode = AVCaptureWhiteBalanceModeLocked; -} - -bool avf_set_white_balance_mode(AVCaptureDevice *captureDevice, - AVCaptureWhiteBalanceMode avMode) -{ - Q_ASSERT(captureDevice); - - const bool lock = [captureDevice lockForConfiguration:nil]; - if (!lock) { - qDebug() << "Failed to lock a capture device for configuration\n"; - return false; - } - - captureDevice.whiteBalanceMode = avMode; - [captureDevice unlockForConfiguration]; - return true; -} - -#ifdef Q_OS_IOS -bool avf_convert_temp_and_tint_to_wb_gains(AVCaptureDevice *captureDevice, - float temp, float tint, AVCaptureWhiteBalanceGains &wbGains) -{ - Q_ASSERT(captureDevice); - - AVCaptureWhiteBalanceTemperatureAndTintValues wbTTValues = { - .temperature = temp, - .tint = tint - }; - wbGains = [captureDevice deviceWhiteBalanceGainsForTemperatureAndTintValues:wbTTValues]; - - if (wbGains.redGain >= 1.0 && wbGains.redGain <= captureDevice.maxWhiteBalanceGain - && wbGains.greenGain >= 1.0 && wbGains.greenGain <= captureDevice.maxWhiteBalanceGain - && wbGains.blueGain >= 1.0 && wbGains.blueGain <= captureDevice.maxWhiteBalanceGain) - return true; - - return false; -} - -bool avf_set_white_balance_gains(AVCaptureDevice *captureDevice, - AVCaptureWhiteBalanceGains wbGains) -{ - const bool lock = [captureDevice lockForConfiguration:nil]; - if (!lock) { - qDebug() << "Failed to lock a capture device for configuration\n"; - return false; - } - - [captureDevice setWhiteBalanceModeLockedWithDeviceWhiteBalanceGains:wbGains - completionHandler:nil]; - [captureDevice unlockForConfiguration]; - return true; -} -#endif - -} - -AVFCameraImageProcessing::AVFCameraImageProcessing(AVFCamera *camera) - : QPlatformCameraImageProcessing(camera), - m_camera(camera), - m_whiteBalanceMode(QCamera::WhiteBalanceAuto) -{ - Q_ASSERT(m_camera); - - // AVFoundation's API allows adjusting white balance gains values(or temperature and tint) - // only for iOS -#ifdef Q_OS_IOS - m_mappedWhiteBalancePresets[QCamera::WhiteBalanceSunlight] - = qMakePair(5600.0, .0); - m_mappedWhiteBalancePresets[QCamera::WhiteBalanceCloudy] - = qMakePair(6000.0, .0); - m_mappedWhiteBalancePresets[QCamera::WhiteBalanceShade] - = qMakePair(7000.0, .0); - m_mappedWhiteBalancePresets[QCamera::WhiteBalanceTungsten] - = qMakePair(3200.0, .0); - m_mappedWhiteBalancePresets[QCamera::WhiteBalanceFluorescent] - = qMakePair(4000.0, .0); - m_mappedWhiteBalancePresets[QCamera::WhiteBalanceFlash] - = qMakePair(5500.0, .0); - m_mappedWhiteBalancePresets[QCamera::WhiteBalanceSunset] - = qMakePair(3000.0, .0); -#endif - - // The default white balance mode of AVFoundation is WhiteBalanceModeLocked - // so set it to correspond to Qt's WhiteBalanceModeAuto as soon as the device - // is available - connect(m_camera, SIGNAL(activeChanged(bool)), SLOT(cameraActiveChanged(bool))); -} - -AVFCameraImageProcessing::~AVFCameraImageProcessing() -{ -} - -bool AVFCameraImageProcessing::isParameterSupported( - QPlatformCameraImageProcessing::ProcessingParameter parameter) const -{ -#ifdef Q_OS_IOS - return (parameter == QPlatformCameraImageProcessing::WhiteBalancePreset - || parameter == QPlatformCameraImageProcessing::ColorTemperature) - && m_camera->device(); -#else - return parameter == QPlatformCameraImageProcessing::WhiteBalancePreset - && m_camera->device(); -#endif -} - -bool AVFCameraImageProcessing::isParameterValueSupported( - QPlatformCameraImageProcessing::ProcessingParameter parameter, - const QVariant &value) const -{ - AVCaptureDevice *captureDevice = m_camera->device(); - Q_ASSERT(captureDevice); - - if (parameter == QPlatformCameraImageProcessing::WhiteBalancePreset) - return isWhiteBalanceModeSupported( - value.value<QCamera::WhiteBalanceMode>()); - -#ifdef Q_OS_IOS - if (parameter == QPlatformCameraImageProcessing::ColorTemperature) { - AVCaptureWhiteBalanceGains gains; - return avf_convert_temp_and_tint_to_wb_gains( - captureDevice, value.value<float>(), .0, gains); - } -#endif - - return false; -} - -void AVFCameraImageProcessing::setParameter( - QPlatformCameraImageProcessing::ProcessingParameter parameter, - const QVariant &value) -{ - bool result = false; - if (parameter == QPlatformCameraImageProcessing::WhiteBalancePreset) - result = setWhiteBalanceMode(value.value<QCamera::WhiteBalanceMode>()); - -#ifdef Q_OS_IOS - else if (parameter == QPlatformCameraImageProcessing::ColorTemperature) - result = setColorTemperature(value.value<float>()); -#endif - - else - qDebug() << "Setting parameter is not supported\n"; - - if (!result) - qDebug() << "Could not set parameter\n"; -} - -bool AVFCameraImageProcessing::setWhiteBalanceMode( - QCamera::WhiteBalanceMode mode) -{ - AVCaptureDevice *captureDevice = m_camera->device(); - Q_ASSERT(captureDevice); - - AVCaptureWhiteBalanceMode avMode; - avf_convert_white_balance_mode(mode, avMode); - - if (!isWhiteBalanceModeSupported(mode)) - return false; - - if (mode == QCamera::WhiteBalanceAuto - && avf_set_white_balance_mode(captureDevice, avMode)) { - m_whiteBalanceMode = mode; - return true; - } - -#ifdef Q_OS_IOS - if (mode == QCamera::WhiteBalanceManual - && avf_set_white_balance_mode(captureDevice, avMode)) { - m_whiteBalanceMode = mode; - return true; - } - - const auto mappedValues = m_mappedWhiteBalancePresets[mode]; - AVCaptureWhiteBalanceGains wbGains; - if (avf_convert_temp_and_tint_to_wb_gains(captureDevice, mappedValues.first, mappedValues.second, wbGains) - && avf_set_white_balance_gains(captureDevice, wbGains)) { - m_whiteBalanceMode = mode; - return true; - } -#endif - - return false; -} - -bool AVFCameraImageProcessing::isWhiteBalanceModeSupported( - QCamera::WhiteBalanceMode qtMode) const -{ - AVCaptureDevice *captureDevice = m_camera->device(); - Q_ASSERT(captureDevice); - - AVCaptureWhiteBalanceMode avMode; - avf_convert_white_balance_mode(qtMode, avMode); - - // Since AVFoundation's API does not support setting custom white balance gains - // on macOS, only WhiteBalanceAuto mode is supported. - if (qtMode == QCamera::WhiteBalanceAuto) - return [captureDevice isWhiteBalanceModeSupported:avMode]; - -#ifdef Q_OS_IOS - // Qt's WhiteBalanceManual corresponds to AVFoundations's WhiteBalanceModeLocked - // + setting custom white balance gains (or color temperature in Qt) - if (qtMode == QCamera::WhiteBalanceManual) - return [captureDevice isWhiteBalanceModeSupported:avMode] - && captureDevice.lockingWhiteBalanceWithCustomDeviceGainsSupported; - - // Qt's white balance presets correspond to AVFoundation's WhiteBalanceModeLocked - // + setting the white balance gains to the mapped value for each preset - if (m_mappedWhiteBalancePresets.find(qtMode) != m_mappedWhiteBalancePresets.end()) { - const auto mappedValues = m_mappedWhiteBalancePresets[qtMode]; - AVCaptureWhiteBalanceGains wbGains; - return [captureDevice isWhiteBalanceModeSupported:avMode] - && captureDevice.lockingWhiteBalanceWithCustomDeviceGainsSupported - && avf_convert_temp_and_tint_to_wb_gains(captureDevice, mappedValues.first, - mappedValues.second, wbGains); - } -#endif - - qDebug() << "White balance mode not supported"; - return false; -} - -#ifdef Q_OS_IOS -float AVFCameraImageProcessing::colorTemperature() const -{ - return m_colorTemperature; -} - -bool AVFCameraImageProcessing::setColorTemperature(float temperature) -{ - AVCaptureDevice *captureDevice = m_camera->device(); - Q_ASSERT(captureDevice); - - AVCaptureWhiteBalanceGains wbGains; - if (avf_convert_temp_and_tint_to_wb_gains(captureDevice, temperature, .0, wbGains) - && avf_set_white_balance_gains(captureDevice, wbGains)) { - m_whiteBalanceMode = QCamera::WhiteBalanceManual; - return true; - } - - return false; -} -#endif - -void AVFCameraImageProcessing::cameraActiveChanged(bool active) -{ - if (!active) - return; - setWhiteBalanceMode(QCamera::WhiteBalanceAuto); -} - -QT_END_NAMESPACE diff --git a/src/multimedia/platform/darwin/camera/avfcameraimageprocessing_p.h b/src/multimedia/platform/darwin/camera/avfcameraimageprocessing_p.h deleted file mode 100644 index 7f0ae6788..000000000 --- a/src/multimedia/platform/darwin/camera/avfcameraimageprocessing_p.h +++ /dev/null @@ -1,98 +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 AVFCAMERAIMAGEPROCESSING_H -#define AVFCAMERAIMAGEPROCESSING_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 <QtMultimedia/private/qtmultimediaglobal_p.h> -#include <qcamera.h> -#include <private/qplatformcameraimageprocessing_p.h> - -QT_BEGIN_NAMESPACE - -class AVFCamera; - -class AVFCameraImageProcessing : public QPlatformCameraImageProcessing -{ - Q_OBJECT - -public: - AVFCameraImageProcessing(AVFCamera *camera); - virtual ~AVFCameraImageProcessing(); - - bool isParameterSupported(ProcessingParameter) const override; - bool isParameterValueSupported(ProcessingParameter parameter, const QVariant &value) const override; - void setParameter(ProcessingParameter parameter, const QVariant &value) override; - - bool setWhiteBalanceMode(QCamera::WhiteBalanceMode mode); - -#ifdef Q_OS_IOS - float colorTemperature() const; - bool setColorTemperature(float temperature); -#endif - -private Q_SLOTS: - void cameraActiveChanged(bool active); - -private: - bool isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const; - - AVFCamera *m_camera; - QCamera::WhiteBalanceMode m_whiteBalanceMode; - -#ifdef Q_OS_IOS - float m_colorTemperature = .0; - QMap<QCamera::WhiteBalanceMode, QPair<float, float>> m_mappedWhiteBalancePresets; -#endif -}; - -QT_END_NAMESPACE - -#endif // AVFCAMERAIMAGEPROCESSING_H diff --git a/src/multimedia/platform/darwin/camera/avfcameraservice.mm b/src/multimedia/platform/darwin/camera/avfcameraservice.mm index 6a577e4fe..c75d7665e 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 "avfcameraimageprocessing_p.h" #include "avfmediaencoder_p.h" #include <qmediadevices.h> diff --git a/src/multimedia/platform/darwin/camera/avfcameraservice_p.h b/src/multimedia/platform/darwin/camera/avfcameraservice_p.h index 869ba113f..4bb8db5d6 100644 --- a/src/multimedia/platform/darwin/camera/avfcameraservice_p.h +++ b/src/multimedia/platform/darwin/camera/avfcameraservice_p.h @@ -58,7 +58,6 @@ QT_BEGIN_NAMESPACE class QPlatformCamera; class QPlatformMediaEncoder; -class QPlatformCameraImageProcessing; class AVFCamera; class AVFCameraImageCapture; class AVFCameraSession; diff --git a/src/multimedia/platform/gstreamer/mediacapture/qgstreamercamera.cpp b/src/multimedia/platform/gstreamer/mediacapture/qgstreamercamera.cpp index 9ece4a09e..2ac1da4b4 100644 --- a/src/multimedia/platform/gstreamer/mediacapture/qgstreamercamera.cpp +++ b/src/multimedia/platform/gstreamer/mediacapture/qgstreamercamera.cpp @@ -43,9 +43,13 @@ #include "qgstreamercameraimagecapture_p.h" #include <private/qgstreamermediadevices_p.h> #include <private/qgstreamerintegration_p.h> -#include <private/qgstreamercameraimageprocessing_p.h> #include <qmediacapturesession.h> +#if QT_CONFIG(linux_v4l) +#include <linux/videodev2.h> +#include <private/qcore_unix_p.h> +#endif + #include <QtCore/qdebug.h> QGstreamerCamera::QGstreamerCamera(QCamera *camera) @@ -60,8 +64,6 @@ QGstreamerCamera::QGstreamerCamera(QCamera *camera) gstCamera.link(gstDecode, gstVideoConvert, gstVideoScale); gstCameraBin.addGhostPad(gstVideoScale, "src"); - - imageProcessing = new QGstreamerImageProcessing(this); } QGstreamerCamera::~QGstreamerCamera() = default; @@ -125,8 +127,7 @@ void QGstreamerCamera::setCamera(const QCameraInfo &camera) gstPipeline.setStateSync(state); } - //m_session->cameraChanged(); - imageProcessing->update(); + updateCameraProperties(); } void QGstreamerCamera::setCameraFormatInternal(const QCameraFormat &format) @@ -183,17 +184,17 @@ void QGstreamerCamera::setCaptureSession(QPlatformMediaCaptureSession *session) // is this enough? } -QPlatformCameraImageProcessing *QGstreamerCamera::imageProcessingControl() +void QGstreamerCamera::updateCameraProperties() { - return imageProcessing; -} +#if QT_CONFIG(linux_v4l) + if (isV4L2Camera()) + initV4L2Controls(); +#endif +#if QT_CONFIG(gstreamer_photography) + if (auto *p = photography()) + gst_photography_set_white_balance_mode(p, GST_PHOTOGRAPHY_WB_MODE_AUTO); +#endif -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) @@ -405,4 +406,194 @@ float QGstreamerCamera::shutterSpeed() const } return -1; } + +bool QGstreamerCamera::isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const +{ + if (mode == QCamera::WhiteBalanceAuto) + return true; + +#if QT_CONFIG(linux_v4l) + if (isV4L2Camera()) { + if (v4l2AutoWhiteBalanceSupported && v4l2ColorTemperatureSupported) + return true; + } +#endif +#if QT_CONFIG(gstreamer_photography) + if (photography()) { + switch (mode) { + case QCamera::WhiteBalanceAuto: + case QCamera::WhiteBalanceSunlight: + case QCamera::WhiteBalanceCloudy: + case QCamera::WhiteBalanceShade: + case QCamera::WhiteBalanceSunset: + case QCamera::WhiteBalanceTungsten: + case QCamera::WhiteBalanceFluorescent: + return true; + case QCamera::WhiteBalanceManual: { +#if GST_CHECK_VERSION(1, 18, 0) + GstPhotographyInterface *iface = GST_PHOTOGRAPHY_GET_INTERFACE(p); + if (iface->set_color_temperature && iface->get_color_temperature) + return true; +#endif + break; + } + default: + break; + } + } +#endif + + return mode == QCamera::WhiteBalanceAuto; +} + +void QGstreamerCamera::setWhiteBalanceMode(QCamera::WhiteBalanceMode mode) +{ + Q_ASSERT(isWhiteBalanceModeSupported(mode)); + +#if QT_CONFIG(gstreamer_photography) + if (auto *p = photography()) { + GstPhotographyWhiteBalanceMode gstMode = GST_PHOTOGRAPHY_WB_MODE_AUTO; + switch (mode) { + case QCamera::WhiteBalanceSunlight: + gstMode = GST_PHOTOGRAPHY_WB_MODE_DAYLIGHT; + break; + case QCamera::WhiteBalanceCloudy: + gstMode = GST_PHOTOGRAPHY_WB_MODE_CLOUDY; + break; + case QCamera::WhiteBalanceShade: + gstMode = GST_PHOTOGRAPHY_WB_MODE_SHADE; + break; + case QCamera::WhiteBalanceSunset: + gstMode = GST_PHOTOGRAPHY_WB_MODE_SUNSET; + break; + case QCamera::WhiteBalanceTungsten: + gstMode = GST_PHOTOGRAPHY_WB_MODE_TUNGSTEN; + break; + case QCamera::WhiteBalanceFluorescent: + gstMode = GST_PHOTOGRAPHY_WB_MODE_FLUORESCENT; + break; + case QCamera::WhiteBalanceAuto: + default: + break; + } + if (gst_photography_set_white_balance_mode(p, gstMode)) { + whiteBalanceModeChanged(mode); + return; + } + } else +#endif + + if (isV4L2Camera()) { + int temperature = colorTemperatureForWhiteBalance(mode); + int t = setV4L2ColorTemperature(temperature); + if (t == 0) + mode = QCamera::WhiteBalanceAuto; + whiteBalanceModeChanged(mode); + } +} + +void QGstreamerCamera::setColorTemperature(int temperature) +{ + if (temperature == 0) { + setWhiteBalanceMode(QCamera::WhiteBalanceAuto); + return; + } + + Q_ASSERT(isWhiteBalanceModeSupported(QCamera::WhiteBalanceManual)); + +#if QT_CONFIG(gstreamer_photography) && GST_CHECK_VERSION(1, 18, 0) + if (auto *p = photography()) { + GstPhotographyInterface *iface = GST_PHOTOGRAPHY_GET_INTERFACE(p); + Q_ASSERT(iface->set_color_temperature); + iface->set_color_temperature(p, temperature); + return; + } +#endif + + if (isV4L2Camera()) { + int t = setV4L2ColorTemperature(temperature); + if (t) + colorTemperatureChanged(t); + } +} + +#if QT_CONFIG(linux_v4l) +void QGstreamerCamera::initV4L2Controls() +{ + v4l2AutoWhiteBalanceSupported = false; + v4l2ColorTemperatureSupported = false; + + const QString deviceName = v4l2Device(); + Q_ASSERT(!deviceName.isEmpty()); + + const int fd = qt_safe_open(deviceName.toLocal8Bit().constData(), O_RDONLY); + if (fd == -1) { + qWarning() << "Unable to open the camera" << deviceName + << "for read to query the parameter info:" << qt_error_string(errno); + return; + } + + struct v4l2_queryctrl queryControl; + ::memset(&queryControl, 0, sizeof(queryControl)); + queryControl.id = V4L2_CID_AUTO_WHITE_BALANCE; + + if (::ioctl(fd, VIDIOC_QUERYCTRL, &queryControl) == 0) { + v4l2AutoWhiteBalanceSupported = true; + struct v4l2_control control; + control.id = V4L2_CID_WHITE_BALANCE_TEMPERATURE; + control.value = true; + ::ioctl(fd, VIDIOC_S_CTRL, &control); + } + + ::memset(&queryControl, 0, sizeof(queryControl)); + queryControl.id = V4L2_CID_WHITE_BALANCE_TEMPERATURE; + if (::ioctl(fd, VIDIOC_QUERYCTRL, &queryControl) == 0) { + v4l2MinColorTemp = queryControl.minimum; + v4l2MaxColorTemp = queryControl.maximum; + v4l2ColorTemperatureSupported = true; + } + + qt_safe_close(fd); + +} + +int QGstreamerCamera::setV4L2ColorTemperature(int temperature) +{ + struct v4l2_control control; + ::memset(&control, 0, sizeof(control)); + + const int fd = qt_safe_open(v4l2Device().toLocal8Bit().constData(), O_RDONLY); + if (fd == -1) { + qWarning() << "Unable to open the camera" << v4l2Device() + << "for read to get the parameter value:" << qt_error_string(errno); + return 0; + } + + if (v4l2AutoWhiteBalanceSupported) { + control.id = V4L2_CID_AUTO_WHITE_BALANCE; + control.value = temperature == 0 ? true : false; + if (::ioctl(fd, VIDIOC_S_CTRL, &control) != 0) { + qWarning() << "Unable to set the V4L2 AUTO_WHITE_BALANCE property" << qt_error_string(errno); + } + } else if (temperature == 0) { + temperature = 5600; + } + + if (temperature != 0 && v4l2ColorTemperatureSupported) { + temperature = qBound(v4l2MinColorTemp, temperature, v4l2MaxColorTemp); + control.id = V4L2_CID_WHITE_BALANCE_TEMPERATURE; + control.value = qBound(v4l2MinColorTemp, temperature, v4l2MaxColorTemp); + if (::ioctl(fd, VIDIOC_S_CTRL, &control) != 0) { + qWarning() << "Unable to set the V4L2 AUTO_WHITE_BALANCE property" << qt_error_string(errno); + temperature = 0; + } + } else { + temperature = 0; + } + + qt_safe_close(fd); + return temperature; +} +#endif + #endif diff --git a/src/multimedia/platform/gstreamer/mediacapture/qgstreamercamera_p.h b/src/multimedia/platform/gstreamer/mediacapture/qgstreamercamera_p.h index 2397cfa84..54064e399 100644 --- a/src/multimedia/platform/gstreamer/mediacapture/qgstreamercamera_p.h +++ b/src/multimedia/platform/gstreamer/mediacapture/qgstreamercamera_p.h @@ -56,10 +56,8 @@ #include <private/qplatformcamera_p.h> #include "qgstreamermediacapture_p.h" #include <private/qgst_p.h> -#include <gst/video/colorbalance.h> QT_BEGIN_NAMESPACE -class QGstreamerImageProcessing; class QGstreamerCamera : public QPlatformCamera { @@ -80,8 +78,6 @@ public: QGstElement gstElement() const { return gstCameraBin.element(); } void setPipeline(const QGstPipeline &pipeline) { gstPipeline = pipeline; } - QPlatformCameraImageProcessing *imageProcessingControl() override; - #if QT_CONFIG(gstreamer_photography) GstPhotography *photography() const; @@ -100,16 +96,26 @@ public: void setManualShutterSpeed(float) override; float shutterSpeed() const override; #endif + bool isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const override; + void setWhiteBalanceMode(QCamera::WhiteBalanceMode mode) override; + void setColorTemperature(int temperature) override; QString v4l2Device() const { return m_v4l2Device; } bool isV4L2Camera() const { return !m_v4l2Device.isEmpty(); } - GstColorBalance *colorBalance() const; - private: - QGstreamerMediaCapture *m_session = nullptr; + void updateCameraProperties(); +#if QT_CONFIG(linux_v4l) + void initV4L2Controls(); + int setV4L2ColorTemperature(int temperature); + + bool v4l2AutoWhiteBalanceSupported = false; + bool v4l2ColorTemperatureSupported = false; + qint32 v4l2MinColorTemp = 5600; // Daylight... + qint32 v4l2MaxColorTemp = 5600; +#endif - QGstreamerImageProcessing *imageProcessing = nullptr; + QGstreamerMediaCapture *m_session = nullptr; QCameraInfo m_cameraInfo; diff --git a/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraimageprocessing.cpp b/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraimageprocessing.cpp deleted file mode 100644 index 8a692b866..000000000 --- a/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraimageprocessing.cpp +++ /dev/null @@ -1,312 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Copyright (C) 2016 Denis Shienkov <denis.shienkov@gmail.com> -** 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 "qgstreamercameraimageprocessing_p.h" -#include "qgstreamercamera_p.h" - -#include <gst/video/colorbalance.h> - -#if QT_CONFIG(linux_v4l) -#include <linux/videodev2.h> -#include <private/qcore_unix_p.h> -#endif - -QT_BEGIN_NAMESPACE - -QGstreamerImageProcessing::QGstreamerImageProcessing(QGstreamerCamera *camera) - : QPlatformCameraImageProcessing(camera) - , m_camera(camera) -{ -#if QT_CONFIG(linux_v4l) - if (m_camera->isV4L2Camera()) - initV4L2Controls(); -#endif -#if QT_CONFIG(gstreamer_photography) - if (auto *photography = m_camera->photography()) - gst_photography_set_white_balance_mode(photography, GST_PHOTOGRAPHY_WB_MODE_AUTO); -#endif -} - -QGstreamerImageProcessing::~QGstreamerImageProcessing() -{ -} - -bool QGstreamerImageProcessing::setWhiteBalanceMode(QCamera::WhiteBalanceMode mode) -{ - if (!isWhiteBalanceModeSupported(mode)) - return false; -#if QT_CONFIG(gstreamer_photography) - if (auto *photography = m_camera->photography()) { - GstPhotographyWhiteBalanceMode gstMode = GST_PHOTOGRAPHY_WB_MODE_AUTO; - switch (mode) { - case QCamera::WhiteBalanceSunlight: - gstMode = GST_PHOTOGRAPHY_WB_MODE_DAYLIGHT; - break; - case QCamera::WhiteBalanceCloudy: - gstMode = GST_PHOTOGRAPHY_WB_MODE_CLOUDY; - break; - case QCamera::WhiteBalanceShade: - gstMode = GST_PHOTOGRAPHY_WB_MODE_SHADE; - break; - case QCamera::WhiteBalanceSunset: - gstMode = GST_PHOTOGRAPHY_WB_MODE_SUNSET; - break; - case QCamera::WhiteBalanceTungsten: - gstMode = GST_PHOTOGRAPHY_WB_MODE_TUNGSTEN; - break; - case QCamera::WhiteBalanceFluorescent: - gstMode = GST_PHOTOGRAPHY_WB_MODE_FLUORESCENT; - break; - case QCamera::WhiteBalanceAuto: - default: - break; - } - if (gst_photography_set_white_balance_mode(photography, gstMode)) { - m_whiteBalanceMode = mode; - return true; - } - } -#endif - - return false; -} - -bool QGstreamerImageProcessing::isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const -{ -#if QT_CONFIG(linux_v4l) - if (m_camera->isV4L2Camera()) { - if (mode == QCamera::WhiteBalanceAuto) - return true; - if (v4l2AutoWhiteBalanceSupported && mode == QCamera::WhiteBalanceManual) - return true; - // ### Could emulate the others through hardcoded color temperatures - return false; - } -#endif -#if QT_CONFIG(gstreamer_photography) - if (m_camera->photography()) { - switch (mode) { - case QCamera::WhiteBalanceAuto: - case QCamera::WhiteBalanceSunlight: - case QCamera::WhiteBalanceCloudy: - case QCamera::WhiteBalanceShade: - case QCamera::WhiteBalanceSunset: - case QCamera::WhiteBalanceTungsten: - case QCamera::WhiteBalanceFluorescent: - return true; - default: - break; - } - } -#endif - - return mode == QCamera::WhiteBalanceAuto; -} - - -bool QGstreamerImageProcessing::isParameterSupported(QPlatformCameraImageProcessing::ProcessingParameter parameter) const -{ -#if QT_CONFIG(linux_v4l) - if (m_camera->isV4L2Camera()) { - switch (parameter) { - case WhiteBalancePreset: - return v4l2AutoWhiteBalanceSupported; - case ColorTemperature: - return v4l2ColorTemperatureSupported; - default: - // v4l2 doesn't have photography - return false; - } - } -#endif - -#if QT_CONFIG(gstreamer_photography) - if (m_camera->photography()) { - if (parameter == QPlatformCameraImageProcessing::WhiteBalancePreset) - return true; - } -#endif - - return false; -} - -bool QGstreamerImageProcessing::isParameterValueSupported(QPlatformCameraImageProcessing::ProcessingParameter parameter, const QVariant &value) const -{ - switch (parameter) { - case ColorTemperature: { -#if QT_CONFIG(linux_v4l) - if (m_camera->isV4L2Camera()) { - int temp = value.toInt(); - return v4l2ColorTemperatureSupported && v4l2MinColorTemp <= temp && temp <= v4l2MaxColorTemp; - } -#endif - return false; - } - case WhiteBalancePreset: - return isWhiteBalanceModeSupported(value.value<QCamera::WhiteBalanceMode>()); - default: - break; - } - - return false; -} - -void QGstreamerImageProcessing::setParameter(QPlatformCameraImageProcessing::ProcessingParameter parameter, const QVariant &value) -{ -#if QT_CONFIG(linux_v4l) - if (m_camera->isV4L2Camera()) { - if (setV4L2Param(parameter, value)) - return; - } -#endif - - switch (parameter) { - case WhiteBalancePreset: - setWhiteBalanceMode(value.value<QCamera::WhiteBalanceMode>()); - break; - case QPlatformCameraImageProcessing::ColorTemperature: - break; - default: - break; - } -} - -void QGstreamerImageProcessing::update() -{ -#if QT_CONFIG(linux_v4l) - initV4L2Controls(); -#endif -} - -#if QT_CONFIG(linux_v4l) -void QGstreamerImageProcessing::initV4L2Controls() -{ - v4l2AutoWhiteBalanceSupported = false; - v4l2ColorTemperatureSupported = false; - - const QString deviceName = m_camera->v4l2Device(); - if (deviceName.isEmpty()) - return; - isV4L2Device = true; - - const int fd = qt_safe_open(deviceName.toLocal8Bit().constData(), O_RDONLY); - if (fd == -1) { - qWarning() << "Unable to open the camera" << deviceName - << "for read to query the parameter info:" << qt_error_string(errno); - return; - } - - struct v4l2_queryctrl queryControl; - ::memset(&queryControl, 0, sizeof(queryControl)); - queryControl.id = V4L2_CID_AUTO_WHITE_BALANCE; - - if (::ioctl(fd, VIDIOC_QUERYCTRL, &queryControl) == 0) { - v4l2AutoWhiteBalanceSupported = true; - struct v4l2_control control; - control.id = V4L2_CID_WHITE_BALANCE_TEMPERATURE; - control.value = true; - ::ioctl(fd, VIDIOC_S_CTRL, &control); - } - - ::memset(&queryControl, 0, sizeof(queryControl)); - queryControl.id = V4L2_CID_WHITE_BALANCE_TEMPERATURE; - if (::ioctl(fd, VIDIOC_QUERYCTRL, &queryControl) == 0) { - v4l2MinColorTemp = queryControl.minimum; - v4l2MaxColorTemp = queryControl.maximum; - v4l2CurrentColorTemp = queryControl.default_value; - v4l2ColorTemperatureSupported = true; - struct v4l2_control control; - control.id = V4L2_CID_WHITE_BALANCE_TEMPERATURE; - control.value = 0; - if (::ioctl(fd, VIDIOC_G_CTRL, &control) == 0) - v4l2CurrentColorTemp = control.value; - } - - qt_safe_close(fd); - -} - -bool QGstreamerImageProcessing::setV4L2Param(ProcessingParameter parameter, const QVariant &value) -{ - struct v4l2_control control; - ::memset(&control, 0, sizeof(control)); - - switch (parameter) { - case QPlatformCameraImageProcessing::WhiteBalancePreset: { - if (!v4l2AutoWhiteBalanceSupported) - return false; - const QCamera::WhiteBalanceMode mode = value.value<QCamera::WhiteBalanceMode>(); - if (mode != QCamera::WhiteBalanceAuto && mode != QCamera::WhiteBalanceManual) - return false; - control.id = V4L2_CID_AUTO_WHITE_BALANCE; - control.value = (mode == QCamera::WhiteBalanceAuto); - m_whiteBalanceMode = mode; - break; - } - case QPlatformCameraImageProcessing::ColorTemperature: - control.id = V4L2_CID_WHITE_BALANCE_TEMPERATURE; - control.value = qBound(v4l2MinColorTemp, value.toInt(), v4l2MaxColorTemp); - break; - default: - return false; - } - - if (!control.id) - return false; - - const int fd = qt_safe_open(m_camera->v4l2Device().toLocal8Bit().constData(), O_RDONLY); - if (fd == -1) { - qWarning() << "Unable to open the camera" << m_camera->v4l2Device() - << "for read to get the parameter value:" << qt_error_string(errno); - return false; - } - - if (::ioctl(fd, VIDIOC_S_CTRL, &control) != 0) { - qWarning() << "Unable to set the parameter value:" << parameter << ":" << qt_error_string(errno); - return false; - } - - qt_safe_close(fd); - return true; -} -#endif - - -QT_END_NAMESPACE diff --git a/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraimageprocessing_p.h b/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraimageprocessing_p.h deleted file mode 100644 index 171cb060f..000000000 --- a/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraimageprocessing_p.h +++ /dev/null @@ -1,111 +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 QGSTREAMERIMAGEPROCESSING_P_H -#define QGSTREAMERIMAGEPROCESSING_P_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 <QtMultimedia/private/qtmultimediaglobal_p.h> -#include <qcamera.h> -#include <private/qplatformcameraimageprocessing_p.h> - -#include <private/qgst_p.h> -#include <gst/video/colorbalance.h> - -#if QT_CONFIG(gstreamer_photography) -# include <gst/interfaces/photography.h> -#endif - -QT_BEGIN_NAMESPACE - -#if QT_CONFIG(linux_v4l) -class QGstreamerImageProcessingV4L2; -#endif - -class QGstreamerCamera; - -class QGstreamerImageProcessing : public QPlatformCameraImageProcessing -{ - Q_OBJECT - -public: - QGstreamerImageProcessing(QGstreamerCamera *camera); - virtual ~QGstreamerImageProcessing(); - - bool setWhiteBalanceMode(QCamera::WhiteBalanceMode mode); - bool isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const; - - bool isParameterSupported(ProcessingParameter) const override; - bool isParameterValueSupported(ProcessingParameter parameter, const QVariant &value) const override; - void setParameter(ProcessingParameter parameter, const QVariant &value) override; - - void update(); - -private: - QGstreamerCamera *m_camera; - QCamera::WhiteBalanceMode m_whiteBalanceMode = QCamera::WhiteBalanceAuto; - -#if QT_CONFIG(linux_v4l) - bool isV4L2Device = false; - void initV4L2Controls(); - bool setV4L2Param(ProcessingParameter parameter, const QVariant &value); - -public: -private: - bool v4l2AutoWhiteBalanceSupported = false; - bool v4l2ColorTemperatureSupported = false; - qint32 v4l2MinColorTemp = 5600; // Daylight... - qint32 v4l2MaxColorTemp = 5600; - qint32 v4l2CurrentColorTemp = 5600; -#endif -}; - -QT_END_NAMESPACE - -#endif // QGSTREAMERIMAGEPROCESSING_P_H diff --git a/src/multimedia/platform/qplatformcamera.cpp b/src/multimedia/platform/qplatformcamera.cpp index e1a6baac2..518ec0652 100644 --- a/src/multimedia/platform/qplatformcamera.cpp +++ b/src/multimedia/platform/qplatformcamera.cpp @@ -281,6 +281,49 @@ void QPlatformCamera::shutterSpeedChanged(float speed) emit m_camera->shutterSpeedChanged(speed); } +void QPlatformCamera::whiteBalanceModeChanged(QCamera::WhiteBalanceMode mode) +{ + if (m_whiteBalance == mode) + return; + m_whiteBalance = mode; + emit m_camera->whiteBalanceModeChanged(); +} + +void QPlatformCamera::colorTemperatureChanged(int temperature) +{ + Q_ASSERT(temperature >= 0); + Q_ASSERT((temperature > 0 && whiteBalanceMode() == QCamera::WhiteBalanceManual) || + (temperature == 0 && whiteBalanceMode() == QCamera::WhiteBalanceAuto)); + if (m_colorTemperature == temperature) + return; + m_colorTemperature = temperature; + emit m_camera->colorTemperatureChanged(); +} + +int QPlatformCamera::colorTemperatureForWhiteBalance(QCamera::WhiteBalanceMode mode) +{ + switch (mode) { + case QCamera::WhiteBalanceAuto: + break; + case QCamera::WhiteBalanceManual: + case QCamera::WhiteBalanceSunlight: + return 5600; + case QCamera::WhiteBalanceCloudy: + return 6000; + case QCamera::WhiteBalanceShade: + return 7000; + case QCamera::WhiteBalanceTungsten: + return 3200; + case QCamera::WhiteBalanceFluorescent: + return 4000; + case QCamera::WhiteBalanceFlash: + return 5500; + case QCamera::WhiteBalanceSunset: + return 3000; + } + return 0; +} + QT_END_NAMESPACE diff --git a/src/multimedia/platform/qplatformcamera_p.h b/src/multimedia/platform/qplatformcamera_p.h index df9c0d4aa..c895b22ad 100644 --- a/src/multimedia/platform/qplatformcamera_p.h +++ b/src/multimedia/platform/qplatformcamera_p.h @@ -58,9 +58,6 @@ QT_BEGIN_NAMESPACE -class QPlatformCameraExposure; -class QPlatformCameraImageProcessing; - class Q_MULTIMEDIA_EXPORT QPlatformCamera : public QObject { Q_OBJECT @@ -76,9 +73,6 @@ public: virtual void setCaptureSession(QPlatformMediaCaptureSession *) {} - virtual QPlatformCameraExposure *exposureControl() { return nullptr; } - virtual QPlatformCameraImageProcessing *imageProcessingControl() { return nullptr; } - virtual bool isFocusModeSupported(QCamera::FocusMode mode) const { return mode == QCamera::FocusModeAuto; } virtual void setFocusMode(QCamera::FocusMode /*mode*/) {} @@ -105,6 +99,10 @@ public: virtual void setManualShutterSpeed(float) {} virtual float shutterSpeed() const { return -1.; } + virtual bool isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const { return mode == QCamera::WhiteBalanceAuto; } + virtual void setWhiteBalanceMode(QCamera::WhiteBalanceMode /*mode*/) {} + virtual void setColorTemperature(int /*temperature*/) {} + QCamera::FocusMode focusMode() const { return m_focusMode; } QPointF focusPoint() const { return m_customFocusPoint; } @@ -125,6 +123,8 @@ public: float manualShutterSpeed() const { return m_shutterSpeed; } float minShutterSpeed() const { return m_minShutterSpeed; } float maxShutterSpeed() const { return m_maxShutterSpeed; } + QCamera::WhiteBalanceMode whiteBalanceMode() const { return m_whiteBalance; } + int colorTemperature() const { return m_colorTemperature; } void statusChanged(QCamera::Status); void minimumZoomFactorChanged(float factor); @@ -145,6 +145,10 @@ public: void shutterSpeedChanged(float speed); void minShutterSpeedChanged(float secs) { m_minShutterSpeed = secs; } void maxShutterSpeedChanged(float secs) { m_maxShutterSpeed = secs; } + void whiteBalanceModeChanged(QCamera::WhiteBalanceMode mode); + void colorTemperatureChanged(int temperature); + + static int colorTemperatureForWhiteBalance(QCamera::WhiteBalanceMode mode); Q_SIGNALS: void activeChanged(bool); @@ -176,6 +180,8 @@ private: float m_shutterSpeed = -1.; float m_minShutterSpeed = -1.; float m_maxShutterSpeed = -1.; + QCamera::WhiteBalanceMode m_whiteBalance = QCamera::WhiteBalanceAuto; + int m_colorTemperature = 0; }; QT_END_NAMESPACE diff --git a/src/multimedia/platform/qplatformcameraimageprocessing.cpp b/src/multimedia/platform/qplatformcameraimageprocessing.cpp deleted file mode 100644 index 11e22d48f..000000000 --- a/src/multimedia/platform/qplatformcameraimageprocessing.cpp +++ /dev/null @@ -1,147 +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 "qplatformcameraimageprocessing_p.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QPlatformCameraImageProcessing - \obsolete - \inmodule QtMultimedia - - - \ingroup multimedia_control - - - \brief The QPlatformCameraImageProcessing class provides an abstract class - for controlling image processing parameters, like white balance, - contrast, saturation. - - Camera service may choose the parameters of image processing pipeline depending - on sensor properties camera settings and capture parameters. - - This control allows to modify some parameters of image processing pipeline - to achieve desired results. - - Parameters with the "Adjustment" suffix, like ContrastAdjustment, SaturationAdjustment etc - allows to adjust the parameter values, selected by camera engine, - while parameters like Contrast and Saturation overwrites them. - - \sa QCamera -*/ - -/*! - Constructs an image processing control object with \a parent. -*/ - -QPlatformCameraImageProcessing::QPlatformCameraImageProcessing(QObject *parent) - : QObject(parent) -{ -} - -/*! - \fn bool QPlatformCameraImageProcessing::isParameterSupported(ProcessingParameter parameter) const - - Returns true if the camera supports adjusting image processing \a parameter. - - Usually the supported setting is static, - but some parameters may not be available depending on other - camera settings, like presets. - In such case the currently supported parameters should be returned. -*/ - -/*! - \fn bool QPlatformCameraImageProcessing::isParameterValueSupported(ProcessingParameter parameter, const QVariant &value) const - - Returns true if the camera supports setting the image processing \a parameter \a value. - - It's used only for parameters with a limited set of values, like WhiteBalancePreset. -*/ - - -/*! - \fn QPlatformCameraImageProcessing::parameter(ProcessingParameter parameter) const - - Returns the image processing \a parameter value. -*/ - -/*! - \fn QPlatformCameraImageProcessing::setParameter(ProcessingParameter parameter, const QVariant &value) - - Sets the image processing \a parameter \a value. - Passing the null or invalid QVariant value allows - backend to choose the suitable parameter value. - - The valid values range depends on the parameter type. - For WhiteBalancePreset the value should be one of QCamera::WhiteBalanceMode values; - for Contrast, Saturation and Brightness the value should be in [0..1.0] range with invalid QVariant - value indicating the default parameter value; - for ContrastAdjustment, SaturationAdjustment, BrightnessAdjustment, the value should be - in [-1.0..1.0] range with default 0. -*/ - -/*! - \enum QPlatformCameraImageProcessing::ProcessingParameter - - \value WhiteBalancePreset - The white balance preset. - \value ColorTemperature - Color temperature in K. This value is used when the manual white balance mode is selected. - \value Contrast - Image contrast. - \value Saturation - Image saturation. - \value Brightness - Image brightness. - \value ContrastAdjustment - Image contrast adjustment. - \value SaturationAdjustment - Image saturation adjustment. - \value BrightnessAdjustment - Image brightness adjustment. - \value ColorFilter - Image filter applied. Since 5.5 - \value ExtendedParameter - The base value for platform specific extended parameters. - */ - -QT_END_NAMESPACE - -#include "moc_qplatformcameraimageprocessing_p.cpp" diff --git a/src/multimedia/platform/qplatformcameraimageprocessing_p.h b/src/multimedia/platform/qplatformcameraimageprocessing_p.h deleted file mode 100644 index 000939e95..000000000 --- a/src/multimedia/platform/qplatformcameraimageprocessing_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 QCAMERAIMAGEPROCESSINGCONTROL_H -#define QCAMERAIMAGEPROCESSINGCONTROL_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 QPlatformCameraImageProcessing : public QObject -{ - Q_OBJECT - Q_ENUMS(ProcessingParameter) - -public: - enum ProcessingParameter { - WhiteBalancePreset, - ColorTemperature - }; - - virtual bool isParameterSupported(ProcessingParameter) const = 0; - virtual bool isParameterValueSupported(ProcessingParameter parameter, const QVariant &value) const = 0; - virtual void setParameter(ProcessingParameter parameter, const QVariant &value) = 0; - -protected: - explicit QPlatformCameraImageProcessing(QObject *parent = nullptr); -}; - -QT_END_NAMESPACE - -Q_MEDIA_ENUM_DEBUG(QPlatformCameraImageProcessing, ProcessingParameter) - -#endif - diff --git a/src/multimedia/platform/windows/mediacapture/qwindowscamera.cpp b/src/multimedia/platform/windows/mediacapture/qwindowscamera.cpp index a6cd0e6cc..675290a71 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 "qwindowscameraimageprocessing_p.h" #include "qwindowsmediacapture_p.h" #include <qcamerainfo.h> @@ -121,11 +120,4 @@ void QWindowsCamera::setCaptureSession(QPlatformMediaCaptureSession *session) m_cameraSession->setActiveCamera(m_cameraInfo); } -QPlatformCameraImageProcessing *QWindowsCamera::imageProcessingControl() -{ - if (!m_cameraSession) - return nullptr; - return m_cameraSession->imageProcessingControl(); -} - QT_END_NAMESPACE diff --git a/src/multimedia/platform/windows/mediacapture/qwindowscamera_p.h b/src/multimedia/platform/windows/mediacapture/qwindowscamera_p.h index 63b9ff84c..7524c3357 100644 --- a/src/multimedia/platform/windows/mediacapture/qwindowscamera_p.h +++ b/src/multimedia/platform/windows/mediacapture/qwindowscamera_p.h @@ -74,8 +74,6 @@ public: void setCaptureSession(QPlatformMediaCaptureSession *) override; - QPlatformCameraImageProcessing *imageProcessingControl() override; - private Q_SLOTS: void updateStatus(); diff --git a/src/multimedia/platform/windows/mediacapture/qwindowscameraimageprocessing.cpp b/src/multimedia/platform/windows/mediacapture/qwindowscameraimageprocessing.cpp deleted file mode 100644 index 399cc7fe7..000000000 --- a/src/multimedia/platform/windows/mediacapture/qwindowscameraimageprocessing.cpp +++ /dev/null @@ -1,65 +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 "qwindowscameraimageprocessing_p.h" - -QT_BEGIN_NAMESPACE - -QWindowsCameraImageProcessing::QWindowsCameraImageProcessing(QWindowsCameraSession *session) - : m_session(session) -{ - Q_ASSERT(m_session); -} - -bool QWindowsCameraImageProcessing::isParameterSupported(ProcessingParameter parameter) const -{ - return false; -} - -bool QWindowsCameraImageProcessing::isParameterValueSupported(ProcessingParameter parameter, - const QVariant &value) const -{ - return false; -} - -void QWindowsCameraImageProcessing::setParameter(ProcessingParameter parameter, const QVariant &value) -{ -} - -QT_END_NAMESPACE diff --git a/src/multimedia/platform/windows/mediacapture/qwindowscameraimageprocessing_p.h b/src/multimedia/platform/windows/mediacapture/qwindowscameraimageprocessing_p.h deleted file mode 100644 index e58b7098f..000000000 --- a/src/multimedia/platform/windows/mediacapture/qwindowscameraimageprocessing_p.h +++ /dev/null @@ -1,76 +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 QWINDOWSCAMERAIMAGEPROCESSING_H -#define QWINDOWSCAMERAIMAGEPROCESSING_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/qplatformcameraimageprocessing_p.h> - -QT_BEGIN_NAMESPACE - -class QWindowsCameraSession; - -class QWindowsCameraImageProcessing : public QPlatformCameraImageProcessing -{ - Q_OBJECT -public: - explicit QWindowsCameraImageProcessing(QWindowsCameraSession *session); - - bool isParameterSupported(ProcessingParameter) const override; - bool isParameterValueSupported(ProcessingParameter parameter, const QVariant &value) const override; - void setParameter(ProcessingParameter parameter, const QVariant &value) override; - -private: - QWindowsCameraSession *m_session; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/multimedia/platform/windows/mediacapture/qwindowscamerasession.cpp b/src/multimedia/platform/windows/mediacapture/qwindowscamerasession.cpp index 2177e6c5f..ae5c79dec 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 "qwindowscameraimageprocessing_p.h" #include "qwindowsmultimediautils_p.h" #include <qvideosink.h> #include <QtCore/qdebug.h> @@ -51,7 +50,6 @@ QWindowsCameraSession::QWindowsCameraSession(QObject *parent) : QObject(parent) { m_cameraReader = new QWindowsCameraReader(this); - m_cameraImageProcessing = new QWindowsCameraImageProcessing(this); connect(m_cameraReader, SIGNAL(streamingStarted()), this, SLOT(handleStreamingStarted())); connect(m_cameraReader, SIGNAL(streamingStopped()), this, SLOT(handleStreamingStopped())); connect(m_cameraReader, SIGNAL(recordingStarted()), this, SIGNAL(recordingStarted())); @@ -61,7 +59,6 @@ QWindowsCameraSession::QWindowsCameraSession(QObject *parent) QWindowsCameraSession::~QWindowsCameraSession() { - delete m_cameraImageProcessing; delete m_cameraReader; } @@ -124,11 +121,6 @@ void QWindowsCameraSession::setVideoSink(QVideoSink *surface) m_cameraReader->setSurface(surface); } -QWindowsCameraImageProcessing *QWindowsCameraSession::imageProcessingControl() -{ - return m_cameraImageProcessing; -} - void QWindowsCameraSession::handleStreamingStarted() { m_active = true; diff --git a/src/multimedia/platform/windows/mediacapture/qwindowscamerasession_p.h b/src/multimedia/platform/windows/mediacapture/qwindowscamerasession_p.h index ca4e31cd2..21b14608f 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 QWindowsCameraImageProcessing; class QWindowsCameraSession : public QObject { @@ -84,8 +83,6 @@ public: void setVideoSink(QVideoSink *surface); - QWindowsCameraImageProcessing *imageProcessingControl(); - QMediaEncoderSettings videoSettings() const; void setVideoSettings(const QMediaEncoderSettings &settings); @@ -112,7 +109,6 @@ private: bool m_readyForCapture = false; QCameraInfo m_activeCameraInfo; QWindowsCameraReader *m_cameraReader = 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 3d1b970b5..4c5f6c251 100644 --- a/tests/auto/integration/qcamerabackend/tst_qcamerabackend.cpp +++ b/tests/auto/integration/qcamerabackend/tst_qcamerabackend.cpp @@ -34,7 +34,6 @@ #include <private/qplatformcamera_p.h> #include <private/qplatformcameraimagecapture_p.h> -#include <private/qplatformcameraimageprocessing_p.h> #include <qcamera.h> #include <qcamerainfo.h> #include <qcameraimagecapture.h> diff --git a/tests/auto/unit/mockbackend/CMakeLists.txt b/tests/auto/unit/mockbackend/CMakeLists.txt index 0c471e7f1..8f43aafdd 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 - qmockcameraimageprocessing.h qmockimagecapture.h qmockimagecapture.cpp qmockmediaplayer.h qmockmediaencoder.h diff --git a/tests/auto/unit/mockbackend/qmockcamera.h b/tests/auto/unit/mockbackend/qmockcamera.h index 5ccf79e2f..b5fe3f745 100644 --- a/tests/auto/unit/mockbackend/qmockcamera.h +++ b/tests/auto/unit/mockbackend/qmockcamera.h @@ -31,7 +31,6 @@ #include "private/qplatformcamera_p.h" #include "qcamerainfo.h" -#include "qmockcameraimageprocessing.h" #include <qtimer.h> class QMockCamera : public QPlatformCamera @@ -53,7 +52,6 @@ public: m_propertyChangesSupported(false) { if (!simpleCamera) { - mockImageProcessing = new QMockCameraImageProcessing(this); minIsoChanged(100); maxIsoChanged(800); minShutterSpeedChanged(.001); @@ -164,14 +162,29 @@ public: return manualShutterSpeed() > 0 ? manualShutterSpeed() : .05; } - QPlatformCameraImageProcessing *imageProcessingControl() override { return mockImageProcessing; } + bool isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const override + { + if (simpleCamera) + return mode == QCamera::WhiteBalanceAuto; + return mode == QCamera::WhiteBalanceAuto || + mode == QCamera::WhiteBalanceManual || + mode == QCamera::WhiteBalanceSunlight; + } + void setWhiteBalanceMode(QCamera::WhiteBalanceMode mode) override + { + if (isWhiteBalanceModeSupported(mode)) + whiteBalanceModeChanged(mode); + } + void setColorTemperature(int temperature) override + { + if (!simpleCamera) + colorTemperatureChanged(temperature); + } bool m_active = false; QCamera::Status m_status; QCameraInfo m_camera; bool m_propertyChangesSupported; - - QMockCameraImageProcessing *mockImageProcessing = nullptr; }; diff --git a/tests/auto/unit/mockbackend/qmockcameraimageprocessing.h b/tests/auto/unit/mockbackend/qmockcameraimageprocessing.h deleted file mode 100644 index 3de32002a..000000000 --- a/tests/auto/unit/mockbackend/qmockcameraimageprocessing.h +++ /dev/null @@ -1,104 +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 MOCKCAMERAIMAGEPROCESSINGCONTROL_H -#define MOCKCAMERAIMAGEPROCESSINGCONTROL_H - -#include "private/qplatformcameraimageprocessing_p.h" - -class QMockCameraImageProcessing : public QPlatformCameraImageProcessing -{ - Q_OBJECT -public: - QMockCameraImageProcessing(QObject *parent = 0) - : QPlatformCameraImageProcessing(parent) - { - m_supportedWhiteBalance.insert(QCamera::WhiteBalanceAuto); - } - - QCamera::WhiteBalanceMode whiteBalanceMode() const - { - return m_whiteBalanceMode; - } - void setWhiteBalanceMode(QCamera::WhiteBalanceMode mode) - { - m_whiteBalanceMode = mode; - } - - bool isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const - { - return m_supportedWhiteBalance.contains(mode); - } - - void setSupportedWhiteBalanceModes(QSet<QCamera::WhiteBalanceMode> modes) - { - m_supportedWhiteBalance = modes; - } - - bool isParameterSupported(ProcessingParameter parameter) const - { - switch (parameter) - { - case ColorTemperature: - case WhiteBalancePreset: - return true; - default : - return false; - } - } - - bool isParameterValueSupported(ProcessingParameter parameter, const QVariant &value) const - { - if (parameter != WhiteBalancePreset) - return false; - - return m_supportedWhiteBalance.contains(value.value<QCamera::WhiteBalanceMode>()); - } - - void setParameter(ProcessingParameter parameter, const QVariant &value) - { - switch (parameter) { - case ColorTemperature: - m_manualWhiteBalance = value; - break; - case WhiteBalancePreset: - m_whiteBalanceMode = value.value<QCamera::WhiteBalanceMode>(); - break; - default: - break; - } - } - - -private: - QCamera::WhiteBalanceMode m_whiteBalanceMode; - QSet<QCamera::WhiteBalanceMode> m_supportedWhiteBalance; - QVariant m_manualWhiteBalance; -}; - -#endif // MOCKCAMERAIMAGEPROCESSINGCONTROL_H diff --git a/tests/auto/unit/multimedia/qcamera/tst_qcamera.cpp b/tests/auto/unit/multimedia/qcamera/tst_qcamera.cpp index 08202be51..9265f0799 100644 --- a/tests/auto/unit/multimedia/qcamera/tst_qcamera.cpp +++ b/tests/auto/unit/multimedia/qcamera/tst_qcamera.cpp @@ -34,7 +34,6 @@ #include <qvideosink.h> #include <private/qplatformcamera_p.h> #include <private/qplatformcameraimagecapture_p.h> -#include <private/qplatformcameraimageprocessing_p.h> #include <qcamera.h> #include <qcamerainfo.h> #include <qcameraimagecapture.h> @@ -134,14 +133,15 @@ void tst_QCamera::testSimpleCameraWhiteBalance() QCamera camera; //only WhiteBalanceAuto is supported - QVERIFY(!camera.isWhiteBalanceModeSupported(QCamera::WhiteBalanceAuto)); + QVERIFY(camera.isWhiteBalanceModeSupported(QCamera::WhiteBalanceAuto)); + QVERIFY(!camera.isWhiteBalanceModeSupported(QCamera::WhiteBalanceManual)); QVERIFY(!camera.isWhiteBalanceModeSupported(QCamera::WhiteBalanceCloudy)); QCOMPARE(camera.whiteBalanceMode(), QCamera::WhiteBalanceAuto); camera.setWhiteBalanceMode(QCamera::WhiteBalanceCloudy); QCOMPARE(camera.whiteBalanceMode(), QCamera::WhiteBalanceAuto); - QCOMPARE(camera.manualWhiteBalance()+1.0, 1.0); - camera.setManualWhiteBalance(5000); - QCOMPARE(camera.manualWhiteBalance()+1.0, 1.0); + QCOMPARE(camera.colorTemperature(), 0); + camera.setColorTemperature(5000); + QCOMPARE(camera.colorTemperature(), 0); } void tst_QCamera::testSimpleCameraExposure() @@ -296,34 +296,36 @@ void tst_QCamera::testCameraCaptureMetadata() void tst_QCamera::testCameraWhiteBalance() { - QSet<QCamera::WhiteBalanceMode> whiteBalanceModes; - whiteBalanceModes << QCamera::WhiteBalanceAuto; - whiteBalanceModes << QCamera::WhiteBalanceFlash; - whiteBalanceModes << QCamera::WhiteBalanceTungsten; - whiteBalanceModes << QCamera::WhiteBalanceManual; - QCamera camera; - QMockCamera *mockCamera = integration.lastCamera(); - mockCamera->mockImageProcessing->setSupportedWhiteBalanceModes(whiteBalanceModes); QCOMPARE(camera.whiteBalanceMode(), QCamera::WhiteBalanceAuto); camera.setWhiteBalanceMode(QCamera::WhiteBalanceFlash); - QCOMPARE(camera.whiteBalanceMode(), QCamera::WhiteBalanceFlash); + QCOMPARE(camera.whiteBalanceMode(), QCamera::WhiteBalanceAuto); QVERIFY(camera.isWhiteBalanceModeSupported(QCamera::WhiteBalanceAuto)); - QVERIFY(camera.isWhiteBalanceModeSupported(QCamera::WhiteBalanceFlash)); - QVERIFY(camera.isWhiteBalanceModeSupported(QCamera::WhiteBalanceTungsten)); + QVERIFY(camera.isWhiteBalanceModeSupported(QCamera::WhiteBalanceManual)); + QVERIFY(camera.isWhiteBalanceModeSupported(QCamera::WhiteBalanceSunlight)); QVERIFY(!camera.isWhiteBalanceModeSupported(QCamera::WhiteBalanceCloudy)); - camera.setWhiteBalanceMode(QCamera::WhiteBalanceTungsten); - QCOMPARE(camera.whiteBalanceMode(), QCamera::WhiteBalanceTungsten); + camera.setWhiteBalanceMode(QCamera::WhiteBalanceSunlight); + QCOMPARE(camera.whiteBalanceMode(), QCamera::WhiteBalanceSunlight); camera.setWhiteBalanceMode(QCamera::WhiteBalanceManual); QCOMPARE(camera.whiteBalanceMode(), QCamera::WhiteBalanceManual); - camera.setManualWhiteBalance(34); - QCOMPARE(camera.manualWhiteBalance(), 34.0); + camera.setColorTemperature(4000); + QCOMPARE(camera.colorTemperature(), 4000); + + camera.setColorTemperature(8000); + QCOMPARE(camera.colorTemperature(), 8000); + + camera.setWhiteBalanceMode(QCamera::WhiteBalanceAuto); + QCOMPARE(camera.whiteBalanceMode(), QCamera::WhiteBalanceAuto); + camera.setColorTemperature(4000); + QCOMPARE(camera.colorTemperature(), 4000); + QCOMPARE(camera.whiteBalanceMode(), QCamera::WhiteBalanceManual); - camera.setManualWhiteBalance(432.0); - QCOMPARE(camera.manualWhiteBalance(), 432.0); + camera.setColorTemperature(0); + QCOMPARE(camera.colorTemperature(), 0); + QCOMPARE(camera.whiteBalanceMode(), QCamera::WhiteBalanceAuto); } void tst_QCamera::testCameraExposure() @@ -385,7 +387,6 @@ void tst_QCamera::testCameraExposure() qreal minShutterSpeed = camera.minimumShutterSpeed(); qreal maxShutterSpeed = camera.maximumShutterSpeed(); - qDebug() << minShutterSpeed << maxShutterSpeed; QVERIFY(minShutterSpeed > 0); QVERIFY(maxShutterSpeed > 0); QVERIFY(camera.shutterSpeed() >= minShutterSpeed); diff --git a/tests/auto/unit/multimedia/qcameraimagecapture/tst_qcameraimagecapture.cpp b/tests/auto/unit/multimedia/qcameraimagecapture/tst_qcameraimagecapture.cpp index 2b11636c0..3fda9b0de 100644 --- a/tests/auto/unit/multimedia/qcameraimagecapture/tst_qcameraimagecapture.cpp +++ b/tests/auto/unit/multimedia/qcameraimagecapture/tst_qcameraimagecapture.cpp @@ -31,7 +31,6 @@ #include <private/qplatformcamera_p.h> #include <private/qplatformcameraimagecapture_p.h> -#include <private/qplatformcameraimageprocessing_p.h> #include <qcamera.h> #include <qcameraimagecapture.h> #include <qmediacapturesession.h> diff --git a/tests/auto/unit/multimediawidgets/qcamerawidgets/tst_qcamerawidgets.cpp b/tests/auto/unit/multimediawidgets/qcamerawidgets/tst_qcamerawidgets.cpp index 00cfc1646..757a8c805 100644 --- a/tests/auto/unit/multimediawidgets/qcamerawidgets/tst_qcamerawidgets.cpp +++ b/tests/auto/unit/multimediawidgets/qcamerawidgets/tst_qcamerawidgets.cpp @@ -33,7 +33,6 @@ #include <private/qplatformcamera_p.h> #include <private/qplatformcameraimagecapture_p.h> -#include <private/qplatformcameraimageprocessing_p.h> #include <qmediacapturesession.h> #include <qcamera.h> #include <qcameraimagecapture.h> |