Merge branch 'lane-t900' (14d627be): intra-coded 128-root HORZ/VERT halves inside inter frames lifted from opt-in; edge-forced witness gated byte-exact
Browse files at this commit3 changed files +106 -16
- crates/ec-av1/fixtures/intra128_in_inter_witness2.obu +0 -0
- crates/ec-av1/src/decode.rs +15 -14
- crates/ec-av1/src/stream.rs +91 -2
crates/ec-av1/fixtures/intra128_in_inter_witness2.obuadded+0 -0
Binary file changed
crates/ec-av1/src/decode.rsmodified+15 -14
| @@ -7731,20 +7731,21 @@ fn decode_intra_rect_in_inter( | ||
| 7731 | 7731 | // already read), the `tx_depth` context (the real TXFM_CONTEXT bands) and |
| 7732 | 7732 | // the `set_txfm_ctxs` publication. CfL (>32), filter intra (>32) and |
| 7733 | 7733 | // palette (>64) do not exist at this size and are refused by name there. |
| 7734 | - // lane-inter128intra r1: OPT-IN ONLY (`EC_INTRA128_IN_INTER=1`) until a | |
| 7735 | - // gate exists. The body below is believed right (it is the key frame's own | |
| 7736 | - // proven body plus the three inter-frame differences), but nothing proves | |
| 7737 | - // it: no aomenc recipe found so far emits a 128-root HORZ/VERT half coded | |
| 7738 | - // intra in an inter frame. A refusal is lifted only with a gate (COMMON), | |
| 7739 | - // so the default path still refuses by name below. | |
| 7740 | - // | |
| 7741 | - // lane-t900 r17: the opt-in STAYS. `intra128_in_inter_witness.obu` was | |
| 7742 | - // built as this arm's witness and r16 measured three hits in it -- but | |
| 7743 | - // every one of them was an artifact of the skipped-128-block entropy | |
| 7744 | - // desync fixed this round (class `counter-from-refused-stream`). With the | |
| 7745 | - // stream decoding byte-exact the arm fires ZERO times, so the witness does | |
| 7746 | - // not carry the shape at all and the lift has no gate. | |
| 7747 | - if bw.max(bh) == 128 && std::env::var_os("EC_INTRA128_IN_INTER").is_some() { | |
| 7734 | + // lane-t900 r18: the opt-in is LIFTED -- the arm has a witness. | |
| 7735 | + // `intra128_in_inter_witness2.obu` (gate | |
| 7736 | + // `an_intra_coded_128_half_inside_an_inter_frame_decodes_pixel_exact`) | |
| 7737 | + // fires it 3x 128x64 + 6x 64x128 and decodes byte-exact on every plane of | |
| 7738 | + // all 15 frames, so the hits are counted out of exact frames (class | |
| 7739 | + // `counter-from-refused-stream`). What r16/r17 could not find, and what | |
| 7740 | + // that recipe exploits: libaom's RD essentially never PICKS a 128-root | |
| 7741 | + // HORZ/VERT in the interior -- the 512x512 r16 witness and a textured | |
| 7742 | + // 640x384 sweep code 128 roots as NONE or SPLIT only. The shape appears | |
| 7743 | + // where the frame EDGE forces it: a partial last superblock row has | |
| 7744 | + // `has_rows128 == false`, so the 128x64 top half is implied, and a | |
| 7745 | + // partial last column implies the 64x128 left half. Put content no | |
| 7746 | + // reference holds (a fresh smooth ramp) in exactly those two bands of an | |
| 7747 | + // inter frame and the encoder codes those forced halves INTRA. | |
| 7748 | + if bw.max(bh) == 128 { | |
| 7748 | 7749 | if allow_screen_content_tools { |
| 7749 | 7750 | return Err(unsupported( |
| 7750 | 7751 | "a HORZ/VERT intra strip in a screen-content frame (palette syntax \ |
crates/ec-av1/src/stream.rsmodified+91 -2
| @@ -30729,8 +30729,8 @@ mod tests { | ||
| 30729 | 30729 | intra128_now[1] - intra128_before[1] |
| 30730 | 30730 | ], |
| 30731 | 30731 | [0, 0], |
| 30732 | - "{NAME}: the intra-128-in-inter arm fired on a stream that decodes \ | |
| 30733 | - exactly -- the opt-in now HAS a witness and should be lifted" | |
| 30732 | + "{NAME}: this stream does not carry a 128-root intra half -- the \ | |
| 30733 | + witness for that arm is `intra128_in_inter_witness2.obu` (r18)" | |
| 30734 | 30734 | ); |
| 30735 | 30735 | assert_eq!(frames.len(), 10, "{NAME}: 10 shown frames"); |
| 30736 | 30736 | assert_eq!((frames[0].width, frames[0].height), (width, height)); |
| @@ -30753,6 +30753,95 @@ mod tests { | ||
| 30753 | 30753 | ); |
| 30754 | 30754 | } |
| 30755 | 30755 | |
| 30756 | + /// lane-t900 r18 GATE: a 128-root `PARTITION_HORZ`/`PARTITION_VERT` half | |
| 30757 | + /// coded INTRA inside an INTER frame -- the shape the | |
| 30758 | + /// `EC_INTRA128_IN_INTER` opt-in guarded from lane-inter128intra r1 until | |
| 30759 | + /// this round, lifted here because this stream proves it. | |
| 30760 | + /// | |
| 30761 | + /// What r16 and r17 could not find, and what this recipe exploits: libaom | |
| 30762 | + /// does not PICK a 128-root HORZ/VERT in the frame interior -- r16's | |
| 30763 | + /// 512x512 witness codes its 128 roots as NONE (96) or SPLIT (64) and | |
| 30764 | + /// nothing else, and a textured 640x384 sweep the same. The shape appears | |
| 30765 | + /// where the frame EDGE forces it: with a partial last superblock ROW | |
| 30766 | + /// `has_rows128 == false`, so `PARTITION_HORZ` is implied and only the | |
| 30767 | + /// 128x64 top half is decoded; a partial last COLUMN implies the 64x128 | |
| 30768 | + /// left half the same way (the arm the | |
| 30769 | + /// `..._sb128_gathered_edge_horz_partition_...` gate pins for INTER | |
| 30770 | + /// blocks). Put content no reference holds in exactly those two bands and | |
| 30771 | + /// the encoder codes those forced halves INTRA. | |
| 30772 | + /// | |
| 30773 | + /// `crates/ec-av1/fixtures/intra128_in_inter_witness2.obu`, 86516 bytes, | |
| 30774 | + /// sha256 `cace4cc3a5ba4dc5f8c7c219e87c9052351e832cad3d7f4c8ffe09288a6d7ccf`, | |
| 30775 | + /// produced by this repository's aomenc oracle: | |
| 30776 | + /// | |
| 30777 | + /// ```text | |
| 30778 | + /// aomenc --codec=av1 -w 704 -h 320 --input-bit-depth=10 --bit-depth=10 \ | |
| 30779 | + /// --sb-size=128 --max-partition-size=128 --enable-rect-partitions=1 \ | |
| 30780 | + /// --enable-ab-partitions=0 --enable-1to4-partitions=0 \ | |
| 30781 | + /// --enable-intrabc=0 --enable-palette=0 --tune=psnr \ | |
| 30782 | + /// --kf-max-dist=9999 --lag-in-frames=0 --cpu-used=1 --end-usage=q \ | |
| 30783 | + /// --cq-level=20 --threads=1 --passes=1 --obu -o s.obu src.y4m | |
| 30784 | + /// ``` | |
| 30785 | + /// | |
| 30786 | + /// The source is 15 frames of 10-bit 704x320 (704 = 5*128 + 64 and | |
| 30787 | + /// 320 = 2*128 + 64, so BOTH the last superblock column and the last | |
| 30788 | + /// superblock row are partial) whose interior is a low-passed noise | |
| 30789 | + /// texture panning 4 px per frame -- an exact integer translation, so | |
| 30790 | + /// inter predicts it and intra never would -- and whose bottom 64 rows and | |
| 30791 | + /// right 64 columns are replaced at frames 6, 9 and 12 by a fresh smooth | |
| 30792 | + /// diagonal ramp with a different angle and offset each time. No | |
| 30793 | + /// reference holds that content (`--lag-in-frames=0`, so there is no | |
| 30794 | + /// hidden alt-ref either), it is internally smooth, and it lands exactly | |
| 30795 | + /// in the edge-forced halves: `intra128_in_inter` fires 3x 128x64 and | |
| 30796 | + /// 6x 64x128, every one of them inside a frame this gate compares | |
| 30797 | + /// byte-exact against ffmpeg (class `counter-from-refused-stream`). | |
| 30798 | + #[test] | |
| 30799 | + fn an_intra_coded_128_half_inside_an_inter_frame_decodes_pixel_exact() { | |
| 30800 | + const NAME: &str = | |
| 30801 | + "an_intra_coded_128_half_inside_an_inter_frame_decodes_pixel_exact"; | |
| 30802 | + if !have_ffmpeg() { | |
| 30803 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 30804 | + return; | |
| 30805 | + } | |
| 30806 | + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | |
| 30807 | + .join("fixtures/intra128_in_inter_witness2.obu"); | |
| 30808 | + let stream = std::fs::read(&path) | |
| 30809 | + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); | |
| 30810 | + let (width, height) = (704usize, 320usize); | |
| 30811 | + let before = intra128_in_inter_counters(); | |
| 30812 | + let frames = match decode_stream(&stream) { | |
| 30813 | + Ok(frames) => frames, | |
| 30814 | + Err(e) => panic!("{NAME}: decode_stream refused: {e}"), | |
| 30815 | + }; | |
| 30816 | + let after = intra128_in_inter_counters(); | |
| 30817 | + let fired = [after[0] - before[0], after[1] - before[1]]; | |
| 30818 | + assert!( | |
| 30819 | + fired[0] > 0 && fired[1] > 0, | |
| 30820 | + "{NAME}: intra-128-in-inter fired {fired:?} (128x64, 64x128) -- both \ | |
| 30821 | + arms must fire or the gate is vacuous for the one that did not" | |
| 30822 | + ); | |
| 30823 | + assert_eq!(frames.len(), 15, "{NAME}: 15 shown frames"); | |
| 30824 | + assert_eq!((frames[0].width, frames[0].height), (width, height)); | |
| 30825 | + let ffmpeg_frames = ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len()); | |
| 30826 | + assert_eq!( | |
| 30827 | + ffmpeg_frames.len(), | |
| 30828 | + frames.len(), | |
| 30829 | + "{NAME}: ffmpeg returned {} frames, we decoded {}", | |
| 30830 | + ffmpeg_frames.len(), | |
| 30831 | + frames.len() | |
| 30832 | + ); | |
| 30833 | + for (i, (ours, theirs)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | |
| 30834 | + assert_eq!(ours.y, theirs.y, "{NAME}: frame {i} luma vs ffmpeg"); | |
| 30835 | + assert_eq!(ours.u, theirs.u, "{NAME}: frame {i} U vs ffmpeg"); | |
| 30836 | + assert_eq!(ours.v, theirs.v, "{NAME}: frame {i} V vs ffmpeg"); | |
| 30837 | + } | |
| 30838 | + eprintln!( | |
| 30839 | + "{NAME}: 15 shown frames pixel-exact on every plane; \ | |
| 30840 | + intra128_in_inter 128x64={} 64x128={}", | |
| 30841 | + fired[0], fired[1] | |
| 30842 | + ); | |
| 30843 | + } | |
| 30844 | + | |
| 30756 | 30845 | /// lane-t900 r10: the small-side GLOBALMV / rect warp-reach witness. |
| 30757 | 30846 | /// `crates/ec-av1/fixtures/gm_small_side_witness.obu`, 1158066 bytes, |
| 30758 | 30847 | /// sha256 `f1cdbcbb8d6d469c7957d70252ab42b24ab75f48a717600ffa25991458775dca`: |