Loop filter level must not forward from the primary ref frame
Browse files at this commit3024af4cc8a1d96d05497ce2f7abe65da0a7e07fParent: a0f4d37- fix
- loop filter level must not forward from the primary ref frame
2 changed files +57 -2
crates/ec-av1-syntax/src/frame.rsmodified+15 -2
| @@ -989,12 +989,25 @@ pub(crate) fn parse_uncompressed_header( | ||
| 989 | 989 | // setup_past_independence / load_previous (spec 6.8.2): the loop filter |
| 990 | 990 | // deltas, segmentation data and global motion this frame starts from either |
| 991 | 991 | // reset to their defaults or come from the primary reference frame. |
| 992 | - let mut lf = LoopFilterParams::default(); | |
| 992 | + // `loop_filter_level`/`loop_filter_sharpness` are NOT part of that forward | |
| 993 | + // (spec 7.20 only loads `LoopFilterRefDeltas`/`LoopFilterModeDeltas`) -- | |
| 994 | + // level is always parsed fresh in `read_loop_filter_params`, defaulting to | |
| 995 | + // 0 for the chroma levels when that frame's luma levels are both 0 (its | |
| 996 | + // own guard skips reading them). Forwarding the whole struct here left a | |
| 997 | + // previous frame's nonzero chroma level in place on a frame that never | |
| 998 | + // wrote one, over-filtering U/V at edges this frame's own header says are | |
| 999 | + // off (lane-av1golden3: seed 47, frame 1 chroma vs ffmpeg). | |
| 1000 | + let mut lf = LoopFilterParams { | |
| 1001 | + level: [0; 4], | |
| 1002 | + sharpness: 0, | |
| 1003 | + ..LoopFilterParams::default() | |
| 1004 | + }; | |
| 993 | 1005 | let mut seg = SegmentationParams::default(); |
| 994 | 1006 | let mut prev_gm_params = [WarpParams::default(); REFS_PER_FRAME]; |
| 995 | 1007 | if h.primary_ref_frame != PRIMARY_REF_NONE { |
| 996 | 1008 | let prev = state.refs[h.ref_frame_idx[h.primary_ref_frame as usize] as usize]; |
| 997 | - lf = prev.loop_filter; | |
| 1009 | + lf.ref_deltas = prev.loop_filter.ref_deltas; | |
| 1010 | + lf.mode_deltas = prev.loop_filter.mode_deltas; | |
| 998 | 1011 | seg = prev.segmentation; |
| 999 | 1012 | prev_gm_params = prev.gm_params; |
| 1000 | 1013 | } |
crates/ec-av1/src/stream.rsmodified+42 -0
| @@ -1769,6 +1769,19 @@ mod tests { | ||
| 1769 | 1769 | }; |
| 1770 | 1770 | let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); |
| 1771 | 1771 | assert_eq!(frames.len(), frame_count); |
| 1772 | + // lane-av1golden3: pin the exact raw stream on the first mismatch | |
| 1773 | + // so a flaky-looking gate failure becomes a deterministic, static | |
| 1774 | + // fixture to bisect against -- env-gated, no cost on a normal run. | |
| 1775 | + let mismatched = frames | |
| 1776 | + .iter() | |
| 1777 | + .zip(&ffmpeg_frames) | |
| 1778 | + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); | |
| 1779 | + if mismatched { | |
| 1780 | + if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") { | |
| 1781 | + std::fs::write(&path, &stream).expect("writing pinned stream"); | |
| 1782 | + eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); | |
| 1783 | + } | |
| 1784 | + } | |
| 1772 | 1785 | for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { |
| 1773 | 1786 | assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (seed {seed})"); |
| 1774 | 1787 | assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg (seed {seed})"); |
| @@ -1783,6 +1796,35 @@ mod tests { | ||
| 1783 | 1796 | ); |
| 1784 | 1797 | } |
| 1785 | 1798 | |
| 1799 | + /// lane-av1golden3: reproduces the pinned mismatch bytes captured by | |
| 1800 | + /// `EC_AV1_GATE_DUMP=$SP/golden3-pin.obu` off | |
| 1801 | + /// [`a_real_aomenc_inter_sequence_with_cdf_forwarding_decodes_pixel_exact`] | |
| 1802 | + /// (seed 47, frame 1 U). Deterministic and static -- no aomenc/ffmpeg | |
| 1803 | + /// re-encode involved, only re-decodes the fixed bytes on disk, so it is | |
| 1804 | + /// `#[ignore]`d (the file only exists on this machine's scratchpad) but | |
| 1805 | + /// gives a fast red/green loop for the actual fix. | |
| 1806 | + #[test] | |
| 1807 | + #[ignore = "reads a pinned fixture path outside the repo; run manually"] | |
| 1808 | + fn pinned_golden3_stream_decodes_pixel_exact() { | |
| 1809 | + let path = std::env::var("EC_AV1_GATE_DUMP_PIN").unwrap_or_else(|_| { | |
| 1810 | + "/tmp/claude-1000/-home-user-Documents-Code-Rust-edith-codecs/\ | |
| 1811 | + 51b5f611-f998-43a8-b975-e64cb643a3e1/scratchpad/golden3-pin.obu" | |
| 1812 | + .to_string() | |
| 1813 | + }); | |
| 1814 | + let stream = std::fs::read(&path).expect("reading pinned stream"); | |
| 1815 | + if !have_ffmpeg() { | |
| 1816 | + eprintln!("SKIP pinned_golden3_stream_decodes_pixel_exact: no ffmpeg"); | |
| 1817 | + return; | |
| 1818 | + } | |
| 1819 | + let frames = decode_stream(&stream).expect("pinned stream must decode"); | |
| 1820 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, 64, 64, 4); | |
| 1821 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | |
| 1822 | + assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (pinned)"); | |
| 1823 | + assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg (pinned)"); | |
| 1824 | + assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (pinned)"); | |
| 1825 | + } | |
| 1826 | + } | |
| 1827 | + | |
| 1786 | 1828 | /// lane-av1refs's decisive single-non-LAST-reference gate: identical |
| 1787 | 1829 | /// recipe to |
| 1788 | 1830 | /// [`a_real_aomenc_inter_sequence_with_cdf_forwarding_decodes_pixel_exact`] |