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-vp9-refsetup — intra-only frames + scaled references |
| 2 | |
| 3 | Branch `lane-vp9-refsetup`, off main `79984549`. Two named refusals removed: |
| 4 | |
| 5 | 1. `vp9 intra-only` — an INTER frame with `intra_only = 1`, `show_frame = 0` |
| 6 | (`decode.rs:233`, `:320`). |
| 7 | 2. `vp9 inter reference size change` — an inter frame whose reference slot |
| 8 | holds a picture of a different coded size (`decode.rs:372`). |
| 9 | |
| 10 | Acceptance bar: byte-exact vs libvpx 1.15 (the frozen oracle drivers |
| 11 | `$HOME/.cache/vp9pix/drv_pix3`, `drv_err`, statically linked to the 1.15 build) |
| 12 | on real streams, plus the full 8-bit regression corpus unchanged. |
| 13 | |
| 14 | ## What changed |
| 15 | |
| 16 | | path | why | |
| 17 | | --- | --- | |
| 18 | | `crates/ec-vp9/src/decode.rs` `decode_one` / `decode_syntax` | intra-only routes to the new `decode_intra_only_frame` instead of refusing | |
| 19 | | `crates/ec-vp9/src/decode.rs` `decode_intra_only_frame` | new: keyframe body, storage-loaded frame context (reset only for `reset_frame_context` 2/3 / error-resilient), `refresh_frame_flags`-scoped reference refresh | |
| 20 | | `crates/ec-vp9/src/decode.rs` `decode_block` | intra dispatch keys on `frame_is_intra_only` (keyframe OR intra-only), not `frame_type == Key` | |
| 21 | | `crates/ec-vp9/src/decode.rs` `decode_inter_frame` | size-change refusal removed; slot-existence checks kept | |
| 22 | | `crates/ec-vp9/src/decode.rs` `inter_predict_plane` | `ScaleFactors::setup` per reference (`valid_ref_frame_size` -> `vp9 reference scale` refusal where libvpx errors) | |
| 23 | | `crates/ec-vp9/src/mc.rs` | `ScaleFactors` (`vp9_setup_scale_factors_for_frame`, `vp9_scale_mv`), step-aware `convolve_horiz`/`convolve_vert`, `sf->predict` kernel selection, scaled block/MV mapping in `build_inter_predictors` | |
| 24 | | `crates/ec-vp9/src/header.rs` | `FrameContext::use_key_partition` (`set_partition_probs`) | |
| 25 | | `crates/ec-vp9/tests/{intraonly,scaledref}_exact.rs` + `tests/data/*.ivf` | regression witnesses | |
| 26 | |
| 27 | ### Semantics ported (bug-for-bug, libvpx 1.15.0) |
| 28 | |
| 29 | * `vp9_setup_past_independence` (`vp9/common/vp9_entropymode.c:424`) is called |
| 30 | for intra-only frames, but `cm->frame_type != KEY_FRAME`, so the stored |
| 31 | contexts are reset only for `reset_frame_context` 2 (selected) / 3 (all) or |
| 32 | error-resilient mode. The ACTIVE context is then |
| 33 | `*cm->fc = cm->frame_contexts[frame_context_idx]` |
| 34 | (`vp9_decodeframe.c:3008`) — storage, not the defaults. |
| 35 | * Partitions for intra-only (and key) frames come from the const |
| 36 | `vp9_kf_partition_probs` (`set_partition_probs`, `onyxc_int.h:367`), which is |
| 37 | NOT a `FRAME_CONTEXT` field: the stored context's `partition` survives the |
| 38 | frame untouched (restored before storing). |
| 39 | * Reference refresh is `refresh_frame_flags`-scoped; `show_frame` stays 0 (an |
| 40 | intra-only frame is never displayable — the parser only reads `intra_only` |
| 41 | when `show_frame == 0`). |
| 42 | * Scaling: `x_scale_fp = (other << 14) / this`, `x_step_q4 = scaled_x(16)`; |
| 43 | the block maps with `scale_value_x/y`, the MV with `vp9_scale_mv` |
| 44 | (`vp9_scale.c:29`), and `sf->predict[subpel_x != 0][subpel_y != 0]` picks the |
| 45 | kernel (`vpx_scaled_horiz/vert/2d` == the step-aware convolve helpers). |
| 46 | The tap-padding branch is `subpel || step != 16`; the direct read keeps the |
| 47 | pre-padding coordinates. |
| 48 | |
| 49 | ## Fixtures and generators (reproducibility) |
| 50 | |
| 51 | None of these can be produced by an ffmpeg invocation: |
| 52 | |
| 53 | * **intra-only**: libvpx's encoder emits intra-only frames only through its SVC |
| 54 | path (`set_intra_only_frame`, `vp9_ratectrl.c:2211`), which ffmpeg does not |
| 55 | expose. Generated by `lanes/vp9refsetup/gen_intraonly.py` from a plain |
| 56 | ffmpeg keyframe GOP: |
| 57 | ``` |
| 58 | ffmpeg -v error -y -f lavfi -i testsrc2=size=320x240:rate=24:duration=0.4 \ |
| 59 | -c:v libvpx-vp9 -g 999 -auto-alt-ref 0 -crf 32 -deadline good -cpu-used 4 \ |
| 60 | -pix_fmt yuv420p -f ivf S.ivf |
| 61 | python3 lanes/vp9refsetup/gen_intraonly.py S.ivf intraonly.ivf |
| 62 | ``` |
| 63 | The generator reproduces the committed `tests/data/intraonly.ivf` byte for |
| 64 | byte (`cmp` verified). 11 frames: keyframe, hidden intra-only twin, 9 inter. |
| 65 | * **size change**: libvpx's encoder resizes only through rate control |
| 66 | (`vp9_resize_one_pass_cbr`, `vp9_ratectrl.c:2728`); ffmpeg exposes neither |
| 67 | `rc_resize_allowed` nor SVC, and ffmpeg's rawvideo output size is locked to |
| 68 | the first decoded frame (see the oracle caveat), so a two-size stream cannot |
| 69 | be dumped in one pass. Generated by |
| 70 | `lanes/vp9refsetup/gen_scaledref.c` (links the pristine libvpx 1.15.0 |
| 71 | encoder): |
| 72 | ``` |
| 73 | gcc -I<libvpx> -I<libvpx>/vpx gen_scaledref.c <libvpx>/libvpx.a -o enc -lm -lpthread |
| 74 | ./enc scaledref.ivf 1280 720 10 200 # one-pass CBR, 200 kbps, lag 0 |
| 75 | ``` |
| 76 | libvpx's force-downsize rule (`>= 1280x720` input and |
| 77 | `avg_frame_bandwidth < 300000/30`) downscales frame 1 to 640x360 against the |
| 78 | 1280x720 keyframe — a genuine 2x reference scale (`x_step_q4 == 32`). |
| 79 | * **odd variant**: `scaledref_odd.ivf` is `scaledref.ivf` with the keyframe's |
| 80 | size fields patched 1280x720 -> 1279x719 (mi-grid invariant, so the tile data |
| 81 | stays valid) — the reference is then an odd coded extent and its chroma crop |
| 82 | ceils. Patch with the existing |
| 83 | `$HOME/.cache/vp9pix/patch_kf_size.py <in> <out> 1279 719`, which rewrites the |
| 84 | IVF container size as well (`sha256 af289a0f8dd91bfa854adeac1814dc77644ad87b9df0af884d33abaae2595413`). |
| 85 | |
| 86 | ## Gates |
| 87 | |
| 88 | `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-vp9ref` |
| 89 | |
| 90 | 1. **Suite**: `cargo test -p ec-vp9` — every binary green, **0 failed**, |
| 91 | 0 ignored. Warning parity: exactly the 5 pre-existing (`TM_PRED`, |
| 92 | `read_partition`, `partition_probs`, `x_mis`, `y_mis`). |
| 93 | 2. **New witnesses** (byte-exact vs ffmpeg's libvpx-backed rawvideo): |
| 94 | * `intra_only_frame_and_its_successors_match_ffmpeg` — 10/10 shown frames |
| 95 | identical; the fixture is asserted to carry exactly one intra-only frame. |
| 96 | * `size_changing_reference_decodes_byte_exact` — 10/10 identical. |
| 97 | * `size_changing_odd_reference_decodes_byte_exact` — 10/10 identical. |
| 98 | 3. **Crate-level oracle** (my dump vs libvpx's `drv_pix3`, per-shown-frame |
| 99 | native dims + ceil chroma, compared with `cmp`): |
| 100 | `scaledref.ivf` **IDENTICAL** (4,492,800 bytes, 10 frames); |
| 101 | `scaledref_odd.ivf` **IDENTICAL** (4,490,801 bytes, 10 frames); |
| 102 | `intraonly.ivf` **IDENTICAL** via drv_pix (all 10 output frames match the |
| 103 | source GOP's, i.e. the intra-only frame reconstructs exactly like the |
| 104 | keyframe it replaced). |
| 105 | 4. **Fail-pre-fix** (throwaway base worktree at `79984549`, tests+fixtures |
| 106 | copied in, private target dir): |
| 107 | * intra-only: `Unsupported { what: "vp9 intra-only", why: "this lane decodes |
| 108 | inter frames and keyframes only" }` at `intraonly_exact.rs:72`. |
| 109 | * scaled: `Unsupported { what: "vp9 inter reference size change", why: |
| 110 | "reference `last` in slot 0 is 1280x720 but this frame is 640x360; |
| 111 | reference-frame scaling is not ported" }` (and the 1279x719 twin) at |
| 112 | `scaledref_exact.rs:107`. |
| 113 | 5. **Regression corpus** (`$HOME/.cache/vp9ref-sweep.sh` = `drv_pix3` vs |
| 114 | `scratch_pixdump`, byte `cmp`) — all **IDENTICAL**: |
| 115 | |
| 116 | | stream | oracle frames | bytes | |
| 117 | | --- | --- | --- | |
| 118 | | `vp9-1080p-23.976-8bit.ivf` | 48 | 149,299,200 | |
| 119 | | `vp9-1080p-60-8bit.ivf` (120 frames, the frame-72 witness) | 120 | 373,248,000 | |
| 120 | | `vp9-2160p-23.976-8bit.ivf` | 48 | 597,196,800 | |
| 121 | | `vp9-tiles-1280.ivf` | 30 | 41,472,000 | |
| 122 | | `vp9-superframe-altref.ivf` | 60 | 6,912,000 | |
| 123 | | `$HOME/.cache/vp9pix/inter.ivf` | 3 | 9,331,200 | |
| 124 | | `$HOME/.cache/vp9pix/inter1.ivf` | 3 | 9,331,200 | |
| 125 | | odd testsrc2 321x241 (322x242 encode + `patch_kf_size.py`) | 12 | 1,395,876 | |
| 126 | |
| 127 | 6. **Interaction (size change x odd dims)**: `scaledref_odd.ivf` covers it — |
| 128 | the scaled reference is an odd extent (1279x719, chroma `(w+1)/2`) and the |
| 129 | result is byte-identical to libvpx. Not deferred. |
| 130 | |
| 131 | ## Oracle caveat (why the committed tests skip frame 1) |
| 132 | |
| 133 | ffmpeg locks its rawvideo output size to the FIRST decoded frame's, so a |
| 134 | two-size stream cannot be dumped in one pass: frames 1..N come out upscaled to |
| 135 | 1280x720. The tests decode frame 0 alone (`-frames:v 1`, identity) and frames |
| 136 | 2..N with `select=gte(n,1)` at the small size, where the filtergraph has |
| 137 | re-initialised and every frame passes through unchanged. The size-change frame |
| 138 | (file frame 1) is the one ffmpeg mangles during that re-initialisation, so it |
| 139 | is covered INDIRECTLY: every later frame predicts from its reconstruction (a |
| 140 | wrong scaler fails frames 2..N). Frame 1 itself is covered directly by the |
| 141 | crate-level `drv_pix3` comparison in gate 3. |
| 142 | |
| 143 | ## Deferred / accepted |
| 144 | |
| 145 | * accepted: **profile 2 / 4:4:4** still refused by name (`decode.rs:211/217`, |
| 146 | and `vp9 reference scale` for a colour-format mismatch) — out of scope, owned |
| 147 | by the sibling lane. |
| 148 | * accepted: `vp9 reference scale` (the `valid_ref_frame_size` ratio bound) stays |
| 149 | a named refusal; libvpx errors the same way (`Reference frame has invalid |
| 150 | dimensions`). Reaching it needs an adversarial 2x+ ratio that no encoder |
| 151 | emits. |
| 152 | * noted, not touched: the existing inter path resets stored frame contexts for |
| 153 | `reset_frame_context` 2/3 even though libvpx only does that via |
| 154 | `vp9_setup_past_independence` (i.e. only for intra-only / error-resilient |
| 155 | frames). Pre-existing, unreachable on the corpus (which codes `reset = 0`), |
| 156 | and outside this lane's scope. |
| 157 | * noted: `scratch_pixdump`/`drv_pix3` are per-`inter_pixdump`-style scratch |
| 158 | harnesses; the new `drv_pix3` (per-frame native dims) lives only in |
| 159 | `$HOME/.cache/vp9pix`. |
| 160 | |
| 161 | ## Test scope actually run |
| 162 | |
| 163 | * `cargo test -p ec-vp9` (whole crate) — green, 0 failed, 5 warnings. |
| 164 | * `cargo test -p ec-vp9 --test intraonly_exact --test scaledref_exact` — 3 |
| 165 | passed. |
| 166 | * corpus sweep above — 8 streams IDENTICAL. |
| 167 | * base-worktree fail-pre-fix — 3 failures with the named refusals. |
| 168 | |
| 169 | ## MERGE-SIDE FOLLOW-UPS (2026-09-19) |
| 170 | |
| 171 | - **Doc nit dropped on the lane before the merge** (commit `2129be51`): the |
| 172 | "`scale=...:eval=frame` exits 139 with a 0-byte file (ffmpeg 8.1.2)" sentence |
| 173 | is gone from this report and from `scaledref_exact.rs`. The reviewer cannot |
| 174 | reproduce the exit-139 shape; the builder can — environment-dependent, so it |
| 175 | is not load-bearing. Kept: ffmpeg's rawvideo output size is locked to the |
| 176 | first decoded frame, hence the two-pass dump recipe (frame 0 alone with |
| 177 | `-frames:v 1`, frames 2..N with `select=gte(n,1)`). |
| 178 | - **Merge**: `33904e74` — parents `ccc5a836` (main) and `2129be51` (lane), so a |
| 179 | real merge, not a fast-forward. Between this lane's base `79984549` and the |
| 180 | merge, main absorbed `lane-vp9-hbd`, which converted every ec-vp9 plane to |
| 181 | `u16` (`ec_vp9::Sample`) and threaded `bd` through every pixel kernel. The |
| 182 | lane wrote its scaling against the u8 kernels, so the merge was resolved by |
| 183 | porting the lane's semantics onto the u16 substrate. |
| 184 | - **Conflict regions and resolution** (both sides read from the index `:2:`/`:3:`; |
| 185 | the working-tree markers elide lines): |
| 186 | - `crates/ec-vp9/src/decode.rs` — one conflict, the capability doc block. |
| 187 | Combined: both the profile-2 10-bit clause and the intra-only / |
| 188 | scaled-reference clauses in one paragraph. The auto-merged remainder was |
| 189 | verified by diff: everything the lane changed (intra-only dispatch + |
| 190 | `decode_intra_only_frame`, `frame_is_intra_only` routing in `decode_block`, |
| 191 | `ScaleFactors::setup` + `valid_ref_frame_size` refusal, the removed |
| 192 | size-change refusal) is present; the only deltas vs the lane side are |
| 193 | u16/`bd`/profile-2 mechanics. |
| 194 | - `crates/ec-vp9/src/mc.rs` — four conflicts (the two 1D convolve calls in |
| 195 | `inter_predictor`, the `convolve_vert` call inside the avg branch, and the |
| 196 | `build_inter_predictors` signature + coordinate head). Resolved by |
| 197 | COMBINING: main's `Sample`/`bd` kernels stay the substrate and the lane's |
| 198 | scaling is ported onto them — |
| 199 | `convolve_horiz(.., x0_q4, x_step, w, rows, avg, bd)`, |
| 200 | `convolve_vert(.., y0_q4, y_step, w, h, avg, bd)` (both default |
| 201 | `SUBPEL_SHIFTS`), the scaled dispatch at the top of `inter_predictor`, the |
| 202 | lane's extracted `convolve_2d` ported to `Sample` + `bd`, and `sf: |
| 203 | &ScaleFactors` in `build_inter_predictors` with the lane's scaled |
| 204 | block/MV mapping. The scale arithmetic (`scale_value`, |
| 205 | `vp9_scale_mv`, step derivation) is depth-independent and kept verbatim. |
| 206 | Because both sides rewrote these functions, the file was re-composed rather |
| 207 | than marker-resolved; the result was proof-read in both directions |
| 208 | (`diff` vs each side shows only the other side's delta). |
| 209 | - `crates/ec-vp9/src/header.rs` — clean auto-merge (`use_key_partition`). |
| 210 | - `crates/ec-vp9/tests/{intraonly,scaledref}_exact.rs` — not a git conflict, |
| 211 | but the lane's u8-era comparison had to be re-expressed: the pictures are |
| 212 | `Vec<Sample>` (u16) now, so the byte comparison goes through |
| 213 | `got.extend(pic.y.iter().map(|&v| v as u8))` (the crate's convention in |
| 214 | `odd_dimensions_exact.rs` / `inter_pixels_exact.rs`). |
| 215 | - **Create-list audit**: exactly the expected creates — the three TRACKED |
| 216 | fixtures under `crates/ec-vp9/tests/data/` (they are committed, not |
| 217 | gitignored, so no fixture-copy step), `intraonly_exact.rs`, |
| 218 | `scaledref_exact.rs`, this report, `lanes/vp9refsetup/gen_intraonly.py` and |
| 219 | `gen_scaledref.c`. No junk files, no target artifacts. |
| 220 | - **Gates on the MERGED tree** (`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-vp9refmerge`): |
| 221 | `cargo test -p ec-vp9` → **25 binaries, 40 passed / 0 failed / 0 ignored**; |
| 222 | the non-skipped named gates: `scaledref_exact` 2/2, `intraonly_exact` 1/1, |
| 223 | `odd_dimensions_exact` 3/3, `hbd_exact` 2/2, `inter_pixels_exact` 3/3, |
| 224 | `keyframe_exact` 4/4, lib 9/9. Warning parity: |
| 225 | `cargo check -p ec-vp9 --all-targets` → exactly the 5 pre-existing |
| 226 | (`TM_PRED`, `read_partition`, `partition_probs`, `x_mis`, `y_mis`). No crate |
| 227 | in the repo depends on `ec-vp9` (only on `ec-vp9-syntax`), so there is no |
| 228 | cross-crate suite to run. |
| 229 | - **Merged-tree corpus re-sweep** (both lanes touched the prediction path; |
| 230 | EVERY stream regenerated from the merged build and `cmp`ed against the |
| 231 | libvpx 1.15.0 oracle) — all **BYTE-IDENTICAL**, with the frame count derived |
| 232 | arithmetically (`dump_bytes / (w*h + 2*ceil(w/2)*ceil(h/2))`, ×2 for u16): |
| 233 | |
| 234 | | stream | frames | oracle | bytes | |
| 235 | | --- | --- | --- | --- | |
| 236 | | `tests/data/scaledref.ivf` (1x 1280x720 + 9x 640x360) | 10 | `drv_pix3` | 4,492,800 | |
| 237 | | `tests/data/scaledref_odd.ivf` (1x 1279x719 + 9x 640x360) | 10 | `drv_pix3` | 4,490,801 | |
| 238 | | `tests/data/intraonly.ivf` (11 coded, 10 shown) | 10 | `drv_pix3` | 1,152,000 | |
| 239 | | `vp9-1080p-23.976-8bit` | 48 | `drv_pix3` | 149,299,200 | |
| 240 | | `vp9-1080p-60-8bit` | 120 | `drv_pix3` | 373,248,000 | |
| 241 | | `vp9-superframe-altref` | 60 | `drv_pix3` | 6,912,000 | |
| 242 | | `vp9-tiles-1280` | 30 | `drv_pix3` | 41,472,000 | |
| 243 | | `vp9-1080p-23.976-10bit` | 48 | `drv_pix10` (u16-LE) | 298,598,400 | |
| 244 | | `vp9-1080p-60-10bit` | 120 | `drv_pix10` (u16-LE) | 746,496,000 | |
| 245 | | odd `testsrc2` patched 321x241 | 12 | `drv_pix2` + `pixcmp2.py` | 1,395,876 | |
| 246 | |
| 247 | - **Push**: `ccc5a836..33904e74 main -> main`; `git ls-remote origin |
| 248 | refs/heads/main` == `33904e747ab7881b4e97d518f68cd03d3afa6c6b` == local HEAD. |
| 249 | - **Cleanup**: lane worktree `../edith_codecs-vp9ref` removed (branch |
| 250 | `lane-vp9-refsetup` kept as history); `rm -rf |
| 251 | $HOME/.cache/cargo-target-vp9ref{,merge,verify}` and the builder/verify |
| 252 | dirs. `EDITH_FINDINGS.md` (untracked, sibling session) left untouched. |
| 253 | - **Instruments kept**: `tests/scratch_pixdump{,10}.rs` + the `EC_VP9_*` trace |
| 254 | hooks stay in tree — they are the next lane's comparators, not throwaways. |
| 255 | - **Still open** (unchanged from the lane): the `valid_ref_frame_size` ratio |
| 256 | bound stays a named refusal (libvpx errors the same way), and profile-2 |
| 257 | intra-only / scaled-reference interaction has no corpus stream — the scaled |
| 258 | path is exercised only at profile 0 (the odd fixture covers odd x scaled). |