use crate::PixelFormat;
use objc2_core_video::{
CVPixelBufferGetHeight, CVPixelBufferGetHeightOfPlane, CVPixelBufferGetWidth,
CVPixelBufferGetWidthOfPlane,
};
use super::MacOsVideoFrame;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MetalPlaneFormat {
R8Unorm,
Rg8Unorm,
Bgra8Unorm,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MetalPlaneDescriptor {
pub plane_index: usize,
pub width: usize,
pub height: usize,
pub format: MetalPlaneFormat,
}
impl MacOsVideoFrame {
pub fn metal_planes(&self) -> Vec<MetalPlaneDescriptor> {
use crate::DecodedSurface;
match self.pixel_format() {
PixelFormat::Nv12VideoRange | PixelFormat::Nv12FullRange => vec![
MetalPlaneDescriptor {
plane_index: 0,
width: CVPixelBufferGetWidthOfPlane(self.pixel_buffer(), 0),
height: CVPixelBufferGetHeightOfPlane(self.pixel_buffer(), 0),
format: MetalPlaneFormat::R8Unorm,
},
MetalPlaneDescriptor {
plane_index: 1,
width: CVPixelBufferGetWidthOfPlane(self.pixel_buffer(), 1),
height: CVPixelBufferGetHeightOfPlane(self.pixel_buffer(), 1),
format: MetalPlaneFormat::Rg8Unorm,
},
],
PixelFormat::Bgra8 => vec![MetalPlaneDescriptor {
plane_index: 0,
width: CVPixelBufferGetWidth(self.pixel_buffer()),
height: CVPixelBufferGetHeight(self.pixel_buffer()),
format: MetalPlaneFormat::Bgra8Unorm,
}],
PixelFormat::Native(_) => Vec::new(),
}
}
}