diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index e1a80dad..7bfb8d18 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -12798,13 +12798,30 @@ fn apply_loop_restoration( deblocked_v: &PlaneBuf, lr: &LoopRestorationParams, grid: &crate::restoration::RestorationGrid, + // lane-golomb r8: this frame header's own (cropped) luma size. Loop + // restoration is the ONE post-decode filter that does NOT run over the + // mi-rounded plane: libaom's `av1_loop_restoration_filter_frame` sizes + // every plane with `av1_get_upsampled_plane_size` -- `plane_w = + // ROUND_POWER_OF_TWO(cm->superres_upscaled_width, ss_x)`, `plane_h = + // ROUND_POWER_OF_TWO(cm->height, ss_y)` (`av1/common/restoration.c:47`) + // -- and asserts it equals the buffer's CROP width + // (`restoration.c:1106`), then `av1_extend_frame(..., plane_w, plane_h, + // ...)` (`restoration.c:1109`) replicates the right/bottom border from + // that cropped edge before any unit is filtered. Deblock and CDEF DO + // walk the mi grid, which is why passing `true_width`/`true_height` + // here went unnoticed until a frame whose size is not a multiple of 8 + // (68 -> mi-rounded 72): the LR taps at the last four real columns then + // read this decoder's own decoded samples at columns 68..71 where + // libaom reads column 67 replicated -- +-1 over the straddling band + // (class av1-truesize-lane: true frame size vs mi-rounded). + (frame_w, frame_h): (usize, usize), ) { y.data = crate::restoration::apply_loop_restoration_plane( &y.data, &deblocked_y.data, y.width, - y.true_width, - y.true_height, + frame_w, + frame_h, 0, lr.frame_restoration_type[0], lr.loop_restoration_size[0], @@ -12815,8 +12832,8 @@ fn apply_loop_restoration( &u.data, &deblocked_u.data, u.width, - u.true_width, - u.true_height, + frame_w.div_ceil(2), + frame_h.div_ceil(2), 1, lr.frame_restoration_type[1], lr.loop_restoration_size[1], @@ -12827,8 +12844,8 @@ fn apply_loop_restoration( &v.data, &deblocked_v.data, v.width, - v.true_width, - v.true_height, + frame_w.div_ceil(2), + frame_h.div_ceil(2), 1, lr.frame_restoration_type[2], lr.loop_restoration_size[2], @@ -14837,7 +14854,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v); dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); - apply_loop_restoration(&mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid); + apply_loop_restoration( + &mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid, + (frame_width as usize, frame_height as usize), + ); let (fw, fh) = (frame_width as usize, frame_height as usize); if fw == width && fh == height { @@ -20713,7 +20733,18 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // true size. Height must still match: AV1 superres never scales height // (r8's derivation, `mc.rs`'s own doc), and nothing in this decode path // has a vertical scaling pass. - if reference.height != true_height { + // lane-golomb r8: the comparison is against the header's own frame + // height, NOT the mi-rounded `true_height`. libaom compares references + // on the CROPPED dimensions -- `av1_setup_scale_factors_for_frame(&sf, + // ref->y_crop_width, ref->y_crop_height, cm->width, cm->height)` + // (`av1/common/reconinter.c`), and a reference is "scaled" only when + // those differ (`av1_is_scaled`). A decoded `Picture` is cropped to + // `fw`/`fh`, so for any height that is not a multiple of 8 (68 -> + // mi_rows 18 -> `true_height` 72) this test compared 68 against 72 and + // refused every same-size reference (class av1-truesize-lane: true + // frame size vs mi-rounded). Height must still MATCH: AV1 superres + // never scales height, and no path here has a vertical scaling pass. + if reference.height != frame_height as usize { return Err(unsupported( "a reference picture whose height does not match this frame's own true size", )); @@ -22663,7 +22694,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v); dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); - apply_loop_restoration(&mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid); + apply_loop_restoration( + &mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid, + (frame_width as usize, frame_height as usize), + ); let motion_field = build_motion_field( &grid, diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 319e4d72..dced19d4 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -18888,6 +18888,28 @@ mod tests { // The inter arm: >= 4 frames so the 32-level edge path in the INTER // tile walk is exercised too. arms.push((192, 80, 5, false)); + // lane-golomb r8 MEASURED, arm STILL NOT added (every cq level is + // vacuous, panicking or red -- each measured this round with + // `arms.push((192, 68, 5, false))`, log + // `$HOME/.cache/golomb-gate-r8{b,e,f,g}.log`): + // * the r7 blocker IS fixed -- no attempt refuses "a reference + // picture whose height does not match this frame's own true + // size" any more (`decode.rs`'s comparison now uses the header's + // frame height, per libaom's crop-dimension reference test). + // * cq35 now refuses LATER, by another lane's name: "an inter + // SB-level AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B)" -- so the + // arm compares nothing (class `counter-from-refused-stream`). + // * cq40 PANICS in `decode_inter_block8` + // (`from_switchable_symbol` handed a 4th symbol, `mc.rs:203`) = + // lane-sub8's own open below-8x8 desync; a panic cannot be + // tolerated as a named refusal. + // * cq59 8-bit is RED: `frame 1 plane Y: 217 pixels differ, first + // at row 60 col 170 (ours 172 vs ffmpeg 173)`, and the cq35 + // 10-bit twin is RED at `row 56 col 48 (ours 530 vs ffmpeg + // 531)`. Both are +-1 bands in rows 56..63, i.e. the deblock/CDEF + // bleed ABOVE the 4-px straddling row band (64..67) -- the same + // shape as the `(68, 192, 5, false)` column defect below, so the + // two are very likely ONE straddling-band reconstruction defect. // lane-golomb r7 MEASURED, arm NOT added (it would be vacuous or red): // a 68-px axis leaves the last superblock straddling by 4 px, the // shape `read_var_tx_size`'s `blk_row >= max_h_mi || blk_col >= @@ -19010,6 +19032,12 @@ mod tests { } let tag = format!("{width}x{height} cq{cq} frames={frame_count} 10bit={ten_bit}"); let before = crate::decode::edge32_hits(); + // lane-golomb r8: name the attempt BEFORE decoding it -- a + // desync surfaces as a panic deep in mc.rs with no arm in the + // message, and r8 spent a run bisecting arms by hand. + if std::env::var_os("EC_GATE_VERBOSE").is_some() { + eprintln!("{NAME}: attempting {tag}"); + } let decoded = match decode_stream(&stream) { Ok(frames) => frames, Err(e) => {