From 8de5b005adad7e922b7de261c4199754a03fd2f6 Mon Sep 17 00:00:00 2001 From: misos1 <30872003+misos1@users.noreply.github.com> Date: Thu, 5 Sep 2024 21:17:20 +0200 Subject: [PATCH] revert reordering lockDevice with beginConfigurationForSession --- .../ios/RunnerTests/CameraSettingsTests.m | 6 ++-- .../Sources/camera_avfoundation/FLTCam.m | 30 +++++++++---------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraSettingsTests.m b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraSettingsTests.m index 418b316bea62..10bc7d253290 100644 --- a/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraSettingsTests.m +++ b/packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraSettingsTests.m @@ -11,7 +11,7 @@ #import #import "CameraTestUtils.h" -static const FCPPlatformResolutionPreset gTestResolutionPreset = FCPPlatformResolutionPresetMedium; +static const FCPPlatformResolutionPreset gTestResolutionPreset = FCPPlatformResolutionPresetMediumFCPPlatformResolutionPresetMedium; static const int gTestFramesPerSecond = 15; static const int gTestVideoBitrate = 200000; static const int gTestAudioBitrate = 32000; @@ -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..d47ce26de85b 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,11 +235,8 @@ - (instancetype)initWithMediaSettings:(FCPPlatformMediaSettings *)mediaSettings [mediaSettingsAVWrapper setMinFrameDuration:duration onDevice:_captureDevice]; [mediaSettingsAVWrapper setMaxFrameDuration:duration onDevice:_captureDevice]; - [_mediaSettingsAVWrapper unlockDevice:_captureDevice]; - [_mediaSettingsAVWrapper commitConfigurationForSession:_videoCaptureSession]; - } else { [_mediaSettingsAVWrapper commitConfigurationForSession:_videoCaptureSession]; - return nil; + [_mediaSettingsAVWrapper unlockDevice:_captureDevice]; } } else { // If the frame rate is not important fall to a less restrictive