fix: Move minExposure/maxExposure from format into device (#2211)

* fix: Move `minExposure`/`maxExposure` into `device`

* Update docs

* chore: Remove unneeded dependency

* chore: Update code
This commit is contained in:
Marc Rousavy
2023-11-24 18:20:56 +01:00
committed by GitHub
parent bb3a42e6bc
commit cad5240420
8 changed files with 25 additions and 36 deletions

View File

@@ -187,14 +187,14 @@ extension CameraSession {
ReactLogger.log(level: .info, message: "Configuring Format (\(targetFormat))...")
let currentFormat = CameraDeviceFormat(fromFormat: device.activeFormat, forDevice: device)
let currentFormat = CameraDeviceFormat(fromFormat: device.activeFormat)
if currentFormat == targetFormat {
ReactLogger.log(level: .info, message: "Already selected active format, no need to configure.")
return
}
// Find matching format (JS Dictionary -> strongly typed Swift class)
let format = device.formats.first { targetFormat.isEqualTo(format: $0, device: device) }
let format = device.formats.first { targetFormat.isEqualTo(format: $0) }
guard let format else {
throw CameraError.format(.invalidFormat)
}
@@ -295,7 +295,7 @@ extension CameraSession {
return
}
let clamped = max(min(exposure, device.maxExposureTargetBias), device.minExposureTargetBias)
let clamped = min(max(exposure, device.minExposureTargetBias), device.maxExposureTargetBias)
device.setExposureTargetBias(clamped)
}

View File

@@ -10,7 +10,7 @@ import AVFoundation
extension AVCaptureDevice {
func toDictionary() -> [String: Any] {
let formats = formats.map { CameraDeviceFormat(fromFormat: $0, forDevice: self) }
let formats = formats.map { CameraDeviceFormat(fromFormat: $0) }
return [
"id": uniqueID,
@@ -20,8 +20,10 @@ extension AVCaptureDevice {
"hasFlash": hasFlash,
"hasTorch": hasTorch,
"minZoom": minAvailableVideoZoomFactor,
"neutralZoom": neutralZoomFactor,
"maxZoom": maxAvailableVideoZoomFactor,
"neutralZoom": neutralZoomFactor,
"minExposure": minExposureTargetBias,
"maxExposure": maxExposureTargetBias,
"isMultiCam": isMultiCam,
"supportsRawCapture": false, // TODO: supportsRawCapture
"supportsLowLightBoost": isLowLightBoostSupported,

View File

@@ -22,9 +22,6 @@ struct CameraDeviceFormat: Equatable, CustomStringConvertible {
let minFps: Double
let maxFps: Double
let minExposure: Float
let maxExposure: Float
let minISO: Float
let maxISO: Float
@@ -41,15 +38,13 @@ struct CameraDeviceFormat: Equatable, CustomStringConvertible {
let supportsDepthCapture: Bool
init(fromFormat format: AVCaptureDevice.Format, forDevice device: AVCaptureDevice) {
init(fromFormat format: AVCaptureDevice.Format) {
videoWidth = Int(format.videoDimensions.width)
videoHeight = Int(format.videoDimensions.height)
photoWidth = Int(format.photoDimensions.width)
photoHeight = Int(format.photoDimensions.height)
minFps = format.minFps
maxFps = format.maxFps
minExposure = device.minExposureTargetBias
maxExposure = device.maxExposureTargetBias
minISO = format.minISO
maxISO = format.maxISO
fieldOfView = format.videoFieldOfView
@@ -72,8 +67,6 @@ struct CameraDeviceFormat: Equatable, CustomStringConvertible {
maxFps = jsValue["maxFps"] as! Double
minISO = jsValue["minISO"] as! Float
maxISO = jsValue["maxISO"] as! Float
minExposure = jsValue["minExposure"] as! Float
maxExposure = jsValue["maxExposure"] as! Float
fieldOfView = jsValue["fieldOfView"] as! Float
maxZoom = jsValue["maxZoom"] as! Double
let jsVideoStabilizationModes = jsValue["videoStabilizationModes"] as! [String]
@@ -88,8 +81,8 @@ struct CameraDeviceFormat: Equatable, CustomStringConvertible {
// swiftlint:enable force_cast
}
func isEqualTo(format other: AVCaptureDevice.Format, device otherDevice: AVCaptureDevice) -> Bool {
let other = CameraDeviceFormat(fromFormat: other, forDevice: otherDevice)
func isEqualTo(format other: AVCaptureDevice.Format) -> Bool {
let other = CameraDeviceFormat(fromFormat: other)
return self == other
}
@@ -103,8 +96,6 @@ struct CameraDeviceFormat: Equatable, CustomStringConvertible {
"videoWidth": videoWidth,
"minISO": minISO,
"maxISO": maxISO,
"minExposure": minExposure,
"maxExposure": maxExposure,
"fieldOfView": fieldOfView,
"maxZoom": maxZoom,
"supportsVideoHdr": supportsVideoHdr,