@@ -5,16 +5,23 @@ import Foundation
5
5
/// An object that provides the interface to control the AVCaptureDevice's transport behavior.
6
6
@available ( tvOS 17 . 0 , * )
7
7
public class IOVideoCaptureUnit : IOCaptureUnit {
8
- /// The default videoSettings for a device.
9
- public static let defaultVideoSettings : [ NSString : AnyObject ] = [
10
- kCVPixelBufferPixelFormatTypeKey: NSNumber ( value: kCVPixelFormatType_32BGRA)
11
- ]
8
+ #if os(iOS) || os(macOS)
9
+ /// The default color format.
10
+ public static let colorFormat = kCVPixelFormatType_32BGRA
11
+ #else
12
+ /// The default color format.
13
+ public static let colorFormat = kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
14
+ #endif
12
15
13
16
typealias Output = AVCaptureVideoDataOutput
14
17
15
18
/// The current video device object.
16
19
public private( set) var device : AVCaptureDevice ?
17
20
21
+ /// Specifies the video capture color format.
22
+ /// - Warning: If a format other than kCVPixelFormatType_32BGRA is set, the multi-camera feature will become unavailable. We intend to support this in the future.
23
+ public var colorFormat = IOVideoCaptureUnit . colorFormat
24
+
18
25
#if os(iOS) || os(macOS)
19
26
/// Specifies the videoOrientation indicates whether to rotate the video flowing through the connection to a given orientation.
20
27
public var videoOrientation : AVCaptureVideoOrientation = . portrait {
@@ -53,15 +60,11 @@ public class IOVideoCaptureUnit: IOCaptureUnit {
53
60
return
54
61
}
55
62
output. alwaysDiscardsLateVideoFrames = true
56
- #if os(iOS) || os(macOS)
57
- if output. availableVideoPixelFormatTypes. contains ( kCVPixelFormatType_32BGRA) {
58
- output. videoSettings = IOVideoCaptureUnit . defaultVideoSettings as [ String : Any ]
59
- }
60
- #elseif os(tvOS)
61
- if output. availableVideoPixelFormatTypes. contains ( kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange) {
62
- output. videoSettings = [ kCVPixelBufferPixelFormatTypeKey as String : NSNumber ( value: kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange) ]
63
+ if output. availableVideoPixelFormatTypes. contains ( colorFormat) {
64
+ output. videoSettings = [ kCVPixelBufferPixelFormatTypeKey as String : NSNumber ( value: colorFormat) ]
65
+ } else {
66
+ logger. warn ( " device doesn't support this color format " , colorFormat, " . " )
63
67
}
64
- #endif
65
68
}
66
69
}
67
70
var connection : AVCaptureConnection ?
0 commit comments