use yuv::color::ChromaSampling;
use yuv::color::Depth;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProfileConstraint {
pub max_bit_depth: Depth,
pub chroma_formats: Vec<ChromaSampling>,
}
impl ProfileConstraint {
pub fn new(max_bit_depth: Depth, chroma_formats: Vec<ChromaSampling>) -> Self {
Self {
max_bit_depth,
chroma_formats,
}
}
pub fn max_chroma_format(&self) -> ChromaSampling {
if self.chroma_formats.contains(&ChromaSampling::Cs444) {
ChromaSampling::Cs444
} else if self.chroma_formats.contains(&ChromaSampling::Cs422) {
ChromaSampling::Cs422
} else if self.chroma_formats.contains(&ChromaSampling::Cs420) {
ChromaSampling::Cs420
} else {
ChromaSampling::Monochrome
}
}
pub fn supports_chroma_format(&self, chroma_format: ChromaSampling) -> bool {
self.chroma_formats.contains(&chroma_format)
}
pub fn supports_mono_chrome(&self) -> bool {
self.chroma_formats.contains(&ChromaSampling::Monochrome)
}
}
pub fn yuv_bitrate(
width: u32,
height: u32,
fps: f32,
subsampling: ChromaSampling,
bit_depth: Depth,
) -> f32 {
let pixels = width * height;
dbg!(pixels);
let bpp = match subsampling {
ChromaSampling::Cs444 => {
3 * bit_depth as u32
}
ChromaSampling::Cs422 => {
(2 * bit_depth as u32) + (bit_depth as u32)
}
ChromaSampling::Cs420 => {
(bit_depth as u32) + (bit_depth as u32 / 2)
}
ChromaSampling::Monochrome => {
bit_depth as u32
}
};
(pixels as f32 * bpp as f32 * fps) / 1000.0
}