New QCameraInfo class.
authorYoann Lopes <yoann.lopes@digia.com>
Wed, 22 Jan 2014 15:18:42 +0000 (16:18 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 28 Feb 2014 13:10:00 +0000 (14:10 +0100)
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>
54 files changed:
src/multimedia/camera/camera.pri
src/multimedia/camera/qcamera.cpp
src/multimedia/camera/qcamera.h
src/multimedia/camera/qcamera_p.h [new file with mode: 0644]
src/multimedia/camera/qcameraexposure.h
src/multimedia/camera/qcamerafocus.h
src/multimedia/camera/qcameraimageprocessing.h
src/multimedia/camera/qcamerainfo.cpp [new file with mode: 0644]
src/multimedia/camera/qcamerainfo.h [new file with mode: 0644]
src/multimedia/controls/controls.pri
src/multimedia/controls/qcamerainfocontrol.cpp [new file with mode: 0644]
src/multimedia/controls/qcamerainfocontrol.h [new file with mode: 0644]
src/multimedia/doc/snippets/multimedia-snippets/camera.cpp
src/multimedia/doc/src/cameraoverview.qdoc
src/multimedia/qmediaserviceprovider.cpp
src/multimedia/qmediaserviceprovider_p.h
src/multimedia/qmediaserviceproviderplugin.h
src/plugins/android/src/mediacapture/qandroidvideodeviceselectorcontrol.cpp
src/plugins/android/src/mediacapture/qandroidvideodeviceselectorcontrol.h
src/plugins/android/src/qandroidmediaserviceplugin.cpp
src/plugins/android/src/qandroidmediaserviceplugin.h
src/plugins/avfoundation/camera/avfcameraserviceplugin.h
src/plugins/avfoundation/camera/avfcameraserviceplugin.mm
src/plugins/avfoundation/camera/avfvideodevicecontrol.h
src/plugins/avfoundation/camera/avfvideodevicecontrol.mm
src/plugins/directshow/camera/dsvideodevicecontrol.cpp
src/plugins/directshow/dsserviceplugin.cpp
src/plugins/directshow/dsserviceplugin.h
src/plugins/gstreamer/camerabin/camerabinserviceplugin.cpp
src/plugins/gstreamer/camerabin/camerabinserviceplugin.h
src/plugins/gstreamer/mediacapture/qgstreamercaptureserviceplugin.cpp
src/plugins/gstreamer/mediacapture/qgstreamercaptureserviceplugin.h
src/plugins/qnx/bbserviceplugin.cpp
src/plugins/qnx/bbserviceplugin.h
src/plugins/wmf/wmfserviceplugin.cpp
src/plugins/wmf/wmfserviceplugin.h
tests/auto/integration/qcamerabackend/tst_qcamerabackend.cpp
tests/auto/unit/multimedia.pro
tests/auto/unit/qcamera/tst_qcamera.cpp
tests/auto/unit/qcamerainfo/qcamerainfo.pro [new file with mode: 0644]
tests/auto/unit/qcamerainfo/tst_qcamerainfo.cpp [new file with mode: 0644]
tests/auto/unit/qmediaserviceprovider/mockserviceplugin1/mockserviceplugin1.cpp
tests/auto/unit/qmediaserviceprovider/mockserviceplugin3/mockserviceplugin3.cpp
tests/auto/unit/qmediaserviceprovider/mockserviceplugin3/mockserviceplugin3.json
tests/auto/unit/qmediaserviceprovider/mockserviceplugin5/mockserviceplugin5.cpp [new file with mode: 0644]
tests/auto/unit/qmediaserviceprovider/mockserviceplugin5/mockserviceplugin5.json [new file with mode: 0644]
tests/auto/unit/qmediaserviceprovider/mockserviceplugin5/mockserviceplugin5.pro [new file with mode: 0644]
tests/auto/unit/qmediaserviceprovider/qmediaserviceprovider.pro
tests/auto/unit/qmediaserviceprovider/tst_qmediaserviceprovider.cpp
tests/auto/unit/qmultimedia_common/mockcamera.pri
tests/auto/unit/qmultimedia_common/mockcamerainfocontrol.h [new file with mode: 0644]
tests/auto/unit/qmultimedia_common/mockcameraservice.h
tests/auto/unit/qmultimedia_common/mockmediaserviceprovider.h
tests/auto/unit/qmultimedia_common/mockvideodeviceselectorcontrol.h [new file with mode: 0644]

index be7868c..0e0031f 100644 (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
 
index e91a031..32bab00 100644 (file)
 **
 ****************************************************************************/
 
-#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.
index 6a29b2c..9c413c3 100644 (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
diff --git a/src/multimedia/camera/qcamera_p.h b/src/multimedia/camera/qcamera_p.h
new file mode 100644 (file)
index 0000000..ac2ab87
--- /dev/null
@@ -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
index ba8e25c..df3b4ba 100644 (file)
@@ -159,6 +159,7 @@ Q_SIGNALS:
 
 private:
     friend class QCamera;
+    friend class QCameraPrivate;
     explicit QCameraExposure(QCamera *parent = 0);
     virtual ~QCameraExposure();
 
index 675ae2e..f4ac6a5 100644 (file)
@@ -156,6 +156,7 @@ Q_SIGNALS:
 
 private:
     friend class QCamera;
+    friend class QCameraPrivate;
     QCameraFocus(QCamera *camera);
     ~QCameraFocus();
 
index ffb088f..d0360d8 100644 (file)
@@ -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 (file)
index 0000000..218219c
--- /dev/null
@@ -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 (file)
index 0000000..4aea2b7
--- /dev/null
@@ -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
index e756abc..b19532f 100644 (file)
@@ -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 (file)
index 0000000..585413a
--- /dev/null
@@ -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 (file)
index 0000000..a5742c0
--- /dev/null
@@ -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
index a512e0b..65dff26 100644 (file)
 /* 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]
index 71515ab..b2b9d46 100644 (file)
@@ -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,
index 0f5ff2b..79227c5 100644 (file)
@@ -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.
 */
 
 /*!
index df4d5d8..0913822 100644 (file)
@@ -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);
 };
index fa3b882..2c276be 100644 (file)
@@ -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;
 
index 04af610..4bc664b 100644 (file)
@@ -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()
index 3ebf83a..b5cebec 100644 (file)
@@ -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;
 
index d7a2cd2..03c2b28 100644 (file)
@@ -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)
index 18b1def..8966d6c 100644 (file)
@@ -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);
 };
index 34130ff..f974bcf 100644 (file)
 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;
 };
index 19e4e79..8ec3390 100644 (file)
@@ -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]);
index 2fc376e..fe27906 100644 (file)
@@ -80,6 +80,7 @@ private:
 
     int m_selectedDevice;
     bool m_dirty;
+    int m_defaultDevice;
     QStringList m_devices;
     QStringList m_deviceDescriptions;
 };
index 3c8e39c..7767075 100644 (file)
@@ -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
index 0f639bd..ead1060 100644 (file)
@@ -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:"))
index dca7430..d262feb 100644 (file)
@@ -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
index 82f1acd..6d59de5 100644 (file)
@@ -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
index 4d530d6..37641b0 100644 (file)
@@ -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
index f0aea0b..50ffc59 100644 (file)
@@ -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;
 };
index dbb7649..de07d27 100644 (file)
@@ -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
 
index 3003cbb..a1141d3 100644 (file)
@@ -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
index 59be464..2351e57 100644 (file)
@@ -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();
     }
 }
 
index 62fc4a0..45ea4cc 100644 (file)
@@ -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;
 };
index 79354b4..f114e29 100644 (file)
@@ -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>();
index bc2e6ff..a58af5c 100644 (file)
@@ -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);
 };
index 602fbf3..137377c 100644 (file)
@@ -58,6 +58,7 @@
 #include <qcameracapturedestinationcontrol.h>
 #include <qmediaservice.h>
 #include <qcamera.h>
+#include <qcamerainfo.h>
 #include <qcameraimagecapture.h>
 #include <qvideorenderercontrol.h>
 #include <private/qmediaserviceprovider_p.h>
@@ -82,7 +83,10 @@ public slots:
 private slots:
     void testAvailableDevices();
     void testDeviceDescription();
+    void testCameraInfo();
     void testCtorWithDevice();
+    void testCtorWithCameraInfo();
+    void testCtorWithPosition();
 
     void testCameraStates();
     void testCaptureMode();
@@ -126,6 +130,23 @@ void tst_QCameraBackend::testDeviceDescription()
     }
 }
 
+void tst_QCameraBackend::testCameraInfo()
+{
+    int deviceCount = QMediaServiceProvider::defaultServiceProvider()->devices(QByteArray(Q_MEDIASERVICE_CAMERA)).count();
+    QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
+    QCOMPARE(cameras.count(), deviceCount);
+    if (cameras.isEmpty()) {
+        QVERIFY(QCameraInfo::defaultCamera().isNull());
+        QSKIP("Camera selection is not supported");
+    }
+
+    foreach (const QCameraInfo &info, cameras) {
+        QVERIFY(!info.deviceName().isEmpty());
+        QVERIFY(!info.description().isEmpty());
+        QVERIFY(info.orientation() % 90 == 0);
+    }
+}
+
 void tst_QCameraBackend::testCtorWithDevice()
 {
     if (QCamera::availableDevices().isEmpty())
@@ -142,6 +163,58 @@ void tst_QCameraBackend::testCtorWithDevice()
     delete camera;
 }
 
+void tst_QCameraBackend::testCtorWithCameraInfo()
+{
+    if (QCameraInfo::availableCameras().isEmpty())
+        QSKIP("Camera selection not supported");
+
+    {
+        QCameraInfo info = QCameraInfo::defaultCamera();
+        QCamera camera(info);
+        QCOMPARE(camera.error(), QCamera::NoError);
+        QCOMPARE(QCameraInfo(camera), info);
+    }
+    {
+        QCameraInfo info = QCameraInfo::availableCameras().first();
+        QCamera camera(info);
+        QCOMPARE(camera.error(), QCamera::NoError);
+        QCOMPARE(QCameraInfo(camera), info);
+    }
+    {
+        // loading an invalid CameraInfo should fail
+        QCamera *camera = new QCamera(QCameraInfo());
+        QCOMPARE(camera->error(), QCamera::ServiceMissingError);
+        QVERIFY(QCameraInfo(*camera).isNull());
+        delete camera;
+    }
+    {
+        // loading non existing camera should fail
+        QCamera camera(QCameraInfo(QUuid::createUuid().toByteArray()));
+        QCOMPARE(camera.error(), QCamera::ServiceMissingError);
+        QVERIFY(QCameraInfo(camera).isNull());
+    }
+}
+
+void tst_QCameraBackend::testCtorWithPosition()
+{
+    {
+        QCamera camera(QCamera::UnspecifiedPosition);
+        QCOMPARE(camera.error(), QCamera::NoError);
+    }
+    {
+        QCamera camera(QCamera::FrontFace);
+        // even if no camera is available at this position, it should not fail
+        // and load the default camera
+        QCOMPARE(camera.error(), QCamera::NoError);
+    }
+    {
+        QCamera camera(QCamera::BackFace);
+        // even if no camera is available at this position, it should not fail
+        // and load the default camera
+        QCOMPARE(camera.error(), QCamera::NoError);
+    }
+}
+
 void tst_QCameraBackend::testCameraStates()
 {
     QCamera camera;
index f9bf0f3..5c9a831 100644 (file)
@@ -7,6 +7,7 @@ SUBDIRS += \
     qaudioformat \
     qaudionamespace \
     qcamera \
+    qcamerainfo \
     qcameraimagecapture \
     qmediabindableinterface \
     qmediacontainercontrol \
index 8c72acb..11032a4 100644 (file)
@@ -57,6 +57,7 @@
 #include <qcameracapturedestinationcontrol.h>
 #include <qmediaservice.h>
 #include <qcamera.h>
+#include <qcamerainfo.h>
 #include <qcameraimagecapture.h>
 #include <qvideorenderercontrol.h>
 
@@ -101,7 +102,7 @@ private slots:
     void testCaptureDestination();
     void testCaptureFormat();
 
-    void testConstructorWithDefaultProvider();
+    void testConstructor();
     void testCaptureMode();
     void testIsCaptureModeSupported();
     void testRequestedLocks();
@@ -1141,6 +1142,8 @@ void tst_QCamera::testEnumDebug()
     qDebug() << QCamera::NoLock;
     QTest::ignoreMessage(QtDebugMsg, "QCamera::LockExposure ");
     qDebug() << QCamera::LockExposure;
+    QTest::ignoreMessage(QtDebugMsg, "QCamera::FrontFace ");
+    qDebug() << QCamera::FrontFace;
 }
 
 void tst_QCamera::testCameraControl()
@@ -1149,13 +1152,75 @@ void tst_QCamera::testCameraControl()
     QVERIFY(m_cameraControl != NULL);
 }
 
-/* Test case for constructor with default provider */
-void tst_QCamera::testConstructorWithDefaultProvider()
+void tst_QCamera::testConstructor()
 {
-    QCamera *camera = new QCamera(0);
-    QVERIFY(camera != NULL);
-    QCOMPARE(camera->state(), QCamera::UnloadedState);
-    delete camera;
+    // Service doesn't implement QVideoDeviceSelectorControl
+    provider->service = mockSimpleCameraService;
+
+    {
+        QCamera camera;
+        QCOMPARE(camera.availability(), QMultimedia::Available);
+        QCOMPARE(camera.error(), QCamera::NoError);
+    }
+
+    {
+        // Requesting a camera at a specific position from a service which doesn't implement
+        // the QVideoDeviceSelectorControl should result in loading the default camera
+        QCamera camera(QCamera::FrontFace);
+        QCOMPARE(camera.availability(), QMultimedia::Available);
+        QCOMPARE(camera.error(), QCamera::NoError);
+    }
+
+    // Service implements QVideoDeviceSelectorControl
+    provider->service = mockCameraService;
+
+    {
+        QCamera camera;
+        QCOMPARE(camera.availability(), QMultimedia::Available);
+        QCOMPARE(camera.error(), QCamera::NoError);
+        QCOMPARE(mockCameraService->mockVideoDeviceSelectorControl->selectedDevice(), 1); // default is 1
+    }
+
+    {
+        QCamera camera(QCameraInfo::defaultCamera());
+        QCOMPARE(camera.availability(), QMultimedia::Available);
+        QCOMPARE(camera.error(), QCamera::NoError);
+        QCOMPARE(mockCameraService->mockVideoDeviceSelectorControl->selectedDevice(), 1);
+        QCOMPARE(QCameraInfo(camera), QCameraInfo::defaultCamera());
+    }
+
+    {
+        QCameraInfo cameraInfo = QCameraInfo::availableCameras().at(0);
+        QCamera camera(cameraInfo);
+        QCOMPARE(camera.availability(), QMultimedia::Available);
+        QCOMPARE(camera.error(), QCamera::NoError);
+        QCOMPARE(mockCameraService->mockVideoDeviceSelectorControl->selectedDevice(), 0);
+        QCOMPARE(QCameraInfo(camera), cameraInfo);
+    }
+
+    {
+        // Requesting a camera at a position which is not available should result in
+        // loading the default camera
+        QCamera camera(QCamera::FrontFace);
+        QCOMPARE(camera.availability(), QMultimedia::Available);
+        QCOMPARE(camera.error(), QCamera::NoError);
+        QCOMPARE(mockCameraService->mockVideoDeviceSelectorControl->selectedDevice(), 1);
+    }
+
+    {
+        QCamera camera(QCamera::BackFace);
+        QCOMPARE(camera.availability(), QMultimedia::Available);
+        QCOMPARE(camera.error(), QCamera::NoError);
+        QCOMPARE(mockCameraService->mockVideoDeviceSelectorControl->selectedDevice(), 0);
+    }
+
+    {
+        // Should load the default camera when UnspecifiedPosition is requested
+        QCamera camera(QCamera::UnspecifiedPosition);
+        QCOMPARE(camera.availability(), QMultimedia::Available);
+        QCOMPARE(camera.error(), QCamera::NoError);
+        QCOMPARE(mockCameraService->mockVideoDeviceSelectorControl->selectedDevice(), 1);
+    }
 }
 
 /* captureModeChanged Signal test case. */
@@ -1530,6 +1595,7 @@ void tst_QCamera::testLockChangeReason()
     QVERIFY(LockChangeReason == QCamera::LockAcquired);
 
 }
+
 /* All the enums test case for QCameraControl class*/
 void tst_QCamera::testEnumsOfQCameraControl()
 {
diff --git a/tests/auto/unit/qcamerainfo/qcamerainfo.pro b/tests/auto/unit/qcamerainfo/qcamerainfo.pro
new file mode 100644 (file)
index 0000000..70cea2d
--- /dev/null
@@ -0,0 +1,10 @@
+CONFIG += testcase
+TARGET = tst_qcamerainfo
+
+QT += multimedia-private testlib
+
+include (../qmultimedia_common/mock.pri)
+include (../qmultimedia_common/mockcamera.pri)
+
+SOURCES += tst_qcamerainfo.cpp
+DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
diff --git a/tests/auto/unit/qcamerainfo/tst_qcamerainfo.cpp b/tests/auto/unit/qcamerainfo/tst_qcamerainfo.cpp
new file mode 100644 (file)
index 0000000..86bd05f
--- /dev/null
@@ -0,0 +1,217 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QDebug>
+
+#include <qcamera.h>
+#include <qcamerainfo.h>
+
+#include "mockcameraservice.h"
+#include "mockmediaserviceprovider.h"
+
+QT_USE_NAMESPACE
+
+class tst_QCameraInfo: public QObject
+{
+    Q_OBJECT
+
+public slots:
+    void initTestCase();
+    void init();
+    void cleanup();
+
+private slots:
+    void constructor();
+    void defaultCamera();
+    void availableCameras();
+    void equality_operators();
+
+private:
+    MockSimpleCameraService  *mockSimpleCameraService;
+    MockCameraService *mockCameraService;
+    MockMediaServiceProvider *provider;
+};
+
+void tst_QCameraInfo::initTestCase()
+{
+}
+
+void tst_QCameraInfo::init()
+{
+    provider = new MockMediaServiceProvider;
+    mockSimpleCameraService = new MockSimpleCameraService;
+    mockCameraService = new MockCameraService;
+
+    provider->service = mockCameraService;
+    QMediaServiceProvider::setDefaultServiceProvider(provider);
+}
+
+void tst_QCameraInfo::cleanup()
+{
+    delete provider;
+    delete mockCameraService;
+    delete mockSimpleCameraService;
+}
+
+void tst_QCameraInfo::constructor()
+{
+    // Service doesn't implement QVideoDeviceSelectorControl
+    // QCameraInfo should not be valid in this case
+    provider->service = mockSimpleCameraService;
+
+    {
+        QCamera camera;
+        QCameraInfo info(camera);
+        QVERIFY(info.isNull());
+        QVERIFY(info.deviceName().isEmpty());
+        QVERIFY(info.description().isEmpty());
+        QCOMPARE(info.position(), QCamera::UnspecifiedPosition);
+        QCOMPARE(info.orientation(), 0);
+    }
+
+    // Service implements QVideoDeviceSelectorControl
+    provider->service = mockCameraService;
+
+    {
+        // default camera
+        QCamera camera;
+        QCameraInfo info(camera);
+        QVERIFY(!info.isNull());
+        QCOMPARE(info.deviceName(), QStringLiteral("othercamera"));
+        QCOMPARE(info.description(), QStringLiteral("othercamera desc"));
+        QCOMPARE(info.position(), QCamera::UnspecifiedPosition);
+        QCOMPARE(info.orientation(), 0);
+    }
+
+    QCamera camera("backcamera");
+    QCameraInfo info(camera);
+    QVERIFY(!info.isNull());
+    QCOMPARE(info.deviceName(), QStringLiteral("backcamera"));
+    QCOMPARE(info.description(), QStringLiteral("backcamera desc"));
+    QCOMPARE(info.position(), QCamera::BackFace);
+    QCOMPARE(info.orientation(), 90);
+
+    QCameraInfo info2(info);
+    QVERIFY(!info2.isNull());
+    QCOMPARE(info2.deviceName(), QStringLiteral("backcamera"));
+    QCOMPARE(info2.description(), QStringLiteral("backcamera desc"));
+    QCOMPARE(info2.position(), QCamera::BackFace);
+    QCOMPARE(info2.orientation(), 90);
+}
+
+void tst_QCameraInfo::defaultCamera()
+{
+    provider->service = mockCameraService;
+
+    QCameraInfo info = QCameraInfo::defaultCamera();
+
+    QVERIFY(!info.isNull());
+    QCOMPARE(info.deviceName(), QStringLiteral("othercamera"));
+    QCOMPARE(info.description(), QStringLiteral("othercamera desc"));
+    QCOMPARE(info.position(), QCamera::UnspecifiedPosition);
+    QCOMPARE(info.orientation(), 0);
+
+    QCamera camera(info);
+    QCOMPARE(QCameraInfo(camera), info);
+}
+
+void tst_QCameraInfo::availableCameras()
+{
+    provider->service = mockCameraService;
+
+    QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
+    QCOMPARE(cameras.count(), 2);
+
+    QCameraInfo info = cameras.at(0);
+    QVERIFY(!info.isNull());
+    QCOMPARE(info.deviceName(), QStringLiteral("backcamera"));
+    QCOMPARE(info.description(), QStringLiteral("backcamera desc"));
+    QCOMPARE(info.position(), QCamera::BackFace);
+    QCOMPARE(info.orientation(), 90);
+
+    info = cameras.at(1);
+    QVERIFY(!info.isNull());
+    QCOMPARE(info.deviceName(), QStringLiteral("othercamera"));
+    QCOMPARE(info.description(), QStringLiteral("othercamera desc"));
+    QCOMPARE(info.position(), QCamera::UnspecifiedPosition);
+    QCOMPARE(info.orientation(), 0);
+
+    cameras = QCameraInfo::availableCameras(QCamera::BackFace);
+    QCOMPARE(cameras.count(), 1);
+    info = cameras.at(0);
+    QVERIFY(!info.isNull());
+    QCOMPARE(info.deviceName(), QStringLiteral("backcamera"));
+    QCOMPARE(info.description(), QStringLiteral("backcamera desc"));
+    QCOMPARE(info.position(), QCamera::BackFace);
+    QCOMPARE(info.orientation(), 90);
+
+    cameras = QCameraInfo::availableCameras(QCamera::FrontFace);
+    QCOMPARE(cameras.count(), 0);
+}
+
+void tst_QCameraInfo::equality_operators()
+{
+    provider->service = mockCameraService;
+
+    QCameraInfo defaultCamera = QCameraInfo::defaultCamera();
+    QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
+
+    QVERIFY(defaultCamera == cameras.at(1));
+    QVERIFY(defaultCamera != cameras.at(0));
+    QVERIFY(cameras.at(0) != cameras.at(1));
+
+    {
+        QCamera camera(defaultCamera);
+        QVERIFY(QCameraInfo(camera) == defaultCamera);
+        QVERIFY(QCameraInfo(camera) == cameras.at(1));
+    }
+
+    {
+        QCamera camera(cameras.at(0));
+        QVERIFY(QCameraInfo(camera) == cameras.at(0));
+    }
+}
+
+
+QTEST_MAIN(tst_QCameraInfo)
+
+#include "tst_qcamerainfo.moc"
index ba63ac3..b4469e7 100644 (file)
 #include "../mockservice.h"
 
 class MockServicePlugin1 : public QMediaServiceProviderPlugin,
-                           public QMediaServiceSupportedFormatsInterface,
-                           public QMediaServiceSupportedDevicesInterface
+                           public QMediaServiceSupportedFormatsInterface
 {
     Q_OBJECT
     Q_INTERFACES(QMediaServiceSupportedFormatsInterface)
-    Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
     Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "mockserviceplugin1.json")
 public:
     QStringList keys() const
@@ -87,21 +85,6 @@ public:
     {
         return QStringList("audio/ogg");
     }
-
-    QList<QByteArray> devices(const QByteArray &service) const
-    {
-        Q_UNUSED(service);
-        QList<QByteArray> res;
-        return res;
-    }
-
-    QString deviceDescription(const QByteArray &service, const QByteArray &device)
-    {
-        if (devices(service).contains(device))
-            return QString(device)+" description";
-        else
-            return QString();
-    }
 };
 
 #include "mockserviceplugin1.moc"
index fe7d492..592afde 100644 (file)
 #include "../mockservice.h"
 
 class MockServicePlugin3 : public QMediaServiceProviderPlugin,
-                            public QMediaServiceSupportedDevicesInterface
+                           public QMediaServiceSupportedDevicesInterface,
+                           public QMediaServiceDefaultDeviceInterface,
+                           public QMediaServiceCameraInfoInterface
 {
     Q_OBJECT
     Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
+    Q_INTERFACES(QMediaServiceDefaultDeviceInterface)
+    Q_INTERFACES(QMediaServiceCameraInfoInterface)
     Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "mockserviceplugin3.json")
 public:
     QStringList keys() const
     {
         return QStringList() <<
                QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER) <<
-               QLatin1String(Q_MEDIASERVICE_AUDIOSOURCE);
+               QLatin1String(Q_MEDIASERVICE_AUDIOSOURCE) <<
+               QLatin1String(Q_MEDIASERVICE_CAMERA);
     }
 
     QMediaService* create(QString const& key)
@@ -70,12 +75,26 @@ public:
         delete service;
     }
 
