feat: Correctly get videoDimensions on devices below iOS 13

This commit is contained in:
Marc Rousavy
2021-08-03 10:37:48 +02:00
parent aaecb90937
commit c078cdf933
6 changed files with 50 additions and 26 deletions

View File

@@ -22,13 +22,11 @@ extension AVCaptureDevice.Format {
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 video dimensions
let leftVideo = self.videoDimensions
let rightVideo = other.videoDimensions
if leftVideo.height * leftVideo.width > rightVideo.height * rightVideo.width {
return true
}
// compare max fps

View File

@@ -24,22 +24,14 @@ extension AVCaptureDevice.Format {
return false
}
}
if #available(iOS 13.0, *) {
if let videoHeight = filter.value(forKey: "videoHeight") as? NSNumber {
if self.formatDescription.presentationDimensions().height != CGFloat(videoHeight.doubleValue) {
return false
}
if let videoHeight = filter.value(forKey: "videoHeight") as? NSNumber {
if videoDimensions.height != CGFloat(videoHeight.doubleValue) {
return false
}
if let videoWidth = filter.value(forKey: "videoWidth") as? NSNumber {
if self.formatDescription.presentationDimensions().width != CGFloat(videoWidth.doubleValue) {
return false
}
}
if let isHighestPhotoQualitySupported = filter.value(forKey: "isHighestPhotoQualitySupported") as? Bool {
if self.isHighestPhotoQualitySupported != isHighestPhotoQualitySupported {
return false
}
}
if let videoWidth = filter.value(forKey: "videoWidth") as? NSNumber {
if videoDimensions.width != CGFloat(videoWidth.doubleValue) {
return false
}
}
if let maxISO = filter.value(forKey: "maxISO") as? NSNumber {
@@ -97,6 +89,14 @@ extension AVCaptureDevice.Format {
return false
}
}
if #available(iOS 13.0, *) {
if let isHighestPhotoQualitySupported = filter.value(forKey: "isHighestPhotoQualitySupported") as? Bool {
if self.isHighestPhotoQualitySupported != isHighestPhotoQualitySupported {
return false
}
}
}
return true
}

View File

@@ -22,8 +22,6 @@ extension AVCaptureDevice.Format {
}
func toDictionary() -> [String: Any] {
let videoDimensions = CMVideoFormatDescriptionGetDimensions(formatDescription)
var dict: [String: Any] = [
"videoStabilizationModes": videoStabilizationModes.map(\.descriptor),
"autoFocusSystem": autoFocusSystem.descriptor,

View File

@@ -0,0 +1,24 @@
//
// AVCaptureDevice.Format+videoDimensions.swift
// VisionCamera
//
// Created by Marc Rousavy on 03.08.21.
// Copyright © 2021 mrousavy. All rights reserved.
//
import Foundation
import AVFoundation
extension AVCaptureDevice.Format {
/**
* Returns the video dimensions, adjusted to take pixel aspect ratio and/or clean
* aperture into account.
*
* Pixel aspect ratio is used to adjust the width, leaving the height alone.
*/
var videoDimensions: CGSize {
return CMVideoFormatDescriptionGetPresentationDimensions(formatDescription,
usePixelAspectRatio: true,
useCleanAperture: true)
}
}