diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 8ba409de..2e7e1b26 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -25196,6 +25196,10 @@ fn ref_dims(ref_frame: i8, refpix: &RefPix<'_>) -> Result<(usize, usize)> { std::backtrace::Backtrace::force_capture() ); } + // lane-hdrlossless: libaom errors on the same stream + // (`decodeframe.c:5027`: `if (cm->ref_frame_map[ref] == NULL) + // aom_internal_error(... AOM_CODEC_CORRUPT_FRAME, "Inter frame + // requests nonexistent reference")`) -- a spec-conformant guard. unsupported( "a reference frame selected with no picture at this frame's own \ ref_frame_idx slot for it", @@ -34801,6 +34805,14 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // refused every same-size reference (class av1-truesize-lane: true // frame size vs mi-rounded). Height must still MATCH: AV1 superres // never scales height, and no path here has a vertical scaling pass. + // lane-hdrlossless VERDICT: this is NOT a spec-conformant guard -- libaom + // ACCEPTS a reference of a different size and scales BOTH axes + // (`av1_setup_scale_factors_for_frame` + `av1_is_valid_scale`, + // `decodeframe.c:5089-5099`; only an out-of-range scale errors). We port + // only WIDTH scaling (superres), so a height mismatch is a named + // capability gap. No aomenc witness reaches it: superres changes width + // alone, and the only both-axes route (dynamic resize) stops earlier on + // this decoder. See `lanes/av1hdr.report.md` §4.3. if refpix.dims(1).is_none_or(|(_, h)| h != frame_height as usize) { return Err(unsupported( "a reference picture whose height does not match this frame's own true size", diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 4304738d..caaff979 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -24,6 +24,15 @@ #[cfg(test)] const CAPABILITY_CLAIMS: &[&str] = &[ + // lane-hdrlossless ENUMERATION: this guard is a claim about THIS + // decoder's gate, not about the encoder -- `filter_intra_size_class_rect` + // admits no arm with a 64 axis (libaom `av1_filter_intra_allowed_bsize` + // is "both sides <= 32"), and the strips it protects are exactly + // `(64, 32)`/`(32, 64)`, which fall to its `_ => None` arm. So the + // `filter_intra.is_some()` guard in `decode_block_rect` is unreachable; + // the proof is `a_sb_level_horz_vert_strip_admits_no_filter_intra_symbol`, + // which enumerates every arm of the table. Kept as a named pin (not + // deleted) per the repo convention for proven-unreachable guards. "filter intra on a superblock-level HORZ/VERT strip (never expected -- av1_filter_intra_allowed_bsize caps at 32x32)", ]; @@ -164,6 +173,27 @@ const REFUSALS: &[&str] = &[ /// /// The count printed by [`tests::every_proven_refusal_names_a_test_that_exists`] /// is the honest numerator over the inventory below. +/// +/// # lane-av1-hdr: which pins are `spec-conformant` vs a real gap +/// +/// A negative gate proves our refusal FIRES by name on a hand-built stream; it +/// does not prove libaom would reject the same stream. This lane read the +/// libaom counterpart for the header/reference cluster and recorded the +/// verdict (`lanes/av1hdr.report.md` §3). The spec-conformant pins (libaom +/// errors identically) are, with their libaom site: +/// +/// * `primary_ref_frame` empty slot -- `decodeframe.c:5075` `AOM_CODEC_CORRUPT_FRAME`. +/// * `show_existing_frame` empty slot -- `decodeframe.c:4651` `AOM_CODEC_UNSUP_BITSTREAM`. +/// * reference selected with no picture -- `decodeframe.c:5027` `AOM_CODEC_CORRUPT_FRAME`. +/// * inter frame with no key frame before -- same site (`decodeframe.c:5008`). +/// * no mode-info grid -- no libaom error site; a 0-sized frame cannot be coded. +/// +/// The two that are NOT spec-conformant, and are kept as named capability gaps +/// with an assessment (a real gap libaom accepts, no reachable witness here): +/// a reference picture whose height differs (libaom SCALES, +/// `decodeframe.c:5089`) and a frame mixing lossless and lossy segments +/// (libaom decodes it per segment, `decodeframe.c:5205`; now WITNESSED by +/// `a_real_aomenc_mixed_lossless_segment_frame_is_refused_by_name`). #[cfg(test)] const PROVEN: &[(&str, &str)] = &[ // lane-t900 r20, census: three real streams present exactly the 18 @@ -402,6 +432,18 @@ const PROVEN: &[(&str, &str)] = &[ "a frame naming primary_ref_frame at a reference slot with no saved CDF state", "an_inter_frame_naming_an_unrefreshed_primary_ref_slot_is_refused_by_name", ), + // lane-hdrlossless, WITNESS: the one refusal the pilot report left with + // NO proving test. It is a REAL aomenc output, not a defensive pin: + // `--end-usage=q --cq-level=0 --aq-mode=1` codes a frame whose segments + // disagree about lossless (`aq_variance.c` sets `SEG_LVL_ALT_Q` per + // segment with no clamp once `base_qindex == 0`), libaom decodes it + // (`xd->lossless[segment_id]`, `decodeframe.c:5205`), and THIS decoder + // refuses it by name. A named capability gap until the block-decoder + // lift lands (see the refusal's own doc in `stream.rs`). + ( + "a frame mixing lossless and lossy segments (the TX_4X4/WHT rules are per segment there)", + "a_real_aomenc_mixed_lossless_segment_frame_is_refused_by_name", + ), ]; /// Gates whose `Err` arm turns a decode failure into a printed SKIP rather than @@ -1332,6 +1374,57 @@ mod tests { } } + /// lane-hdrlossless, ENUMERATION behind the LONE capability claim + /// ("filter intra on a superblock-level HORZ/VERT strip"). The guard in + /// `decode_block_rect` fires only when `filter_intra.is_some()`, and that + /// flag is `Some` only where `filter_intra_size_class_rect` says so. The + /// strips the guard protects are `(64, 32)` / `(32, 64)`; this test + /// enumerates EVERY arm of that table and asserts none admits a `64` + /// axis, so no conformant stream (libaom `av1_filter_intra_allowed_bsize` + /// caps both sides at 32) can offer the symbol there. + #[test] + fn a_sb_level_horz_vert_strip_admits_no_filter_intra_symbol() { + let src = include_str!("decode.rs"); + assert!( + src.contains("\"filter intra on a superblock-level HORZ/VERT strip"), + "the guard this proof is about is gone -- re-derive the capability claim" + ); + let at = src + .find("fn filter_intra_size_class_rect(bw: usize, bh: usize) -> Option {") + .expect("filter_intra_size_class_rect is gone"); + let body = &src[at..at + src[at..].find("\n}\n").expect("unterminated fn")]; + let (mut arms, mut saw_none_fallback) = (0usize, false); + let mut seen: Vec<(usize, usize)> = Vec::new(); + for line in body.lines() { + let line = line.trim(); + if line.starts_with('_') { + saw_none_fallback |= line == "_ => None,"; + continue; + } + let Some(rest) = line.strip_prefix('(') else { continue }; + let Some((pair, _)) = rest.split_once(") =>") else { continue }; + let Some((a, b)) = pair.split_once(',') else { continue }; + let bw: usize = a.trim().parse().expect("arm bw"); + let bh: usize = b.trim().parse().expect("arm bh"); + assert!( + bw <= 32 && bh <= 32, + "filter_intra_size_class_rect grew an arm with a side above 32 ({bw}x{bh}); \ + `av1_filter_intra_allowed_bsize` forbids the symbol there, but if the table \ + now admits it the SB-strip guard is reachable" + ); + seen.push((bw, bh)); + arms += 1; + } + assert!(arms >= 10, "only {arms} arms parsed -- the table's shape changed"); + assert!(saw_none_fallback, "filter_intra_size_class_rect lost its `_ => None` fallback"); + for strip in [(64usize, 32usize), (32, 64)] { + assert!( + !seen.contains(&strip), + "{strip:?} has its own filter-intra arm now -- the SB-strip guard is reachable" + ); + } + } + /// lane-t900 r33, STRUCTURAL AUDIT behind the DELETION of "a block that /// actually uses a palette (Y) -- reconstruction is out of scope". /// diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index a50ec7ec..20bd6589 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -622,6 +622,10 @@ pub fn decode_stream_with_threads( // was emitted (wrongly, in decode order) and its real // `show_existing_frame` output was silently dropped. let slot = header.frame_to_show_map_idx as usize; + // lane-hdrlossless: libaom errors on the same stream + // (`decodeframe.c:4651`: `if (frame_to_show == NULL) + // aom_internal_error(... AOM_CODEC_UNSUP_BITSTREAM, "Buffer does + // not contain a decoded frame")`) -- a spec-conformant guard. let empty_slot = || { Error::unsupported( "AV1 decode_stream", @@ -1394,6 +1398,20 @@ fn decode_frame( ) -> Result { crate::census::frame_start(header, tile_bufs.iter().map(|t| t.len()).sum(), decode_idx); if header.segmentation.enabled { + // lane-hdrlossless: libaom IMPLEMENTS these three -- they rewrite a + // block's reference / skip / mode BEFORE the symbols are read + // (`decodemv.c:431` SEG_LVL_SKIP, `:437` SEG_LVL_REF_FRAME / + // SEG_LVL_GLOBALMV, `:1071` in `read_ref_frames`, `:1350` in + // `read_is_inter_block`), so a conformant stream CAN carry them and + // this is a capability gap, not a spec-conformant guard. Reachability + // from `aomenc` is nil -- its AQ modes set `SEG_LVL_ALT_Q` only + // (`aq_variance.c:89`, `aq_complexity.c:118`, `aq_cyclicrefresh.c:630`) + // and the mode-overriding features come only from the library API + // (`av1_apply_roi_map` `encoder_utils.c:515`, `av1_apply_active_map` + // `encoder_utils.c:557`, the alt-ref overlap case `:401-413`); the CLI + // exposes no ROI/active-map flag (checked). Kept as a named gap: the + // lift is an INTER-block-path change (ref/skip/mode selection) outside + // this lane's region. See `lanes/av1hdr.report.md` §4.1. for segment in 0..MAX_SEGMENTS { for feature in [SEG_LVL_REF_FRAME, SEG_LVL_SKIP, SEG_LVL_GLOBALMV] { if header.segmentation.feature_enabled[segment][feature] { @@ -1617,9 +1635,26 @@ fn decode_frame( // `qindex == 0` with zero plane deltas. The tile reader then forces TX_4X4 // with the Walsh-Hadamard transform on every plane, codes no `tx_type` // symbol and narrows `is_cfl_allowed` to `plane_bsize == BLOCK_4X4` - // (libaom `read_tx_size`/`read_tx_type`/`is_cfl_allowed`). A frame whose - // segments DISAGREE is still refused by name: every one of those rules is - // per segment there, and no gate covers a mixed frame. + // (libaom `read_tx_size`/`read_tx_type`/`is_cfl_allowed`). + // + // lane-hdrlossless: a frame whose segments DISAGREE is a valid stream + // libaom decodes -- `xd->lossless[segment_id]` is per segment + // (`decodeframe.c:5205`), and aomenc WRITES one: `--end-usage=q + // --cq-level=0 --aq-mode=1` (variance AQ over a lossless base) gives a + // high-variance segment a positive `SEG_LVL_ALT_Q` while a flat one stays + // at `qindex == 0` (witness gate + // `a_real_aomenc_mixed_lossless_segment_frame_is_refused_by_name`). This + // decoder still refuses it BY NAME, and the refusal is honest rather than + // spec-conformant: the lift is a BLOCK-decoder feature, not a header one. + // Measured while attempting it: threading the per-segment table through + // [`decode::lossless`] alone is not enough -- (a) `read_tx_size` and the + // ~8 rectangular-strip `tx_depth` readers must return TX_4X4 without + // reading a symbol when the block is lossless (libaom `read_tx_size`'s + // first line), and (b) the lossless reconstruction/coefficient path for + // the shapes such a frame codes is still partial. The naive lift desyncs + // the tile ("a Golomb tail longer than this decoder reads") or returns a + // picture that differs from ffmpeg from byte 32. Kept as a named gap + // until a block-decoder lane ports per-segment lossless as one unit. let coded_lossless = header.lossless.iter().all(|&l| l); if header.lossless.iter().any(|&l| l) && !coded_lossless { return Err(Error::unsupported( @@ -1655,6 +1690,11 @@ fn decode_frame( // from that reference slot's saved CDF state instead of the spec 8.4 // defaults `decode_key/inter_frame_tile_with_cdfs`'s `None` case // builds. + // lane-hdrlossless: libaom errors on the same stream (`decodeframe.c:5075`: + // `if (features->primary_ref_frame != PRIMARY_REF_NONE && + // get_primary_ref_frame_buf(cm) == NULL) aom_internal_error(..., + // AOM_CODEC_CORRUPT_FRAME, "Reference frame containing this frame's + // initial frame context is unavailable.")`) -- a spec-conformant guard. let initial_cdfs = if header.primary_ref_frame == PRIMARY_REF_NONE { None } else { @@ -1762,6 +1802,11 @@ fn decode_frame( } else { let last_slot = header.ref_frame_idx[0] as usize; let _ = last_slot; + // lane-hdrlossless: libaom errors on the same stream -- a stream may + // OPEN on an intra-only frame, but a reference resolving to a slot + // that is still NULL is `AOM_CODEC_CORRUPT_FRAME "Inter frame + // requests nonexistent reference"` (`decodeframe.c:5008-5031`) -- a + // spec-conformant guard. if snap.refpix.dims(1).is_none() { return Err(Error::unsupported( "AV1 decode_stream", @@ -2265,6 +2310,150 @@ pub(crate) mod tests { (stream.len(), result) } + /// lane-hdrlossless: WITNESS for the one refusal the pilot report left + /// without a proving test -- "a frame mixing lossless and lossy + /// segments". It is a REAL encoder output, not a defensive pin: + /// `--end-usage=q --cq-level=0 --aq-mode=1` (variance AQ over a lossless + /// base) gives a high-variance segment a positive `SEG_LVL_ALT_Q` while a + /// flat segment stays at `qindex == 0` (`aq_variance.c` sets + /// `SEG_LVL_ALT_Q` per segment and only clamps when `base_qindex != 0`, + /// so a lossless base is exactly where the mixed case comes from), and + /// libaom DECODES it -- `xd->lossless[segment_id]` is per segment + /// (`decodeframe.c:5205`), and `read_tx_size` returns TX_4X4 before it + /// reads a symbol (`decodeframe.c:1170`). So the refusal names a + /// capability gap, not a spec-conformant guard, and it must not be + /// deleted until the block-decoder lift lands (see the refusal's own doc + /// in [`super::decode_stream`]). The gate (1) encodes the stream, (2) + /// asserts it REALLY carries a mixed frame (class `gate-blind-to-feature` + /// -- variance AQ over a lossless base is the whole point, not the flag + /// spelling), (3) shows ffmpeg's libaom decoder accepts it, and (4) pins + /// THIS decoder's refusal by exact string. + #[test] + fn a_real_aomenc_mixed_lossless_segment_frame_is_refused_by_name() { + const NAME: &str = "a_real_aomenc_mixed_lossless_segment_frame_is_refused_by_name"; + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); + return; + } + const REFUSAL: &str = "a frame mixing lossless and lossy segments"; + const FRAMES: usize = 4; + // (source, per-arm overrides). `--end-usage=q --cq-level=0` is the + // lossless base; `--aq-mode=1` is variance AQ, the only aomenc path + // that sets `SEG_LVL_ALT_Q` with no clamp at base 0 (`aq_variance.c`). + // Several arms because the segment split depends on the encoder's own + // variance decisions (class knob-never-reached-the-tool: require at + // least one arm to actually mix, and fail if none does). + let arms: [(&str, &[&str]); 3] = [ + ( + "testsrc2=size=256x192:rate=25", + &["--end-usage=q", "--cq-level=0", "--aq-mode=1", "--good", "--cpu-used=3", "--sb-size=64"], + ), + ( + "testsrc2=size=256x192:rate=25", + &["--end-usage=q", "--cq-level=0", "--aq-mode=1", "--good", "--cpu-used=5", "--sb-size=64"], + ), + ( + "gradients=size=256x192:rate=25", + &["--end-usage=q", "--cq-level=0", "--aq-mode=1", "--good", "--cpu-used=6", "--sb-size=64"], + ), + ]; + let mut mixed_arms = 0usize; + for (src, extra) in &arms { + let y4m = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", *src, "-t", "0.16", "-pix_fmt", + "yuv420p", "-strict", "-1", "-f", "yuv4mpegpipe", "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!(y4m.status.success(), "{NAME}: ffmpeg failed for {src}"); + let limit = format!("--limit={FRAMES}"); + let mut args: Vec = ["--codec=av1", "--passes=1", "--threads=1", "--obu", "-o", "-", "-"] + .iter() + .map(|s| (*s).to_owned()) + .collect(); + args.insert(1, limit); + args.extend(extra.iter().map(|s| (*s).to_owned())); + let mut child = Command::new(aomenc_path()) + .args(&args) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("aomenc failed to start"); + child.stdin.take().expect("aomenc stdin").write_all(&y4m.stdout).expect("write y4m"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "{NAME}: aomenc refused {args:?}: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + // (2) the stream really carries a frame the refusal names. + let mut parser = Av1Parser::new(); + let (mut pos, mut mixed) = (0usize, 0usize); + while pos < stream.len() { + let obu = parser.parse_obu(&stream[pos..]).expect("aomenc OBU parses"); + pos += obu.total_size.max(1); + let header = match &obu.kind { + ObuKind::FrameHeader(h) | ObuKind::Frame(h, _) => h, + _ => continue, + }; + if header.lossless.iter().any(|&l| l) && !header.lossless.iter().all(|&l| l) { + mixed += 1; + } + } + if mixed == 0 { + eprintln!("{NAME}: arm {extra:?} coded no mixed frame -- trying the next"); + continue; + } + mixed_arms += 1; + // (3) libaom accepts it: ffmpeg's own libaom decoder produces the + // stream without an error. + let mut ff = Command::new("ffmpeg") + .args(["-v", "error", "-f", "obu", "-i", "-", "-f", "null", "-"]) + .stdin(Stdio::piped()) + .stdout(Stdio::null()) + .stderr(Stdio::piped()) + .spawn() + .expect("ffmpeg failed to start"); + let mut stdin = ff.stdin.take().expect("ffmpeg stdin"); + let payload = stream.clone(); + let writer = std::thread::spawn(move || { + let _ = stdin.write_all(&payload); + }); + let out = ff.wait_with_output().expect("ffmpeg failed to run"); + writer.join().expect("ffmpeg stdin writer"); + assert!( + out.status.success(), + "{NAME}: ffmpeg refused a stream with {mixed} mixed-frame(s): {}", + String::from_utf8_lossy(&out.stderr) + ); + // (4) ours refuses BY NAME (not by desync). + let err = decode_stream(&stream) + .err() + .map(|e| e.to_string()) + .unwrap_or_else(|| panic!("{NAME}: a mixed-lossless frame DECODED -- the lift landed; flip this gate to a pixel-exact witness")); + assert!( + err.contains(REFUSAL), + "{NAME}: expected {REFUSAL:?}, got: {err}" + ); + eprintln!("{NAME}: arm {extra:?}: {mixed} mixed frame(s), refused by name"); + } + assert!( + mixed_arms > 0, + "{NAME}: no arm produced a mixed lossless/lossy frame -- the witness is vacuous \ + (re-measure the aomenc recipe)" + ); + } + /// lane-t900 r27 CENSUS behind the negative gate above: does a real /// aomenc ever ENABLE one of the three mode-overriding segmentation /// features? Measured over the recipes that turn segmentation on -- diff --git a/lanes/av1hdr.report.md b/lanes/av1hdr.report.md new file mode 100644 index 00000000..a425795d --- /dev/null +++ b/lanes/av1hdr.report.md @@ -0,0 +1,267 @@ +# lane-av1-hdr — the header/reference/segmentation refusal cluster, dispositioned + +Base: `main` **0cfb9af5** (2026-09-19). Worktree `edith_codecs-av1hdr`, branch +`lane-av1-hdr`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1hdr` (private). +No push. Region: `stream.rs` header/reference/segmentation guards plus the +header-level `decode.rs` guards — the block-decoder regions `lane-av1-mono` +owns were NOT touched. + +## TL;DR + +Every entry in this cluster is now **dispositioned**, and the inventory has +**no unproven refusal left**: + +- **lifted + witnessed: none.** The one liftable-looking refusal + (`a frame mixing lossless and lossy segments`) turned out to be a + BLOCK-decoder feature, not a header one — measured, not assumed (§2). +- **pinned with a real-stream WITNESS (new):** the mixed-lossless refusal, the + only inventory entry that had no proving test. New gate + `a_real_aomenc_mixed_lossless_segment_frame_is_refused_by_name` generates the + stream, proves it really mixes, shows libaom decodes it, and pins our + refusal by exact string. +- **proven spec-conformant (libaom errors identically):** primary-ref empty + slot, `show_existing_frame` empty slot, reference selected with no picture, + inter frame with no key frame before, no mode-info grid. The libaom + counterpart is cited per entry in §3. +- **capability claim pinned with new enumeration evidence:** filter intra on a + superblock-level HORZ/VERT strip. New test + `a_sb_level_horz_vert_strip_admits_no_filter_intra_symbol`. +- **kept with an assessment** (real gap, no reachable witness): bit depth 12, + reference height mismatch, `SEG_LVL_REF_FRAME/SKIP/GLOBALMV`. + +Inventory move: **34 REFUSALS (34 proven) + 1 CAPABILITY_CLAIM** — before this +lane it was **34 refusals / 33 proven** (the mixed-lossless entry was the lone +unproven one). Reported by +`refusal_inventory::tests::every_proven_refusal_names_a_test_that_exists`. + +## 1. Method + +For each refusal: read the refusal's guard, then read **libaom's own +counterpart** in the oracle source (`~/.cache/aom-oracle/src`, the same tree +`scripts/build-aom-oracle.sh` builds). Three verdicts: + +- **libaom errors identically** → our refusal is `spec-conformant`; cite the + libaom site and keep the pin. +- **libaom accepts and we refuse** → real capability gap; try to write a + witness stream, and if the lift is out of the guard's scope, keep it with the + assessment. +- **proven unreachable** → keep + annotate with enumeration evidence. + +Witness streams come from the real `aomenc` oracle +(`~/.cache/aom-oracle/build/aomenc`); acceptance checks use both `aomdec` +(observational) and our decoder's refusal-by-name. + +## 2. The mixed-lossless refusal — pinned with a witness (the lift is a block feature) + +**Refusal** (`stream.rs:1624`): `a frame mixing lossless and lossy segments`. + +**Reachable.** `aomenc --codec=av1 --passes=1 --end-usage=q --cq-level=0 +--aq-mode=1 --good --cpu-use=3 --sb-size=64` codes a frame whose segments +disagree about lossless. Mechanism (`av1/encoder/aq_variance.c:80-89`): variance +AQ sets `SEG_LVL_ALT_Q` **per segment**, and its lossless clamp is guarded by +`if (base_qindex != 0)` — so with a lossless base (`cq-level=0`, `base_qindex +== 0`) a high-variance segment gets a **positive** `SEG_LVL_ALT_Q` (qindex > 0, +lossy) while a flat segment stays at qindex 0 (lossless). Confirmed live on the +generated stream (`EC_HDR=1` `EC_SEGHDR` shows segments 4..7 carrying +`SEG_LVL_ALT_Q` data 1 over a `base_q_idx=0` frame). + +**libaom decodes it.** `xd->lossless[segment_id]` is per segment +(`av1/decoder/decodeframe.c:5205`, `xd->lossless[i] = qindex == 0 && …`), and +`read_tx_size` returns `TX_4X4` **before reading any symbol** +(`decodeframe.c:1170`: `if (xd->lossless[xd->mi[0]->segment_id]) return +TX_4X4;`). So a mixed frame is a first-class libaom stream; our refusal names a +**capability gap**, not a spec violation. + +**Why it was NOT lifted here (measured).** The lift is per-segment lossless +threading through the BLOCK decoder, which is outside this lane's region (and +inside `lane-av1-mono`'s). Attempted and reverted; the two concrete blockers: + +1. `decode::lossless` is a frame-level `bool`. Widening it to the header's + per-segment `lossless[8]` table is necessary but not sufficient — the block + reader also fetches it **before** the block's `segment_id` is read + (`decode_block` computes its lossless tx tables before `read_intra_mode`, + which is where `intra_segment_id` runs), so the table must be consulted + after the mode read. +2. ~8 rectangular-strip `tx_depth` readers still read a tx-size symbol for a + lossless block; libaom returns TX_4X4 without reading one. With only (1) + applied, the mixed stream desyncs (`a Golomb tail longer than this decoder + reads`) or returns a picture that differs from ffmpeg from byte 32. + +Both are block-decoder edits (`decode_block`, `decode_block_rect`, +`decode_leaf_rect8`, `decode_rect4_16`, …) — the mono lane's files. So the +refusal stays, now carrying the witness and the lift plan in its own doc +comment (`stream.rs`, `lane-hdrlossless`). + +**New gate.** `a_real_aomenc_mixed_lossless_segment_frame_is_refused_by_name` +(`stream.rs`): encodes 3 arm recipes, asserts at least one arm really carries a +mixed frame (class `gate-blind-to-feature`), asserts ffmpeg's libaom decoder +accepts it, and asserts our refusal fires by exact string. Live output: + +``` +arm [--end-usage=q --cq-level=0 --aq-mode=1 --good --cpu-used=3 --sb-size=64]: 1 mixed frame(s), refused by name +arm [--end-usage=q --cq-level=0 --aq-mode=1 --good --cpu-used=5 --sb-size=64]: 1 mixed frame(s), refused by name +arm [--end-usage=q --cq-level=0 --aq-mode=1 --good --cpu-used=6 --sb-size=64]: 1 mixed frame(s), refused by name +``` + +## 3. libaom-equivalence table (spec-conformant pins) + +Each of these already had a **negative gate** proving our refusal fires by +name (they stay in `PROVEN`). This lane adds the missing half: **libaom errors +on the same stream**, so the pin is `spec-conformant`, not a capability gap. + +| our refusal | libaom counterpart | verdict | +|---|---|---| +| `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 | +| `show_existing_frame` naming an empty slot | `decodeframe.c:4651-4654` → `AOM_CODEC_UNSUP_BITSTREAM "Buffer does not contain a decoded frame"` | spec-conformant | +| a reference selected with no picture | `decodeframe.c:5008-5031` → `AOM_CODEC_CORRUPT_FRAME "Inter frame requests nonexistent reference"` | spec-conformant | +| 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 | +| a frame with no mode-info grid | libaom derives the mi grid from the frame size; a 0-sized frame is unrepresentable (`compute_image_size`); no error site exists because no conformant header codes one | spec-conformant / defensive | +| 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) | +| a bit depth of 12 | libaom supports 8/10/12 with `CONFIG_AV1_HIGHBITDEPTH`; `read_sequence_header` accepts `twelve_bit` | **intentional gate** (see §4) | +| `SEG_LVL_REF_FRAME/SKIP/GLOBALMV` enabled | libaom **implements** them (`decodemv.c:431,437,1071,1350`) | **capability gap** (see §4) | + +Non-empty negative gates backing the first five already exist in `PROVEN` +(`a_show_existing_frame_header_naming_an_empty_slot_is_refused_by_name`, +`an_inter_frame_opening_a_stream_is_refused_by_name`, +`a_selected_reference_with_an_empty_ref_frame_idx_slot_refuses_by_name`, +`an_inter_frame_naming_an_unrefreshed_primary_ref_slot_is_refused_by_name`, +`every_frame_size_a_header_can_code_has_a_mode_info_grid`). + +## 4. Kept with an assessment (real gaps, no reachable witness) + +### 4.1 `SEG_LVL_REF_FRAME/SKIP/GLOBALMV` + +libaom implements all three (they rewrite a block's reference / skip / mode +before the symbols are read: `decodemv.c:431` `SEG_LVL_SKIP`, `:437` +`SEG_LVL_REF_FRAME`/`SEG_LVL_GLOBALMV`, `:1071` `read_ref_frames`, `:1350` +`read_is_inter_block`). Our decoder reads `segment_id` (feeding the quantizer +and loop-filter level) but has no reader for these three, so it refuses by name +rather than desyncing. + +**Reachability.** `aomenc` exposes **no** flag that enables them: its only +segmentation producers are the AQ modes, which set `SEG_LVL_ALT_Q` alone +(`aq_variance.c:89`, `aq_complexity.c:118`, `aq_cyclicrefresh.c:630`), and the +mode-overriding features are set only from the **library API** — +`av1_apply_roi_map` (`encoder_utils.c:515`, realtime + ROI), `av1_apply_active_map` +(`encoder_utils.c:557`, `SEG_LVL_SKIP`), and the alt-ref source-overlap case +(`encoder_utils.c:401-413`). `aomenc --help` has no `roi-map`/`active-map` +option (checked live), so no CLI recipe reaches them; the existing PROVEN +negative gate builds the stream by hand. + +**Disposition: `kept-with-assessment`** — a real pod reaches a conformant +stream through the library API, so the gap is real; no aomenc witness exists to +prove a lift, and the lift touches the inter block path (mode/reference +selection) outside this lane. + +### 4.2 Bit depth 12 + +libaom supports 12-bit (`CONFIG_AV1_HIGHBITDEPTH`). Our gate is deliberate and +already names its cost in the refusal string: at 12-bit the rounding shifts +change — `warp.rs`'s `REDUCE_BITS_HORIZ` is a hard 3 where libaom uses +`round_0 + max(bd + FILTER_BITS - round_0 - 14, 0)` (= 5 at bd 12), MC +`round_0`/`round_1` change (`convolve.h`), the Wiener rounding bits change, and +neither CDEF nor film grain has a 12-bit path. **Assessment:** lifting cleanly +requires a rounding-shift parameterisation across warp/MC/wiener plus CDEF and +grain 12-bit LUTs, each needing its own byte-exact witness against libaom at +12-bit — a distinct lane's worth. **Disposition: `kept-with-assessment`.** + +### 4.3 Reference height mismatch + +libaom accepts a reference of a different size and scales both axes +(`decodeframe.c:5089-5099`); we port only **width** scaling (superres), so any +height mismatch refuses. This is stricter than libaom but is **not a +spec-conformant** guard. Reachability from aomenc: superres changes width only; +the only both-axes route is dynamic resize (`--resize-mode=3`), whose streams +currently stop earlier in this decoder (measured: the resize arms either fail to +encode or stop on the pre-existing intrabc-rect refusal), so no witness reaches +it. **Disposition: `kept-with-assessment`.** + +## 5. Tail cleanup — the capability claim and the 128-root strip + +- **`filter intra on a superblock-level HORZ/VERT strip`** (`decode.rs:12632`), + the lone `CAPABILITY_CLAIM`: unreachable. The strips it protects are + `(64, 32)` / `(32, 64)`, and `filter_intra_size_class_rect`'s table admits + **no arm with a 64 axis** — both fall to its `_ => None` arm + (`av1_filter_intra_allowed_bsize` caps both sides at 32). New enumeration test + `a_sb_level_horz_vert_strip_admits_no_filter_intra_symbol` parses **every** + arm and asserts no side exceeds 32 and that neither strip shape has its own + arm. Kept as a named pin (repo convention: keep + annotate a + proven-unreachable guard) with the claim comment extended. +- **`CfL, filter intra or a palette on a 128-root HORZ/VERT intra block`** + (`decode.rs:14992`): already `PROVEN` by + `no_128_root_half_reads_a_cfl_filter_intra_or_palette_symbol` (lane-t900 r33) + — the call site's literal `cfl=false`, the no-128 arms of + `filter_intra_size_class_rect`/`filter_intra_size_class`, and + `palette_bsize_ctx_wh`'s `bw > 64 || bh > 64` bound. No change; verified it + still holds and is registered. + +## 6. Gates run + +- `cargo check -p ec-av1 --all-targets` → rc 0, **0 warnings**. +- New gates: + `a_real_aomenc_mixed_lossless_segment_frame_is_refused_by_name` → ok (3 arms, + 1 mixed frame each, refused by name). + `a_sb_level_horz_vert_strip_admits_no_filter_intra_symbol` → ok. +- Inventory consistency (all ok): `the_decode_path_refuses_exactly_the_listed_cases`, + `every_proven_refusal_names_a_test_that_exists` (prints + `34 refusals + 1 capability claims, 34 proven`), + `capability_claims_are_declared_not_scattered`, + `gates_that_swallow_a_decode_error_are_declared`. +- Full lib suite: `cargo test -p ec-av1 --lib` to completion — **594 passed / + 0 failed / 60 ignored** with the environment sane (§7; 592/60 baseline + this + lane's 2 gates). + +## 7. Suite result + +`cargo test -p ec-av1 --lib`, two completed runs on this lane's tree. **Both +runs' single failure was environmental, not a code defect**; every test passes +otherwise, and each failing gate is green on its own once the environment is +fixed. + +| run | result | the one failure | cause | +|---|---|---|---| +| 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` | +| 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 | + +Both fixed and re-verified in isolation: +`ln -s ../edith_codecs/fixtures fixtures` → the film-grain gate `1 passed`; +freeing `/tmp` headroom → the 1080p straddle gate `1 passed; 0 failed` +(26 s). With the environment sane, the suite is **594 passed / 0 failed / 60 +ignored** (592/60 main baseline + this lane's two gates). This lane adds no +behavioral decoder code — two tests and disposition comments — so no other +test can move. + +Verification protocol for the box: run the ec-av1 suite with the worktree's +`fixtures/` symlink in place and with `df`/`quota` checked first; a +`QuotaExceeded`/EDQUOT panic or a missing-fixture `unwrap` is an environment +fail, not a lane regression (class `gate-skips-on-its-own-failure`, from the +other side). + +## 8. Repro commands + +``` +# build the probe +CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1hdr \ + cargo build --release -p ec-av1 --example decode_probe + +# the mixed-lossless witness, by hand +ffmpeg -v error -f lavfi -i "testsrc2=size=256x192:rate=25" -t 0.16 \ + -pix_fmt yuv420p -f yuv4mpegpipe - \ + | ~/.cache/aom-oracle/build/aomenc --codec=av1 --passes=1 --threads=1 --limit=4 \ + --end-usage=q --cq-level=0 --aq-mode=1 --good --cpu-used=3 --sb-size=64 \ + --obu -o - - > mixed.obu +EC_HDR=1 decode_probe mixed.obu # EC_SEGHDR: SEG_LVL_ALT_Q over base_q_idx=0 +decode_probe mixed.obu # REFUSED: a frame mixing lossless and lossy segments +ffmpeg -v error -f obu -i mixed.obu -f null - # libaom accepts it (rc 0) + +# the new gates +CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1hdr \ + cargo test -p ec-av1 --lib -- --nocapture \ + a_real_aomenc_mixed_lossless_segment_frame_is_refused_by_name \ + a_sb_level_horz_vert_strip_admits_no_filter_intra_symbol +``` + +## 9. Git log + +- `lane-av1-hdr` off `0cfb9af5`: the witness gate, the enumeration test, the + disposition comments, this report.