use crate::container::bmff::BoxType;
pub(crate) const TOP_LEVEL_COPIED: [BoxType; 2] = [*b"ftyp", *b"mdat"];
pub(crate) const FRAGMENT_BOXES: [BoxType; 6] =
[*b"moof", *b"mfra", *b"mvex", *b"styp", *b"sidx", *b"ssix"];
pub(crate) const FRAGMENT_BRANDS: [BoxType; 5] = [*b"dash", *b"msdh", *b"msix", *b"cmfc", *b"cmfl"];
pub(crate) const PROTECTION_BOXES: [BoxType; 4] = [*b"pssh", *b"senc", *b"sinf", *b"schm"];
pub(crate) const PROTECTED_SAMPLE_ENTRIES: [BoxType; 6] =
[*b"encv", *b"enca", *b"encs", *b"enct", *b"drms", *b"drmi"];
pub(crate) const MP4_BRANDS: [BoxType; 9] = [
*b"isom", *b"iso2", *b"iso4", *b"iso5", *b"iso6", *b"mp41", *b"mp42", *b"mmp4", *b"avc1",
];
pub(crate) const M4A_BRANDS: [BoxType; 2] = [*b"M4A ", *b"M4B "];
pub(crate) const MP4_BRANDS_VIDEO: [BoxType; 1] = [*b"M4V "];
pub(crate) const PROTECTED_BRAND: BoxType = *b"M4P ";
pub(crate) const QUICKTIME_BRAND: BoxType = *b"qt ";
pub(crate) const MOOV_KEPT: [BoxType; 2] = [*b"mvhd", *b"trak"];
pub(crate) const TRAK_KEPT: [BoxType; 4] = [*b"tkhd", *b"edts", *b"tref", *b"mdia"];
pub(crate) const MDIA_KEPT: [BoxType; 3] = [*b"mdhd", *b"hdlr", *b"minf"];
pub(crate) const MINF_KEPT: [BoxType; 6] =
[*b"vmhd", *b"smhd", *b"hmhd", *b"sthd", *b"nmhd", *b"stbl"];
pub(crate) const MINF_DINF: BoxType = *b"dinf";
pub(crate) const STBL_KEPT: [BoxType; 15] = [
*b"stsd", *b"stts", *b"ctts", *b"cslg", *b"stss", *b"stsh", *b"sdtp", *b"stsc", *b"stsz", *b"stz2", *b"stco", *b"co64", *b"sbgp", *b"sgpd", *b"stps", ];
pub(crate) const STCO: BoxType = *b"stco";
pub(crate) const CO64: BoxType = *b"co64";
pub(crate) const XMP_UUID: [u8; 16] = [
0xBE, 0x7A, 0xCF, 0xCB, 0x97, 0xA9, 0x42, 0xE8, 0x9C, 0x71, 0x99, 0x94, 0x91, 0xE3, 0xAF, 0xAC,
];
pub(crate) fn kept_in(parent: BoxType, kind: BoxType) -> bool {
match &parent {
b"moov" => MOOV_KEPT.contains(&kind),
b"trak" => TRAK_KEPT.contains(&kind),
b"mdia" => MDIA_KEPT.contains(&kind),
b"minf" => MINF_KEPT.contains(&kind) || kind == MINF_DINF,
b"stbl" => STBL_KEPT.contains(&kind),
_ => false,
}
}
pub(crate) fn is_container(kind: BoxType) -> bool {
matches!(&kind, b"moov" | b"trak" | b"mdia" | b"minf" | b"stbl")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn an_unknown_box_is_kept_at_no_level() {
for parent in [*b"moov", *b"trak", *b"mdia", *b"minf", *b"stbl"] {
assert!(!kept_in(parent, *b"XPRV"));
assert!(!kept_in(parent, *b"uuid"));
assert!(!kept_in(parent, *b"udta"));
assert!(!kept_in(parent, *b"meta"));
assert!(!kept_in(parent, *b"free"));
}
}
#[test]
fn the_boxes_a_playable_file_needs_are_kept() {
assert!(kept_in(*b"moov", *b"trak"));
assert!(kept_in(*b"trak", *b"mdia"));
assert!(kept_in(*b"mdia", *b"minf"));
assert!(kept_in(*b"minf", *b"stbl"));
assert!(kept_in(*b"minf", *b"dinf"));
assert!(kept_in(*b"stbl", STCO));
assert!(kept_in(*b"stbl", CO64));
}
#[test]
fn the_protection_signals_do_not_overlap_the_keep_lists() {
for kind in PROTECTION_BOXES {
for parent in [*b"moov", *b"trak", *b"mdia", *b"minf", *b"stbl"] {
assert!(!kept_in(parent, kind), "{kind:?} under {parent:?}");
}
}
}
#[test]
fn a_container_is_filtered_and_a_leaf_is_not() {
assert!(is_container(*b"stbl"));
assert!(!is_container(*b"stsd"));
assert!(!is_container(*b"mdat"));
}
}