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>
This commit is contained in:
Yoann Lopes
2014-01-22 16:18:42 +01:00
committed by The Qt Project
parent d964388b38
commit b28ee24628
54 changed files with 2218 additions and 154 deletions

View File

@@ -0,0 +1,217 @@
/****************************************************************************
**
** 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 <QtTest/QtTest>
#include <QDebug>
#include <qcamera.h>
#include <qcamerainfo.h>
#include "mockcameraservice.h"
#include "mockmediaserviceprovider.h"
QT_USE_NAMESPACE
class tst_QCameraInfo: public QObject
{
Q_OBJECT
public slots:
void initTestCase();
void init();
void cleanup();
private slots:
void constructor();
void defaultCamera();
void availableCameras();
void equality_operators();
private:
MockSimpleCameraService *mockSimpleCameraService;
MockCameraService *mockCameraService;
MockMediaServiceProvider *provider;
};
void tst_QCameraInfo::initTestCase()
{
}
void tst_QCameraInfo::init()
{
provider = new MockMediaServiceProvider;
mockSimpleCameraService = new MockSimpleCameraService;
mockCameraService = new MockCameraService;
provider->service = mockCameraService;
QMediaServiceProvider::setDefaultServiceProvider(provider);
}
void tst_QCameraInfo::cleanup()
{
delete provider;
delete mockCameraService;
delete mockSimpleCameraService;
}
void tst_QCameraInfo::constructor()
{
// Service doesn't implement QVideoDeviceSelectorControl
// QCameraInfo should not be valid in this case
provider->service = mockSimpleCameraService;
{
QCamera camera;
QCameraInfo info(camera);
QVERIFY(info.isNull());
QVERIFY(info.deviceName().isEmpty());
QVERIFY(info.description().isEmpty());
QCOMPARE(info.position(), QCamera::UnspecifiedPosition);
QCOMPARE(info.orientation(), 0);
}
// Service implements QVideoDeviceSelectorControl
provider->service = mockCameraService;
{
// default camera
QCamera camera;
QCameraInfo info(camera);
QVERIFY(!info.isNull());
QCOMPARE(info.deviceName(), QStringLiteral("othercamera"));
QCOMPARE(info.description(), QStringLiteral("othercamera desc"));
QCOMPARE(info.position(), QCamera::UnspecifiedPosition);
QCOMPARE(info.orientation(), 0);
}
QCamera camera("backcamera");
QCameraInfo info(camera);
QVERIFY(!info.isNull());
QCOMPARE(info.deviceName(), QStringLiteral("backcamera"));
QCOMPARE(info.description(), QStringLiteral("backcamera desc"));
QCOMPARE(info.position(), QCamera::BackFace);
QCOMPARE(info.orientation(), 90);
QCameraInfo info2(info);
QVERIFY(!info2.isNull());
QCOMPARE(info2.deviceName(), QStringLiteral("backcamera"));
QCOMPARE(info2.description(), QStringLiteral("backcamera desc"));
QCOMPARE(info2.position(), QCamera::BackFace);
QCOMPARE(info2.orientation(), 90);
}
void tst_QCameraInfo::defaultCamera()
{
provider->service = mockCameraService;
QCameraInfo info = QCameraInfo::defaultCamera();
QVERIFY(!info.isNull());
QCOMPARE(info.deviceName(), QStringLiteral("othercamera"));
QCOMPARE(info.description(), QStringLiteral("othercamera desc"));
QCOMPARE(info.position(), QCamera::UnspecifiedPosition);
QCOMPARE(info.orientation(), 0);
QCamera camera(info);
QCOMPARE(QCameraInfo(camera), info);
}
void tst_QCameraInfo::availableCameras()
{
provider->service = mockCameraService;
QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
QCOMPARE(cameras.count(), 2);
QCameraInfo info = cameras.at(0);
QVERIFY(!info.isNull());
QCOMPARE(info.deviceName(), QStringLiteral("backcamera"));
QCOMPARE(info.description(), QStringLiteral("backcamera desc"));
QCOMPARE(info.position(), QCamera::BackFace);
QCOMPARE(info.orientation(), 90);
info = cameras.at(1);
QVERIFY(!info.isNull());
QCOMPARE(info.deviceName(), QStringLiteral("othercamera"));
QCOMPARE(info.description(), QStringLiteral("othercamera desc"));
QCOMPARE(info.position(), QCamera::UnspecifiedPosition);
QCOMPARE(info.orientation(), 0);
cameras = QCameraInfo::availableCameras(QCamera::BackFace);
QCOMPARE(cameras.count(), 1);
info = cameras.at(0);
QVERIFY(!info.isNull());
QCOMPARE(info.deviceName(), QStringLiteral("backcamera"));
QCOMPARE(info.description(), QStringLiteral("backcamera desc"));
QCOMPARE(info.position(), QCamera::BackFace);
QCOMPARE(info.orientation(), 90);
cameras = QCameraInfo::availableCameras(QCamera::FrontFace);
QCOMPARE(cameras.count(), 0);
}
void tst_QCameraInfo::equality_operators()
{
provider->service = mockCameraService;
QCameraInfo defaultCamera = QCameraInfo::defaultCamera();
QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
QVERIFY(defaultCamera == cameras.at(1));
QVERIFY(defaultCamera != cameras.at(0));
QVERIFY(cameras.at(0) != cameras.at(1));
{
QCamera camera(defaultCamera);
QVERIFY(QCameraInfo(camera) == defaultCamera);
QVERIFY(QCameraInfo(camera) == cameras.at(1));
}
{
QCamera camera(cameras.at(0));
QVERIFY(QCameraInfo(camera) == cameras.at(0));
}
}
QTEST_MAIN(tst_QCameraInfo)
#include "tst_qcamerainfo.moc"