summaryrefslogtreecommitdiffstats
path: root/src
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 /src
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 'src')
-rw-r--r--src/multimedia/camera/camera.pri9
-rw-r--r--src/multimedia/camera/qcamera.cpp265
-rw-r--r--src/multimedia/camera/qcamera.h22
-rw-r--r--src/multimedia/camera/qcamera_p.h141
-rw-r--r--src/multimedia/camera/qcameraexposure.h1
-rw-r--r--src/multimedia/camera/qcamerafocus.h1
-rw-r--r--src/multimedia/camera/qcameraimageprocessing.h1
-rw-r--r--src/multimedia/camera/qcamerainfo.cpp289
-rw-r--r--src/multimedia/camera/qcamerainfo.h86
-rw-r--r--src/multimedia/controls/controls.pri3
-rw-r--r--src/multimedia/controls/qcamerainfocontrol.cpp104
-rw-r--r--src/multimedia/controls/qcamerainfocontrol.h71
-rw-r--r--src/multimedia/doc/snippets/multimedia-snippets/camera.cpp65
-rw-r--r--src/multimedia/doc/src/cameraoverview.qdoc11
-rw-r--r--src/multimedia/qmediaserviceprovider.cpp180
-rw-r--r--src/multimedia/qmediaserviceprovider_p.h4
-rw-r--r--src/multimedia/qmediaserviceproviderplugin.h30
-rw-r--r--src/plugins/android/src/mediacapture/qandroidvideodeviceselectorcontrol.cpp13
-rw-r--r--src/plugins/android/src/mediacapture/qandroidvideodeviceselectorcontrol.h2
-rw-r--r--src/plugins/android/src/qandroidmediaserviceplugin.cpp8
-rw-r--r--src/plugins/android/src/qandroidmediaserviceplugin.h3
-rw-r--r--src/plugins/avfoundation/camera/avfcameraserviceplugin.h6
-rw-r--r--src/plugins/avfoundation/camera/avfcameraserviceplugin.mm17
-rw-r--r--src/plugins/avfoundation/camera/avfvideodevicecontrol.h1
-rw-r--r--src/plugins/avfoundation/camera/avfvideodevicecontrol.mm8
-rw-r--r--src/plugins/directshow/camera/dsvideodevicecontrol.cpp2
-rw-r--r--src/plugins/directshow/dsserviceplugin.cpp17
-rw-r--r--src/plugins/directshow/dsserviceplugin.h4
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinserviceplugin.cpp16
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinserviceplugin.h4
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamercaptureserviceplugin.cpp16
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamercaptureserviceplugin.h4
-rw-r--r--src/plugins/qnx/bbserviceplugin.cpp15
-rw-r--r--src/plugins/qnx/bbserviceplugin.h4
-rw-r--r--src/plugins/wmf/wmfserviceplugin.cpp5
-rw-r--r--src/plugins/wmf/wmfserviceplugin.h3
36 files changed, 1307 insertions, 124 deletions
diff --git a/src/multimedia/camera/camera.pri b/src/multimedia/camera/camera.pri
index be7868cd4..0e0031fd9 100644
--- a/src/multimedia/camera/camera.pri
+++ b/src/multimedia/camera/camera.pri
@@ -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
diff --git a/src/multimedia/camera/qcamera.cpp b/src/multimedia/camera/qcamera.cpp
index e91a0318c..32bab0019 100644
--- a/src/multimedia/camera/qcamera.cpp
+++ b/src/multimedia/camera/qcamera.cpp
@@ -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.
- See the \l{Camera Overview}{camera overview} for more information.
+ You can use QCameraInfo to list available cameras and choose which one to use.
- \snippet multimedia-snippets/media.cpp Request control
+ \snippet multimedia-snippets/camera.cpp Camera selection
+ See the \l{Camera Overview}{camera overview} for more information.
*/
-
-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;
}
}
}
}
+}
+
+/*!
+ \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;
+ }
+ }
+ }
- d->cameraExposure = new QCameraExposure(this);
- d->cameraFocus = new QCameraFocus(this);
- d->imageProcessing = new QCameraImageProcessing(this);
+ 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
{
@@ -973,6 +999,25 @@ void QCamera::unlock()
*/
/*!
+ \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)
Signals the capture \a mode has changed.
diff --git a/src/multimedia/camera/qcamera.h b/src/multimedia/camera/qcamera.h
index 6a29b2c86..9c413c3ac 100644
--- a/src/multimedia/camera/qcamera.h
+++ b/src/multimedia/camera/qcamera.h
@@ -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
diff --git a/src/multimedia/camera/qcamera_p.h b/src/multimedia/camera/qcamera_p.h
new file mode 100644
index 000000000..ac2ab87ff
--- /dev/null
+++ b/src/multimedia/camera/qcamera_p.h
@@ -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
diff --git a/src/multimedia/camera/qcameraexposure.h b/src/multimedia/camera/qcameraexposure.h
index ba8e25cb7..df3b4baf3 100644
--- a/src/multimedia/camera/qcameraexposure.h
+++ b/src/multimedia/camera/qcameraexposure.h
@@ -159,6 +159,7 @@ Q_SIGNALS:
private:
friend class QCamera;
+ friend class QCameraPrivate;
explicit QCameraExposure(QCamera *parent = 0);
virtual ~QCameraExposure();
diff --git a/src/multimedia/camera/qcamerafocus.h b/src/multimedia/camera/qcamerafocus.h
index 675ae2ea3..f4ac6a5a5 100644
--- a/src/multimedia/camera/qcamerafocus.h
+++ b/src/multimedia/camera/qcamerafocus.h
@@ -156,6 +156,7 @@ Q_SIGNALS:
private:
friend class QCamera;
+ friend class QCameraPrivate;
QCameraFocus(QCamera *camera);
~QCameraFocus();
diff --git a/src/multimedia/camera/qcameraimageprocessing.h b/src/multimedia/camera/qcameraimageprocessing.h
index ffb088f3d..d0360d860 100644
--- a/src/multimedia/camera/qcameraimageprocessing.h
+++ b/src/multimedia/camera/qcameraimageprocessing.h
@@ -100,6 +100,7 @@ public:
private:
friend class QCamera;
+ friend class QCameraPrivate;
QCameraImageProcessing(QCamera *camera);
~QCameraImageProcessing();
diff --git a/src/multimedia/camera/qcamerainfo.cpp b/src/multimedia/camera/qcamerainfo.cpp
new file mode 100644
index 000000000..218219c7e
--- /dev/null
+++ b/src/multimedia/camera/qcamerainfo.cpp
@@ -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
diff --git a/src/multimedia/camera/qcamerainfo.h b/src/multimedia/camera/qcamerainfo.h
new file mode 100644
index 000000000..4aea2b7ab
--- /dev/null
+++ b/src/multimedia/camera/qcamerainfo.h
@@ -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
diff --git a/src/multimedia/controls/controls.pri b/src/multimedia/controls/controls.pri
index e756abc63..b19532fdc 100644
--- a/src/multimedia/controls/controls.pri
+++ b/src/multimedia/controls/controls.pri
@@ -9,6 +9,7 @@ PUBLIC_HEADERS += \
controls/qcameracapturebufferformatcontrol.h \
controls/qcameracapturedestinationcontrol.h \
controls/qcameracontrol.h \
+ controls/qcamerainfocontrol.h \
controls/qcameraexposurecontrol.h \
controls/qcamerafeedbackcontrol.h \
controls/qcameraflashcontrol.h \
@@ -45,6 +46,7 @@ SOURCES += \
controls/qcameracapturebufferformatcontrol.cpp \
controls/qcameracapturedestinationcontrol.cpp \
controls/qcameracontrol.cpp \
+ controls/qcamerainfocontrol.cpp \
controls/qcameraexposurecontrol.cpp \
controls/qcamerafeedbackcontrol.cpp \
controls/qcameraflashcontrol.cpp \
@@ -79,4 +81,3 @@ SOURCES += \
controls/qaudiooutputselectorcontrol.cpp \
controls/qvideodeviceselectorcontrol.cpp
-
diff --git a/src/multimedia/controls/qcamerainfocontrol.cpp b/src/multimedia/controls/qcamerainfocontrol.cpp
new file mode 100644
index 000000000..585413aad
--- /dev/null
+++ b/src/multimedia/controls/qcamerainfocontrol.cpp
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** 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 "qcamerainfocontrol.h"
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QCameraInfoControl
+ \since 5.3
+
+ \brief The QCameraInfoControl class provides a camera info media control.
+ \inmodule QtMultimedia
+
+ \ingroup multimedia_control
+
+ The QCameraInfoControl class provides information about the camera devices
+ available on the system.
+
+ The interface name of QCameraInfoControl is \c org.qt-project.qt.camerainfocontrol/5.3 as
+ defined in QCameraInfoControl_iid.
+*/
+
+/*!
+ \macro QCameraInfoControl_iid
+
+ \c org.qt-project.qt.camerainfocontrol/5.3
+
+ Defines the interface name of the QCameraInfoControl class.
+
+ \relates QVideoDeviceSelectorControl
+*/
+
+/*!
+ Constructs a camera info control with the given \a parent.
+*/
+QCameraInfoControl::QCameraInfoControl(QObject *parent)
+ : QMediaControl(parent)
+{
+}
+
+/*!
+ Destroys a camera info control.
+*/
+QCameraInfoControl::~QCameraInfoControl()
+{
+}
+
+/*!
+ \fn QCameraInfoControl::cameraPosition(const QString &deviceName) const
+
+ Returns the physical position of the camera named \a deviceName on the hardware system.
+*/
+
+/*!
+ \fn QCameraInfoControl::cameraOrientation(const QString &deviceName) const
+
+ Returns the physical orientation of the sensor for the camera named \a deviceName.
+
+ 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.
+*/
+
+#include "moc_qcamerainfocontrol.cpp"
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/controls/qcamerainfocontrol.h b/src/multimedia/controls/qcamerainfocontrol.h
new file mode 100644
index 000000000..a5742c0cb
--- /dev/null
+++ b/src/multimedia/controls/qcamerainfocontrol.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** 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 QCAMERAINFOCONTROL_H
+#define QCAMERAINFOCONTROL_H
+
+#include <QtMultimedia/qcamera.h>
+
+QT_BEGIN_NAMESPACE
+
+// Required for QDoc workaround
+class QString;
+
+class Q_MULTIMEDIA_EXPORT QCameraInfoControl : public QMediaControl
+{
+ Q_OBJECT
+
+public:
+ virtual ~QCameraInfoControl();
+
+ virtual QCamera::Position cameraPosition(const QString &deviceName) const = 0;
+ virtual int cameraOrientation(const QString &deviceName) const = 0;
+
+protected:
+ QCameraInfoControl(QObject *parent = 0);
+};
+
+#define QCameraInfoControl_iid "org.qt-project.qt.camerainfocontrol/5.3"
+Q_MEDIA_DECLARE_CONTROL(QCameraInfoControl, QCameraInfoControl_iid)
+
+QT_END_NAMESPACE
+
+#endif // QCAMERAINFOCONTROL_H
diff --git a/src/multimedia/doc/snippets/multimedia-snippets/camera.cpp b/src/multimedia/doc/snippets/multimedia-snippets/camera.cpp
index a512e0b92..65dff2618 100644
--- a/src/multimedia/doc/snippets/multimedia-snippets/camera.cpp
+++ b/src/multimedia/doc/snippets/multimedia-snippets/camera.cpp
@@ -42,11 +42,15 @@
/* Camera snippets */
#include "qcamera.h"
+#include "qcamerainfo.h"
#include "qcameraviewfinder.h"
#include "qmediarecorder.h"
#include "qcameraimagecapture.h"
#include "qcameraimageprocessing.h"
#include "qabstractvideosurface.h"
+#include <QtGui/qscreen.h>
+#include <QtGui/qguiapplication.h>
+#include <QtGui/qimage.h>
/* Globals so that everything is consistent. */
QCamera *camera = 0;
@@ -94,6 +98,32 @@ void overview_surface()
//! [Camera overview surface]
}
+void overview_viewfinder_orientation()
+{
+ QCamera camera;
+
+ //! [Camera overview viewfinder orientation]
+ // Assuming a QImage has been created from the QVideoFrame that needs to be presented
+ QImage videoFrame;
+ QCameraInfo cameraInfo(camera); // needed to get the camera sensor position and orientation
+
+ // Get the current display orientation
+ const QScreen *screen = QGuiApplication::primaryScreen();
+ const int screenAngle = screen->angleBetween(screen->nativeOrientation(), screen->orientation());
+
+ int rotation;
+ if (cameraInfo.position() == QCamera::BackFace) {
+ rotation = (cameraInfo.orientation() - screenAngle) % 360;
+ } else {
+ // Front position, compensate the mirror
+ rotation = (360 - cameraInfo.orientation() + screenAngle) % 360;
+ }
+
+ // Rotate the frame so it always shows in the correct orientation
+ videoFrame = videoFrame.transformed(QTransform().rotate(rotation));
+ //! [Camera overview viewfinder orientation]
+}
+
void overview_still()
{
//! [Camera overview capture]
@@ -130,6 +160,41 @@ void overview_movie()
//! [Camera overview movie]
}
+void camera_listing()
+{
+ //! [Camera listing]
+ QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
+ foreach (const QCameraInfo &cameraInfo, cameras)
+ qDebug() << cameraInfo.deviceName();
+ //! [Camera listing]
+}
+
+void camera_selection()
+{
+ //! [Camera selection]
+ QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
+ foreach (const QCameraInfo &cameraInfo, cameras) {
+ if (cameraInfo.deviceName() == "mycamera")
+ camera = new QCamera(cameraInfo);
+ }
+ //! [Camera selection]
+}
+
+void camera_info()
+{
+ //! [Camera info]
+ QCamera myCamera;
+ QCameraInfo cameraInfo(myCamera);
+
+ if (cameraInfo.position() == QCamera::FrontFace)
+ qDebug() << "The camera is on the front face of the hardware system.";
+ else if (cameraInfo.position() == QCamera::BackFace)
+ qDebug() << "The camera is on the back face of the hardware system.";
+
+ qDebug() << "The camera sensor orientation is " << cameraInfo.orientation() << " degrees.";
+ //! [Camera info]
+}
+
void camera_blah()
{
//! [Camera]
diff --git a/src/multimedia/doc/src/cameraoverview.qdoc b/src/multimedia/doc/src/cameraoverview.qdoc
index 71515ab19..b2b9d46a5 100644
--- a/src/multimedia/doc/src/cameraoverview.qdoc
+++ b/src/multimedia/doc/src/cameraoverview.qdoc
@@ -118,7 +118,7 @@ VideoOutput {
\endqml
In C++, your choice depends on whether you are using widgets, or QGraphicsView.
-The \l QVideoWidget class is used in the widgets case, and \l QGraphicsVideoItem
+The \l QCameraViewfinder class is used in the widgets case, and \l QGraphicsVideoItem
is useful for QGraphicsView.
\snippet multimedia-snippets/camera.cpp Camera overview viewfinder
@@ -130,6 +130,15 @@ need to render the viewfinder image yourself.
\snippet multimedia-snippets/camera.cpp Camera overview surface
+On mobile devices, the viewfinder image might not always be in the orientation you would expect.
+The camera sensors on these devices are often mounted in landscape while the natural
+orientation of the screen is portrait. This results in the image appearing sideways or inverted
+depending on the device orientation. In order to reflect on screen what the user actually sees, you
+should make sure the viewfinder frames are always rotated to the correct orientation, taking into
+account the camera sensor orientation and the current display orientation.
+
+ \snippet multimedia-snippets/camera.cpp Camera overview viewfinder orientation
+
\section2 Still Images
After setting up a viewfinder and finding something photogenic,
diff --git a/src/multimedia/qmediaserviceprovider.cpp b/src/multimedia/qmediaserviceprovider.cpp
index 0f5ff2b97..79227c5d2 100644
--- a/src/multimedia/qmediaserviceprovider.cpp
+++ b/src/multimedia/qmediaserviceprovider.cpp
@@ -58,7 +58,7 @@ class QMediaServiceProviderHintPrivate : public QSharedData
{
public:
QMediaServiceProviderHintPrivate(QMediaServiceProviderHint::Type type)
- :type(type), features(0)
+ :type(type), cameraPosition(QCamera::UnspecifiedPosition), features(0)
{
}
@@ -66,6 +66,7 @@ public:
:QSharedData(other),
type(other.type),
device(other.device),
+ cameraPosition(other.cameraPosition),
mimeType(other.mimeType),
codecs(other.codecs),
features(other.features)
@@ -78,6 +79,7 @@ public:
QMediaServiceProviderHint::Type type;
QByteArray device;
+ QCamera::Position cameraPosition;
QString mimeType;
QStringList codecs;
QMediaServiceProviderHint::Features features;
@@ -129,6 +131,7 @@ public:
\value ContentType Select media service most suitable for certain content type.
\value Device Select media service which supports certain device.
\value SupportedFeatures Select media service supporting the set of optional features.
+ \value CameraPosition Select media service having a camera at a specified position.
*/
@@ -165,6 +168,19 @@ QMediaServiceProviderHint::QMediaServiceProviderHint(const QByteArray &device)
}
/*!
+ \since 5.3
+
+ Constructs a CameraPosition media service provider hint.
+
+ This type of hint describes a media service that has a camera in the specific \a position.
+*/
+QMediaServiceProviderHint::QMediaServiceProviderHint(QCamera::Position position)
+ :d(new QMediaServiceProviderHintPrivate(CameraPosition))
+{
+ d->cameraPosition = position;
+}
+
+/*!
Constructs a SupportedFeatures media service provider hint.
This type of hint describes a service which supports a specific set of \a features.
@@ -209,6 +225,7 @@ bool QMediaServiceProviderHint::operator == (const QMediaServiceProviderHint &ot
return (d == other.d) ||
(d->type == other.d->type &&
d->device == other.d->device &&
+ d->cameraPosition == other.d->cameraPosition &&
d->mimeType == other.d->mimeType &&
d->codecs == other.d->codecs &&
d->features == other.d->features);
@@ -265,6 +282,17 @@ QByteArray QMediaServiceProviderHint::device() const
}
/*!
+ \since 5.3
+
+ Returns the camera's position a media service is expected to utilize.
+*/
+QCamera::Position QMediaServiceProviderHint::cameraPosition() const
+{
+ return d->cameraPosition;
+}
+
+
+/*!
Returns a set of features a media service is expected to provide.
*/
QMediaServiceProviderHint::Features QMediaServiceProviderHint::features() const
@@ -349,6 +377,29 @@ public:
}
}
break;
+ case QMediaServiceProviderHint::CameraPosition: {
+ plugin = plugins[0];
+ if (type == QByteArray(Q_MEDIASERVICE_CAMERA)
+ && hint.cameraPosition() != QCamera::UnspecifiedPosition) {
+ foreach (QMediaServiceProviderPlugin *currentPlugin, plugins) {
+ const QMediaServiceSupportedDevicesInterface *deviceIface =
+ qobject_cast<QMediaServiceSupportedDevicesInterface*>(currentPlugin);
+ const QMediaServiceCameraInfoInterface *cameraIface =
+ qobject_cast<QMediaServiceCameraInfoInterface*>(currentPlugin);
+
+ if (deviceIface && cameraIface) {
+ const QList<QByteArray> cameras = deviceIface->devices(type);
+ foreach (const QByteArray &camera, cameras) {
+ if (cameraIface->cameraPosition(camera) == hint.cameraPosition()) {
+ plugin = currentPlugin;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ break;
case QMediaServiceProviderHint::ContentType: {
QMultimedia::SupportEstimate estimate = QMultimedia::NotSupported;
foreach (QMediaServiceProviderPlugin *currentPlugin, plugins) {
@@ -496,6 +547,25 @@ public:
return supportedTypes;
}
+ QByteArray defaultDevice(const QByteArray &serviceType) const
+ {
+ foreach (QObject *obj, loader()->instances(QLatin1String(serviceType))) {
+ const QMediaServiceDefaultDeviceInterface *iface =
+ qobject_cast<QMediaServiceDefaultDeviceInterface*>(obj);
+
+ if (iface)
+ return iface->defaultDevice(serviceType);
+ }
+
+ // if QMediaServiceDefaultDeviceInterface is not implemented, return the
+ // first available device.
+ QList<QByteArray> devs = devices(serviceType);
+ if (!devs.isEmpty())
+ return devs.first();
+
+ return QByteArray();
+ }
+
QList<QByteArray> devices(const QByteArray &serviceType) const
{
QList<QByteArray> res;
@@ -526,6 +596,44 @@ public:
return QString();
}
+
+ QCamera::Position cameraPosition(const QByteArray &device) const
+ {
+ const QByteArray serviceType(Q_MEDIASERVICE_CAMERA);
+ foreach (QObject *obj, loader()->instances(QString::fromLatin1(serviceType))) {
+ const QMediaServiceSupportedDevicesInterface *deviceIface =
+ qobject_cast<QMediaServiceSupportedDevicesInterface*>(obj);
+ const QMediaServiceCameraInfoInterface *cameraIface =
+ qobject_cast<QMediaServiceCameraInfoInterface*>(obj);
+
+ if (cameraIface) {
+ if (deviceIface && !deviceIface->devices(serviceType).contains(device))
+ continue;
+ return cameraIface->cameraPosition(device);
+ }
+ }
+
+ return QCamera::UnspecifiedPosition;
+ }
+
+ int cameraOrientation(const QByteArray &device) const
+ {
+ const QByteArray serviceType(Q_MEDIASERVICE_CAMERA);
+ foreach (QObject *obj, loader()->instances(QString::fromLatin1(serviceType))) {
+ const QMediaServiceSupportedDevicesInterface *deviceIface =
+ qobject_cast<QMediaServiceSupportedDevicesInterface*>(obj);
+ const QMediaServiceCameraInfoInterface *cameraIface =
+ qobject_cast<QMediaServiceCameraInfoInterface*>(obj);
+
+ if (cameraIface) {
+ if (deviceIface && !deviceIface->devices(serviceType).contains(device))
+ continue;
+ return cameraIface->cameraOrientation(device);
+ }
+ }
+
+ return 0;
+ }
};
Q_GLOBAL_STATIC(QPluginServiceProvider, pluginProvider);
@@ -599,6 +707,17 @@ QStringList QMediaServiceProvider::supportedMimeTypes(const QByteArray &serviceT
}
/*!
+ \since 5.3
+
+ Returns the default device for a \a service type.
+*/
+QByteArray QMediaServiceProvider::defaultDevice(const QByteArray &serviceType) const
+{
+ Q_UNUSED(serviceType);
+ return QByteArray();
+}
+
+/*!
Returns the list of devices related to \a service type.
*/
QList<QByteArray> QMediaServiceProvider::devices(const QByteArray &service) const
@@ -618,6 +737,30 @@ QString QMediaServiceProvider::deviceDescription(const QByteArray &serviceType,
return QString();
}
+/*!
+ \since 5.3
+
+ Returns the physical position of a camera \a device on the system hardware.
+*/
+QCamera::Position QMediaServiceProvider::cameraPosition(const QByteArray &device) const
+{
+ Q_UNUSED(device);
+ return QCamera::UnspecifiedPosition;
+}
+
+/*!
+ \since 5.3
+
+ Returns the physical orientation of the camera \a device. The value is the angle by which the
+ camera image should be rotated anti-clockwise (in steps of 90 degrees) so it shows correctly on
+ the display in its natural orientation.
+*/
+int QMediaServiceProvider::cameraOrientation(const QByteArray &device) const
+{
+ Q_UNUSED(device);
+ return 0;
+}
+
static QMediaServiceProvider *qt_defaultMediaServiceProvider = 0;
/*!
@@ -713,15 +856,46 @@ QMediaServiceProvider *QMediaServiceProvider::defaultServiceProvider()
*/
/*!
+ \since 5.3
+
+ \fn QMediaServiceSupportedDevicesInterface::defaultDevice(const QByteArray &service) const
+
+ Returns the default device for a \a service type.
+*/
+
+/*!
\fn QMediaServiceSupportedDevicesInterface::devices(const QByteArray &service) const
- Returns a list of devices supported by a plug-in \a service.
+ Returns a list of devices available for a \a service type.
*/
/*!
\fn QMediaServiceSupportedDevicesInterface::deviceDescription(const QByteArray &service, const QByteArray &device)
- Returns a description of a \a device supported by a plug-in \a service.
+ Returns the description of a \a device available for a \a service type.
+*/
+
+/*!
+ \class QMediaServiceCameraInfoInterface
+ \inmodule QtMultimedia
+ \since 5.3
+ \brief The QMediaServiceCameraInfoInterface class interface
+ provides camera-specific information about devices supported by a camera service plug-in.
+
+ A QMediaServiceProviderPlugin may implement this interface, in that case it also needs to
+ implement the QMediaServiceSupportedDevicesInterface.
+*/
+
+/*!
+ \fn QMediaServiceCameraInfoInterface::cameraPosition(const QByteArray &device) const
+
+ Returns the physical position of a camera \a device supported by a camera service plug-in.
+*/
+
+/*!
+ \fn QMediaServiceCameraInfoInterface::cameraOrientation(const QByteArray &device) const
+
+ Returns the physical orientation of a camera \a device supported by a camera service plug-in.
*/
/*!
diff --git a/src/multimedia/qmediaserviceprovider_p.h b/src/multimedia/qmediaserviceprovider_p.h
index df4d5d819..0913822c2 100644
--- a/src/multimedia/qmediaserviceprovider_p.h
+++ b/src/multimedia/qmediaserviceprovider_p.h
@@ -67,9 +67,13 @@ public:
int flags = 0) const;
virtual QStringList supportedMimeTypes(const QByteArray &serviceType, int flags = 0) const;
+ virtual QByteArray defaultDevice(const QByteArray &serviceType) const;
virtual QList<QByteArray> devices(const QByteArray &serviceType) const;
virtual QString deviceDescription(const QByteArray &serviceType, const QByteArray &device);
+ virtual QCamera::Position cameraPosition(const QByteArray &device) const;
+ virtual int cameraOrientation(const QByteArray &device) const;
+
static QMediaServiceProvider* defaultServiceProvider();
static void setDefaultServiceProvider(QMediaServiceProvider *provider);
};
diff --git a/src/multimedia/qmediaserviceproviderplugin.h b/src/multimedia/qmediaserviceproviderplugin.h
index fa3b88235..2c276beed 100644
--- a/src/multimedia/qmediaserviceproviderplugin.h
+++ b/src/multimedia/qmediaserviceproviderplugin.h
@@ -46,6 +46,7 @@
#include <QtCore/qplugin.h>
#include <QtMultimedia/qmultimedia.h>
#include <QtMultimedia/qtmultimediadefs.h>
+#include <QtMultimedia/qcamera.h>
#ifdef Q_MOC_RUN
# pragma Q_MOC_EXPAND_MACROS
@@ -62,7 +63,7 @@ class QMediaServiceProviderHintPrivate;
class Q_MULTIMEDIA_EXPORT QMediaServiceProviderHint
{
public:
- enum Type { Null, ContentType, Device, SupportedFeatures };
+ enum Type { Null, ContentType, Device, SupportedFeatures, CameraPosition };
enum Feature {
LowLatencyPlayback = 0x01,
@@ -75,6 +76,7 @@ public:
QMediaServiceProviderHint();
QMediaServiceProviderHint(const QString &mimeType, const QStringList& codecs);
QMediaServiceProviderHint(const QByteArray &device);
+ QMediaServiceProviderHint(QCamera::Position position);
QMediaServiceProviderHint(Features features);
QMediaServiceProviderHint(const QMediaServiceProviderHint &other);
~QMediaServiceProviderHint();
@@ -92,6 +94,7 @@ public:
QStringList codecs() const;
QByteArray device() const;
+ QCamera::Position cameraPosition() const;
Features features() const;
@@ -145,6 +148,31 @@ struct Q_MULTIMEDIA_EXPORT QMediaServiceSupportedDevicesInterface
"org.qt-project.qt.mediaservicesupporteddevices/5.0"
Q_DECLARE_INTERFACE(QMediaServiceSupportedDevicesInterface, QMediaServiceSupportedDevicesInterface_iid)
+// This should be part of QMediaServiceSupportedDevicesInterface but it can't in order
+// to preserve binary compatibility with 5.2 and earlier.
+// The whole media service plugin API shouldn't even be public in the first place. It should
+// be made private in Qt 6.0 and QMediaServiceDefaultDeviceInterface should be merged with
+// QMediaServiceSupportedDevicesInterface
+struct Q_MULTIMEDIA_EXPORT QMediaServiceDefaultDeviceInterface
+{
+ virtual ~QMediaServiceDefaultDeviceInterface() {}
+ virtual QByteArray defaultDevice(const QByteArray &service) const = 0;
+};
+
+#define QMediaServiceDefaultDeviceInterface_iid \
+ "org.qt-project.qt.mediaservicedefaultdevice/5.3"
+Q_DECLARE_INTERFACE(QMediaServiceDefaultDeviceInterface, QMediaServiceDefaultDeviceInterface_iid)
+
+struct Q_MULTIMEDIA_EXPORT QMediaServiceCameraInfoInterface
+{
+ virtual QCamera::Position cameraPosition(const QByteArray &device) const = 0;
+ virtual int cameraOrientation(const QByteArray &device) const = 0;
+};
+
+#define QMediaServiceCameraInfoInterface_iid \
+ "org.qt-project.qt.mediaservicecamerainfo/5.3"
+Q_DECLARE_INTERFACE(QMediaServiceCameraInfoInterface, QMediaServiceCameraInfoInterface_iid)
+
// Required for QDoc workaround
class QString;
diff --git a/src/plugins/android/src/mediacapture/qandroidvideodeviceselectorcontrol.cpp b/src/plugins/android/src/mediacapture/qandroidvideodeviceselectorcontrol.cpp
index 04af61085..4bc664b7a 100644
--- a/src/plugins/android/src/mediacapture/qandroidvideodeviceselectorcontrol.cpp
+++ b/src/plugins/android/src/mediacapture/qandroidvideodeviceselectorcontrol.cpp
@@ -46,6 +46,7 @@
QT_BEGIN_NAMESPACE
+QByteArray QAndroidVideoDeviceSelectorControl::m_defaultDevice;
QList<QByteArray> QAndroidVideoDeviceSelectorControl::m_names;
QStringList QAndroidVideoDeviceSelectorControl::m_descriptions;
@@ -99,6 +100,7 @@ void QAndroidVideoDeviceSelectorControl::setSelectedDevice(int index)
void QAndroidVideoDeviceSelectorControl::update()
{
+ m_defaultDevice.clear();
m_names.clear();
m_descriptions.clear();
@@ -127,6 +129,17 @@ void QAndroidVideoDeviceSelectorControl::update()
break;
}
}
+
+ if (!m_names.isEmpty())
+ m_defaultDevice = m_names.first();
+}
+
+QByteArray QAndroidVideoDeviceSelectorControl::defaultDeviceName()
+{
+ if (m_names.isEmpty())
+ update();
+
+ return m_defaultDevice;
}
QList<QByteArray> QAndroidVideoDeviceSelectorControl::availableDevices()
diff --git a/src/plugins/android/src/mediacapture/qandroidvideodeviceselectorcontrol.h b/src/plugins/android/src/mediacapture/qandroidvideodeviceselectorcontrol.h
index 3ebf83ab2..b5cebec8e 100644
--- a/src/plugins/android/src/mediacapture/qandroidvideodeviceselectorcontrol.h
+++ b/src/plugins/android/src/mediacapture/qandroidvideodeviceselectorcontrol.h
@@ -66,6 +66,7 @@ public:
void setSelectedDevice(int index);
+ static QByteArray defaultDeviceName();
static QList<QByteArray> availableDevices();
static QString availableDeviceDescription(const QByteArray &device);
@@ -73,6 +74,7 @@ private:
static void update();
int m_selectedDevice;
+ static QByteArray m_defaultDevice;
static QList<QByteArray> m_names;
static QStringList m_descriptions;
diff --git a/src/plugins/android/src/qandroidmediaserviceplugin.cpp b/src/plugins/android/src/qandroidmediaserviceplugin.cpp
index d7a2cd29f..03c2b287c 100644
--- a/src/plugins/android/src/qandroidmediaserviceplugin.cpp
+++ b/src/plugins/android/src/qandroidmediaserviceplugin.cpp
@@ -96,6 +96,14 @@ QMediaServiceProviderHint::Features QAndroidMediaServicePlugin::supportedFeature
return QMediaServiceProviderHint::Features();
}
+QByteArray QAndroidMediaServicePlugin::defaultDevice(const QByteArray &service) const
+{
+ if (service == Q_MEDIASERVICE_CAMERA)
+ return QAndroidVideoDeviceSelectorControl::defaultDeviceName();
+
+ return QByteArray();
+}
+
QList<QByteArray> QAndroidMediaServicePlugin::devices(const QByteArray &service) const
{
if (service == Q_MEDIASERVICE_CAMERA)
diff --git a/src/plugins/android/src/qandroidmediaserviceplugin.h b/src/plugins/android/src/qandroidmediaserviceplugin.h
index 18b1def21..8966d6cb3 100644
--- a/src/plugins/android/src/qandroidmediaserviceplugin.h
+++ b/src/plugins/android/src/qandroidmediaserviceplugin.h
@@ -49,10 +49,12 @@ QT_BEGIN_NAMESPACE
class QAndroidMediaServicePlugin
: public QMediaServiceProviderPlugin
, public QMediaServiceSupportedDevicesInterface
+ , public QMediaServiceDefaultDeviceInterface
, public QMediaServiceFeaturesInterface
{
Q_OBJECT
Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
+ Q_INTERFACES(QMediaServiceDefaultDeviceInterface)
Q_INTERFACES(QMediaServiceFeaturesInterface)
Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0"
FILE "android_mediaservice.json")
@@ -66,6 +68,7 @@ public:
QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const Q_DECL_OVERRIDE;
+ QByteArray defaultDevice(const QByteArray &service) const;
QList<QByteArray> devices(const QByteArray &service) const;
QString deviceDescription(const QByteArray &service, const QByteArray &device);
};
diff --git a/src/plugins/avfoundation/camera/avfcameraserviceplugin.h b/src/plugins/avfoundation/camera/avfcameraserviceplugin.h
index 34130ffcb..f974bcf0b 100644
--- a/src/plugins/avfoundation/camera/avfcameraserviceplugin.h
+++ b/src/plugins/avfoundation/camera/avfcameraserviceplugin.h
@@ -49,10 +49,12 @@
QT_BEGIN_NAMESPACE
class AVFServicePlugin : public QMediaServiceProviderPlugin,
- public QMediaServiceSupportedDevicesInterface
+ public QMediaServiceSupportedDevicesInterface,
+ public QMediaServiceDefaultDeviceInterface
{
Q_OBJECT
Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
+ Q_INTERFACES(QMediaServiceDefaultDeviceInterface)
Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "avfcamera.json")
public:
@@ -61,12 +63,14 @@ public:
QMediaService* create(QString const& key);
void release(QMediaService *service);
+ QByteArray defaultDevice(const QByteArray &service) const;
QList<QByteArray> devices(const QByteArray &service) const;
QString deviceDescription(const QByteArray &service, const QByteArray &device);
private:
void updateDevices() const;
+ mutable QByteArray m_defaultCameraDevice;
mutable QList<QByteArray> m_cameraDevices;
mutable QMap<QByteArray, QString> m_cameraDescriptions;
};
diff --git a/src/plugins/avfoundation/camera/avfcameraserviceplugin.mm b/src/plugins/avfoundation/camera/avfcameraserviceplugin.mm
index 19e4e7975..8ec3390e9 100644
--- a/src/plugins/avfoundation/camera/avfcameraserviceplugin.mm
+++ b/src/plugins/avfoundation/camera/avfcameraserviceplugin.mm
@@ -72,6 +72,18 @@ void AVFServicePlugin::release(QMediaService *service)
delete service;
}
+QByteArray AVFServicePlugin::defaultDevice(const QByteArray &service) const
+{
+ if (service == Q_MEDIASERVICE_CAMERA) {
+ if (m_cameraDevices.isEmpty())
+ updateDevices();
+
+ return m_defaultCameraDevice;
+ }
+
+ return QByteArray();
+}
+
QList<QByteArray> AVFServicePlugin::devices(const QByteArray &service) const
{
if (service == Q_MEDIASERVICE_CAMERA) {
@@ -98,9 +110,14 @@ QString AVFServicePlugin::deviceDescription(const QByteArray &service, const QBy
void AVFServicePlugin::updateDevices() const
{
+ m_defaultCameraDevice.clear();
m_cameraDevices.clear();
m_cameraDescriptions.clear();
+ AVCaptureDevice *defaultDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
+ if (defaultDevice)
+ m_defaultCameraDevice = QByteArray([[defaultDevice uniqueID] UTF8String]);
+
NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in videoDevices) {
QByteArray deviceId([[device uniqueID] UTF8String]);
diff --git a/src/plugins/avfoundation/camera/avfvideodevicecontrol.h b/src/plugins/avfoundation/camera/avfvideodevicecontrol.h
index 2fc376e27..fe27906cf 100644
--- a/src/plugins/avfoundation/camera/avfvideodevicecontrol.h
+++ b/src/plugins/avfoundation/camera/avfvideodevicecontrol.h
@@ -80,6 +80,7 @@ private:
int m_selectedDevice;
bool m_dirty;
+ int m_defaultDevice;
QStringList m_devices;
QStringList m_deviceDescriptions;
};
diff --git a/src/plugins/avfoundation/camera/avfvideodevicecontrol.mm b/src/plugins/avfoundation/camera/avfvideodevicecontrol.mm
index 3c8e39c0e..776707549 100644
--- a/src/plugins/avfoundation/camera/avfvideodevicecontrol.mm
+++ b/src/plugins/avfoundation/camera/avfvideodevicecontrol.mm
@@ -50,11 +50,17 @@ AVFVideoDeviceControl::AVFVideoDeviceControl(AVFCameraService *service, QObject
, m_service(service)
, m_selectedDevice(0)
, m_dirty(true)
+ , m_defaultDevice(0)
{
+ AVCaptureDevice *defaultDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
+ int i = 0;
for (AVCaptureDevice *device in videoDevices) {
m_devices << QString::fromUtf8([[device uniqueID] UTF8String]);
m_deviceDescriptions << QString::fromUtf8([[device localizedName] UTF8String]);
+ if (defaultDevice && [[device uniqueID] isEqualToString:[defaultDevice uniqueID]])
+ m_defaultDevice = i;
+ ++i;
}
}
@@ -79,7 +85,7 @@ QString AVFVideoDeviceControl::deviceDescription(int index) const
int AVFVideoDeviceControl::defaultDevice() const
{
- return 0;
+ return m_defaultDevice;
}
int AVFVideoDeviceControl::selectedDevice() const
diff --git a/src/plugins/directshow/camera/dsvideodevicecontrol.cpp b/src/plugins/directshow/camera/dsvideodevicecontrol.cpp
index 0f639bdce..ead1060d4 100644
--- a/src/plugins/directshow/camera/dsvideodevicecontrol.cpp
+++ b/src/plugins/directshow/camera/dsvideodevicecontrol.cpp
@@ -153,7 +153,7 @@ void DSVideoDeviceControl::enumerateDevices(QList<QByteArray> *devices, QStringL
void DSVideoDeviceControl::setSelectedDevice(int index)
{
- if (index >= 0 && index <= m_devices.count()) {
+ if (index >= 0 && index < m_devices.count()) {
if (m_session) {
QString device = m_devices.at(index);
if (device.startsWith("ds:"))
diff --git a/src/plugins/directshow/dsserviceplugin.cpp b/src/plugins/directshow/dsserviceplugin.cpp
index dca7430af..d262febdd 100644
--- a/src/plugins/directshow/dsserviceplugin.cpp
+++ b/src/plugins/directshow/dsserviceplugin.cpp
@@ -107,6 +107,20 @@ QMediaServiceProviderHint::Features DSServicePlugin::supportedFeatures(
return QMediaServiceProviderHint::Features();
}
+QByteArray DSServicePlugin::defaultDevice(const QByteArray &service) const
+{
+#ifdef QMEDIA_DIRECTSHOW_CAMERA
+ if (service == Q_MEDIASERVICE_CAMERA) {
+ if (m_cameraDevices.isEmpty())
+ updateDevices();
+
+ return m_defaultCameraDevice;
+ }
+#endif
+
+ return QByteArray();
+}
+
QList<QByteArray> DSServicePlugin::devices(const QByteArray &service) const
{
#ifdef QMEDIA_DIRECTSHOW_CAMERA
@@ -140,10 +154,13 @@ QString DSServicePlugin::deviceDescription(const QByteArray &service, const QByt
void DSServicePlugin::updateDevices() const
{
+ m_defaultCameraDevice.clear();
DSVideoDeviceControl::enumerateDevices(&m_cameraDevices, &m_cameraDescriptions);
if (m_cameraDevices.isEmpty()) {
qWarning() << "No camera devices found";
+ } else {
+ m_defaultCameraDevice = m_cameraDevices.first();
}
}
#endif
diff --git a/src/plugins/directshow/dsserviceplugin.h b/src/plugins/directshow/dsserviceplugin.h
index 82f1acd6d..6d59de558 100644
--- a/src/plugins/directshow/dsserviceplugin.h
+++ b/src/plugins/directshow/dsserviceplugin.h
@@ -49,10 +49,12 @@ QT_USE_NAMESPACE
class DSServicePlugin
: public QMediaServiceProviderPlugin
, public QMediaServiceSupportedDevicesInterface
+ , public QMediaServiceDefaultDeviceInterface
, public QMediaServiceFeaturesInterface
{
Q_OBJECT
Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
+ Q_INTERFACES(QMediaServiceDefaultDeviceInterface)
Q_INTERFACES(QMediaServiceFeaturesInterface)
// The player service provided by the WMF-plugin should preferably be used.
// DirectShow should then only provide the camera (see QTBUG-29172, QTBUG-29175).
@@ -68,6 +70,7 @@ public:
QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const;
+ QByteArray defaultDevice(const QByteArray &service) const;
QList<QByteArray> devices(const QByteArray &service) const;
QString deviceDescription(const QByteArray &service, const QByteArray &device);
@@ -75,6 +78,7 @@ private:
#ifdef QMEDIA_DIRECTSHOW_CAMERA
void updateDevices() const;
+ mutable QByteArray m_defaultCameraDevice;
mutable QList<QByteArray> m_cameraDevices;
mutable QStringList m_cameraDescriptions;
#endif
diff --git a/src/plugins/gstreamer/camerabin/camerabinserviceplugin.cpp b/src/plugins/gstreamer/camerabin/camerabinserviceplugin.cpp
index 4d530d66f..37641b001 100644
--- a/src/plugins/gstreamer/camerabin/camerabinserviceplugin.cpp
+++ b/src/plugins/gstreamer/camerabin/camerabinserviceplugin.cpp
@@ -90,6 +90,18 @@ QMediaServiceProviderHint::Features CameraBinServicePlugin::supportedFeatures(
return QMediaServiceProviderHint::Features();
}
+QByteArray CameraBinServicePlugin::defaultDevice(const QByteArray &service) const
+{
+ if (service == Q_MEDIASERVICE_CAMERA) {
+ if (m_cameraDevices.isEmpty())
+ updateDevices();
+
+ return m_defaultCameraDevice;
+ }
+
+ return QByteArray();
+}
+
QList<QByteArray> CameraBinServicePlugin::devices(const QByteArray &service) const
{
if (service == Q_MEDIASERVICE_CAMERA) {
@@ -126,6 +138,7 @@ QVariant CameraBinServicePlugin::deviceProperty(const QByteArray &service, const
void CameraBinServicePlugin::updateDevices() const
{
+ m_defaultCameraDevice.clear();
m_cameraDevices.clear();
m_cameraDescriptions.clear();
@@ -167,6 +180,9 @@ void CameraBinServicePlugin::updateDevices() const
}
::close(fd);
}
+
+ if (!m_cameraDevices.isEmpty())
+ m_defaultCameraDevice = m_cameraDevices.first();
}
QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabinserviceplugin.h b/src/plugins/gstreamer/camerabin/camerabinserviceplugin.h
index f0aea0b3a..50ffc59b2 100644
--- a/src/plugins/gstreamer/camerabin/camerabinserviceplugin.h
+++ b/src/plugins/gstreamer/camerabin/camerabinserviceplugin.h
@@ -51,10 +51,12 @@ QT_BEGIN_NAMESPACE
class CameraBinServicePlugin
: public QMediaServiceProviderPlugin
, public QMediaServiceSupportedDevicesInterface
+ , public QMediaServiceDefaultDeviceInterface
, public QMediaServiceFeaturesInterface
{
Q_OBJECT
Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
+ Q_INTERFACES(QMediaServiceDefaultDeviceInterface)
Q_INTERFACES(QMediaServiceFeaturesInterface)
Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "camerabin.json")
public:
@@ -63,6 +65,7 @@ public:
QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const;
+ QByteArray defaultDevice(const QByteArray &service) const;
QList<QByteArray> devices(const QByteArray &service) const;
QString deviceDescription(const QByteArray &service, const QByteArray &device);
QVariant deviceProperty(const QByteArray &service, const QByteArray &device, const QByteArray &property);
@@ -70,6 +73,7 @@ public:
private:
void updateDevices() const;
+ mutable QByteArray m_defaultCameraDevice;
mutable QList<QByteArray> m_cameraDevices;
mutable QStringList m_cameraDescriptions;
};
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercaptureserviceplugin.cpp b/src/plugins/gstreamer/mediacapture/qgstreamercaptureserviceplugin.cpp
index dbb7649f4..de07d2707 100644
--- a/src/plugins/gstreamer/mediacapture/qgstreamercaptureserviceplugin.cpp
+++ b/src/plugins/gstreamer/mediacapture/qgstreamercaptureserviceplugin.cpp
@@ -95,6 +95,18 @@ QMediaServiceProviderHint::Features QGstreamerCaptureServicePlugin::supportedFea
return QMediaServiceProviderHint::Features();
}
+QByteArray QGstreamerCaptureServicePlugin::defaultDevice(const QByteArray &service) const
+{
+ if (service == Q_MEDIASERVICE_CAMERA) {
+ if (m_cameraDevices.isEmpty())
+ updateDevices();
+
+ return m_defaultCameraDevice;
+ }
+
+ return QByteArray();
+}
+
QList<QByteArray> QGstreamerCaptureServicePlugin::devices(const QByteArray &service) const
{
if (service == Q_MEDIASERVICE_CAMERA) {
@@ -131,6 +143,7 @@ QVariant QGstreamerCaptureServicePlugin::deviceProperty(const QByteArray &servic
void QGstreamerCaptureServicePlugin::updateDevices() const
{
+ m_defaultCameraDevice.clear();
m_cameraDevices.clear();
m_cameraDescriptions.clear();
@@ -174,6 +187,9 @@ void QGstreamerCaptureServicePlugin::updateDevices() const
}
::close(fd);
}
+
+ if (!m_cameraDevices.isEmpty())
+ m_defaultCameraDevice = m_cameraDevices.first();
}
#endif
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamercaptureserviceplugin.h b/src/plugins/gstreamer/mediacapture/qgstreamercaptureserviceplugin.h
index 3003cbbcc..a1141d324 100644
--- a/src/plugins/gstreamer/mediacapture/qgstreamercaptureserviceplugin.h
+++ b/src/plugins/gstreamer/mediacapture/qgstreamercaptureserviceplugin.h
@@ -53,6 +53,7 @@ class QGstreamerCaptureServicePlugin
: public QMediaServiceProviderPlugin
#if defined(USE_GSTREAMER_CAMERA)
, public QMediaServiceSupportedDevicesInterface
+ , public QMediaServiceDefaultDeviceInterface
, public QMediaServiceFeaturesInterface
#endif
, public QMediaServiceSupportedFormatsInterface
@@ -60,6 +61,7 @@ class QGstreamerCaptureServicePlugin
Q_OBJECT
#if defined(USE_GSTREAMER_CAMERA)
Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
+ Q_INTERFACES(QMediaServiceDefaultDeviceInterface)
Q_INTERFACES(QMediaServiceFeaturesInterface)
#endif
Q_INTERFACES(QMediaServiceSupportedFormatsInterface)
@@ -75,6 +77,7 @@ public:
#if defined(USE_GSTREAMER_CAMERA)
QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const;
+ QByteArray defaultDevice(const QByteArray &service) const;
QList<QByteArray> devices(const QByteArray &service) const;
QString deviceDescription(const QByteArray &service, const QByteArray &device);
QVariant deviceProperty(const QByteArray &service, const QByteArray &device, const QByteArray &property);
@@ -87,6 +90,7 @@ private:
#if defined(USE_GSTREAMER_CAMERA)
void updateDevices() const;
+ mutable QByteArray m_defaultCameraDevice;
mutable QList<QByteArray> m_cameraDevices;
mutable QStringList m_cameraDescriptions;
#endif
diff --git a/src/plugins/qnx/bbserviceplugin.cpp b/src/plugins/qnx/bbserviceplugin.cpp
index 59be46453..2351e5730 100644
--- a/src/plugins/qnx/bbserviceplugin.cpp
+++ b/src/plugins/qnx/bbserviceplugin.cpp
@@ -74,6 +74,18 @@ QMediaServiceProviderHint::Features BbServicePlugin::supportedFeatures(const QBy
return QMediaServiceProviderHint::Features();
}
+QByteArray BbServicePlugin::defaultDevice(const QByteArray &service) const
+{
+ if (service == Q_MEDIASERVICE_CAMERA) {
+ if (m_cameraDevices.isEmpty())
+ updateDevices();
+
+ return m_defaultCameraDevice;
+ }
+
+ return QByteArray();
+}
+
QList<QByteArray> BbServicePlugin::devices(const QByteArray &service) const
{
if (service == Q_MEDIASERVICE_CAMERA) {
@@ -102,10 +114,13 @@ QString BbServicePlugin::deviceDescription(const QByteArray &service, const QByt
void BbServicePlugin::updateDevices() const
{
+ m_defaultCameraDevice.clear();
BbVideoDeviceSelectorControl::enumerateDevices(&m_cameraDevices, &m_cameraDescriptions);
if (m_cameraDevices.isEmpty()) {
qWarning() << "No camera devices found";
+ } else {
+ m_defaultCameraDevice = m_cameraDevices.first();
}
}
diff --git a/src/plugins/qnx/bbserviceplugin.h b/src/plugins/qnx/bbserviceplugin.h
index 62fc4a0df..45ea4cc6f 100644
--- a/src/plugins/qnx/bbserviceplugin.h
+++ b/src/plugins/qnx/bbserviceplugin.h
@@ -48,10 +48,12 @@ QT_BEGIN_NAMESPACE
class BbServicePlugin
: public QMediaServiceProviderPlugin,
public QMediaServiceSupportedDevicesInterface,
+ public QMediaServiceDefaultDeviceInterface,
public QMediaServiceFeaturesInterface
{
Q_OBJECT
Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
+ Q_INTERFACES(QMediaServiceDefaultDeviceInterface)
Q_INTERFACES(QMediaServiceFeaturesInterface)
Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "blackberry_mediaservice.json")
public:
@@ -61,6 +63,7 @@ public:
void release(QMediaService *service) Q_DECL_OVERRIDE;
QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const Q_DECL_OVERRIDE;
+ QByteArray defaultDevice(const QByteArray &service) const Q_DECL_OVERRIDE;
QList<QByteArray> devices(const QByteArray &service) const Q_DECL_OVERRIDE;
QString deviceDescription(const QByteArray &service, const QByteArray &device) Q_DECL_OVERRIDE;
QVariant deviceProperty(const QByteArray &service, const QByteArray &device, const QByteArray &property) Q_DECL_OVERRIDE;
@@ -68,6 +71,7 @@ public:
private:
void updateDevices() const;
+ mutable QByteArray m_defaultCameraDevice;
mutable QList<QByteArray> m_cameraDevices;
mutable QStringList m_cameraDescriptions;
};
diff --git a/src/plugins/wmf/wmfserviceplugin.cpp b/src/plugins/wmf/wmfserviceplugin.cpp
index 79354b4e1..f114e2908 100644
--- a/src/plugins/wmf/wmfserviceplugin.cpp
+++ b/src/plugins/wmf/wmfserviceplugin.cpp
@@ -105,6 +105,11 @@ QMediaServiceProviderHint::Features WMFServicePlugin::supportedFeatures(
return QMediaServiceProviderHint::Features();
}
+QByteArray WMFServicePlugin::defaultDevice(const QByteArray &) const
+{
+ return QByteArray();
+}
+
QList<QByteArray> WMFServicePlugin::devices(const QByteArray &) const
{
return QList<QByteArray>();
diff --git a/src/plugins/wmf/wmfserviceplugin.h b/src/plugins/wmf/wmfserviceplugin.h
index bc2e6ff54..a58af5c4b 100644
--- a/src/plugins/wmf/wmfserviceplugin.h
+++ b/src/plugins/wmf/wmfserviceplugin.h
@@ -49,10 +49,12 @@ QT_USE_NAMESPACE
class WMFServicePlugin
: public QMediaServiceProviderPlugin
, public QMediaServiceSupportedDevicesInterface
+ , public QMediaServiceDefaultDeviceInterface
, public QMediaServiceFeaturesInterface
{
Q_OBJECT
Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
+ Q_INTERFACES(QMediaServiceDefaultDeviceInterface)
Q_INTERFACES(QMediaServiceFeaturesInterface)
Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "wmf.json")
public:
@@ -61,6 +63,7 @@ public:
QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const;
+ QByteArray defaultDevice(const QByteArray &service) const;
QList<QByteArray> devices(const QByteArray &service) const;
QString deviceDescription(const QByteArray &service, const QByteArray &device);
};