summaryrefslogtreecommitdiffstats
path: root/tests/auto/unit/qmediaserviceprovider
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@digia.com>2014-01-22 16:18:42 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-28 14:10:00 +0100
commitb28ee24628f77fced393cacc45500be6761e4497 (patch)
tree811173f8a2caf84e0fa386010283ccfd32c6ad0d /tests/auto/unit/qmediaserviceprovider
parentd964388b38ec4762e315d86aacb779604bcdca1b (diff)
New QCameraInfo class.
The class allows to get the list of available cameras on the system as well as getting some static information about them such as their unique ID, display name, physical position and sensor orientation. This makes QCamera::availableDevices() and QCamera::deviceDescription() obsolete. This patch contains the API, documentation and auto-tests but not the actual implementation by each backend (except for retrieving the default camera device). [ChangeLog][QtMultimedia] Added new QCameraInfo class [ChangeLog][QtMultimedia] QCamera: availableDevices() and deviceDescription() are deprecated, use QCameraInfo instead Change-Id: I64fd65729ab26a789468979ed5444ee90bb82cd0 Reviewed-by: Christian Stromme <christian.stromme@digia.com>
Diffstat (limited to 'tests/auto/unit/qmediaserviceprovider')
-rw-r--r--tests/auto/unit/qmediaserviceprovider/mockserviceplugin1/mockserviceplugin1.cpp19
-rw-r--r--tests/auto/unit/qmediaserviceprovider/mockserviceplugin3/mockserviceplugin3.cpp41
-rw-r--r--tests/auto/unit/qmediaserviceprovider/mockserviceplugin3/mockserviceplugin3.json2
-rw-r--r--tests/auto/unit/qmediaserviceprovider/mockserviceplugin5/mockserviceplugin5.cpp118
-rw-r--r--tests/auto/unit/qmediaserviceprovider/mockserviceplugin5/mockserviceplugin5.json4
-rw-r--r--tests/auto/unit/qmediaserviceprovider/mockserviceplugin5/mockserviceplugin5.pro23
-rw-r--r--tests/auto/unit/qmediaserviceprovider/qmediaserviceprovider.pro1
-rw-r--r--tests/auto/unit/qmediaserviceprovider/tst_qmediaserviceprovider.cpp116
8 files changed, 302 insertions, 22 deletions
diff --git a/tests/auto/unit/qmediaserviceprovider/mockserviceplugin1/mockserviceplugin1.cpp b/tests/auto/unit/qmediaserviceprovider/mockserviceplugin1/mockserviceplugin1.cpp
index ba63ac34f..b4469e71c 100644
--- a/tests/auto/unit/qmediaserviceprovider/mockserviceplugin1/mockserviceplugin1.cpp
+++ b/tests/auto/unit/qmediaserviceprovider/mockserviceplugin1/mockserviceplugin1.cpp
@@ -44,12 +44,10 @@
#include "../mockservice.h"
class MockServicePlugin1 : public QMediaServiceProviderPlugin,
- public QMediaServiceSupportedFormatsInterface,
- public QMediaServiceSupportedDevicesInterface
+ public QMediaServiceSupportedFormatsInterface
{
Q_OBJECT
Q_INTERFACES(QMediaServiceSupportedFormatsInterface)
- Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "mockserviceplugin1.json")
public:
QStringList keys() const
@@ -87,21 +85,6 @@ public:
{
return QStringList("audio/ogg");
}
-
- QList<QByteArray> devices(const QByteArray &service) const
- {
- Q_UNUSED(service);
- QList<QByteArray> res;
- return res;
- }
-
- QString deviceDescription(const QByteArray &service, const QByteArray &device)
- {
- if (devices(service).contains(device))
- return QString(device)+" description";
- else
- return QString();
- }
};
#include "mockserviceplugin1.moc"
diff --git a/tests/auto/unit/qmediaserviceprovider/mockserviceplugin3/mockserviceplugin3.cpp b/tests/auto/unit/qmediaserviceprovider/mockserviceplugin3/mockserviceplugin3.cpp
index fe7d49210..592afdec3 100644
--- a/tests/auto/unit/qmediaserviceprovider/mockserviceplugin3/mockserviceplugin3.cpp
+++ b/tests/auto/unit/qmediaserviceprovider/mockserviceplugin3/mockserviceplugin3.cpp
@@ -44,17 +44,22 @@
#include "../mockservice.h"
class MockServicePlugin3 : public QMediaServiceProviderPlugin,
- public QMediaServiceSupportedDevicesInterface
+ public QMediaServiceSupportedDevicesInterface,
+ public QMediaServiceDefaultDeviceInterface,
+ public QMediaServiceCameraInfoInterface
{
Q_OBJECT
Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
+ Q_INTERFACES(QMediaServiceDefaultDeviceInterface)
+ Q_INTERFACES(QMediaServiceCameraInfoInterface)
Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "mockserviceplugin3.json")
public:
QStringList keys() const
{
return QStringList() <<
QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER) <<
- QLatin1String(Q_MEDIASERVICE_AUDIOSOURCE);
+ QLatin1String(Q_MEDIASERVICE_AUDIOSOURCE) <<
+ QLatin1String(Q_MEDIASERVICE_CAMERA);
}
QMediaService* create(QString const& key)
@@ -70,12 +75,26 @@ public:
delete service;
}
+ QByteArray defaultDevice(const QByteArray &service) const
+ {
+ if (service == Q_MEDIASERVICE_AUDIOSOURCE)
+ return "audiosource1";
+
+ if (service == Q_MEDIASERVICE_CAMERA)
+ return "frontcamera";
+
+ return QByteArray();
+ }
+
QList<QByteArray> devices(const QByteArray &service) const
{
QList<QByteArray> res;
- if (service == QByteArray(Q_MEDIASERVICE_AUDIOSOURCE))
+ if (service == Q_MEDIASERVICE_AUDIOSOURCE)
res << "audiosource1" << "audiosource2";
+ if (service == Q_MEDIASERVICE_CAMERA)
+ res << "frontcamera";
+
return res;
}
@@ -86,6 +105,22 @@ public:
else
return QString();
}
+
+ QCamera::Position cameraPosition(const QByteArray &device) const
+ {
+ if (device == "frontcamera")
+ return QCamera::FrontFace;
+
+ return QCamera::UnspecifiedPosition;
+ }
+
+ int cameraOrientation(const QByteArray &device) const
+ {
+ if (device == "frontcamera")
+ return 270;
+
+ return 0;
+ }
};
#include "mockserviceplugin3.moc"
diff --git a/tests/auto/unit/qmediaserviceprovider/mockserviceplugin3/mockserviceplugin3.json b/tests/auto/unit/qmediaserviceprovider/mockserviceplugin3/mockserviceplugin3.json
index 591a02e51..ab55b5d1d 100644
--- a/tests/auto/unit/qmediaserviceprovider/mockserviceplugin3/mockserviceplugin3.json
+++ b/tests/auto/unit/qmediaserviceprovider/mockserviceplugin3/mockserviceplugin3.json
@@ -1,4 +1,4 @@
{
"Keys": ["mockserviceplugin3"],
- "Services": ["org.qt-project.qt.mediaplayer", "org.qt-project.qt.audiosource"]
+ "Services": ["org.qt-project.qt.mediaplayer", "org.qt-project.qt.audiosource", "org.qt-project.qt.camera"]
}
diff --git a/tests/auto/unit/qmediaserviceprovider/mockserviceplugin5/mockserviceplugin5.cpp b/tests/auto/unit/qmediaserviceprovider/mockserviceplugin5/mockserviceplugin5.cpp
new file mode 100644
index 000000000..c255914e7
--- /dev/null
+++ b/tests/auto/unit/qmediaserviceprovider/mockserviceplugin5/mockserviceplugin5.cpp
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qmediaserviceproviderplugin.h>
+#include <qmediaservice.h>
+#include "../mockservice.h"
+
+class MockServicePlugin5 : public QMediaServiceProviderPlugin,
+ public QMediaServiceSupportedDevicesInterface,
+ public QMediaServiceDefaultDeviceInterface,
+ public QMediaServiceCameraInfoInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
+ Q_INTERFACES(QMediaServiceDefaultDeviceInterface)
+ Q_INTERFACES(QMediaServiceCameraInfoInterface)
+ Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "mockserviceplugin5.json")
+public:
+ QStringList keys() const
+ {
+ return QStringList() << QLatin1String(Q_MEDIASERVICE_CAMERA);
+ }
+
+ QMediaService* create(QString const& key)
+ {
+ if (keys().contains(key))
+ return new MockMediaService("MockServicePlugin5");
+ else
+ return 0;
+ }
+
+ void release(QMediaService *service)
+ {
+ delete service;
+ }
+
+ QByteArray defaultDevice(const QByteArray &service) const
+ {
+ if (service == Q_MEDIASERVICE_CAMERA)
+ return "backcamera";
+
+ return QByteArray();
+ }
+
+ QList<QByteArray> devices(const QByteArray &service) const
+ {
+ QList<QByteArray> res;
+ if (service == Q_MEDIASERVICE_CAMERA)
+ res << "backcamera" << "somecamera";
+
+ return res;
+ }
+
+ QString deviceDescription(const QByteArray &service, const QByteArray &device)
+ {
+ if (devices(service).contains(device))
+ return QString(device)+" description";
+ else
+ return QString();
+ }
+
+ QCamera::Position cameraPosition(const QByteArray &device) const
+ {
+ if (device == "backcamera")
+ return QCamera::BackFace;
+
+ return QCamera::UnspecifiedPosition;
+ }
+
+ int cameraOrientation(const QByteArray &device) const
+ {
+ if (device == "backcamera")
+ return 90;
+
+ return 0;
+ }
+};
+
+#include "mockserviceplugin5.moc"
+
diff --git a/tests/auto/unit/qmediaserviceprovider/mockserviceplugin5/mockserviceplugin5.json b/tests/auto/unit/qmediaserviceprovider/mockserviceplugin5/mockserviceplugin5.json
new file mode 100644
index 000000000..cc6f4816c
--- /dev/null
+++ b/tests/auto/unit/qmediaserviceprovider/mockserviceplugin5/mockserviceplugin5.json
@@ -0,0 +1,4 @@
+{
+ "Keys": ["mockserviceplugin5"],
+ "Services": ["org.qt-project.qt.camera"]
+}
diff --git a/tests/auto/unit/qmediaserviceprovider/mockserviceplugin5/mockserviceplugin5.pro b/tests/auto/unit/qmediaserviceprovider/mockserviceplugin5/mockserviceplugin5.pro
new file mode 100644
index 000000000..9657e3cc1
--- /dev/null
+++ b/tests/auto/unit/qmediaserviceprovider/mockserviceplugin5/mockserviceplugin5.pro
@@ -0,0 +1,23 @@
+TARGET = mockserviceplugin5
+QT += multimedia-private
+
+PLUGIN_TYPE=mediaservice
+PLUGIN_CLASS_NAME = MockServicePlugin5
+load(qt_plugin)
+
+DESTDIR = ../$${PLUGIN_TYPE}
+win32 {
+ CONFIG(debug, debug|release) {
+ DESTDIR = ../debug/$${PLUGIN_TYPE}
+ } else {
+ DESTDIR = ../release/$${PLUGIN_TYPE}
+ }
+}
+
+HEADERS += ../mockservice.h
+SOURCES += mockserviceplugin5.cpp
+OTHER_FILES += mockserviceplugin5.json
+
+target.path = $$[QT_INSTALL_TESTS]/tst_qmediaserviceprovider/$${PLUGIN_TYPE}
+
+DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
diff --git a/tests/auto/unit/qmediaserviceprovider/qmediaserviceprovider.pro b/tests/auto/unit/qmediaserviceprovider/qmediaserviceprovider.pro
index dbe878f39..cea19e212 100644
--- a/tests/auto/unit/qmediaserviceprovider/qmediaserviceprovider.pro
+++ b/tests/auto/unit/qmediaserviceprovider/qmediaserviceprovider.pro
@@ -6,6 +6,7 @@ SUBDIRS += \
mockserviceplugin2 \
mockserviceplugin3 \
mockserviceplugin4 \
+ mockserviceplugin5 \
test
# no special install rule for subdir
diff --git a/tests/auto/unit/qmediaserviceprovider/tst_qmediaserviceprovider.cpp b/tests/auto/unit/qmediaserviceprovider/tst_qmediaserviceprovider.cpp
index e39070d5f..3ad787130 100644
--- a/tests/auto/unit/qmediaserviceprovider/tst_qmediaserviceprovider.cpp
+++ b/tests/auto/unit/qmediaserviceprovider/tst_qmediaserviceprovider.cpp
@@ -52,6 +52,8 @@
#include <qmediaservice.h>
#include <qmediaplayer.h>
#include <qaudiorecorder.h>
+#include <qcamera.h>
+#include <qcamerainfo.h>
QT_USE_NAMESPACE
@@ -83,6 +85,9 @@ private slots:
void testHasSupport();
void testSupportedMimeTypes();
void testProviderHints();
+ void testDefaultDevice();
+ void testAvailableDevices();
+ void testCameraInfo();
private:
QObjectList plugins;
@@ -195,6 +200,7 @@ void tst_QMediaServiceProvider::testProviderHints()
QVERIFY(hint.isNull());
QCOMPARE(hint.type(), QMediaServiceProviderHint::Null);
QVERIFY(hint.device().isEmpty());
+ QCOMPARE(hint.cameraPosition(), QCamera::UnspecifiedPosition);
QVERIFY(hint.mimeType().isEmpty());
QVERIFY(hint.codecs().isEmpty());
QCOMPARE(hint.features(), 0);
@@ -206,6 +212,18 @@ void tst_QMediaServiceProvider::testProviderHints()
QVERIFY(!hint.isNull());
QCOMPARE(hint.type(), QMediaServiceProviderHint::Device);
QCOMPARE(hint.device(), deviceName);
+ QCOMPARE(hint.cameraPosition(), QCamera::UnspecifiedPosition);
+ QVERIFY(hint.mimeType().isEmpty());
+ QVERIFY(hint.codecs().isEmpty());
+ QCOMPARE(hint.features(), 0);
+ }
+
+ {
+ QMediaServiceProviderHint hint(QCamera::FrontFace);
+ QVERIFY(!hint.isNull());
+ QCOMPARE(hint.type(), QMediaServiceProviderHint::CameraPosition);
+ QVERIFY(hint.device().isEmpty());
+ QCOMPARE(hint.cameraPosition(), QCamera::FrontFace);
QVERIFY(hint.mimeType().isEmpty());
QVERIFY(hint.codecs().isEmpty());
QCOMPARE(hint.features(), 0);
@@ -216,6 +234,7 @@ void tst_QMediaServiceProvider::testProviderHints()
QVERIFY(!hint.isNull());
QCOMPARE(hint.type(), QMediaServiceProviderHint::SupportedFeatures);
QVERIFY(hint.device().isEmpty());
+ QCOMPARE(hint.cameraPosition(), QCamera::UnspecifiedPosition);
QVERIFY(hint.mimeType().isEmpty());
QVERIFY(hint.codecs().isEmpty());
QCOMPARE(hint.features(), QMediaServiceProviderHint::LowLatencyPlayback);
@@ -226,6 +245,7 @@ void tst_QMediaServiceProvider::testProviderHints()
QVERIFY(!hint.isNull());
QCOMPARE(hint.type(), QMediaServiceProviderHint::SupportedFeatures);
QVERIFY(hint.device().isEmpty());
+ QCOMPARE(hint.cameraPosition(), QCamera::UnspecifiedPosition);
QVERIFY(hint.mimeType().isEmpty());
QVERIFY(hint.codecs().isEmpty());
QCOMPARE(hint.features(), QMediaServiceProviderHint::RecordingSupport);
@@ -240,6 +260,7 @@ void tst_QMediaServiceProvider::testProviderHints()
QVERIFY(!hint.isNull());
QCOMPARE(hint.type(), QMediaServiceProviderHint::ContentType);
QVERIFY(hint.device().isEmpty());
+ QCOMPARE(hint.cameraPosition(), QCamera::UnspecifiedPosition);
QCOMPARE(hint.mimeType(), mimeType);
QCOMPARE(hint.codecs(), codecs);
@@ -248,6 +269,7 @@ void tst_QMediaServiceProvider::testProviderHints()
QVERIFY(!hint2.isNull());
QCOMPARE(hint2.type(), QMediaServiceProviderHint::ContentType);
QVERIFY(hint2.device().isEmpty());
+ QCOMPARE(hint.cameraPosition(), QCamera::UnspecifiedPosition);
QCOMPARE(hint2.mimeType(), mimeType);
QCOMPARE(hint2.codecs(), codecs);
@@ -257,6 +279,7 @@ void tst_QMediaServiceProvider::testProviderHints()
QVERIFY(!hint3.isNull());
QCOMPARE(hint3.type(), QMediaServiceProviderHint::ContentType);
QVERIFY(hint3.device().isEmpty());
+ QCOMPARE(hint.cameraPosition(), QCamera::UnspecifiedPosition);
QCOMPARE(hint3.mimeType(), mimeType);
QCOMPARE(hint3.codecs(), codecs);
@@ -271,6 +294,99 @@ void tst_QMediaServiceProvider::testProviderHints()
}
}
+void tst_QMediaServiceProvider::testDefaultDevice()
+{
+ QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider();
+
+ if (provider == 0)
+ QSKIP("No default provider");
+
+ QCOMPARE(provider->defaultDevice(Q_MEDIASERVICE_AUDIOSOURCE), QByteArray("audiosource1"));
+ QCOMPARE(provider->defaultDevice(Q_MEDIASERVICE_CAMERA), QByteArray("frontcamera"));
+}
+
+void tst_QMediaServiceProvider::testAvailableDevices()
+{
+ QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider();
+
+ if (provider == 0)
+ QSKIP("No default provider");
+
+ QList<QByteArray> devices = provider->devices(Q_MEDIASERVICE_AUDIOSOURCE);
+ QCOMPARE(devices.count(), 2);
+ QCOMPARE(devices.at(0), QByteArray("audiosource1"));
+ QCOMPARE(devices.at(1), QByteArray("audiosource2"));
+
+ devices = provider->devices(Q_MEDIASERVICE_CAMERA);
+ QCOMPARE(devices.count(), 3);
+ QCOMPARE(devices.at(0), QByteArray("frontcamera"));
+ QCOMPARE(devices.at(1), QByteArray("backcamera"));
+ QCOMPARE(devices.at(2), QByteArray("somecamera"));
+}
+
+void tst_QMediaServiceProvider::testCameraInfo()
+{
+ QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider();
+
+ if (provider == 0)
+ QSKIP("No default provider");
+
+ QCOMPARE(provider->cameraPosition("backcamera"), QCamera::BackFace);
+ QCOMPARE(provider->cameraOrientation("backcamera"), 90);
+ QCOMPARE(provider->cameraPosition("frontcamera"), QCamera::FrontFace);
+ QCOMPARE(provider->cameraOrientation("frontcamera"), 270);
+ QCOMPARE(provider->cameraPosition("somecamera"), QCamera::UnspecifiedPosition);
+ QCOMPARE(provider->cameraOrientation("somecamera"), 0);
+
+ {
+ QCamera camera;
+ QVERIFY(camera.service());
+ QCOMPARE(camera.service()->objectName(), QLatin1String("MockServicePlugin3"));
+ }
+
+ {
+ QCamera camera(QCameraInfo::defaultCamera());
+ QVERIFY(camera.service());
+ QCOMPARE(camera.service()->objectName(), QLatin1String("MockServicePlugin3"));
+ }
+
+ {
+ QCamera camera(QCameraInfo::availableCameras().at(0));
+ QVERIFY(camera.service());
+ QCOMPARE(camera.service()->objectName(), QLatin1String("MockServicePlugin3"));
+ }
+
+ {
+ QCamera camera(QCameraInfo::availableCameras().at(1));
+ QVERIFY(camera.service());
+ QCOMPARE(camera.service()->objectName(), QLatin1String("MockServicePlugin5"));
+ }
+
+ {
+ QCamera camera(QCameraInfo::availableCameras().at(2));
+ QVERIFY(camera.service());
+ QCOMPARE(camera.service()->objectName(), QLatin1String("MockServicePlugin5"));
+ }
+
+ {
+ QCamera camera(QCamera::FrontFace);
+ QVERIFY(camera.service());
+ QCOMPARE(camera.service()->objectName(), QLatin1String("MockServicePlugin3"));
+ }
+
+ {
+ QCamera camera(QCamera::BackFace);
+ QVERIFY(camera.service());
+ QCOMPARE(camera.service()->objectName(), QLatin1String("MockServicePlugin5"));
+ }
+
+ {
+ QCamera camera(QCamera::UnspecifiedPosition);
+ QVERIFY(camera.service());
+ QCOMPARE(camera.service()->objectName(), QLatin1String("MockServicePlugin3"));
+ }
+}
+
QTEST_MAIN(tst_QMediaServiceProvider)
#include "tst_qmediaserviceprovider.moc"