diff --git a/crates/ec-av1/fixtures/svt1-split-tx-pin.obu b/crates/ec-av1/fixtures/svt1-split-tx-pin.obu new file mode 100644 index 0000000000000000000000000000000000000000..1b3f64d651955a019e950722f85db4dc506e8344 GIT binary patch literal 1838 zcmV+}2hsQv016HO000BM{J7QgAV5H%fHIj56aXb~A(l)qBriVj2+#EG3DhD_k&30^ zvBGmm-C)c>vPWhvTGbqU0yUy_P;TD9eG5M6PhGu=f>0PN7Vqu2sbUSOkB-C73~fq% zim$cB0%RR>6j;tC7N9C*+vRLSn<+%@*z$%j?c_U?%!c<~9CM2*-rl|vxOX9nf>zbP z@%xOe+sFzO$1(pszodY5i@_}@aCB71TNabUX!Wy5PI9BTbA;*UrdLG^U{fP0^Y+VV zOz`1pec;N=1aA`p%bY^aoxVt!^h@xb{CFC8TA4 zJtOyJmlVz9va1DJ6kPy2%1B(GlG%J$Enu!%;?4^x``u6?#bk(x2x<6j9 zZJ5JQ6H)E)mj>KmpEJ6a)vk(Qu2U#$FGhV5z~v4M^#8!T>MNmi-3k*K4w93zSUlWh zVRuw%kFNJTj%E*Umkw)FuLRZlJmL_S?fsq(<& zz~*(gX1+@l*b?0&0x0o*LX-hLs^koEQ>q!u2vo)FHkD)lfLgZ&T76?jyl{0R?w0XF zkoclA{xOYw_>*V9YLiAAdCy{HNQF+J*m3k`Et2fxhwhL)ntmOcWm7ePrks~PHys#l z@nBZrPL7AF8c9B5u1X4Q)aT=RqF>-@Zm1%M7zo@N7!&)ahDT! zC&(ZiyG&o@$EU=abUJt6JfOi>?f!=a3~|0bC&jmiGrBor9TN8~2|T*G5r+b^0B8uu z;f|1Bo`QNMjD9U+Kq_s?2pa6JDm@XAb?8Ta1r`?y76TX0z@o@nL}$BbXidODe;0Wd z%kOjqfx1T_s+ib7r$;k5>(JeF-e34!6wB-2X{HVhCP{bG=>$UqG;@Ra!+7*PmJ{b@ zsbY=IyY*jQ!A&(|Q=U>^7z9~vsw-BuJ9Rg_-av8U0WHr^*wCg~!!QbSE8J-dl%v$b=>V(kdbs&xNX9e0*2Ga!ZN}6J-*~yC29~srP>=%Z zznaudPgy|MM1vOL%qYA+HLA6cV9`k!{Vw#_IBRutGD!}?0IMcKsFICma)1Oe%S=!; zn$G1n`QXVuY@8y3w}UA&)1E0{6;Q`_Y&}V5()$fboW=4&;>!k$<8N4kBz<5;U=^&v z4l2XO(E*rkJ>#GF>SJlIrR(3{7=6G+rcIPlCb9#OrY4EUSjo& z7zHSbc^Y>n5b@TJcevZS_(#`)tMA!YOKwdlxXik!ma6ZT*j; zYDvjg>@45biAKsubCq?H;{(1bBXQ$($d!fep={ow=}uTu#}RHzMnxqLTEX5*#I83lsz|I7K8Bb6tUG0aZtZk#qIUEZ5uItTg} zcXV(2q@OTX;Sx?XtjE?G$#d>Y25Z7t|6!d%Hhus>^S7EnK9+m``RloMYc^SzAM(bL z!W=}YIBb9UPbD=~NAd7s_p{DUB{nb5HkQ={YnVGW#3Lt0zF5>5&_NaG8925ohbjO7 c00AHy$pj=mSKG~v(n1FF4%#~jfR)^|U|#uxqyPW_ literal 0 HcmV?d00001 diff --git a/crates/ec-av1/src/gate_coverage.rs b/crates/ec-av1/src/gate_coverage.rs index 89f83c43..222261c6 100644 --- a/crates/ec-av1/src/gate_coverage.rs +++ b/crates/ec-av1/src/gate_coverage.rs @@ -2250,8 +2250,12 @@ mod count_vacuity { let mut out: Vec<(String, &str)> = Vec::new(); for (i, line) in lines.iter().enumerate() { let t = line.trim_start(); - let Some(rest) = t.strip_prefix("fn ") else { continue }; - let Some(nm) = rest.split('(').next() else { continue }; + let Some(rest) = t.strip_prefix("fn ") else { + continue; + }; + let Some(nm) = rest.split('(').next() else { + continue; + }; if nm.contains(' ') { continue; } @@ -2551,7 +2555,6 @@ mod count_vacuity { s.len() ); } - } #[cfg(test)] @@ -2598,23 +2601,24 @@ mod count_vacuity_tests { // call (`-frames:v 1` / `-vframes 1` / `--limit=N` / a helper's `frames` // parameter / the arm tuple's `frame_count` / the wire's own OBU frame // headers), so the count handed to the oracle is a value already proven - // against the encode instead of read off our decode. The two that remain - // are the two that are not a count to fix: - // * `an_svt_screen_palette_block_with_a_split_transform_decodes_exactly` - // reads the path `EC_AV1_SVT1_STREAM` names, and that crop is not - // committed to `fixtures/`, so no `--limit`, no `-frames:v` and no - // frame count exists anywhere in the tree for it. The doc comment's - // "12-frame stream" is prose about one capture and the env var - // accepts any file, so asserting 12 would pin a number nothing can - // check. Counting the stream's own OBU frame headers with - // `Av1Parser` would derive one, and is left on the table - // deliberately: the gate SKIPs on any box without that env var, so - // such an assert would ship unexercised. - // * a `///` DOC COMMENT quoting the pre-r4 body of - // `pinned_lr_sgr_stream_call_unique_dump`, which this line-based - // scan cannot tell from code. The gate it describes already spends - // `FRAMES` and asserts `pics.len() == FRAMES`. - const UNPINNED_CEILING: usize = 2; + // against the encode instead of read off our decode. Two rows survived + // that round; lane-av1pinspec2 closed both, so the ceiling is now 0. + // + // lane-av1pinspec2: 2 -> 1, for the SVT row. That gate was handed + // forward last round because the count was underivable: the stream came + // from `EC_AV1_SVT1_STREAM`, was never committed, and the gate SKIPped + // on a stock box -- so a wire-derived assert would have been an + // unexercised assert wearing a pin's clothes. The crop is now COMMITTED + // (`fixtures/svt1-split-tx-pin.obu`, a byte-reproducible replay of a + // `-frames:v 1` libsvtav1 encode), the gate reads it, and its count + // comes from the stream's own OBU frame headers with + // `show_existing_frame` asserted false, so a header count cannot + // over-count. The gate runs on a stock box, so the assert executes. + // + // The remaining unpinned row is a `///` DOC COMMENT quoting the pre-r4 + // body of `pinned_lr_sgr_stream_call_unique_dump`, which this + // line-based scan cannot tell from code. + const UNPINNED_CEILING: usize = 1; let unpinned = s.iter().filter(|x| x.pinned_by.is_none()).count(); assert!( unpinned <= UNPINNED_CEILING, diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index aba2aa92..09d1e858 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -5582,23 +5582,52 @@ pub(crate) mod tests { } } - /// lane-svt1: an SVT-AV1 (v3.1.2, `-preset 8 -crf 35`) screen key frame - /// codes 16x16 PALETTE blocks with `skip == 1` whose `tx_depth` split the - /// luma transform. [`crate::decode::decode_block`] armed the palette - /// prediction only when the transform covered the whole block, so that one - /// block predicted DC off its own edges instead: the right symbols (the - /// whole mode ladder diffs clean against an instrumented aomdec) and the - /// wrong pixels -- 812 luma samples in frame 0, carried by the V_PRED - /// blocks under it to 10122 samples over the 12-frame stream. - /// - /// No lavfi recipe witnesses it in a stream this decoder otherwise decodes: - /// 6 sources x 5 sizes x 6 crf values through `libsvtav1 -preset 8 - /// -svtav1-params screen-content-mode=1` produced 8 streams that reach the - /// path, and every one of them either refuses on an unrelated Golomb tail - /// or misses by ~200k samples on unrelated inter-frame defects (both - /// recorded in `lanes/svt1.report.md`). So the gate rides the kept stream - /// named by `EC_AV1_SVT1_STREAM` and SKIPs when it is unset -- the screen - /// crop itself is never committed to `fixtures/`. + /// lane-svt1: an SVT-AV1 (v3.1.2, `-preset 8`) screen key frame codes 16x16 + /// PALETTE blocks with `skip == 1` whose `tx_depth` split the luma + /// transform. [`crate::decode::decode_block`] armed the palette prediction + /// only when the transform covered the whole block, so that one block + /// predicted DC off its own edges instead: the right symbols (the whole mode + /// ladder diffs clean against an instrumented aomdec) and the wrong pixels + /// -- 812 luma samples in frame 0, carried by the V_PRED blocks under it to + /// 10122 samples over the 12-frame stream the defect was found on. + /// + /// lane-av1pinspec2: the gate used to RIDE an external crop named by + /// `EC_AV1_SVT1_STREAM` and SKIP when that was unset, so it never ran on a + /// stock box -- which is exactly why its oracle count could not be pinned + /// (an assert on a gate that never executes is an unexercised assert wearing + /// a pin's clothes). It now runs on the COMMITTED pin + /// `crates/ec-av1/fixtures/svt1-split-tx-pin.obu`. + /// + /// The pin is a REPLAY, not a fresh capture, and the recipe is recorded + /// because it reproduces the bytes exactly (two independent encodes on this + /// box, SVT-AV1 v3.1.2, both sha256 + /// `c9d9c0ae934fba72fc9a9374bc36853f290796a8a4d6442140e239669e0b341f`, + /// 1838 bytes): + /// + /// ffmpeg -v error -f lavfi \ + /// -i "smptehdbars=s=192x152:r=12,drawgrid=w=8:h=8:t=1:c=black" \ + /// -frames:v 1 -c:v libsvtav1 -preset 8 -crf 50 \ + /// -svtav1-params "lp=1:screen-content-mode=1" -g 12 -f obu out.obu + /// + /// `-frames:v 1` is the part lane-svt1's search lacked: its 6x5x6 sweep ran + /// FOUR frames per stream, and the ~200k-sample misses that killed every + /// candidate were on the INTER frames (`lanes/svt1.report.md`). One key + /// frame has no inter frames, and this one reaches the fixed arm + /// (`skip_split_tx_override_hits == 1`) and is pixel-exact. + /// + /// THE COUNT, and why it is derived from the wire rather than from a + /// literal. The oracle is handed the number of frame OBUs this stream + /// actually codes, counted with `Av1Parser` below -- never our decode's + /// length, which is the thing under test. A header count would OVER-count + /// a stream carrying `show_existing_frame` (spec 5.9.5: it codes no pixels, + /// so the header count is larger than the shown-frame count), so that case + /// is asserted impossible on this pin rather than assumed: the loop refuses + /// any frame header with `show_existing_frame` set, which is what makes + /// "one header == one shown frame" a checked fact here instead of an + /// argument. + /// + /// `EC_AV1_SVT1_STREAM` still overrides the pin, so a re-capture is one env + /// var away; `crate_pin` falls back to `pin_dir()` for the same reason. /// /// `skip_split_tx_override_hits` is asserted non-zero so the row cannot /// pass on a stream that never reaches the fixed arm (class @@ -5606,29 +5635,67 @@ pub(crate) mod tests { #[test] fn an_svt_screen_palette_block_with_a_split_transform_decodes_exactly() { const NAME: &str = "an_svt_screen_palette_block_with_a_split_transform_decodes_exactly"; - let Ok(path) = std::env::var("EC_AV1_SVT1_STREAM") else { - eprintln!("SKIP {NAME}: EC_AV1_SVT1_STREAM names no stream"); - return; - }; + const PIN: &str = "svt1-split-tx-pin.obu"; if !have_ffmpeg() { eprintln!("SKIP {NAME}: no ffmpeg"); return; } - let data = match std::fs::read(&path) { - Ok(data) => data, - Err(e) => { - eprintln!("SKIP {NAME}: {path}: {e}"); - return; - } + let path = match std::env::var("EC_AV1_SVT1_STREAM") { + Ok(p) => std::path::PathBuf::from(p), + // The name is spelled as a LITERAL here even though `PIN` is right + // above, on purpose: `gate_coverage::pin_inventory` matches a pin + // read by the quote that follows the callee name, so a const + // argument would leave this pin outside the "every pin a gate reads + // is a committed crate-local copy" invariant. The dup is the + // coverage -- and it is also why this comment must NOT quote that + // spelling: the scanner reads prose too, and a quoted spelling here + // parses as a pin called " and would not see a const argument, ...". + Err(_) => crate_pin("svt1-split-tx-pin.obu"), }; + let data = require_pin(&path, PIN); + // The ENCODE's frame count, read off the WIRE: parse this stream's own + // OBUs and count the frame headers. `show_existing_frame` is refused + // here on purpose -- such a header codes no pixels, so counting it + // would make this count larger than the frames the oracle can decode. + let mut parser = Av1Parser::new(); + let mut pos = 0usize; + let mut frame_headers = 0usize; + while pos < data.len() { + let Ok(obu) = parser.parse_obu(&data[pos..]) else { + break; + }; + pos += obu.total_size.max(1); + let header = match &obu.kind { + ObuKind::Frame(h, _) | ObuKind::FrameHeader(h) => h, + _ => continue, + }; + assert!( + !header.show_existing_frame, + "{NAME}: frame header {frame_headers} sets show_existing_frame, so the header \ + count is not the shown-frame count and this gate's oracle budget would be wrong" + ); + frame_headers += 1; + } + assert!( + frame_headers > 0, + "{NAME}: {} carries no frame header at all", + path.display() + ); crate::decode::reset_skip_split_tx_override_hits(); - let decoded = decode_stream(&data).expect("the kept SVT-AV1 screen stream decodes"); + let decoded = decode_stream(&data).expect("the pinned SVT-AV1 screen stream decodes"); assert!( crate::decode::skip_split_tx_override_hits() > 0, - "{NAME}: no skipped split-transform palette block in {path} -- the gate would pass blind" + "{NAME}: no skipped split-transform palette block in {} -- the gate would pass blind", + path.display() + ); + assert_eq!( + decoded.len(), + frame_headers, + "{NAME}: the stream codes {frame_headers} frame(s), the decode showed {}", + decoded.len() ); let (width, height) = (decoded[0].width, decoded[0].height); - let want = ffmpeg_decode_sequence(&data, width, height, decoded.len()); + let want = ffmpeg_decode_sequence(&data, width, height, frame_headers); for (i, (got, want)) in decoded.iter().zip(&want).enumerate() { assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg"); assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg");