feat: Correctly get videoDimensions
on devices below iOS 13
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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,
|
||||
|
24
ios/Extensions/AVCaptureDevice.Format+videoDimensions.swift
Normal file
24
ios/Extensions/AVCaptureDevice.Format+videoDimensions.swift
Normal 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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user