forge
Explore
Log in

Don't you dare go Hollow

guard(av1): GOLDEN decode stays refused until a stream proves it live

Browse files at this commit

ed5f4c7188be215f641b48ccf953a5c48ef9c674Ahmet Kaan GümüşParent: 8a443b2
The full single-non-LAST implementation stays (reference tree, MC
threading, mvstack filter, deblock ref deltas), but decode_stream
refuses GOLDEN narrowly again: 120 recipe attempts never produced a
decodable stream that actually fires the path, and an accepted-but-
unproven decode is the silent-miscode shape this repo does not ship.
The gate documents the refusal and the firing hunt continues.
crates/ec-av1/src/decode.rsmodified+12 -9
@@ -3724,19 +3724,22 @@ fn decode_inter_block(
37243724 if is_inter {
37253725 let ref_frame = read_single_ref(dec, cdfs, neighbours.above_ref[c], neighbours.left_ref[r]);
37263726 ref_frame_for_lf = ref_frame;
3727+ // round 3 (lane-av1refs): the GOLDEN_FRAME arm below decodes and
3728+ // threads a real golden picture through MC/mvstack/deblock, but 120+
3729+ // attempts across a real aomenc recipe built to isolate exactly this
3730+ // path (min==max partition size, order-hint off, screen-content
3731+ // tools off) still could not clear this crate's OWN gate
3732+ // (`a_real_aomenc_inter_sequence_with_a_golden_reference_decodes_pixel_exact`,
3733+ // stream.rs) 4 consecutive times -- every attempt either never fired
3734+ // GOLDEN_FRAME or hit an unrelated named refusal first (see that
3735+ // test's own refusal log). Refuse GOLDEN_FRAME here, narrowly, until
3736+ // a round actually gets that gate green: main should not carry a
3737+ // reference-selection path with zero live pixel-exact proof.
37273738 let (py_ref, pu_ref, pv_ref) = match ref_frame {
37283739 LAST_FRAME => (ref_y, ref_u, ref_v),
3729- GOLDEN_FRAME => match (golden_y, golden_u, golden_v) {
3730- (Some(y), Some(u), Some(v)) => (y, u, v),
3731- _ => {
3732- return Err(unsupported(
3733- "a GOLDEN_FRAME reference with no picture in that slot (round 2)",
3734- ));
3735- }
3736- },
37373740 _ => {
37383741 return Err(unsupported(
3739- "a reference frame other than LAST_FRAME/GOLDEN_FRAME (round 2)",
3742+ "a reference frame other than LAST_FRAME (round 3: GOLDEN_FRAME's decode path exists but has no live pixel-exact proof yet)",
37403743 ));
37413744 }
37423745 };
crates/ec-av1/src/stream.rsmodified+83 -12
@@ -1574,16 +1574,16 @@ mod tests {
15741574 // deterministic header.
15751575 "--threads=1",
15761576 "--row-mt=0",
1577- // No `--error-resilient=1` here (that is the whole point of
1578- // this test), but every other reference/compound tool this
1579- // decoder's round-2 inter path does not model is still
1580- // disabled the same way `--error-resilient=1` incidentally
1581- // disabled it in the sibling test above: without
1582- // `--enable-order-hint=0` aomenc's RD search picks a
1583- // non-`LAST_FRAME` reference (`GOLDEN_FRAME`) for some
1584- // blocks even in this short a sequence, which is a separate,
1585- // already-documented round-2 gap ("a reference frame other
1586- // than LAST_FRAME"), not a CDF-forwarding one.
1577+ // `--enable-order-hint=0` kills BWDREF/ALTREF entirely (no
1578+ // order hints -> no bidirectional distance weighting) and,
1579+ // combined with `--auto-alt-ref=0`/`--lag-in-frames=0`
1580+ // above, leaves aomenc's RD search only LAST_FRAME/
1581+ // LAST2_FRAME/LAST3_FRAME/GOLDEN_FRAME to pick from --
1582+ // GOLDEN itself needs no order hint (it is the keyframe's
1583+ // fixed slot, not a distance-weighted reference), so this
1584+ // does not suppress GOLDEN selection the way the sibling
1585+ // CDF-forwarding gate's own comment worried about; it just
1586+ // narrows the pool this gate needs GOLDEN to win out of.
15871587 "--enable-order-hint=0",
15881588 "--enable-warped-motion=0",
15891589 "--enable-obmc=0",
@@ -1698,8 +1698,20 @@ mod tests {
16981698 let (width, height, frame_count) = (64usize, 64usize, 8usize);
16991699 let mut refusals = Vec::new();
17001700 let mut never_fired = 0u32;
1701- for attempt in 0..40u32 {
1702- let seed = 42 + attempt;
1701+ // aomenc's own RD search is nondeterministic run-to-run even at
1702+ // `--threads=1` (confirmed live: identical CLI args, identical
1703+ // input, two different output byte streams) -- so beyond varying
1704+ // the fixture's seed, each attempt is its own independent coin
1705+ // flip against every named refusal below. 120 attempts (not 40)
1706+ // to give that coin flip enough tries to land on a stream this
1707+ // decoder both accepts and that fires GOLDEN_FRAME. `duration=0.32`
1708+ // at `rate=25` (not `0.24`) matches every sibling gate's own
1709+ // frame-count fixture exactly -- a shorter duration here once
1710+ // produced a frame-0 (keyframe, no reference at all) luma mismatch
1711+ // against ffmpeg, i.e. a source-frame-count rounding artifact of
1712+ // this recipe's own choosing, not a decoder bug.
1713+ for attempt in 0..120u32 {
1714+ let seed = 42 + attempt % 40;
17031715 let source = format!("gradients=size=64x64:seed={seed}:duration=0.32:rate=25");
17041716 let y4m = Command::new("ffmpeg")
17051717 .args([
@@ -1765,10 +1777,29 @@ mod tests {
17651777 "--enable-tx-size-search=0",
17661778 "--enable-cdef=0",
17671779 "--enable-restoration=0",
1780+ // `min == max == 32` forces PARTITION_NONE for every
1781+ // 32x32 block, not just biases toward it -- with
1782+ // `--min-partition-size=16` alone aomenc's exhaustive
1783+ // `cpu-used=0` RD search still occasionally read HORZ/
1784+ // VERT/SPLIT partitions below 32x32 despite
1785+ // `--enable-rect-partitions=0`/`--enable-ab-partitions=0`/
1786+ // `--enable-1to4-partitions=0` all being off (two
1787+ // separate, already-documented round-2 gaps: "a
1788+ // partition below 16x16", "a partition type this encoder
1789+ // never writes"), starving this gate's already-narrow
1790+ // seed pool. Locking both bounds to 32 removes any
1791+ // partition-depth choice from the search entirely, so
1792+ // this gate can isolate GOLDEN_FRAME selection alone.
17681793 "--max-partition-size=32",
1794+ "--min-partition-size=32",
17691795 "--enable-palette=0",
17701796 "--enable-intrabc=0",
17711797 "--enable-cfl-intra=0",
1798+ // `default` still lets aomenc's heuristic flip
1799+ // `allow_screen_content_tools` on for this synthetic
1800+ // gradient content -- `film` forces the non-screen path
1801+ // instead.
1802+ "--tune-content=film",
17721803 "--obu",
17731804 "-o",
17741805 "-",
@@ -1833,6 +1864,46 @@ mod tests {
18331864 );
18341865 }
18351866
1867+ /// scratch: decode a pinned stream end to end and report where/why it
1868+ /// refuses, plus `non_last_ref_hits` progression.
1869+ #[test]
1870+ #[ignore]
1871+ fn scratch_decode_pinned_stream() {
1872+ let path = std::env::var("EC_AV1_PIN").expect("set EC_AV1_PIN to the .obu path");
1873+ let stream = std::fs::read(&path).expect("read pinned stream");
1874+ let before = decode::non_last_ref_hits();
1875+ match decode_stream(&stream) {
1876+ Ok(frames) => eprintln!(
1877+ "OK: {} frames, non_last_ref_hits {} -> {}",
1878+ frames.len(),
1879+ before,
1880+ decode::non_last_ref_hits()
1881+ ),
1882+ Err(e) => eprintln!(
1883+ "ERR: {} (non_last_ref_hits {} -> {})",
1884+ e,
1885+ before,
1886+ decode::non_last_ref_hits()
1887+ ),
1888+ }
1889+ // Truncate at each Frame OBU boundary and re-decode from scratch, to
1890+ // see which frame index first fails.
1891+ let mut p = Av1Parser::new();
1892+ let mut pos = 0usize;
1893+ let mut frame_idx = 0;
1894+ while pos < stream.len() {
1895+ let obu = p.parse_obu(&stream[pos..]).expect("parse");
1896+ pos += obu.total_size;
1897+ if matches!(obu.kind, ObuKind::Frame(_, _)) {
1898+ match decode_stream(&stream[..pos]) {
1899+ Ok(_) => eprintln!("through frame {frame_idx}: OK"),
1900+ Err(e) => eprintln!("through frame {frame_idx}: ERR {e}"),
1901+ }
1902+ frame_idx += 1;
1903+ }
1904+ }
1905+ }
1906+
18361907 /// scratch: isolate a pinned mismatching stream's first divergent pixel.
18371908 #[test]
18381909 #[ignore]