use super::options::PixelLayout;
pub struct VideoFrame {
width: u32,
height: u32,
layout: PixelLayout,
pts_us: Option<i64>,
index: u64,
data: Vec<u8>,
}
impl VideoFrame {
pub(crate) fn new(
width: u32,
height: u32,
layout: PixelLayout,
pts_us: Option<i64>,
index: u64,
data: Vec<u8>,
) -> Self {
debug_assert_eq!(
data.len(),
width as usize * height as usize * layout.bytes_per_pixel(),
"VideoFrame buffer must be tightly packed"
);
Self {
width,
height,
layout,
pts_us,
index,
data,
}
}
pub fn width(&self) -> u32 {
self.width
}
pub fn height(&self) -> u32 {
self.height
}
pub fn layout(&self) -> PixelLayout {
self.layout
}
pub fn pts_us(&self) -> Option<i64> {
self.pts_us
}
pub fn index(&self) -> u64 {
self.index
}
pub fn as_bytes(&self) -> &[u8] {
&self.data
}
pub fn into_vec(self) -> Vec<u8> {
self.data
}
pub fn row_bytes(&self) -> usize {
self.width as usize * self.layout.bytes_per_pixel()
}
}
impl std::fmt::Debug for VideoFrame {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("VideoFrame")
.field("width", &self.width)
.field("height", &self.height)
.field("layout", &self.layout)
.field("pts_us", &self.pts_us)
.field("index", &self.index)
.field("bytes", &self.data.len())
.finish()
}
}