Skip to content

Commit 5532f6f

Browse files
committed
Improve configuration commit logic
1 parent d73f355 commit 5532f6f

File tree

1 file changed

+5
-13
lines changed
  • packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation

1 file changed

+5
-13
lines changed

packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation/DefaultCamera.swift

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,17 @@ final class DefaultCamera: FLTCam, Camera {
191191
if mediaSettings.framesPerSecond != nil {
192192
// The frame rate can be changed only on a locked for configuration device.
193193
try mediaSettingsAVWrapper.lockDevice(captureDevice)
194+
defer { mediaSettingsAVWrapper.unlockDevice(captureDevice) }
195+
194196
mediaSettingsAVWrapper.beginConfiguration(for: videoCaptureSession)
197+
defer { mediaSettingsAVWrapper.commitConfiguration(for: videoCaptureSession) }
195198

196199
// Possible values for presets are hard-coded in FLT interface having
197200
// corresponding AVCaptureSessionPreset counterparts.
198201
// If _resolutionPreset is not supported by camera there is
199202
// fallback to lower resolution presets.
200203
// If none can be selected there is error condition.
201-
do {
202-
try setCaptureSessionPreset(mediaSettings.resolutionPreset)
203-
} catch {
204-
videoCaptureSession.commitConfiguration()
205-
captureDevice.unlockForConfiguration()
206-
throw error
207-
}
204+
try setCaptureSessionPreset(mediaSettings.resolutionPreset)
208205

209206
FLTSelectBestFormatForRequestedFrameRate(
210207
captureDevice,
@@ -219,9 +216,6 @@ final class DefaultCamera: FLTCam, Camera {
219216
mediaSettingsAVWrapper.setMinFrameDuration(duration, on: captureDevice)
220217
mediaSettingsAVWrapper.setMaxFrameDuration(duration, on: captureDevice)
221218
}
222-
223-
mediaSettingsAVWrapper.commitConfiguration(for: videoCaptureSession)
224-
mediaSettingsAVWrapper.unlockDevice(captureDevice)
225219
} else {
226220
// If the frame rate is not important fall to a less restrictive
227221
// behavior (no configuration locking).
@@ -582,9 +576,7 @@ final class DefaultCamera: FLTCam, Camera {
582576
guard let strongSelf = self else { return }
583577

584578
strongSelf.captureSessionQueue.async { [weak self] in
585-
self?.inProgressSavePhotoDelegates.removeValue(
586-
forKey:
587-
settings.uniqueID)
579+
self?.inProgressSavePhotoDelegates.removeValue(forKey: settings.uniqueID)
588580
}
589581

590582
if let error = error {

0 commit comments

Comments
 (0)