diff options
Diffstat (limited to 'src/plugins/directshow/camera')
28 files changed, 0 insertions, 4209 deletions
diff --git a/src/plugins/directshow/camera/camera.pri b/src/plugins/directshow/camera/camera.pri deleted file mode 100644 index 3be1acc49..000000000 --- a/src/plugins/directshow/camera/camera.pri +++ /dev/null @@ -1,37 +0,0 @@ -INCLUDEPATH += $$PWD - -win32: DEFINES += _CRT_SECURE_NO_WARNINGS - -HEADERS += \ - $$PWD/dscameraservice.h \ - $$PWD/dscameracontrol.h \ - $$PWD/dsvideorenderer.h \ - $$PWD/dsvideodevicecontrol.h \ - $$PWD/dsimagecapturecontrol.h \ - $$PWD/dscamerasession.h \ - $$PWD/directshowcameraglobal.h \ - $$PWD/dscameraviewfindersettingscontrol.h \ - $$PWD/dscameraimageprocessingcontrol.h \ - $$PWD/directshowcameraexposurecontrol.h \ - $$PWD/directshowcameracapturedestinationcontrol.h \ - $$PWD/directshowcameracapturebufferformatcontrol.h \ - $$PWD/directshowcamerazoomcontrol.h \ - $$PWD/directshowcameraimageencodercontrol.h - -SOURCES += \ - $$PWD/dscameraservice.cpp \ - $$PWD/dscameracontrol.cpp \ - $$PWD/dsvideorenderer.cpp \ - $$PWD/dsvideodevicecontrol.cpp \ - $$PWD/dsimagecapturecontrol.cpp \ - $$PWD/dscamerasession.cpp \ - $$PWD/dscameraviewfindersettingscontrol.cpp \ - $$PWD/dscameraimageprocessingcontrol.cpp \ - $$PWD/directshowcameraexposurecontrol.cpp \ - $$PWD/directshowcameracapturedestinationcontrol.cpp \ - $$PWD/directshowcameracapturebufferformatcontrol.cpp \ - $$PWD/directshowcamerazoomcontrol.cpp \ - $$PWD/directshowcameraimageencodercontrol.cpp - -*-msvc*:INCLUDEPATH += $$(DXSDK_DIR)/include -QMAKE_USE += directshow diff --git a/src/plugins/directshow/camera/directshowcameracapturebufferformatcontrol.cpp b/src/plugins/directshow/camera/directshowcameracapturebufferformatcontrol.cpp deleted file mode 100644 index cc0a0ad17..000000000 --- a/src/plugins/directshow/camera/directshowcameracapturebufferformatcontrol.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 "directshowcameracapturebufferformatcontrol.h" - -#include "dscamerasession.h" - -QT_BEGIN_NAMESPACE - -DirectShowCameraCaptureBufferFormatControl::DirectShowCameraCaptureBufferFormatControl() -{ -} - -QList<QVideoFrame::PixelFormat> DirectShowCameraCaptureBufferFormatControl::supportedBufferFormats() const -{ - return QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_RGB32; -} - -QVideoFrame::PixelFormat DirectShowCameraCaptureBufferFormatControl::bufferFormat() const -{ - return QVideoFrame::Format_RGB32; -} - -void DirectShowCameraCaptureBufferFormatControl::setBufferFormat(QVideoFrame::PixelFormat format) -{ - Q_UNUSED(format); -} - -QT_END_NAMESPACE diff --git a/src/plugins/directshow/camera/directshowcameracapturebufferformatcontrol.h b/src/plugins/directshow/camera/directshowcameracapturebufferformatcontrol.h deleted file mode 100644 index cacd3652b..000000000 --- a/src/plugins/directshow/camera/directshowcameracapturebufferformatcontrol.h +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 DIRECTSHOWCAMERACAPTUREBUFFERFORMATCONTROL_H -#define DIRECTSHOWCAMERACAPTUREBUFFERFORMATCONTROL_H - -#include <QtMultimedia/qcameracapturebufferformatcontrol.h> - -QT_BEGIN_NAMESPACE - -class DirectShowCameraCaptureBufferFormatControl : public QCameraCaptureBufferFormatControl -{ - Q_OBJECT -public: - DirectShowCameraCaptureBufferFormatControl(); - - QList<QVideoFrame::PixelFormat> supportedBufferFormats() const override; - QVideoFrame::PixelFormat bufferFormat() const override; - void setBufferFormat(QVideoFrame::PixelFormat format) override; -}; - -QT_END_NAMESPACE - -#endif // DIRECTSHOWCAMERACAPTUREBUFFERFORMATCONTROL_H diff --git a/src/plugins/directshow/camera/directshowcameracapturedestinationcontrol.cpp b/src/plugins/directshow/camera/directshowcameracapturedestinationcontrol.cpp deleted file mode 100644 index bfb10fc03..000000000 --- a/src/plugins/directshow/camera/directshowcameracapturedestinationcontrol.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 "directshowcameracapturedestinationcontrol.h" - -#include "dscamerasession.h" - -QT_BEGIN_NAMESPACE - -DirectShowCameraCaptureDestinationControl::DirectShowCameraCaptureDestinationControl(DSCameraSession *session) - : m_session(session) -{ - connect(m_session, &DSCameraSession::captureDestinationChanged, - this, &DirectShowCameraCaptureDestinationControl::captureDestinationChanged); -} - -bool DirectShowCameraCaptureDestinationControl::isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const -{ - return m_session->isCaptureDestinationSupported(destination); -} - -QCameraImageCapture::CaptureDestinations DirectShowCameraCaptureDestinationControl::captureDestination() const -{ - return m_session->captureDestination(); -} - -void DirectShowCameraCaptureDestinationControl::setCaptureDestination(QCameraImageCapture::CaptureDestinations destination) -{ - m_session->setCaptureDestination(destination); -} - -QT_END_NAMESPACE diff --git a/src/plugins/directshow/camera/directshowcameracapturedestinationcontrol.h b/src/plugins/directshow/camera/directshowcameracapturedestinationcontrol.h deleted file mode 100644 index 224df9dbc..000000000 --- a/src/plugins/directshow/camera/directshowcameracapturedestinationcontrol.h +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 DIRECTSHOWCAMERACAPTUREDESTINATIONCONTROL_H -#define DIRECTSHOWCAMERACAPTUREDESTINATIONCONTROL_H - -#include <QtMultimedia/qcameracapturedestinationcontrol.h> - -QT_BEGIN_NAMESPACE - -class DSCameraSession; - -class DirectShowCameraCaptureDestinationControl : public QCameraCaptureDestinationControl -{ - Q_OBJECT -public: - DirectShowCameraCaptureDestinationControl(DSCameraSession *session); - - bool isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const override; - QCameraImageCapture::CaptureDestinations captureDestination() const override; - void setCaptureDestination(QCameraImageCapture::CaptureDestinations destination) override; - -private: - DSCameraSession *m_session; - -}; - -QT_END_NAMESPACE - -#endif // DIRECTSHOWCAMERACAPTUREDESTINATIONCONTROL_H diff --git a/src/plugins/directshow/camera/directshowcameraexposurecontrol.cpp b/src/plugins/directshow/camera/directshowcameraexposurecontrol.cpp deleted file mode 100644 index 6f138450c..000000000 --- a/src/plugins/directshow/camera/directshowcameraexposurecontrol.cpp +++ /dev/null @@ -1,413 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 "directshowcameraexposurecontrol.h" -#include "dscamerasession.h" -#include "directshowglobal.h" -#include "directshowutils.h" - -#include <functional> -#include <cmath> - -QT_BEGIN_NAMESPACE - -static qreal convertToSec(long v) { return (v < 0) ? (1 / std::pow(2., qreal(v))) : std::pow(2., qreal(v)); } -static Q_DECL_CONSTEXPR qreal convertToFvalue(long v) { return qreal(v) / 10.; } - -DirectShowCameraExposureControl::DirectShowCameraExposureControl(DSCameraSession *session) - : m_session(session) - , m_shutterSpeedValues({ 0, 0, 0, 0, 0 }) - , m_apertureValues({ 0, 0, 0, 0, 0 }) - , m_requestedShutterSpeed(qreal(0.0)) - , m_currentShutterSpeed(qreal(-1.0)) - , m_requestedAperture(qreal(0.0)) - , m_currentAperture(qreal(-1.0)) - , m_requestedExposureMode(QCameraExposure::ExposureAuto) - , m_currentExposureMode(QCameraExposure::ExposureAuto) -{ - Q_ASSERT(m_session); - connect(m_session, &DSCameraSession::statusChanged, - this, &DirectShowCameraExposureControl::onStatusChanged); -} - -bool DirectShowCameraExposureControl::isParameterSupported(QCameraExposureControl::ExposureParameter parameter) const -{ - switch (parameter) { - case QCameraExposureControl::Aperture: - return (m_apertureValues.caps & CameraControl_Flags_Manual); - case QCameraExposureControl::ShutterSpeed: - return (m_shutterSpeedValues.caps & CameraControl_Flags_Manual); - case QCameraExposureControl::ExposureMode: - return true; - default: - break; - } - return false; -} - -QVariantList DirectShowCameraExposureControl::supportedParameterRange(QCameraExposureControl::ExposureParameter parameter, - bool *continuous) const -{ - if (continuous) - *continuous = false; - - if (parameter == ShutterSpeed) - return m_supportedShutterSpeeds; - - if (parameter == Aperture) - return m_supportedApertureValues; - - if (parameter == ExposureMode) - return m_supportedExposureModes; - - return QVariantList(); -} - -QVariant DirectShowCameraExposureControl::requestedValue(QCameraExposureControl::ExposureParameter parameter) const -{ - if (parameter == ShutterSpeed) - return QVariant::fromValue(m_requestedShutterSpeed); - - if (parameter == Aperture) - return QVariant::fromValue(m_requestedAperture); - - if (parameter == ExposureMode) - return QVariant::fromValue(m_requestedExposureMode); - - return QVariant(); -} - -QVariant DirectShowCameraExposureControl::actualValue(QCameraExposureControl::ExposureParameter parameter) const -{ - if (parameter == ExposureMode) - return QVariant::fromValue(m_currentExposureMode); - - if (parameter == ShutterSpeed) { - return qFuzzyCompare(m_currentShutterSpeed, qreal(-1.0)) - ? QVariant() - : QVariant::fromValue(m_currentShutterSpeed); - } - - if (parameter == Aperture) { - return qFuzzyCompare(m_currentAperture, qreal(-1.0)) - ? QVariant() - : QVariant::fromValue(m_currentAperture); - } - - return QVariant(); -} - -bool DirectShowCameraExposureControl::setValue(QCameraExposureControl::ExposureParameter parameter, - const QVariant &value) -{ - IAMCameraControl *cameraControl = nullptr; - const DirectShowUtils::ScopedSafeRelease<IAMCameraControl> rControl { &cameraControl }; - if (!m_session->getCameraControlInterface(&cameraControl)) - return false; - - // Reset exposure mode if the value is invalid. - if (!value.isValid()) { - m_requestedExposureMode = QCameraExposure::ExposureAuto; - return setExposureMode(cameraControl, m_requestedExposureMode); - } - - if (parameter == ShutterSpeed || parameter == Aperture) { - bool ok = false; - const qreal newValue = value.toReal(&ok); - if (!ok) - return false; - - // Change the exposure mode first - setExposureMode(cameraControl, QCameraExposure::ExposureManual); - - if (parameter == ShutterSpeed) { - m_requestedShutterSpeed = newValue; - return setShutterSpeed(cameraControl, m_requestedShutterSpeed); - } - m_requestedAperture = newValue; - return setAperture(cameraControl, m_requestedAperture); - } - - if (parameter == ExposureMode) { - m_requestedExposureMode = value.value<QCameraExposure::ExposureMode>(); - return setExposureMode(cameraControl, m_requestedExposureMode); - } - - return false; -} - -void DirectShowCameraExposureControl::onStatusChanged(QCamera::Status status) -{ - const bool shouldUpdate = (qFuzzyCompare(m_currentAperture, qreal(-1.0)) && qFuzzyCompare(m_currentShutterSpeed, qreal(-1.0))); - - if (status == QCamera::LoadedStatus && shouldUpdate) - updateExposureSettings(); - - if (status == QCamera::UnloadedStatus) { - m_supportedApertureValues.clear(); - m_supportedExposureModes.clear(); - m_supportedShutterSpeeds.clear(); - m_currentAperture = qreal(-1.0); - m_currentShutterSpeed = qreal(-1.0); - m_currentExposureMode = QCameraExposure::ExposureAuto; - } -} - -void DirectShowCameraExposureControl::updateExposureSettings() -{ - IAMCameraControl *cameraControl = nullptr; - const DirectShowUtils::ScopedSafeRelease<IAMCameraControl> rControl { &cameraControl }; - if (!m_session->getCameraControlInterface(&cameraControl)) - return; - - const auto updateValues = [cameraControl](long property, - ExposureValues ¤tValues, - QVariantList ¶meterRange, - const std::function<qreal(long)> &converter, - bool *changed) -> bool { - ExposureValues values { 0, 0, 0, 0, 0 }; - if (FAILED(cameraControl->GetRange(property, - &values.minValue, - &values.maxValue, - &values.stepping, - &values.defaultValue, - &values.caps))) { - return false; - } - - const bool minValueChanged = values.minValue != currentValues.minValue; - const bool maxValueChanged = values.maxValue != currentValues.maxValue; - const bool steppingChanged = values.stepping != currentValues.stepping; - - if (minValueChanged || maxValueChanged || steppingChanged) { - parameterRange.clear(); - long nextValue = values.minValue; - while (nextValue != values.maxValue && values.stepping != 0) { - parameterRange << converter(nextValue); - nextValue += values.stepping; - } - - if (changed) - *changed = true; - } - - currentValues = values; - return true; - }; - - const auto getCurrentValue = [cameraControl](long property, const std::function<qreal(long)> &converter, qreal *value) -> bool { - long currentValue; - long currentFlags; - if (FAILED(cameraControl->Get(property, ¤tValue, ¤tFlags))) - return false; - - *value = converter(currentValue); - return true; - }; - - // Shutter speed - bool changed = false; - if (!updateValues(CameraControl_Exposure, m_shutterSpeedValues, m_supportedShutterSpeeds, convertToSec, &changed)) - qCDebug(qtDirectShowPlugin, "Unable to update the shutter speed values"); - - if (changed) - Q_EMIT parameterRangeChanged(int(ShutterSpeed)); - - if ((m_shutterSpeedValues.caps & CameraControl_Flags_Manual)) { - if (getCurrentValue(CameraControl_Exposure, convertToSec, &m_currentShutterSpeed)) { - if (m_currentExposureMode == QCameraExposure::ExposureManual) - setShutterSpeed(cameraControl, m_requestedShutterSpeed); - } else { - m_currentShutterSpeed = qreal(-1.0); - qCDebug(qtDirectShowPlugin, "Unable to get the current shutter speed!"); - } - } - - // Aperture - changed = false; - if (!updateValues(CameraControl_Iris, m_apertureValues, m_supportedApertureValues, convertToFvalue, &changed)) - qCDebug(qtDirectShowPlugin, "Unable to update the aperture values"); - - if (changed) - Q_EMIT parameterRangeChanged(int(Aperture)); - - if (getCurrentValue(CameraControl_Iris, convertToFvalue, &m_currentAperture)) { - if (m_currentExposureMode == QCameraExposure::ExposureManual) - setAperture(cameraControl, m_requestedAperture); - } else { - m_currentAperture = qreal(-1.0); - qCDebug(qtDirectShowPlugin, "Unable to get the current aperture value!"); - } - - // Update exposure modes - const bool hasAutoExposure = (m_apertureValues.caps & CameraControl_Flags_Auto) - || (m_shutterSpeedValues.caps & CameraControl_Flags_Auto); - const bool hasManualExposure = (m_apertureValues.caps & CameraControl_Flags_Manual) - || (m_shutterSpeedValues.caps & CameraControl_Flags_Manual); - - QVariantList exposureModes; - if (hasAutoExposure && !m_supportedExposureModes.contains(QVariant::fromValue(QCameraExposure::ExposureAuto))) - exposureModes << QVariant::fromValue(QCameraExposure::ExposureAuto); - - if (hasManualExposure && !m_supportedExposureModes.contains(QVariant::fromValue(QCameraExposure::ExposureManual))) - exposureModes << QVariant::fromValue(QCameraExposure::ExposureManual); - - if (!exposureModes.isEmpty() || !m_supportedExposureModes.isEmpty()) { - m_supportedExposureModes = exposureModes; - Q_EMIT parameterRangeChanged(int(ExposureMode)); - } -} - -bool DirectShowCameraExposureControl::setShutterSpeed(IAMCameraControl *cameraControl, qreal shutterSpeed) -{ - if (m_currentExposureMode != QCameraExposure::ExposureManual) { - qCDebug(qtDirectShowPlugin, "Trying to set shutter speed value while in auto exposure mode!"); - return false; - } - - if (qFuzzyCompare(m_currentShutterSpeed, shutterSpeed)) - return true; - - if ((m_shutterSpeedValues.caps & CameraControl_Flags_Manual) == 0) - return false; - - if (!m_supportedShutterSpeeds.contains(QVariant::fromValue(shutterSpeed))) - return false; - - if (qFuzzyIsNull(shutterSpeed) || (shutterSpeed < qreal(0.0))) - return false; - - const long newValue = long(log2(shutterSpeed)); - if (FAILED(cameraControl->Set(CameraControl_Exposure, newValue, CameraControl_Flags_Manual))) { - qCDebug(qtDirectShowPlugin, "Unable to set shutter speed value to: %d", int(shutterSpeed)); - return false; - } - - m_currentShutterSpeed = shutterSpeed; - Q_EMIT actualValueChanged(int(ShutterSpeed)); - return true; -} - -bool DirectShowCameraExposureControl::setAperture(IAMCameraControl *cameraControl, qreal aperture) -{ - if (m_currentExposureMode != QCameraExposure::ExposureManual) { - qCDebug(qtDirectShowPlugin, "Trying to set aperture value while in auto exposure mode!"); - return false; - } - - if (qFuzzyCompare(m_currentAperture, aperture)) - return true; - - if ((m_apertureValues.caps & CameraControl_Flags_Manual) == 0) - return false; - - if (!m_supportedApertureValues.contains(QVariant::fromValue(aperture))) - return false; - - if (aperture < qreal(0.0)) - return false; - - const long newValue = long(10 * aperture); - if (FAILED(cameraControl->Set(CameraControl_Iris, newValue, CameraControl_Flags_Manual))) { - qCDebug(qtDirectShowPlugin, "Unable to set aperture value to: %d", int(aperture)); - return false; - } - - m_currentAperture = aperture; - Q_EMIT actualValueChanged(int(Aperture)); - - return true; -} - -bool DirectShowCameraExposureControl::setExposureMode(IAMCameraControl *cameraControl, QCameraExposure::ExposureMode mode) -{ - if (m_currentExposureMode == mode) - return true; - - bool exposureModeChanged = true; - - // Set auto exposure mode - if (mode == QCameraExposure::ExposureAuto) { - if ((m_apertureValues.caps & CameraControl_Flags_Auto) - && FAILED(cameraControl->Set(CameraControl_Iris, 0, CameraControl_Flags_Auto))) { - qCDebug(qtDirectShowPlugin, "Setting auto exposure mode failed!"); - exposureModeChanged = false; - } - - if ((m_shutterSpeedValues.caps & CameraControl_Flags_Auto) - && FAILED(cameraControl->Set(CameraControl_Exposure, 0, CameraControl_Flags_Auto))) { - qCDebug(qtDirectShowPlugin, "Setting auto exposure mode failed"); - exposureModeChanged = false; - } - - if (exposureModeChanged) { - m_currentExposureMode = mode; - Q_EMIT actualValueChanged(int(ExposureMode)); - } - - return exposureModeChanged; - } - - // Change the current exposure mode to manual first. - m_currentExposureMode = QCameraExposure::ExposureManual; - - const qreal newShutterSpeed = qFuzzyCompare(m_requestedShutterSpeed, -1.0) - ? convertToSec(m_shutterSpeedValues.defaultValue) - : m_requestedShutterSpeed; - if ((m_shutterSpeedValues.caps & CameraControl_Flags_Manual)) - setShutterSpeed(cameraControl, newShutterSpeed); - - const qreal newAperture = qFuzzyCompare(m_requestedAperture, -1.0) - ? convertToFvalue(m_apertureValues.defaultValue) - : m_requestedAperture; - if ((m_apertureValues.caps & CameraControl_Flags_Manual)) - setAperture(cameraControl, newAperture); - - - // Check if any of the values changed. - exposureModeChanged = (qFuzzyCompare(m_currentShutterSpeed, newShutterSpeed) - || qFuzzyCompare(m_currentAperture, newAperture)); - - if (exposureModeChanged) - Q_EMIT actualValueChanged(int(ExposureMode)); - - return exposureModeChanged; -} - -QT_END_NAMESPACE diff --git a/src/plugins/directshow/camera/directshowcameraexposurecontrol.h b/src/plugins/directshow/camera/directshowcameraexposurecontrol.h deleted file mode 100644 index db3fc5984..000000000 --- a/src/plugins/directshow/camera/directshowcameraexposurecontrol.h +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 DIRECTSHOWCAMERAEXPOSURECONTROL_H -#define DIRECTSHOWCAMERAEXPOSURECONTROL_H - -#include <QtMultimedia/qcameraexposurecontrol.h> - -struct IAMCameraControl; - -QT_BEGIN_NAMESPACE - -class DSCameraSession; - -class DirectShowCameraExposureControl : public QCameraExposureControl -{ - Q_OBJECT -public: - DirectShowCameraExposureControl(DSCameraSession *session); - - bool isParameterSupported(ExposureParameter parameter) const override; - QVariantList supportedParameterRange(ExposureParameter parameter, bool *continuous) const override; - QVariant requestedValue(ExposureParameter parameter) const override; - QVariant actualValue(ExposureParameter parameter) const override; - bool setValue(ExposureParameter parameter, const QVariant &value) override; - -private Q_SLOTS: - void onStatusChanged(QCamera::Status status); - -private: - DSCameraSession *m_session; - - struct ExposureValues - { - long caps; - long minValue; - long maxValue; - long stepping; - long defaultValue; - } m_shutterSpeedValues, m_apertureValues; - - qreal m_requestedShutterSpeed; - qreal m_currentShutterSpeed; - - qreal m_requestedAperture; - qreal m_currentAperture; - - QVariantList m_supportedShutterSpeeds; - QVariantList m_supportedApertureValues; - QVariantList m_supportedExposureModes; - - QCameraExposure::ExposureMode m_requestedExposureMode; - QCameraExposure::ExposureMode m_currentExposureMode; - - void updateExposureSettings(); - - bool setShutterSpeed(IAMCameraControl *cameraControl, qreal shutterSpeed); - bool setAperture(IAMCameraControl *cameraControl, qreal aperture); - bool setExposureMode(IAMCameraControl *cameraControl, QCameraExposure::ExposureMode mode); -}; - -QT_END_NAMESPACE - -#endif // DIRECTSHOWCAMERAEXPOSURECONTROL_H diff --git a/src/plugins/directshow/camera/directshowcameraglobal.h b/src/plugins/directshow/camera/directshowcameraglobal.h deleted file mode 100644 index 917ae2dc7..000000000 --- a/src/plugins/directshow/camera/directshowcameraglobal.h +++ /dev/null @@ -1,231 +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 DIRECTSHOWCAMERAGLOBAL_H -#define DIRECTSHOWCAMERAGLOBAL_H - -#include <QtCore/qglobal.h> - -#include <dshow.h> - -extern const GUID MEDIASUBTYPE_RGB24; -extern const GUID MEDIASUBTYPE_RGB32; -extern const GUID MEDIASUBTYPE_YUY2; -extern const GUID MEDIASUBTYPE_MJPG; -extern const GUID MEDIASUBTYPE_RGB555; -extern const GUID MEDIASUBTYPE_YVU9; -extern const GUID MEDIASUBTYPE_UYVY; -extern const GUID PIN_CATEGORY_CAPTURE; -extern const GUID PIN_CATEGORY_PREVIEW; - -extern const IID IID_IPropertyBag; -extern const IID IID_ISampleGrabber; -extern const IID IID_ICaptureGraphBuilder2; -extern const IID IID_IAMStreamConfig; - - -extern const CLSID CLSID_CVidCapClassManager; -extern const CLSID CLSID_VideoInputDeviceCategory; -extern const CLSID CLSID_SampleGrabber; -extern const CLSID CLSID_CaptureGraphBuilder2; - -#define SAFE_RELEASE(x) { if (x) x->Release(); x = nullptr; } - -typedef struct IFileSinkFilter *LPFILESINKFILTER; -typedef struct IAMCopyCaptureFileProgress *LPAMCOPYCAPTUREFILEPROGRESS; - -#ifndef __ICaptureGraphBuilder2_INTERFACE_DEFINED__ -#define __ICaptureGraphBuilder2_INTERFACE_DEFINED__ -struct ICaptureGraphBuilder2 : public IUnknown -{ -public: - virtual HRESULT STDMETHODCALLTYPE SetFiltergraph( - /* [in] */ IGraphBuilder *pfg) = 0; - - virtual HRESULT STDMETHODCALLTYPE GetFiltergraph( - /* [out] */ IGraphBuilder **ppfg) = 0; - - virtual HRESULT STDMETHODCALLTYPE SetOutputFileName( - /* [in] */ const GUID *pType, - /* [in] */ LPCOLESTR lpstrFile, - /* [out] */ IBaseFilter **ppf, - /* [out] */ IFileSinkFilter **ppSink) = 0; - - virtual /* [local] */ HRESULT STDMETHODCALLTYPE FindInterface( - /* [in] */ const GUID *pCategory, - /* [in] */ const GUID *pType, - /* [in] */ IBaseFilter *pf, - /* [in] */ REFIID riid, - /* [out] */ void **ppint) = 0; - - virtual HRESULT STDMETHODCALLTYPE RenderStream( - /* [in] */ const GUID *pCategory, - /* [in] */ const GUID *pType, - /* [in] */ IUnknown *pSource, - /* [in] */ IBaseFilter *pfCompressor, - /* [in] */ IBaseFilter *pfRenderer) = 0; - - virtual HRESULT STDMETHODCALLTYPE ControlStream( - /* [in] */ const GUID *pCategory, - /* [in] */ const GUID *pType, - /* [in] */ IBaseFilter *pFilter, - /* [in] */ REFERENCE_TIME *pstart, - /* [in] */ REFERENCE_TIME *pstop, - /* [in] */ WORD wStartCookie, - /* [in] */ WORD wStopCookie) = 0; - - virtual HRESULT STDMETHODCALLTYPE AllocCapFile( - /* [in] */ LPCOLESTR lpstr, - /* [in] */ DWORDLONG dwlSize) = 0; - - virtual HRESULT STDMETHODCALLTYPE CopyCaptureFile( - /* [in] */ LPOLESTR lpwstrOld, - /* [in] */ LPOLESTR lpwstrNew, - /* [in] */ int fAllowEscAbort, - /* [in] */ IAMCopyCaptureFileProgress *pCallback) = 0; - - virtual HRESULT STDMETHODCALLTYPE FindPin( - /* [in] */ IUnknown *pSource, - /* [in] */ PIN_DIRECTION pindir, - /* [in] */ const GUID *pCategory, - /* [in] */ const GUID *pType, - /* [in] */ BOOL fUnconnected, - /* [in] */ int num, - /* [out] */ IPin **ppPin) = 0; - -}; -#endif - -#ifndef __IAMStreamConfig_INTERFACE_DEFINED__ -#define __IAMStreamConfig_INTERFACE_DEFINED__ -struct IAMStreamConfig : public IUnknown -{ -public: - virtual HRESULT STDMETHODCALLTYPE SetFormat( - /* [in] */ AM_MEDIA_TYPE *pmt) = 0; - - virtual HRESULT STDMETHODCALLTYPE GetFormat( - /* [out] */ AM_MEDIA_TYPE **ppmt) = 0; - - virtual HRESULT STDMETHODCALLTYPE GetNumberOfCapabilities( - /* [out] */ int *piCount, - /* [out] */ int *piSize) = 0; - - virtual HRESULT STDMETHODCALLTYPE GetStreamCaps( - /* [in] */ int iIndex, - /* [out] */ AM_MEDIA_TYPE **ppmt, - /* [out] */ BYTE *pSCC) = 0; - -}; -#endif - -#ifndef __IErrorLog_INTERFACE_DEFINED__ -#define __IErrorLog_INTERFACE_DEFINED__ -struct IErrorLog : public IUnknown - { - public: - virtual HRESULT STDMETHODCALLTYPE AddError( - /* [in] */ LPCOLESTR pszPropName, - /* [in] */ EXCEPINFO *pExcepInfo) = 0; - - }; -#endif - -#ifndef __IPropertyBag_INTERFACE_DEFINED__ -#define __IPropertyBag_INTERFACE_DEFINED__ -struct IPropertyBag : public IUnknown -{ -public: - virtual /* [local] */ HRESULT STDMETHODCALLTYPE Read( - /* [in] */ LPCOLESTR pszPropName, - /* [out][in] */ VARIANT *pVar, - /* [in] */ IErrorLog *pErrorLog) = 0; - - virtual HRESULT STDMETHODCALLTYPE Write( - /* [in] */ LPCOLESTR pszPropName, - /* [in] */ VARIANT *pVar) = 0; - -}; -#endif - -typedef struct IMediaSample *LPMEDIASAMPLE; - -EXTERN_C const IID IID_ISampleGrabberCB; - -#ifndef __ISampleGrabberCB_INTERFACE_DEFINED__ -#define __ISampleGrabberCB_INTERFACE_DEFINED__ - -#undef INTERFACE -#define INTERFACE ISampleGrabberCB -DECLARE_INTERFACE_(ISampleGrabberCB, IUnknown) -{ -// STDMETHOD(QueryInterface) (THIS_ const GUID *, void **) PURE; - STDMETHOD(QueryInterface) (THIS_ REFIID riid, void **) PURE; - STDMETHOD_(ULONG, AddRef) (THIS) PURE; - STDMETHOD_(ULONG, Release) (THIS) PURE; - STDMETHOD_(HRESULT, SampleCB) (THIS_ double, LPMEDIASAMPLE) PURE; - STDMETHOD_(HRESULT, BufferCB) (THIS_ double, BYTE *, long) PURE; -}; -#undef INTERFACE - -#endif - - -#ifndef __ISampleGrabber_INTERFACE_DEFINED__ -#define __ISampleGrabber_INTERFACE_DEFINED__ - -#define INTERFACE ISampleGrabber -DECLARE_INTERFACE_(ISampleGrabber,IUnknown) -{ - STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE; - STDMETHOD_(ULONG,AddRef)(THIS) PURE; - STDMETHOD_(ULONG,Release)(THIS) PURE; - STDMETHOD(SetOneShot)(THIS_ BOOL) PURE; - STDMETHOD(SetMediaType)(THIS_ const AM_MEDIA_TYPE*) PURE; - STDMETHOD(GetConnectedMediaType)(THIS_ AM_MEDIA_TYPE*) PURE; - STDMETHOD(SetBufferSamples)(THIS_ BOOL) PURE; - STDMETHOD(GetCurrentBuffer)(THIS_ long*,long*) PURE; - STDMETHOD(GetCurrentSample)(THIS_ IMediaSample**) PURE; - STDMETHOD(SetCallback)(THIS_ ISampleGrabberCB *,long) PURE; -}; -#undef INTERFACE -#endif - - -#endif diff --git a/src/plugins/directshow/camera/directshowcameraimageencodercontrol.cpp b/src/plugins/directshow/camera/directshowcameraimageencodercontrol.cpp deleted file mode 100644 index 912f67a2d..000000000 --- a/src/plugins/directshow/camera/directshowcameraimageencodercontrol.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 "directshowcameraimageencodercontrol.h" -#include "dscamerasession.h" -#include <QImageWriter> - -QT_BEGIN_NAMESPACE - -DirectShowCameraImageEncoderControl::DirectShowCameraImageEncoderControl(DSCameraSession *session) - : QImageEncoderControl(session) - , m_session(session) -{ -} - -QList<QSize> DirectShowCameraImageEncoderControl::supportedResolutions(const QImageEncoderSettings &settings, bool *continuous) const -{ - QList<QSize> res; - if (!settings.codec().isEmpty() && !supportedImageCodecs().contains(settings.codec(), Qt::CaseInsensitive)) - return res; - - QList<QSize> resolutions = m_session->supportedResolutions(continuous); - QSize r = settings.resolution(); - if (!r.isValid()) - return resolutions; - - if (resolutions.contains(r)) - res << settings.resolution(); - - return res; -} - -QStringList DirectShowCameraImageEncoderControl::supportedImageCodecs() const -{ - QStringList supportedCodecs; - for (const QByteArray &type: QImageWriter::supportedImageFormats()) { - supportedCodecs << type; - } - - return supportedCodecs; -} - -QString DirectShowCameraImageEncoderControl::imageCodecDescription(const QString &codecName) const -{ - Q_UNUSED(codecName); - return QString(); -} - -QImageEncoderSettings DirectShowCameraImageEncoderControl::imageSettings() const -{ - return m_session->imageEncoderSettings(); -} - -void DirectShowCameraImageEncoderControl::setImageSettings(const QImageEncoderSettings &settings) -{ - m_session->setImageEncoderSettings(settings); -} - -QT_END_NAMESPACE diff --git a/src/plugins/directshow/camera/directshowcameraimageencodercontrol.h b/src/plugins/directshow/camera/directshowcameraimageencodercontrol.h deleted file mode 100644 index 6891bea77..000000000 --- a/src/plugins/directshow/camera/directshowcameraimageencodercontrol.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 DIRECTSHOWCAMERAIMAGEENCODERCONTROL_H -#define DIRECTSHOWCAMERAIMAGEENCODERCONTROL_H - -#include <qimageencodercontrol.h> - -QT_BEGIN_NAMESPACE - -class DSCameraSession; -class DirectShowCameraImageEncoderControl : public QImageEncoderControl -{ - Q_OBJECT -public: - DirectShowCameraImageEncoderControl(DSCameraSession *session); - - QList<QSize> supportedResolutions( - const QImageEncoderSettings &settings = QImageEncoderSettings(), - bool *continuous = nullptr) const override; - - QStringList supportedImageCodecs() const override; - QString imageCodecDescription(const QString &formatName) const override; - - QImageEncoderSettings imageSettings() const override; - void setImageSettings(const QImageEncoderSettings &settings) override; - -private: - DSCameraSession *m_session; -}; - -QT_END_NAMESPACE - -#endif // DIRECTSHOWCAMERAIMAGEENCODERCONTROL_H diff --git a/src/plugins/directshow/camera/directshowcamerazoomcontrol.cpp b/src/plugins/directshow/camera/directshowcamerazoomcontrol.cpp deleted file mode 100644 index 079976e15..000000000 --- a/src/plugins/directshow/camera/directshowcamerazoomcontrol.cpp +++ /dev/null @@ -1,209 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 "directshowcamerazoomcontrol.h" -#include "dscamerasession.h" -#include "directshowutils.h" - -QT_BEGIN_NAMESPACE - -inline static qreal defaultZoomValue() { return qreal(1.0); } - -DirectShowCameraZoomControl::DirectShowCameraZoomControl(DSCameraSession *session) - : m_session(session) - , m_opticalZoom({0, 0, 0, 0, 0}) - , m_currentOpticalZoom(qreal(0.0)) - , m_requestedOpticalZoom(qreal(0.0)) - , m_maxOpticalZoom(qreal(1.0)) -{ - Q_ASSERT(m_session); - connect(m_session, &DSCameraSession::statusChanged, - this, &DirectShowCameraZoomControl::onStatusChanged); -} - -qreal DirectShowCameraZoomControl::maximumOpticalZoom() const -{ - return m_maxOpticalZoom; -} - -qreal DirectShowCameraZoomControl::maximumDigitalZoom() const -{ - return defaultZoomValue(); -} - -qreal DirectShowCameraZoomControl::requestedOpticalZoom() const -{ - return qMax(defaultZoomValue(), m_requestedOpticalZoom); -} - -qreal DirectShowCameraZoomControl::requestedDigitalZoom() const -{ - return defaultZoomValue(); -} - -qreal DirectShowCameraZoomControl::currentOpticalZoom() const -{ - return qMax(defaultZoomValue(), m_currentOpticalZoom); -} - -qreal DirectShowCameraZoomControl::currentDigitalZoom() const -{ - return defaultZoomValue(); -} - -void DirectShowCameraZoomControl::zoomTo(qreal optical, qreal digital) -{ - Q_UNUSED(digital); - if (!(m_opticalZoom.caps & CameraControl_Flags_Manual)) - return; - - if (qFuzzyCompare(optical, m_requestedOpticalZoom)) - return; - - m_requestedOpticalZoom = optical; - Q_EMIT requestedOpticalZoomChanged(m_requestedOpticalZoom); - - if (qFuzzyCompare(m_requestedOpticalZoom, m_currentOpticalZoom)) - return; - - if (m_session->status() != QCamera::LoadedStatus && m_session->status() != QCamera::ActiveStatus) - return; // We'll wait until the camera is loaded, see: statusChanged connection - - opticalZoomToPrivate(optical); -} - -void DirectShowCameraZoomControl::onStatusChanged(QCamera::Status status) -{ - if (status == QCamera::LoadedStatus) { - updateZoomValues(); - } else if (status == QCamera::UnloadedStatus) { - SecureZeroMemory(&m_opticalZoom, sizeof(ZoomValues)); - m_currentOpticalZoom = qreal(0.0); - m_requestedOpticalZoom = qreal(0.0); - } - -} - -void DirectShowCameraZoomControl::updateZoomValues() -{ - IAMCameraControl *cameraControl = nullptr; - const DirectShowUtils::ScopedSafeRelease<IAMCameraControl> rControl { &cameraControl }; - if (!m_session->getCameraControlInterface(&cameraControl)) - return; - - ZoomValues values { 0, 0, 0, 0, 0 }; - // Zoom levels in DS are in the range [10, 600] - // The default zoom is device specific. - HRESULT hr = cameraControl->GetRange(CameraControl_Zoom, - &values.minZoom, - &values.maxZoom, - &values.stepping, - &values.defaultZoom, - &values.caps); - - if (FAILED(hr)) { - qCDebug(qtDirectShowPlugin, "Getting the camera's zoom properties failed"); - SecureZeroMemory(&m_opticalZoom, sizeof(ZoomValues)); - return; - } - - if (!(values.caps & CameraControl_Flags_Manual)) { - qCDebug(qtDirectShowPlugin, "Camera does not support manual zoom"); - SecureZeroMemory(&m_opticalZoom, sizeof(ZoomValues)); - return; - } - - if (values.maxZoom != m_opticalZoom.maxZoom) { - const qreal newMaxZoomScale = (values.minZoom == 0) ? defaultZoomValue() - : (qreal(values.maxZoom) / qreal(values.minZoom)); - if (!qFuzzyCompare(newMaxZoomScale, m_maxOpticalZoom)) { - m_maxOpticalZoom = newMaxZoomScale; - Q_EMIT maximumOpticalZoomChanged(m_maxOpticalZoom); - } - } - - m_opticalZoom = values; - - long currentZoom = 0; - long flags = 0; - if (FAILED(cameraControl->Get(CameraControl_Zoom, ¤tZoom, &flags))) { - qCDebug(qtDirectShowPlugin, "Getting the camera's current zoom value failed!"); - return; - } - - qreal currentOpticalZoom = (m_opticalZoom.minZoom == 0) ? defaultZoomValue() - : (qreal(currentZoom) / qreal(m_opticalZoom.minZoom)); - currentOpticalZoom = qMax(defaultZoomValue(), currentOpticalZoom); - if (!qFuzzyCompare(m_currentOpticalZoom, currentOpticalZoom)) { - m_currentOpticalZoom = currentOpticalZoom; - Q_EMIT currentOpticalZoomChanged(m_currentOpticalZoom); - } - - // Check if there is a pending zoom value. - if (!qFuzzyCompare(m_currentOpticalZoom, m_requestedOpticalZoom) && !qFuzzyIsNull(m_requestedOpticalZoom)) - opticalZoomToPrivate(m_requestedOpticalZoom); -} - -bool DirectShowCameraZoomControl::opticalZoomToPrivate(qreal scaleFactor) -{ - IAMCameraControl *cameraControl = nullptr; - const DirectShowUtils::ScopedSafeRelease<IAMCameraControl> rControl { &cameraControl }; - if (!m_session->getCameraControlInterface(&cameraControl)) - return false; - - // Convert to DS zoom value - const int newDSOpticalZoom = qRound(m_opticalZoom.minZoom * scaleFactor); - long newDSOpticalZoomAdjusted = newDSOpticalZoom - (newDSOpticalZoom % m_opticalZoom.stepping); - newDSOpticalZoomAdjusted = qBound(m_opticalZoom.minZoom, newDSOpticalZoomAdjusted, m_opticalZoom.maxZoom); - - if (FAILED(cameraControl->Set(CameraControl_Zoom, newDSOpticalZoomAdjusted, CameraControl_Flags_Manual))) { - qCDebug(qtDirectShowPlugin, "Setting the camera's zoom value failed"); - return false; - } - - const qreal newScaleFactor = (m_opticalZoom.minZoom == 0) ? defaultZoomValue() - : (qreal(newDSOpticalZoomAdjusted) / qreal(m_opticalZoom.minZoom)); - // convert back to Qt scale value - m_currentOpticalZoom = qMax(defaultZoomValue(), newScaleFactor); - Q_EMIT currentOpticalZoomChanged(m_currentOpticalZoom); - - return true; -} - -QT_END_NAMESPACE diff --git a/src/plugins/directshow/camera/directshowcamerazoomcontrol.h b/src/plugins/directshow/camera/directshowcamerazoomcontrol.h deleted file mode 100644 index f6fb05b0e..000000000 --- a/src/plugins/directshow/camera/directshowcamerazoomcontrol.h +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 DIRECTSHOWCAMERAZOOMCONTROL_H -#define DIRECTSHOWCAMERAZOOMCONTROL_H - -#include <QtMultimedia/qcamerazoomcontrol.h> -#include <QtMultimedia/qcamera.h> - -QT_BEGIN_NAMESPACE - -class DSCameraSession; - -class DirectShowCameraZoomControl : public QCameraZoomControl -{ - Q_OBJECT -public: - DirectShowCameraZoomControl(DSCameraSession *session); - - qreal maximumOpticalZoom() const override; - qreal maximumDigitalZoom() const override; - qreal requestedOpticalZoom() const override; - qreal requestedDigitalZoom() const override; - qreal currentOpticalZoom() const override; - qreal currentDigitalZoom() const override; - void zoomTo(qreal optical, qreal digital) override; - -private Q_SLOTS: - void onStatusChanged(QCamera::Status status); - -private: - DSCameraSession *m_session; - struct ZoomValues - { - long maxZoom; - long minZoom; - long stepping; - long defaultZoom; - long caps; - } m_opticalZoom; - - qreal m_currentOpticalZoom; - qreal m_requestedOpticalZoom; - qreal m_maxOpticalZoom; - - void updateZoomValues(); - bool opticalZoomToPrivate(qreal value); -}; - -QT_END_NAMESPACE - -#endif // DIRECTSHOWCAMERAZOOMCONTROL_H diff --git a/src/plugins/directshow/camera/dscameracontrol.cpp b/src/plugins/directshow/camera/dscameracontrol.cpp deleted file mode 100644 index 3f60ec848..000000000 --- a/src/plugins/directshow/camera/dscameracontrol.cpp +++ /dev/null @@ -1,120 +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 <QtCore/qdebug.h> - -#include "dscameracontrol.h" -#include "dscameraservice.h" -#include "dscamerasession.h" - -QT_BEGIN_NAMESPACE - -DSCameraControl::DSCameraControl(QObject *parent) - : QCameraControl(parent) -{ - m_session = qobject_cast<DSCameraSession*>(parent); - connect(m_session, &DSCameraSession::statusChanged, this, - [&](QCamera::Status status) { - if (status == QCamera::UnloadedStatus) - m_state = QCamera::UnloadedState; - emit statusChanged(status); - }); - connect(m_session, &DSCameraSession::cameraError, - this, &DSCameraControl::error); -} - -DSCameraControl::~DSCameraControl() = default; - -void DSCameraControl::setState(QCamera::State state) -{ - if (m_state == state) - return; - - bool succeeded = false; - switch (state) { - case QCamera::UnloadedState: - succeeded = m_session->unload(); - break; - case QCamera::LoadedState: - case QCamera::ActiveState: - if (m_state == QCamera::UnloadedState && !m_session->load()) - return; - - if (state == QCamera::ActiveState) - succeeded = m_session->startPreview(); - else - succeeded = m_session->stopPreview(); - - break; - } - - if (succeeded) { - m_state = state; - emit stateChanged(m_state); - } -} - -bool DSCameraControl::isCaptureModeSupported(QCamera::CaptureModes mode) const -{ - bool bCaptureSupported = false; - switch (mode) { - case QCamera::CaptureStillImage: - bCaptureSupported = true; - break; - case QCamera::CaptureVideo: - bCaptureSupported = false; - break; - } - return bCaptureSupported; -} - -void DSCameraControl::setCaptureMode(QCamera::CaptureModes mode) -{ - if (m_captureMode != mode && isCaptureModeSupported(mode)) { - m_captureMode = mode; - emit captureModeChanged(mode); - } -} - -QCamera::Status DSCameraControl::status() const -{ - return m_session->status(); -} - -QT_END_NAMESPACE diff --git a/src/plugins/directshow/camera/dscameracontrol.h b/src/plugins/directshow/camera/dscameracontrol.h deleted file mode 100644 index 2087623d1..000000000 --- a/src/plugins/directshow/camera/dscameracontrol.h +++ /dev/null @@ -1,80 +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 DSCAMERACONTROL_H -#define DSCAMERACONTROL_H - -#include <QtCore/qobject.h> -#include <qcameracontrol.h> - -QT_BEGIN_NAMESPACE - -class DSCameraSession; - - -class DSCameraControl : public QCameraControl -{ - Q_OBJECT -public: - DSCameraControl(QObject *parent = nullptr); - ~DSCameraControl() override; - - QCamera::State state() const override { return m_state; } - - QCamera::CaptureModes captureMode() const override { return m_captureMode; } - void setCaptureMode(QCamera::CaptureModes mode) override; - - void setState(QCamera::State state) override; - - QCamera::Status status() const override; - bool isCaptureModeSupported(QCamera::CaptureModes mode) const override; - bool canChangeProperty(PropertyChangeType, QCamera::Status) const override - { return false; } - -private: - DSCameraSession *m_session; - QCamera::State m_state = QCamera::UnloadedState; - QCamera::CaptureModes m_captureMode = QCamera::CaptureStillImage; -}; - -QT_END_NAMESPACE - -#endif - - diff --git a/src/plugins/directshow/camera/dscameraimageprocessingcontrol.cpp b/src/plugins/directshow/camera/dscameraimageprocessingcontrol.cpp deleted file mode 100644 index 6d0f45ae9..000000000 --- a/src/plugins/directshow/camera/dscameraimageprocessingcontrol.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** 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 "dscameraimageprocessingcontrol.h" -#include "dscamerasession.h" - -QT_BEGIN_NAMESPACE - -DSCameraImageProcessingControl::DSCameraImageProcessingControl(DSCameraSession *session) - : QCameraImageProcessingControl(session) - , m_session(session) -{ -} - -DSCameraImageProcessingControl::~DSCameraImageProcessingControl() = default; - -bool DSCameraImageProcessingControl::isParameterSupported( - QCameraImageProcessingControl::ProcessingParameter parameter) const -{ - return m_session->isImageProcessingParameterSupported(parameter); -} - -bool DSCameraImageProcessingControl::isParameterValueSupported( - QCameraImageProcessingControl::ProcessingParameter parameter, - const QVariant &value) const -{ - return m_session->isImageProcessingParameterValueSupported(parameter, value); -} - -QVariant DSCameraImageProcessingControl::parameter( - QCameraImageProcessingControl::ProcessingParameter parameter) const -{ - return m_session->imageProcessingParameter(parameter); -} - -void DSCameraImageProcessingControl::setParameter(QCameraImageProcessingControl::ProcessingParameter parameter, - const QVariant &value) -{ - m_session->setImageProcessingParameter(parameter, value); -} - -QT_END_NAMESPACE diff --git a/src/plugins/directshow/camera/dscameraimageprocessingcontrol.h b/src/plugins/directshow/camera/dscameraimageprocessingcontrol.h deleted file mode 100644 index 48f1b6b2c..000000000 --- a/src/plugins/directshow/camera/dscameraimageprocessingcontrol.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef DSCAMERAIMAGEPROCESSINGCONTROL_H -#define DSCAMERAIMAGEPROCESSINGCONTROL_H - -#include <qcamera.h> -#include <qcameraimageprocessingcontrol.h> - -QT_BEGIN_NAMESPACE - -class DSCameraSession; - -class DSCameraImageProcessingControl : public QCameraImageProcessingControl -{ - Q_OBJECT - -public: - DSCameraImageProcessingControl(DSCameraSession *session); - ~DSCameraImageProcessingControl() override; - - bool isParameterSupported(ProcessingParameter) const override; - bool isParameterValueSupported(ProcessingParameter parameter, - const QVariant &value) const override; - QVariant parameter(ProcessingParameter parameter) const override; - void setParameter(ProcessingParameter parameter, const QVariant &value) override; - -private: - DSCameraSession *m_session; -}; - -QT_END_NAMESPACE - -#endif // DSCAMERAIMAGEPROCESSINGCONTROL_H diff --git a/src/plugins/directshow/camera/dscameraservice.cpp b/src/plugins/directshow/camera/dscameraservice.cpp deleted file mode 100644 index ff488cf09..000000000 --- a/src/plugins/directshow/camera/dscameraservice.cpp +++ /dev/null @@ -1,161 +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 <QtCore/qvariant.h> -#include <QtCore/qdebug.h> - -#include "dscameraservice.h" -#include "dscameracontrol.h" -#include "dscamerasession.h" -#include "dsvideorenderer.h" -#include "dsvideodevicecontrol.h" -#include "dsimagecapturecontrol.h" -#include "dscameraviewfindersettingscontrol.h" -#include "dscameraimageprocessingcontrol.h" -#include "directshowcameraexposurecontrol.h" -#include "directshowcameracapturedestinationcontrol.h" -#include "directshowcameracapturebufferformatcontrol.h" -#include "directshowvideoprobecontrol.h" -#include "directshowcamerazoomcontrol.h" -#include "directshowcameraimageencodercontrol.h" - -QT_BEGIN_NAMESPACE - -DSCameraService::DSCameraService(QObject *parent): - QMediaService(parent) - , m_session(new DSCameraSession(this)) - , m_control(new DSCameraControl(m_session)) - , m_videoDevice(new DSVideoDeviceControl(m_session)) - , m_imageCapture(new DSImageCaptureControl(m_session)) - , m_viewfinderSettings(new DSCameraViewfinderSettingsControl(m_session)) - , m_imageProcessingControl(new DSCameraImageProcessingControl(m_session)) - , m_exposureControl(new DirectShowCameraExposureControl(m_session)) - , m_captureDestinationControl(new DirectShowCameraCaptureDestinationControl(m_session)) - , m_captureBufferFormatControl(new DirectShowCameraCaptureBufferFormatControl) - , m_zoomControl(new DirectShowCameraZoomControl(m_session)) - , m_imageEncoderControl(new DirectShowCameraImageEncoderControl(m_session)) -{ -} - -DSCameraService::~DSCameraService() -{ - delete m_control; - delete m_viewfinderSettings; - delete m_imageProcessingControl; - delete m_videoDevice; - delete m_videoRenderer; - delete m_imageCapture; - delete m_imageEncoderControl; - delete m_session; - delete m_exposureControl; - delete m_captureDestinationControl; - delete m_captureBufferFormatControl; - delete m_videoProbeControl; - delete m_zoomControl; -} - -QMediaControl* DSCameraService::requestControl(const char *name) -{ - if(qstrcmp(name,QCameraControl_iid) == 0) - return m_control; - - if (qstrcmp(name, QCameraImageCaptureControl_iid) == 0) - return m_imageCapture; - - if (qstrcmp(name,QVideoRendererControl_iid) == 0) { - if (!m_videoRenderer) { - m_videoRenderer = new DSVideoRendererControl(m_session, this); - return m_videoRenderer; - } - } - - if (qstrcmp(name,QVideoDeviceSelectorControl_iid) == 0) - return m_videoDevice; - - if (qstrcmp(name, QCameraViewfinderSettingsControl2_iid) == 0) - return m_viewfinderSettings; - - if (qstrcmp(name, QCameraImageProcessingControl_iid) == 0) - return m_imageProcessingControl; - - if (qstrcmp(name, QCameraExposureControl_iid) == 0) - return m_exposureControl; - - if (qstrcmp(name, QCameraCaptureDestinationControl_iid) == 0) - return m_captureDestinationControl; - - if (qstrcmp(name, QCameraCaptureBufferFormatControl_iid) == 0) - return m_captureBufferFormatControl; - - if (qstrcmp(name, QMediaVideoProbeControl_iid) == 0) { - if (!m_videoProbeControl) - m_videoProbeControl = new DirectShowVideoProbeControl; - - m_videoProbeControl->ref(); - m_session->addVideoProbe(m_videoProbeControl); - return m_videoProbeControl; - } - - if (qstrcmp(name, QCameraZoomControl_iid) == 0) - return m_zoomControl; - - if (qstrcmp(name, QImageEncoderControl_iid) == 0) - return m_imageEncoderControl; - - return nullptr; -} - -void DSCameraService::releaseControl(QMediaControl *control) -{ - if (control == m_videoRenderer) { - delete m_videoRenderer; - m_videoRenderer = nullptr; - return; - } - - if (control == m_videoProbeControl) { - m_session->removeVideoProbe(m_videoProbeControl); - if (!m_videoProbeControl->deref()) { - delete m_videoProbeControl; - m_videoProbeControl = nullptr; - } - } -} - -QT_END_NAMESPACE diff --git a/src/plugins/directshow/camera/dscameraservice.h b/src/plugins/directshow/camera/dscameraservice.h deleted file mode 100644 index 6ea85b725..000000000 --- a/src/plugins/directshow/camera/dscameraservice.h +++ /dev/null @@ -1,91 +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 DSCAMERASERVICE_H -#define DSCAMERASERVICE_H - -#include <QtCore/qobject.h> - -#include <qmediaservice.h> - -QT_BEGIN_NAMESPACE - -class DSCameraControl; -class DSCameraSession; -class DSVideoDeviceControl; -class DSImageCaptureControl; -class DSCameraViewfinderSettingsControl; -class DSCameraImageProcessingControl; -class DirectShowCameraExposureControl; -class DirectShowCameraCaptureDestinationControl; -class DirectShowCameraCaptureBufferFormatControl; -class DirectShowVideoProbeControl; -class DirectShowCameraZoomControl; -class DirectShowCameraImageEncoderControl; - -class DSCameraService : public QMediaService -{ - Q_OBJECT - -public: - DSCameraService(QObject *parent = nullptr); - ~DSCameraService() override; - - QMediaControl* requestControl(const char *name) override; - void releaseControl(QMediaControl *control) override; - -private: - DSCameraSession *m_session; - DSCameraControl *m_control; - DSVideoDeviceControl *m_videoDevice; - QMediaControl *m_videoRenderer = nullptr; - DSImageCaptureControl *m_imageCapture; - DSCameraViewfinderSettingsControl *m_viewfinderSettings; - DSCameraImageProcessingControl *m_imageProcessingControl; - DirectShowCameraExposureControl *m_exposureControl; - DirectShowCameraCaptureDestinationControl *m_captureDestinationControl; - DirectShowCameraCaptureBufferFormatControl *m_captureBufferFormatControl; - DirectShowVideoProbeControl *m_videoProbeControl = nullptr; - DirectShowCameraZoomControl *m_zoomControl; - DirectShowCameraImageEncoderControl *m_imageEncoderControl; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/directshow/camera/dscamerasession.cpp b/src/plugins/directshow/camera/dscamerasession.cpp deleted file mode 100644 index 7ceefe2c5..000000000 --- a/src/plugins/directshow/camera/dscamerasession.cpp +++ /dev/null @@ -1,1177 +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 <QtCore/qdebug.h> -#include <QFile> -#include <QtConcurrent/QtConcurrentRun> -#include <QtMultimedia/qabstractvideobuffer.h> -#include <QtMultimedia/qvideosurfaceformat.h> -#include <QtMultimedia/qcameraimagecapture.h> -#include <private/qmemoryvideobuffer_p.h> - -#include "dscamerasession.h" -#include "dsvideorenderer.h" -#include "directshowsamplegrabber.h" -#include "directshowcameraglobal.h" -#include "directshowmediatype.h" -#include "directshowutils.h" -#include "directshowvideoprobecontrol.h" - -QT_BEGIN_NAMESPACE - -DSCameraSession::DSCameraSession(QObject *parent) - : QObject(parent) -{ - connect(this, &DSCameraSession::statusChanged, - this, &DSCameraSession::updateReadyForCapture); - - m_deviceLostEventTimer.setSingleShot(true); - connect(&m_deviceLostEventTimer, &QTimer::timeout, [&]() { - IMediaEvent *pEvent = com_cast<IMediaEvent>(m_filterGraph, IID_IMediaEvent); - if (!pEvent) - return; - - long eventCode; - LONG_PTR param1; - LONG_PTR param2; - while (pEvent->GetEvent(&eventCode, ¶m1, ¶m2, 0) == S_OK) { - switch (eventCode) { - case EC_DEVICE_LOST: - unload(); - break; - default: - break; - } - - pEvent->FreeEventParams(eventCode, param1, param2); - } - - pEvent->Release(); - }); -} - -DSCameraSession::~DSCameraSession() -{ - unload(); -} - -void DSCameraSession::setSurface(QAbstractVideoSurface* surface) -{ - m_surface = surface; -} - -void DSCameraSession::setDevice(const QString &device) -{ - m_sourceDeviceName = device; -} - -QCameraViewfinderSettings DSCameraSession::viewfinderSettings() const -{ - return m_status == QCamera::ActiveStatus ? m_actualViewfinderSettings : m_viewfinderSettings; -} - -void DSCameraSession::setViewfinderSettings(const QCameraViewfinderSettings &settings) -{ - m_viewfinderSettings = settings; -} - -qreal DSCameraSession::scaledImageProcessingParameterValue( - const ImageProcessingParameterInfo &sourceValueInfo) -{ - if (sourceValueInfo.currentValue == sourceValueInfo.defaultValue) - return 0.0f; - if (sourceValueInfo.currentValue < sourceValueInfo.defaultValue) { - return ((sourceValueInfo.currentValue - sourceValueInfo.minimumValue) - / qreal(sourceValueInfo.defaultValue - sourceValueInfo.minimumValue)) - + (-1.0f); - } - return ((sourceValueInfo.currentValue - sourceValueInfo.defaultValue) - / qreal(sourceValueInfo.maximumValue - sourceValueInfo.defaultValue)); -} - -qint32 DSCameraSession::sourceImageProcessingParameterValue( - qreal scaledValue, const ImageProcessingParameterInfo &valueRange) -{ - if (qFuzzyIsNull(scaledValue)) - return valueRange.defaultValue; - if (scaledValue < 0.0f) { - return ((scaledValue - (-1.0f)) * (valueRange.defaultValue - valueRange.minimumValue)) - + valueRange.minimumValue; - } - return (scaledValue * (valueRange.maximumValue - valueRange.defaultValue)) - + valueRange.defaultValue; -} - -static QCameraImageProcessingControl::ProcessingParameter searchRelatedResultingParameter( - QCameraImageProcessingControl::ProcessingParameter sourceParameter) -{ - if (sourceParameter == QCameraImageProcessingControl::WhiteBalancePreset) - return QCameraImageProcessingControl::ColorTemperature; - return sourceParameter; -} - -bool DSCameraSession::isImageProcessingParameterSupported( - QCameraImageProcessingControl::ProcessingParameter parameter) const -{ - const QCameraImageProcessingControl::ProcessingParameter resultingParameter = - searchRelatedResultingParameter(parameter); - - return m_imageProcessingParametersInfos.contains(resultingParameter); -} - -bool DSCameraSession::isImageProcessingParameterValueSupported( - QCameraImageProcessingControl::ProcessingParameter parameter, - const QVariant &value) const -{ - const QCameraImageProcessingControl::ProcessingParameter resultingParameter = - searchRelatedResultingParameter(parameter); - - QMap<QCameraImageProcessingControl::ProcessingParameter, - ImageProcessingParameterInfo>::const_iterator sourceValueInfo = - m_imageProcessingParametersInfos.constFind(resultingParameter); - - if (sourceValueInfo == m_imageProcessingParametersInfos.constEnd()) - return false; - - switch (parameter) { - - case QCameraImageProcessingControl::WhiteBalancePreset: { - const QCameraImageProcessing::WhiteBalanceMode checkedValue = - value.value<QCameraImageProcessing::WhiteBalanceMode>(); - // Supports only the Manual and the Auto values - if (checkedValue != QCameraImageProcessing::WhiteBalanceManual - && checkedValue != QCameraImageProcessing::WhiteBalanceAuto) { - return false; - } - } - break; - - case QCameraImageProcessingControl::ColorTemperature: { - const qint32 checkedValue = value.toInt(); - if (checkedValue < (*sourceValueInfo).minimumValue - || checkedValue > (*sourceValueInfo).maximumValue) { - return false; - } - } - break; - - case QCameraImageProcessingControl::ContrastAdjustment: // falling back - case QCameraImageProcessingControl::SaturationAdjustment: // falling back - case QCameraImageProcessingControl::BrightnessAdjustment: // falling back - case QCameraImageProcessingControl::SharpeningAdjustment: { - const qint32 sourceValue = sourceImageProcessingParameterValue( - value.toReal(), (*sourceValueInfo)); - if (sourceValue < (*sourceValueInfo).minimumValue - || sourceValue > (*sourceValueInfo).maximumValue) - return false; - } - break; - - default: - return false; - } - - return true; -} - -QVariant DSCameraSession::imageProcessingParameter( - QCameraImageProcessingControl::ProcessingParameter parameter) const -{ - if (!m_graphBuilder) { - auto it = m_pendingImageProcessingParametrs.find(parameter); - return it != m_pendingImageProcessingParametrs.end() ? it.value() : QVariant(); - } - - const QCameraImageProcessingControl::ProcessingParameter resultingParameter = - searchRelatedResultingParameter(parameter); - - QMap<QCameraImageProcessingControl::ProcessingParameter, - ImageProcessingParameterInfo>::const_iterator sourceValueInfo = - m_imageProcessingParametersInfos.constFind(resultingParameter); - - if (sourceValueInfo == m_imageProcessingParametersInfos.constEnd()) - return QVariant(); - - switch (parameter) { - - case QCameraImageProcessingControl::WhiteBalancePreset: - return QVariant::fromValue<QCameraImageProcessing::WhiteBalanceMode>( - (*sourceValueInfo).capsFlags == VideoProcAmp_Flags_Auto - ? QCameraImageProcessing::WhiteBalanceAuto - : QCameraImageProcessing::WhiteBalanceManual); - - case QCameraImageProcessingControl::ColorTemperature: - return QVariant::fromValue<qint32>((*sourceValueInfo).currentValue); - - case QCameraImageProcessingControl::ContrastAdjustment: // falling back - case QCameraImageProcessingControl::SaturationAdjustment: // falling back - case QCameraImageProcessingControl::BrightnessAdjustment: // falling back - case QCameraImageProcessingControl::SharpeningAdjustment: - return scaledImageProcessingParameterValue((*sourceValueInfo)); - - default: - return QVariant(); - } -} - -void DSCameraSession::setImageProcessingParameter( - QCameraImageProcessingControl::ProcessingParameter parameter, - const QVariant &value) -{ - if (!m_graphBuilder) { - m_pendingImageProcessingParametrs.insert(parameter, value); - return; - } - - const QCameraImageProcessingControl::ProcessingParameter resultingParameter = - searchRelatedResultingParameter(parameter); - - QMap<QCameraImageProcessingControl::ProcessingParameter, - ImageProcessingParameterInfo>::iterator sourceValueInfo = - m_imageProcessingParametersInfos.find(resultingParameter); - - if (sourceValueInfo == m_imageProcessingParametersInfos.end()) - return; - - LONG sourceValue = 0; - LONG capsFlags = VideoProcAmp_Flags_Manual; - - switch (parameter) { - - case QCameraImageProcessingControl::WhiteBalancePreset: { - const QCameraImageProcessing::WhiteBalanceMode checkedValue = - value.value<QCameraImageProcessing::WhiteBalanceMode>(); - // Supports only the Manual and the Auto values - if (checkedValue == QCameraImageProcessing::WhiteBalanceManual) - capsFlags = VideoProcAmp_Flags_Manual; - else if (checkedValue == QCameraImageProcessing::WhiteBalanceAuto) - capsFlags = VideoProcAmp_Flags_Auto; - else - return; - - sourceValue = ((*sourceValueInfo).hasBeenExplicitlySet) - ? (*sourceValueInfo).currentValue - : (*sourceValueInfo).defaultValue; - } - break; - - case QCameraImageProcessingControl::ColorTemperature: - sourceValue = value.isValid() ? - value.value<qint32>() : (*sourceValueInfo).defaultValue; - capsFlags = (*sourceValueInfo).capsFlags; - break; - - case QCameraImageProcessingControl::ContrastAdjustment: // falling back - case QCameraImageProcessingControl::SaturationAdjustment: // falling back - case QCameraImageProcessingControl::BrightnessAdjustment: // falling back - case QCameraImageProcessingControl::SharpeningAdjustment: - if (value.isValid()) { - sourceValue = sourceImageProcessingParameterValue( - value.toReal(), (*sourceValueInfo)); - } else { - sourceValue = (*sourceValueInfo).defaultValue; - } - break; - - default: - return; - } - - IAMVideoProcAmp *pVideoProcAmp = nullptr; - HRESULT hr = m_graphBuilder->FindInterface( - nullptr, - nullptr, - m_sourceFilter, - IID_IAMVideoProcAmp, - reinterpret_cast<void**>(&pVideoProcAmp) - ); - - if (FAILED(hr) || !pVideoProcAmp) { - qWarning() << "failed to find the video proc amp"; - return; - } - - hr = pVideoProcAmp->Set( - (*sourceValueInfo).videoProcAmpProperty, - sourceValue, - capsFlags); - - pVideoProcAmp->Release(); - - if (FAILED(hr)) { - qWarning() << "failed to set the parameter value"; - } else { - (*sourceValueInfo).capsFlags = capsFlags; - (*sourceValueInfo).hasBeenExplicitlySet = true; - (*sourceValueInfo).currentValue = sourceValue; - } -} - -bool DSCameraSession::getCameraControlInterface(IAMCameraControl **cameraControl) const -{ - if (!m_sourceFilter) { - qCDebug(qtDirectShowPlugin, "getCameraControlInterface failed: No capture filter!"); - return false; - } - - if (!cameraControl) { - qCDebug(qtDirectShowPlugin, "getCameraControlInterface failed: Invalid out argument!"); - return false; - } - - if (FAILED(m_sourceFilter->QueryInterface(IID_IAMCameraControl, reinterpret_cast<void **>(cameraControl)))) { - qCDebug(qtDirectShowPlugin, "getCameraControlInterface failed: Querying camera control failed!"); - return false; - } - - return true; -} - -bool DSCameraSession::isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const -{ - return destination & (QCameraImageCapture::CaptureToFile | QCameraImageCapture::CaptureToBuffer); -} - -QCameraImageCapture::CaptureDestinations DSCameraSession::captureDestination() const -{ - return m_captureDestinations; -} - -void DSCameraSession::setCaptureDestination(QCameraImageCapture::CaptureDestinations destinations) -{ - if (m_captureDestinations == destinations) - return; - - m_captureDestinations = destinations; - Q_EMIT captureDestinationChanged(m_captureDestinations); -} - -void DSCameraSession::addVideoProbe(DirectShowVideoProbeControl *probe) -{ - const QMutexLocker locker(&m_probeMutex); - m_videoProbeControl = probe; -} - -void DSCameraSession::removeVideoProbe(DirectShowVideoProbeControl *probe) -{ - Q_UNUSED(probe); - Q_ASSERT(m_videoProbeControl == probe); - const QMutexLocker locker(&m_probeMutex); - m_videoProbeControl = nullptr; -} - -bool DSCameraSession::load() -{ - unload(); - - setStatus(QCamera::LoadingStatus); - - bool succeeded = createFilterGraph(); - if (succeeded) - setStatus(QCamera::LoadedStatus); - else - setStatus(QCamera::UnavailableStatus); - - return succeeded; -} - -bool DSCameraSession::unload() -{ - if (!m_graphBuilder) - return false; - - if (!stopPreview()) - return false; - - setStatus(QCamera::UnloadingStatus); - - m_needsHorizontalMirroring = false; - m_supportedViewfinderSettings.clear(); - m_supportedFormats.clear(); - SAFE_RELEASE(m_sourceFilter); - SAFE_RELEASE(m_nullRendererFilter); - SAFE_RELEASE(m_filterGraph); - SAFE_RELEASE(m_graphBuilder); - SAFE_RELEASE(m_outputPin); - - setStatus(QCamera::UnloadedStatus); - - return true; -} - -bool DSCameraSession::startPreview() -{ - if (m_previewStarted) - return true; - - if (!m_graphBuilder) - return false; - - setStatus(QCamera::StartingStatus); - - QString errorString; - HRESULT hr = S_OK; - IMediaControl* pControl = nullptr; - - if (!configurePreviewFormat()) { - errorString = tr("Failed to configure preview format"); - goto failed; - } - - if (!connectGraph()) { - errorString = tr("Failed to connect graph"); - goto failed; - } - - if (m_surface) - m_surface->start(m_previewSurfaceFormat); - - hr = m_filterGraph->QueryInterface(IID_IMediaControl, reinterpret_cast<void**>(&pControl)); - if (FAILED(hr)) { - errorString = tr("Failed to get stream control"); - goto failed; - } - hr = pControl->Run(); - pControl->Release(); - - if (FAILED(hr)) { - errorString = tr("Failed to start"); - goto failed; - } - - setStatus(QCamera::ActiveStatus); - m_previewStarted = true; - return true; - -failed: - // go back to a clean state - if (m_surface && m_surface->isActive()) - m_surface->stop(); - disconnectGraph(); - setError(QCamera::CameraError, errorString, hr); - return false; -} - -bool DSCameraSession::stopPreview() -{ - if (!m_previewStarted) - return true; - - setStatus(QCamera::StoppingStatus); - - if (m_previewSampleGrabber) - m_previewSampleGrabber->stop(); - - QString errorString; - IMediaControl* pControl = nullptr; - HRESULT hr = m_filterGraph->QueryInterface(IID_IMediaControl, - reinterpret_cast<void**>(&pControl)); - if (FAILED(hr)) { - errorString = tr("Failed to get stream control"); - goto failed; - } - - hr = pControl->Stop(); - pControl->Release(); - if (FAILED(hr)) { - errorString = tr("Failed to stop"); - goto failed; - } - - disconnectGraph(); - - m_sourceFormat.clear(); - - m_previewStarted = false; - setStatus(QCamera::LoadedStatus); - return true; - -failed: - setError(QCamera::CameraError, errorString, hr); - return false; -} - -void DSCameraSession::setError(int error, const QString &errorString, HRESULT hr) -{ - qErrnoWarning(hr, "[0x%x] %s", hr, qPrintable(errorString)); - emit cameraError(error, errorString); - setStatus(QCamera::UnloadedStatus); -} - -void DSCameraSession::setStatus(QCamera::Status status) -{ - if (m_status == status) - return; - - m_status = status; - emit statusChanged(m_status); -} - -bool DSCameraSession::isReadyForCapture() -{ - return m_readyForCapture; -} - -void DSCameraSession::updateReadyForCapture() -{ - bool isReady = (m_status == QCamera::ActiveStatus && m_imageCaptureFileName.isEmpty()); - if (isReady != m_readyForCapture) { - m_readyForCapture = isReady; - emit readyForCaptureChanged(isReady); - } -} - -int DSCameraSession::captureImage(const QString &fileName) -{ - ++m_imageIdCounter; - - if (!m_readyForCapture) { - emit captureError(m_imageIdCounter, QCameraImageCapture::NotReadyError, - tr("Camera not ready for capture")); - return m_imageIdCounter; - } - - const QString ext = !m_imageEncoderSettings.codec().isEmpty() - ? m_imageEncoderSettings.codec().toLower() - : QLatin1String("jpg"); - m_imageCaptureFileName = m_fileNameGenerator.generateFileName(fileName, - QMediaStorageLocation::Pictures, - QLatin1String("IMG_"), - ext); - - updateReadyForCapture(); - - m_captureMutex.lock(); - m_currentImageId = m_imageIdCounter; - m_captureMutex.unlock(); - - return m_imageIdCounter; -} - -void DSCameraSession::onFrameAvailable(double time, const QByteArray &data) -{ - // !!! Not called on the main thread - Q_UNUSED(time); - - m_presentMutex.lock(); - - // In case the source produces frames faster than we can display them, - // only keep the most recent one - m_currentFrame = QVideoFrame(new QMemoryVideoBuffer(data, m_stride), - m_previewSize, - m_previewPixelFormat); - - m_presentMutex.unlock(); - - { - const QMutexLocker locker(&m_probeMutex); - if (m_currentFrame.isValid() && m_videoProbeControl) - Q_EMIT m_videoProbeControl->videoFrameProbed(m_currentFrame); - } - - // Image capture - QMutexLocker locker(&m_captureMutex); - if (m_currentImageId != -1 && !m_capturedFrame.isValid()) { - m_capturedFrame = m_currentFrame; - QMetaObject::invokeMethod(this, "imageExposed", Qt::QueuedConnection, Q_ARG(int, m_currentImageId)); - } - - QMetaObject::invokeMethod(this, "presentFrame", Qt::QueuedConnection); -} - -void DSCameraSession::presentFrame() -{ - // If no frames provided from ISampleGrabber for some time - // the device might be potentially unplugged. - m_deviceLostEventTimer.start(100); - - m_presentMutex.lock(); - - if (m_currentFrame.isValid() && m_surface) { - m_surface->present(m_currentFrame); - m_currentFrame = QVideoFrame(); - } - - m_presentMutex.unlock(); - - QImage captureImage; - const int captureId = m_currentImageId; - - m_captureMutex.lock(); - - if (m_capturedFrame.isValid()) { - - captureImage = m_capturedFrame.image(); - - const bool needsVerticalMirroring = m_previewSurfaceFormat.scanLineDirection() != QVideoSurfaceFormat::TopToBottom; - captureImage = captureImage.mirrored(m_needsHorizontalMirroring, needsVerticalMirroring); // also causes a deep copy of the data - - QtConcurrent::run(&DSCameraSession::processCapturedImage, this, - m_currentImageId, m_captureDestinations, captureImage, m_imageCaptureFileName); - - m_imageCaptureFileName.clear(); - m_currentImageId = -1; - - m_capturedFrame = QVideoFrame(); - } - - m_captureMutex.unlock(); - - if (!captureImage.isNull()) - emit imageCaptured(captureId, captureImage); - - updateReadyForCapture(); -} - -void DSCameraSession::processCapturedImage(int id, - QCameraImageCapture::CaptureDestinations captureDestinations, - const QImage &image, - const QString &path) -{ - const QString format = m_imageEncoderSettings.codec(); - if (captureDestinations & QCameraImageCapture::CaptureToFile) { - if (image.save(path, !format.isEmpty() ? format.toUtf8().constData() : "JPG")) { - Q_EMIT imageSaved(id, path); - } else { - Q_EMIT captureError(id, QCameraImageCapture::ResourceError, - tr("Could not save image to file.")); - } - } - - if (captureDestinations & QCameraImageCapture::CaptureToBuffer) - Q_EMIT imageAvailable(id, QVideoFrame(image)); -} - -bool DSCameraSession::createFilterGraph() -{ - // Previously containered in <qedit.h>. - static const CLSID cLSID_NullRenderer = { 0xC1F400A4, 0x3F08, 0x11d3, { 0x9F, 0x0B, 0x00, 0x60, 0x08, 0x03, 0x9E, 0x37 } }; - - QString errorString; - HRESULT hr; - IMoniker* pMoniker = nullptr; - ICreateDevEnum* pDevEnum = nullptr; - IEnumMoniker* pEnum = nullptr; - - // Create the filter graph - hr = CoCreateInstance(CLSID_FilterGraph, nullptr, CLSCTX_INPROC, - IID_IGraphBuilder, reinterpret_cast<void**>(&m_filterGraph)); - if (FAILED(hr)) { - errorString = tr("Failed to create filter graph"); - goto failed; - } - - // Create the capture graph builder - hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, nullptr, CLSCTX_INPROC, - IID_ICaptureGraphBuilder2, - reinterpret_cast<void**>(&m_graphBuilder)); - if (FAILED(hr)) { - errorString = tr("Failed to create graph builder"); - goto failed; - } - - // Attach the filter graph to the capture graph - hr = m_graphBuilder->SetFiltergraph(m_filterGraph); - if (FAILED(hr)) { - errorString = tr("Failed to connect capture graph and filter graph"); - goto failed; - } - - // Find the Capture device - hr = CoCreateInstance(CLSID_SystemDeviceEnum, nullptr, - CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, - reinterpret_cast<void**>(&pDevEnum)); - if (SUCCEEDED(hr)) { - // Create an enumerator for the video capture category - hr = pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnum, 0); - pDevEnum->Release(); - if (S_OK == hr) { - pEnum->Reset(); - IMalloc *mallocInterface = nullptr; - CoGetMalloc(1, (LPMALLOC*)&mallocInterface); - //go through and find all video capture devices - while (pEnum->Next(1, &pMoniker, nullptr) == S_OK) { - - BSTR strName = nullptr; - hr = pMoniker->GetDisplayName(nullptr, nullptr, &strName); - if (SUCCEEDED(hr)) { - QString output = QString::fromWCharArray(strName); - mallocInterface->Free(strName); - if (m_sourceDeviceName.contains(output)) { - hr = pMoniker->BindToObject(nullptr, nullptr, IID_IBaseFilter, - reinterpret_cast<void**>(&m_sourceFilter)); - if (SUCCEEDED(hr)) { - pMoniker->Release(); - break; - } - } - } - pMoniker->Release(); - } - mallocInterface->Release(); - if (nullptr == m_sourceFilter) - { - if (m_sourceDeviceName.contains(QLatin1String("default"))) - { - pEnum->Reset(); - // still have to loop to discard bind to storage failure case - while (pEnum->Next(1, &pMoniker, nullptr) == S_OK) { - IPropertyBag *pPropBag = nullptr; - - hr = pMoniker->BindToStorage(nullptr, nullptr, IID_IPropertyBag, - reinterpret_cast<void**>(&pPropBag)); - if (FAILED(hr)) { - pMoniker->Release(); - continue; // Don't panic yet - } - - // No need to get the description, just grab it - - hr = pMoniker->BindToObject(nullptr, nullptr, IID_IBaseFilter, - reinterpret_cast<void**>(&m_sourceFilter)); - pPropBag->Release(); - pMoniker->Release(); - if (SUCCEEDED(hr)) - break; // done, stop looping through - qWarning("Object bind failed"); - } - } - } - pEnum->Release(); - } - } - - if (!m_sourceFilter) { - errorString = tr("No capture device found"); - goto failed; - } - - if (!DirectShowUtils::getPin(m_sourceFilter, PINDIR_OUTPUT, PIN_CATEGORY_CAPTURE, &m_outputPin, &hr)) - qWarning() << "Failed to get the pin for the video control:" << hr; - - // Sample grabber filter - if (!m_previewSampleGrabber) { - m_previewSampleGrabber = new DirectShowSampleGrabber(this); - connect(m_previewSampleGrabber, &DirectShowSampleGrabber::bufferAvailable, - this, &DSCameraSession::onFrameAvailable, Qt::DirectConnection); - } - - - // Null renderer. Input connected to the sample grabber's output. Simply - // discard the samples it receives. - hr = CoCreateInstance(cLSID_NullRenderer, nullptr, CLSCTX_INPROC, - IID_IBaseFilter, (void**)&m_nullRendererFilter); - if (FAILED(hr)) { - errorString = tr("Failed to create null renderer"); - goto failed; - } - - updateSourceCapabilities(); - - return true; - -failed: - m_needsHorizontalMirroring = false; - SAFE_RELEASE(m_sourceFilter); - SAFE_RELEASE(m_nullRendererFilter); - SAFE_RELEASE(m_filterGraph); - SAFE_RELEASE(m_graphBuilder); - setError(QCamera::CameraError, errorString, hr); - - return false; -} - -bool DSCameraSession::configurePreviewFormat() -{ - // Resolve viewfinder settings - int settingsIndex = 0; - const QSize captureResolution = m_imageEncoderSettings.resolution(); - const QSize resolution = captureResolution.isValid() ? captureResolution : m_viewfinderSettings.resolution(); - QCameraViewfinderSettings resolvedViewfinderSettings; - for (const QCameraViewfinderSettings &s : qAsConst(m_supportedViewfinderSettings)) { - if ((resolution.isEmpty() || resolution == s.resolution()) - && (qFuzzyIsNull(m_viewfinderSettings.minimumFrameRate()) || qFuzzyCompare((float)m_viewfinderSettings.minimumFrameRate(), (float)s.minimumFrameRate())) - && (qFuzzyIsNull(m_viewfinderSettings.maximumFrameRate()) || qFuzzyCompare((float)m_viewfinderSettings.maximumFrameRate(), (float)s.maximumFrameRate())) - && (m_viewfinderSettings.pixelFormat() == QVideoFrame::Format_Invalid || m_viewfinderSettings.pixelFormat() == s.pixelFormat()) - && (m_viewfinderSettings.pixelAspectRatio().isEmpty() || m_viewfinderSettings.pixelAspectRatio() == s.pixelAspectRatio())) { - resolvedViewfinderSettings = s; - break; - } - ++settingsIndex; - } - - if (resolvedViewfinderSettings.isNull()) { - qWarning("Invalid viewfinder settings"); - return false; - } - - m_actualViewfinderSettings = resolvedViewfinderSettings; - - m_sourceFormat = m_supportedFormats[settingsIndex]; - // Set frame rate. - // We don't care about the minimumFrameRate, DirectShow only allows to set an - // average frame rate, so set that to the maximumFrameRate. - VIDEOINFOHEADER *videoInfo = reinterpret_cast<VIDEOINFOHEADER*>(m_sourceFormat->pbFormat); - videoInfo->AvgTimePerFrame = 10000000 / resolvedViewfinderSettings.maximumFrameRate(); - - m_previewPixelFormat = resolvedViewfinderSettings.pixelFormat(); - const AM_MEDIA_TYPE *resolvedGrabberFormat = &m_sourceFormat; - - if (m_surface) { - const auto surfaceFormats = m_surface->supportedPixelFormats(QAbstractVideoBuffer::NoHandle); - if (!surfaceFormats.contains(m_previewPixelFormat)) { - if (surfaceFormats.contains(QVideoFrame::Format_RGB32)) { - // As a fallback, we support RGB32, if the capture source doesn't support - // that format, the graph builder will automatically insert a - // converter (when possible). - - static const AM_MEDIA_TYPE rgb32GrabberFormat { MEDIATYPE_Video, MEDIASUBTYPE_ARGB32, 0, 0, 0, FORMAT_VideoInfo, nullptr, 0, nullptr}; - resolvedGrabberFormat = &rgb32GrabberFormat; - m_previewPixelFormat = QVideoFrame::Format_RGB32; - - } else { - qWarning() << "Video surface needs to support at least RGB32 pixel format"; - return false; - } - } - } - - m_previewSize = resolvedViewfinderSettings.resolution(); - m_previewSurfaceFormat = QVideoSurfaceFormat(m_previewSize, - m_previewPixelFormat, - QAbstractVideoBuffer::NoHandle); - m_previewSurfaceFormat.setScanLineDirection(DirectShowMediaType::scanLineDirection(m_previewPixelFormat, videoInfo->bmiHeader)); - m_stride = DirectShowMediaType::bytesPerLine(m_previewSurfaceFormat); - - HRESULT hr; - IAMStreamConfig* pConfig = nullptr; - hr = m_graphBuilder->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, - m_sourceFilter, IID_IAMStreamConfig, - reinterpret_cast<void**>(&pConfig)); - if (FAILED(hr)) { - qWarning() << "Failed to get config for capture device"; - return false; - } - - hr = pConfig->SetFormat(&m_sourceFormat); - - pConfig->Release(); - - if (FAILED(hr)) { - qWarning() << "Unable to set video format on capture device"; - return false; - } - - if (!m_previewSampleGrabber->setMediaType(resolvedGrabberFormat)) - return false; - - m_previewSampleGrabber->start(DirectShowSampleGrabber::CallbackMethod::BufferCB); - - return true; -} - -void DSCameraSession::updateImageProcessingParametersInfos() -{ - if (!m_graphBuilder) { - qWarning() << "failed to access to the graph builder"; - return; - } - - IAMVideoProcAmp *pVideoProcAmp = nullptr; - const HRESULT hr = m_graphBuilder->FindInterface( - nullptr, - nullptr, - m_sourceFilter, - IID_IAMVideoProcAmp, - reinterpret_cast<void**>(&pVideoProcAmp) - ); - - if (FAILED(hr) || !pVideoProcAmp) { - qWarning() << "failed to find the video proc amp"; - return; - } - - for (int property = VideoProcAmp_Brightness; property <= VideoProcAmp_Gain; ++property) { - - QCameraImageProcessingControl::ProcessingParameter processingParameter; // not initialized - - switch (property) { - case VideoProcAmp_Brightness: - processingParameter = QCameraImageProcessingControl::BrightnessAdjustment; - break; - case VideoProcAmp_Contrast: - processingParameter = QCameraImageProcessingControl::ContrastAdjustment; - break; - case VideoProcAmp_Saturation: - processingParameter = QCameraImageProcessingControl::SaturationAdjustment; - break; - case VideoProcAmp_Sharpness: - processingParameter = QCameraImageProcessingControl::SharpeningAdjustment; - break; - case VideoProcAmp_WhiteBalance: - processingParameter = QCameraImageProcessingControl::ColorTemperature; - break; - default: // unsupported or not implemented yet parameter - continue; - } - - ImageProcessingParameterInfo sourceValueInfo; - LONG steppingDelta = 0; - - HRESULT hr = pVideoProcAmp->GetRange( - property, - &sourceValueInfo.minimumValue, - &sourceValueInfo.maximumValue, - &steppingDelta, - &sourceValueInfo.defaultValue, - &sourceValueInfo.capsFlags); - - if (FAILED(hr)) - continue; - - hr = pVideoProcAmp->Get( - property, - &sourceValueInfo.currentValue, - &sourceValueInfo.capsFlags); - - if (FAILED(hr)) - continue; - - sourceValueInfo.videoProcAmpProperty = static_cast<VideoProcAmpProperty>(property); - - m_imageProcessingParametersInfos.insert(processingParameter, sourceValueInfo); - } - - pVideoProcAmp->Release(); - - for (auto it = m_pendingImageProcessingParametrs.cbegin(); - it != m_pendingImageProcessingParametrs.cend(); - ++it) { - setImageProcessingParameter(it.key(), it.value()); - } - m_pendingImageProcessingParametrs.clear(); -} - -bool DSCameraSession::connectGraph() -{ - HRESULT hr = m_filterGraph->AddFilter(m_sourceFilter, L"Capture Filter"); - if (FAILED(hr)) { - qWarning() << "failed to add capture filter to graph"; - return false; - } - - if (FAILED(m_filterGraph->AddFilter(m_previewSampleGrabber->filter(), L"Sample Grabber"))) { - qWarning() << "failed to add sample grabber to graph"; - return false; - } - - hr = m_filterGraph->AddFilter(m_nullRendererFilter, L"Null Renderer"); - if (FAILED(hr)) { - qWarning() << "failed to add null renderer to graph"; - return false; - } - - hr = m_graphBuilder->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, - m_sourceFilter, - m_previewSampleGrabber->filter(), - m_nullRendererFilter); - if (FAILED(hr)) { - qWarning() << "Graph failed to connect filters" << hr; - return false; - } - - return true; -} - -void DSCameraSession::disconnectGraph() -{ - // To avoid increasing the memory usage every time the graph is re-connected it's - // important that all filters are released; also the ones added by the "Intelligent Connect". - IEnumFilters *enumFilters = nullptr; - if (SUCCEEDED(m_filterGraph->EnumFilters(&enumFilters))) { - IBaseFilter *filter = nullptr; - while (enumFilters->Next(1, &filter, nullptr) == S_OK) { - m_filterGraph->RemoveFilter(filter); - enumFilters->Reset(); - filter->Release(); - } - enumFilters->Release(); - } -} - -static bool qt_frameRateRangeGreaterThan(const QCamera::FrameRateRange &r1, const QCamera::FrameRateRange &r2) -{ - return r1.maximumFrameRate > r2.maximumFrameRate; -} - -void DSCameraSession::updateSourceCapabilities() -{ - HRESULT hr; - AM_MEDIA_TYPE *pmt = nullptr; - VIDEOINFOHEADER *pvi = nullptr; - VIDEO_STREAM_CONFIG_CAPS scc; - IAMStreamConfig* pConfig = nullptr; - - m_supportedViewfinderSettings.clear(); - m_needsHorizontalMirroring = false; - m_supportedFormats.clear(); - m_imageProcessingParametersInfos.clear(); - - IAMVideoControl *pVideoControl = nullptr; - hr = m_graphBuilder->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, - m_sourceFilter, IID_IAMVideoControl, - reinterpret_cast<void**>(&pVideoControl)); - if (FAILED(hr)) { - qWarning() << "Failed to get the video control"; - } else if (m_outputPin) { - long supportedModes; - hr = pVideoControl->GetCaps(m_outputPin, &supportedModes); - if (FAILED(hr)) { - qWarning() << "Failed to get the supported modes of the video control"; - } else if (supportedModes & VideoControlFlag_FlipHorizontal) { - long mode; - hr = pVideoControl->GetMode(m_outputPin, &mode); - if (FAILED(hr)) - qWarning() << "Failed to get the mode of the video control"; - else if (supportedModes & VideoControlFlag_FlipHorizontal) - m_needsHorizontalMirroring = (mode & VideoControlFlag_FlipHorizontal); - } - pVideoControl->Release(); - } - - hr = m_graphBuilder->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, - m_sourceFilter, IID_IAMStreamConfig, - reinterpret_cast<void**>(&pConfig)); - if (FAILED(hr)) { - qWarning() << "failed to get config on capture device"; - return; - } - - int iCount; - int iSize; - hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize); - if (FAILED(hr)) { - qWarning() << "failed to get capabilities"; - return; - } - - for (int iIndex = 0; iIndex < iCount; ++iIndex) { - hr = pConfig->GetStreamCaps(iIndex, &pmt, reinterpret_cast<BYTE*>(&scc)); - if (hr == S_OK) { - QVideoFrame::PixelFormat pixelFormat = DirectShowMediaType::pixelFormatFromType(pmt); - - if (pmt->majortype == MEDIATYPE_Video - && pmt->formattype == FORMAT_VideoInfo - && pixelFormat != QVideoFrame::Format_Invalid) { - - pvi = reinterpret_cast<VIDEOINFOHEADER*>(pmt->pbFormat); - QSize resolution(pvi->bmiHeader.biWidth, pvi->bmiHeader.biHeight); - - QList<QCamera::FrameRateRange> frameRateRanges; - - if (pVideoControl && m_outputPin) { - long listSize = 0; - LONGLONG *frameRates = nullptr; - SIZE size = { resolution.width(), resolution.height() }; - hr = pVideoControl->GetFrameRateList(m_outputPin, iIndex, size, &listSize, &frameRates); - if (hr == S_OK && listSize > 0 && frameRates) { - for (long i = 0; i < listSize; ++i) { - qreal fr = qreal(10000000) / frameRates[i]; - frameRateRanges.append(QCamera::FrameRateRange(fr, fr)); - } - - // Make sure higher frame rates come first - std::sort(frameRateRanges.begin(), frameRateRanges.end(), qt_frameRateRangeGreaterThan); - } - - CoTaskMemFree(frameRates); - } - - if (frameRateRanges.isEmpty()) { - frameRateRanges.append(QCamera::FrameRateRange(qreal(10000000) / scc.MaxFrameInterval, - qreal(10000000) / scc.MinFrameInterval)); - } - - for (const QCamera::FrameRateRange &frameRateRange : qAsConst(frameRateRanges)) { - QCameraViewfinderSettings settings; - settings.setResolution(resolution); - settings.setMinimumFrameRate(frameRateRange.minimumFrameRate); - settings.setMaximumFrameRate(frameRateRange.maximumFrameRate); - settings.setPixelFormat(pixelFormat); - settings.setPixelAspectRatio(1, 1); - m_supportedViewfinderSettings.append(settings); - m_supportedFormats.append(DirectShowMediaType(*pmt)); - } - } else { - OLECHAR *guidString = nullptr; - StringFromCLSID(pmt->subtype, &guidString); - if (guidString) - qWarning() << "Unsupported media type:" << QString::fromWCharArray(guidString); - ::CoTaskMemFree(guidString); - } - - DirectShowMediaType::deleteType(pmt); - } - } - - pConfig->Release(); - - updateImageProcessingParametersInfos(); -} - -QList<QSize> DSCameraSession::supportedResolutions(bool *continuous) const -{ - if (continuous) - *continuous = false; - - QList<QSize> res; - for (auto &settings : m_supportedViewfinderSettings) { - auto size = settings.resolution(); - if (!res.contains(size)) - res << size; - } - - std::sort(res.begin(), res.end(), [](const QSize &r1, const QSize &r2) { - return qlonglong(r1.width()) * r1.height() < qlonglong(r2.width()) * r2.height(); - }); - - return res; -} - -QT_END_NAMESPACE diff --git a/src/plugins/directshow/camera/dscamerasession.h b/src/plugins/directshow/camera/dscamerasession.h deleted file mode 100644 index 9f88163b9..000000000 --- a/src/plugins/directshow/camera/dscamerasession.h +++ /dev/null @@ -1,242 +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 DSCAMERASESSION_H -#define DSCAMERASESSION_H - -#include <QtCore/qobject.h> -#include <QTime> -#include <QUrl> -#include <QMutex> -#include <QTimer> -#include <qcamera.h> -#include <QtMultimedia/qvideoframe.h> -#include <QtMultimedia/qabstractvideosurface.h> -#include <QtMultimedia/qvideosurfaceformat.h> -#include <QtMultimedia/qcameraimageprocessingcontrol.h> -#include <QtMultimedia/qcameraimagecapture.h> -#include <QtMultimedia/qmediaencodersettings.h> -#include <private/qmediastoragelocation_p.h> - -#include <tchar.h> -#include <dshow.h> -#include <objbase.h> -#include <initguid.h> -#include "directshowmediatype.h" -#ifdef Q_CC_MSVC -# pragma comment(lib, "strmiids.lib") -# pragma comment(lib, "ole32.lib") -#endif // Q_CC_MSVC -#include <windows.h> - -#ifdef Q_CC_MSVC -# pragma include_alias("dxtrans.h","qedit.h") -#endif // Q_CC_MSVC -#define __IDxtCompositor_INTERFACE_DEFINED__ -#define __IDxtAlphaSetter_INTERFACE_DEFINED__ -#define __IDxtJpeg_INTERFACE_DEFINED__ -#define __IDxtKey_INTERFACE_DEFINED__ - -struct ICaptureGraphBuilder2; - -QT_BEGIN_NAMESPACE - -class DirectShowSampleGrabber; -class DirectShowVideoProbeControl; - -class DSCameraSession : public QObject -{ - Q_OBJECT -public: - DSCameraSession(QObject *parent = nullptr); - ~DSCameraSession() override; - - QCamera::Status status() const { return m_status; } - - void setDevice(const QString &device); - - bool load(); - bool unload(); - bool startPreview(); - bool stopPreview(); - - bool isReadyForCapture(); - int captureImage(const QString &fileName); - - void setSurface(QAbstractVideoSurface* surface); - - QCameraViewfinderSettings viewfinderSettings() const; - void setViewfinderSettings(const QCameraViewfinderSettings &settings); - - QList<QCameraViewfinderSettings> supportedViewfinderSettings() const - { return m_supportedViewfinderSettings; } - - bool isImageProcessingParameterSupported( - QCameraImageProcessingControl::ProcessingParameter) const; - - bool isImageProcessingParameterValueSupported( - QCameraImageProcessingControl::ProcessingParameter, - const QVariant &) const; - - QVariant imageProcessingParameter( - QCameraImageProcessingControl::ProcessingParameter) const; - - void setImageProcessingParameter( - QCameraImageProcessingControl::ProcessingParameter, - const QVariant &); - - bool getCameraControlInterface(IAMCameraControl **cameraControl) const; - - bool isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const; - QCameraImageCapture::CaptureDestinations captureDestination() const; - void setCaptureDestination(QCameraImageCapture::CaptureDestinations destinations); - - void addVideoProbe(DirectShowVideoProbeControl *probe); - void removeVideoProbe(DirectShowVideoProbeControl *probe); - - QList<QSize> supportedResolutions(bool *continuous) const; - QImageEncoderSettings imageEncoderSettings() const { return m_imageEncoderSettings; } - void setImageEncoderSettings(const QImageEncoderSettings &settings) - { m_imageEncoderSettings = settings; } - -Q_SIGNALS: - void statusChanged(QCamera::Status); - void imageExposed(int id); - void imageCaptured(int id, const QImage &preview); - void imageSaved(int id, const QString &fileName); - void imageAvailable(int id, const QVideoFrame &buffer); - void readyForCaptureChanged(bool); - void captureError(int id, int error, const QString &errorString); - void captureDestinationChanged(QCameraImageCapture::CaptureDestinations); - void cameraError(int error, const QString &errorString); - -private Q_SLOTS: - void presentFrame(); - void updateReadyForCapture(); - -private: - struct ImageProcessingParameterInfo - { - LONG minimumValue = 0; - LONG maximumValue = 0; - LONG defaultValue = 0; - LONG currentValue = 0; - LONG capsFlags = 0; - bool hasBeenExplicitlySet = false; - VideoProcAmpProperty videoProcAmpProperty = VideoProcAmp_Brightness; - }; - - void setStatus(QCamera::Status status); - - void onFrameAvailable(double time, const QByteArray &data); - void processCapturedImage(int id, QCameraImageCapture::CaptureDestinations captureDestinations, const QImage &image, const QString &path); - - bool createFilterGraph(); - bool connectGraph(); - void disconnectGraph(); - void updateSourceCapabilities(); - bool configurePreviewFormat(); - void updateImageProcessingParametersInfos(); - void setError(int error, const QString &errorString, HRESULT hr); - - // These static functions are used for scaling of adjustable parameters, - // which have the ranges from -1.0 to +1.0 in the QCameraImageProcessing API. - static qreal scaledImageProcessingParameterValue( - const ImageProcessingParameterInfo &sourceValueInfo); - static qint32 sourceImageProcessingParameterValue( - qreal scaledValue, const ImageProcessingParameterInfo &sourceValueInfo); - - QMutex m_presentMutex; - QMutex m_captureMutex; - - ICaptureGraphBuilder2* m_graphBuilder = nullptr; - IGraphBuilder* m_filterGraph = nullptr; - - // Source (camera) - QString m_sourceDeviceName = QLatin1String("default"); - IBaseFilter* m_sourceFilter = nullptr; - bool m_needsHorizontalMirroring = false; - QList<DirectShowMediaType> m_supportedFormats; - QList<QCameraViewfinderSettings> m_supportedViewfinderSettings; - DirectShowMediaType m_sourceFormat; - QMap<QCameraImageProcessingControl::ProcessingParameter, ImageProcessingParameterInfo> m_imageProcessingParametersInfos; - - // Preview - DirectShowSampleGrabber *m_previewSampleGrabber = nullptr; - IBaseFilter *m_nullRendererFilter = nullptr; - QVideoFrame m_currentFrame; - bool m_previewStarted = false; - QAbstractVideoSurface* m_surface = nullptr; - QVideoSurfaceFormat m_previewSurfaceFormat; - QVideoFrame::PixelFormat m_previewPixelFormat = QVideoFrame::Format_RGB32; - QSize m_previewSize; - int m_stride = -1; - QCameraViewfinderSettings m_viewfinderSettings; - QCameraViewfinderSettings m_actualViewfinderSettings; - - // Image capture - QString m_imageCaptureFileName; - QMediaStorageLocation m_fileNameGenerator; - bool m_readyForCapture = false; - int m_imageIdCounter = 0; - int m_currentImageId = -1; - QVideoFrame m_capturedFrame; - QCameraImageCapture::CaptureDestinations m_captureDestinations = QCameraImageCapture::CaptureToFile; - - // Video probe - QMutex m_probeMutex; - DirectShowVideoProbeControl *m_videoProbeControl = nullptr; - - QImageEncoderSettings m_imageEncoderSettings; - - // Internal state - QCamera::Status m_status = QCamera::UnloadedStatus; - QTimer m_deviceLostEventTimer; - - QMap<QCameraImageProcessingControl::ProcessingParameter, QVariant> m_pendingImageProcessingParametrs; - - IPin *m_outputPin = nullptr; - - friend class SampleGrabberCallbackPrivate; -}; - -QT_END_NAMESPACE - - -#endif diff --git a/src/plugins/directshow/camera/dscameraviewfindersettingscontrol.cpp b/src/plugins/directshow/camera/dscameraviewfindersettingscontrol.cpp deleted file mode 100644 index 655a47d07..000000000 --- a/src/plugins/directshow/camera/dscameraviewfindersettingscontrol.cpp +++ /dev/null @@ -1,66 +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 "dscameraviewfindersettingscontrol.h" -#include "dscamerasession.h" - -QT_BEGIN_NAMESPACE - -DSCameraViewfinderSettingsControl::DSCameraViewfinderSettingsControl(DSCameraSession *session) - : QCameraViewfinderSettingsControl2(session) - , m_session(session) -{ -} - -QList<QCameraViewfinderSettings> DSCameraViewfinderSettingsControl::supportedViewfinderSettings() const -{ - return m_session->supportedViewfinderSettings(); -} - -QCameraViewfinderSettings DSCameraViewfinderSettingsControl::viewfinderSettings() const -{ - return m_session->viewfinderSettings(); -} - -void DSCameraViewfinderSettingsControl::setViewfinderSettings(const QCameraViewfinderSettings &settings) -{ - m_session->setViewfinderSettings(settings); -} - -QT_END_NAMESPACE diff --git a/src/plugins/directshow/camera/dscameraviewfindersettingscontrol.h b/src/plugins/directshow/camera/dscameraviewfindersettingscontrol.h deleted file mode 100644 index a2b646edf..000000000 --- a/src/plugins/directshow/camera/dscameraviewfindersettingscontrol.h +++ /dev/null @@ -1,65 +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 DSCAMERAVIEWFINDERSETTINGSCONTROL_H -#define DSCAMERAVIEWFINDERSETTINGSCONTROL_H - -#include <qcameraviewfindersettingscontrol.h> - -QT_BEGIN_NAMESPACE - -class DSCameraSession; - -class DSCameraViewfinderSettingsControl : public QCameraViewfinderSettingsControl2 -{ -public: - DSCameraViewfinderSettingsControl(DSCameraSession *session); - - QList<QCameraViewfinderSettings> supportedViewfinderSettings() const override; - - QCameraViewfinderSettings viewfinderSettings() const override; - void setViewfinderSettings(const QCameraViewfinderSettings &settings) override; - -private: - DSCameraSession *m_session; -}; - -QT_END_NAMESPACE - -#endif // DSCAMERAVIEWFINDERSETTINGSCONTROL_H diff --git a/src/plugins/directshow/camera/dsimagecapturecontrol.cpp b/src/plugins/directshow/camera/dsimagecapturecontrol.cpp deleted file mode 100644 index e4d2eee30..000000000 --- a/src/plugins/directshow/camera/dsimagecapturecontrol.cpp +++ /dev/null @@ -1,88 +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 <QtCore/QDebug> - -#include "dsimagecapturecontrol.h" - -QT_BEGIN_NAMESPACE - -DSImageCaptureControl::DSImageCaptureControl(DSCameraSession *session) - : QCameraImageCaptureControl(session) - , m_session(session) -{ - connect(m_session, &DSCameraSession::imageExposed, - this, &DSImageCaptureControl::imageExposed); - connect(m_session, &DSCameraSession::imageCaptured, - this, &DSImageCaptureControl::imageCaptured); - connect(m_session, &DSCameraSession::imageSaved, - this, &DSImageCaptureControl::imageSaved); - connect(m_session, &DSCameraSession::readyForCaptureChanged, - this, &DSImageCaptureControl::readyForCaptureChanged); - connect(m_session, &DSCameraSession::captureError, - this, &DSImageCaptureControl::error); - connect(m_session, &DSCameraSession::imageAvailable, - this, &DSImageCaptureControl::imageAvailable); -} - -DSImageCaptureControl::~DSImageCaptureControl() = default; - -bool DSImageCaptureControl::isReadyForCapture() const -{ - return m_session->isReadyForCapture(); -} - -int DSImageCaptureControl::capture(const QString &fileName) -{ - return m_session->captureImage(fileName); -} - -QCameraImageCapture::DriveMode DSImageCaptureControl::driveMode() const -{ - return QCameraImageCapture::SingleImageCapture; -} - -void DSImageCaptureControl::setDriveMode(QCameraImageCapture::DriveMode mode) -{ - if (mode != QCameraImageCapture::SingleImageCapture) - qWarning("Drive mode not supported."); -} - -QT_END_NAMESPACE - diff --git a/src/plugins/directshow/camera/dsimagecapturecontrol.h b/src/plugins/directshow/camera/dsimagecapturecontrol.h deleted file mode 100644 index c619de1a1..000000000 --- a/src/plugins/directshow/camera/dsimagecapturecontrol.h +++ /dev/null @@ -1,69 +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 DSIMAGECAPTURECONTROL_H -#define DSIMAGECAPTURECONTROL_H - -#include <qcameraimagecapturecontrol.h> -#include "dscamerasession.h" - -QT_BEGIN_NAMESPACE - -class DSImageCaptureControl : public QCameraImageCaptureControl -{ - Q_OBJECT -public: - DSImageCaptureControl(DSCameraSession *session); - ~DSImageCaptureControl() override; - - bool isReadyForCapture() const override; - int capture(const QString &fileName) override; - - QCameraImageCapture::DriveMode driveMode() const override; - void setDriveMode(QCameraImageCapture::DriveMode mode) override; - - void cancelCapture() override {} - -private: - DSCameraSession *m_session; -}; - -QT_END_NAMESPACE - -#endif // DSCAPTURECONTROL_H diff --git a/src/plugins/directshow/camera/dsvideodevicecontrol.cpp b/src/plugins/directshow/camera/dsvideodevicecontrol.cpp deleted file mode 100644 index 0f08154f1..000000000 --- a/src/plugins/directshow/camera/dsvideodevicecontrol.cpp +++ /dev/null @@ -1,186 +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 <QDebug> -#include <QFile> -#include <qelapsedtimer.h> - -#include "dsvideodevicecontrol.h" -#include "dscamerasession.h" - -#include <tchar.h> -#include <dshow.h> -#include <objbase.h> -#include <initguid.h> -#include <ocidl.h> -#include <string.h> - -extern const CLSID CLSID_VideoInputDeviceCategory; - -QT_BEGIN_NAMESPACE - -Q_GLOBAL_STATIC(QList<DSVideoDeviceInfo>, deviceList) - -DSVideoDeviceControl::DSVideoDeviceControl(QObject *parent) - : QVideoDeviceSelectorControl(parent) -{ - m_session = qobject_cast<DSCameraSession*>(parent); - selected = 0; -} - -int DSVideoDeviceControl::deviceCount() const -{ - updateDevices(); - return deviceList->count(); -} - -QString DSVideoDeviceControl::deviceName(int index) const -{ - updateDevices(); - - if (index >= 0 && index <= deviceList->count()) - return QString::fromUtf8(deviceList->at(index).first.constData()); - - return QString(); -} - -QString DSVideoDeviceControl::deviceDescription(int index) const -{ - updateDevices(); - - if (index >= 0 && index <= deviceList->count()) - return deviceList->at(index).second; - - return QString(); -} - -int DSVideoDeviceControl::defaultDevice() const -{ - return 0; -} - -int DSVideoDeviceControl::selectedDevice() const -{ - return selected; -} - -void DSVideoDeviceControl::setSelectedDevice(int index) -{ - updateDevices(); - - if (index >= 0 && index < deviceList->count()) { - if (m_session) { - QString device = deviceList->at(index).first; - if (device.startsWith("ds:")) - device.remove(0,3); - m_session->setDevice(device); - } - selected = index; - } -} - -const QList<DSVideoDeviceInfo> &DSVideoDeviceControl::availableDevices() -{ - updateDevices(); - return *deviceList; -} - -void DSVideoDeviceControl::updateDevices() -{ - static QElapsedTimer timer; - if (timer.isValid() && timer.elapsed() < 500) // ms - return; - - deviceList->clear(); - - ICreateDevEnum* pDevEnum = nullptr; - IEnumMoniker* pEnum = nullptr; - // Create the System device enumerator - HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, nullptr, - CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, - reinterpret_cast<void**>(&pDevEnum)); - if (SUCCEEDED(hr)) { - // Create the enumerator for the video capture category - hr = pDevEnum->CreateClassEnumerator( - CLSID_VideoInputDeviceCategory, &pEnum, 0); - if (S_OK == hr) { - pEnum->Reset(); - // go through and find all video capture devices - IMoniker* pMoniker = nullptr; - IMalloc *mallocInterface = nullptr; - CoGetMalloc(1, (LPMALLOC*)&mallocInterface); - while (pEnum->Next(1, &pMoniker, nullptr) == S_OK) { - BSTR strName = nullptr; - hr = pMoniker->GetDisplayName(nullptr, nullptr, &strName); - if (SUCCEEDED(hr)) { - QString output(QString::fromWCharArray(strName)); - mallocInterface->Free(strName); - - DSVideoDeviceInfo devInfo; - devInfo.first = output.toUtf8(); - - IPropertyBag *pPropBag; - hr = pMoniker->BindToStorage(nullptr, nullptr, IID_IPropertyBag, - reinterpret_cast<void**>(&pPropBag)); - if (SUCCEEDED(hr)) { - // Find the description - VARIANT varName; - varName.vt = VT_BSTR; - hr = pPropBag->Read(L"FriendlyName", &varName, nullptr); - if (SUCCEEDED(hr)) { - output = QString::fromWCharArray(varName.bstrVal); - } - pPropBag->Release(); - } - devInfo.second = output; - - deviceList->append(devInfo); - } - pMoniker->Release(); - } - mallocInterface->Release(); - pEnum->Release(); - } - pDevEnum->Release(); - } - - timer.restart(); -} - -QT_END_NAMESPACE diff --git a/src/plugins/directshow/camera/dsvideodevicecontrol.h b/src/plugins/directshow/camera/dsvideodevicecontrol.h deleted file mode 100644 index 24a5b61a1..000000000 --- a/src/plugins/directshow/camera/dsvideodevicecontrol.h +++ /dev/null @@ -1,79 +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 DSVIDEODEVICECONTROL_H -#define DSVIDEODEVICECONTROL_H - -#include <qvideodeviceselectorcontrol.h> -#include <QStringList> - -QT_BEGIN_NAMESPACE -class DSCameraSession; - -//QTM_USE_NAMESPACE - -using DSVideoDeviceInfo = QPair<QByteArray, QString>; - -class DSVideoDeviceControl : public QVideoDeviceSelectorControl -{ - Q_OBJECT -public: - DSVideoDeviceControl(QObject *parent = nullptr); - - int deviceCount() const override; - QString deviceName(int index) const override; - QString deviceDescription(int index) const override; - int defaultDevice() const override; - int selectedDevice() const override; - - static const QList<DSVideoDeviceInfo> &availableDevices(); - -public Q_SLOTS: - void setSelectedDevice(int index) override; - -private: - static void updateDevices(); - - DSCameraSession* m_session; - int selected; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/directshow/camera/dsvideorenderer.cpp b/src/plugins/directshow/camera/dsvideorenderer.cpp deleted file mode 100644 index cde63af65..000000000 --- a/src/plugins/directshow/camera/dsvideorenderer.cpp +++ /dev/null @@ -1,67 +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 <QtCore/qdebug.h> - -#include "dsvideorenderer.h" - -QT_BEGIN_NAMESPACE - -DSVideoRendererControl::DSVideoRendererControl(DSCameraSession* session, QObject *parent) - :QVideoRendererControl(parent), - m_session(session) -{ -} - -DSVideoRendererControl::~DSVideoRendererControl() = default; - -QAbstractVideoSurface* DSVideoRendererControl::surface() const -{ - return m_surface; -} - -void DSVideoRendererControl::setSurface(QAbstractVideoSurface *surface) -{ - m_surface = surface; - if(m_session) - m_session->setSurface(m_surface); -} - -QT_END_NAMESPACE - diff --git a/src/plugins/directshow/camera/dsvideorenderer.h b/src/plugins/directshow/camera/dsvideorenderer.h deleted file mode 100644 index a6a1f8103..000000000 --- a/src/plugins/directshow/camera/dsvideorenderer.h +++ /dev/null @@ -1,68 +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 DSVIDEORENDERER_H -#define DSVIDEORENDERER_H - -#include <qvideorenderercontrol.h> -#include "dscamerasession.h" - -QT_BEGIN_NAMESPACE - - -class DSVideoRendererControl : public QVideoRendererControl -{ - Q_OBJECT -public: - DSVideoRendererControl(DSCameraSession* session, QObject *parent = nullptr); - ~DSVideoRendererControl() override; - - QAbstractVideoSurface *surface() const override; - void setSurface(QAbstractVideoSurface *surface) override; - - void setSession(DSCameraSession* session); - -private: - QAbstractVideoSurface* m_surface = nullptr; - DSCameraSession* m_session; -}; - -QT_END_NAMESPACE - -#endif // DSVIDEORENDERER_H |