diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraSettingsTests.m b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraSettingsTests.m index 418b316bea62..9bed6bea4883 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraSettingsTests.m +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraSettingsTests.m @@ -148,9 +148,9 @@ - (void)testSettings_shouldPassConfigurationToCameraDeviceAndWriter { // Expect FPS configuration is passed to camera device. [self waitForExpectations:@[ - injectedWrapper.beginConfigurationExpectation, injectedWrapper.lockExpectation, + injectedWrapper.lockExpectation, injectedWrapper.beginConfigurationExpectation, injectedWrapper.minFrameDurationExpectation, injectedWrapper.maxFrameDurationExpectation, - injectedWrapper.unlockExpectation, injectedWrapper.commitConfigurationExpectation + injectedWrapper.commitConfigurationExpectation, injectedWrapper.unlockExpectation ] timeout:1 enforceOrder:YES]; diff --git a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/FLTCam.m b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/FLTCam.m index 3b1fe466f7c8..a5fb2154555e 100644 --- a/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/FLTCam.m +++ b/packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/FLTCam.m @@ -211,20 +211,21 @@ - (instancetype)initWithMediaSettings:(FCPPlatformMediaSettings *)mediaSettings [_motionManager startAccelerometerUpdates]; if (_mediaSettings.framesPerSecond) { - [_mediaSettingsAVWrapper beginConfigurationForSession:_videoCaptureSession]; - - // Possible values for presets are hard-coded in FLT interface having - // corresponding AVCaptureSessionPreset counterparts. - // If _resolutionPreset is not supported by camera there is - // fallback to lower resolution presets. - // If none can be selected there is error condition. - if (![self setCaptureSessionPreset:_mediaSettings.resolutionPreset withError:error]) { - [_videoCaptureSession commitConfiguration]; - return nil; - } - // The frame rate can be changed only on a locked for configuration device. if ([mediaSettingsAVWrapper lockDevice:_captureDevice error:error]) { + [_mediaSettingsAVWrapper beginConfigurationForSession:_videoCaptureSession]; + + // Possible values for presets are hard-coded in FLT interface having + // corresponding AVCaptureSessionPreset counterparts. + // If _resolutionPreset is not supported by camera there is + // fallback to lower resolution presets. + // If none can be selected there is error condition. + if (![self setCaptureSessionPreset:_mediaSettings.resolutionPreset withError:error]) { + [_videoCaptureSession commitConfiguration]; + [_captureDevice unlockForConfiguration]; + return nil; + } + selectBestFormatForRequestedFrameRate(_captureDevice, _mediaSettings, videoDimensionsForFormat); // Set frame rate with 1/10 precision allowing not integral values. @@ -234,10 +235,9 @@ - (instancetype)initWithMediaSettings:(FCPPlatformMediaSettings *)mediaSettings [mediaSettingsAVWrapper setMinFrameDuration:duration onDevice:_captureDevice]; [mediaSettingsAVWrapper setMaxFrameDuration:duration onDevice:_captureDevice]; - [_mediaSettingsAVWrapper unlockDevice:_captureDevice]; [_mediaSettingsAVWrapper commitConfigurationForSession:_videoCaptureSession]; + [_mediaSettingsAVWrapper unlockDevice:_captureDevice]; } else { - [_mediaSettingsAVWrapper commitConfigurationForSession:_videoCaptureSession]; return nil; } } else {