+    QByteArray defaultDevice(const QByteArray &service) const
+    {
+        if (service == Q_MEDIASERVICE_AUDIOSOURCE)
+            return "audiosource1";
+
+        if (service == Q_MEDIASERVICE_CAMERA)
+            return "frontcamera";
+
+        return QByteArray();
+    }
+
     QList<QByteArray> devices(const QByteArray &service) const
     {
         QList<QByteArray> res;
-        if (service == QByteArray(Q_MEDIASERVICE_AUDIOSOURCE))
+        if (service == Q_MEDIASERVICE_AUDIOSOURCE)
             res << "audiosource1" << "audiosource2";
 
+        if (service == Q_MEDIASERVICE_CAMERA)
+            res << "frontcamera";
+
         return res;
     }
 
@@ -86,6 +105,22 @@ public:
         else
             return QString();
     }
+
+    QCamera::Position cameraPosition(const QByteArray &device) const
+    {
+        if (device == "frontcamera")
+            return QCamera::FrontFace;
+
+        return QCamera::UnspecifiedPosition;
+    }
+
+    int cameraOrientation(const QByteArray &device) const
+    {
+        if (device == "frontcamera")
+            return 270;
+
+        return 0;
+    }
 };
 
 #include "mockserviceplugin3.moc"
index 591a02e..ab55b5d 100644 (file)
@@ -1,4 +1,4 @@
 {
     "Keys": ["mockserviceplugin3"],
-    "Services": ["org.qt-project.qt.mediaplayer", "org.qt-project.qt.audiosource"]
+    "Services": ["org.qt-project.qt.mediaplayer", "org.qt-project.qt.audiosource", "org.qt-project.qt.camera"]
 }
