Skip to content

Commit

Permalink
fix: Remove maxPhotoDimensions since it is the highest value by def…
Browse files Browse the repository at this point in the history
…ault anyways I think
  • Loading branch information
mrousavy committed Mar 19, 2024
1 parent 53004ae commit ca41f2d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 52 deletions.
1 change: 1 addition & 0 deletions package/example/src/CameraPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export function CameraPage({ navigation }: Props): React.ReactElement {
video={true}
audio={hasMicrophonePermission}
frameProcessor={frameProcessor}
enableHighQualityPhotos={true}
/>
</TapGestureHandler>
</Reanimated.View>
Expand Down
41 changes: 3 additions & 38 deletions package/ios/Core/CameraSession+Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,9 @@ extension CameraSession {
photoOutput.maxPhotoQualityPrioritization = qualityPrioritization
}
if photo.enableHighQualityPhotos {
// TODO: Refactor this into an extension method. Same for AVCapturePhotoOutput.
if #available(iOS 16.0, *) {
if let device = videoDeviceInput?.device,
let targetFormat = configuration.format {
guard let format = device.formats.first(where: { f in targetFormat.isEqualTo(format: f) }) else {
throw CameraError.parameter(.invalid(unionName: "format", receivedValue: targetFormat.toJSValue().description))
}
guard let maxSupportedDimension = format.supportedMaxPhotoDimensions.max(by: { ($0.width * $0.height) < ($1.width * $1.height) }) else {
throw CameraError.unknown(message: "supportedMaxPhotoDimensions was empty!", cause: nil)
}
photoOutput.maxPhotoDimensions = maxSupportedDimension
}
} else {
photoOutput.isHighResolutionCaptureEnabled = true
}
// This is deprecated in favor of `maxPhotoDimensions`, but maxPhotoDimensions is by default
// already set to the highest resolution possible (i think?), so we don't need to set that again.
photoOutput.isHighResolutionCaptureEnabled = true
}
// TODO: Enable isResponsiveCaptureEnabled? (iOS 17+)
// TODO: Enable isFastCapturePrioritizationEnabled? (iOS 17+)
Expand Down Expand Up @@ -215,29 +203,6 @@ extension CameraSession {
ReactLogger.log(level: .info, message: "Successfully configured Format!")
}

func configurePhotoOutputResolution(configuration: CameraConfiguration) {
guard case let .enabled(photo) = configuration.photo,
let photoOutput, let videoDeviceInput else {
// Video is not enabled
return
}

// Configure the PhotoOutput to use the maximum available resolution.
// We need to do this after device.activeFormat has been set.
if #available(iOS 16.0, *) {
let format = videoDeviceInput.device.activeFormat
let maxPhotoResolution = format.supportedMaxPhotoDimensions.max(by: { left, right in
(left.width * left.height) < (right.width * right.height)
})
guard let maxPhotoResolution else {
return
}
photoOutput.maxPhotoDimensions = maxPhotoResolution
} else {
photoOutput.isHighResolutionCaptureEnabled = true
}
}

func configurePixelFormat(configuration: CameraConfiguration) throws {
guard case let .enabled(video) = configuration.video,
let videoOutput else {
Expand Down
6 changes: 1 addition & 5 deletions package/ios/Core/CameraSession+Photo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ extension CameraSession {
// high resolution capture
if photo.enableHighQualityPhotos {
// TODO: On iOS 16+ this will be removed in favor of maxPhotoDimensions.
if #available(iOS 16.0, *) {
photoSettings.maxPhotoDimensions = photoOutput.maxPhotoDimensions
} else {
photoSettings.isHighResolutionPhotoEnabled = true
}
photoSettings.isHighResolutionPhotoEnabled = photoOutput.isHighResolutionCaptureEnabled
}

// depth data
Expand Down
14 changes: 5 additions & 9 deletions package/ios/Core/CameraSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,15 @@ class CameraSession: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate, AVC
if difference.outputsChanged || difference.formatChanged {
try self.configurePixelFormat(configuration: config)
}
// 6. After step 2. and 4. we also need to configure the photo output resolution
if difference.outputsChanged || difference.formatChanged {
self.configurePhotoOutputResolution(configuration: config)
}
// 7. Configure side-props (fps, lowLightBoost)
// 6. Configure side-props (fps, lowLightBoost)
if difference.sidePropsChanged {
try self.configureSideProps(configuration: config, device: device)
}
// 8. Configure zoom
// 7. Configure zoom
if difference.zoomChanged {
self.configureZoom(configuration: config, device: device)
}
// 9. Configure exposure bias
// 8. Configure exposure bias
if difference.exposureChanged {
self.configureExposure(configuration: config, device: device)
}
Expand All @@ -183,10 +179,10 @@ class CameraSession: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate, AVC
self.captureSession.commitConfiguration()
}

// 10. Start or stop the session if needed
// 9. Start or stop the session if needed
self.checkIsActive(configuration: config)

// 11. Enable or disable the Torch if needed (requires session to be running)
// 10. Enable or disable the Torch if needed (requires session to be running)
if difference.torchChanged {
try device.lockForConfiguration()
defer {
Expand Down

0 comments on commit ca41f2d

Please sign in to comment.