diff options
author | Val Doroshchuk <valentyn.doroshchuk@qt.io> | 2020-02-17 15:32:25 +0100 |
---|---|---|
committer | Val Doroshchuk <valentyn.doroshchuk@qt.io> | 2020-02-18 15:54:23 +0100 |
commit | aec140743b1a4110c327c46bdfbf15fcddb2dd17 (patch) | |
tree | e10af1522b7f93f9177f05e8dcc07521bb92b5af /src/plugins/avfoundation | |
parent | 7e64b859b6a663f42ee3067930ef132d9e7d2901 (diff) |
AVF: Fix applying viewfinder settings for iOS
1. If a resolution of the viewfinder is requested to be changed,
it is not needed to check available formats for highResolutionStillImageDimensions
(since it is viewfinder resolution and not still images).
format.highResolutionStillImageDimensions returns the highest resolution still image
that can be produced by the format.
Using this format will cause wrong resolution in the viewfinder.
2. Seems iOS requires to call beginConfiguration/commitConfiguration to apply any changes.
commitConfiguration is currently called when the camera gets active.
In case if settings are changed after starting the camera, they will not be applied.
To fix that, added beginConfiguration/commitConfiguration.
Fixes: QTBUG-79935
Change-Id: I60b6e08887a82e4337a2a302b8e5513c65b26e61
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/plugins/avfoundation')
3 files changed, 15 insertions, 5 deletions
diff --git a/src/plugins/avfoundation/camera/avfcamerautility.h b/src/plugins/avfoundation/camera/avfcamerautility.h index 370302b1c..33956fc8a 100644 --- a/src/plugins/avfoundation/camera/avfcamerautility.h +++ b/src/plugins/avfoundation/camera/avfcamerautility.h @@ -161,7 +161,7 @@ QSize qt_device_format_high_resolution(AVCaptureDeviceFormat *format); QSize qt_device_format_pixel_aspect_ratio(AVCaptureDeviceFormat *format); QVector<AVFPSRange> qt_device_format_framerates(AVCaptureDeviceFormat *format); AVCaptureDeviceFormat *qt_find_best_resolution_match(AVCaptureDevice *captureDevice, const QSize &res, - FourCharCode preferredFormat); + FourCharCode preferredFormat, bool stillImage = true); AVCaptureDeviceFormat *qt_find_best_framerate_match(AVCaptureDevice *captureDevice, FourCharCode preferredFormat, Float64 fps); diff --git a/src/plugins/avfoundation/camera/avfcamerautility.mm b/src/plugins/avfoundation/camera/avfcamerautility.mm index 8c743dcbc..25ccc4b01 100644 --- a/src/plugins/avfoundation/camera/avfcamerautility.mm +++ b/src/plugins/avfoundation/camera/avfcamerautility.mm @@ -239,7 +239,8 @@ QSize qt_device_format_pixel_aspect_ratio(AVCaptureDeviceFormat *format) AVCaptureDeviceFormat *qt_find_best_resolution_match(AVCaptureDevice *captureDevice, const QSize &request, - FourCharCode filter) + FourCharCode filter, + bool stillImage) { Q_ASSERT(captureDevice); Q_ASSERT(!request.isNull() && request.isValid()); @@ -254,7 +255,7 @@ AVCaptureDeviceFormat *qt_find_best_resolution_match(AVCaptureDevice *captureDev if (qt_device_format_resolution(format) == request) return format; // iOS only (still images). - if (qt_device_format_high_resolution(format) == request) + if (stillImage && qt_device_format_high_resolution(format) == request) return format; } @@ -272,7 +273,7 @@ AVCaptureDeviceFormat *qt_find_best_resolution_match(AVCaptureDevice *captureDev if (!res.isNull() && res.isValid() && qt_area_sane(res)) pairs << FormatPair(res, format); const QSize highRes(qt_device_format_high_resolution(format)); - if (!highRes.isNull() && highRes.isValid() && qt_area_sane(highRes)) + if (stillImage && !highRes.isNull() && highRes.isValid() && qt_area_sane(highRes)) pairs << FormatPair(highRes, format); } diff --git a/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm b/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm index a77d7de03..0f7a0560b 100644 --- a/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm +++ b/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm @@ -185,7 +185,16 @@ void AVFCameraViewfinderSettingsControl2::setViewfinderSettings(const QCameraVie return; m_settings = settings; +#if defined(Q_OS_IOS) + bool active = m_service->session()->state() == QCamera::ActiveState; + if (active) + [m_service->session()->captureSession() beginConfiguration]; applySettings(m_settings); + if (active) + [m_service->session()->captureSession() commitConfiguration]; +#else + applySettings(m_settings); +#endif } QVideoFrame::PixelFormat AVFCameraViewfinderSettingsControl2::QtPixelFormatFromCVFormat(unsigned avPixelFormat) @@ -264,7 +273,7 @@ AVCaptureDeviceFormat *AVFCameraViewfinderSettingsControl2::findBestFormatMatch( // Either the exact match (including high resolution for images on iOS) // or a format with a resolution close to the requested one. return qt_find_best_resolution_match(captureDevice, resolution, - m_service->session()->defaultCodec()); + m_service->session()->defaultCodec(), false); } // No resolution requested, what about framerates? |