diff --git a/tests/auto/unit/qmediaserviceprovider/mockserviceplugin5/mockserviceplugin5.cpp b/tests/auto/unit/qmediaserviceprovider/mockserviceplugin5/mockserviceplugin5.cpp
new file mode 100644 (file)
index 0000000..c255914
--- /dev/null
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qmediaserviceproviderplugin.h>
+#include <qmediaservice.h>
+#include "../mockservice.h"
+
+class MockServicePlugin5 : public QMediaServiceProviderPlugin,
+                           public QMediaServiceSupportedDevicesInterface,
+                           public QMediaServiceDefaultDeviceInterface,
+                           public QMediaServiceCameraInfoInterface
+{
+    Q_OBJECT
+    Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
+    Q_INTERFACES(QMediaServiceDefaultDeviceInterface)
+    Q_INTERFACES(QMediaServiceCameraInfoInterface)
+    Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "mockserviceplugin5.json")
+public:
+    QStringList keys() const
+    {
+        return QStringList() << QLatin1String(Q_MEDIASERVICE_CAMERA);
+    }
+
+    QMediaService* create(QString const& key)
+    {
+        if (keys().contains(key))
+            return new MockMediaService("MockServicePlugin5");
+        else
+            return 0;
+    }
+
+    void release(QMediaService *service)
+    {
+        delete service;
+    }
+
+    QByteArray defaultDevice(const QByteArray &service) const
+    {
+        if (service == Q_MEDIASERVICE_CAMERA)
+            return "backcamera";
+
+        return QByteArray();
+    }
+
+    QList<QByteArray> devices(const QByteArray &service) const
+    {
+        QList<QByteArray> res;
+        if (service == Q_MEDIASERVICE_CAMERA)
+            res << "backcamera" << "somecamera";
+
+        return res;
+    }
+
+    QString deviceDescription(const QByteArray &service, const QByteArray &device)
+    {
+        if (devices(service).contains(device))
+            return QString(device)+" description";
+        else
+            return QString();
+    }
+
+    QCamera::Position cameraPosition(const QByteArray &device) const
+    {
+        if (device == "backcamera")
+            return QCamera::BackFace;
+
+        return QCamera::UnspecifiedPosition;
+    }
+
+    int cameraOrientation(const QByteArray &device) const
+    {
+        if (device == "backcamera")
+            return 90;
+
+        return 0;
+    }
+};
+
+#include "mockserviceplugin5.moc"
+
diff --git a/tests/auto/unit/qmediaserviceprovider/mockserviceplugin5/mockserviceplugin5.json b/tests/auto/unit/qmediaserviceprovider/mockserviceplugin5/mockserviceplugin5.json
new file mode 100644 (file)
index 0000000..cc6f481
--- /dev/null
@@ -0,0 +1,4 @@
+{
+    "Keys": ["mockserviceplugin5"],
+    "Services": ["org.qt-project.qt.camera"]
+}
diff --git a/tests/auto/unit/qmediaserviceprovider/mockserviceplugin5/mockserviceplugin5.pro b/tests/auto/unit/qmediaserviceprovider/mockserviceplugin5/mockserviceplugin5.pro
new file mode 100644 (file)
index 0000000..9657e3c
--- /dev/null
@@ -0,0 +1,23 @@
+TARGET = mockserviceplugin5
+QT += multimedia-private
+
+PLUGIN_TYPE=mediaservice
+PLUGIN_CLASS_NAME = MockServicePlugin5
+load(qt_plugin)
+
+DESTDIR = ../$${PLUGIN_TYPE}
+win32 {
+    CONFIG(debug, debug|release) {
+        DESTDIR = ../debug/$${PLUGIN_TYPE}
+    } else {
+        DESTDIR = ../release/$${PLUGIN_TYPE}
+    }
+}
+
+HEADERS += ../mockservice.h
+SOURCES += mockserviceplugin5.cpp
+OTHER_FILES += mockserviceplugin5.json
+
+target.path = $$[QT_INSTALL_TESTS]/tst_qmediaserviceprovider/$${PLUGIN_TYPE}
+
+DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
index dbe878f..cea19e2 100644 (file)
@@ -6,6 +6,7 @@ SUBDIRS += \
     mockserviceplugin2 \
     mockserviceplugin3 \
     mockserviceplugin4 \
