summaryrefslogtreecommitdiffstats
path: root/src/plugins/avfoundation
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@digia.com>2014-01-22 16:18:42 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-28 14:10:00 +0100
commitb28ee24628f77fced393cacc45500be6761e4497 (patch)
tree811173f8a2caf84e0fa386010283ccfd32c6ad0d /src/plugins/avfoundation
parentd964388b38ec4762e315d86aacb779604bcdca1b (diff)
New QCameraInfo class.
The class allows to get the list of available cameras on the system as well as getting some static information about them such as their unique ID, display name, physical position and sensor orientation. This makes QCamera::availableDevices() and QCamera::deviceDescription() obsolete. This patch contains the API, documentation and auto-tests but not the actual implementation by each backend (except for retrieving the default camera device). [ChangeLog][QtMultimedia] Added new QCameraInfo class [ChangeLog][QtMultimedia] QCamera: availableDevices() and deviceDescription() are deprecated, use QCameraInfo instead Change-Id: I64fd65729ab26a789468979ed5444ee90bb82cd0 Reviewed-by: Christian Stromme <christian.stromme@digia.com>
Diffstat (limited to 'src/plugins/avfoundation')
-rw-r--r--src/plugins/avfoundation/camera/avfcameraserviceplugin.h6
-rw-r--r--src/plugins/avfoundation/camera/avfcameraserviceplugin.mm17
-rw-r--r--src/plugins/avfoundation/camera/avfvideodevicecontrol.h1
-rw-r--r--src/plugins/avfoundation/camera/avfvideodevicecontrol.mm8
4 files changed, 30 insertions, 2 deletions
diff --git a/src/plugins/avfoundation/camera/avfcameraserviceplugin.h b/src/plugins/avfoundation/camera/avfcameraserviceplugin.h
index 34130ffcb..f974bcf0b 100644
--- a/src/plugins/avfoundation/camera/avfcameraserviceplugin.h
+++ b/src/plugins/avfoundation/camera/avfcameraserviceplugin.h
@@ -49,10 +49,12 @@
QT_BEGIN_NAMESPACE
class AVFServicePlugin : public QMediaServiceProviderPlugin,
- public QMediaServiceSupportedDevicesInterface
+ public QMediaServiceSupportedDevicesInterface,
+ public QMediaServiceDefaultDeviceInterface
{
Q_OBJECT
Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
+ Q_INTERFACES(QMediaServiceDefaultDeviceInterface)
Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "avfcamera.json")
public:
@@ -61,12 +63,14 @@ public:
QMediaService* create(QString const& key);
void release(QMediaService *service);
+ QByteArray defaultDevice(const QByteArray &service) const;
QList<QByteArray> devices(const QByteArray &service) const;
QString deviceDescription(const QByteArray &service, const QByteArray &device);
private:
void updateDevices() const;
+ mutable QByteArray m_defaultCameraDevice;
mutable QList<QByteArray> m_cameraDevices;
mutable QMap<QByteArray, QString> m_cameraDescriptions;
};
diff --git a/src/plugins/avfoundation/camera/avfcameraserviceplugin.mm b/src/plugins/avfoundation/camera/avfcameraserviceplugin.mm
index 19e4e7975..8ec3390e9 100644
--- a/src/plugins/avfoundation/camera/avfcameraserviceplugin.mm
+++ b/src/plugins/avfoundation/camera/avfcameraserviceplugin.mm
@@ -72,6 +72,18 @@ void AVFServicePlugin::release(QMediaService *service)
delete service;
}
+QByteArray AVFServicePlugin::defaultDevice(const QByteArray &service) const
+{
+ if (service == Q_MEDIASERVICE_CAMERA) {
+ if (m_cameraDevices.isEmpty())
+ updateDevices();
+
+ return m_defaultCameraDevice;
+ }
+
+ return QByteArray();
+}
+
QList<QByteArray> AVFServicePlugin::devices(const QByteArray &service) const
{
if (service == Q_MEDIASERVICE_CAMERA) {
@@ -98,9 +110,14 @@ QString AVFServicePlugin::deviceDescription(const QByteArray &service, const QBy
void AVFServicePlugin::updateDevices() const
{
+ m_defaultCameraDevice.clear();
m_cameraDevices.clear();
m_cameraDescriptions.clear();
+ AVCaptureDevice *defaultDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
+ if (defaultDevice)
+ m_defaultCameraDevice = QByteArray([[defaultDevice uniqueID] UTF8String]);
+
NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in videoDevices) {
QByteArray deviceId([[device uniqueID] UTF8String]);
diff --git a/src/plugins/avfoundation/camera/avfvideodevicecontrol.h b/src/plugins/avfoundation/camera/avfvideodevicecontrol.h
index 2fc376e27..fe27906cf 100644
--- a/src/plugins/avfoundation/camera/avfvideodevicecontrol.h
+++ b/src/plugins/avfoundation/camera/avfvideodevicecontrol.h
@@ -80,6 +80,7 @@ private:
int m_selectedDevice;
bool m_dirty;
+ int m_defaultDevice;
QStringList m_devices;
QStringList m_deviceDescriptions;
};
diff --git a/src/plugins/avfoundation/camera/avfvideodevicecontrol.mm b/src/plugins/avfoundation/camera/avfvideodevicecontrol.mm
index 3c8e39c0e..776707549 100644
--- a/src/plugins/avfoundation/camera/avfvideodevicecontrol.mm
+++ b/src/plugins/avfoundation/camera/avfvideodevicecontrol.mm
@@ -50,11 +50,17 @@ AVFVideoDeviceControl::AVFVideoDeviceControl(AVFCameraService *service, QObject
, m_service(service)
, m_selectedDevice(0)
, m_dirty(true)
+ , m_defaultDevice(0)
{
+ AVCaptureDevice *defaultDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
+ int i = 0;
for (AVCaptureDevice *device in videoDevices) {
m_devices << QString::fromUtf8([[device uniqueID] UTF8String]);
m_deviceDescriptions << QString::fromUtf8([[device localizedName] UTF8String]);
+ if (defaultDevice && [[device uniqueID] isEqualToString:[defaultDevice uniqueID]])
+ m_defaultDevice = i;
+ ++i;
}
}
@@ -79,7 +85,7 @@ QString AVFVideoDeviceControl::deviceDescription(int index) const
int AVFVideoDeviceControl::defaultDevice() const
{
- return 0;
+ return m_defaultDevice;
}
int AVFVideoDeviceControl::selectedDevice() const