Skip to content

Commit

Permalink
Merge pull request #1332 from shogo4405/feature/color-format
Browse files Browse the repository at this point in the history
IOVideoCaptureUnit#colorFormat property
  • Loading branch information
shogo4405 authored Nov 3, 2023
2 parents 4b9e24f + 2dda932 commit ae1d215
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions Sources/Media/IOVideoCaptureUnit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@ import Foundation
/// An object that provides the interface to control the AVCaptureDevice's transport behavior.
@available(tvOS 17.0, *)
public class IOVideoCaptureUnit: IOCaptureUnit {
/// The default videoSettings for a device.
public static let defaultVideoSettings: [NSString: AnyObject] = [
kCVPixelBufferPixelFormatTypeKey: NSNumber(value: kCVPixelFormatType_32BGRA)
]
#if os(iOS) || os(macOS)
/// The default color format.
public static let colorFormat = kCVPixelFormatType_32BGRA
#else
/// The default color format.
public static let colorFormat = kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
#endif

typealias Output = AVCaptureVideoDataOutput

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

/// Specifies the video capture color format.
/// - 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.
public var colorFormat = IOVideoCaptureUnit.colorFormat

#if os(iOS) || os(macOS)
/// Specifies the videoOrientation indicates whether to rotate the video flowing through the connection to a given orientation.
public var videoOrientation: AVCaptureVideoOrientation = .portrait {
Expand Down Expand Up @@ -53,15 +60,11 @@ public class IOVideoCaptureUnit: IOCaptureUnit {
return
}
output.alwaysDiscardsLateVideoFrames = true
#if os(iOS) || os(macOS)
if output.availableVideoPixelFormatTypes.contains(kCVPixelFormatType_32BGRA) {
output.videoSettings = IOVideoCaptureUnit.defaultVideoSettings as [String: Any]
}
#elseif os(tvOS)
if output.availableVideoPixelFormatTypes.contains(kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange) {
output.videoSettings = [kCVPixelBufferPixelFormatTypeKey as String: NSNumber(value: kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange)]
if output.availableVideoPixelFormatTypes.contains(colorFormat) {
output.videoSettings = [kCVPixelBufferPixelFormatTypeKey as String: NSNumber(value: colorFormat)]
} else {
logger.warn("device doesn't support this color format ", colorFormat, ".")
}
#endif
}
}
var connection: AVCaptureConnection?
Expand Down

0 comments on commit ae1d215

Please sign in to comment.