use objc2_core_foundation::CFRetained;
use objc2_core_media::CMSampleBuffer;
use objc2_core_video::{CVImageBuffer, CVPixelBuffer, CVPixelBufferGetHeight, CVPixelBufferGetWidth};
use crate::frame::Frame;
use crate::frame::macos::Surface;
pub(super) fn surface_frame(sample_buffer: &CMSampleBuffer) -> Option<Frame> {
let image: CFRetained<CVImageBuffer> = unsafe { sample_buffer.image_buffer() }?;
let pixel: CFRetained<CVPixelBuffer> = unsafe { CFRetained::from_raw(CFRetained::into_raw(image).cast()) };
let width = CVPixelBufferGetWidth(&pixel) as u32;
let height = CVPixelBufferGetHeight(&pixel) as u32;
Some(Frame::Surface(Surface::new(pixel, width, height)))
}