summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Stromme <christian.stromme@qt.io>2016-11-22 18:53:49 +0100
committerChristian Stromme <christian.stromme@qt.io>2018-01-22 20:50:17 +0000
commitc20d3fa8c42d3ea0a088f208b55dfc66b58f6674 (patch)
tree974dfeafe5fde1aa3f9bbaa77193cf0e1baadd9b /src
parent469a18793a11b45ffa6f7ed3f873bddbae8e900d (diff)
DirectShow: Add camera image capture controls
Adds controls for setting the capture destination and buffer format. [ChangeLog][DirectShow] Added support for setting the capture destination and format. Change-Id: I7420ea5dce9bf1bef391b6ba3a1537bedfbcf52d Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/directshow/camera/camera.pri8
-rw-r--r--src/plugins/directshow/camera/directshowcameracapturebufferformatcontrol.cpp65
-rw-r--r--src/plugins/directshow/camera/directshowcameracapturebufferformatcontrol.h60
-rw-r--r--src/plugins/directshow/camera/directshowcameracapturedestinationcontrol.cpp68
-rw-r--r--src/plugins/directshow/camera/directshowcameracapturedestinationcontrol.h66
-rw-r--r--src/plugins/directshow/camera/dscameraservice.cpp12
-rw-r--r--src/plugins/directshow/camera/dscameraservice.h4
-rw-r--r--src/plugins/directshow/camera/dscamerasession.cpp44
-rw-r--r--src/plugins/directshow/camera/dscamerasession.h10
-rw-r--r--src/plugins/directshow/camera/dsimagecapturecontrol.cpp2
10 files changed, 328 insertions, 11 deletions
diff --git a/src/plugins/directshow/camera/camera.pri b/src/plugins/directshow/camera/camera.pri
index 6ea69477b..5d8c4cfe4 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 000000000..cc0a0ad17
--- /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 000000000..cacd3652b
--- /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 000000000..bfb10fc03
--- /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 000000000..224df9dbc
--- /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 c11111be1..71c0f685a 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 12b07bd84..bf2e31435 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 6590afeb9..82125d4f6 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 90407f49e..85bddbc9e 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 9d4a7ea1d..c92ce98e1 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()