diff options
author | Lars Knoll <lars.knoll@qt.io> | 2021-01-22 10:03:21 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2021-01-29 08:51:25 +0000 |
commit | 2bcbc8953c2fa247937d1bc31638b583477f7471 (patch) | |
tree | b85e484e94f7979da1a649e8179d6b6f03d6ee4c /tests | |
parent | a5bfe043139ae40fa9f7ffc01b71ec37668a5534 (diff) |
Get rid of QVideoDeviceSelectorControl
Move the camera selection into QCameraControl directly
and give it a more decent API using QCameraInfo.
Remove the QCamer(name) constructor, as it could lead
to invalid cameras being constructed.
Change-Id: Ieb26f62684080eaf9a10770ec7df2cde2996bcff
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests')
8 files changed, 41 insertions, 181 deletions
diff --git a/tests/auto/integration/qcamerabackend/tst_qcamerabackend.cpp b/tests/auto/integration/qcamerabackend/tst_qcamerabackend.cpp index cba570b7e..ce5b8e507 100644 --- a/tests/auto/integration/qcamerabackend/tst_qcamerabackend.cpp +++ b/tests/auto/integration/qcamerabackend/tst_qcamerabackend.cpp @@ -65,7 +65,6 @@ public slots: private slots: void testCameraInfo(); - void testCtorWithDevice(); void testCtorWithCameraInfo(); void testCtorWithPosition(); @@ -111,22 +110,6 @@ void tst_QCameraBackend::testCameraInfo() } } -void tst_QCameraBackend::testCtorWithDevice() -{ - const auto availableCameras = QMediaDeviceManager::videoInputs(); - if (availableCameras.isEmpty()) - QSKIP("Camera selection not supported"); - - QCamera *camera = new QCamera(availableCameras.first().id()); - QCOMPARE(camera->error(), QCamera::NoError); - delete camera; - - //loading non existing camera should fail - camera = new QCamera(QUuid::createUuid().toByteArray()); - QCOMPARE(camera->error(), QCamera::CameraError); - delete camera; -} - void tst_QCameraBackend::testCtorWithCameraInfo() { if (QMediaDeviceManager::videoInputs().isEmpty()) @@ -533,7 +516,7 @@ void tst_QCameraBackend::testExposureMode() void tst_QCameraBackend::testVideoRecording_data() { - QTest::addColumn<QByteArray>("device"); + QTest::addColumn<QCameraInfo>("device"); const auto devices = QMediaDeviceManager::videoInputs(); @@ -543,14 +526,14 @@ void tst_QCameraBackend::testVideoRecording_data() } if (devices.isEmpty()) - QTest::newRow("Default device") << QByteArray(); + QTest::newRow("Default device") << QCameraInfo(); } void tst_QCameraBackend::testVideoRecording() { - QFETCH(QByteArray, device); + QFETCH(QCameraInfo, device); - QScopedPointer<QCamera> camera(device.isEmpty() ? new QCamera : new QCamera(device)); + QScopedPointer<QCamera> camera(new QCamera(device)); QMediaRecorder recorder(camera.data()); diff --git a/tests/auto/unit/mockbackend/CMakeLists.txt b/tests/auto/unit/mockbackend/CMakeLists.txt index bddc6710b..a5add2065 100644 --- a/tests/auto/unit/mockbackend/CMakeLists.txt +++ b/tests/auto/unit/mockbackend/CMakeLists.txt @@ -33,7 +33,6 @@ target_sources(QtMultimediaMockBackend INTERFACE mockmediastreamscontrol.h mockmetadatareadercontrol.h mockmetadatawritercontrol.h - mockvideodeviceselectorcontrol.h mockvideoencodercontrol.h mockvideoprobecontrol.h mockvideorenderercontrol.h diff --git a/tests/auto/unit/mockbackend/mockcameracontrol.h b/tests/auto/unit/mockbackend/mockcameracontrol.h index 5f9ed6c9f..cb48e8be7 100644 --- a/tests/auto/unit/mockbackend/mockcameracontrol.h +++ b/tests/auto/unit/mockbackend/mockcameracontrol.h @@ -30,6 +30,7 @@ #define MOCKCAMERACONTROL_H #include "qcameracontrol.h" +#include "qcamerainfo.h" #include <qtimer.h> class MockCameraControl : public QCameraControl @@ -234,9 +235,16 @@ public: emit statusChanged(newStatus); } + void setCamera(const QCameraInfo &camera) + { + m_camera = camera; + } + + QCamera::State m_state; QCamera::CaptureModes m_captureMode; QCamera::Status m_status; + QCameraInfo m_camera; bool m_propertyChangesSupported; diff --git a/tests/auto/unit/mockbackend/mockmediarecorderservice.h b/tests/auto/unit/mockbackend/mockmediarecorderservice.h index 50e68efca..7a68cf35d 100644 --- a/tests/auto/unit/mockbackend/mockmediarecorderservice.h +++ b/tests/auto/unit/mockbackend/mockmediarecorderservice.h @@ -45,7 +45,6 @@ #include "mockcameracontrol.h" #include "mockvideorenderercontrol.h" #include "mockvideowindowcontrol.h" -#include "mockvideodeviceselectorcontrol.h" #include <private/qmediaplatformcaptureinterface_p.h> class MockMediaRecorderService : public QMediaPlatformCaptureInterface @@ -69,7 +68,6 @@ public: mockImageEncoderControl = new MockImageEncoderControl(this); rendererControl = new MockVideoRendererControl(this); windowControl = new MockVideoWindowControl(this); - mockVideoDeviceSelectorControl = new MockVideoDeviceSelectorControl(this); rendererRef = 0; windowRef = 0; } @@ -108,8 +106,6 @@ public: return mockImageProcessingControl; if (qstrcmp(name, QImageEncoderControl_iid) == 0) return mockImageEncoderControl; - if (qstrcmp(name, QVideoDeviceSelectorControl_iid) == 0) - return mockVideoDeviceSelectorControl; if (qstrcmp(name, QVideoRendererControl_iid) == 0) { if (rendererRef == 0) { @@ -145,7 +141,6 @@ public: MockImageEncoderControl *mockImageEncoderControl; MockVideoRendererControl *rendererControl; MockVideoWindowControl *windowControl; - MockVideoDeviceSelectorControl *mockVideoDeviceSelectorControl; int rendererRef; int windowRef; diff --git a/tests/auto/unit/mockbackend/mockvideodeviceselectorcontrol.h b/tests/auto/unit/mockbackend/mockvideodeviceselectorcontrol.h deleted file mode 100644 index 764c062b9..000000000 --- a/tests/auto/unit/mockbackend/mockvideodeviceselectorcontrol.h +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef MOCKVIDEODEVICESELECTORCONTROL_H -#define MOCKVIDEODEVICESELECTORCONTROL_H - -#include <qvideodeviceselectorcontrol.h> - -class MockVideoDeviceSelectorControl : public QVideoDeviceSelectorControl -{ - Q_OBJECT -public: - MockVideoDeviceSelectorControl(QObject *parent) - : QVideoDeviceSelectorControl(parent) - , m_selectedDevice(1) - { - } - - ~MockVideoDeviceSelectorControl() { } - - int deviceCount() const { return availableCameras().count(); } - - QString deviceName(int index) const { return QString::fromLatin1(availableCameras().at(index)); } - QString deviceDescription(int index) const { return cameraDescription(availableCameras().at(index)); } - QCamera::Position cameraPosition(int index) const - { - if (deviceName(index) == "backcamera") - return QCamera::BackFace; - else - return QCamera::UnspecifiedPosition; - } - int cameraOrientation(int index) const - { - if (deviceName(index) == "backcamera") - return 90; - else - return 0; - } - - int defaultDevice() const { return availableCameras().indexOf(defaultCamera()); } - int selectedDevice() const { return m_selectedDevice; } - void setSelectedDevice(int index) - { - m_selectedDevice = index; - emit selectedDeviceChanged(m_selectedDevice); - emit selectedDeviceChanged(deviceName(m_selectedDevice)); - } - - static QByteArray defaultCamera() - { - return "othercamera"; - } - - static QList<QByteArray> availableCameras() - { - return QList<QByteArray>() << "backcamera" << "othercamera"; - } - - static QString cameraDescription(const QByteArray &camera) - { - if (camera == "backcamera") - return QStringLiteral("backcamera desc"); - else if (camera == "othercamera") - return QStringLiteral("othercamera desc"); - else - return QString(); - } - -private: - int m_selectedDevice; - QStringList m_devices; - QStringList m_descriptions; -}; - -#endif // MOCKVIDEODEVICESELECTORCONTROL_H diff --git a/tests/auto/unit/multimedia/qcamera/tst_qcamera.cpp b/tests/auto/unit/multimedia/qcamera/tst_qcamera.cpp index 5e5118331..48e71a5e2 100644 --- a/tests/auto/unit/multimedia/qcamera/tst_qcamera.cpp +++ b/tests/auto/unit/multimedia/qcamera/tst_qcamera.cpp @@ -1618,76 +1618,61 @@ void tst_QCamera::testCameraControl() void tst_QCamera::testConstructor() { - // Service doesn't implement QVideoDeviceSelectorControl - MockMediaRecorderService::simpleCamera = true; - + auto cameras = QMediaDeviceManager::videoInputs(); + QCameraInfo defaultCamera = QMediaDeviceManager::defaultVideoInput(); + QCameraInfo frontCamera, backCamera; + for (const auto &c : cameras) { + if (frontCamera.isNull() && c.position() == QCamera::FrontFace) + frontCamera = c; + if (backCamera.isNull() && c.position() == QCamera::BackFace) + backCamera = c; + } + QVERIFY(!defaultCamera.isNull()); + QVERIFY(!frontCamera.isNull()); + QVERIFY(!backCamera.isNull()); { QCamera camera; QCOMPARE(camera.availability(), QMultimedia::Available); QCOMPARE(camera.error(), QCamera::NoError); + QCOMPARE(camera.cameraInfo(), defaultCamera); } { - // Requesting a camera at a specific position from a service which doesn't implement - // the QVideoDeviceSelectorControl should result in loading the default camera QCamera camera(QCamera::FrontFace); QCOMPARE(camera.availability(), QMultimedia::Available); QCOMPARE(camera.error(), QCamera::NoError); - } - - { - QCamera camera; - auto *service = integration->lastCaptureService(); - QCOMPARE(camera.availability(), QMultimedia::Available); - QCOMPARE(camera.error(), QCamera::NoError); - QCOMPARE(service->mockVideoDeviceSelectorControl->selectedDevice(), 1); // default is 1 + QCOMPARE(camera.cameraInfo(), frontCamera); } { QCamera camera(QMediaDeviceManager::defaultVideoInput()); - auto *service = integration->lastCaptureService(); QCOMPARE(camera.availability(), QMultimedia::Available); QCOMPARE(camera.error(), QCamera::NoError); - QCOMPARE(service->mockVideoDeviceSelectorControl->selectedDevice(), 1); - QCOMPARE(QCameraInfo(camera), QMediaDeviceManager::defaultVideoInput()); + QCOMPARE(camera.cameraInfo(), defaultCamera); } { QCameraInfo cameraInfo = QMediaDeviceManager::videoInputs().at(0); QCamera camera(cameraInfo); - auto *service = integration->lastCaptureService(); QCOMPARE(camera.availability(), QMultimedia::Available); QCOMPARE(camera.error(), QCamera::NoError); - QCOMPARE(service->mockVideoDeviceSelectorControl->selectedDevice(), 0); QCOMPARE(QCameraInfo(camera), cameraInfo); } { - // Requesting a camera at a position which is not available should result in - // loading the default camera - QCamera camera(QCamera::FrontFace); - auto *service = integration->lastCaptureService(); - QCOMPARE(camera.availability(), QMultimedia::Available); - QCOMPARE(camera.error(), QCamera::NoError); - QCOMPARE(service->mockVideoDeviceSelectorControl->selectedDevice(), 1); - } - - { QCamera camera(QCamera::BackFace); - auto *service = integration->lastCaptureService(); QCOMPARE(camera.availability(), QMultimedia::Available); QCOMPARE(camera.error(), QCamera::NoError); - QCOMPARE(service->mockVideoDeviceSelectorControl->selectedDevice(), 0); + QCOMPARE(camera.cameraInfo(), backCamera); } { // Should load the default camera when UnspecifiedPosition is requested QCamera camera(QCamera::UnspecifiedPosition); - auto *service = integration->lastCaptureService(); QCOMPARE(camera.availability(), QMultimedia::Available); QCOMPARE(camera.error(), QCamera::NoError); - QCOMPARE(service->mockVideoDeviceSelectorControl->selectedDevice(), 1); + QCOMPARE(camera.cameraInfo(), defaultCamera); } } @@ -1773,7 +1758,7 @@ void tst_QCamera::testQCameraIsAvailable() void tst_QCamera::testQCameraIsNotAvailable() { integration->setFlags(QMockIntegration::NoCaptureInterface); - QCamera camera("random"); + QCamera camera; QCOMPARE(camera.error(), QCamera::CameraError); QVERIFY(!camera.isAvailable()); diff --git a/tests/auto/unit/multimedia/qcamerainfo/tst_qcamerainfo.cpp b/tests/auto/unit/multimedia/qcamerainfo/tst_qcamerainfo.cpp index 139eb0130..42deae79b 100644 --- a/tests/auto/unit/multimedia/qcamerainfo/tst_qcamerainfo.cpp +++ b/tests/auto/unit/multimedia/qcamerainfo/tst_qcamerainfo.cpp @@ -74,24 +74,6 @@ void tst_QCameraInfo::cleanup() void tst_QCameraInfo::constructor() { - // Service doesn't implement QVideoDeviceSelectorControl - // QCameraInfo should not be valid in this case - MockMediaRecorderService::simpleCamera = true; - - { - QCamera camera; - - QCameraInfo info(camera); - QVERIFY(info.isNull()); - QVERIFY(info.id().isEmpty()); - QVERIFY(info.description().isEmpty()); - QCOMPARE(info.position(), QCamera::UnspecifiedPosition); - QCOMPARE(info.orientation(), 0); - } - - // Service implements QVideoDeviceSelectorControl - MockMediaRecorderService::simpleCamera = false; - { // default camera QCamera camera; @@ -103,8 +85,17 @@ void tst_QCameraInfo::constructor() QCOMPARE(info.orientation(), 0); } - QCamera camera("backcamera"); - QCameraInfo info(camera); + auto cameras = QMediaDeviceManager::videoInputs(); + QCameraInfo info; + for (const auto &c : cameras) { + if (c.position() == QCamera::BackFace) + info = c; + } + QVERIFY(!info.isNull()); + + QCamera camera(info); + QCOMPARE(info, camera.cameraInfo()); + QCOMPARE(info, QCameraInfo(camera)); QVERIFY(!info.isNull()); QCOMPARE(info.id(), QStringLiteral("backcamera")); QCOMPARE(info.description(), QStringLiteral("backcamera desc")); diff --git a/tests/auto/unit/multimedia/qmediaservice/tst_qmediaservice.cpp b/tests/auto/unit/multimedia/qmediaservice/tst_qmediaservice.cpp index 574b1f327..c3860930d 100644 --- a/tests/auto/unit/multimedia/qmediaservice/tst_qmediaservice.cpp +++ b/tests/auto/unit/multimedia/qmediaservice/tst_qmediaservice.cpp @@ -30,7 +30,6 @@ #include <QtTest/QtTest> -#include <qvideodeviceselectorcontrol.h> #include <qmediaservice.h> #include <qmediaservice.h> |