use crate::container::bmff::BoxType;
pub(crate) const TOP_LEVEL_KEPT: [BoxType; 2] = [*b"ftyp", *b"meta"];
pub(crate) const META_KEPT: [BoxType; 7] = [
*b"hdlr", *b"pitm", *b"iloc", *b"iinf", *b"iref", *b"iprp", *b"dinf",
];
pub(crate) const MOTION_BOXES: [BoxType; 4] = [*b"moov", *b"moof", *b"mfra", *b"mvex"];
pub(crate) const SEQUENCE_BRANDS: [BoxType; 2] = [*b"msf1", *b"hevc"];
pub(crate) const IMAGE_ITEM_TYPES: [BoxType; 8] = [
*b"av01", *b"hvc1", *b"hev1", *b"vvc1", *b"unci", *b"jpeg", *b"grid", *b"iovl", ];
pub(crate) const PROPERTIES_KEPT: [BoxType; 15] = [
*b"ispe", *b"pixi", *b"av1C", *b"hvcC", *b"vvcC", *b"pasp", *b"clap", *b"irot", *b"imir", *b"auxC", *b"a1op", *b"a1lx", *b"lsel", *b"clli", *b"mdcv", ];
pub(crate) const COLOUR_TYPE_NCLX: [u8; 4] = *b"nclx";
pub(crate) const REFERENCE_TYPES_KEPT: [BoxType; 2] = [*b"dimg", *b"auxl"];
pub(crate) const REFERENCE_THUMBNAIL: BoxType = *b"thmb";
pub(crate) fn top_level_kept(kind: BoxType) -> bool {
TOP_LEVEL_KEPT.contains(&kind)
}
pub(crate) fn meta_kept(kind: BoxType) -> bool {
META_KEPT.contains(&kind)
}
pub(crate) fn is_image_item(kind: BoxType) -> bool {
IMAGE_ITEM_TYPES.contains(&kind)
}
pub(crate) fn property_kept(kind: BoxType, payload: &[u8]) -> bool {
if &kind == b"colr" {
return payload.get(..4) == Some(&COLOUR_TYPE_NCLX);
}
PROPERTIES_KEPT.contains(&kind)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn an_unknown_item_type_is_not_an_image_item() {
assert!(!is_image_item(*b"XPRV"));
assert!(!is_image_item(*b"Exif"));
assert!(is_image_item(*b"av01"));
}
#[test]
fn an_unknown_property_is_not_kept() {
assert!(!property_kept(*b"udes", b""));
assert!(!property_kept(*b"XPRV", b"anything"));
assert!(property_kept(*b"ispe", b""));
}
#[test]
fn an_icc_profile_is_removed_and_numeric_colour_signalling_is_kept() {
assert!(property_kept(*b"colr", b"nclx\x00\x01\x00\x0d\x00\x01\x80"));
assert!(!property_kept(*b"colr", b"prof\x00\x00\x02\x0c"));
assert!(!property_kept(*b"colr", b"rICC\x00\x00\x02\x0c"));
assert!(!property_kept(*b"colr", b"ncl"));
assert!(!property_kept(*b"colr", b""));
}
#[test]
fn a_uuid_box_is_not_kept_at_any_level() {
assert!(!top_level_kept(*b"uuid"));
assert!(!meta_kept(*b"uuid"));
assert!(!top_level_kept(*b"free"));
assert!(!top_level_kept(*b"skip"));
}
}