diff --git a/src/plugins/directshow/camera/camera.pri b/src/plugins/directshow/camera/camera.pri index 6ea69477bdc0129769d2f39bb057430be0ca640f..5d8c4cfe4137badae4fdeb47db1fd10cebfadadd 100644 --- a/src/plugins/directshow/camera/camera.pri +++ b/src/plugins/directshow/camera/camera.pri @@ -12,7 +12,9 @@ HEADERS += \ $$PWD/directshowcameraglobal.h \ $$PWD/dscameraviewfindersettingscontrol.h \ $$PWD/dscameraimageprocessingcontrol.h \ - $$PWD/directshowcameraexposurecontrol.h + $$PWD/directshowcameraexposurecontrol.h \ + $$PWD/directshowcameracapturedestinationcontrol.h \ + $$PWD/directshowcameracapturebufferformatcontrol.h SOURCES += \ $$PWD/dscameraservice.cpp \ @@ -23,7 +25,9 @@ SOURCES += \ $$PWD/dscamerasession.cpp \ $$PWD/dscameraviewfindersettingscontrol.cpp \ $$PWD/dscameraimageprocessingcontrol.cpp \ - $$PWD/directshowcameraexposurecontrol.cpp + $$PWD/directshowcameraexposurecontrol.cpp \ + $$PWD/directshowcameracapturedestinationcontrol.cpp \ + $$PWD/directshowcameracapturebufferformatcontrol.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 new file mode 100644 index 0000000000000000000000000000000000000000..cc0a0ad17204f5935ea669e8fdf1e5c4fc6d4c29 --- /dev/null +++ b/src/plugins/directshow/camera/directshowcameracapturebufferformatcontrol.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** 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 new file mode 100644 index 0000000000000000000000000000000000000000..cacd3652bfa8ad9f527c9e0da0a18bea8fb2c939 --- /dev/null +++ b/src/plugins/directshow/camera/directshowcameracapturebufferformatcontrol.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** 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 new file mode 100644 index 0000000000000000000000000000000000000000..bfb10fc03397e22d014f488fda92019d2e00ceb3 --- /dev/null +++ b/src/plugins/directshow/camera/directshowcameracapturedestinationcontrol.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** 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 new file mode 100644 index 0000000000000000000000000000000000000000..224df9dbcae5269c1aa826d07233ccbc636bb052 --- /dev/null +++ b/src/plugins/directshow/camera/directshowcameracapturedestinationcontrol.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** 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/dscameraservice.cpp b/src/plugins/directshow/camera/dscameraservice.cpp index c11111be1e8ea971c2df34b7b461fb051d5bb2e9..71c0f685a58585fada3e4ed9ff29bb6bc06ec815 100644 --- a/src/plugins/directshow/camera/dscameraservice.cpp +++ b/src/plugins/directshow/camera/dscameraservice.cpp @@ -49,6 +49,8 @@ #include "dscameraviewfindersettingscontrol.h" #include "dscameraimageprocessingcontrol.h" #include "directshowcameraexposurecontrol.h" +#include "directshowcameracapturedestinationcontrol.h" +#include "directshowcameracapturebufferformatcontrol.h" QT_BEGIN_NAMESPACE @@ -62,6 +64,8 @@ DSCameraService::DSCameraService(QObject *parent): , 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) { } @@ -75,6 +79,8 @@ DSCameraService::~DSCameraService() delete m_imageCapture; delete m_session; delete m_exposureControl; + delete m_captureDestinationControl; + delete m_captureBufferFormatControl; } QMediaControl* DSCameraService::requestControl(const char *name) @@ -104,6 +110,12 @@ QMediaControl* DSCameraService::requestControl(const char *name) 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; + return 0; } diff --git a/src/plugins/directshow/camera/dscameraservice.h b/src/plugins/directshow/camera/dscameraservice.h index 12b07bd84eec07a5ec87966f45d0e69225a61bc9..bf2e31435977c4057f2eb4cbc8978ccc4f2815bc 100644 --- a/src/plugins/directshow/camera/dscameraservice.h +++ b/src/plugins/directshow/camera/dscameraservice.h @@ -53,6 +53,8 @@ class DSImageCaptureControl; class DSCameraViewfinderSettingsControl; class DSCameraImageProcessingControl; class DirectShowCameraExposureControl; +class DirectShowCameraCaptureDestinationControl; +class DirectShowCameraCaptureBufferFormatControl; class DSCameraService : public QMediaService { @@ -74,6 +76,8 @@ private: DSCameraViewfinderSettingsControl *m_viewfinderSettings; DSCameraImageProcessingControl *m_imageProcessingControl; DirectShowCameraExposureControl *m_exposureControl; + DirectShowCameraCaptureDestinationControl *m_captureDestinationControl; + DirectShowCameraCaptureBufferFormatControl *m_captureBufferFormatControl; }; QT_END_NAMESPACE diff --git a/src/plugins/directshow/camera/dscamerasession.cpp b/src/plugins/directshow/camera/dscamerasession.cpp index 6590afeb9b08155145e35ab1c02782b03e41dbba..82125d4f60368c8d95c227ac8cea8c3e9b843a99 100644 --- a/src/plugins/directshow/camera/dscamerasession.cpp +++ b/src/plugins/directshow/camera/dscamerasession.cpp @@ -69,6 +69,7 @@ DSCameraSession::DSCameraSession(QObject *parent) , m_readyForCapture(false) , m_imageIdCounter(0) , m_currentImageId(-1) + , m_captureDestinations(QCameraImageCapture::CaptureToFile) , m_status(QCamera::UnloadedStatus) { connect(this, SIGNAL(statusChanged(QCamera::Status)), @@ -354,6 +355,25 @@ bool DSCameraSession::getCameraControlInterface(IAMCameraControl **cameraControl 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); +} + bool DSCameraSession::load() { unload(); @@ -586,8 +606,8 @@ void DSCameraSession::presentFrame() m_capturedFrame.unmap(); - QtConcurrent::run(this, &DSCameraSession::saveCapturedImage, - m_currentImageId, captureImage, m_imageCaptureFileName); + QtConcurrent::run(this, &DSCameraSession::processCapturedImage, + m_currentImageId, m_captureDestinations, captureImage, m_imageCaptureFileName); m_imageCaptureFileName.clear(); m_currentImageId = -1; @@ -603,14 +623,22 @@ void DSCameraSession::presentFrame() updateReadyForCapture(); } -void DSCameraSession::saveCapturedImage(int id, const QImage &image, const QString &path) +void DSCameraSession::processCapturedImage(int id, + QCameraImageCapture::CaptureDestinations captureDestinations, + const QImage &image, + const QString &path) { - if (image.save(path, "JPG")) { - emit imageSaved(id, path); - } else { - emit captureError(id, QCameraImageCapture::ResourceError, - tr("Could not save image to file.")); + if (captureDestinations & QCameraImageCapture::CaptureToFile) { + if (image.save(path, "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() diff --git a/src/plugins/directshow/camera/dscamerasession.h b/src/plugins/directshow/camera/dscamerasession.h index 90407f49e9faf36b4a50c2a9174bc3acd788efb1..85bddbc9e93eee2398379f79f42ac0eb50020180 100644 --- a/src/plugins/directshow/camera/dscamerasession.h +++ b/src/plugins/directshow/camera/dscamerasession.h @@ -50,6 +50,7 @@ #include <QtMultimedia/qabstractvideosurface.h> #include <QtMultimedia/qvideosurfaceformat.h> #include <QtMultimedia/qcameraimageprocessingcontrol.h> +#include <QtMultimedia/qcameraimagecapture.h> #include <private/qmediastoragelocation_p.h> #include <tchar.h> @@ -120,13 +121,19 @@ public: bool getCameraControlInterface(IAMCameraControl **cameraControl) const; + bool isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const; + QCameraImageCapture::CaptureDestinations captureDestination() const; + void setCaptureDestination(QCameraImageCapture::CaptureDestinations destinations); + 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); private Q_SLOTS: void presentFrame(); @@ -157,7 +164,7 @@ private: void setStatus(QCamera::Status status); void onFrameAvailable(double time, const QByteArray &data); - void saveCapturedImage(int id, const QImage &image, const QString &path); + void processCapturedImage(int id, QCameraImageCapture::CaptureDestinations captureDestinations, const QImage &image, const QString &path); bool createFilterGraph(); bool connectGraph(); @@ -208,6 +215,7 @@ private: int m_imageIdCounter; int m_currentImageId; QVideoFrame m_capturedFrame; + QCameraImageCapture::CaptureDestinations m_captureDestinations; // Internal state QCamera::Status m_status; diff --git a/src/plugins/directshow/camera/dsimagecapturecontrol.cpp b/src/plugins/directshow/camera/dsimagecapturecontrol.cpp index 9d4a7ea1dbc21c564115070813b7c8b79d2f28af..c92ce98e1adc4b07ffeab0276830c9ec9446b7e0 100644 --- a/src/plugins/directshow/camera/dsimagecapturecontrol.cpp +++ b/src/plugins/directshow/camera/dsimagecapturecontrol.cpp @@ -57,6 +57,8 @@ DSImageCaptureControl::DSImageCaptureControl(DSCameraSession *session) this, SIGNAL(readyForCaptureChanged(bool))); connect(m_session, SIGNAL(captureError(int,int,QString)), this, SIGNAL(error(int,int,QString))); + connect(m_session, &DSCameraSession::imageAvailable, + this, &DSImageCaptureControl::imageAvailable); } DSImageCaptureControl::~DSImageCaptureControl()