| 
									
										
										
										
											2021-02-19 16:28:05 +01:00
										 |  |  | // | 
					
						
							|  |  |  | //  AVCaptureDevice.Format+toDictionary.swift | 
					
						
							| 
									
										
										
										
											2021-06-21 22:42:46 +02:00
										 |  |  | //  mrousavy | 
					
						
							| 
									
										
										
										
											2021-02-19 16:28:05 +01:00
										 |  |  | // | 
					
						
							|  |  |  | //  Created by Marc Rousavy on 15.01.21. | 
					
						
							| 
									
										
										
										
											2021-06-01 13:07:57 +02:00
										 |  |  | //  Copyright © 2021 mrousavy. All rights reserved. | 
					
						
							| 
									
										
										
										
											2021-02-19 16:28:05 +01:00
										 |  |  | // | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import AVFoundation | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | extension AVCaptureDevice.Format { | 
					
						
							|  |  |  |   var videoStabilizationModes: [AVCaptureVideoStabilizationMode] { | 
					
						
							| 
									
										
										
										
											2023-10-13 18:33:20 +02:00
										 |  |  |     let allModes = AVCaptureDevice.Format.getAllVideoStabilizationModes() | 
					
						
							|  |  |  |     return allModes.filter { self.isVideoStabilizationModeSupported($0) } | 
					
						
							| 
									
										
										
										
											2021-02-19 16:28:05 +01:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-13 18:33:20 +02:00
										 |  |  |   var minFps: Float64 { | 
					
						
							| 
									
										
										
										
											2023-12-04 13:41:56 +03:00
										 |  |  |     let minRange = videoSupportedFrameRateRanges.min { l, r in | 
					
						
							|  |  |  |       return l.minFrameRate < r.minFrameRate | 
					
						
							| 
									
										
										
										
											2023-08-21 12:50:14 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-12-04 13:41:56 +03:00
										 |  |  |     return minRange?.minFrameRate ?? 0 | 
					
						
							| 
									
										
										
										
											2023-08-21 12:50:14 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-13 18:33:20 +02:00
										 |  |  |   var maxFps: Float64 { | 
					
						
							| 
									
										
										
										
											2023-08-21 12:50:14 +02:00
										 |  |  |     let maxRange = videoSupportedFrameRateRanges.max { l, r in | 
					
						
							|  |  |  |       return l.maxFrameRate < r.maxFrameRate | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return maxRange?.maxFrameRate ?? 0 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-15 18:33:12 +01:00
										 |  |  |   var supportsVideoHdr: Bool { | 
					
						
							| 
									
										
										
										
											2023-10-06 16:11:09 +02:00
										 |  |  |     let pixelFormat = CMFormatDescriptionGetMediaSubType(formatDescription) | 
					
						
							|  |  |  |     let hdrFormats = [ | 
					
						
							|  |  |  |       kCVPixelFormatType_420YpCbCr10BiPlanarFullRange, | 
					
						
							|  |  |  |       kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange, | 
					
						
							| 
									
										
										
										
											2023-11-22 16:19:29 +01:00
										 |  |  |       kCVPixelFormatType_Lossy_420YpCbCr10PackedBiPlanarVideoRange, | 
					
						
							| 
									
										
										
										
											2023-10-06 16:11:09 +02:00
										 |  |  |     ] | 
					
						
							|  |  |  |     return hdrFormats.contains(pixelFormat) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-15 18:33:12 +01:00
										 |  |  |   var supportsPhotoHdr: Bool { | 
					
						
							| 
									
										
										
										
											2023-10-13 18:33:20 +02:00
										 |  |  |     // TODO: Supports Photo HDR on iOS? | 
					
						
							|  |  |  |     return false | 
					
						
							| 
									
										
										
										
											2021-02-19 16:28:05 +01:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-10-06 16:11:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-13 18:33:20 +02:00
										 |  |  |   var supportsDepthCapture: Bool { | 
					
						
							|  |  |  |     return !supportedDepthDataFormats.isEmpty | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-10-06 16:11:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-13 18:33:20 +02:00
										 |  |  |   private static func getAllVideoStabilizationModes() -> [AVCaptureVideoStabilizationMode] { | 
					
						
							|  |  |  |     var modes: [AVCaptureVideoStabilizationMode] = [.auto, .cinematic, .off, .standard] | 
					
						
							|  |  |  |     if #available(iOS 13, *) { | 
					
						
							|  |  |  |       modes.append(.cinematicExtended) | 
					
						
							| 
									
										
										
										
											2023-10-06 16:11:09 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-10-13 18:33:20 +02:00
										 |  |  |     return modes | 
					
						
							| 
									
										
										
										
											2023-10-06 16:11:09 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-02-19 16:28:05 +01:00
										 |  |  | } |