New QCameraInfo class.
The class allows to get the list of available cameras on the system as well as getting some static information about them such as their unique ID, display name, physical position and sensor orientation. This makes QCamera::availableDevices() and QCamera::deviceDescription() obsolete. This patch contains the API, documentation and auto-tests but not the actual implementation by each backend (except for retrieving the default camera device). [ChangeLog][QtMultimedia] Added new QCameraInfo class [ChangeLog][QtMultimedia] QCamera: availableDevices() and deviceDescription() are deprecated, use QCameraInfo instead Change-Id: I64fd65729ab26a789468979ed5444ee90bb82cd0 Reviewed-by: Christian Stromme <christian.stromme@digia.com>
This commit is contained in:
committed by
The Qt Project
parent
d964388b38
commit
b28ee24628
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -80,6 +80,7 @@ private:
|
||||
|
||||
int m_selectedDevice;
|
||||
bool m_dirty;
|
||||
int m_defaultDevice;
|
||||
QStringList m_devices;
|
||||
QStringList m_deviceDescriptions;
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user