Skip to content

Commit ae1d215

Browse files
authored
Merge pull request #1332 from shogo4405/feature/color-format
IOVideoCaptureUnit#colorFormat property
2 parents 4b9e24f + 2dda932 commit ae1d215

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

Sources/Media/IOVideoCaptureUnit.swift

+15-12
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,23 @@ import Foundation
55
/// An object that provides the interface to control the AVCaptureDevice's transport behavior.
66
@available(tvOS 17.0, *)
77
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
1215

1316
typealias Output = AVCaptureVideoDataOutput
1417

1518
/// The current video device object.
1619
public private(set) var device: AVCaptureDevice?
1720

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+
1825
#if os(iOS) || os(macOS)
1926
/// Specifies the videoOrientation indicates whether to rotate the video flowing through the connection to a given orientation.
2027
public var videoOrientation: AVCaptureVideoOrientation = .portrait {
@@ -53,15 +60,11 @@ public class IOVideoCaptureUnit: IOCaptureUnit {
5360
return
5461
}
5562
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, ".")
6367
}
64-
#endif
6568
}
6669
}
6770
var connection: AVCaptureConnection?

0 commit comments

Comments
 (0)