stream: run the SVT split-transform gate on a committed pin, count off the wire
Browse files at this commit1e73b1b278100aee4ed720ca221f35f9eb354005Parent: b6966d63 changed files +121 -50
- crates/ec-av1/fixtures/svt1-split-tx-pin.obu +0 -0
- crates/ec-av1/src/gate_coverage.rs +24 -20
- crates/ec-av1/src/stream.rs +97 -30
crates/ec-av1/fixtures/svt1-split-tx-pin.obuadded+0 -0
Binary file changed
crates/ec-av1/src/gate_coverage.rsmodified+24 -20
| @@ -2250,8 +2250,12 @@ mod count_vacuity { | ||
| 2250 | 2250 | let mut out: Vec<(String, &str)> = Vec::new(); |
| 2251 | 2251 | for (i, line) in lines.iter().enumerate() { |
| 2252 | 2252 | let t = line.trim_start(); |
| 2253 | - let Some(rest) = t.strip_prefix("fn ") else { continue }; | |
| 2254 | - let Some(nm) = rest.split('(').next() else { continue }; | |
| 2253 | + let Some(rest) = t.strip_prefix("fn ") else { | |
| 2254 | + continue; | |
| 2255 | + }; | |
| 2256 | + let Some(nm) = rest.split('(').next() else { | |
| 2257 | + continue; | |
| 2258 | + }; | |
| 2255 | 2259 | if nm.contains(' ') { |
| 2256 | 2260 | continue; |
| 2257 | 2261 | } |
| @@ -2551,7 +2555,6 @@ mod count_vacuity { | ||
| 2551 | 2555 | s.len() |
| 2552 | 2556 | ); |
| 2553 | 2557 | } |
| 2554 | - | |
| 2555 | 2558 | } |
| 2556 | 2559 | |
| 2557 | 2560 | #[cfg(test)] |
| @@ -2598,23 +2601,24 @@ mod count_vacuity_tests { | ||
| 2598 | 2601 | // call (`-frames:v 1` / `-vframes 1` / `--limit=N` / a helper's `frames` |
| 2599 | 2602 | // parameter / the arm tuple's `frame_count` / the wire's own OBU frame |
| 2600 | 2603 | // headers), so the count handed to the oracle is a value already proven |
| 2601 | - // against the encode instead of read off our decode. The two that remain | |
| 2602 | - // are the two that are not a count to fix: | |
| 2603 | - // * `an_svt_screen_palette_block_with_a_split_transform_decodes_exactly` | |
| 2604 | - // reads the path `EC_AV1_SVT1_STREAM` names, and that crop is not | |
| 2605 | - // committed to `fixtures/`, so no `--limit`, no `-frames:v` and no | |
| 2606 | - // frame count exists anywhere in the tree for it. The doc comment's | |
| 2607 | - // "12-frame stream" is prose about one capture and the env var | |
| 2608 | - // accepts any file, so asserting 12 would pin a number nothing can | |
| 2609 | - // check. Counting the stream's own OBU frame headers with | |
| 2610 | - // `Av1Parser` would derive one, and is left on the table | |
| 2611 | - // deliberately: the gate SKIPs on any box without that env var, so | |
| 2612 | - // such an assert would ship unexercised. | |
| 2613 | - // * a `///` DOC COMMENT quoting the pre-r4 body of | |
| 2614 | - // `pinned_lr_sgr_stream_call_unique_dump`, which this line-based | |
| 2615 | - // scan cannot tell from code. The gate it describes already spends | |
| 2616 | - // `FRAMES` and asserts `pics.len() == FRAMES`. | |
| 2617 | - const UNPINNED_CEILING: usize = 2; | |
| 2604 | + // against the encode instead of read off our decode. Two rows survived | |
| 2605 | + // that round; lane-av1pinspec2 closed both, so the ceiling is now 0. | |
| 2606 | + // | |
| 2607 | + // lane-av1pinspec2: 2 -> 1, for the SVT row. That gate was handed | |
| 2608 | + // forward last round because the count was underivable: the stream came | |
| 2609 | + // from `EC_AV1_SVT1_STREAM`, was never committed, and the gate SKIPped | |
| 2610 | + // on a stock box -- so a wire-derived assert would have been an | |
| 2611 | + // unexercised assert wearing a pin's clothes. The crop is now COMMITTED | |
| 2612 | + // (`fixtures/svt1-split-tx-pin.obu`, a byte-reproducible replay of a | |
| 2613 | + // `-frames:v 1` libsvtav1 encode), the gate reads it, and its count | |
| 2614 | + // comes from the stream's own OBU frame headers with | |
| 2615 | + // `show_existing_frame` asserted false, so a header count cannot | |
| 2616 | + // over-count. The gate runs on a stock box, so the assert executes. | |
| 2617 | + // | |
| 2618 | + // The remaining unpinned row is a `///` DOC COMMENT quoting the pre-r4 | |
| 2619 | + // body of `pinned_lr_sgr_stream_call_unique_dump`, which this | |
| 2620 | + // line-based scan cannot tell from code. | |
| 2621 | + const UNPINNED_CEILING: usize = 1; | |
| 2618 | 2622 | let unpinned = s.iter().filter(|x| x.pinned_by.is_none()).count(); |
| 2619 | 2623 | assert!( |
| 2620 | 2624 | unpinned <= UNPINNED_CEILING, |
crates/ec-av1/src/stream.rsmodified+97 -30
| @@ -5582,23 +5582,52 @@ pub(crate) mod tests { | ||
| 5582 | 5582 | } |
| 5583 | 5583 | } |
| 5584 | 5584 | |
| 5585 | - /// lane-svt1: an SVT-AV1 (v3.1.2, `-preset 8 -crf 35`) screen key frame | |
| 5586 | - /// codes 16x16 PALETTE blocks with `skip == 1` whose `tx_depth` split the | |
| 5587 | - /// luma transform. [`crate::decode::decode_block`] armed the palette | |
| 5588 | - /// prediction only when the transform covered the whole block, so that one | |
| 5589 | - /// block predicted DC off its own edges instead: the right symbols (the | |
| 5590 | - /// whole mode ladder diffs clean against an instrumented aomdec) and the | |
| 5591 | - /// wrong pixels -- 812 luma samples in frame 0, carried by the V_PRED | |
| 5592 | - /// blocks under it to 10122 samples over the 12-frame stream. | |
| 5593 | - /// | |
| 5594 | - /// No lavfi recipe witnesses it in a stream this decoder otherwise decodes: | |
| 5595 | - /// 6 sources x 5 sizes x 6 crf values through `libsvtav1 -preset 8 | |
| 5596 | - /// -svtav1-params screen-content-mode=1` produced 8 streams that reach the | |
| 5597 | - /// path, and every one of them either refuses on an unrelated Golomb tail | |
| 5598 | - /// or misses by ~200k samples on unrelated inter-frame defects (both | |
| 5599 | - /// recorded in `lanes/svt1.report.md`). So the gate rides the kept stream | |
| 5600 | - /// named by `EC_AV1_SVT1_STREAM` and SKIPs when it is unset -- the screen | |
| 5601 | - /// crop itself is never committed to `fixtures/`. | |
| 5585 | + /// lane-svt1: an SVT-AV1 (v3.1.2, `-preset 8`) screen key frame codes 16x16 | |
| 5586 | + /// PALETTE blocks with `skip == 1` whose `tx_depth` split the luma | |
| 5587 | + /// transform. [`crate::decode::decode_block`] armed the palette prediction | |
| 5588 | + /// only when the transform covered the whole block, so that one block | |
| 5589 | + /// predicted DC off its own edges instead: the right symbols (the whole mode | |
| 5590 | + /// ladder diffs clean against an instrumented aomdec) and the wrong pixels | |
| 5591 | + /// -- 812 luma samples in frame 0, carried by the V_PRED blocks under it to | |
| 5592 | + /// 10122 samples over the 12-frame stream the defect was found on. | |
| 5593 | + /// | |
| 5594 | + /// lane-av1pinspec2: the gate used to RIDE an external crop named by | |
| 5595 | + /// `EC_AV1_SVT1_STREAM` and SKIP when that was unset, so it never ran on a | |
| 5596 | + /// stock box -- which is exactly why its oracle count could not be pinned | |
| 5597 | + /// (an assert on a gate that never executes is an unexercised assert wearing | |
| 5598 | + /// a pin's clothes). It now runs on the COMMITTED pin | |
| 5599 | + /// `crates/ec-av1/fixtures/svt1-split-tx-pin.obu`. | |
| 5600 | + /// | |
| 5601 | + /// The pin is a REPLAY, not a fresh capture, and the recipe is recorded | |
| 5602 | + /// because it reproduces the bytes exactly (two independent encodes on this | |
| 5603 | + /// box, SVT-AV1 v3.1.2, both sha256 | |
| 5604 | + /// `c9d9c0ae934fba72fc9a9374bc36853f290796a8a4d6442140e239669e0b341f`, | |
| 5605 | + /// 1838 bytes): | |
| 5606 | + /// | |
| 5607 | + /// ffmpeg -v error -f lavfi \ | |
| 5608 | + /// -i "smptehdbars=s=192x152:r=12,drawgrid=w=8:h=8:t=1:c=black" \ | |
| 5609 | + /// -frames:v 1 -c:v libsvtav1 -preset 8 -crf 50 \ | |
| 5610 | + /// -svtav1-params "lp=1:screen-content-mode=1" -g 12 -f obu out.obu | |
| 5611 | + /// | |
| 5612 | + /// `-frames:v 1` is the part lane-svt1's search lacked: its 6x5x6 sweep ran | |
| 5613 | + /// FOUR frames per stream, and the ~200k-sample misses that killed every | |
| 5614 | + /// candidate were on the INTER frames (`lanes/svt1.report.md`). One key | |
| 5615 | + /// frame has no inter frames, and this one reaches the fixed arm | |
| 5616 | + /// (`skip_split_tx_override_hits == 1`) and is pixel-exact. | |
| 5617 | + /// | |
| 5618 | + /// THE COUNT, and why it is derived from the wire rather than from a | |
| 5619 | + /// literal. The oracle is handed the number of frame OBUs this stream | |
| 5620 | + /// actually codes, counted with `Av1Parser` below -- never our decode's | |
| 5621 | + /// length, which is the thing under test. A header count would OVER-count | |
| 5622 | + /// a stream carrying `show_existing_frame` (spec 5.9.5: it codes no pixels, | |
| 5623 | + /// so the header count is larger than the shown-frame count), so that case | |
| 5624 | + /// is asserted impossible on this pin rather than assumed: the loop refuses | |
| 5625 | + /// any frame header with `show_existing_frame` set, which is what makes | |
| 5626 | + /// "one header == one shown frame" a checked fact here instead of an | |
| 5627 | + /// argument. | |
| 5628 | + /// | |
| 5629 | + /// `EC_AV1_SVT1_STREAM` still overrides the pin, so a re-capture is one env | |
| 5630 | + /// var away; `crate_pin` falls back to `pin_dir()` for the same reason. | |
| 5602 | 5631 | /// |
| 5603 | 5632 | /// `skip_split_tx_override_hits` is asserted non-zero so the row cannot |
| 5604 | 5633 | /// pass on a stream that never reaches the fixed arm (class |
| @@ -5606,29 +5635,67 @@ pub(crate) mod tests { | ||
| 5606 | 5635 | #[test] |
| 5607 | 5636 | fn an_svt_screen_palette_block_with_a_split_transform_decodes_exactly() { |
| 5608 | 5637 | const NAME: &str = "an_svt_screen_palette_block_with_a_split_transform_decodes_exactly"; |
| 5609 | - let Ok(path) = std::env::var("EC_AV1_SVT1_STREAM") else { | |
| 5610 | - eprintln!("SKIP {NAME}: EC_AV1_SVT1_STREAM names no stream"); | |
| 5611 | - return; | |
| 5612 | - }; | |
| 5638 | + const PIN: &str = "svt1-split-tx-pin.obu"; | |
| 5613 | 5639 | if !have_ffmpeg() { |
| 5614 | 5640 | eprintln!("SKIP {NAME}: no ffmpeg"); |
| 5615 | 5641 | return; |
| 5616 | 5642 | } |
| 5617 | - let data = match std::fs::read(&path) { | |
| 5618 | - Ok(data) => data, | |
| 5619 | - Err(e) => { | |
| 5620 | - eprintln!("SKIP {NAME}: {path}: {e}"); | |
| 5621 | - return; | |
| 5622 | - } | |
| 5643 | + let path = match std::env::var("EC_AV1_SVT1_STREAM") { | |
| 5644 | + Ok(p) => std::path::PathBuf::from(p), | |
| 5645 | + // The name is spelled as a LITERAL here even though `PIN` is right | |
| 5646 | + // above, on purpose: `gate_coverage::pin_inventory` matches a pin | |
| 5647 | + // read by the quote that follows the callee name, so a const | |
| 5648 | + // argument would leave this pin outside the "every pin a gate reads | |
| 5649 | + // is a committed crate-local copy" invariant. The dup is the | |
| 5650 | + // coverage -- and it is also why this comment must NOT quote that | |
| 5651 | + // spelling: the scanner reads prose too, and a quoted spelling here | |
| 5652 | + // parses as a pin called " and would not see a const argument, ...". | |
| 5653 | + Err(_) => crate_pin("svt1-split-tx-pin.obu"), | |
| 5623 | 5654 | }; |
| 5655 | + let data = require_pin(&path, PIN); | |
| 5656 | + // The ENCODE's frame count, read off the WIRE: parse this stream's own | |
| 5657 | + // OBUs and count the frame headers. `show_existing_frame` is refused | |
| 5658 | + // here on purpose -- such a header codes no pixels, so counting it | |
| 5659 | + // would make this count larger than the frames the oracle can decode. | |
| 5660 | + let mut parser = Av1Parser::new(); | |
| 5661 | + let mut pos = 0usize; | |
| 5662 | + let mut frame_headers = 0usize; | |
| 5663 | + while pos < data.len() { | |
| 5664 | + let Ok(obu) = parser.parse_obu(&data[pos..]) else { | |
| 5665 | + break; | |
| 5666 | + }; | |
| 5667 | + pos += obu.total_size.max(1); | |
| 5668 | + let header = match &obu.kind { | |
| 5669 | + ObuKind::Frame(h, _) | ObuKind::FrameHeader(h) => h, | |
| 5670 | + _ => continue, | |
| 5671 | + }; | |
| 5672 | + assert!( | |
| 5673 | + !header.show_existing_frame, | |
| 5674 | + "{NAME}: frame header {frame_headers} sets show_existing_frame, so the header \ | |
| 5675 | + count is not the shown-frame count and this gate's oracle budget would be wrong" | |
| 5676 | + ); | |
| 5677 | + frame_headers += 1; | |
| 5678 | + } | |
| 5679 | + assert!( | |
| 5680 | + frame_headers > 0, | |
| 5681 | + "{NAME}: {} carries no frame header at all", | |
| 5682 | + path.display() | |
| 5683 | + ); | |
| 5624 | 5684 | crate::decode::reset_skip_split_tx_override_hits(); |
| 5625 | - let decoded = decode_stream(&data).expect("the kept SVT-AV1 screen stream decodes"); | |
| 5685 | + let decoded = decode_stream(&data).expect("the pinned SVT-AV1 screen stream decodes"); | |
| 5626 | 5686 | assert!( |
| 5627 | 5687 | crate::decode::skip_split_tx_override_hits() > 0, |
| 5628 | - "{NAME}: no skipped split-transform palette block in {path} -- the gate would pass blind" | |
| 5688 | + "{NAME}: no skipped split-transform palette block in {} -- the gate would pass blind", | |
| 5689 | + path.display() | |
| 5690 | + ); | |
| 5691 | + assert_eq!( | |
| 5692 | + decoded.len(), | |
| 5693 | + frame_headers, | |
| 5694 | + "{NAME}: the stream codes {frame_headers} frame(s), the decode showed {}", | |
| 5695 | + decoded.len() | |
| 5629 | 5696 | ); |
| 5630 | 5697 | let (width, height) = (decoded[0].width, decoded[0].height); |
| 5631 | - let want = ffmpeg_decode_sequence(&data, width, height, decoded.len()); | |
| 5698 | + let want = ffmpeg_decode_sequence(&data, width, height, frame_headers); | |
| 5632 | 5699 | for (i, (got, want)) in decoded.iter().zip(&want).enumerate() { |
| 5633 | 5700 | assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg"); |
| 5634 | 5701 | assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg"); |