2021-02-19 08:28:05 -07:00
|
|
|
//
|
|
|
|
// AVCaptureDevice.Format+toDictionary.swift
|
2021-06-21 14:42:46 -06:00
|
|
|
// mrousavy
|
2021-02-19 08:28:05 -07:00
|
|
|
//
|
|
|
|
// Created by Marc Rousavy on 15.01.21.
|
2021-06-01 05:07:57 -06:00
|
|
|
// Copyright © 2021 mrousavy. All rights reserved.
|
2021-02-19 08:28:05 -07:00
|
|
|
//
|
|
|
|
|
|
|
|
import AVFoundation
|
|
|
|
|
|
|
|
extension AVCaptureDevice.Format {
|
|
|
|
var videoStabilizationModes: [AVCaptureVideoStabilizationMode] {
|
2023-10-13 10:33:20 -06:00
|
|
|
let allModes = AVCaptureDevice.Format.getAllVideoStabilizationModes()
|
|
|
|
return allModes.filter { self.isVideoStabilizationModeSupported($0) }
|
2021-02-19 08:28:05 -07:00
|
|
|
}
|
|
|
|
|
2023-10-13 10:33:20 -06:00
|
|
|
var minFps: Float64 {
|
2023-08-21 04:50:14 -06:00
|
|
|
let maxRange = videoSupportedFrameRateRanges.max { l, r in
|
|
|
|
return l.maxFrameRate < r.maxFrameRate
|
|
|
|
}
|
|
|
|
return maxRange?.maxFrameRate ?? 0
|
|
|
|
}
|
|
|
|
|
2023-10-13 10:33:20 -06:00
|
|
|
var maxFps: Float64 {
|
2023-08-21 04:50:14 -06:00
|
|
|
let maxRange = videoSupportedFrameRateRanges.max { l, r in
|
|
|
|
return l.maxFrameRate < r.maxFrameRate
|
|
|
|
}
|
|
|
|
return maxRange?.maxFrameRate ?? 0
|
|
|
|
}
|
|
|
|
|
2023-10-06 08:11:09 -06:00
|
|
|
var supportsVideoHDR: Bool {
|
|
|
|
let pixelFormat = CMFormatDescriptionGetMediaSubType(formatDescription)
|
|
|
|
let hdrFormats = [
|
|
|
|
kCVPixelFormatType_420YpCbCr10BiPlanarFullRange,
|
|
|
|
kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange,
|
|
|
|
kCVPixelFormatType_Lossless_420YpCbCr10PackedBiPlanarVideoRange,
|
|
|
|
]
|
|
|
|
return hdrFormats.contains(pixelFormat)
|
|
|
|
}
|
|
|
|
|
2023-10-13 10:33:20 -06:00
|
|
|
var supportsPhotoHDR: Bool {
|
|
|
|
// TODO: Supports Photo HDR on iOS?
|
|
|
|
return false
|
2021-02-19 08:28:05 -07:00
|
|
|
}
|
2023-10-06 08:11:09 -06:00
|
|
|
|
2023-10-13 10:33:20 -06:00
|
|
|
var supportsDepthCapture: Bool {
|
|
|
|
return !supportedDepthDataFormats.isEmpty
|
|
|
|
}
|
2023-10-06 08:11:09 -06:00
|
|
|
|
2023-10-13 10:33:20 -06:00
|
|
|
private static func getAllVideoStabilizationModes() -> [AVCaptureVideoStabilizationMode] {
|
|
|
|
var modes: [AVCaptureVideoStabilizationMode] = [.auto, .cinematic, .off, .standard]
|
|
|
|
if #available(iOS 13, *) {
|
|
|
|
modes.append(.cinematicExtended)
|
2023-10-06 08:11:09 -06:00
|
|
|
}
|
2023-10-13 10:33:20 -06:00
|
|
|
return modes
|
2023-10-06 08:11:09 -06:00
|
|
|
}
|
2021-02-19 08:28:05 -07:00
|
|
|
}
|