2021-02-19 08:28:05 -07:00
|
|
|
//
|
|
|
|
// AVCaptureDevice.Format+isBetterThan.swift
|
2021-06-21 14:42:46 -06:00
|
|
|
// mrousavy
|
2021-02-19 08:28:05 -07:00
|
|
|
//
|
|
|
|
// Created by Marc Rousavy on 19.12.20.
|
2021-06-01 05:07:57 -06:00
|
|
|
// Copyright © 2020 mrousavy. All rights reserved.
|
2021-02-19 08:28:05 -07:00
|
|
|
//
|
|
|
|
|
|
|
|
import AVFoundation
|
|
|
|
|
|
|
|
extension AVCaptureDevice.Format {
|
|
|
|
/** Compares the current Format to the given format and returns true if the current format has either:
|
|
|
|
* 1. Higher still image capture dimensions
|
|
|
|
* 2. Higher video format dimensions (iOS 13.0)
|
|
|
|
* 3. Higher FPS
|
|
|
|
*/
|
|
|
|
func isBetterThan(_ other: AVCaptureDevice.Format) -> Bool {
|
|
|
|
// compare still image dimensions
|
|
|
|
let leftDimensions = highResolutionStillImageDimensions
|
|
|
|
let rightDimensions = other.highResolutionStillImageDimensions
|
2021-02-25 05:59:50 -07:00
|
|
|
if leftDimensions.height * leftDimensions.width > rightDimensions.height * rightDimensions.width {
|
2021-02-19 08:28:05 -07:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-08-03 02:37:48 -06:00
|
|
|
// compare video dimensions
|
2021-08-03 04:01:39 -06:00
|
|
|
let leftVideo = videoDimensions
|
2021-08-03 02:37:48 -06:00
|
|
|
let rightVideo = other.videoDimensions
|
|
|
|
if leftVideo.height * leftVideo.width > rightVideo.height * rightVideo.width {
|
|
|
|
return true
|
2021-02-19 08:28:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// compare max fps
|
|
|
|
if let leftMaxFps = videoSupportedFrameRateRanges.max(by: { $0.maxFrameRate > $1.maxFrameRate }),
|
2021-02-25 05:59:50 -07:00
|
|
|
let rightMaxFps = other.videoSupportedFrameRateRanges.max(by: { $0.maxFrameRate > $1.maxFrameRate }) {
|
2021-02-19 08:28:05 -07:00
|
|
|
if leftMaxFps.maxFrameRate > rightMaxFps.maxFrameRate {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|