guard(av1): GOLDEN decode stays refused until a stream proves it live
Browse files at this commited5f4c7188be215f641b48ccf953a5c48ef9c674Parent: 8a443b22 changed files +95 -21
- crates/ec-av1/src/decode.rs +12 -9
- crates/ec-av1/src/stream.rs +83 -12
crates/ec-av1/src/decode.rsmodified+12 -9
| @@ -3724,19 +3724,22 @@ fn decode_inter_block( | |||
| 3724 | if is_inter { | 3724 | if is_inter { |
| 3725 | let ref_frame = read_single_ref(dec, cdfs, neighbours.above_ref[c], neighbours.left_ref[r]); | 3725 | let ref_frame = read_single_ref(dec, cdfs, neighbours.above_ref[c], neighbours.left_ref[r]); |
| 3726 | ref_frame_for_lf = ref_frame; | 3726 | 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. | ||
| 3727 | let (py_ref, pu_ref, pv_ref) = match ref_frame { | 3738 | let (py_ref, pu_ref, pv_ref) = match ref_frame { |
| 3728 | LAST_FRAME => (ref_y, ref_u, ref_v), | 3739 | 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 | - }, | ||
| 3737 | _ => { | 3740 | _ => { |
| 3738 | return Err(unsupported( | 3741 | 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)", |
| 3740 | )); | 3743 | )); |
| 3741 | } | 3744 | } |
| 3742 | }; | 3745 | }; |
crates/ec-av1/src/stream.rsmodified+83 -12
| @@ -1574,16 +1574,16 @@ mod tests { | |||
| 1574 | // deterministic header. | 1574 | // deterministic header. |
| 1575 | "--threads=1", | 1575 | "--threads=1", |
| 1576 | "--row-mt=0", | 1576 | "--row-mt=0", |
| 1577 | - // No `--error-resilient=1` here (that is the whole point of | 1577 | + // `--enable-order-hint=0` kills BWDREF/ALTREF entirely (no |
| 1578 | - // this test), but every other reference/compound tool this | 1578 | + // order hints -> no bidirectional distance weighting) and, |
| 1579 | - // decoder's round-2 inter path does not model is still | 1579 | + // combined with `--auto-alt-ref=0`/`--lag-in-frames=0` |
| 1580 | - // disabled the same way `--error-resilient=1` incidentally | 1580 | + // above, leaves aomenc's RD search only LAST_FRAME/ |
| 1581 | - // disabled it in the sibling test above: without | 1581 | + // LAST2_FRAME/LAST3_FRAME/GOLDEN_FRAME to pick from -- |
| 1582 | - // `--enable-order-hint=0` aomenc's RD search picks a | 1582 | + // GOLDEN itself needs no order hint (it is the keyframe's |
| 1583 | - // non-`LAST_FRAME` reference (`GOLDEN_FRAME`) for some | 1583 | + // fixed slot, not a distance-weighted reference), so this |
| 1584 | - // blocks even in this short a sequence, which is a separate, | 1584 | + // does not suppress GOLDEN selection the way the sibling |
| 1585 | - // already-documented round-2 gap ("a reference frame other | 1585 | + // CDF-forwarding gate's own comment worried about; it just |
| 1586 | - // than LAST_FRAME"), not a CDF-forwarding one. | 1586 | + // narrows the pool this gate needs GOLDEN to win out of. |
| 1587 | "--enable-order-hint=0", | 1587 | "--enable-order-hint=0", |
| 1588 | "--enable-warped-motion=0", | 1588 | "--enable-warped-motion=0", |
| 1589 | "--enable-obmc=0", | 1589 | "--enable-obmc=0", |
| @@ -1698,8 +1698,20 @@ mod tests { | |||
| 1698 | let (width, height, frame_count) = (64usize, 64usize, 8usize); | 1698 | let (width, height, frame_count) = (64usize, 64usize, 8usize); |
| 1699 | let mut refusals = Vec::new(); | 1699 | let mut refusals = Vec::new(); |
| 1700 | let mut never_fired = 0u32; | 1700 | let mut never_fired = 0u32; |
| 1701 | - for attempt in 0..40u32 { | 1701 | + // aomenc's own RD search is nondeterministic run-to-run even at |
| 1702 | - let seed = 42 + attempt; | 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; | ||
| 1703 | let source = format!("gradients=size=64x64:seed={seed}:duration=0.32:rate=25"); | 1715 | let source = format!("gradients=size=64x64:seed={seed}:duration=0.32:rate=25"); |
| 1704 | let y4m = Command::new("ffmpeg") | 1716 | let y4m = Command::new("ffmpeg") |
| 1705 | .args([ | 1717 | .args([ |
| @@ -1765,10 +1777,29 @@ mod tests { | |||
| 1765 | "--enable-tx-size-search=0", | 1777 | "--enable-tx-size-search=0", |
| 1766 | "--enable-cdef=0", | 1778 | "--enable-cdef=0", |
| 1767 | "--enable-restoration=0", | 1779 | "--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. | ||
| 1768 | "--max-partition-size=32", | 1793 | "--max-partition-size=32", |
| 1794 | + "--min-partition-size=32", | ||
| 1769 | "--enable-palette=0", | 1795 | "--enable-palette=0", |
| 1770 | "--enable-intrabc=0", | 1796 | "--enable-intrabc=0", |
| 1771 | "--enable-cfl-intra=0", | 1797 | "--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", | ||
| 1772 | "--obu", | 1803 | "--obu", |
| 1773 | "-o", | 1804 | "-o", |
| 1774 | "-", | 1805 | "-", |
| @@ -1833,6 +1864,46 @@ mod tests { | |||
| 1833 | ); | 1864 | ); |
| 1834 | } | 1865 | } |
| 1835 | 1866 | ||
| 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 | + | ||
| 1836 | /// scratch: isolate a pinned mismatching stream's first divergent pixel. | 1907 | /// scratch: isolate a pinned mismatching stream's first divergent pixel. |
| 1837 | #[test] | 1908 | #[test] |
| 1838 | #[ignore] | 1909 | #[ignore] |