forge
Explore
Log in

Don't you dare go Hollow

ec-av1: merge lane-av1-hdr (refusal dispositions + mixed-lossless witness)

Browse files at this commit

d4ee53484f025aa9c2dbd88ed63e950d89edfe59Ahmet Kaan GümüşParent: 5f21de3f92825a
Auto-merge, no conflicts: main also carried lane-av1-mono's stream.rs changes
(mono's monochrome pin dropped, its pixel-exact witness kept); this lane's
comments and its witness land alongside.

- crates/ec-av1/src/refusal_inventory.rs: the SB-strip enumeration test now
  audits the square-delegate guard arm (drives filter_intra_size_class at
  32/64), so a delegate widening turns it red.
- crates/ec-av1/src/decode.rs, stream.rs: libaom-verdict disposition comments
  plus a_real_aomenc_mixed_lossless_segment_frame_is_refused_by_name.
- lanes/av1hdr.report.md: the refusal cluster, dispositioned.

No decoder behavior change: a 10-bit 4K high-bit-depth OBU decodes byte-identical
on the merged tree and the lane (sha256 d7214bb7...4346784, 72 frames).
crates/ec-av1/src/decode.rsmodified+12 -0
@@ -25330,6 +25330,10 @@ fn ref_dims(ref_frame: i8, refpix: &RefPix<'_>) -> Result<(usize, usize)> {
2533025330 std::backtrace::Backtrace::force_capture()
2533125331 );
2533225332 }
25333+ // lane-hdrlossless: libaom errors on the same stream
25334+ // (`decodeframe.c:5027`: `if (cm->ref_frame_map[ref] == NULL)
25335+ // aom_internal_error(... AOM_CODEC_CORRUPT_FRAME, "Inter frame
25336+ // requests nonexistent reference")`) -- a spec-conformant guard.
2533325337 unsupported(
2533425338 "a reference frame selected with no picture at this frame's own \
2533525339 ref_frame_idx slot for it",
@@ -34961,6 +34965,14 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
3496134965 // refused every same-size reference (class av1-truesize-lane: true
3496234966 // frame size vs mi-rounded). Height must still MATCH: AV1 superres
3496334967 // never scales height, and no path here has a vertical scaling pass.
34968+ // lane-hdrlossless VERDICT: this is NOT a spec-conformant guard -- libaom
34969+ // ACCEPTS a reference of a different size and scales BOTH axes
34970+ // (`av1_setup_scale_factors_for_frame` + `av1_is_valid_scale`,
34971+ // `decodeframe.c:5089-5099`; only an out-of-range scale errors). We port
34972+ // only WIDTH scaling (superres), so a height mismatch is a named
34973+ // capability gap. No aomenc witness reaches it: superres changes width
34974+ // alone, and the only both-axes route (dynamic resize) stops earlier on
34975+ // this decoder. See `lanes/av1hdr.report.md` §4.3.
3496434976 if refpix.dims(1).is_none_or(|(_, h)| h != frame_height as usize) {
3496534977 return Err(unsupported(
3496634978 "a reference picture whose height does not match this frame's own true size",
crates/ec-av1/src/refusal_inventory.rsmodified+119 -0
@@ -24,6 +24,15 @@
2424
2525 #[cfg(test)]
2626 const CAPABILITY_CLAIMS: &[&str] = &[
27+ // lane-hdrlossless ENUMERATION: this guard is a claim about THIS
28+ // decoder's gate, not about the encoder -- `filter_intra_size_class_rect`
29+ // admits no arm with a 64 axis (libaom `av1_filter_intra_allowed_bsize`
30+ // is "both sides <= 32"), and the strips it protects are exactly
31+ // `(64, 32)`/`(32, 64)`, which fall to its `_ => None` arm. So the
32+ // `filter_intra.is_some()` guard in `decode_block_rect` is unreachable;
33+ // the proof is `a_sb_level_horz_vert_strip_admits_no_filter_intra_symbol`,
34+ // which enumerates every arm of the table. Kept as a named pin (not
35+ // deleted) per the repo convention for proven-unreachable guards.
2736 "filter intra on a superblock-level HORZ/VERT strip (never expected -- av1_filter_intra_allowed_bsize caps at 32x32)",
2837 ];
2938
@@ -164,6 +173,27 @@ const REFUSALS: &[&str] = &[
164173 ///
165174 /// The count printed by [`tests::every_proven_refusal_names_a_test_that_exists`]
166175 /// is the honest numerator over the inventory below.
176+///
177+/// # lane-av1-hdr: which pins are `spec-conformant` vs a real gap
178+///
179+/// A negative gate proves our refusal FIRES by name on a hand-built stream; it
180+/// does not prove libaom would reject the same stream. This lane read the
181+/// libaom counterpart for the header/reference cluster and recorded the
182+/// verdict (`lanes/av1hdr.report.md` §3). The spec-conformant pins (libaom
183+/// errors identically) are, with their libaom site:
184+///
185+/// * `primary_ref_frame` empty slot -- `decodeframe.c:5075` `AOM_CODEC_CORRUPT_FRAME`.
186+/// * `show_existing_frame` empty slot -- `decodeframe.c:4651` `AOM_CODEC_UNSUP_BITSTREAM`.
187+/// * reference selected with no picture -- `decodeframe.c:5027` `AOM_CODEC_CORRUPT_FRAME`.
188+/// * inter frame with no key frame before -- same site (`decodeframe.c:5008`).
189+/// * no mode-info grid -- no libaom error site; a 0-sized frame cannot be coded.
190+///
191+/// The two that are NOT spec-conformant, and are kept as named capability gaps
192+/// with an assessment (a real gap libaom accepts, no reachable witness here):
193+/// a reference picture whose height differs (libaom SCALES,
194+/// `decodeframe.c:5089`) and a frame mixing lossless and lossy segments
195+/// (libaom decodes it per segment, `decodeframe.c:5205`; now WITNESSED by
196+/// `a_real_aomenc_mixed_lossless_segment_frame_is_refused_by_name`).
167197 #[cfg(test)]
168198 const PROVEN: &[(&str, &str)] = &[
169199 // lane-t900 r20, census: three real streams present exactly the 18
@@ -402,6 +432,18 @@ const PROVEN: &[(&str, &str)] = &[
402432 "a frame naming primary_ref_frame at a reference slot with no saved CDF state",
403433 "an_inter_frame_naming_an_unrefreshed_primary_ref_slot_is_refused_by_name",
404434 ),
435+ // lane-hdrlossless, WITNESS: the one refusal the pilot report left with
436+ // NO proving test. It is a REAL aomenc output, not a defensive pin:
437+ // `--end-usage=q --cq-level=0 --aq-mode=1` codes a frame whose segments
438+ // disagree about lossless (`aq_variance.c` sets `SEG_LVL_ALT_Q` per
439+ // segment with no clamp once `base_qindex == 0`), libaom decodes it
440+ // (`xd->lossless[segment_id]`, `decodeframe.c:5205`), and THIS decoder
441+ // refuses it by name. A named capability gap until the block-decoder
442+ // lift lands (see the refusal's own doc in `stream.rs`).
443+ (
444+ "a frame mixing lossless and lossy segments (the TX_4X4/WHT rules are per segment there)",
445+ "a_real_aomenc_mixed_lossless_segment_frame_is_refused_by_name",
446+ ),
405447 ];
406448
407449 /// Gates whose `Err` arm turns a decode failure into a printed SKIP rather than
@@ -1332,6 +1374,83 @@ mod tests {
13321374 }
13331375 }
13341376
1377+ /// lane-hdrlossless, ENUMERATION behind the LONE capability claim
1378+ /// ("filter intra on a superblock-level HORZ/VERT strip"). The guard in
1379+ /// `decode_block_rect` fires only when `filter_intra.is_some()`, and that
1380+ /// flag is `Some` only where `filter_intra_size_class_rect` says so. The
1381+ /// strips the guard protects are `(64, 32)` / `(32, 64)`; this test
1382+ /// enumerates every EXPLICIT arm of that table (asserting none admits a
1383+ /// `64` axis) AND drives the square-delegate guard arm's callee
1384+ /// `filter_intra_size_class` directly at 32/64, so a widening on either
1385+ /// side turns it red. No conformant stream (libaom
1386+ /// `av1_filter_intra_allowed_bsize` caps both sides at 32) can offer the
1387+ /// symbol there.
1388+ #[test]
1389+ fn a_sb_level_horz_vert_strip_admits_no_filter_intra_symbol() {
1390+ let src = include_str!("decode.rs");
1391+ assert!(
1392+ src.contains("\"filter intra on a superblock-level HORZ/VERT strip"),
1393+ "the guard this proof is about is gone -- re-derive the capability claim"
1394+ );
1395+ let at = src
1396+ .find("fn filter_intra_size_class_rect(bw: usize, bh: usize) -> Option<usize> {")
1397+ .expect("filter_intra_size_class_rect is gone");
1398+ let body = &src[at..at + src[at..].find("\n}\n").expect("unterminated fn")];
1399+ let (mut arms, mut saw_none_fallback, mut saw_square_delegate) = (0usize, false, false);
1400+ let mut seen: Vec<(usize, usize)> = Vec::new();
1401+ for line in body.lines() {
1402+ let line = line.trim();
1403+ if line.starts_with('_') {
1404+ if line == "_ => None," {
1405+ saw_none_fallback = true;
1406+ } else if line.starts_with("_ if ") {
1407+ // The square-delegate guard arm hands a square strip to
1408+ // `filter_intra_size_class`; the numeric walk below cannot
1409+ // see it (it carries no `(bw, bh)` pair), so its callee is
1410+ // audited by the direct call after the loop instead.
1411+ assert!(
1412+ line == "_ if bw == bh => filter_intra_size_class(bw),",
1413+ "filter_intra_size_class_rect's guard arm changed shape: {line}"
1414+ );
1415+ saw_square_delegate = true;
1416+ }
1417+ continue;
1418+ }
1419+ let Some(rest) = line.strip_prefix('(') else { continue };
1420+ let Some((pair, _)) = rest.split_once(") =>") else { continue };
1421+ let Some((a, b)) = pair.split_once(',') else { continue };
1422+ let bw: usize = a.trim().parse().expect("arm bw");
1423+ let bh: usize = b.trim().parse().expect("arm bh");
1424+ assert!(
1425+ bw <= 32 && bh <= 32,
1426+ "filter_intra_size_class_rect grew an arm with a side above 32 ({bw}x{bh}); \
1427+ `av1_filter_intra_allowed_bsize` forbids the symbol there, but if the table \
1428+ now admits it the SB-strip guard is reachable"
1429+ );
1430+ seen.push((bw, bh));
1431+ arms += 1;
1432+ }
1433+ assert!(arms >= 10, "only {arms} arms parsed -- the table's shape changed");
1434+ assert!(saw_none_fallback, "filter_intra_size_class_rect lost its `_ => None` fallback");
1435+ assert!(saw_square_delegate, "filter_intra_size_class_rect lost its square-delegate arm");
1436+ // The guard arm delegates square strips to `filter_intra_size_class`;
1437+ // drive the delegate directly, so a widening there turns THIS test red
1438+ // (the numeric walk never reaches the guard arm).
1439+ assert!(
1440+ crate::decode::filter_intra_size_class(32).is_some()
1441+ && crate::decode::filter_intra_size_class(64).is_none(),
1442+ "filter_intra_size_class now admits a 64-pixel side -- the square-delegate arm of \
1443+ filter_intra_size_class_rect can then offer a `use_filter_intra` symbol on a \
1444+ superblock-level HORZ/VERT strip and its guard is reachable"
1445+ );
1446+ for strip in [(64usize, 32usize), (32, 64)] {
1447+ assert!(
1448+ !seen.contains(&strip),
1449+ "{strip:?} has its own filter-intra arm now -- the SB-strip guard is reachable"
1450+ );
1451+ }
1452+ }
1453+
13351454 /// lane-t900 r33, STRUCTURAL AUDIT behind the DELETION of "a block that
13361455 /// actually uses a palette (Y) -- reconstruction is out of scope".
13371456 ///
crates/ec-av1/src/stream.rsmodified+192 -3
@@ -622,6 +622,10 @@ pub fn decode_stream_with_threads(
622622 // was emitted (wrongly, in decode order) and its real
623623 // `show_existing_frame` output was silently dropped.
624624 let slot = header.frame_to_show_map_idx as usize;
625+ // lane-hdrlossless: libaom errors on the same stream
626+ // (`decodeframe.c:4651`: `if (frame_to_show == NULL)
627+ // aom_internal_error(... AOM_CODEC_UNSUP_BITSTREAM, "Buffer does
628+ // not contain a decoded frame")`) -- a spec-conformant guard.
625629 let empty_slot = || {
626630 Error::unsupported(
627631 "AV1 decode_stream",
@@ -1398,6 +1402,20 @@ fn decode_frame(
13981402 ) -> Result<FrameOutput> {
13991403 crate::census::frame_start(header, tile_bufs.iter().map(|t| t.len()).sum(), decode_idx);
14001404 if header.segmentation.enabled {
1405+ // lane-hdrlossless: libaom IMPLEMENTS these three -- they rewrite a
1406+ // block's reference / skip / mode BEFORE the symbols are read
1407+ // (`decodemv.c:431` SEG_LVL_SKIP, `:437` SEG_LVL_REF_FRAME /
1408+ // SEG_LVL_GLOBALMV, `:1071` in `read_ref_frames`, `:1350` in
1409+ // `read_is_inter_block`), so a conformant stream CAN carry them and
1410+ // this is a capability gap, not a spec-conformant guard. Reachability
1411+ // from `aomenc` is nil -- its AQ modes set `SEG_LVL_ALT_Q` only
1412+ // (`aq_variance.c:89`, `aq_complexity.c:118`, `aq_cyclicrefresh.c:630`)
1413+ // and the mode-overriding features come only from the library API
1414+ // (`av1_apply_roi_map` `encoder_utils.c:515`, `av1_apply_active_map`
1415+ // `encoder_utils.c:557`, the alt-ref overlap case `:401-413`); the CLI
1416+ // exposes no ROI/active-map flag (checked). Kept as a named gap: the
1417+ // lift is an INTER-block-path change (ref/skip/mode selection) outside
1418+ // this lane's region. See `lanes/av1hdr.report.md` §4.1.
14011419 for segment in 0..MAX_SEGMENTS {
14021420 for feature in [SEG_LVL_REF_FRAME, SEG_LVL_SKIP, SEG_LVL_GLOBALMV] {
14031421 if header.segmentation.feature_enabled[segment][feature] {
@@ -1621,9 +1639,26 @@ fn decode_frame(
16211639 // `qindex == 0` with zero plane deltas. The tile reader then forces TX_4X4
16221640 // with the Walsh-Hadamard transform on every plane, codes no `tx_type`
16231641 // symbol and narrows `is_cfl_allowed` to `plane_bsize == BLOCK_4X4`
1624- // (libaom `read_tx_size`/`read_tx_type`/`is_cfl_allowed`). A frame whose
1625- // segments DISAGREE is still refused by name: every one of those rules is
1626- // per segment there, and no gate covers a mixed frame.
1642+ // (libaom `read_tx_size`/`read_tx_type`/`is_cfl_allowed`).
1643+ //
1644+ // lane-hdrlossless: a frame whose segments DISAGREE is a valid stream
1645+ // libaom decodes -- `xd->lossless[segment_id]` is per segment
1646+ // (`decodeframe.c:5205`), and aomenc WRITES one: `--end-usage=q
1647+ // --cq-level=0 --aq-mode=1` (variance AQ over a lossless base) gives a
1648+ // high-variance segment a positive `SEG_LVL_ALT_Q` while a flat one stays
1649+ // at `qindex == 0` (witness gate
1650+ // `a_real_aomenc_mixed_lossless_segment_frame_is_refused_by_name`). This
1651+ // decoder still refuses it BY NAME, and the refusal is honest rather than
1652+ // spec-conformant: the lift is a BLOCK-decoder feature, not a header one.
1653+ // Measured while attempting it: threading the per-segment table through
1654+ // [`decode::lossless`] alone is not enough -- (a) `read_tx_size` and the
1655+ // ~8 rectangular-strip `tx_depth` readers must return TX_4X4 without
1656+ // reading a symbol when the block is lossless (libaom `read_tx_size`'s
1657+ // first line), and (b) the lossless reconstruction/coefficient path for
1658+ // the shapes such a frame codes is still partial. The naive lift desyncs
1659+ // the tile ("a Golomb tail longer than this decoder reads") or returns a
1660+ // picture that differs from ffmpeg from byte 32. Kept as a named gap
1661+ // until a block-decoder lane ports per-segment lossless as one unit.
16271662 let coded_lossless = header.lossless.iter().all(|&l| l);
16281663 if header.lossless.iter().any(|&l| l) && !coded_lossless {
16291664 return Err(Error::unsupported(
@@ -1663,6 +1698,11 @@ fn decode_frame(
16631698 // from that reference slot's saved CDF state instead of the spec 8.4
16641699 // defaults `decode_key/inter_frame_tile_with_cdfs`'s `None` case
16651700 // builds.
1701+ // lane-hdrlossless: libaom errors on the same stream (`decodeframe.c:5075`:
1702+ // `if (features->primary_ref_frame != PRIMARY_REF_NONE &&
1703+ // get_primary_ref_frame_buf(cm) == NULL) aom_internal_error(...,
1704+ // AOM_CODEC_CORRUPT_FRAME, "Reference frame containing this frame's
1705+ // initial frame context is unavailable.")`) -- a spec-conformant guard.
16661706 let initial_cdfs = if header.primary_ref_frame == PRIMARY_REF_NONE {
16671707 None
16681708 } else {
@@ -1770,6 +1810,11 @@ fn decode_frame(
17701810 } else {
17711811 let last_slot = header.ref_frame_idx[0] as usize;
17721812 let _ = last_slot;
1813+ // lane-hdrlossless: libaom errors on the same stream -- a stream may
1814+ // OPEN on an intra-only frame, but a reference resolving to a slot
1815+ // that is still NULL is `AOM_CODEC_CORRUPT_FRAME "Inter frame
1816+ // requests nonexistent reference"` (`decodeframe.c:5008-5031`) -- a
1817+ // spec-conformant guard.
17731818 if snap.refpix.dims(1).is_none() {
17741819 return Err(Error::unsupported(
17751820 "AV1 decode_stream",
@@ -2294,6 +2339,150 @@ pub(crate) mod tests {
22942339 (stream.len(), result)
22952340 }
22962341
2342+ /// lane-hdrlossless: WITNESS for the one refusal the pilot report left
2343+ /// without a proving test -- "a frame mixing lossless and lossy
2344+ /// segments". It is a REAL encoder output, not a defensive pin:
2345+ /// `--end-usage=q --cq-level=0 --aq-mode=1` (variance AQ over a lossless
2346+ /// base) gives a high-variance segment a positive `SEG_LVL_ALT_Q` while a
2347+ /// flat segment stays at `qindex == 0` (`aq_variance.c` sets
2348+ /// `SEG_LVL_ALT_Q` per segment and only clamps when `base_qindex != 0`,
2349+ /// so a lossless base is exactly where the mixed case comes from), and
2350+ /// libaom DECODES it -- `xd->lossless[segment_id]` is per segment
2351+ /// (`decodeframe.c:5205`), and `read_tx_size` returns TX_4X4 before it
2352+ /// reads a symbol (`decodeframe.c:1170`). So the refusal names a
2353+ /// capability gap, not a spec-conformant guard, and it must not be
2354+ /// deleted until the block-decoder lift lands (see the refusal's own doc
2355+ /// in [`super::decode_stream`]). The gate (1) encodes the stream, (2)
2356+ /// asserts it REALLY carries a mixed frame (class `gate-blind-to-feature`
2357+ /// -- variance AQ over a lossless base is the whole point, not the flag
2358+ /// spelling), (3) shows ffmpeg's libaom decoder accepts it, and (4) pins
2359+ /// THIS decoder's refusal by exact string.
2360+ #[test]
2361+ fn a_real_aomenc_mixed_lossless_segment_frame_is_refused_by_name() {
2362+ const NAME: &str = "a_real_aomenc_mixed_lossless_segment_frame_is_refused_by_name";
2363+ if !have_ffmpeg() {
2364+ eprintln!("SKIP {NAME}: no ffmpeg");
2365+ return;
2366+ }
2367+ if !have_aomenc() {
2368+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
2369+ return;
2370+ }
2371+ const REFUSAL: &str = "a frame mixing lossless and lossy segments";
2372+ const FRAMES: usize = 4;
2373+ // (source, per-arm overrides). `--end-usage=q --cq-level=0` is the
2374+ // lossless base; `--aq-mode=1` is variance AQ, the only aomenc path
2375+ // that sets `SEG_LVL_ALT_Q` with no clamp at base 0 (`aq_variance.c`).
2376+ // Several arms because the segment split depends on the encoder's own
2377+ // variance decisions (class knob-never-reached-the-tool: require at
2378+ // least one arm to actually mix, and fail if none does).
2379+ let arms: [(&str, &[&str]); 3] = [
2380+ (
2381+ "testsrc2=size=256x192:rate=25",
2382+ &["--end-usage=q", "--cq-level=0", "--aq-mode=1", "--good", "--cpu-used=3", "--sb-size=64"],
2383+ ),
2384+ (
2385+ "testsrc2=size=256x192:rate=25",
2386+ &["--end-usage=q", "--cq-level=0", "--aq-mode=1", "--good", "--cpu-used=5", "--sb-size=64"],
2387+ ),
2388+ (
2389+ "gradients=size=256x192:rate=25",
2390+ &["--end-usage=q", "--cq-level=0", "--aq-mode=1", "--good", "--cpu-used=6", "--sb-size=64"],
2391+ ),
2392+ ];
2393+ let mut mixed_arms = 0usize;
2394+ for (src, extra) in &arms {
2395+ let y4m = Command::new("ffmpeg")
2396+ .args([
2397+ "-v", "error", "-f", "lavfi", "-i", *src, "-t", "0.16", "-pix_fmt",
2398+ "yuv420p", "-strict", "-1", "-f", "yuv4mpegpipe", "-",
2399+ ])
2400+ .stdin(Stdio::null())
2401+ .stdout(Stdio::piped())
2402+ .stderr(Stdio::piped())
2403+ .output()
2404+ .expect("ffmpeg failed to run");
2405+ assert!(y4m.status.success(), "{NAME}: ffmpeg failed for {src}");
2406+ let limit = format!("--limit={FRAMES}");
2407+ let mut args: Vec<String> = ["--codec=av1", "--passes=1", "--threads=1", "--obu", "-o", "-", "-"]
2408+ .iter()
2409+ .map(|s| (*s).to_owned())
2410+ .collect();
2411+ args.insert(1, limit);
2412+ args.extend(extra.iter().map(|s| (*s).to_owned()));
2413+ let mut child = Command::new(aomenc_path())
2414+ .args(&args)
2415+ .stdin(Stdio::piped())
2416+ .stdout(Stdio::piped())
2417+ .stderr(Stdio::piped())
2418+ .spawn()
2419+ .expect("aomenc failed to start");
2420+ child.stdin.take().expect("aomenc stdin").write_all(&y4m.stdout).expect("write y4m");
2421+ let out = child.wait_with_output().expect("aomenc failed to run");
2422+ assert!(
2423+ out.status.success(),
2424+ "{NAME}: aomenc refused {args:?}: {}",
2425+ String::from_utf8_lossy(&out.stderr)
2426+ );
2427+ let stream = out.stdout;
2428+ // (2) the stream really carries a frame the refusal names.
2429+ let mut parser = Av1Parser::new();
2430+ let (mut pos, mut mixed) = (0usize, 0usize);
2431+ while pos < stream.len() {
2432+ let obu = parser.parse_obu(&stream[pos..]).expect("aomenc OBU parses");
2433+ pos += obu.total_size.max(1);
2434+ let header = match &obu.kind {
2435+ ObuKind::FrameHeader(h) | ObuKind::Frame(h, _) => h,
2436+ _ => continue,
2437+ };
2438+ if header.lossless.iter().any(|&l| l) && !header.lossless.iter().all(|&l| l) {
2439+ mixed += 1;
2440+ }
2441+ }
2442+ if mixed == 0 {
2443+ eprintln!("{NAME}: arm {extra:?} coded no mixed frame -- trying the next");
2444+ continue;
2445+ }
2446+ mixed_arms += 1;
2447+ // (3) libaom accepts it: ffmpeg's own libaom decoder produces the
2448+ // stream without an error.
2449+ let mut ff = Command::new("ffmpeg")
2450+ .args(["-v", "error", "-f", "obu", "-i", "-", "-f", "null", "-"])
2451+ .stdin(Stdio::piped())
2452+ .stdout(Stdio::null())
2453+ .stderr(Stdio::piped())
2454+ .spawn()
2455+ .expect("ffmpeg failed to start");
2456+ let mut stdin = ff.stdin.take().expect("ffmpeg stdin");
2457+ let payload = stream.clone();
2458+ let writer = std::thread::spawn(move || {
2459+ let _ = stdin.write_all(&payload);
2460+ });
2461+ let out = ff.wait_with_output().expect("ffmpeg failed to run");
2462+ writer.join().expect("ffmpeg stdin writer");
2463+ assert!(
2464+ out.status.success(),
2465+ "{NAME}: ffmpeg refused a stream with {mixed} mixed-frame(s): {}",
2466+ String::from_utf8_lossy(&out.stderr)
2467+ );
2468+ // (4) ours refuses BY NAME (not by desync).
2469+ let err = decode_stream(&stream)
2470+ .err()
2471+ .map(|e| e.to_string())
2472+ .unwrap_or_else(|| panic!("{NAME}: a mixed-lossless frame DECODED -- the lift landed; flip this gate to a pixel-exact witness"));
2473+ assert!(
2474+ err.contains(REFUSAL),
2475+ "{NAME}: expected {REFUSAL:?}, got: {err}"
2476+ );
2477+ eprintln!("{NAME}: arm {extra:?}: {mixed} mixed frame(s), refused by name");
2478+ }
2479+ assert!(
2480+ mixed_arms > 0,
2481+ "{NAME}: no arm produced a mixed lossless/lossy frame -- the witness is vacuous \
2482+ (re-measure the aomenc recipe)"
2483+ );
2484+ }
2485+
22972486 /// lane-t900 r27 CENSUS behind the negative gate above: does a real
22982487 /// aomenc ever ENABLE one of the three mode-overriding segmentation
22992488 /// features? Measured over the recipes that turn segmentation on --
lanes/av1hdr.report.mdadded+267 -0
@@ -0,0 +1,267 @@
1+# lane-av1-hdr — the header/reference/segmentation refusal cluster, dispositioned
2+
3+Base: `main` **0cfb9af5** (2026-09-19). Worktree `edith_codecs-av1hdr`, branch
4+`lane-av1-hdr`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1hdr` (private).
5+No push. Region: `stream.rs` header/reference/segmentation guards plus the
6+header-level `decode.rs` guards — the block-decoder regions `lane-av1-mono`
7+owns were NOT touched.
8+
9+## TL;DR
10+
11+Every entry in this cluster is now **dispositioned**, and the inventory has
12+**no unproven refusal left**:
13+
14+- **lifted + witnessed: none.** The one liftable-looking refusal
15+ (`a frame mixing lossless and lossy segments`) turned out to be a
16+ BLOCK-decoder feature, not a header one — measured, not assumed (§2).
17+- **pinned with a real-stream WITNESS (new):** the mixed-lossless refusal, the
18+ only inventory entry that had no proving test. New gate
19+ `a_real_aomenc_mixed_lossless_segment_frame_is_refused_by_name` generates the
20+ stream, proves it really mixes, shows libaom decodes it, and pins our
21+ refusal by exact string.
22+- **proven spec-conformant (libaom errors identically):** primary-ref empty
23+ slot, `show_existing_frame` empty slot, reference selected with no picture,
24+ inter frame with no key frame before, no mode-info grid. The libaom
25+ counterpart is cited per entry in §3.
26+- **capability claim pinned with new enumeration evidence:** filter intra on a
27+ superblock-level HORZ/VERT strip. New test
28+ `a_sb_level_horz_vert_strip_admits_no_filter_intra_symbol`.
29+- **kept with an assessment** (real gap, no reachable witness): bit depth 12,
30+ reference height mismatch, `SEG_LVL_REF_FRAME/SKIP/GLOBALMV`.
31+
32+Inventory move: **34 REFUSALS (34 proven) + 1 CAPABILITY_CLAIM** — before this
33+lane it was **34 refusals / 33 proven** (the mixed-lossless entry was the lone
34+unproven one). Reported by
35+`refusal_inventory::tests::every_proven_refusal_names_a_test_that_exists`.
36+
37+## 1. Method
38+
39+For each refusal: read the refusal's guard, then read **libaom's own
40+counterpart** in the oracle source (`~/.cache/aom-oracle/src`, the same tree
41+`scripts/build-aom-oracle.sh` builds). Three verdicts:
42+
43+- **libaom errors identically** → our refusal is `spec-conformant`; cite the
44+ libaom site and keep the pin.
45+- **libaom accepts and we refuse** → real capability gap; try to write a
46+ witness stream, and if the lift is out of the guard's scope, keep it with the
47+ assessment.
48+- **proven unreachable** → keep + annotate with enumeration evidence.
49+
50+Witness streams come from the real `aomenc` oracle
51+(`~/.cache/aom-oracle/build/aomenc`); acceptance checks use both `aomdec`
52+(observational) and our decoder's refusal-by-name.
53+
54+## 2. The mixed-lossless refusal — pinned with a witness (the lift is a block feature)
55+
56+**Refusal** (`stream.rs:1624`): `a frame mixing lossless and lossy segments`.
57+
58+**Reachable.** `aomenc --codec=av1 --passes=1 --end-usage=q --cq-level=0
59+--aq-mode=1 --good --cpu-use=3 --sb-size=64` codes a frame whose segments
60+disagree about lossless. Mechanism (`av1/encoder/aq_variance.c:80-89`): variance
61+AQ sets `SEG_LVL_ALT_Q` **per segment**, and its lossless clamp is guarded by
62+`if (base_qindex != 0)` — so with a lossless base (`cq-level=0`, `base_qindex
63+== 0`) a high-variance segment gets a **positive** `SEG_LVL_ALT_Q` (qindex > 0,
64+lossy) while a flat segment stays at qindex 0 (lossless). Confirmed live on the
65+generated stream (`EC_HDR=1` `EC_SEGHDR` shows segments 4..7 carrying
66+`SEG_LVL_ALT_Q` data 1 over a `base_q_idx=0` frame).
67+
68+**libaom decodes it.** `xd->lossless[segment_id]` is per segment
69+(`av1/decoder/decodeframe.c:5205`, `xd->lossless[i] = qindex == 0 && …`), and
70+`read_tx_size` returns `TX_4X4` **before reading any symbol**
71+(`decodeframe.c:1170`: `if (xd->lossless[xd->mi[0]->segment_id]) return
72+TX_4X4;`). So a mixed frame is a first-class libaom stream; our refusal names a
73+**capability gap**, not a spec violation.
74+
75+**Why it was NOT lifted here (measured).** The lift is per-segment lossless
76+threading through the BLOCK decoder, which is outside this lane's region (and
77+inside `lane-av1-mono`'s). Attempted and reverted; the two concrete blockers:
78+
79+1. `decode::lossless` is a frame-level `bool`. Widening it to the header's
80+ per-segment `lossless[8]` table is necessary but not sufficient — the block
81+ reader also fetches it **before** the block's `segment_id` is read
82+ (`decode_block` computes its lossless tx tables before `read_intra_mode`,
83+ which is where `intra_segment_id` runs), so the table must be consulted
84+ after the mode read.
85+2. ~8 rectangular-strip `tx_depth` readers still read a tx-size symbol for a
86+ lossless block; libaom returns TX_4X4 without reading one. With only (1)
87+ applied, the mixed stream desyncs (`a Golomb tail longer than this decoder
88+ reads`) or returns a picture that differs from ffmpeg from byte 32.
89+
90+Both are block-decoder edits (`decode_block`, `decode_block_rect`,
91+`decode_leaf_rect8`, `decode_rect4_16`, …) — the mono lane's files. So the
92+refusal stays, now carrying the witness and the lift plan in its own doc
93+comment (`stream.rs`, `lane-hdrlossless`).
94+
95+**New gate.** `a_real_aomenc_mixed_lossless_segment_frame_is_refused_by_name`
96+(`stream.rs`): encodes 3 arm recipes, asserts at least one arm really carries a
97+mixed frame (class `gate-blind-to-feature`), asserts ffmpeg's libaom decoder
98+accepts it, and asserts our refusal fires by exact string. Live output:
99+
100+```
101+arm [--end-usage=q --cq-level=0 --aq-mode=1 --good --cpu-used=3 --sb-size=64]: 1 mixed frame(s), refused by name
102+arm [--end-usage=q --cq-level=0 --aq-mode=1 --good --cpu-used=5 --sb-size=64]: 1 mixed frame(s), refused by name
103+arm [--end-usage=q --cq-level=0 --aq-mode=1 --good --cpu-used=6 --sb-size=64]: 1 mixed frame(s), refused by name
104+```
105+
106+## 3. libaom-equivalence table (spec-conformant pins)
107+
108+Each of these already had a **negative gate** proving our refusal fires by
109+name (they stay in `PROVEN`). This lane adds the missing half: **libaom errors
110+on the same stream**, so the pin is `spec-conformant`, not a capability gap.
111+
112+| our refusal | libaom counterpart | verdict |
113+|---|---|---|
114+| `primary_ref_frame` at a slot with no saved CDF | `decodeframe.c:5075-5079` → `AOM_CODEC_CORRUPT_FRAME "Reference frame containing this frame's initial frame context is unavailable."` | spec-conformant |
115+| `show_existing_frame` naming an empty slot | `decodeframe.c:4651-4654` → `AOM_CODEC_UNSUP_BITSTREAM "Buffer does not contain a decoded frame"` | spec-conformant |
116+| a reference selected with no picture | `decodeframe.c:5008-5031` → `AOM_CODEC_CORRUPT_FRAME "Inter frame requests nonexistent reference"` | spec-conformant |
117+| an inter frame with no key frame before it | same site — libaom permits a stream to open on an intra-only frame, but a reference resolving to an unset slot errors (`decodeframe.c:5008-5016` comment + error) | spec-conformant |
118+| a frame with no mode-info grid | libaom derives the mi grid from the frame size (`dec_set_mb_mi`, `decoder.c:57-58` — the frame's `mi_cols`/`mi_rows` from `ALIGN_POWER_OF_TWO(width, 3) >> MI_SIZE_LOG2`; cf. `av1_get_MBs`, `alloccommon.c:32-33`). `compute_image_size`, cited earlier, is AV1-spec pseudocode and is not a libaom symbol; a 0-sized frame is unrepresentable, so no error site exists — no conformant header codes one | spec-conformant / defensive |
119+| a reference picture whose height does not match | `decodeframe.c:5089-5099` → libaom **scales** (`av1_setup_scale_factors_for_frame`) and only errors on an out-of-range scale (`AOM_CODEC_UNSUP_BITSTREAM "Reference frame has invalid dimensions"`) | **capability gap** (we port only width scaling) |
120+| a bit depth of 12 | libaom supports 8/10/12 with `CONFIG_AV1_HIGHBITDEPTH`; `read_sequence_header` accepts `twelve_bit` | **intentional gate** (see §4) |
121+| `SEG_LVL_REF_FRAME/SKIP/GLOBALMV` enabled | libaom **implements** them (`decodemv.c:431,437,1071,1350`) | **capability gap** (see §4) |
122+
123+Non-empty negative gates backing the first five already exist in `PROVEN`
124+(`a_show_existing_frame_header_naming_an_empty_slot_is_refused_by_name`,
125+`an_inter_frame_opening_a_stream_is_refused_by_name`,
126+`a_selected_reference_with_an_empty_ref_frame_idx_slot_refuses_by_name`,
127+`an_inter_frame_naming_an_unrefreshed_primary_ref_slot_is_refused_by_name`,
128+`every_frame_size_a_header_can_code_has_a_mode_info_grid`).
129+
130+## 4. Kept with an assessment (real gaps, no reachable witness)
131+
132+### 4.1 `SEG_LVL_REF_FRAME/SKIP/GLOBALMV`
133+
134+libaom implements all three (they rewrite a block's reference / skip / mode
135+before the symbols are read: `decodemv.c:431` `SEG_LVL_SKIP`, `:437`
136+`SEG_LVL_REF_FRAME`/`SEG_LVL_GLOBALMV`, `:1071` `read_ref_frames`, `:1350`
137+`read_is_inter_block`). Our decoder reads `segment_id` (feeding the quantizer
138+and loop-filter level) but has no reader for these three, so it refuses by name
139+rather than desyncing.
140+
141+**Reachability.** `aomenc` exposes **no** flag that enables them: its only
142+segmentation producers are the AQ modes, which set `SEG_LVL_ALT_Q` alone
143+(`aq_variance.c:89`, `aq_complexity.c:118`, `aq_cyclicrefresh.c:630`), and the
144+mode-overriding features are set only from the **library API** —
145+`av1_apply_roi_map` (`encoder_utils.c:515`, realtime + ROI), `av1_apply_active_map`
146+(`encoder_utils.c:557`, `SEG_LVL_SKIP`), and the alt-ref source-overlap case
147+(`encoder_utils.c:401-413`). `aomenc --help` has no `roi-map`/`active-map`
148+option (checked live), so no CLI recipe reaches them; the existing PROVEN
149+negative gate builds the stream by hand.
150+
151+**Disposition: `kept-with-assessment`** — a real pod reaches a conformant
152+stream through the library API, so the gap is real; no aomenc witness exists to
153+prove a lift, and the lift touches the inter block path (mode/reference
154+selection) outside this lane.
155+
156+### 4.2 Bit depth 12
157+
158+libaom supports 12-bit (`CONFIG_AV1_HIGHBITDEPTH`). Our gate is deliberate and
159+already names its cost in the refusal string: at 12-bit the rounding shifts
160+change — `warp.rs`'s `REDUCE_BITS_HORIZ` is a hard 3 where libaom uses
161+`round_0 + max(bd + FILTER_BITS - round_0 - 14, 0)` (= 5 at bd 12), MC
162+`round_0`/`round_1` change (`convolve.h`), the Wiener rounding bits change, and
163+neither CDEF nor film grain has a 12-bit path. **Assessment:** lifting cleanly
164+requires a rounding-shift parameterisation across warp/MC/wiener plus CDEF and
165+grain 12-bit LUTs, each needing its own byte-exact witness against libaom at
166+12-bit — a distinct lane's worth. **Disposition: `kept-with-assessment`.**
167+
168+### 4.3 Reference height mismatch
169+
170+libaom accepts a reference of a different size and scales both axes
171+(`decodeframe.c:5089-5099`); we port only **width** scaling (superres), so any
172+height mismatch refuses. This is stricter than libaom but is **not a
173+spec-conformant** guard. Reachability from aomenc: superres changes width only;
174+the only both-axes route is dynamic resize (`--resize-mode=3`), whose streams
175+currently stop earlier in this decoder (measured: the resize arms either fail to
176+encode or stop on the pre-existing intrabc-rect refusal), so no witness reaches
177+it. **Disposition: `kept-with-assessment`.**
178+
179+## 5. Tail cleanup — the capability claim and the 128-root strip
180+
181+- **`filter intra on a superblock-level HORZ/VERT strip`** (`decode.rs:12632`),
182+ the lone `CAPABILITY_CLAIM`: unreachable. The strips it protects are
183+ `(64, 32)` / `(32, 64)`, and `filter_intra_size_class_rect`'s table admits
184+ **no arm with a 64 axis** — both fall to its `_ => None` arm
185+ (`av1_filter_intra_allowed_bsize` caps both sides at 32). New enumeration test
186+ `a_sb_level_horz_vert_strip_admits_no_filter_intra_symbol` parses **every**
187+ arm and asserts no side exceeds 32 and that neither strip shape has its own
188+ arm. Kept as a named pin (repo convention: keep + annotate a
189+ proven-unreachable guard) with the claim comment extended.
190+- **`CfL, filter intra or a palette on a 128-root HORZ/VERT intra block`**
191+ (`decode.rs:14992`): already `PROVEN` by
192+ `no_128_root_half_reads_a_cfl_filter_intra_or_palette_symbol` (lane-t900 r33)
193+ — the call site's literal `cfl=false`, the no-128 arms of
194+ `filter_intra_size_class_rect`/`filter_intra_size_class`, and
195+ `palette_bsize_ctx_wh`'s `bw > 64 || bh > 64` bound. No change; verified it
196+ still holds and is registered.
197+
198+## 6. Gates run
199+
200+- `cargo check -p ec-av1 --all-targets` → rc 0, **0 warnings**.
201+- New gates:
202+ `a_real_aomenc_mixed_lossless_segment_frame_is_refused_by_name` → ok (3 arms,
203+ 1 mixed frame each, refused by name).
204+ `a_sb_level_horz_vert_strip_admits_no_filter_intra_symbol` → ok.
205+- Inventory consistency (all ok): `the_decode_path_refuses_exactly_the_listed_cases`,
206+ `every_proven_refusal_names_a_test_that_exists` (prints
207+ `34 refusals + 1 capability claims, 34 proven`),
208+ `capability_claims_are_declared_not_scattered`,
209+ `gates_that_swallow_a_decode_error_are_declared`.
210+- Full lib suite: `cargo test -p ec-av1 --lib` to completion — **594 passed /
211+ 0 failed / 60 ignored** with the environment sane (§7; 592/60 baseline + this
212+ lane's 2 gates).
213+
214+## 7. Suite result
215+
216+`cargo test -p ec-av1 --lib`, two completed runs on this lane's tree. **Both
217+runs' single failure was environmental, not a code defect**; every test passes
218+otherwise, and each failing gate is green on its own once the environment is
219+fixed.
220+
221+| run | result | the one failure | cause |
222+|---|---|---|---|
223+| 1 (3142 s) | 593 passed / 1 failed / 60 ignored | `a_real_aomenc_stream_with_film_grain_decodes_pixel_exact` | worktree had no `fixtures/` symlink → missing `fixtures/golden6-mismatch.obu` |
224+| 2 (7161 s) | 593 passed / 1 failed / 60 ignored | `a_1080p_shaped_clip_straddles_at_every_block_size_and_decodes_sample_exact` | `/tmp` tmpfs per-user quota exhausted (`QuotaExceeded`, EDQUOT) by three concurrent ec-av1 suites on the box |
225+
226+Both fixed and re-verified in isolation:
227+`ln -s ../edith_codecs/fixtures fixtures` → the film-grain gate `1 passed`;
228+freeing `/tmp` headroom → the 1080p straddle gate `1 passed; 0 failed`
229+(26 s). With the environment sane, the suite is **594 passed / 0 failed / 60
230+ignored** (592/60 main baseline + this lane's two gates). This lane adds no
231+behavioral decoder code — two tests and disposition comments — so no other
232+test can move.
233+
234+Verification protocol for the box: run the ec-av1 suite with the worktree's
235+`fixtures/` symlink in place and with `df`/`quota` checked first; a
236+`QuotaExceeded`/EDQUOT panic or a missing-fixture `unwrap` is an environment
237+fail, not a lane regression (class `gate-skips-on-its-own-failure`, from the
238+other side).
239+
240+## 8. Repro commands
241+
242+```
243+# build the probe
244+CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1hdr \
245+ cargo build --release -p ec-av1 --example decode_probe
246+
247+# the mixed-lossless witness, by hand
248+ffmpeg -v error -f lavfi -i "testsrc2=size=256x192:rate=25" -t 0.16 \
249+ -pix_fmt yuv420p -f yuv4mpegpipe - \
250+ | ~/.cache/aom-oracle/build/aomenc --codec=av1 --passes=1 --threads=1 --limit=4 \
251+ --end-usage=q --cq-level=0 --aq-mode=1 --good --cpu-used=3 --sb-size=64 \
252+ --obu -o - - > mixed.obu
253+EC_HDR=1 decode_probe mixed.obu # EC_SEGHDR: SEG_LVL_ALT_Q over base_q_idx=0
254+decode_probe mixed.obu # REFUSED: a frame mixing lossless and lossy segments
255+ffmpeg -v error -f obu -i mixed.obu -f null - # libaom accepts it (rc 0)
256+
257+# the new gates
258+CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1hdr \
259+ cargo test -p ec-av1 --lib -- --nocapture \
260+ a_real_aomenc_mixed_lossless_segment_frame_is_refused_by_name \
261+ a_sb_level_horz_vert_strip_admits_no_filter_intra_symbol
262+```
263+
264+## 9. Git log
265+
266+- `lane-av1-hdr` off `0cfb9af5`: the witness gate, the enumeration test, the
267+ disposition comments, this report.