+    mockserviceplugin5 \
     test
 
 # no special install rule for subdir
index e39070d..3ad7871 100644 (file)
@@ -52,6 +52,8 @@
 #include <qmediaservice.h>
 #include <qmediaplayer.h>
 #include <qaudiorecorder.h>
+#include <qcamera.h>
+#include <qcamerainfo.h>
 
 QT_USE_NAMESPACE
 
@@ -83,6 +85,9 @@ private slots:
     void testHasSupport();
     void testSupportedMimeTypes();
     void testProviderHints();
+    void testDefaultDevice();
+    void testAvailableDevices();
+    void testCameraInfo();
 
 private:
     QObjectList plugins;
@@ -195,6 +200,7 @@ void tst_QMediaServiceProvider::testProviderHints()
         QVERIFY(hint.isNull());
         QCOMPARE(hint.type(), QMediaServiceProviderHint::Null);
         QVERIFY(hint.device().isEmpty());
+        QCOMPARE(hint.cameraPosition(), QCamera::UnspecifiedPosition);
         QVERIFY(hint.mimeType().isEmpty());
         QVERIFY(hint.codecs().isEmpty());
         QCOMPARE(hint.features(), 0);
@@ -206,6 +212,18 @@ void tst_QMediaServiceProvider::testProviderHints()
         QVERIFY(!hint.isNull());
         QCOMPARE(hint.type(), QMediaServiceProviderHint::Device);
         QCOMPARE(hint.device(), deviceName);
