forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-av1golden7': film grain, not GOLDEN, broke frame 0; refuse apply_grain

Browse files at this commit

64fb81bd8c7f90c363c768894b3b2a449ccd7deaAhmet Kaan GümüşParent: c11ca7a2e169ef
crates/ec-av1/src/decode.rsmodified+34 -66
@@ -3700,11 +3700,9 @@ fn decode_inter_block(
3700 // into a `[Option<&PlaneBuf>; REFS_PER_FRAME]` addressed by the decoded3700 // into a `[Option<&PlaneBuf>; REFS_PER_FRAME]` addressed by the decoded
3701 // reference, same as the CDF/picture DPB slots `decode_stream` already3701 // reference, same as the CDF/picture DPB slots `decode_stream` already
3702 // keeps.3702 // keeps.
3703- // (round 6: parameters kept threaded but unread while the GOLDEN arm is3703+ golden_y: Option<&PlaneBuf>,
3704- // masked again -- see the refusal below.)3704+ golden_u: Option<&PlaneBuf>,
3705- _golden_y: Option<&PlaneBuf>,3705+ golden_v: Option<&PlaneBuf>,
3706- _golden_u: Option<&PlaneBuf>,
3707- _golden_v: Option<&PlaneBuf>,
3708 base_q_idx: u8,3706 base_q_idx: u8,
3709 luma_set_intra: TxbSet,3707 luma_set_intra: TxbSet,
3710 luma_set_inter: TxbSet,3708 luma_set_inter: TxbSet,
@@ -3739,71 +3737,41 @@ fn decode_inter_block(
3739 if is_inter {3737 if is_inter {
3740 let ref_frame = read_single_ref(dec, cdfs, neighbours.above_ref[c], neighbours.left_ref[r]);3738 let ref_frame = read_single_ref(dec, cdfs, neighbours.above_ref[c], neighbours.left_ref[r]);
3741 ref_frame_for_lf = ref_frame;3739 ref_frame_for_lf = ref_frame;
3742- // round 4 (lane-av1golden): 120+ attempts across a real aomenc3740+ // round 4-8 (lane-av1golden through lane-av1golden6): repeatedly
3743- // recipe never landed a GOLDEN_FRAME-firing, decodable stream (every3741+ // un-masked and re-masked chasing what looked like a GOLDEN_FRAME MC
3744- // attempt hit an unrelated named refusal first), so this arm stayed3742+ // bug -- lf_level `mode_deltas`/`ref_deltas` forwarding fixes
3745- // refused pending a fixture that could prove it another way. A3743+ // (rounds 5/6, both real and kept), and a switchable_interp ctx
3746- // hand-built stream did (stream.rs's fixture drives GOLDEN_FRAME3744+ // ref-frame gate (round 8, real and kept). Every remaining
3747- // through a real OBU stream ffmpeg also decodes), and the arm went3745+ // "GOLDEN_FRAME mismatch" chased past round 8 (including a frame-0
3748- // live at the round-4 merge.3746+ // *intra keyframe* luma mismatch that could not possibly depend on
3749- // round 5 (lane-av1golden2): the first real aomenc streams through3747+ // this arm at all) turned out to be a single unrelated cause: round
3750- // this arm mismatched. Symbol-trace vs a patched aomdec proved one3748+ // 9 (lane-av1golden7) traced `fixtures/golden6-mismatch.obu`'s
3751- // cause `LAST_FRAME`-reachable -- `lf_level`'s flat `mode_deltas[1]`3749+ // frame-0 mismatch down to `header.film_grain.apply_grain == true`
3752- // on `GLOBALMV` blocks (fixed; see `Neighbours::ref_grid`'s packed3750+ // (aomenc's `--tune-content=film` denoises the coded picture and
3753- // sign) -- and a second, loop-filter level/sharpness wrongly3751+ // has the decoder re-synthesize grain per spec 7.18.3) -- this
3754- // forwarding from the primary ref frame instead of spec 7.20's3752+ // decoder never implements grain synthesis at all, so it silently
3755- // `ref_deltas`/`mode_deltas` (fixed, lane-av1golden3). Both fixes3753+ // returned the clean base picture while ffmpeg (dav1d) returned the
3756- // are `LAST_FRAME`-reachable and independent of the golden plane3754+ // grain-synthesized one. That bug fires on *any* frame, key or
3757- // itself.3755+ // inter, and is orthogonal to which reference a block selects --
3758- // round 6 (lane-av1golden4): un-masked again and re-masked in the3756+ // the earlier "correlates with GOLDEN firing" pattern was survivor
3759- // same round. A real aomenc stream (pinned:3757+ // bias: the golden gate only ever compared streams where
3760- // `stream::tests::pinned_golden4_stream_decodes_pixel_exact`, seed3758+ // `non_last_ref_hits` fired, and `--tune-content=film` is part of
3761- // 43, frame 3 luma) mismatched by exactly +-1 on 3 of 4096 pixels,3759+ // that same gate's own aomenc recipe. `decode_stream` now refuses
3762- // all inside the loop filter's 14-wide edge window at the y=323760+ // `apply_grain` streams by name instead of silently mismatching --
3763- // horizontal boundary between a GOLDEN_FRAME block (ref_idx 4,3761+ // but unmasking `GOLDEN_FRAME` with that fix in still shows a real,
3764- // computed level 3) and a LAST_FRAME block (ref_idx 1, level 4) --3762+ // separate residual MC bug: round 9 (lane-av1golden7)'s forwarding
3765- // `edge_params`/`lf_level`'s own math checks out against spec 7.14.43763+ // gate hit 1/20 real aomenc streams mismatching (frame 3 luma,
3766- // by hand (`base=4`, `ref_deltas[4]=-1`, `mode_deltas=[0,0]` all3764+ // apply_grain=false, non_last_ref_hits delta=2), pinned in
3767- // match the default table).3765+ // `fixtures/golden7-forwarding-mismatch.obu` for round 10. `GOLDEN_FRAME`
3768- //3766+ // stays refused by name until that's found.
3769- // round 7 (lane-av1golden5): un-masked again, bisected with a
3770- // patched aomdec (`EC_AV1_PREFILT_DUMP`/`EC_AV1_POSTFILT_DUMP` env
3771- // dumps already in `/tmp/libaom-src`'s `decodeframe.c`) against the
3772- // same pin. Dumped this decoder's own pre-`apply_deblock` luma rows
3773- // 30-36 for frame 3 and diffed them against aomdec's pre-filter
3774- // dump for the same bytes: the exact same 3 pixels (row32 col37,
3775- // row33 col39, row33 col54) already mismatch BEFORE the loop filter
3776- // runs, by the exact same +-1 the final assertion sees --
3777- // `apply_deblock` itself is now CLEARED, both this round's kernel
3778- // hypothesis and round 6's are ruled out. All 3 pixels are inside
3779- // the single `GOLDEN_FRAME` 32x32 NEWMV block at (px=32,py=32),
3780- // mv=(-7,-7) 1/8-pel (x_q4=y_q4=498, both axes fraction 2/16),
3781- // `skip=1` (no residual, so the mismatch is pure MC output),
3782- // REGULAR/REGULAR resolved filter, `enable_dual_filter=true`. The
3783- // reference plane bytes this block reads (dumped, rows 28-37) match
3784- // the picture the outer per-frame ffmpeg assertion already proved
3785- // bit-exact for frames 0-2, so it is not a stale/wrong golden
3786- // picture either -- the divergence is inside
3787- // `mc::predict_with_filters`'s own 2D convolution or the
3788- // switchable-filter symbol resolution for this exact (dual axis,
3789- // non-globalmv, GOLDEN_FRAME) combination, unproven past that.
3790- // Re-masked pending that isolation -- do not re-litigate
3791- // `apply_deblock`/`lf_level` again, both are cleared for this pin.
3792 let (py_ref, pu_ref, pv_ref) = match ref_frame {3767 let (py_ref, pu_ref, pv_ref) = match ref_frame {
3793 LAST_FRAME => (ref_y, ref_u, ref_v),3768 LAST_FRAME => (ref_y, ref_u, ref_v),
3794 _ => {3769 _ => {
3795 return Err(unsupported(3770 return Err(unsupported(
3796- "a reference frame other than LAST_FRAME (round 8: GOLDEN_FRAME's decode \3771+ "a reference frame other than LAST_FRAME (LAST2/LAST3/GOLDEN/BWDREF/\
3797- path exists but is masked -- unmasking it with a switchable_interp \3772+ ALTREF2/ALTREF still have no MC path -- GOLDEN's residual MC bug is \
3798- ref_frame-gated context fix still produces a real frame-0 (intra \3773+ pinned in fixtures/golden7-forwarding-mismatch.obu, round 9 \
3799- keyframe) luma mismatch against ffmpeg whenever GOLDEN_FRAME actually \3774+ lane-av1golden7)",
3800- fires downstream in the same stream, reproduced twice live \
3801- (seeds 57, 59; reproducing stream dumped to \
3802- fixtures/golden6-mismatch.obu). Root cause is not \
3803- the switchable_interp context (that gate is correct and kept) but \
3804- something GOLDEN-adjacent that corrupts an unrelated earlier frame's \
3805- comparison -- possibly frame-count/ordering divergence between our \
3806- decoder and ffmpeg once aomenc's RD picks GOLDEN, unproven past that)",
3807 ));3775 ));
3808 }3776 }
3809 };3777 };
crates/ec-av1/src/stream.rsmodified+75 -0
@@ -138,6 +138,28 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
138 "a frame with segmentation enabled (this decoder never reads a per-block segment_id symbol)",138 "a frame with segmentation enabled (this decoder never reads a per-block segment_id symbol)",
139 ));139 ));
140 }140 }
141+ // lane-av1golden7 r9: `apply_grain` (spec 7.18.3, the decoder-side
142+ // synthesis `film_grain_params` drives) is never applied by this
143+ // crate -- it returns the coded (denoised, for content aomenc's
144+ // `--tune-content=film` re-grains) base picture unchanged. Traced
145+ // live from `fixtures/golden6-mismatch.obu`: a frame-0 intra
146+ // keyframe with `apply_grain=true` mismatched ffmpeg on 3855/4096
147+ // luma pixels, all explained by missing synthetic grain (this
148+ // decoder's smooth prediction+residual output visually matches
149+ // ffmpeg's grain-textured one; pixel-exact only where the grain
150+ // scaling curve happens to hit zero). This is what a round-8 hunt
151+ // mistook for a GOLDEN_FRAME-adjacent bug: the golden gate only
152+ // ever compares streams where `non_last_ref_hits` fired, and
153+ // `--tune-content=film` (which turns grain synthesis on) is part of
154+ // that same gate's own aomenc recipe -- pure survivor bias, not
155+ // causation. Refuse by name rather than silently return a
156+ // grain-free picture.
157+ if header.film_grain.apply_grain {
158+ return Err(Error::unsupported(
159+ "AV1 decode_stream",
160+ "a frame with apply_grain set (this decoder never synthesizes film grain, spec 7.18.3)",
161+ ));
162+ }
141 // Loop restoration carries per-restoration-unit symbols in the tile163 // Loop restoration carries per-restoration-unit symbols in the tile
142 // (spec 5.11.57 `read_lr`, one group per LR unit reached from the164 // (spec 5.11.57 `read_lr`, one group per LR unit reached from the
143 // superblock walk) that this decoder never reads -- same165 // superblock walk) that this decoder never reads -- same
@@ -1864,6 +1886,37 @@ mod tests {
1864 }1886 }
1865 }1887 }
1866 1888
1889+ /// lane-av1golden7 round 9: pins the residual GOLDEN_FRAME MC bug found
1890+ /// by the forwarding gate once film grain is out of the way (1/20 real
1891+ /// aomenc streams, frame 3 luma, apply_grain=false, `non_last_ref_hits`
1892+ /// delta=2). `GOLDEN_FRAME` refuses by name until this decodes exact.
1893+ #[test]
1894+ #[ignore = "reads a pinned fixture path outside the repo; run manually"]
1895+ fn pinned_golden7_stream_decodes_pixel_exact() {
1896+ use crate::decode::non_last_ref_hits;
1897+ let path = concat!(
1898+ env!("CARGO_MANIFEST_DIR"),
1899+ "/../../fixtures/golden7-forwarding-mismatch.obu"
1900+ );
1901+ let stream = std::fs::read(path).expect("reading pinned stream");
1902+ if !have_ffmpeg() {
1903+ eprintln!("SKIP pinned_golden7_stream_decodes_pixel_exact: no ffmpeg");
1904+ return;
1905+ }
1906+ let before = non_last_ref_hits();
1907+ let frames = decode_stream(&stream).expect("pinned stream must decode");
1908+ eprintln!(
1909+ "non_last_ref_hits before={before} after={}",
1910+ non_last_ref_hits()
1911+ );
1912+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, 64, 64, 4);
1913+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
1914+ assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (pinned)");
1915+ assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg (pinned)");
1916+ assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (pinned)");
1917+ }
1918+ }
1919+
1867 /// lane-av1refs's decisive single-non-LAST-reference gate: identical1920 /// lane-av1refs's decisive single-non-LAST-reference gate: identical
1868 /// recipe to1921 /// recipe to
1869 /// [`a_real_aomenc_inter_sequence_with_cdf_forwarding_decodes_pixel_exact`]1922 /// [`a_real_aomenc_inter_sequence_with_cdf_forwarding_decodes_pixel_exact`]
@@ -2349,4 +2402,26 @@ mod tests {
2349 refusals.join("\n")2402 refusals.join("\n")
2350 );2403 );
2351 }2404 }
2405+
2406+ /// lane-av1golden7 r9's decisive fixture: a real aomenc stream (seed 59,
2407+ /// `--tune-content=film`, GOLDEN_FRAME firing downstream) whose frame-0
2408+ /// *intra keyframe* mismatched ffmpeg on 3855/4096 luma pixels -- traced
2409+ /// to `apply_grain=true` (spec 7.18.3 grain synthesis, never
2410+ /// implemented here), entirely unrelated to GOLDEN_FRAME or frame
2411+ /// ordering. `decode_stream` now refuses `apply_grain` streams by name;
2412+ /// this pins that refusal rather than a silent grain-free mismatch.
2413+ #[test]
2414+ fn a_real_aomenc_stream_with_film_grain_refuses_by_name() {
2415+ let data = std::fs::read(concat!(
2416+ env!("CARGO_MANIFEST_DIR"),
2417+ "/../../fixtures/golden6-mismatch.obu"
2418+ ))
2419+ .unwrap();
2420+ let err = decode_stream(&data).expect_err("apply_grain stream must be refused");
2421+ let msg = err.to_string();
2422+ assert!(
2423+ msg.contains("apply_grain"),
2424+ "expected an apply_grain refusal, got: {msg}"
2425+ );
2426+ }
2352 }2427 }