edith_codecs
Clone
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits
Lane vp9pix: VP9 inter-frame PIXELS (motion compensation → reconstruction)
Branch lane-vp9-pix, base main 597b7442. Crate scope: crates/ec-vp9 only.
Worktree /home/user/Documents/Code/Rust/edith_codecs-vp9pix, private
CARGO_TARGET_DIR=$HOME/.cache/cargo-target-vp9pix.
Deliverable: decode() decodes inter frames through motion compensation,
residual reconstruction, the loop filter and reference-slot management, and is
byte-identical to a locally built libvpx 1.15 oracle on every fixture swept.
Baseline (milestone 0)
$ CARGO_TARGET_DIR=$HOME/.cache/cargo-target-vp9pix cargo test -p ec-vp9
exit=0 (20 test binaries, 0 failures, 0 ignored)
No pre-existing reds, so no base triage was needed. (Pre-existing warnings:
crates/ec-vp9/src/modes.rs unused partition_probs/x_mis/y_mis +
read_partition, tables/mod.rs TM_PRED — untouched files, present at base.)
The gate: byte-exactness against libvpx 1.15
Oracle: the instrumented build the syntax lane left at /tmp/vp9loss
(drv_pix.c is new here: it appends every SHOWN frame's cropped I420 planes,
frame-indexed, to PIXDUMP). Rich fixtures copied to $HOME/.cache/vp9pix/
for tmpfs insurance. Comparator: $HOME/.cache/vp9pix/pixcmp.py
(oracle, ours, w, h) → per-frame identical/first-diff report.
$ python3 $HOME/.cache/vp9pix/pixcmp.py oracle_inter1.pix ours_inter1.pix 1920 1080
oracle=9331200 bytes ours=9331200 bytes frame_bytes=3110400
frame 0: IDENTICAL (3110400 bytes)
frame 1: IDENTICAL (3110400 bytes)
frame 2: IDENTICAL (3110400 bytes)
That is the acceptance gate: 3/3 shown frames of the 1080p single-tile inter stream, loop filter ON, planes byte-for-byte.
Corroborating instruments (all agree):
SKIPLForacle +EC_VP9_SKIP_LF=1ours: identical too (isolates MC+residual from the filter).- Per-superblock LUMA loop-filter masks: oracle
LFMASKSY=1vs ourEC_VP9_LFMASKSY=1→ 0 of 510 SBs differ, on all three frames. - Emitted loop-filter edges: oracle
LFTRACE=<frame>vs oursLFTRACE=1 EC_VP9_LF_FRAME=<n>(our per-frame gate) → every oracle edge is emitted by us (oracle-only = 0); our extra 2660/3116 lines are the second column of a dual H16 pair — libvpx prints one line forvpx_lpf_horizontal_16_dual, we print one per 8x8 cell. Verified 2660/2660 and 3116/3116 of the extras have an oracle twin at(x-8, y).
The entry-gate fixture is /tmp/inter1.ivf (1080p, 1 tile column). It is
reachable through tests/scratch_pixdump.rs
(INTER_IVF=… EC_VP9_PIXDUMP=… cargo test -p ec-vp9 --test scratch_pixdump -- --nocapture).
Corpus sweep (real content)
| fixture | frames | result |
|---|---|---|
vp9-1080p-23.976-8bit.ivf (48) |
48 | all byte-identical |
vp9-2160p-23.976-8bit.ivf (48) |
48 | all byte-identical |
vp9-superframe-altref.ivf (320x240, 60) |
60 | all byte-identical |
/tmp/inter1.ivf (1080p, 1 tile col) |
3 | all byte-identical |
/tmp/inter.ivf (1080p, 2 tile cols) |
3 | all byte-identical |
vp9-1080p-60-8bit.ivf (120) |
72 | identical 0..71, desync at 72 (deferred, below) |
Sweep driver: $HOME/.cache/vp9pix/sweep.sh <fixture> <w> <h> (oracle dump +
our dump + pixcmp.py).
Milestones
- Pixel plumbing — oracle
drv_pix.c+tests/scratch_pixdump.rs+pixcmp.py. Done; the comparator is the instrument every claim below uses. - Reference slots —
refs: [Option<RefFrame>; 8],RefFrameholds the frame at its 64-aligned extent (Arc<Planes>) plus its coded size.refresh_frame_flagsis applied after the frame's loop filter (swap_frame_buffers), so a later frame predicts from filtered pixels. Evidence: the 1080p GOP and the 60-frame altref stream decode identically, which is only possible if each frame's prediction reads exactly the frame the header names (any slot mistake shows as a pixel diff on frame 1+). The refusal for a size-changing reference is named (below). - Motion compensation — new
crates/ec-vp9/src/mc.rs: libvpx'sclamp_mv_to_umv_border_sb,build_mc_border(per-block reference border extension — the VP9 decoder does NOT extend reference borders in place),dec_build_inter_predictorsincluding the "window inside the frame" direct read, the four convolve kernels (EIGHTTAP,EIGHTTAP_SMOOTH,EIGHTTAP_SHARP,BILINEAR, index order =vp9_filter_kernels), compound averaging, andaverage_split_mvs(luma per sub-block, 4:2:0 chroma q4 average). - Residual — tokens via the shared
decode_inter_tx_tokens(one read per transform block), theninverse_transform_addwith the DEFAULT scan andDCT_DCT(inverse_transform_block_inter). - Loop filter — per-cell level from
get_filter_level(lvl[seg][ref_frame[0]][mode_lf_lut[mode]]), the skip promotion (!less8x8 && eobtotal == 0 → skip) and the skipped-inter mask rule (skip && is_interkeeps only the prediction masks). Verified by mask-identity + edge-set + pixels (above). - Gates —
cargo test -p ec-vp9green (below); refusals re-checked; prose updated.
Bug classes found while porting (all fixed, each with its evidence)
- Direct-read coordinates taken after the tap padding.
dec_build_inter_predictorscomputesbuf_ptr = ref_frame + y0*stride + x0BEFOREy0 -= INTERP_EXTEND - 1/x0 -= …; our first version read the direct path from the padded coordinates, i.e. 3 rows/cols early. Signature: border-path blocks exact (top/bottom SB rows), direct-path blocks wrong by up to ±5, andSKIPLF-style isolation shows the error is in prediction. Independent python re-derivation of the C predictor from the oracle's reference frame identified it in one step (oracle 45 vs ours 47). - Skipped intra blocks inside an inter frame skipped
dec_reset_skip_context. libvpx calls it at the top ofdecode_block(before the intra/inter split); ours only in the inter arm, leaving stale above-context bytes → atile bool decoder desyncin frame 2, with the first divergence a prob difference at the same ordinal read (the skill's "same ordinal, different question" signature). - Skipped inter blocks kept full loop-filter masks.
grids.skip_interwas only set by the eob promotion, so a coded-skip inter block got the size/tx masks instead of prediction-only masks → extra 16-tap edges (mask-identity check caught it asL16 ⊉ L32). - Intra-in-inter tx type. libvpx's luma mode for a sub-8x8 block is the
SUB-BLOCK's (
mi->bmi[…]), used forintra_mode_to_tx_type_lookup; the merged syntax walk usedinfo.mode. Now shared by the syntax and pixel walks (they must agree or the two paths read different tokens). mv_ref_list[2]write (crash).ADD_MV_REF_LIST_EB's successful second add isgoto Done; in the "different reference frame" loop the C leaves the loop, our port kept iterating and wrote past the two-entry list (inter.rs, now an explicitbreak). Found by the corpus sweep —vp9-superframe-altref.ivfpanicked at frame 14 before the fix; 60/60 frames byte-identical after.- Frame-level interpolation filter numbering (
read_interp_filter): the header's literal index runs throughliteral_to_filter = {EIGHTTAP_SMOOTH, EIGHTTAP, EIGHTTAP_SHARP, BILINEAR}— NOT libvpx's#definenumbering (EIGHTTAP 0). Converted whereframe_interpis built; inert on switchable streams (the fixture's), correct for non-switchable ones.
Named refusals (unchanged or added)
vp9 profile N/vp9 subsampling— unchanged (existing tests).vp9 intra-only— unchanged refusal, now also reachable fromdecode().vp9 inter reference size change(new): a named reference whose coded size differs from the current frame is refused by name (libvpx scales it; scaling is not ported in this lane).vp9 inter odd frame dimensions(new): odd width/height refused by name — the keyframe crop stores chroma atfloor(w/2)while the predictor reads libvpx'suv_crop_width = (w+1)/2; the two disagree only for odd extents, so those are refused rather than silently wrong.
Deferred
deferred(fix-now-next-lane)— frame 72 desync onvp9-1080p-60-8bit.ivf. Frames 0..71 are byte-identical; frame 72 is an ordinary inter frame (MODEDUMPCHSUM:tx_mode=4 ref_mode=0 allow_hp=1 interp=4 intra_only=0 er=0, matching its neighbours) and dies withtile bool decoder desync. An unexercised inter syntax path (compound reference / sub-8x8 / a specificuse_prev_frame_mvsstate) is the likely home; the 1080p 24fps GOP, the 4K GOP and the altref stream do not reach it. Repro:$HOME/.cache/vp9pix/sweep.sh vp9-1080p-60-8bit 1920 1080.deferred(unblock: odd-extent chroma layout)— the odd-dimension refusal above; the root fix is to store reference chroma at(w+1)/2, which also changes the keyframe path's returned plane layout.- Superseded claim:
lanes/vp9inter.report.mdranked cause 3 ("keyframe multi-tile-column desync on/tmp/inter.ivfframe 0") does not reproduce at this lane's base —INTER_IVF=/tmp/inter.ivf INTER_EXPECT=none cargo test -p ec-vp9 --test scratch_interdumppasses on the untouched main checkout (f715d70c, the tile-row fix, landed before the inter-syntax merge 32d81e8f)./tmp/inter.ivfnow decodes all 3 frames byte-exactly.
Gates
$ CARGO_TARGET_DIR=$HOME/.cache/cargo-target-vp9pix cargo test -p ec-vp9
exit=0 — every binary green, including the new witness
tests/inter_pixels_exact.rs (2 tests: GOP + GOP with tile columns,
ffmpeg libvpx rawvideo oracle, self-generated
fixtures; non-vacuity proof: with
EC_VP9_SKIP_LF=1 both tests FAIL at frame 0
byte 31 — ours 81 vs ffmpeg 82)
tests/keyframe_exact.rs (4 tests, incl. the rewritten
inter_stream_decodes_and_matches_ffmpeg:
60/60 frames of the altref stream vs ffmpeg)
Repro (all commands)
# gate
cd /home/user/Documents/Code/Rust/edith_codecs-vp9pix
CARGO_TARGET_DIR=$HOME/.cache/cargo-target-vp9pix cargo test -p ec-vp9
# 1080p single-tile inter stream vs the instrumented oracle
cd $HOME/.cache/vp9pix && PIXDUMP=$HOME/.cache/vp9pix/oracle_inter1.pix ./drv_pix inter1.ivf
cd /home/user/Documents/Code/Rust/edith_codecs-vp9pix
CARGO_TARGET_DIR=$HOME/.cache/cargo-target-vp9pix INTER_IVF=$HOME/.cache/vp9pix/inter1.ivf \
EC_VP9_PIXDUMP=$HOME/.cache/vp9pix/ours_inter1.pix \
cargo test -p ec-vp9 --test scratch_pixdump -- --nocapture
cd $HOME/.cache/vp9pix && python3 pixcmp.py oracle_inter1.pix ours_inter1.pix 1920 1080
# mask identity / edge sets
LFMASKSY=1 ./drv_pix inter1.ivf 2>&1 | grep '^LFY' > lfy_oracle.txt
LFTRACE=1 ./drv_pix inter1.ivf 2>&1 | grep '^LFTR' > lf_oracle_1.txt # LFTRACE=<frame>
VERDICT
GATE 1 — cargo test -p ec-vp9 green in the worktree (private target dir),
including the new pixel witnesses: PASS.
GATE 2 — inter1.ivf decode() returns 3 shown frames, each byte-identical to
the libvpx 1.15 oracle's planes (comparator output above): PASS.
GATE 3 — per-milestone evidence lines above; every pixel mismatch met during
development is named with its root cause (6 classes): PASS.
GATE 4 — this report: baseline, per-milestone evidence, inter.ivf
disposition, deferred items with dispositions, repro commands: PASS.
GATE 5 — committed to lane-vp9-pix, git status clean, no push/merge: see
the git log below.
GATE 6 — VERDICT section: this one.
FLAGS (the verifier should re-derive these independently)
- The direct-read coordinate rule (class 1) is the single most load-bearing
line in
mc.rs:originmust come from the MV-adjusted, NOT tap-padded,x0/y0. Re-derive fromvp9_decodeframe.c:672-728and check ourx0_mv/y0_mvusage. skip_intersemantics:skip && is_interat BOTH the coded-skip and theeobtotal == 0promotion, and the mask early-return placement (after the above/left prediction masks). Mask-identity can be re-run per SB withEC_VP9_LFMASKSY=1vsLFMASKSY=1.- The
mv_ref_list[2]fix changes an existing (merged) syntax path: the altref fixture panicked before it and is byte-exact after — re-runvp9-superframe-altref.ivfend to end. - Reference storage extent: refs must keep the 64-aligned plane buffer (the decoded overhang rows are readable by the direct path). Cropping them reproduces the class-1 symptom set; confirm by checking that frames 1+ of the 1080p GOP match (the overhang is read at the frame bottom).
- The 60fps frame-72 desync is a real open defect: verify it is
independent of this lane's changes (
scratch_interdumpon the base checkout reports the same frame-72 desync in the syntax walk). - Corpus sweeps were run on this workstation with
/tmpfixtures; the 1080p/2160p/altref dumps are regenerable fromsweep.sh.
MERGE-SIDE FOLLOW-UPS (2026-09-19)
- Merge: fast-forward
597b7442..7f1ff7d5from the main checkout; the create-list carried exactly the four expected files (src/mc.rs,tests/inter_pixels_exact.rs,tests/scratch_pixdump.rs, this report) — no junk-file class. - Independent verification before merge: reviewer re-derived all eight claim
families (own oracle+Rust pixel dumps, corpus sweeps 48/48, 48/48, 60/60,
frame-72 desync reproduced AND proven lane-independent at base 597b7442 via
scratch_interdump, non-vacuity reproduced byte-for-byte, all six bug-class fixes audited against the libvpx sources). VERDICT: PASS, confidence 0.94. Residual-risk note: the MV clamp is applied unconditionally where libvpx gates it — benign on these streams, recorded for the next inter lane. - Fixtures: the lane's permanent tests self-generate their streams with
ffmpeg/libvpx at run time, and the worktree's
fixtures/was a symlink to the main checkout's — no gitignored fixture copy was needed. - Dependent-crate sweep: nothing depends on
ec-vp9(the dependency edge isec-vp9 -> ec-vp9-syntax, untouched by this lane). - Merged-tree gates, run on main after the ff:
cargo test -p ec-vp9— 20 test binaries, 0 failed, 0 ignored;cargo check --workspace --all-targets— clean, warning parity with the declared baseline (modes.rspartition_probs/x_mis/y_mis,read_partition, tablesTM_PRED). tests/scratch_pixdump.rsSKIPs whenINTER_IVF/EC_VP9_PIXDUMPare unset and panics naming the path when set-but-missing — workspace runs are safe after tmpfs reaps.- Kept for the next lane (deliberately not deleted): the
EC_VP9_TRACE/EC_VP9_PIXDUMP/EC_VP9_SKIP_LF/EC_VP9_LFMASKSYhooks, the scratch harnesses, and$HOME/.cache/vp9pix/(oracledrv_pix, fixtures,pixcmp.py,sweep.sh). - Lane worktree
../edith_codecs-vp9pixand its private target dir were removed after the merge; branchlane-vp9-pixstays.