GLOBALMV loop-filter mode delta
Browse files at this commitef03524404e1fc9c8f356617af08afbc2c880c6fParent: 181baf7- fix
- GLOBALMV loop-filter mode delta
- mask GOLDEN behind its stacked defect
2 changed files +69 -63
- crates/ec-av1/src/decode.rs +48 -28
- crates/ec-av1/src/stream.rs +21 -35
crates/ec-av1/src/decode.rsmodified+48 -28
| @@ -674,7 +674,9 @@ struct Neighbours { | ||
| 674 | 674 | /// transform size, spec 7.14's `get_transform_size`/`get_filter_level` |
| 675 | 675 | /// edge-length lookup (`apply_deblock`). |
| 676 | 676 | tx_grid: Vec<u8>, |
| 677 | - /// Per-4x4-mi reference frame (`0` = intra, `1..=7` = `MV_REFERENCE_FRAME`) | |
| 677 | + /// Per-4x4-mi reference frame (`0` = intra, magnitude `1..=7` = | |
| 678 | + /// `MV_REFERENCE_FRAME`, negative = that reference coded as `GLOBALMV` -- | |
| 679 | + /// `lf_level`'s `mode_lf_lut` row 0, lane-av1golden2) | |
| 678 | 680 | /// -- the loop filter's ref/mode delta lookup (spec 7.14.4 |
| 679 | 681 | /// `get_filter_level`, `loop_filter_ref_deltas[ref_frame]`; lane-av1refs: |
| 680 | 682 | /// widened from a bare `is_inter` bool, which collapsed every non-`LAST` |
| @@ -2398,10 +2400,14 @@ fn unit_log2(px: u32) -> i32 { | ||
| 2398 | 2400 | } |
| 2399 | 2401 | } |
| 2400 | 2402 | |
| 2401 | -/// spec 7.14.4's `get_filter_level`, restricted to this decoder's shapes: | |
| 2402 | -/// every inter block is a single `LAST_FRAME` reference with a non-`GLOBALMV` | |
| 2403 | -/// mode, so `is_inter` alone selects `ref_deltas`/`mode_deltas` (design note | |
| 2404 | -/// on [`Neighbours::ref_grid`]). | |
| 2403 | +/// spec 7.14.4's `get_filter_level`: `ref_deltas` is indexed by the block's | |
| 2404 | +/// reference frame, `mode_deltas` by `mode_lf_lut[mode]` -- `0` for | |
| 2405 | +/// `GLOBALMV`, `1` for `NEARESTMV`/`NEARMV`/`NEWMV` (intra gets no mode | |
| 2406 | +/// delta). `ref_frame` here is [`Neighbours::ref_grid`]'s packed cell: | |
| 2407 | +/// magnitude = reference (`0` = intra), sign = `GLOBALMV` (lane-av1golden2: | |
| 2408 | +/// the flat `mode_deltas[1]` this used before was a `LAST_FRAME`-reachable | |
| 2409 | +/// wrong delta on every `GLOBALMV` block, masked while any `GOLDEN_FRAME` | |
| 2410 | +/// block anywhere aborted the whole stream's decode before comparison). | |
| 2405 | 2411 | fn lf_level(lf: &LoopFilterParams, plane_idx: usize, dir: usize, ref_frame: i8) -> i32 { |
| 2406 | 2412 | let base = i32::from(if plane_idx == 0 { |
| 2407 | 2413 | lf.level[dir] |
| @@ -2415,10 +2421,11 @@ fn lf_level(lf: &LoopFilterParams, plane_idx: usize, dir: usize, ref_frame: i8) | ||
| 2415 | 2421 | } |
| 2416 | 2422 | let scale = 1i32 << (base >> 5); |
| 2417 | 2423 | let is_inter = ref_frame != 0; |
| 2418 | - let ref_idx = ref_frame as usize; | |
| 2424 | + let is_globalmv = ref_frame < 0; | |
| 2425 | + let ref_idx = ref_frame.unsigned_abs() as usize; | |
| 2419 | 2426 | let mut lvl = base + i32::from(lf.ref_deltas[ref_idx]) * scale; |
| 2420 | 2427 | if is_inter { |
| 2421 | - lvl += i32::from(lf.mode_deltas[1]) * scale; | |
| 2428 | + lvl += i32::from(lf.mode_deltas[usize::from(!is_globalmv)]) * scale; | |
| 2422 | 2429 | } |
| 2423 | 2430 | lvl.clamp(0, 63) |
| 2424 | 2431 | } |
| @@ -3693,9 +3700,11 @@ fn decode_inter_block( | ||
| 3693 | 3700 | // into a `[Option<&PlaneBuf>; REFS_PER_FRAME]` addressed by the decoded |
| 3694 | 3701 | // reference, same as the CDF/picture DPB slots `decode_stream` already |
| 3695 | 3702 | // keeps. |
| 3696 | - golden_y: Option<&PlaneBuf>, | |
| 3697 | - golden_u: Option<&PlaneBuf>, | |
| 3698 | - golden_v: Option<&PlaneBuf>, | |
| 3703 | + // (round 5: parameters kept threaded but unread while the GOLDEN arm is | |
| 3704 | + // masked -- see the refusal below.) | |
| 3705 | + _golden_y: Option<&PlaneBuf>, | |
| 3706 | + _golden_u: Option<&PlaneBuf>, | |
| 3707 | + _golden_v: Option<&PlaneBuf>, | |
| 3699 | 3708 | base_q_idx: u8, |
| 3700 | 3709 | luma_set_intra: TxbSet, |
| 3701 | 3710 | luma_set_inter: TxbSet, |
| @@ -3726,6 +3735,7 @@ fn decode_inter_block( | ||
| 3726 | 3735 | let (luma_grid, u_grid, v_grid); |
| 3727 | 3736 | let block_filter; |
| 3728 | 3737 | let ref_frame_for_lf; |
| 3738 | + let globalmv_for_lf; | |
| 3729 | 3739 | if is_inter { |
| 3730 | 3740 | let ref_frame = read_single_ref(dec, cdfs, neighbours.above_ref[c], neighbours.left_ref[r]); |
| 3731 | 3741 | ref_frame_for_lf = ref_frame; |
| @@ -3733,27 +3743,29 @@ fn decode_inter_block( | ||
| 3733 | 3743 | // recipe never landed a GOLDEN_FRAME-firing, decodable stream (every |
| 3734 | 3744 | // attempt hit an unrelated named refusal first), so this arm stayed |
| 3735 | 3745 | // refused pending a fixture that could prove it another way. A |
| 3736 | - // hand-built stream now does: `a_hand_built_golden_reference_decodes_pixel_exact_against_ffmpeg` | |
| 3737 | - // (stream.rs) drives GOLDEN_FRAME through a real OBU stream that | |
| 3738 | - // ffmpeg also decodes, byte for byte. GOLDEN_FRAME is threaded to | |
| 3739 | - // MC/mvstack/deblock the same as LAST_FRAME from here; every other | |
| 3740 | - // reference (LAST2/LAST3/BWDREF/ALTREF2/ALTREF) still refuses by | |
| 3741 | - // name below -- none of them have a live pixel-exact proof yet. | |
| 3746 | + // hand-built stream did (stream.rs's fixture drives GOLDEN_FRAME | |
| 3747 | + // through a real OBU stream ffmpeg also decodes), and the arm went | |
| 3748 | + // live at the round-4 merge. | |
| 3749 | + // round 5 (lane-av1golden2): the first real aomenc streams through | |
| 3750 | + // this arm mismatched. Symbol-trace vs a patched aomdec proved one | |
| 3751 | + // cause `LAST_FRAME`-reachable -- `lf_level`'s flat `mode_deltas[1]` | |
| 3752 | + // on `GLOBALMV` blocks (fixed; see `Neighbours::ref_grid`'s packed | |
| 3753 | + // sign), previously masked because a GOLDEN block anywhere aborted | |
| 3754 | + // the whole stream via `?` here -- and that fix moved the failure | |
| 3755 | + // from seed 42 (frame 1, V) to seed 48 (frame 3, U): at least one | |
| 3756 | + // more stacked defect remains on the GOLDEN-live path, so the | |
| 3757 | + // refusal narrows back to `LAST_FRAME` until a real-stream gate | |
| 3758 | + // holds pixel-exact with GOLDEN live (the hand-built fixture below | |
| 3759 | + // proved the symbol path and a whole-pel copy, not subpel MC off the | |
| 3760 | + // golden plane -- `a_hand_built_golden_reference_refuses_by_name` | |
| 3761 | + // keeps the fixture and asserts the mask instead). | |
| 3742 | 3762 | let (py_ref, pu_ref, pv_ref) = match ref_frame { |
| 3743 | 3763 | LAST_FRAME => (ref_y, ref_u, ref_v), |
| 3744 | - GOLDEN_FRAME => match (golden_y, golden_u, golden_v) { | |
| 3745 | - (Some(gy), Some(gu), Some(gv)) => (gy, gu, gv), | |
| 3746 | - _ => { | |
| 3747 | - return Err(unsupported( | |
| 3748 | - "GOLDEN_FRAME selected with no golden picture at this frame's \ | |
| 3749 | - ref_frame_idx[3] slot", | |
| 3750 | - )); | |
| 3751 | - } | |
| 3752 | - }, | |
| 3753 | 3764 | _ => { |
| 3754 | 3765 | return Err(unsupported( |
| 3755 | - "a reference frame other than LAST_FRAME/GOLDEN_FRAME (LAST2/LAST3/\ | |
| 3756 | - BWDREF/ALTREF2/ALTREF still have no live pixel-exact proof)", | |
| 3766 | + "a reference frame other than LAST_FRAME (round 5: GOLDEN_FRAME's decode \ | |
| 3767 | + path exists but is masked -- a stacked defect past the GLOBALMV \ | |
| 3768 | + loop-filter mode-delta fix keeps real GOLDEN streams from pixel-exact)", | |
| 3757 | 3769 | )); |
| 3758 | 3770 | } |
| 3759 | 3771 | }; |
| @@ -3840,6 +3852,7 @@ fn decode_inter_block( | ||
| 3840 | 3852 | neighbours.left_filter[r], |
| 3841 | 3853 | ); |
| 3842 | 3854 | block_filter = resolved_filter; |
| 3855 | + globalmv_for_lf = is_globalmv; | |
| 3843 | 3856 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| 3844 | 3857 | eprintln!( |
| 3845 | 3858 | "EC_TRACE mi_row={mi_row} mi_col={mi_col} skip={} is_inter=1 mv=({},{}) is_new_mv={is_new_mv} bsize={side}", |
| @@ -3999,6 +4012,7 @@ fn decode_inter_block( | ||
| 3999 | 4012 | mode_for_tx = mode; |
| 4000 | 4013 | block_filter = [3, 3]; |
| 4001 | 4014 | ref_frame_for_lf = 0; |
| 4015 | + globalmv_for_lf = false; | |
| 4002 | 4016 | let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize); |
| 4003 | 4017 | for dr in 0..side / 4 { |
| 4004 | 4018 | for dc in 0..side / 4 { |
| @@ -4130,7 +4144,13 @@ fn decode_inter_block( | ||
| 4130 | 4144 | (r * (SUB / MI), c * (SUB / MI)), |
| 4131 | 4145 | side / MI, |
| 4132 | 4146 | side as u8, |
| 4133 | - ref_frame_for_lf, | |
| 4147 | + // ref_grid's packed convention (lf_level): sign carries GLOBALMV, | |
| 4148 | + // whose mode_lf_lut row is 0, not the 1 every other inter mode gets. | |
| 4149 | + if globalmv_for_lf { | |
| 4150 | + -ref_frame_for_lf | |
| 4151 | + } else { | |
| 4152 | + ref_frame_for_lf | |
| 4153 | + }, | |
| 4134 | 4154 | ); |
| 4135 | 4155 | Ok(()) |
| 4136 | 4156 | } |
crates/ec-av1/src/stream.rsmodified+21 -35
| @@ -536,20 +536,17 @@ mod tests { | ||
| 536 | 536 | /// (GOLDEN_FRAME's slot) and `ref_frame_idx[0] = 0` (LAST_FRAME's), whose |
| 537 | 537 | /// lone block codes `single_ref` all the way out to `GOLDEN_FRAME` |
| 538 | 538 | /// (`p1=0, p3=1, p5=1`) and a `skip` zero-MV `NEARESTMV`: a direct copy |
| 539 | - /// of GOLDEN's picture, so its output must equal frame 0's own | |
| 540 | - /// reconstruction exactly, and must differ from frame 1's -- proof the | |
| 541 | - /// decoder actually read the golden plane, not silently substituted | |
| 542 | - /// `LAST_FRAME`'s. ffmpeg decodes the identical wire bytes as the | |
| 543 | - /// foreign oracle (shared-oracle-blindness class): this crate's own | |
| 544 | - /// decoder agreeing with itself would prove nothing. | |
| 539 | + /// of GOLDEN's picture. Round 4 asserted a pixel-exact decode against | |
| 540 | + /// ffmpeg here; round 5 (lane-av1golden2) found that only proved the | |
| 541 | + /// symbol path plus a whole-pel copy -- the first real aomenc GOLDEN | |
| 542 | + /// streams mismatch past a stacked defect (`decode.rs`'s round-5 note), | |
| 543 | + /// so the arm is masked again and this fixture now asserts the mask: | |
| 544 | + /// the stream must still reach the `GOLDEN_FRAME` `single_ref` read | |
| 545 | + /// (hit counter) and must then refuse by name, not decode-and-be-wrong | |
| 546 | + /// or misparse. The fixture itself is kept verbatim -- r3 flips this | |
| 547 | + /// test back to the pixel-exact form the moment the live path holds. | |
| 545 | 548 | #[test] |
| 546 | - fn a_hand_built_golden_reference_decodes_pixel_exact_against_ffmpeg() { | |
| 547 | - if !have_ffmpeg() { | |
| 548 | - eprintln!( | |
| 549 | - "SKIP a_hand_built_golden_reference_decodes_pixel_exact_against_ffmpeg: no ffmpeg" | |
| 550 | - ); | |
| 551 | - return; | |
| 552 | - } | |
| 549 | + fn a_hand_built_golden_reference_refuses_by_name() { | |
| 553 | 550 | use crate::cdf_state::Cdfs; |
| 554 | 551 | use crate::decode::{intra_inter_ctx, non_last_ref_hits, q_ctx_of}; |
| 555 | 552 | use crate::encode::{inter_frame_headers, key_frame_headers}; |
| @@ -623,31 +620,20 @@ mod tests { | ||
| 623 | 620 | stream.extend(frame_obu(&seq, &header2, &tile2).unwrap()); |
| 624 | 621 | |
| 625 | 622 | let before = non_last_ref_hits(); |
| 626 | - let decoded = decode_stream(&stream).unwrap(); | |
| 627 | - assert_eq!(decoded.len(), 3, "run {run}: expected 3 pictures"); | |
| 623 | + let err = decode_stream(&stream).expect_err( | |
| 624 | + "the masked GOLDEN_FRAME arm decoded a hand-built GOLDEN stream -- \ | |
| 625 | + if the mask was lifted on purpose, flip this test back to its round-4 \ | |
| 626 | + pixel-exact form", | |
| 627 | + ); | |
| 628 | 628 | assert!( |
| 629 | 629 | non_last_ref_hits() > before, |
| 630 | - "run {run}: GOLDEN_FRAME never fired" | |
| 630 | + "run {run}: GOLDEN_FRAME's single_ref read never fired -- the stream \ | |
| 631 | + misparsed before reaching the refusal it is supposed to prove" | |
| 631 | 632 | ); |
| 632 | - | |
| 633 | - let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 3); | |
| 634 | - for (i, (got, want)) in decoded.iter().zip(&ffmpeg_frames).enumerate() { | |
| 635 | - assert_eq!(got.y, want.y, "run {run} frame {i}: luma vs ffmpeg"); | |
| 636 | - assert_eq!(got.u, want.u, "run {run} frame {i}: U vs ffmpeg"); | |
| 637 | - assert_eq!(got.v, want.v, "run {run} frame {i}: V vs ffmpeg"); | |
| 638 | - } | |
| 639 | - assert_eq!( | |
| 640 | - decoded[0].y, key.reconstruction.y, | |
| 641 | - "run {run}: frame 0 vs the encoder's own reconstruction" | |
| 642 | - ); | |
| 643 | - assert_eq!( | |
| 644 | - decoded[2].y, key.reconstruction.y, | |
| 645 | - "run {run}: GOLDEN_FRAME's block did not reproduce the keyframe it names" | |
| 646 | - ); | |
| 647 | - assert_ne!( | |
| 648 | - decoded[2].y, decoded[1].y, | |
| 649 | - "run {run}: LAST_FRAME's and GOLDEN_FRAME's slots were not actually \ | |
| 650 | - distinguishable -- the gate proves nothing" | |
| 633 | + let msg = err.to_string(); | |
| 634 | + assert!( | |
| 635 | + msg.contains("other than LAST_FRAME"), | |
| 636 | + "run {run}: refused, but not by the GOLDEN mask's own name: {msg}" | |
| 651 | 637 | ); |
| 652 | 638 | } |
| 653 | 639 | } |