use std::{ffi::c_void, time::Duration};
#[cfg(target_os = "android")]
use super::image_reader::Image;
#[cfg(any(target_os = "macos", target_os = "ios"))]
use super::pixel_buffer::Image;
#[cfg(not(any(target_os = "android", target_os = "macos", target_os = "ios")))]
use super::unavailable::Image;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct FrameInfo {
pub timestamp: Duration,
pub metadata: u64,
pub decode_time: Duration,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct CropRect {
pub x: u32,
pub y: u32,
pub width: u32,
pub height: u32,
}
pub struct VideoFrame {
info: FrameInfo,
size: (u32, u32),
crop: CropRect,
image: Image,
}
impl VideoFrame {
#[cfg(any(target_os = "android", target_os = "macos", target_os = "ios"))]
pub(super) fn new(info: FrameInfo, size: (u32, u32), crop: CropRect, image: Image) -> Self {
Self {
info,
size,
crop,
image,
}
}
pub fn info(&self) -> FrameInfo {
self.info
}
pub fn size(&self) -> (u32, u32) {
self.size
}
pub fn crop(&self) -> CropRect {
self.crop
}
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
pub fn as_hardware_buffer_ptr(&self) -> *mut c_void {
self.image.hardware_buffer()
}
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub fn as_pixel_buffer_ptr(&self) -> *mut c_void {
self.image.pixel_buffer()
}
}
impl std::fmt::Debug for VideoFrame {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("VideoFrame")
.field("info", &self.info)
.field("size", &self.size)
.field("crop", &self.crop)
.finish_non_exhaustive()
}
}