edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching·0 forks·Rust·370.3 MiB·9b67700·Tahinli·3 days ago·4021 commits
| 1 | # lane-av1dumpyuv — the depth-packing class outside the test helpers |
| 2 | |
| 3 | Branch `lane-av1dumpyuv`, branched from `afa13bcf` ("Merge lane-whtshape"). |
| 4 | Worktree `~/.cache/wt/av1dumpyuv`. Examples/tools/scripts only: no decoder |
| 5 | logic, no gate touched. The primary checkout was never edited |
| 6 | (`git status --porcelain` there is empty). |
| 7 | |
| 8 | ## 1. The class |
| 9 | |
| 10 | `aomdec --rawvideo` and `ffmpeg -f rawvideo` pack **8 bits per sample for an |
| 11 | 8-bit stream** and **16 bits per sample (`*p10le` / `*p12le`) for a |
| 12 | high-bit-depth one** — they never pack to the stream's own bit depth. A site |
| 13 | that reads decoded `u16` planes and writes them `as u8`, or writes them `u16` |
| 14 | unconditionally, therefore produces a file of the wrong size, and the next |
| 15 | person's `cmp` against the oracle fails on LENGTH and reads like a decoder |
| 16 | bug. The prior audit (lanes/av1cmpaudit.report.md) fixed the test helper |
| 17 | `assert_rawvideo_matches`'s sibling `EC_AV1_FINAL_DUMP` |
| 18 | (`crates/ec-av1/src/stream.rs:2137-2152`, depth-correct since lane-hidden r1) |
| 19 | and named exactly one unfixed non-test site: `examples/dump_yuv.rs`. |
| 20 | |
| 21 | ## 2. Sweep of the non-test surfaces |
| 22 | |
| 23 | Rows verified by reading each file. "Assumes" = what the code takes the |
| 24 | bits-per-sample to be. |
| 25 | |
| 26 | | site | assumes about depth | derived from | failure mode on the wrong depth | |
| 27 | |---|---|---|---| |
| 28 | | `crates/ec-av1/examples/dump_yuv.rs:33` (pre-fix) | always 2 bytes/sample (u16 LE) | **nothing** | silent 2x file on an 8-bit stream; docstring named `yuv420p10le` as the companion, so a reader hands it 8-bit input and diffs the size | |
| 29 | | `crates/ec-av1/examples/dump_yuv.rs` (**fixed**) | sequence header `color_config.bit_depth` | the stream's own parsed header; `--depth` is an ASSERTED argument | hard exit 1 naming both depths, no file | |
| 30 | | `crates/ec-av1/examples/decode_probe.rs:434-462` | `EC_PROBE_OUT16` = 2 B/sample, `EC_PROBE_OUT`/argv[2] = 1 B/sample | two SEPARATE, explicitly named output targets, each a fixed choice by the caller | none for a single file: the 16-bit target is a full 16-bit container (same as `-pix_fmt yuv420p10le` on an 8-bit stream), the 8-bit target narrows. Both are written, so a wrong choice is visible as two files of different sizes, not one mislabelled file. **not fixed** | |
| 31 | | `crates/ec-vp8/examples/dump_frame.rs:28-45` | 1 byte/sample | VP8 has no high-bit-depth profile (its 8-bit 4:2:0 is the format) | none possible. **not flagged** | |
| 32 | | `crates/ec-av1/examples/{alloc_probe,enc_probe,syntax_census}.rs` | — | no plane is read or serialised | none. **not flagged** | |
| 33 | | `crates/ec-h264/examples/bench_decode.rs`, `bench_encode.rs`, `crates/ec-aac/examples/*`, `crates/ec-ac3/examples/ac3dec.rs` | — | audio `f32`/metric only; no video planes | none. **not flagged** | |
| 34 | | `scripts/instrument-aom-oracle.sh:130-145` (rung PREFILT), `:333-350` (POSTDEBLOCK), `:384-398` (PREFILT_WIDE), `:880-896` (POSTCDEF) | 1 byte/sample, no `YV12_FLAG_HIGHBITDEPTH` check | nothing | on a 10/12-bit stream: a **half-length** file (u8 rows of a u16 plane) that can still byte-match a decoder-side `as u8` narrowing. Rung 12 (`FINAL`, `:684-705`) IS depth-correct and is what `EC_AV1_FINAL_DUMP` pairs with. **NOT FIXED** — these are oracle C rungs whose decoder-side counterparts (`EC_AV1_PREFILT_DUMP`, `EC_AV1_DECODE_ORDER_DUMP`, and the `as u8` debug dumps at `stream.rs:2123-2126`) narrow identically on purpose; changing one side alone would break the byte-pairing those rungs exist for, and both sides are decoder/oracle logic, out of this lane's scope. The script's own comment at `:659-660` already calls them the "u8-narrowing debug dumps". | |
| 35 | | `scripts/lr-sgr-pin-harness.c:33-36` (pre-fix) | 1 byte/sample of `/tmp/lr_full.bin`; `bit_depth=8, highbd=0` hardcoded at `:47`, `:54`, `:75` | nothing (the capture is a bare `std::fs::write` from a since-reverted `EC_LR_DUMP` in `apply_sgrproj_stripe`, lanes/lr.report.md:352-354) | a 10-bit re-capture is exactly 2x the bytes; the harness read its first half as plane data and printed plausible A/B taps for the wrong pixels | |
| 36 | | `scripts/lr-sgr-pin-harness.c` (**fixed**) | still reads 8-bit, but the file length is now an ASSERTION | file size, checked against `bw*bh` | 2x capture → exit 1 naming the byte counts, the assumed depth, and the uint16 port; truncated → exit 1 | |
| 37 | | `scripts/raw_to_y4m.py:9` (pre-fix) | `w*h*3//2` = 8-bit 4:2:0, unconditionally; header hardcoded `C420jpeg` | nothing | a 10-bit stream was cut at half frame length, frame N+1's chroma read as frame N's tail, trailing partial frame **dropped silently** — and vpxenc encodes the result without complaint | |
| 38 | | `scripts/raw_to_y4m.py` (**fixed**) | required `DEPTH` argument, asserted against the stdin length | explicit asserted argument (no parser exists for a headerless raw stream) | non-integer frame multiple → exit 1 naming both implied frame sizes; a missing/!8/10/12 depth → usage error | |
| 39 | | `scripts/superres-pin-harness.c:14-17,50,80,89-142` | — | coverage gap, not depth: only the `uint8` `av1_convolve_horiz_rs_c` arm is called and the input rows were transcribed from an 8-bit fixture | a 10-bit superres pin would be silently uncovered. Different class; **not fixed** | |
| 40 | | `tools/oracle/src/main.rs:352-357` (`sample`), `:383-390`, `:414`, `:424-425`, `:479` | bytes-per-sample from the `--pix-fmt` string (or ffprobe of the reference CONTAINER, `:383-388`), never from a parsed header | explicit CLI flag / container probe | a wrong `--pix-fmt` yields `fa != fb`, and `len_ok = fa == fb` feeds the verdict at `:479` → **loud FAIL**, not a silent compare. Acceptable shape (an argument that is checked). **not fixed** | |
| 41 | | `tools/ec-bench/src/main.rs:253`, `:367`, `:557` | 1 byte/sample `frame_len`; `:564-571` widens those 8-bit samples into `Av1Picture`'s `u16` planes | the same forced `-pix_fmt yuv420p` on the extracting ffmpeg (`:242-243`) | self-consistent: the frame arithmetic and the file it slices come from one explicit ffmpeg argument. Mild real hole: `Av1Config` (`:536-544`) has no depth field, so the encoder's own output depth is whatever it defaults to. **not fixed** (bench table, no oracle compare) | |
| 42 | | `tools/ec-bench/src/main.rs:404-410`, `:423`, `:452`, `:485` | 10-bit for the `ec-hw` row | a comment about the local VA driver's stored format, plus a matching `-pix_fmt yuv420p10le` at `:485` | arithmetic agrees with the forced format. **not fixed** | |
| 43 | | `shims/**` | — | 16 Cargo path-shim crates (`Cargo.toml` + thin `lib.rs` re-exports), no video or raw-byte code | none. **out of scope** | |
| 44 | | `scripts/{build-aom-oracle,build-aom-affine-oracle,gen-bitstream-fixtures,gen_vp8_fixtures,gen-still-fixtures,pgs-white-level,scan-real-library,fetch-vectors,link-fixtures}.sh`, `scripts/av1-timeline-report.py` | force an explicit `-pix_fmt` (or read no planes at all); sizes that exist (`gen_vp8_fixtures.sh:60`, `pgs-white-level.sh:27`) are computed from that same argument | CLI flag | none. **not flagged** | |
| 45 | |
| 46 | Sites fixed: 3 (`examples/dump_yuv.rs`, `scripts/raw_to_y4m.py`, |
| 47 | `scripts/lr-sgr-pin-harness.c`). Sites examined and deliberately NOT fixed: |
| 48 | 7 (`decode_probe.rs`, `tools/oracle/src/main.rs`, `tools/ec-bench` x2, |
| 49 | `instrument-aom-oracle.sh` rungs 1/6/7/15, `superres-pin-harness.c`), each with |
| 50 | the reason above. |
| 51 | |
| 52 | ## 3. `examples/dump_yuv.rs` — what changed |
| 53 | |
| 54 | - The depth comes from the stream's **own parsed sequence header** |
| 55 | (`ec_av1_syntax::Av1Parser` walking OBU by OBU until a sequence header |
| 56 | appears, then `seq.color_config.bit_depth`). It is never taken from the file |
| 57 | name, the extension, or a reference tool's `-pix_fmt`. |
| 58 | - 8 bit → one byte per sample; 10/12 → little-endian `u16` (the container |
| 59 | both oracles use). Monochrome streams write the luma plane only. |
| 60 | - `--depth N` is an **assertion, not a switch**: the packing always follows the |
| 61 | parsed header, and a contradiction exits 1 naming both depths, both |
| 62 | bytes-per-sample values, and the size mismatch the `cmp` would have shown. |
| 63 | Two spellings accepted (`--depth 8`, `--depth=8`); given twice → usage error. |
| 64 | - A stream with no parseable sequence header → hard error instead of a guess. |
| 65 | - A sample that does not fit the container about to be written (an 8-bit |
| 66 | header with a sample above 255) → hard error. That is the mirror of the |
| 67 | original bug and the reason `as u8` may never be applied silently here. |
| 68 | - The docstring no longer says `yuv420p10le`; it states the both-depths |
| 69 | contract and the `--depth` assertion. |
| 70 | - Measured while doing this: the crate's own 8-bit fixture |
| 71 | `av1_192x128_8bit_intra64_in_inter.obu` parses `subsampling_x/y = 1/1`, |
| 72 | which is **4:2:0** (spec 5.5.3) — 36864 samples for 192x128 = W*H*3/2. The |
| 73 | first pix_fmt table I wrote had 1/1 → 4:4:0 and the measurement caught it; |
| 74 | the shipped table is 0/0→444, 0/1→440, 1/0→422, 1/1→420. |
| 75 | |
| 76 | ## 4. Proof |
| 77 | |
| 78 | Committed crate fixtures only, worktree at `afa13bcf`, |
| 79 | `CARGO_TARGET_DIR=$HOME/.cache/cargo-target`. |
| 80 | |
| 81 | ### 4.1 GREEN — 8-bit stream, committed fixture |
| 82 | |
| 83 | ``` |
| 84 | $ dump_yuv crates/ec-av1/fixtures/av1_192x128_8bit_intra64_in_inter.obu /tmp/dy/eight |
| 85 | sequence header: bit_depth 8 -> 1 byte(s) per sample, seq_profile 0, subsampling 1/1, mono_chrome false; ffmpeg -pix_fmt yuv420p |
| 86 | frame 0: 192x128 -> /tmp/dy/eight.f0.yuv (36864 samples, 36864 bytes, yuv420p) |
| 87 | ... |
| 88 | eight.f0.yuv 36864 bytes <- W*H*3/2 = 192*128*3/2 = 36864 (Y 24576 + U 6144 + V 6144) |
| 89 | ``` |
| 90 | Byte-exact against the oracle at its own depth: |
| 91 | `aomdec --codec=av1 --rawvideo -o ref8.raw <fixture>` → 221184 bytes for 6 |
| 92 | frames; our 6 concatenated frames → 221184 bytes; `cmp` → **IDENTICAL**. |
| 93 | |
| 94 | ### 4.2 GREEN — high-bit-depth stream, committed fixture |
| 95 | |
| 96 | ``` |
| 97 | $ dump_yuv crates/ec-av1/fixtures/av112bit-key.obu /tmp/dy/twelve |
| 98 | sequence header: bit_depth 12 -> 2 byte(s) per sample, seq_profile 2, subsampling 1/1, mono_chrome false; ffmpeg -pix_fmt yuv420p12le |
| 99 | frame 0: 160x128 -> /tmp/dy/twelve.f0.yuv (30720 samples, 61440 bytes, yuv420p12le) |
| 100 | twelve.f0.yuv 61440 bytes <- W*H*3 = 160*128*3 = 61440 (30720 samples x 2 bytes) |
| 101 | cmp twelve.f0.yuv (ffmpeg -f obu -pix_fmt yuv420p12le -f rawvideo) -> IDENTICAL |
| 102 | ``` |
| 103 | |
| 104 | ### 4.3 The wrong depth fails loudly and writes nothing |
| 105 | |
| 106 | ``` |
| 107 | $ dump_yuv .../av1_192x128_8bit_intra64_in_inter.obu /tmp/dy/wrong --depth 10 |
| 108 | dump_yuv: ...: --depth 10 contradicts the stream's own sequence header, which carries |
| 109 | bit_depth 8 (seq_profile 0, subsampling 1/1, mono_chrome false). Writing 10-bit would emit |
| 110 | 2 bytes per sample against the oracle's aomdec --rawvideo / ffmpeg -pix_fmt yuv420p (1 bytes |
| 111 | per sample, W*H*3/2 for 4:2:0), so every `cmp` would fail on size alone and read like a decoder |
| 112 | defect. Nothing was written. |
| 113 | exit=1 |
| 114 | ls: cannot access '/tmp/dy/wrong.f0.yuv': No such file or directory |
| 115 | |
| 116 | $ dump_yuv .../av112bit-key.obu /tmp/dy/wrong2 --depth=8 -> same message, exit=1, no file |
| 117 | $ dump_yuv .../av1_192x128_... --depth=8 -> runs, 36864 bytes (assertion holds) |
| 118 | $ dump_yuv .../av112bit-key.obu --depth 12 -> runs, 61440 bytes |
| 119 | ``` |
| 120 | |
| 121 | ### 4.4 RED-BEFORE — the depth derivation reverted |
| 122 | |
| 123 | `git show HEAD:crates/ec-av1/examples/dump_yuv.rs` restored, rebuilt, same |
| 124 | 8-bit fixture, same command: |
| 125 | |
| 126 | ``` |
| 127 | --- RED (pre-fix, u16 unconditional) on the 8-bit fixture --- |
| 128 | ours 73728 bytes <- 2 x 36864 |
| 129 | aomdec --rawvideo 221184 bytes <- 6 x 36864 |
| 130 | cmp exit=1 (mismatch on size alone) |
| 131 | ``` |
| 132 | 73728 = 2 x (W*H*3/2): exactly the silent 2x file the lane was chartered to |
| 133 | close. Fixed tree restored and rebuilt afterwards. |
| 134 | |
| 135 | ### 4.5 `scripts/raw_to_y4m.py` |
| 136 | |
| 137 | ``` |
| 138 | $ ... | raw_to_y4m.py 64 64 25 g8.y4m 8 -> YUV4MPEG2 ... C420jpeg, 18491 bytes (3 frames) |
| 139 | $ ... | raw_to_y4m.py 64 64 25 g10.y4m 10 -> YUV4MPEG2 ... C420p10, 36922 bytes (3 frames) |
| 140 | $ 12289 bytes | raw_to_y4m.py ... 8 |
| 141 | raw_to_y4m.py: stdin is 12289 bytes, not a whole number of 64x64 4:2:0 frames at 8-bit |
| 142 | (1 bytes per sample, 6144 bytes each): 1 trailing bytes. At the other depth a frame would be |
| 143 | 12288 bytes and each frame would carry half a frame of the next one's planes. Refusing to |
| 144 | write a misframed y4m. exit=1, no file |
| 145 | $ DEPTH 7 -> "DEPTH 7 is not 8, 10 or 12 ..." exit=1 |
| 146 | $ DEPTH omitted (the old 4-arg invocation) -> usage error, exit=1 |
| 147 | ``` |
| 148 | Documented limit, stated in the script's own docstring: raw planar video |
| 149 | carries no depth, so a 10-bit stream of N frames is exactly 2N 8-bit frames |
| 150 | and no length test can separate them. That case is caught by the caller |
| 151 | asserting the right DEPTH — which is why the argument is required, not |
| 152 | defaulted. |
| 153 | |
| 154 | ### 4.6 `scripts/lr-sgr-pin-harness.c` |
| 155 | |
| 156 | Linked against `~/.cache/aom-oracle/build/libaom.a`, `/tmp/lr_full.bin` |
| 157 | faked at three sizes: |
| 158 | |
| 159 | ``` |
| 160 | 1020 bytes (correct) -> ret=0 / out[1][6] = 151 / dgd[1][6] = 151 (real libaom taps printed) |
| 161 | 2040 bytes (2x, HBD) -> "/tmp/lr_full.bin is 2040 bytes, this harness reads it as 8-bit |
| 162 | (1020 bytes: 102x10 at 1 byte per sample). That is exactly a 2x-size |
| 163 | high-bit-depth capture: re-capture it as 8-bit, or port the harness to |
| 164 | the uint16 arm (bit_depth=10, highbd=1) before trusting a single |
| 165 | printed tap." exit=1 |
| 166 | 900 bytes (short) -> "... 900 bytes ... Recapture it, or fix bw/bh to the plane the |
| 167 | capture came from." exit=1 |
| 168 | ``` |
| 169 | |
| 170 | ## 5. Not done, deliberately |
| 171 | |
| 172 | - `instrument-aom-oracle.sh` rungs 1/6/7/15 (section 2): changing one side of |
| 173 | a byte-paired rung breaks the pairing, and both sides are decoder/oracle C. |
| 174 | Rung 12 is already depth-correct; that is the rung the depth-sensitive |
| 175 | compares use. |
| 176 | - `tools/oracle/src/main.rs` and `tools/ec-bench/src/main.rs`: already the |
| 177 | "explicit argument that is checked" shape (a length/frame-count FAIL), with |
| 178 | no header parser reachable from those binaries to derive a better answer |
| 179 | from (`oracle` drives ffmpeg through std pipes and is deliberately |
| 180 | dependency-free). |
| 181 | - `decode_probe.rs`: its two output targets are separate, explicitly named |
| 182 | files; see section 2. |
| 183 | - No gate, counter, decoder path or fixture was touched. |