summaryrefslogtreecommitdiffstats
path: root/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@theqtcompany.com>2015-11-19 15:41:01 +0100
committerTimur Pocheptsov <timur.pocheptsov@theqtcompany.com>2015-12-10 18:07:03 +0000
commit604a5753fa2d9b8e1ef65ccd8c5fb72465462479 (patch)
treeda9922c5621e22d3b7204d2394a823eac47c6859 /src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm
parent8b00d8e5422566d2ca3e6c6fe1a1bbace1a0bff0 (diff)
AVFoundation: correctly set the activeFormat on the AVCaptureDevice.
According to the AVCaptureDevice documentation, the device must be locked before starting the capture session to prevent the activeFormat from being overridden. We now do that, but only if we explicitly set an activeFormat. Otherwise the device is not locked, which allows the session to find an appropriate format for the capture device. The device is also locked when enabling video capture, as doing so might also reset the activeFormat. Task-number: QTBUG-49170 Change-Id: I75478fd4bbfec96cd2abd2c3ae2951088b38978e Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
Diffstat (limited to 'src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm')
-rw-r--r--src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm b/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm
index 95fadb816..3c20801e5 100644
--- a/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm
+++ b/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm
@@ -384,11 +384,6 @@ QCameraViewfinderSettings AVFCameraViewfinderSettingsControl2::viewfinderSetting
void AVFCameraViewfinderSettingsControl2::setViewfinderSettings(const QCameraViewfinderSettings &settings)
{
- if (settings.isNull()) {
- qDebugCamera() << Q_FUNC_INFO << "empty viewfinder settings";
- return;
- }
-
if (m_settings == settings)
return;
@@ -454,7 +449,7 @@ bool AVFCameraViewfinderSettingsControl2::CVPixelFormatFromQtFormat(QVideoFrame:
AVCaptureDeviceFormat *AVFCameraViewfinderSettingsControl2::findBestFormatMatch(const QCameraViewfinderSettings &settings) const
{
AVCaptureDevice *captureDevice = m_service->session()->videoCaptureDevice();
- if (!captureDevice)
+ if (!captureDevice || settings.isNull())
return nil;
#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0)
@@ -553,32 +548,30 @@ bool AVFCameraViewfinderSettingsControl2::convertPixelFormatIfSupported(QVideoFr
return found;
}
-void AVFCameraViewfinderSettingsControl2::applySettings()
+bool AVFCameraViewfinderSettingsControl2::applySettings()
{
- if (m_settings.isNull())
- return;
-
if (m_service->session()->state() != QCamera::LoadedState &&
m_service->session()->state() != QCamera::ActiveState) {
- return;
+ return false;
}
AVCaptureDevice *captureDevice = m_service->session()->videoCaptureDevice();
if (!captureDevice)
- return;
+ return false;
+
+ bool activeFormatChanged = false;
- NSMutableDictionary *videoSettings = [NSMutableDictionary dictionaryWithCapacity:1];
#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0)
AVCaptureDeviceFormat *match = findBestFormatMatch(m_settings);
if (match) {
if (match != captureDevice.activeFormat) {
const AVFConfigurationLock lock(captureDevice);
- if (!lock) {
+ if (lock) {
+ captureDevice.activeFormat = match;
+ activeFormatChanged = true;
+ } else {
qDebugCamera() << Q_FUNC_INFO << "failed to lock for configuration";
- return;
}
-
- captureDevice.activeFormat = match;
}
} else {
qDebugCamera() << Q_FUNC_INFO << "matching device format not found";
@@ -617,6 +610,7 @@ void AVFCameraViewfinderSettingsControl2::applySettings()
}
if (avfPixelFormat != 0) {
+ NSMutableDictionary *videoSettings = [NSMutableDictionary dictionaryWithCapacity:1];
[videoSettings setObject:[NSNumber numberWithUnsignedInt:avfPixelFormat]
forKey:(id)kCVPixelBufferPixelFormatTypeKey];
@@ -625,6 +619,8 @@ void AVFCameraViewfinderSettingsControl2::applySettings()
}
qt_set_framerate_limits(captureDevice, videoConnection(), m_settings);
+
+ return activeFormatChanged;
}
QCameraViewfinderSettings AVFCameraViewfinderSettingsControl2::requestedSettings() const