+        QCOMPARE(hint.cameraPosition(), QCamera::UnspecifiedPosition);
+        QVERIFY(hint.mimeType().isEmpty());
+        QVERIFY(hint.codecs().isEmpty());
+        QCOMPARE(hint.features(), 0);
+    }
+
+    {
+        QMediaServiceProviderHint hint(QCamera::FrontFace);
+        QVERIFY(!hint.isNull());
+        QCOMPARE(hint.type(), QMediaServiceProviderHint::CameraPosition);
+        QVERIFY(hint.device().isEmpty());
+        QCOMPARE(hint.cameraPosition(), QCamera::FrontFace);
         QVERIFY(hint.mimeType().isEmpty());
         QVERIFY(hint.codecs().isEmpty());
         QCOMPARE(hint.features(), 0);
@@ -216,6 +234,7 @@ void tst_QMediaServiceProvider::testProviderHints()
         QVERIFY(!hint.isNull());
         QCOMPARE(hint.type(), QMediaServiceProviderHint::SupportedFeatures);
         QVERIFY(hint.device().isEmpty());
+        QCOMPARE(hint.cameraPosition(), QCamera::UnspecifiedPosition);
         QVERIFY(hint.mimeType().isEmpty());
         QVERIFY(hint.codecs().isEmpty());
         QCOMPARE(hint.features(), QMediaServiceProviderHint::LowLatencyPlayback);
@@ -226,6 +245,7 @@ void tst_QMediaServiceProvider::testProviderHints()
         QVERIFY(!hint.isNull());
         QCOMPARE(hint.type(), QMediaServiceProviderHint::SupportedFeatures);
         QVERIFY(hint.device().isEmpty());
+        QCOMPARE(hint.cameraPosition(), QCamera::UnspecifiedPosition);
         QVERIFY(hint.mimeType().isEmpty());
         QVERIFY(hint.codecs().isEmpty());
         QCOMPARE(hint.features(), QMediaServiceProviderHint::RecordingSupport);
@@ -240,6 +260,7 @@ void tst_QMediaServiceProvider::testProviderHints()
         QVERIFY(!hint.isNull());
         QCOMPARE(hint.type(), QMediaServiceProviderHint::ContentType);
         QVERIFY(hint.device().isEmpty());
+        QCOMPARE(hint.cameraPosition(), QCamera::UnspecifiedPosition);
         QCOMPARE(hint.mimeType(), mimeType);
         QCOMPARE(hint.codecs(), codecs);
 
@@ -248,6 +269,7 @@ void tst_QMediaServiceProvider::testProviderHints()
         QVERIFY(!hint2.isNull());
         QCOMPARE(hint2.type(), QMediaServiceProviderHint::ContentType);
         QVERIFY(hint2.device().isEmpty());
+        QCOMPARE(hint.cameraPosition(), QCamera::UnspecifiedPosition);
         QCOMPARE(hint2.mimeType(), mimeType);
         QCOMPARE(hint2.codecs(), codecs);
 
@@ -257,6 +279,7 @@ void tst_QMediaServiceProvider::testProviderHints()
         QVERIFY(!hint3.isNull());
         QCOMPARE(hint3.type(), QMediaServiceProviderHint::ContentType);
         QVERIFY(hint3.device().isEmpty());
+        QCOMPARE(hint.cameraPosition(), QCamera::UnspecifiedPosition);
         QCOMPARE(hint3.mimeType(), mimeType);
         QCOMPARE(hint3.codecs(), codecs);
 
@@ -271,6 +294,99 @@ void tst_QMediaServiceProvider::testProviderHints()
     }
 }
 
