diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 05d1950f..35ae8ccf 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -6372,6 +6372,26 @@ fn decode_inter_block( } } } + // lane-gm r4: `allow_warp`'s `global_warp_allowed` branch + // (`reconinter.c:33-55`), gated INDEPENDENTLY of `motion_mode` -- + // libaom's `av1_init_warp_params` runs for every inter + // predictor build, not just a `WARPED_CAUSAL`-selected one. Only + // reachable when `warp_params` is still `None` here: a block + // that read (and got) local `WARPED_CAUSAL` above already has + // `local_warp_allowed && !wm_params.invalid`, which `allow_warp` + // checks FIRST and short-circuits on -- the global branch is an + // `else if`, never layered on top. `is_global_mv_block` already + // encodes `allow_warp`'s size bound (`min(bw4,bh4) >= 2`, i.e. + // >=8px both dims, matching `av1_init_warp_params`'s + // `block_height < 8 || block_width < 8` early return) and, via + // `motion_mode_eligible`'s own suppression above, the + // `force_integer_mv` case never reads a motion_mode symbol at + // all -- checked again here directly since this branch fires + // independent of `motion_mode_eligible`. + let gm_ref = &global_motion[(ref_frame - LAST_FRAME) as usize]; + if warp_params.is_none() && is_global_mv_block && !force_integer_mv && !gm_ref.invalid { + warp_params = crate::warp::global_warp_params(gm_ref.params); + } if std::env::var_os("EC_AV1_TELL").is_some() { eprintln!( "TELL mi_row={mi_row} mi_col={mi_col} label=post_motion_mode eligible={} tell={} range={}", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 4d96fd86..7bf000a9 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -235,14 +235,47 @@ pub fn decode_stream(data: &[u8]) -> Result> { // to plain translational MC with the block-centre mv for every // other GLOBALMV block, which is only a centre-point approximation // of the true per-pixel warp. That is the entire remaining gap. + // lane-gm r4: `decode.rs` now feeds `global_motion[ref]` into + // `crate::warp::global_warp_params` for every single-ref + // `is_global_mv_block` (ROTZOOM/AFFINE), matching `allow_warp`'s + // `global_warp_allowed` branch -- ROTZOOM is pin-verified + // (`gm-seed43.obu`, frame 1 luma MATCH) and TRANSLATION already + // worked (`gm_get_motion_vector`'s translation-only mv, no warp + // needed). AFFINE is untested this round (no aomenc fixture in the + // wedge gate reached a 6-parameter model) -- keep refusing it by + // name rather than shipping an unverified decode. if header.frame_type != FrameType::Key && header.global_motion[..7] .iter() - .any(|gm| gm.model != WarpModel::Identity) + .any(|gm| gm.model == WarpModel::Affine) { return Err(Error::unsupported( "AV1 decode_stream", - "an inter frame whose global motion for a single-reference frame is not IDENTITY (GLOBALMV needs the full warp derivation this decoder does not carry)", + "an inter frame whose global motion for a single-reference frame is AFFINE (unverified this round; ROTZOOM/TRANSLATION/IDENTITY are proven)", + )); + } + // lane-gm r4: a NEW mismatch, distinct from the one this round + // fixed and NOT explained by `reference_select`/compound (traced + // live: the mismatched frame of the seed-43 pin has + // `reference_select == false`) -- localized instead to the one + // property that DOES distinguish it from every frame that already + // matches: TWO different ref slots (`GOLDEN_FRAME`, `BWDREF_FRAME`) + // carry a non-translation model AT THE SAME TIME. The pin-verified + // fix (frame 1) only ever exercised a single active non-identity + // slot (`LAST_FRAME` alone). Root cause not yet found within this + // round's budget (do not guess-fix): refuse the untested shape by + // name -- more than one concurrently active ROTZOOM/AFFINE ref -- + // rather than ship it silently wrong. + if header.frame_type != FrameType::Key + && header.global_motion[..7] + .iter() + .filter(|gm| gm.model != WarpModel::Identity && gm.model != WarpModel::Translation) + .count() + > 1 + { + return Err(Error::unsupported( + "AV1 decode_stream", + "an inter frame with more than one concurrently active ROTZOOM/AFFINE global-motion ref slot (single-active-slot ROTZOOM is pin-verified; this shape is not)", )); } // lane-av1comp: `decode_inter_block`/`decode_inter_block8` now read diff --git a/crates/ec-av1/src/warp.rs b/crates/ec-av1/src/warp.rs index db33c9cd..e3228046 100644 --- a/crates/ec-av1/src/warp.rs +++ b/crates/ec-av1/src/warp.rs @@ -400,6 +400,21 @@ pub fn find_projection( }) } +/// lane-gm r4: `allow_warp`'s `global_warp_allowed` branch +/// (`reconinter.c:50`) -- reuses the SAME shear decomposition +/// [`find_projection`]'s local-warp path calls (`get_shear_params`), just +/// keyed on the frame's already-coded `global_motion[ref]` model instead of +/// a per-block least-squares fit. Caller gates this on `is_global_mv_block +/// && !global_motion[ref].invalid` (matching `allow_warp` exactly); `None` +/// here means the model's own shear is not filter-representable even though +/// the frame header's `warpValid` bit said otherwise for a `mat[2] <= 0` +/// edge `get_shear_params` additionally rejects -- caller keeps its +/// translational fallback in that rare case. +pub fn global_warp_params(wmmat: [i32; 6]) -> Option { + let (alpha, beta, gamma, delta) = get_shear_params(wmmat)?; + Some(WarpParams { wmmat, alpha, beta, gamma, delta }) +} + fn clip_pixel(v: i32) -> u8 { v.clamp(0, 255) as u8 }