diff options
author | Yoann Lopes <yoann.lopes@digia.com> | 2014-02-07 14:20:28 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-04 17:53:18 +0100 |
commit | 9a55f5ce5746fa1df6daa62a7111cb2d5ff5138d (patch) | |
tree | beb13b03600a530a6820017dafa33cb0af364c6f /src/plugins/avfoundation/camera/avfcamerasession.mm | |
parent | 70415c3d9752e357e8d49633cdd8e82d3519e59b (diff) |
AVFoundation: implement QCameraInfoControl.
Change-Id: I05f3daa5c4acb90e046e26d6d577ae40dfed0e30
Reviewed-by: Andy Nichols <andy.nichols@digia.com>
Diffstat (limited to 'src/plugins/avfoundation/camera/avfcamerasession.mm')
-rw-r--r-- | src/plugins/avfoundation/camera/avfcamerasession.mm | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/plugins/avfoundation/camera/avfcamerasession.mm b/src/plugins/avfoundation/camera/avfcamerasession.mm index 93c2bacd0..042855aa4 100644 --- a/src/plugins/avfoundation/camera/avfcamerasession.mm +++ b/src/plugins/avfoundation/camera/avfcamerasession.mm @@ -57,6 +57,10 @@ QT_USE_NAMESPACE +QByteArray AVFCameraSession::m_defaultCameraDevice; +QList<QByteArray> AVFCameraSession::m_cameraDevices; +QMap<QByteArray, AVFCameraInfo> AVFCameraSession::m_cameraInfo; + @interface AVFCameraSessionObserver : NSObject { @private @@ -151,6 +155,74 @@ AVFCameraSession::~AVFCameraSession() [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) { m_videoOutput = output; |