pub fn is_nalu(data: &[u8]) -> bool {
if data.len() < 3 {
return false;
}
data.windows(3).any(|window| match window {
[0x00, 0x00, 0x01] => true,
[0x00, 0x00, 0x00] if data.len() >= 4 && data[3] == 0x01 => true,
_ => false,
})
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_nalu_detection() {
assert!(is_nalu(&[0x00, 0x00, 0x01, 0x09, 0xFF]));
assert!(is_nalu(&[0x00, 0x00, 0x00, 0x01, 0x09, 0xFF]));
assert!(is_nalu(&[0xFF, 0xFF, 0x00, 0x00, 0x01, 0x09]));
assert!(is_nalu(&[0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x09]));
assert!(is_nalu(&[0xFF, 0xFF, 0x00, 0x00, 0x01]));
assert!(is_nalu(&[0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01]));
assert!(is_nalu(&[
0xFF, 0x00, 0x00, 0x01, 0x09, 0x00, 0x00, 0x00, 0x01
]));
assert!(!is_nalu(&[0x00, 0x01, 0x00, 0x01]));
assert!(!is_nalu(&[0xFF, 0xFF, 0xFF, 0xFF]));
assert!(!is_nalu(&[0x00, 0x00]));
assert!(!is_nalu(&[]));
assert!(!is_nalu(&[0xFF, 0x00, 0x00]));
assert!(!is_nalu(&[0xFF, 0x00, 0x00, 0x00]));
}
}