Skip to content

Commit c078cdf

Browse files
committed
feat: Correctly get videoDimensions on devices below iOS 13
1 parent aaecb90 commit c078cdf

6 files changed

+50
-26
lines changed

example/ios/Podfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ PODS:
322322
- React
323323
- RNVectorIcons (8.1.0):
324324
- React-Core
325-
- VisionCamera (2.4.2-beta.11):
325+
- VisionCamera (2.4.2-beta.12):
326326
- React
327327
- React-callinvoker
328328
- React-Core
@@ -490,7 +490,7 @@ SPEC CHECKSUMS:
490490
RNReanimated: daebbd404c0cd9df6daa248d63dd940086bea9ff
491491
RNStaticSafeAreaInsets: 6103cf09647fa427186d30f67b0f5163c1ae8252
492492
RNVectorIcons: 31cebfcf94e8cf8686eb5303ae0357da64d7a5a4
493-
VisionCamera: 35bd0ff9611655b0e5506c1721da45e006f3398e
493+
VisionCamera: ed40e8380f2cd139ccf78bfbf9e5a98e91781033
494494
Yoga: 575c581c63e0d35c9a83f4b46d01d63abc1100ac
495495

496496
PODFILE CHECKSUM: 4b093c1d474775c2eac3268011e4b0b80929d3a2

ios/Extensions/AVCaptureDevice.Format+isBetterThan.swift

+5-7
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ extension AVCaptureDevice.Format {
2222
return true
2323
}
2424

25-
if #available(iOS 13.0, *) {
26-
// compare video dimensions
27-
let leftVideo = self.formatDescription.presentationDimensions()
28-
let rightVideo = other.formatDescription.presentationDimensions()
29-
if leftVideo.height * leftVideo.width > rightVideo.height * rightVideo.width {
30-
return true
31-
}
25+
// compare video dimensions
26+
let leftVideo = self.videoDimensions
27+
let rightVideo = other.videoDimensions
28+
if leftVideo.height * leftVideo.width > rightVideo.height * rightVideo.width {
29+
return true
3230
}
3331

3432
// compare max fps

ios/Extensions/AVCaptureDevice.Format+matchesFilter.swift

+15-15
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,14 @@ extension AVCaptureDevice.Format {
2424
return false
2525
}
2626
}
27-
28-
if #available(iOS 13.0, *) {
29-
if let videoHeight = filter.value(forKey: "videoHeight") as? NSNumber {
30-
if self.formatDescription.presentationDimensions().height != CGFloat(videoHeight.doubleValue) {
31-
return false
32-
}
33-
}
34-
if let videoWidth = filter.value(forKey: "videoWidth") as? NSNumber {
35-
if self.formatDescription.presentationDimensions().width != CGFloat(videoWidth.doubleValue) {
36-
return false
37-
}
27+
if let videoHeight = filter.value(forKey: "videoHeight") as? NSNumber {
28+
if videoDimensions.height != CGFloat(videoHeight.doubleValue) {
29+
return false
3830
}
39-
if let isHighestPhotoQualitySupported = filter.value(forKey: "isHighestPhotoQualitySupported") as? Bool {
40-
if self.isHighestPhotoQualitySupported != isHighestPhotoQualitySupported {
41-
return false
42-
}
31+
}
32+
if let videoWidth = filter.value(forKey: "videoWidth") as? NSNumber {
33+
if videoDimensions.width != CGFloat(videoWidth.doubleValue) {
34+
return false
4335
}
4436
}
4537
if let maxISO = filter.value(forKey: "maxISO") as? NSNumber {
@@ -97,6 +89,14 @@ extension AVCaptureDevice.Format {
9789
return false
9890
}
9991
}
92+
93+
if #available(iOS 13.0, *) {
94+
if let isHighestPhotoQualitySupported = filter.value(forKey: "isHighestPhotoQualitySupported") as? Bool {
95+
if self.isHighestPhotoQualitySupported != isHighestPhotoQualitySupported {
96+
return false
97+
}
98+
}
99+
}
100100

101101
return true
102102
}

ios/Extensions/AVCaptureDevice.Format+toDictionary.swift

-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ extension AVCaptureDevice.Format {
2222
}
2323

