forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiBdfeffbcTahinli2 months ago3180 commits

scratch_interdump.rs80 lines, 3.2 KiBHistoryRawDownload
1//! [scratch] Inter-frame syntax dump + count gate.
2//!
3//! Parses every frame of `INTER_IVF` (default `/tmp/inter1.ivf`, the clean
4//! single-tile stream the pinned counts refer to). Keyframes decode as usual;
5//! inter frames are parsed syntax-only (no reconstruction). With
6//! `EC_VP9_INTERDUMP=1` every block prints one `MODE` line in the oracle's
7//! shape, for a by-index diff. Point it at the two-tile-column stream
8//! (`INTER_IVF=/tmp/inter.ivf INTER_EXPECT=none`) to exercise the failing-
9//! keyframe path: that stream's keyframe desyncs its tile reader and the test
10//! is expected to fail there.
11//!
12//! This is a real gate, not a printer:
13//! - any frame error fails the test (keyframe failures are propagated too,
14//! because a half-updated frame context would make later dumps meaningless);
15//! - every inter frame's mode-info block count must equal `INTER_EXPECT`
16//! (default `1213,1851` - the pinned counts of the single-tile fixture
17//! `/tmp/inter1.ivf`, sha256 376532734662ba5faba4c4e97a5aac915ce429c11701bcf6
18//! 6439b61a77388fa8; set `INTER_EXPECT=none` for a different stream);
19//! - the crate already asserts `overreads() == 0` per tile reader at the end of
20//! each tile (decode.rs, "tile bool decoder desync"), which is what would fire
21//! if the walk read past the tile's last bool.
22//!
23//! ```text
24//! INTER_IVF=<file> EC_VP9_INTERDUMP=1 \
25//! cargo test -p ec-vp9 --test scratch_interdump -- --nocapture
26//! ```
27mod ivf;
28
29use ec_vp9::decode::Decoder;
30
31#[test]
32fn inter_syntax_dump() {
33 // An explicitly set INTER_IVF that does not exist is a failure; only the
34 // unset default may fall back to a loud SKIP (the fixture is generated,
35 // not committed).
36 let explicit = std::env::var("INTER_IVF").ok();
37 let path = explicit
38 .clone()
39 .unwrap_or_else(|| "/tmp/inter1.ivf".to_string());
40 let expect_raw = std::env::var("INTER_EXPECT").unwrap_or_else(|_| "1213,1851".to_string());
41 let expect: Vec<usize> = if expect_raw == "none" {
42 Vec::new()
43 } else {
44 expect_raw
45 .split(',')
46 .map(|t| t.trim().parse().expect("INTER_EXPECT entries are block counts"))
47 .collect()
48 };
49 let Ok(bytes) = std::fs::read(&path) else {
50 assert!(
51 explicit.is_none(),
52 "INTER_IVF={path} was set explicitly but the file does not exist"
53 );
54 println!("SKIP: fixture {path} not found - set INTER_IVF=<file> to run");
55 return;
56 };
57 let (_fourcc, w, h, frames) = ivf::parse_ivf(&bytes);
58 println!("IVF {w}x{h} frames={}", frames.len());
59 let mut dec = Decoder::new();
60 let mut counts = Vec::new();
61 for (i, f) in frames.iter().enumerate() {
62 match dec.decode_syntax(&f.data) {
63 Ok(()) => {
64 let n = dec.last_frame_blocks();
65 println!("FRAME {i} parsed blocks={n}");
66 if i > 0 {
67 counts.push(n);
68 }
69 }
70 Err(e) => panic!("FRAME {i} failed: {e:?}"),
71 }
72 }
73 if !expect.is_empty() {
74 assert_eq!(
75 counts, expect,
76 "inter-frame mode-info block counts differ from INTER_EXPECT"
77 );
78 println!("block-count gate passed for {counts:?}");
79 }
80}