Skip to content

Commit aeae649

Browse files
committed
Resolve PR comments
1 parent 3a982c5 commit aeae649

File tree

1 file changed

+14
-12
lines changed
  • packages/camera/camera_avfoundation/ios/camera_avfoundation/Sources/camera_avfoundation

1 file changed

+14
-12
lines changed

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ final class DefaultCamera: NSObject, Camera {
143143
let captureVideoOutput = FLTDefaultCaptureVideoDataOutput(
144144
captureVideoOutput: AVCaptureVideoDataOutput())
145145
captureVideoOutput.videoSettings = [
146-
kCVPixelBufferPixelFormatTypeKey as String: videoFormat as Any
146+
kCVPixelBufferPixelFormatTypeKey as String: videoFormat
147147
]
148148
captureVideoOutput.alwaysDiscardsLateVideoFrames = true
149149

@@ -210,11 +210,6 @@ final class DefaultCamera: NSObject, Camera {
210210
mediaSettingsAVWrapper.beginConfiguration(for: videoCaptureSession)
211211
defer { mediaSettingsAVWrapper.commitConfiguration(for: videoCaptureSession) }
212212

213-
// Possible values for presets are hard-coded in FLT interface having
214-
// corresponding AVCaptureSessionPreset counterparts.
215-
// If _resolutionPreset is not supported by camera there is
216-
// fallback to lower resolution presets.
217-
// If none can be selected there is error condition.
218213
try setCaptureSessionPreset(mediaSettings.resolutionPreset)
219214

220215
FLTSelectBestFormatForRequestedFrameRate(
@@ -239,14 +234,20 @@ final class DefaultCamera: NSObject, Camera {
239234
updateOrientation()
240235
}
241236

237+
// Possible values for presets are hard-coded in FLT interface having
238+
// corresponding AVCaptureSessionPreset counterparts.
239+
// If _resolutionPreset is not supported by camera there is
240+
// fallback to lower resolution presets.
241+
// If none can be selected there is error condition.
242242
private func setCaptureSessionPreset(
243243
_ resolutionPreset: FCPPlatformResolutionPreset
244244
) throws {
245245
switch resolutionPreset {
246246
case .max:
247247
if let bestFormat = highestResolutionFormat(forCaptureDevice: captureDevice) {
248248
videoCaptureSession.sessionPreset = .inputPriority
249-
if (try? captureDevice.lockForConfiguration()) != nil {
249+
do {
250+
try captureDevice.lockForConfiguration()
250251
// Set the best device format found and finish the device configuration.
251252
captureDevice.activeFormat = bestFormat
252253
captureDevice.unlockForConfiguration()
@@ -427,8 +428,9 @@ final class DefaultCamera: NSObject, Camera {
427428
// Get all the state on the current thread, not the main thread.
428429
let state = FCPPlatformCameraState.make(
429430
withPreviewSize: FCPPlatformSize.make(
430-
withWidth: Double(previewSize!.width),
431-
height: Double(previewSize!.height)
431+
// previewSize is set during init, so it will never be nil.
432+
withWidth: previewSize!.width,
433+
height: previewSize!.height
432434
),
433435
exposureMode: exposureMode,
434436
focusMode: focusMode,
@@ -736,7 +738,7 @@ final class DefaultCamera: NSObject, Camera {
736738
private func updateOrientation() {
737739
guard !isRecording else { return }
738740

739-
let orientation: UIDeviceOrientation =
741+
let orientation =
740742
(lockedCaptureOrientation != .unknown)
741743
? lockedCaptureOrientation
742744
: deviceOrientation
@@ -751,11 +753,11 @@ final class DefaultCamera: NSObject, Camera {
751753
if let connection = captureOutput.connection(withMediaType: .video),
752754
connection.isVideoOrientationSupported
753755
{
754-
connection.videoOrientation = getVideoOrientation(forDeviceOrientation: orientation)
756+
connection.videoOrientation = videoOrientation(forDeviceOrientation: orientation)
755757
}
756758
}
757759

758-
private func getVideoOrientation(forDeviceOrientation deviceOrientation: UIDeviceOrientation)
760+
private func videoOrientation(forDeviceOrientation deviceOrientation: UIDeviceOrientation)
759761
-> AVCaptureVideoOrientation
760762
{
761763
switch deviceOrientation {

0 commit comments

Comments
 (0)