mod bits;
mod cabac;
mod decode;
mod error;
mod filter;
mod frame;
mod intra;
mod nal;
mod picture;
mod ps;
mod scan;
mod slice;
mod transform;
#[cfg(any(test, feature = "bench"))]
#[doc(hidden)]
pub mod synth;
#[cfg(feature = "bench")]
#[doc(hidden)]
pub mod bench_api;
#[cfg(test)]
mod golden;
#[cfg(test)]
mod golden_422;
#[cfg(test)]
mod golden_444;
pub use frame::{ChromaFormat, Frame, Info, VideoSignal};
#[cfg(test)]
use nal::split_annexb;
use crate::error::Result;
pub fn decode_still(parameter_sets: &[&[u8]], slices: &[&[u8]]) -> Result<Frame> {
let sets = decode::ParameterSets::parse(parameter_sets)?;
Ok(decode::decode(&sets, slices)?)
}
pub fn probe(parameter_sets: &[&[u8]]) -> Result<Info> {
let sets = decode::ParameterSets::parse(parameter_sets)?;
let sps = sets.first_sps()?;
let [l, r, t, b] = sps.crop;
Ok(Info {
width: sps.width.saturating_sub(l + r).max(1) as u32,
height: sps.height.saturating_sub(t + b).max(1) as u32,
bit_depth: sps.bit_depth_y,
chroma: ChromaFormat::from_idc(sps.chroma_array_type).unwrap_or(ChromaFormat::Monochrome),
})
}
pub fn video_signal(parameter_sets: &[&[u8]]) -> Result<Option<VideoSignal>> {
let sets = decode::ParameterSets::parse(parameter_sets)?;
Ok(sets.first_sps()?.video_signal)
}
#[cfg(test)]
pub(crate) fn decode_annexb(stream: &[u8]) -> Result<Frame> {
use alloc::vec::Vec;
let units = split_annexb(stream);
let mut sets: Vec<&[u8]> = Vec::new();
let mut slices: Vec<&[u8]> = Vec::new();
for u in units {
let Ok(h) = nal::NalHeader::parse(u) else {
continue;
};
if h.is_vcl() {
slices.push(u);
} else if matches!(h.nal_unit_type, 32..=34) {
sets.push(u);
}
}
decode_still(&sets, &slices)
}