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

@@ -1,16 +1,21 @@
INCLUDEPATH += camera
PRIVATE_HEADERS += \
camera/qcamera_p.h
PUBLIC_HEADERS += \
camera/qcamera.h \
camera/qcameraimagecapture.h \
camera/qcameraexposure.h \
camera/qcamerafocus.h \
camera/qcameraimageprocessing.h
camera/qcameraimageprocessing.h \
camera/qcamerainfo.h
SOURCES += \
camera/qcamera.cpp \
camera/qcameraexposure.cpp \
camera/qcamerafocus.cpp \
camera/qcameraimageprocessing.cpp \
camera/qcameraimagecapture.cpp
camera/qcameraimagecapture.cpp \
camera/qcamerainfo.cpp

View File

@@ -39,11 +39,11 @@
**
****************************************************************************/
#include "qvideosurfaceoutput_p.h"
#include "qmediaobject_p.h"
#include "qcamera_p.h"
#include "qmediaserviceprovider_p.h"
#include <qcamera.h>
#include <qcamerainfo.h>
#include <qcameracontrol.h>
#include <qcameralockscontrol.h>
#include <qcameraexposurecontrol.h>
@@ -52,6 +52,7 @@
#include <qcameraimageprocessingcontrol.h>
#include <qcameraimagecapturecontrol.h>
#include <qvideodeviceselectorcontrol.h>
#include <qcamerainfocontrol.h>
#include <QDebug>
@@ -69,6 +70,7 @@ public:
qRegisterMetaType<QCamera::LockType>("QCamera::LockType");
qRegisterMetaType<QCamera::LockStatus>("QCamera::LockStatus");
qRegisterMetaType<QCamera::LockChangeReason>("QCamera::LockChangeReason");
qRegisterMetaType<QCamera::Position>("QCamera::Position");
}
} _registerCameraMetaTypes;
}
@@ -85,82 +87,16 @@ QT_BEGIN_NAMESPACE
\ingroup multimedia
\ingroup multimedia_camera
QCamera can be used with QVideoWidget for viewfinder display,
QCamera can be used with QCameraViewfinder for viewfinder display,
QMediaRecorder for video recording and QCameraImageCapture for image taking.
You can use QCameraInfo to list available cameras and choose which one to use.
\snippet multimedia-snippets/camera.cpp Camera selection
See the \l{Camera Overview}{camera overview} for more information.
\snippet multimedia-snippets/media.cpp Request control
*/
class QCameraPrivate : public QMediaObjectPrivate
{
Q_DECLARE_NON_CONST_PUBLIC(QCamera)
public:
QCameraPrivate():
QMediaObjectPrivate(),
provider(0),
control(0),
deviceControl(0),
viewfinder(0),
capture(0),
state(QCamera::UnloadedState),
error(QCamera::NoError),
supportedLocks(QCamera::NoLock),
requestedLocks(QCamera::NoLock),
lockStatus(QCamera::Unlocked),
lockChangeReason(QCamera::UserRequest),
supressLockChangedSignal(false),
restartPending(false)
{
}
void initControls();
QMediaServiceProvider *provider;
QCameraControl *control;
QVideoDeviceSelectorControl *deviceControl;
QCameraLocksControl *locksControl;
QCameraExposure *cameraExposure;
QCameraFocus *cameraFocus;
QCameraImageProcessing *imageProcessing;
QObject *viewfinder;
QObject *capture;
QCamera::State state;
QCamera::Error error;
QString errorString;
QCamera::LockTypes supportedLocks;
QCamera::LockTypes requestedLocks;
QCamera::LockStatus lockStatus;
QCamera::LockChangeReason lockChangeReason;
bool supressLockChangedSignal;
bool restartPending;
QVideoSurfaceOutput surfaceViewfinder;
void _q_error(int error, const QString &errorString);
void unsetError() { error = QCamera::NoError; errorString.clear(); }
void setState(QCamera::State);
void _q_updateLockStatus(QCamera::LockType, QCamera::LockStatus, QCamera::LockChangeReason);
void _q_updateState(QCamera::State newState);
void _q_preparePropertyChange(int changeType);
void _q_restartCamera();
void updateLockStatus();
};
void QCameraPrivate::_q_error(int error, const QString &errorString)
{
Q_Q(QCamera);
@@ -168,8 +104,6 @@ void QCameraPrivate::_q_error(int error, const QString &errorString)
this->error = QCamera::Error(error);
this->errorString = errorString;
qWarning() << "Camera error:" << errorString;
emit q->error(this->error);
}
@@ -228,6 +162,16 @@ void QCameraPrivate::_q_restartCamera()
}
}
void QCameraPrivate::init()
{
Q_Q(QCamera);
provider = QMediaServiceProvider::defaultServiceProvider();
initControls();
cameraExposure = new QCameraExposure(q);
cameraFocus = new QCameraFocus(q);
imageProcessing = new QCameraImageProcessing(q);
}
void QCameraPrivate::initControls()
{
Q_Q(QCamera);
@@ -238,6 +182,7 @@ void QCameraPrivate::initControls()
control = qobject_cast<QCameraControl *>(service->requestControl(QCameraControl_iid));
locksControl = qobject_cast<QCameraLocksControl *>(service->requestControl(QCameraLocksControl_iid));
deviceControl = qobject_cast<QVideoDeviceSelectorControl*>(service->requestControl(QVideoDeviceSelectorControl_iid));
infoControl = qobject_cast<QCameraInfoControl*>(service->requestControl(QCameraInfoControl_iid));
if (control) {
q->connect(control, SIGNAL(stateChanged(QCamera::State)), q, SLOT(_q_updateState(QCamera::State)));
@@ -259,12 +204,43 @@ void QCameraPrivate::initControls()
control = 0;
locksControl = 0;
deviceControl = 0;
infoControl = 0;
error = QCamera::ServiceMissingError;
errorString = QCamera::tr("The camera service is missing");
}
}
void QCameraPrivate::clear()
{
delete cameraExposure;
delete cameraFocus;
delete imageProcessing;
if (service) {
if (control)
service->releaseControl(control);
if (locksControl)
service->releaseControl(locksControl);
if (deviceControl)
service->releaseControl(deviceControl);
if (infoControl)
service->releaseControl(infoControl);
provider->releaseService(service);
}
cameraExposure = 0;
cameraFocus = 0;
imageProcessing = 0;
control = 0;
locksControl = 0;
deviceControl = 0;
infoControl = 0;
service = 0;
supportedLocks = 0;
}
void QCameraPrivate::updateLockStatus()
{
Q_Q(QCamera);
@@ -337,42 +313,103 @@ QCamera::QCamera(QObject *parent):
QMediaServiceProvider::defaultServiceProvider()->requestService(Q_MEDIASERVICE_CAMERA))
{
Q_D(QCamera);
d->provider = QMediaServiceProvider::defaultServiceProvider();
d->initControls();
d->cameraExposure = new QCameraExposure(this);
d->cameraFocus = new QCameraFocus(this);
d->imageProcessing = new QCameraImageProcessing(this);
d->init();
// Select the default camera
if (d->service != 0 && d->deviceControl)
d->deviceControl->setSelectedDevice(d->deviceControl->defaultDevice());
}
/*!
Construct a QCamera from device name \a device and \a parent.
Construct a QCamera from \a deviceName and \a parent.
If no camera with that \a deviceName exists, the camera object will
be invalid.
*/
QCamera::QCamera(const QByteArray& device, QObject *parent):
QCamera::QCamera(const QByteArray& deviceName, QObject *parent):
QMediaObject(*new QCameraPrivate, parent,
QMediaServiceProvider::defaultServiceProvider()->requestService(Q_MEDIASERVICE_CAMERA, QMediaServiceProviderHint(device)))
QMediaServiceProvider::defaultServiceProvider()->requestService(Q_MEDIASERVICE_CAMERA,
QMediaServiceProviderHint(deviceName)))
{
Q_D(QCamera);
d->provider = QMediaServiceProvider::defaultServiceProvider();
d->initControls();
d->init();
if (d->service != 0) {
//pass device name to service
if (d->deviceControl) {
QString deviceName = QString::fromLatin1(device);
for (int i=0; i<d->deviceControl->deviceCount(); i++) {
if (d->deviceControl->deviceName(i) == deviceName) {
const QString name = QString::fromLatin1(deviceName);
for (int i = 0; i < d->deviceControl->deviceCount(); i++) {
if (d->deviceControl->deviceName(i) == name) {
d->deviceControl->setSelectedDevice(i);
break;
}
}
}
}
}
d->cameraExposure = new QCameraExposure(this);
d->cameraFocus = new QCameraFocus(this);
d->imageProcessing = new QCameraImageProcessing(this);
/*!
\since 5.3
Construct a QCamera from a camera description \a cameraInfo and \a parent.
*/
QCamera::QCamera(const QCameraInfo &cameraInfo, QObject *parent)
: QMediaObject(*new QCameraPrivate,
parent,
QMediaServiceProvider::defaultServiceProvider()->requestService(Q_MEDIASERVICE_CAMERA,
QMediaServiceProviderHint(cameraInfo.deviceName().toLatin1())))
{
Q_D(QCamera);
d->init();
if (d->service != 0 && d->deviceControl) {
for (int i = 0; i < d->deviceControl->deviceCount(); i++) {
if (d->deviceControl->deviceName(i) == cameraInfo.deviceName()) {
d->deviceControl->setSelectedDevice(i);
break;
}
}
}
}
/*!
\since 5.3
Construct a QCamera which uses a hardware camera located a the specified \a position.
For example on a mobile phone it can be used to easily choose between front-facing and
back-facing cameras.
If no camera is available at the specified \a position or if \a position is
QCamera::UnspecifiedPosition, the default camera is used.
*/
QCamera::QCamera(QCamera::Position position, QObject *parent)
: QMediaObject(*new QCameraPrivate,
parent,
QMediaServiceProvider::defaultServiceProvider()->requestService(Q_MEDIASERVICE_CAMERA, QMediaServiceProviderHint(position)))
{
Q_D(QCamera);
d->init();
if (d->service != 0 && d->deviceControl) {
bool selectDefault = true;
if (d->infoControl && position != UnspecifiedPosition) {
for (int i = 0; i < d->deviceControl->deviceCount(); i++) {
if (d->infoControl->cameraPosition(d->deviceControl->deviceName(i)) == position) {
d->deviceControl->setSelectedDevice(i);
selectDefault = false;
break;
}
}
}
if (selectDefault)
d->deviceControl->setSelectedDevice(d->deviceControl->defaultDevice());
}
}
/*!
@@ -382,23 +419,7 @@ QCamera::QCamera(const QByteArray& device, QObject *parent):
QCamera::~QCamera()
{
Q_D(QCamera);
delete d->cameraExposure;
d->cameraExposure = 0;
delete d->cameraFocus;
d->cameraFocus = 0;
delete d->imageProcessing;
d->imageProcessing = 0;
if (d->service) {
if (d->control)
d->service->releaseControl(d->control);
if (d->locksControl)
d->service->releaseControl(d->locksControl);
if (d->deviceControl)
d->service->releaseControl(d->deviceControl);
d->provider->releaseService(d->service);
}
d->clear();
}
/*!
@@ -622,9 +643,11 @@ void QCamera::unload()
d->setState(QCamera::UnloadedState);
}
#if QT_DEPRECATED_SINCE(5, 3)
/*!
Returns a list of camera device's available from the default service provider.
\deprecated
\sa QCameraInfo::availableCameras()
*/
QList<QByteArray> QCamera::availableDevices()
@@ -634,12 +657,15 @@ QList<QByteArray> QCamera::availableDevices()
/*!
Returns the description of the \a device.
\deprecated
\sa QCameraInfo::availableCameras(), QCameraInfo::description()
*/
QString QCamera::deviceDescription(const QByteArray &device)
{
return QMediaServiceProvider::defaultServiceProvider()->deviceDescription(QByteArray(Q_MEDIASERVICE_CAMERA), device);
}
#endif
QCamera::State QCamera::state() const
{
@@ -972,6 +998,25 @@ void QCamera::unlock()
Signal emitted when error state changes to \a value.
*/
/*!
\enum QCamera::Position
\since 5.3
This enum specifies the physical position of the camera on the system hardware.
\value UnspecifiedPosition The camera position is unspecified or unknown.
\value BackFace The camera is on the back face of the system hardware. For example on a
mobile device, it means it is on the opposite side to that of the screen.
\value FrontFace The camera is on the front face of the system hardware. For example on a
mobile device, it means it is on the same side as that of the screen. Viewfinder frames of
front-facing cameras are mirrored horizontally, so the users can see themselves as looking
into a mirror. Captured images or videos are not mirrored.
\sa QCameraInfo::position()
*/
/*!
\fn void QCamera::captureModeChanged(QCamera::CaptureModes mode)

View File

@@ -64,6 +64,7 @@ QT_BEGIN_NAMESPACE
class QAbstractVideoSurface;
class QVideoWidget;
class QGraphicsVideoItem;
class QCameraInfo;
class QCameraPrivate;
class Q_MULTIMEDIA_EXPORT QCamera : public QMediaObject
@@ -81,6 +82,7 @@ class Q_MULTIMEDIA_EXPORT QCamera : public QMediaObject
Q_ENUMS(LockStatus)
Q_ENUMS(LockChangeReason)
Q_ENUMS(LockType)
Q_ENUMS(Position)
public:
enum Status {
UnavailableStatus,
@@ -141,12 +143,23 @@ public:
};
Q_DECLARE_FLAGS(LockTypes, LockType)
enum Position
{
UnspecifiedPosition,
BackFace,
FrontFace
};
QCamera(QObject *parent = 0);
QCamera(const QByteArray& device, QObject *parent = 0);
QCamera(const QByteArray& deviceName, QObject *parent = 0);
QCamera(const QCameraInfo& cameraInfo, QObject *parent = 0);
QCamera(QCamera::Position position, QObject *parent = 0);
~QCamera();
static QList<QByteArray> availableDevices();
static QString deviceDescription(const QByteArray &device);
#if QT_DEPRECATED_SINCE(5, 3)
QT_DEPRECATED static QList<QByteArray> availableDevices();
QT_DEPRECATED static QString deviceDescription(const QByteArray &device);
#endif
QMultimedia::AvailabilityStatus availability() const;
@@ -209,6 +222,7 @@ private:
Q_PRIVATE_SLOT(d_func(), void _q_error(int, const QString &))
Q_PRIVATE_SLOT(d_func(), void _q_updateLockStatus(QCamera::LockType, QCamera::LockStatus, QCamera::LockChangeReason))
Q_PRIVATE_SLOT(d_func(), void _q_updateState(QCamera::State))
friend class QCameraInfo;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QCamera::LockTypes)
@@ -223,6 +237,7 @@ Q_DECLARE_METATYPE(QCamera::CaptureModes)
Q_DECLARE_METATYPE(QCamera::LockType)
Q_DECLARE_METATYPE(QCamera::LockStatus)
Q_DECLARE_METATYPE(QCamera::LockChangeReason)
Q_DECLARE_METATYPE(QCamera::Position)
Q_MEDIA_ENUM_DEBUG(QCamera, State)
Q_MEDIA_ENUM_DEBUG(QCamera, Status)
@@ -231,5 +246,6 @@ Q_MEDIA_ENUM_DEBUG(QCamera, CaptureMode)
Q_MEDIA_ENUM_DEBUG(QCamera, LockType)
Q_MEDIA_ENUM_DEBUG(QCamera, LockStatus)
Q_MEDIA_ENUM_DEBUG(QCamera, LockChangeReason)
Q_MEDIA_ENUM_DEBUG(QCamera, Position)
#endif // QCAMERA_H

View File

@@ -0,0 +1,141 @@
/****************************************************************************
**
** 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$
**
****************************************************************************/
#ifndef QCAMERA_P_H
#define QCAMERA_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include "qmediaobject_p.h"
#include "qvideosurfaceoutput_p.h"
#include "qcamera.h"
QT_BEGIN_NAMESPACE
class QMediaServiceProvider;
class QCameraControl;
class QVideoDeviceSelectorControl;
class QCameraLocksControl;
class QCameraInfoControl;
class QCameraPrivate : public QMediaObjectPrivate
{
Q_DECLARE_NON_CONST_PUBLIC(QCamera)
public:
QCameraPrivate():
QMediaObjectPrivate(),
provider(0),
control(0),
deviceControl(0),
locksControl(0),
infoControl(0),
viewfinder(0),
capture(0),
state(QCamera::UnloadedState),
error(QCamera::NoError),
supportedLocks(QCamera::NoLock),
requestedLocks(QCamera::NoLock),
lockStatus(QCamera::Unlocked),
lockChangeReason(QCamera::UserRequest),
supressLockChangedSignal(false),
restartPending(false)
{
}
void init();
void initControls();
void clear();
QMediaServiceProvider *provider;
QCameraControl *control;
QVideoDeviceSelectorControl *deviceControl;
QCameraLocksControl *locksControl;
QCameraInfoControl *infoControl;
QCameraExposure *cameraExposure;
QCameraFocus *cameraFocus;
QCameraImageProcessing *imageProcessing;
QObject *viewfinder;
QObject *capture;
QCamera::State state;
QCamera::Error error;
QString errorString;
QCamera::LockTypes supportedLocks;
QCamera::LockTypes requestedLocks;
QCamera::LockStatus lockStatus;
QCamera::LockChangeReason lockChangeReason;
bool supressLockChangedSignal;
bool restartPending;
QVideoSurfaceOutput surfaceViewfinder;
void _q_error(int error, const QString &errorString);
void unsetError() { error = QCamera::NoError; errorString.clear(); }
void setState(QCamera::State);
void _q_updateLockStatus(QCamera::LockType, QCamera::LockStatus, QCamera::LockChangeReason);
void _q_updateState(QCamera::State newState);
void _q_preparePropertyChange(int changeType);
void _q_restartCamera();
void updateLockStatus();
};
QT_END_NAMESPACE
#endif // QCAMERA_P_H

View File

@@ -159,6 +159,7 @@ Q_SIGNALS:
private:
friend class QCamera;
friend class QCameraPrivate;
explicit QCameraExposure(QCamera *parent = 0);
virtual ~QCameraExposure();

View File

@@ -156,6 +156,7 @@ Q_SIGNALS:
private:
friend class QCamera;
friend class QCameraPrivate;
QCameraFocus(QCamera *camera);
~QCameraFocus();

View File

@@ -100,6 +100,7 @@ public:
private:
friend class QCamera;
friend class QCameraPrivate;
QCameraImageProcessing(QCamera *camera);
~QCameraImageProcessing();

View File

@@ -0,0 +1,289 @@
/****************************************************************************
**
** 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 "qcamerainfo.h"
#include "qcamera_p.h"
#include "qmediaserviceprovider_p.h"
#include <qvideodeviceselectorcontrol.h>
#include <qcamerainfocontrol.h>
QT_BEGIN_NAMESPACE
/*!
\class QCameraInfo
\brief The QCameraInfo class provides general information about camera devices.
\since 5.3
\inmodule QtMultimedia
\ingroup multimedia
\ingroup multimedia_camera
QCameraInfo lets you query for camera devices that are currently available on the system.
The static functions defaultCamera() and availableCameras() provide you a list of all
available cameras.
This example prints the name of all available cameras:
\snippet multimedia-snippets/camera.cpp Camera listing
A QCameraInfo can be used to construct a QCamera. The following example instantiates a QCamera
whose camera device is named 'mycamera':
\snippet multimedia-snippets/camera.cpp Camera selection
You can also use QCameraInfo to get general information about a camera device such as
description, physical position on the system, or camera sensor orientation.
\snippet multimedia-snippets/camera.cpp Camera info
\sa QCamera
*/
class QCameraInfoPrivate
{
public:
QCameraInfoPrivate() : isNull(true), position(QCamera::UnspecifiedPosition), orientation(0)
{ }
bool isNull;
QString deviceName;
QString description;
QCamera::Position position;
int orientation;
};
/*!
Constructs a camera info object for \a camera.
You can use it to query information about the \a camera object passed as argument.
If the \a camera is invalid, for example when no camera device is available on the system,
the QCameraInfo object will be invalid and isNull() will return true.
*/
QCameraInfo::QCameraInfo(const QCamera &camera)
: d(new QCameraInfoPrivate)
{
const QVideoDeviceSelectorControl *deviceControl = camera.d_func()->deviceControl;
if (deviceControl) {
const int selectedDevice = deviceControl->selectedDevice();
d->deviceName = deviceControl->deviceName(selectedDevice);
d->description = deviceControl->deviceDescription(selectedDevice);
d->isNull = false;
}
const QCameraInfoControl *infoControl = camera.d_func()->infoControl;
if (infoControl) {
d->position = infoControl->cameraPosition(d->deviceName);
d->orientation = infoControl->cameraOrientation(d->deviceName);
d->isNull = false;
}
}
/*!
Constructs a camera info object from a camera device \a name.
If no such device exists, the QCameraInfo object will be invalid and isNull() will return true.
*/
QCameraInfo::QCameraInfo(const QByteArray &name)
: d(new QCameraInfoPrivate)
{
if (!name.isNull()) {
QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider();
const QByteArray service(Q_MEDIASERVICE_CAMERA);
if (provider->devices(service).contains(name)) {
d->deviceName = QString::fromLatin1(name);
d->description = provider->deviceDescription(service, name);
d->position = provider->cameraPosition(name);
d->orientation = provider->cameraOrientation(name);
d->isNull = false;
}
}
}
/*!
Constructs a copy of \a other.
*/
QCameraInfo::QCameraInfo(const QCameraInfo &other)
: d(other.d)
{
}
/*!
Destroys the QCameraInfo.
*/
QCameraInfo::~QCameraInfo()
{
}
/*!
Returns true if this QCameraInfo is equal to \a other.
*/
bool QCameraInfo::operator==(const QCameraInfo &other) const
{
if (d == other.d)
return true;
return (d->deviceName == other.d->deviceName
&& d->description == other.d->description
&& d->position == other.d->position
&& d->orientation == other.d->orientation);
}
/*!
Returns true if this QCameraInfo is null or invalid.
*/
bool QCameraInfo::isNull() const
{
return d->isNull;
}
/*!
Returns the device name of the camera
This is a unique ID to identify the camera and may not be human-readable.
*/
QString QCameraInfo::deviceName() const
{
return d->deviceName;
}
/*!
Returns the human-readable description of the camera.
*/
QString QCameraInfo::description() const
{
return d->description;
}
/*!
Returns the physical position of the camera on the hardware system.
*/
QCamera::Position QCameraInfo::position() const
{
return d->position;
}
/*!
Returns the physical orientation of the camera sensor.
The value is the orientation angle (clockwise, in steps of 90 degrees) of the camera sensor
in relation to the display in its natural orientation.
You can show the camera image in the correct orientation by rotating it by this value in the
anti-clockwise direction.
For example, suppose a mobile device which is naturally in portrait orientation. The back-facing
camera is mounted in landscape. If the top side of the camera sensor is aligned with the
right edge of the screen in natural orientation, the value should be 270. If the top side of a
front-facing camera sensor is aligned with the right of the screen, the value should be 90.
*/
int QCameraInfo::orientation() const
{
return d->orientation;
}
/*!
Returns the default camera on the system.
The returned object should be checked using isNull() before being used, in case there is no
default camera or no cameras at all.
\sa availableCameras()
*/
QCameraInfo QCameraInfo::defaultCamera()
{
return QCameraInfo(QMediaServiceProvider::defaultServiceProvider()->defaultDevice(Q_MEDIASERVICE_CAMERA));
}
/*!
Returns a list of available cameras on the system which are located at \a position.
If \a position is not specified or if the value is QCamera::UnspecifiedPosition, a list of
all available cameras will be returned.
*/
QList<QCameraInfo> QCameraInfo::availableCameras(QCamera::Position position)
{
QList<QCameraInfo> cameras;
const QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider();
const QByteArray service(Q_MEDIASERVICE_CAMERA);
const QList<QByteArray> devices = provider->devices(service);
for (int i = 0; i < devices.count(); ++i) {
const QByteArray &name = devices.at(i);
if (position == QCamera::UnspecifiedPosition
|| position == provider->cameraPosition(name)) {
cameras.append(QCameraInfo(name));
}
}
return cameras;
}
/*!
Sets the QCameraInfo object to be equal to \a other.
*/
QCameraInfo& QCameraInfo::operator=(const QCameraInfo& other)
{
d = other.d;
return *this;
}
/*!
\fn QCameraInfo::operator!=(const QCameraInfo &other) const
Returns true if this QCameraInfo is different from \a other.
*/
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug d, const QCameraInfo &camera)
{
d.maybeSpace() << QStringLiteral("QCameraInfo(deviceName=%1, position=%2, orientation=%3)")
.arg(camera.deviceName())
.arg(QString::fromLatin1(QCamera::staticMetaObject.enumerator(QCamera::staticMetaObject.indexOfEnumerator("Position"))
.valueToKey(camera.position())))
.arg(camera.orientation());
return d.space();
}
#endif
QT_END_NAMESPACE

View File

@@ -0,0 +1,86 @@
/****************************************************************************
**
** 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$
**
****************************************************************************/
#ifndef QCAMERAINFO_H
#define QCAMERAINFO_H
#include <QtMultimedia/qcamera.h>
#include <QtCore/qsharedpointer.h>
QT_BEGIN_NAMESPACE
class QCameraInfoPrivate;
class Q_MULTIMEDIA_EXPORT QCameraInfo
{
public:
explicit QCameraInfo(const QByteArray &name = QByteArray());
explicit QCameraInfo(const QCamera &camera);
QCameraInfo(const QCameraInfo& other);
~QCameraInfo();
QCameraInfo& operator=(const QCameraInfo& other);
bool operator==(const QCameraInfo &other) const;
inline bool operator!=(const QCameraInfo &other) const;
bool isNull() const;
QString deviceName() const;
QString description() const;
QCamera::Position position() const;
int orientation() const;
static QCameraInfo defaultCamera();
static QList<QCameraInfo> availableCameras(QCamera::Position position = QCamera::UnspecifiedPosition);
private:
QSharedPointer<QCameraInfoPrivate> d;
};
bool QCameraInfo::operator!=(const QCameraInfo &other) const { return !operator==(other); }
#ifndef QT_NO_DEBUG_STREAM
Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QCameraInfo&);
#endif
QT_END_NAMESPACE
#endif // QCAMERAINFO_H