fix: Fix app hard-crashing when FPS value is not supported (#391)

This commit is contained in:
Marc Rousavy 2021-08-28 14:14:16 +02:00 committed by GitHub
parent dc02a6ec7c
commit 3c845ed4b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -160,6 +160,14 @@ extension CameraView {
try device.lockForConfiguration()
if let fps = self.fps?.int32Value {
let supportsGivenFps = device.activeFormat.videoSupportedFrameRateRanges.contains { range in
return range.includes(fps: Double(fps))
}
if !supportsGivenFps {
invokeOnError(.format(.invalidFps(fps: Int(fps))))
return
}
let duration = CMTimeMake(value: 1, timescale: fps)
device.activeVideoMinFrameDuration = duration
device.activeVideoMaxFrameDuration = duration