use crate::PixelFormat;
use crate::Rational;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct VideoParamsPod {
pub width: i32,
pub height: i32,
pub time_base_num: i32,
pub time_base_den: i32,
pub format: i32,
pub pixel_aspect_num: i32,
pub pixel_aspect_den: i32,
pub interlacing: i32,
pub color_range: i32,
pub divider: i32,
pub video_type: i32,
pub premultiplied_alpha: i32,
}
impl Default for VideoParamsPod {
fn default() -> Self {
Self {
width: 0,
height: 0,
time_base_num: 1,
time_base_den: 1,
format: PixelFormat::F32 as i32,
pixel_aspect_num: 1,
pixel_aspect_den: 1,
interlacing: 0,
color_range: 0,
divider: 1,
video_type: 0,
premultiplied_alpha: 0,
}
}
}
impl VideoParamsPod {
pub const DEFAULT_WIDTH: i32 = 1920;
pub const DEFAULT_HEIGHT: i32 = 1080;
pub fn frame_rate(&self) -> Rational {
if self.time_base_num <= 0 || self.time_base_den <= 0 {
return Rational::NULL;
}
Rational::new(self.time_base_den as i64, self.time_base_num as i64)
}
pub fn time_base(&self) -> Rational {
if self.time_base_num <= 0 || self.time_base_den <= 0 {
return Rational::NULL;
}
Rational::new(self.time_base_num as i64, self.time_base_den as i64)
}
pub const INTERNAL_CHANNEL_COUNT: i32 = 4;
pub fn effective_width(&self) -> i32 {
(self.width / self.divider.max(1)).max(0)
}
pub fn effective_height(&self) -> i32 {
(self.height / self.divider.max(1)).max(0)
}
}
#[cfg(test)]
mod tests {
use crate::PixelFormat;
use super::*;
#[test]
fn pod_defaults() {
let p = VideoParamsPod::default();
assert_eq!(p.format, PixelFormat::F32 as i32);
assert_eq!(p.time_base(), Rational::new(1, 1));
}
#[test]
fn effective_size_honors_divider() {
let mut p = VideoParamsPod::default();
p.width = 3840;
p.height = 2160;
p.divider = 2;
assert_eq!(p.effective_width(), 1920);
assert_eq!(p.effective_height(), 1080);
}
#[test]
fn frame_rate_is_flipped_time_base() {
let mut p = VideoParamsPod::default();
p.time_base_num = 1001;
p.time_base_den = 30000;
assert_eq!(p.frame_rate(), Rational::new(30000, 1001));
assert_eq!(p.time_base(), Rational::new(1001, 30000));
}
}