71730a73ef
* Set category always if different * rename org * Fix video format sorting * fix format filtering * Update AVAudioSession+setCategoryIfNotSet.swift * upgrade all dependencies * Also run dependabot for JS codebase * Update MediaPage.tsx * Use typescript 4.2.4 * Also run TS in check-all * Downgrade typescript to 4.2.3 * f * recreate lockfiles * docs: Revert package.json changes * revert all package.json changes * Update Podfile.lock * bump all dependencies, pin typescript to 4.2.4 * Downgrade react-native-navigation for now * upgrade to later snapshot * Update yarn.lock * remove yeet
45 lines
1.4 KiB
Swift
45 lines
1.4 KiB
Swift
//
|
|
// AVCaptureDevice.Format+isBetterThan.swift
|
|
// Cuvent
|
|
//
|
|
// Created by Marc Rousavy on 19.12.20.
|
|
// Copyright © 2020 mrousavy. All rights reserved.
|
|
//
|
|
|
|
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
|
|
if leftDimensions.height * leftDimensions.width > rightDimensions.height * rightDimensions.width {
|
|
return true
|
|
}
|
|
|
|
if #available(iOS 13.0, *) {
|
|
// compare video dimensions
|
|
let leftVideo = self.formatDescription.presentationDimensions()
|
|
let rightVideo = other.formatDescription.presentationDimensions()
|
|
if leftVideo.height * leftVideo.width > rightVideo.height * rightVideo.width {
|
|
return true
|
|
}
|
|
}
|
|
|
|
// compare max fps
|
|
if let leftMaxFps = videoSupportedFrameRateRanges.max(by: { $0.maxFrameRate > $1.maxFrameRate }),
|
|
let rightMaxFps = other.videoSupportedFrameRateRanges.max(by: { $0.maxFrameRate > $1.maxFrameRate }) {
|
|
if leftMaxFps.maxFrameRate > rightMaxFps.maxFrameRate {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
}
|