AVFoundation: implement QCameraInfoControl.
Change-Id: I05f3daa5c4acb90e046e26d6d577ae40dfed0e30 Reviewed-by: Andy Nichols <andy.nichols@digia.com>
This commit is contained in:
committed by
The Qt Project
parent
70415c3d97
commit
9a55f5ce57
61
src/plugins/avfoundation/camera/avfcamerainfocontrol.h
Normal file
61
src/plugins/avfoundation/camera/avfcamerainfocontrol.h
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 AVFCAMERAINFOCONTROL_H
|
||||||
|
#define AVFCAMERAINFOCONTROL_H
|
||||||
|
|
||||||
|
#include <qcamerainfocontrol.h>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
class AVFCameraInfoControl : public QCameraInfoControl
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit AVFCameraInfoControl(QObject *parent = 0);
|
||||||
|
|
||||||
|
QCamera::Position cameraPosition(const QString &deviceName) const;
|
||||||
|
int cameraOrientation(const QString &deviceName) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // AVFCAMERAINFOCONTROL_H
|
||||||
62
src/plugins/avfoundation/camera/avfcamerainfocontrol.mm
Normal file
62
src/plugins/avfoundation/camera/avfcamerainfocontrol.mm
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 "avfcamerainfocontrol.h"
|
||||||
|
#include "avfcamerasession.h"
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
AVFCameraInfoControl::AVFCameraInfoControl(QObject *parent)
|
||||||
|
: QCameraInfoControl(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QCamera::Position AVFCameraInfoControl::cameraPosition(const QString &deviceName) const
|
||||||
|
{
|
||||||
|
return AVFCameraSession::cameraDeviceInfo(deviceName.toUtf8()).position;
|
||||||
|
}
|
||||||
|
|
||||||
|
int AVFCameraInfoControl::cameraOrientation(const QString &deviceName) const
|
||||||
|
{
|
||||||
|
return AVFCameraSession::cameraDeviceInfo(deviceName.toUtf8()).orientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
QT_END_NAMESPACE
|
||||||
@@ -50,6 +50,7 @@
|
|||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QCameraControl;
|
class QCameraControl;
|
||||||
class AVFCameraControl;
|
class AVFCameraControl;
|
||||||
|
class AVFCameraInfoControl;
|
||||||
class AVFCameraMetaDataControl;
|
class AVFCameraMetaDataControl;
|
||||||
class AVFVideoWindowControl;
|
class AVFVideoWindowControl;
|
||||||
class AVFVideoWidgetControl;
|
class AVFVideoWidgetControl;
|
||||||
@@ -82,6 +83,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
AVFCameraSession *m_session;
|
AVFCameraSession *m_session;
|
||||||
AVFCameraControl *m_cameraControl;
|
AVFCameraControl *m_cameraControl;
|
||||||
|
AVFCameraInfoControl *m_cameraInfoControl;
|
||||||
AVFVideoDeviceControl *m_videoDeviceControl;
|
AVFVideoDeviceControl *m_videoDeviceControl;
|
||||||
AVFAudioInputSelectorControl *m_audioInputSelectorControl;
|
AVFAudioInputSelectorControl *m_audioInputSelectorControl;
|
||||||
AVFVideoRendererControl *m_videoOutput;
|
AVFVideoRendererControl *m_videoOutput;
|
||||||
|
|||||||
@@ -44,6 +44,7 @@
|
|||||||
|
|
||||||
#include "avfcameraservice.h"
|
#include "avfcameraservice.h"
|
||||||
#include "avfcameracontrol.h"
|
#include "avfcameracontrol.h"
|
||||||
|
#include "avfcamerainfocontrol.h"
|
||||||
#include "avfcamerasession.h"
|
#include "avfcamerasession.h"
|
||||||
#include "avfvideodevicecontrol.h"
|
#include "avfvideodevicecontrol.h"
|
||||||
#include "avfaudioinputselectorcontrol.h"
|
#include "avfaudioinputselectorcontrol.h"
|
||||||
@@ -65,6 +66,7 @@ AVFCameraService::AVFCameraService(QObject *parent):
|
|||||||
{
|
{
|
||||||
m_session = new AVFCameraSession(this);
|
m_session = new AVFCameraSession(this);
|
||||||
m_cameraControl = new AVFCameraControl(this);
|
m_cameraControl = new AVFCameraControl(this);
|
||||||
|
m_cameraInfoControl = new AVFCameraInfoControl(this);
|
||||||
m_videoDeviceControl = new AVFVideoDeviceControl(this);
|
m_videoDeviceControl = new AVFVideoDeviceControl(this);
|
||||||
m_audioInputSelectorControl = new AVFAudioInputSelectorControl(this);
|
m_audioInputSelectorControl = new AVFAudioInputSelectorControl(this);
|
||||||
|
|
||||||
@@ -98,6 +100,9 @@ QMediaControl *AVFCameraService::requestControl(const char *name)
|
|||||||
if (qstrcmp(name, QCameraControl_iid) == 0)
|
if (qstrcmp(name, QCameraControl_iid) == 0)
|
||||||
return m_cameraControl;
|
return m_cameraControl;
|
||||||
|
|
||||||
|
if (qstrcmp(name, QCameraInfoControl_iid) == 0)
|
||||||
|
return m_cameraInfoControl;
|
||||||
|
|
||||||
if (qstrcmp(name, QVideoDeviceSelectorControl_iid) == 0)
|
if (qstrcmp(name, QVideoDeviceSelectorControl_iid) == 0)
|
||||||
return m_videoDeviceControl;
|
return m_videoDeviceControl;
|
||||||
|
|
||||||
|
|||||||
@@ -50,11 +50,13 @@ QT_BEGIN_NAMESPACE
|
|||||||
|
|
||||||
class AVFServicePlugin : public QMediaServiceProviderPlugin,
|
class AVFServicePlugin : public QMediaServiceProviderPlugin,
|
||||||
public QMediaServiceSupportedDevicesInterface,
|
public QMediaServiceSupportedDevicesInterface,
|
||||||
public QMediaServiceDefaultDeviceInterface
|
public QMediaServiceDefaultDeviceInterface,
|
||||||
|
public QMediaServiceCameraInfoInterface
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
|
Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
|
||||||
Q_INTERFACES(QMediaServiceDefaultDeviceInterface)
|
Q_INTERFACES(QMediaServiceDefaultDeviceInterface)
|
||||||
|
Q_INTERFACES(QMediaServiceCameraInfoInterface)
|
||||||
Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "avfcamera.json")
|
Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "avfcamera.json")
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -67,12 +69,8 @@ public:
|
|||||||
QList<QByteArray> devices(const QByteArray &service) const;
|
QList<QByteArray> devices(const QByteArray &service) const;
|
||||||
QString deviceDescription(const QByteArray &service, const QByteArray &device);
|
QString deviceDescription(const QByteArray &service, const QByteArray &device);
|
||||||
|
|
||||||
private:
|
QCamera::Position cameraPosition(const QByteArray &device) const;
|
||||||
void updateDevices() const;
|
int cameraOrientation(const QByteArray &device) const;
|
||||||
|
|
||||||
mutable QByteArray m_defaultCameraDevice;
|
|
||||||
mutable QList<QByteArray> m_cameraDevices;
|
|
||||||
mutable QMap<QByteArray, QString> m_cameraDescriptions;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|||||||
@@ -44,15 +44,12 @@
|
|||||||
|
|
||||||
#include "avfcameraserviceplugin.h"
|
#include "avfcameraserviceplugin.h"
|
||||||
#include "avfcameraservice.h"
|
#include "avfcameraservice.h"
|
||||||
|
#include "avfcamerasession.h"
|
||||||
|
|
||||||
#include <qmediaserviceproviderplugin.h>
|
#include <qmediaserviceproviderplugin.h>
|
||||||
|
|
||||||
#import <AVFoundation/AVFoundation.h>
|
|
||||||
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
|
||||||
AVFServicePlugin::AVFServicePlugin()
|
AVFServicePlugin::AVFServicePlugin()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -74,56 +71,36 @@ void AVFServicePlugin::release(QMediaService *service)
|
|||||||
|
|
||||||
QByteArray AVFServicePlugin::defaultDevice(const QByteArray &service) const
|
QByteArray AVFServicePlugin::defaultDevice(const QByteArray &service) const
|
||||||
{
|
{
|
||||||
if (service == Q_MEDIASERVICE_CAMERA) {
|
if (service == Q_MEDIASERVICE_CAMERA)
|
||||||
if (m_cameraDevices.isEmpty())
|
return AVFCameraSession::defaultCameraDevice();
|
||||||
updateDevices();
|
|
||||||
|
|
||||||
return m_defaultCameraDevice;
|
|
||||||
}
|
|
||||||
|
|
||||||
return QByteArray();
|
return QByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QByteArray> AVFServicePlugin::devices(const QByteArray &service) const
|
QList<QByteArray> AVFServicePlugin::devices(const QByteArray &service) const
|
||||||
{
|
{
|
||||||
if (service == Q_MEDIASERVICE_CAMERA) {
|
if (service == Q_MEDIASERVICE_CAMERA)
|
||||||
if (m_cameraDevices.isEmpty())
|
return AVFCameraSession::availableCameraDevices();
|
||||||
updateDevices();
|
|
||||||
|
|
||||||
return m_cameraDevices;
|
|
||||||
}
|
|
||||||
|
|
||||||
return QList<QByteArray>();
|
return QList<QByteArray>();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString AVFServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device)
|
QString AVFServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device)
|
||||||
{
|
{
|
||||||
if (service == Q_MEDIASERVICE_CAMERA) {
|
if (service == Q_MEDIASERVICE_CAMERA)
|
||||||
if (m_cameraDevices.isEmpty())
|
return AVFCameraSession::cameraDeviceInfo(device).description;
|
||||||
updateDevices();
|
|
||||||
|
|
||||||
return m_cameraDescriptions.value(device);
|
|
||||||
}
|
|
||||||
|
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AVFServicePlugin::updateDevices() const
|
QCamera::Position AVFServicePlugin::cameraPosition(const QByteArray &device) const
|
||||||
{
|
{
|
||||||
m_defaultCameraDevice.clear();
|
return AVFCameraSession::cameraDeviceInfo(device).position;
|
||||||
m_cameraDevices.clear();
|
}
|
||||||
m_cameraDescriptions.clear();
|
|
||||||
|
|
||||||
AVCaptureDevice *defaultDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
|
int AVFServicePlugin::cameraOrientation(const QByteArray &device) const
|
||||||
if (defaultDevice)
|
{
|
||||||
m_defaultCameraDevice = QByteArray([[defaultDevice uniqueID] UTF8String]);
|
return AVFCameraSession::cameraDeviceInfo(device).orientation;
|
||||||
|
|
||||||
NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
|
|
||||||
for (AVCaptureDevice *device in videoDevices) {
|
|
||||||
QByteArray deviceId([[device uniqueID] UTF8String]);
|
|
||||||
m_cameraDevices << deviceId;
|
|
||||||
m_cameraDescriptions.insert(deviceId, QString::fromUtf8([[device localizedName] UTF8String]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|||||||
@@ -55,6 +55,16 @@ class AVFCameraControl;
|
|||||||
class AVFCameraService;
|
class AVFCameraService;
|
||||||
class AVFVideoRendererControl;
|
class AVFVideoRendererControl;
|
||||||
|
|
||||||
|
struct AVFCameraInfo
|
||||||
|
{
|
||||||
|
AVFCameraInfo() : position(QCamera::UnspecifiedPosition), orientation(0)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
QString description;
|
||||||
|
QCamera::Position position;
|
||||||
|
int orientation;
|
||||||
|
};
|
||||||
|
|
||||||
class AVFCameraSession : public QObject
|
class AVFCameraSession : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -62,6 +72,10 @@ public:
|
|||||||
AVFCameraSession(AVFCameraService *service, QObject *parent = 0);
|
AVFCameraSession(AVFCameraService *service, QObject *parent = 0);
|
||||||
~AVFCameraSession();
|
~AVFCameraSession();
|
||||||
|
|
||||||
|
static const QByteArray &defaultCameraDevice();
|
||||||
|
static const QList<QByteArray> &availableCameraDevices();
|
||||||
|
static AVFCameraInfo cameraDeviceInfo(const QByteArray &device);
|
||||||
|
|
||||||
void setVideoOutput(AVFVideoRendererControl *output);
|
void setVideoOutput(AVFVideoRendererControl *output);
|
||||||
AVCaptureSession *captureSession() const { return m_captureSession; }
|
AVCaptureSession *captureSession() const { return m_captureSession; }
|
||||||
AVCaptureDevice *videoCaptureDevice() const;
|
AVCaptureDevice *videoCaptureDevice() const;
|
||||||
@@ -84,8 +98,13 @@ Q_SIGNALS:
|
|||||||
void error(int error, const QString &errorString);
|
void error(int error, const QString &errorString);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static void updateCameraDevices();
|
||||||
void attachInputDevices();
|
void attachInputDevices();
|
||||||
|
|
||||||
|
static QByteArray m_defaultCameraDevice;
|
||||||
|
static QList<QByteArray> m_cameraDevices;
|
||||||
|
static QMap<QByteArray, AVFCameraInfo> m_cameraInfo;
|
||||||
|
|
||||||
AVFCameraService *m_service;
|
AVFCameraService *m_service;
|
||||||
AVFVideoRendererControl *m_videoOutput;
|
AVFVideoRendererControl *m_videoOutput;
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,10 @@
|
|||||||
|
|
||||||
QT_USE_NAMESPACE
|
QT_USE_NAMESPACE
|
||||||
|
|
||||||
|
QByteArray AVFCameraSession::m_defaultCameraDevice;
|
||||||
|
QList<QByteArray> AVFCameraSession::m_cameraDevices;
|
||||||
|
QMap<QByteArray, AVFCameraInfo> AVFCameraSession::m_cameraInfo;
|
||||||
|
|
||||||
@interface AVFCameraSessionObserver : NSObject
|
@interface AVFCameraSessionObserver : NSObject
|
||||||
{
|
{
|
||||||
@private
|
@private
|
||||||
@@ -151,6 +155,74 @@ AVFCameraSession::~AVFCameraSession()
|
|||||||
[m_captureSession release];
|
[m_captureSession release];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QByteArray &AVFCameraSession::defaultCameraDevice()
|
||||||
|
{
|
||||||
|
if (m_cameraDevices.isEmpty())
|
||||||
|
updateCameraDevices();
|
||||||
|
|
||||||
|
return m_defaultCameraDevice;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QList<QByteArray> &AVFCameraSession::availableCameraDevices()
|
||||||
|
{
|
||||||
|
if (m_cameraDevices.isEmpty())
|
||||||
|
updateCameraDevices();
|
||||||
|
|
||||||
|
return m_cameraDevices;
|
||||||
|
}
|
||||||
|
|
||||||
|
AVFCameraInfo AVFCameraSession::cameraDeviceInfo(const QByteArray &device)
|
||||||
|
{
|
||||||
|
if (m_cameraDevices.isEmpty())
|
||||||
|
updateCameraDevices();
|
||||||
|
|
||||||
|
return m_cameraInfo.value(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AVFCameraSession::updateCameraDevices()
|
||||||
|
{
|
||||||
|
m_defaultCameraDevice.clear();
|
||||||
|
m_cameraDevices.clear();
|
||||||
|
m_cameraInfo.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]);
|
||||||
|
|
||||||
|
AVFCameraInfo info;
|
||||||
|
info.description = QString::fromNSString([device localizedName]);
|
||||||
|
|
||||||
|
// There is no API to get the camera sensor orientation, however, cameras are always
|
||||||
|
// mounted in landscape on iDevices.
|
||||||
|
// - Back-facing cameras have the top side of the sensor aligned with the right side of
|
||||||
|
// the screen when held in portrait ==> 270 degrees clockwise angle
|
||||||
|
// - Front-facing cameras have the top side of the sensor aligned with the left side of
|
||||||
|
// the screen when held in portrait ==> 270 degrees clockwise angle
|
||||||
|
// On Mac OS, the position will always be unspecified and the sensor orientation unknown.
|
||||||
|
switch (device.position) {
|
||||||
|
case AVCaptureDevicePositionBack:
|
||||||
|
info.position = QCamera::BackFace;
|
||||||
|
info.orientation = 270;
|
||||||
|
break;
|
||||||
|
case AVCaptureDevicePositionFront:
|
||||||
|
info.position = QCamera::FrontFace;
|
||||||
|
info.orientation = 270;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
info.position = QCamera::UnspecifiedPosition;
|
||||||
|
info.orientation = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_cameraDevices << deviceId;
|
||||||
|
m_cameraInfo.insert(deviceId, info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AVFCameraSession::setVideoOutput(AVFVideoRendererControl *output)
|
void AVFCameraSession::setVideoOutput(AVFVideoRendererControl *output)
|
||||||
{
|
{
|
||||||
m_videoOutput = output;
|
m_videoOutput = output;
|
||||||
|
|||||||
@@ -80,9 +80,6 @@ private:
|
|||||||
|
|
||||||
int m_selectedDevice;
|
int m_selectedDevice;
|
||||||
bool m_dirty;
|
bool m_dirty;
|
||||||
int m_defaultDevice;
|
|
||||||
QStringList m_devices;
|
|
||||||
QStringList m_deviceDescriptions;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
#include "avfcameradebug.h"
|
#include "avfcameradebug.h"
|
||||||
#include "avfvideodevicecontrol.h"
|
#include "avfvideodevicecontrol.h"
|
||||||
#include "avfcameraservice.h"
|
#include "avfcameraservice.h"
|
||||||
|
#include "avfcamerasession.h"
|
||||||
|
|
||||||
QT_USE_NAMESPACE
|
QT_USE_NAMESPACE
|
||||||
|
|
||||||
@@ -50,18 +51,7 @@ AVFVideoDeviceControl::AVFVideoDeviceControl(AVFCameraService *service, QObject
|
|||||||
, m_service(service)
|
, m_service(service)
|
||||||
, m_selectedDevice(0)
|
, m_selectedDevice(0)
|
||||||
, m_dirty(true)
|
, 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AVFVideoDeviceControl::~AVFVideoDeviceControl()
|
AVFVideoDeviceControl::~AVFVideoDeviceControl()
|
||||||
@@ -70,22 +60,30 @@ AVFVideoDeviceControl::~AVFVideoDeviceControl()
|
|||||||
|
|
||||||
int AVFVideoDeviceControl::deviceCount() const
|
int AVFVideoDeviceControl::deviceCount() const
|
||||||
{
|
{
|
||||||
return m_devices.size();
|
return AVFCameraSession::availableCameraDevices().count();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString AVFVideoDeviceControl::deviceName(int index) const
|
QString AVFVideoDeviceControl::deviceName(int index) const
|
||||||
{
|
{
|
||||||
return m_devices[index];
|
const QList<QByteArray> &devices = AVFCameraSession::availableCameraDevices();
|
||||||
|
if (index >= devices.count())
|
||||||
|
return QString();
|
||||||
|
|
||||||
|
return QString::fromUtf8(devices.at(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString AVFVideoDeviceControl::deviceDescription(int index) const
|
QString AVFVideoDeviceControl::deviceDescription(int index) const
|
||||||
{
|
{
|
||||||
return m_deviceDescriptions[index];
|
const QList<QByteArray> &devices = AVFCameraSession::availableCameraDevices();
|
||||||
|
if (index >= devices.count())
|
||||||
|
return QString();
|
||||||
|
|
||||||
|
return AVFCameraSession::cameraDeviceInfo(devices.at(index)).description;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AVFVideoDeviceControl::defaultDevice() const
|
int AVFVideoDeviceControl::defaultDevice() const
|
||||||
{
|
{
|
||||||
return m_defaultDevice;
|
return AVFCameraSession::availableCameraDevices().indexOf(AVFCameraSession::defaultCameraDevice());
|
||||||
}
|
}
|
||||||
|
|
||||||
int AVFVideoDeviceControl::selectedDevice() const
|
int AVFVideoDeviceControl::selectedDevice() const
|
||||||
@@ -99,7 +97,7 @@ void AVFVideoDeviceControl::setSelectedDevice(int index)
|
|||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
m_selectedDevice = index;
|
m_selectedDevice = index;
|
||||||
Q_EMIT selectedDeviceChanged(index);
|
Q_EMIT selectedDeviceChanged(index);
|
||||||
Q_EMIT selectedDeviceChanged(m_devices[index]);
|
Q_EMIT selectedDeviceChanged(deviceName(index));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,9 +106,8 @@ AVCaptureDevice *AVFVideoDeviceControl::createCaptureDevice()
|
|||||||
m_dirty = false;
|
m_dirty = false;
|
||||||
AVCaptureDevice *device = 0;
|
AVCaptureDevice *device = 0;
|
||||||
|
|
||||||
if (!m_devices.isEmpty()) {
|
QString deviceId = deviceName(m_selectedDevice);
|
||||||
QString deviceId = m_devices.at(m_selectedDevice);
|
if (!deviceId.isEmpty()) {
|
||||||
|
|
||||||
device = [AVCaptureDevice deviceWithUniqueID:
|
device = [AVCaptureDevice deviceWithUniqueID:
|
||||||
[NSString stringWithUTF8String:
|
[NSString stringWithUTF8String:
|
||||||
deviceId.toUtf8().constData()]];
|
deviceId.toUtf8().constData()]];
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ HEADERS += \
|
|||||||
avfstoragelocation.h \
|
avfstoragelocation.h \
|
||||||
avfvideodevicecontrol.h \
|
avfvideodevicecontrol.h \
|
||||||
avfaudioinputselectorcontrol.h \
|
avfaudioinputselectorcontrol.h \
|
||||||
|
avfcamerainfocontrol.h
|
||||||
|
|
||||||
OBJECTIVE_SOURCES += \
|
OBJECTIVE_SOURCES += \
|
||||||
avfcameraserviceplugin.mm \
|
avfcameraserviceplugin.mm \
|
||||||
@@ -47,4 +48,5 @@ OBJECTIVE_SOURCES += \
|
|||||||
avfstoragelocation.mm \
|
avfstoragelocation.mm \
|
||||||
avfvideodevicecontrol.mm \
|
avfvideodevicecontrol.mm \
|
||||||
avfaudioinputselectorcontrol.mm \
|
avfaudioinputselectorcontrol.mm \
|
||||||
|
avfcamerainfocontrol.mm
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user