+void tst_QMediaServiceProvider::testDefaultDevice()
+{
+    QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider();
+
+    if (provider == 0)
+        QSKIP("No default provider");
+
+    QCOMPARE(provider->defaultDevice(Q_MEDIASERVICE_AUDIOSOURCE), QByteArray("audiosource1"));
+    QCOMPARE(provider->defaultDevice(Q_MEDIASERVICE_CAMERA), QByteArray("frontcamera"));
+}
+
+void tst_QMediaServiceProvider::testAvailableDevices()
+{
+    QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider();
+
+    if (provider == 0)
+        QSKIP("No default provider");
+
+    QList<QByteArray> devices = provider->devices(Q_MEDIASERVICE_AUDIOSOURCE);
+    QCOMPARE(devices.count(), 2);
+    QCOMPARE(devices.at(0), QByteArray("audiosource1"));
+    QCOMPARE(devices.at(1), QByteArray("audiosource2"));
+
+    devices = provider->devices(Q_MEDIASERVICE_CAMERA);
+    QCOMPARE(devices.count(), 3);
+    QCOMPARE(devices.at(0), QByteArray("frontcamera"));
+    QCOMPARE(devices.at(1), QByteArray("backcamera"));
+    QCOMPARE(devices.at(2), QByteArray("somecamera"));
+}
+
+void tst_QMediaServiceProvider::testCameraInfo()
+{
+    QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider();
+
+    if (provider == 0)
+        QSKIP("No default provider");
+
+    QCOMPARE(provider->cameraPosition("backcamera"), QCamera::BackFace);
+    QCOMPARE(provider->cameraOrientation("backcamera"), 90);
+    QCOMPARE(provider->cameraPosition("frontcamera"), QCamera::FrontFace);
+    QCOMPARE(provider->cameraOrientation("frontcamera"), 270);
+    QCOMPARE(provider->cameraPosition("somecamera"), QCamera::UnspecifiedPosition);
+    QCOMPARE(provider->cameraOrientation("somecamera"), 0);
+
+    {
+        QCamera camera;
+        QVERIFY(camera.service());
+        QCOMPARE(camera.service()->objectName(), QLatin1String("MockServicePlugin3"));
+    }
+
+    {
+        QCamera camera(QCameraInfo::defaultCamera());
+        QVERIFY(camera.service());
+        QCOMPARE(camera.service()->objectName(), QLatin1String("MockServicePlugin3"));
+    }
+
+    {
+        QCamera camera(QCameraInfo::availableCameras().at(0));
+        QVERIFY(camera.service());
+        QCOMPARE(camera.service()->objectName(), QLatin1String("MockServicePlugin3"));
+    }
+
+    {
+        QCamera camera(QCameraInfo::availableCameras().at(1));
+        QVERIFY(camera.service());
+        QCOMPARE(camera.service()->objectName(), QLatin1String("MockServicePlugin5"));
+    }
+
+    {
+        QCamera camera(QCameraInfo::availableCameras().at(2));
+        QVERIFY(camera.service());
+        QCOMPARE(camera.service()->objectName(), QLatin1String("MockServicePlugin5"));
+    }
+
+    {
+        QCamera camera(QCamera::FrontFace);
+        QVERIFY(camera.service());
+        QCOMPARE(camera.service()->objectName(), QLatin1String("MockServicePlugin3"));
+    }
+
+    {
+        QCamera camera(QCamera::BackFace);
+        QVERIFY(camera.service());
+        QCOMPARE(camera.service()->objectName(), QLatin1String("MockServicePlugin5"));
+    }
+
+    {
+        QCamera camera(QCamera::UnspecifiedPosition);
+        QVERIFY(camera.service());
+        QCOMPARE(camera.service()->objectName(), QLatin1String("MockServicePlugin3"));
+    }
+}
+
 QTEST_MAIN(tst_QMediaServiceProvider)
 
 #include "tst_qmediaserviceprovider.moc"
