mirror of
https://github.com/HaishinKit/HaishinKit.swift.git
synced 2026-05-07 20:12:28 +00:00
43 lines
1.1 KiB
Swift
43 lines
1.1 KiB
Swift
import AVFoundation
|
|
import Foundation
|
|
|
|
#if os(macOS)
|
|
extension AVCaptureDevice.Format {
|
|
var isMultiCamSupported: Bool {
|
|
return true
|
|
}
|
|
}
|
|
#elseif os(visionOS)
|
|
extension AVCaptureDevice.Format {
|
|
var isMultiCamSupported: Bool {
|
|
return false
|
|
}
|
|
}
|
|
#endif
|
|
|
|
@available(tvOS 17.0, *)
|
|
extension AVCaptureDevice.Format {
|
|
func isFrameRateSupported(_ frameRate: Float64) -> Bool {
|
|
var durations: [CMTime] = []
|
|
var frameRates: [Float64] = []
|
|
for range in videoSupportedFrameRateRanges {
|
|
if range.minFrameRate == range.maxFrameRate {
|
|
durations.append(range.minFrameDuration)
|
|
frameRates.append(range.maxFrameRate)
|
|
continue
|
|
}
|
|
if range.contains(frameRate: frameRate) {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
let diff = frameRates.map { abs($0 - frameRate) }
|
|
if let minElement = diff.min() {
|
|
for i in 0..<diff.count where diff[i] == minElement {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
}
|