forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

sei_sweep.rs98 lines, 3.6 KiBHistoryRawDownload
1//! The SEI reader over the JCT-VC conformance streams.
2//!
3//! Every prefix and suffix SEI NAL unit of every stream must parse without error,
4//! and the streams that carry a `decoded_picture_hash` are counted. The sweep is
5//! skipped when the vectors are absent, unless `EC_REQUIRE_FIXTURES` is set, in
6//! which case an absent fixture fails the test.
7
8use std::path::{Path, PathBuf};
9
10use ec_h265_syntax::nal::split_annex_b;
11use ec_h265_syntax::sei::{SeiMessage, parse_sei_rbsp};
12
13/// Every `.bin` or `.bit` stream under `fixtures/vectors/hevc-jctvc`, two directory
14/// levels deep, sorted by path. `EC_H265_JCTVC_DIR` overrides the root.
15fn streams() -> Vec<PathBuf> {
16 let root = match std::env::var("EC_H265_JCTVC_DIR") {
17 Ok(dir) => PathBuf::from(dir),
18 Err(_) => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures/vectors/hevc-jctvc"),
19 };
20 fn walk(dir: &Path, depth: u32, out: &mut Vec<PathBuf>) {
21 let Ok(entries) = std::fs::read_dir(dir) else {
22 return;
23 };
24 let mut paths: Vec<PathBuf> = entries.filter_map(|e| e.ok().map(|e| e.path())).collect();
25 paths.sort();
26 for p in paths {
27 if p.is_dir() && depth > 0 {
28 walk(&p, depth - 1, out);
29 } else if matches!(p.extension().and_then(|x| x.to_str()), Some("bin" | "bit")) {
30 out.push(p);
31 }
32 }
33 }
34 let mut out = Vec::new();
35 walk(&root, 2, &mut out);
36 out
37}
38
39#[test]
40fn every_sei_in_the_conformance_streams_parses() {
41 let streams = streams();
42 if streams.is_empty() {
43 assert!(
44 std::env::var_os("EC_REQUIRE_FIXTURES").is_none(),
45 "EC_REQUIRE_FIXTURES=1 but fixtures/vectors/hevc-jctvc has no streams"
46 );
47 eprintln!("SEI sweep skipped: vectors absent");
48 return;
49 }
50 let mut with_hash = 0usize;
51 let mut hash_streams = Vec::new();
52 let mut sei_nals = 0usize;
53 let mut messages = 0usize;
54 let mut hashes = 0usize;
55 let mut failures = Vec::new();
56 for path in &streams {
57 let name = path.file_name().unwrap_or_default().to_string_lossy().to_string();
58 let data = match std::fs::read(path) {
59 Ok(d) => d,
60 Err(e) => {
61 failures.push(format!("{name}: read: {e}"));
62 continue;
63 }
64 };
65 let mut stream_hashes = 0usize;
66 for nal in split_annex_b(&data) {
67 if nal.header.layer_id > 0 || !matches!(nal.header.nal_type.code(), 39 | 40) {
68 continue;
69 }
70 sei_nals += 1;
71 match parse_sei_rbsp(&nal.rbsp()) {
72 Ok(msgs) => {
73 messages += msgs.len();
74 for msg in &msgs {
75 if matches!(msg, SeiMessage::DecodedPictureHash(_)) {
76 stream_hashes += 1;
77 }
78 }
79 }
80 Err(e) => failures.push(format!("{name}: SEI NAL #{sei_nals}: {e}")),
81 }
82 }
83 if stream_hashes > 0 {
84 with_hash += 1;
85 hash_streams.push(name.clone());
86 }
87 hashes += stream_hashes;
88 }
89 eprintln!(
90 "SEI sweep: {} streams, {with_hash} carry decoded_picture_hash ({hashes} hash messages), \
91 {sei_nals} SEI NAL units, {messages} messages, {} parse failures",
92 streams.len(),
93 failures.len()
94 );
95 eprintln!("streams with decoded_picture_hash: {}", hash_streams.join(" "));
96 assert!(failures.is_empty(), "SEI that failed to parse:\n{}", failures.join("\n"));
97 assert!(with_hash > 0, "no conformance stream carries decoded_picture_hash SEI");
98}