index 22a9dc1..c12ac3c 100644 (file)
@@ -17,6 +17,8 @@ HEADERS *= \
     ../qmultimedia_common/mockcameracapturebuffercontrol.h \
     ../qmultimedia_common/mockimageencodercontrol.h \
     ../qmultimedia_common/mockcameracontrol.h \
+    ../qmultimedia_common/mockvideodeviceselectorcontrol.h \
+    ../qmultimedia_common/mockcamerainfocontrol.h
 
 
 include(mockvideo.pri)
diff --git a/tests/auto/unit/qmultimedia_common/mockcamerainfocontrol.h b/tests/auto/unit/qmultimedia_common/mockcamerainfocontrol.h
new file mode 100644 (file)
index 0000000..65b29d4
--- /dev/null
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite 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 MOCKCAMERAINFOCONTROL_H
+#define MOCKCAMERAINFOCONTROL_H
+
+#include <qcamerainfocontrol.h>
+
+class MockCameraInfoControl : public QCameraInfoControl
+{
+    Q_OBJECT
+public:
+    MockCameraInfoControl(QObject *parent)
+        : QCameraInfoControl(parent)
+    {
+    }
+
+    ~MockCameraInfoControl() { }
+
+    QCamera::Position cameraPosition(const QString &deviceName) const
+    {
+        return position(deviceName.toLatin1());
+    }
+
+    int cameraOrientation(const QString &deviceName) const
+    {
+        return orientation(deviceName.toLatin1());
+    }
+
+    static QCamera::Position position(const QByteArray &camera)
+    {
+        if (camera == "backcamera")
+            return QCamera::BackFace;
+        else
+            return QCamera::UnspecifiedPosition;
+    }
+
+    static int orientation(const QByteArray &camera)
+    {
+        if (camera == "backcamera")
+            return 90;
+        else
+            return 0;
+    }
+};
+
+#endif // MOCKCAMERAINFOCONTROL_H
index 633b284..f12b0ea 100644 (file)
@@ -57,6 +57,8 @@
 #include "../qmultimedia_common/mockvideosurface.h"
 #include "../qmultimedia_common/mockvideorenderercontrol.h"
 #include "../qmultimedia_common/mockvideowindowcontrol.h"
