use ffmpeg_the_third::ffi::{AVFrame, av_frame_free};
use libc::{fstat, stat};
use std::os::fd::RawFd;
#[derive(Debug)]
pub struct Nv12DmaBufFrame {
pub(crate) drm_frame: *mut AVFrame,
pub fd: RawFd, pub width: i32,
pub height: i32,
pub format_modifier: u64,
pub pitch_y: u32,
pub offset_y: u32,
pub pitch_uv: u32,
pub offset_uv: u32,
#[allow(unused)]
pub timestamp_ms: i64,
pub generation: u64,
}
impl Drop for Nv12DmaBufFrame {
fn drop(&mut self) {
unsafe {
if !self.drm_frame.is_null() {
av_frame_free(&mut self.drm_frame);
}
}
}
}
impl Nv12DmaBufFrame {
#[allow(unused)]
pub fn get_dma_buf_id(&self) -> Option<u64> {
unsafe {
let mut stat_buf: stat = std::mem::zeroed();
if fstat(self.fd, &mut stat_buf) == 0 {
Some(stat_buf.st_ino)
} else {
None
}
}
}
}
unsafe impl Send for Nv12DmaBufFrame {}