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>
This commit is contained in:
committed by
Timur Pocheptsov
parent
8b00d8e542
commit
604a5753fa
@@ -285,10 +285,23 @@ void AVFCameraSession::setState(QCamera::State newState)
|
||||
Q_EMIT readyToConfigureConnections();
|
||||
m_defaultCodec = 0;
|
||||
defaultCodec();
|
||||
applyImageEncoderSettings();
|
||||
applyViewfinderSettings();
|
||||
|
||||
bool activeFormatSet = applyImageEncoderSettings();
|
||||
activeFormatSet |= applyViewfinderSettings();
|
||||
|
||||
[m_captureSession commitConfiguration];
|
||||
|
||||
if (activeFormatSet) {
|
||||
// According to the doc, the capture device must be locked before
|
||||
// startRunning to prevent the format we set to be overriden by the
|
||||
// session preset.
|
||||
[videoCaptureDevice() lockForConfiguration:nil];
|
||||
}
|
||||
|
||||
[m_captureSession startRunning];
|
||||
|
||||
if (activeFormatSet)
|
||||
[videoCaptureDevice() unlockForConfiguration];
|
||||
}
|
||||
|
||||
if (oldState == QCamera::ActiveState) {
|
||||
@@ -355,13 +368,15 @@ void AVFCameraSession::attachVideoInputDevice()
|
||||
}
|
||||
}
|
||||
|
||||
void AVFCameraSession::applyImageEncoderSettings()
|
||||
bool AVFCameraSession::applyImageEncoderSettings()
|
||||
{
|
||||
if (AVFImageEncoderControl *control = m_service->imageEncoderControl())
|
||||
control->applySettings();
|
||||
return control->applySettings();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void AVFCameraSession::applyViewfinderSettings()
|
||||
bool AVFCameraSession::applyViewfinderSettings()
|
||||
{
|
||||
if (AVFCameraViewfinderSettingsControl2 *vfControl = m_service->viewfinderSettingsControl2()) {
|
||||
QCameraViewfinderSettings vfSettings(vfControl->requestedSettings());
|
||||
@@ -372,12 +387,13 @@ void AVFCameraSession::applyViewfinderSettings()
|
||||
if (!imageResolution.isNull() && imageResolution.isValid()) {
|
||||
vfSettings.setResolution(imageResolution);
|
||||
vfControl->setViewfinderSettings(vfSettings);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
vfControl->applySettings();
|
||||
return vfControl->applySettings();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void AVFCameraSession::addProbe(AVFMediaVideoProbeControl *probe)
|
||||
|
||||
Reference in New Issue
Block a user