+#include "../qmultimedia_common/mockvideodeviceselectorcontrol.h"
+#include "../qmultimedia_common/mockcamerainfocontrol.h"
 
 class MockSimpleCameraService : public QMediaService
 {
@@ -105,6 +107,8 @@ public:
         mockImageEncoderControl = new MockImageEncoderControl(this);
         rendererControl = new MockVideoRendererControl(this);
         windowControl = new MockVideoWindowControl(this);
+        mockVideoDeviceSelectorControl = new MockVideoDeviceSelectorControl(this);
+        mockCameraInfoControl = new MockCameraInfoControl(this);
         rendererRef = 0;
         windowRef = 0;
     }
@@ -148,6 +152,12 @@ public:
         if (qstrcmp(iid, QImageEncoderControl_iid) == 0)
             return mockImageEncoderControl;
 
+        if (qstrcmp(iid, QVideoDeviceSelectorControl_iid) == 0)
+            return mockVideoDeviceSelectorControl;
+
+        if (qstrcmp(iid, QCameraInfoControl_iid) == 0)
+            return mockCameraInfoControl;
+
         if (qstrcmp(iid, QVideoRendererControl_iid) == 0) {
             if (rendererRef == 0) {
                 rendererRef += 1;
@@ -184,6 +194,8 @@ public:
     MockImageEncoderControl *mockImageEncoderControl;
     MockVideoRendererControl *rendererControl;
     MockVideoWindowControl *windowControl;
+    MockVideoDeviceSelectorControl *mockVideoDeviceSelectorControl;
+    MockCameraInfoControl *mockCameraInfoControl;
     int rendererRef;
     int windowRef;
 };
index d582ea3..6bf221c 100644 (file)
@@ -44,6 +44,8 @@
 
 #include "private/qmediaserviceprovider_p.h"
 #include "qmediaservice.h"
+#include "mockvideodeviceselectorcontrol.h"
+#include "mockcamerainfocontrol.h"
 
 // Simple provider that lets you set the service
 class MockMediaServiceProvider : public QMediaServiceProvider
@@ -67,6 +69,40 @@ public:
         }
     }
 
+    QByteArray defaultDevice(const QByteArray &serviceType) const
+    {
+        if (serviceType == Q_MEDIASERVICE_CAMERA)
+            return MockVideoDeviceSelectorControl::defaultCamera();
+
+        return QByteArray();
+    }
+
+    QList<QByteArray> devices(const QByteArray &serviceType) const
+    {
+        if (serviceType == Q_MEDIASERVICE_CAMERA)
+            return MockVideoDeviceSelectorControl::availableCameras();
+
+        return QList<QByteArray>();
+    }
+
+    QString deviceDescription(const QByteArray &serviceType, const QByteArray &device)
+    {
+        if (serviceType == Q_MEDIASERVICE_CAMERA)
+            return MockVideoDeviceSelectorControl::cameraDescription(device);
+
+        return QString();
+    }
+
+    QCamera::Position cameraPosition(const QByteArray &device) const
+    {
+        return MockCameraInfoControl::position(device);
+    }
+
+    int cameraOrientation(const QByteArray &device) const
+    {
+        return MockCameraInfoControl::orientation(device);
+    }
+
     QMediaService *service;
     bool deleteServiceOnRelease;
 };
diff --git a/tests/auto/unit/qmultimedia_common/mockvideodeviceselectorcontrol.h b/tests/auto/unit/qmultimedia_common/mockvideodeviceselectorcontrol.h
new file mode 100644 (file)
index 0000000..04aec6f
--- /dev/null
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite 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 MOCKVIDEODEVICESELECTORCONTROL_H
+#define MOCKVIDEODEVICESELECTORCONTROL_H
+
+#include <qvideodeviceselectorcontrol.h>
+
+class MockVideoDeviceSelectorControl : public QVideoDeviceSelectorControl
+{
+    Q_OBJECT
+public:
+    MockVideoDeviceSelectorControl(QObject *parent)
+        : QVideoDeviceSelectorControl(parent)
+        , m_selectedDevice(1)
+    {
+    }
+
+    ~MockVideoDeviceSelectorControl() { }
+
+    int deviceCount() const { return availableCameras().count(); }
+
+    QString deviceName(int index) const { return QString::fromLatin1(availableCameras().at(index)); }
+    QString deviceDescription(int index) const { return cameraDescription(availableCameras().at(index)); }
+
+    int defaultDevice() const { return availableCameras().indexOf(defaultCamera()); }
+    int selectedDevice() const { return m_selectedDevice; }
+    void setSelectedDevice(int index)
+    {
+        m_selectedDevice = index;
+        emit selectedDeviceChanged(m_selectedDevice);
+        emit selectedDeviceChanged(deviceName(m_selectedDevice));
+    }
+
+    static QByteArray defaultCamera()
+    {
+        return "othercamera";
+    }
+
+    static QList<QByteArray> availableCameras()
+    {
+        return QList<QByteArray>() << "backcamera" << "othercamera";
+    }
+
+    static QString cameraDescription(const QByteArray &camera)
+    {
+        if (camera == "backcamera")
+            return QStringLiteral("backcamera desc");
+        else if (camera == "othercamera")
+            return QStringLiteral("othercamera desc");
+        else
+            return QString();
+    }
+
+private:
+    int m_selectedDevice;
+    QStringList m_devices;
+    QStringList m_descriptions;
+};
+
+#endif // MOCKVIDEODEVICESELECTORCONTROL_H