summaryrefslogtreecommitdiffstats
path: root/src/plugins/avfoundation/camera/avfcamerasession.mm
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2015-04-15 09:26:14 +0200
committerLiang Qi <liang.qi@theqtcompany.com>2015-04-15 09:26:14 +0200
commit1925bb404ec47b6e074c5e3b334fe0be12176d7b (patch)
tree8d7d79ac1b3a549c20bb4fa77c6f457bf1bb61ea /src/plugins/avfoundation/camera/avfcamerasession.mm
parent6187b72c51d0c05955d9d814baf8866b8e70fcfe (diff)
parentf9145aca166ad2ca1514524ce88ded7834eb207c (diff)
Merge remote-tracking branch 'origin/5.4' into 5.5
Conflicts: src/multimedia/playback/playlistfileparser.cpp src/plugins/windowsaudio/qwindowsaudiodeviceinfo.cpp Change-Id: I52950def2b8283ae15797d05d4ead6a1256eba19
Diffstat (limited to 'src/plugins/avfoundation/camera/avfcamerasession.mm')
-rw-r--r--src/plugins/avfoundation/camera/avfcamerasession.mm59
1 files changed, 36 insertions, 23 deletions
diff --git a/src/plugins/avfoundation/camera/avfcamerasession.mm b/src/plugins/avfoundation/camera/avfcamerasession.mm
index af30dd312..48fe428d8 100644
--- a/src/plugins/avfoundation/camera/avfcamerasession.mm
+++ b/src/plugins/avfoundation/camera/avfcamerasession.mm
@@ -48,14 +48,14 @@
#include <QtCore/qdatetime.h>
#include <QtCore/qurl.h>
+#include <QtCore/qelapsedtimer.h>
#include <QtCore/qdebug.h>
QT_USE_NAMESPACE
-QByteArray AVFCameraSession::m_defaultCameraDevice;
-QList<QByteArray> AVFCameraSession::m_cameraDevices;
-QMap<QByteArray, AVFCameraInfo> AVFCameraSession::m_cameraInfo;
+int AVFCameraSession::m_defaultCameraIndex;
+QList<AVFCameraInfo> AVFCameraSession::m_cameraDevices;
@interface AVFCameraSessionObserver : NSObject
{
@@ -169,45 +169,55 @@ AVFCameraSession::~AVFCameraSession()
[m_captureSession release];
}
-const QByteArray &AVFCameraSession::defaultCameraDevice()
+int AVFCameraSession::defaultCameraIndex()
{
- if (m_cameraDevices.isEmpty())
- updateCameraDevices();
-
- return m_defaultCameraDevice;
+ updateCameraDevices();
+ return m_defaultCameraIndex;
}
-const QList<QByteArray> &AVFCameraSession::availableCameraDevices()
+const QList<AVFCameraInfo> &AVFCameraSession::availableCameraDevices()
{
- if (m_cameraDevices.isEmpty())
- updateCameraDevices();
-
+ updateCameraDevices();
return m_cameraDevices;
}
AVFCameraInfo AVFCameraSession::cameraDeviceInfo(const QByteArray &device)
{
- if (m_cameraDevices.isEmpty())
- updateCameraDevices();
+ updateCameraDevices();
+
+ Q_FOREACH (const AVFCameraInfo &info, m_cameraDevices) {
+ if (info.deviceId == device)
+ return info;
+ }
- return m_cameraInfo.value(device);
+ return AVFCameraInfo();
}
void AVFCameraSession::updateCameraDevices()
{
- m_defaultCameraDevice.clear();
+#ifdef Q_OS_IOS
+ // Cameras can't change dynamically on iOS. Update only once.
+ if (!m_cameraDevices.isEmpty())
+ return;
+#else
+ // On OS X, cameras can be added or removed. Update the list every time, but not more than
+ // once every 500 ms
+ static QElapsedTimer timer;
+ if (timer.isValid() && timer.elapsed() < 500) // ms
+ return;
+#endif
+
+ m_defaultCameraIndex = -1;
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]);
+ if (defaultDevice && [defaultDevice.uniqueID isEqualToString:device.uniqueID])
+ m_defaultCameraIndex = m_cameraDevices.count();
AVFCameraInfo info;
+ info.deviceId = QByteArray([[device uniqueID] UTF8String]);
info.description = QString::fromNSString([device localizedName]);
// There is no API to get the camera sensor orientation, however, cameras are always
@@ -232,9 +242,12 @@ void AVFCameraSession::updateCameraDevices()
break;
}
- m_cameraDevices << deviceId;
- m_cameraInfo.insert(deviceId, info);
+ m_cameraDevices.append(info);
}
+
+#ifndef Q_OS_IOS
+ timer.restart();
+#endif
}
void AVFCameraSession::setVideoOutput(AVFCameraRendererControl *output)