2424
func toDictionary() -> [String: Any] {
25-
let videoDimensions = CMVideoFormatDescriptionGetDimensions(formatDescription)
26-
2725
var dict: [String: Any] = [
2826
"videoStabilizationModes": videoStabilizationModes.map(\.descriptor),
2927
"autoFocusSystem": autoFocusSystem.descriptor,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// AVCaptureDevice.Format+videoDimensions.swift
3+
// VisionCamera
4+
//
5+
// Created by Marc Rousavy on 03.08.21.
6+
// Copyright © 2021 mrousavy. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import AVFoundation
11+
12+
extension AVCaptureDevice.Format {
13+
/**
14+
* Returns the video dimensions, adjusted to take pixel aspect ratio and/or clean
15+
* aperture into account.
16+
*
17+
* Pixel aspect ratio is used to adjust the width, leaving the height alone.
18+
*/
19+
var videoDimensions: CGSize {
20+
return CMVideoFormatDescriptionGetPresentationDimensions(formatDescription,
21+
usePixelAspectRatio: true,
22+
useCleanAperture: true)
23+
}
24+
}

ios/VisionCamera.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
B80C0E00260BDDF7001699AB /* FrameProcessorPluginRegistry.mm in Sources */ = {isa = PBXBuildFile; fileRef = B80C0DFF260BDDF7001699AB /* FrameProcessorPluginRegistry.mm */; };
1111
B80E06A0266632F000728644 /* AVAudioSession+updateCategory.swift in Sources */ = {isa = PBXBuildFile; fileRef = B80E069F266632F000728644 /* AVAudioSession+updateCategory.swift */; };
1212
B8103E1C25FF553B007A1684 /* FrameProcessorUtils.mm in Sources */ = {isa = PBXBuildFile; fileRef = B8103E1B25FF553B007A1684 /* FrameProcessorUtils.mm */; };
13+
B81BE1BF26B936FF002696CC /* AVCaptureDevice.Format+videoDimensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B81BE1BE26B936FF002696CC /* AVCaptureDevice.Format+videoDimensions.swift */; };
1314
B82FBA962614B69D00909718 /* RCTBridge+runOnJS.mm in Sources */ = {isa = PBXBuildFile; fileRef = B82FBA952614B69D00909718 /* RCTBridge+runOnJS.mm */; };
1415
B84760A62608EE7C004C3180 /* FrameHostObject.mm in Sources */ = {isa = PBXBuildFile; fileRef = B84760A52608EE7C004C3180 /* FrameHostObject.mm */; };
1516
B84760DF2608F57D004C3180 /* CameraQueues.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84760DE2608F57D004C3180 /* CameraQueues.swift */; };
@@ -84,6 +85,7 @@
8485
B8103E1B25FF553B007A1684 /* FrameProcessorUtils.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FrameProcessorUtils.mm; sourceTree = "<group>"; };
8586
B8103E1E25FF5550007A1684 /* FrameProcessorUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FrameProcessorUtils.h; sourceTree = "<group>"; };
8687
B8103E5725FF56F0007A1684 /* Frame.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Frame.h; sourceTree = "<group>"; };
88+
B81BE1BE26B936FF002696CC /* AVCaptureDevice.Format+videoDimensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AVCaptureDevice.Format+videoDimensions.swift"; sourceTree = "<group>"; };
8789
B81D41EF263C86F900B041FD /* JSIUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSIUtils.h; sourceTree = "<group>"; };
8890
B82FBA942614B69D00909718 /* RCTBridge+runOnJS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTBridge+runOnJS.h"; sourceTree = "<group>"; };
8991
B82FBA952614B69D00909718 /* RCTBridge+runOnJS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "RCTBridge+runOnJS.mm"; sourceTree = "<group>"; };
@@ -197,6 +199,7 @@
197199
B882720F26AEB1A100B14107 /* AVCaptureConnection+setInterfaceOrientation.swift */,
198200
B887516325E0102000DB86D6 /* AVCaptureDevice+neutralZoom.swift */,
199201
B887516425E0102000DB86D6 /* AVCaptureDevice.Format+isBetterThan.swift */,
202+
B81BE1BE26B936FF002696CC /* AVCaptureDevice.Format+videoDimensions.swift */,
200203
B887516525E0102000DB86D6 /* AVCaptureDevice+isMultiCam.swift */,
201204
B887516625E0102000DB86D6 /* AVCaptureDevice+physicalDevices.swift */,
202205
B887516725E0102000DB86D6 /* AVFrameRateRange+includes.swift */,
@@ -369,6 +372,7 @@
369372
files = (
370373
B86DC974260E310600FB17B2 /* CameraView+AVAudioSession.swift in Sources */,
371374
B887518625E0102000DB86D6 /* CameraView+RecordVideo.swift in Sources */,
375+
B81BE1BF26B936FF002696CC /* AVCaptureDevice.Format+videoDimensions.swift in Sources */,
372376
B8DB3BCA263DC4D8004C18D7 /* RecordingSession.swift in Sources */,
373377
B88751A225E0102000DB86D6 /* AVCaptureColorSpace+descriptor.swift in Sources */,
374378
B887518925E0102000DB86D6 /* Collection+safe.swift in Sources */,

0 commit comments

Comments
 (0)