1pub fn is_nalu(data: &[u8]) -> bool {
2 if data.len() < 3 {
3 return false;
4 }
5
6 data.windows(3).any(|window| match window {
7 [0x00, 0x00, 0x01] => true,
8 [0x00, 0x00, 0x00] if data.len() >= 4 && data[3] == 0x01 => true,
9 _ => false,
10 })
11}
12
13#[cfg(test)]
14mod tests {
15 use super::*;
16
17 #[test]
18 fn test_nalu_detection() {
19 assert!(is_nalu(&[0x00, 0x00, 0x01, 0x09, 0xFF]));
21 assert!(is_nalu(&[0x00, 0x00, 0x00, 0x01, 0x09, 0xFF]));
22
23 assert!(is_nalu(&[0xFF, 0xFF, 0x00, 0x00, 0x01, 0x09]));
25 assert!(is_nalu(&[0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x09]));
26
27 assert!(is_nalu(&[0xFF, 0xFF, 0x00, 0x00, 0x01]));
29 assert!(is_nalu(&[0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01]));
30
31 assert!(is_nalu(&[
33 0xFF, 0x00, 0x00, 0x01, 0x09, 0x00, 0x00, 0x00, 0x01
34 ]));
35
36 assert!(!is_nalu(&[0x00, 0x01, 0x00, 0x01]));
38 assert!(!is_nalu(&[0xFF, 0xFF, 0xFF, 0xFF]));
39
40 assert!(!is_nalu(&[0x00, 0x00]));
42 assert!(!is_nalu(&[]));
43
44 assert!(!is_nalu(&[0xFF, 0x00, 0x00]));
46 assert!(!is_nalu(&[0xFF, 0x00, 0x00, 0x00]));
47 }
48}