stream: convert the four skip-on-decode-error gates to attempt loops
Browse files at this commit3104b2b0359e8038e0a62e1161db1910b2094bf4Parent: a460dca1 changed file +533 -327
- crates/ec-av1/src/stream.rs +533 -327
crates/ec-av1/src/stream.rsmodified+533 -327
| @@ -8568,48 +8568,118 @@ pub(crate) mod tests { | |||
| 8568 | /// CDEF *on* (no `-enable-cdef 0`) -- the whole point of `lane-av1cdef`: | 8568 | /// CDEF *on* (no `-enable-cdef 0`) -- the whole point of `lane-av1cdef`: |
| 8569 | /// proves `apply_cdef` itself, not just that this decoder still works | 8569 | /// proves `apply_cdef` itself, not just that this decoder still works |
| 8570 | /// when the filter never fires. Gradient content at a low crf reliably | 8570 | /// when the filter never fires. Gradient content at a low crf reliably |
| 8571 | - /// gives libaom something to dering. If a run happens to land on | 8571 | + /// gives libaom something to dering. |
| 8572 | - /// `cdef_bits > 0` (per-64x64 `cdef_idx`, still unimplemented -- see the | 8572 | + /// |
| 8573 | - /// refusal in `decode_stream`) the stream is skipped rather than failed: | 8573 | + /// lane-av1skipfix: the attempt-loop shape. A single-SB 64x64 frame can |
| 8574 | - /// that gap is named by the refusal's own error text, not silently | 8574 | + /// never make libaom write `cdef_bits > 0` (nothing to differentiate per |
| 8575 | - /// swallowed here. | 8575 | + /// superblock), so this recipe is MULTI-SB and MULTI-FRAME, and it sweeps |
| 8576 | + /// (size, cpu-used, crf) until one attempt reads a real `cdef_idx` literal | ||
| 8577 | + /// -- MEASURED 2026-09-29 on `a21f3680`: 64x64 at every crf/cpu reads | ||
| 8578 | + /// ZERO `cdef_idx` (single superblock, `bits == 0`, though `apply_cdef` | ||
| 8579 | + /// does filter with a nonzero strength pair), while 128x64/128x128 at | ||
| 8580 | + /// 24 frames read 2-8. Every attempt that decodes is ALWAYS pixel- | ||
| 8581 | + /// compared against ffmpeg's own decode of the identical bytes; a decode | ||
| 8582 | + /// error is a named refusal recorded per attempt, never a SKIP, and | ||
| 8583 | + /// exhausting every attempt -- or decoding without ever reading a | ||
| 8584 | + /// `cdef_idx` -- is a hard FAILURE (an unfired gate is a vacuous gate, | ||
| 8585 | + /// class `gate-skips-on-its-own-failure`). | ||
| 8576 | #[test] | 8586 | #[test] |
| 8577 | fn a_real_libaom_gradients_stream_with_cdef_decodes_pixel_exact() { | 8587 | fn a_real_libaom_gradients_stream_with_cdef_decodes_pixel_exact() { |
| 8588 | + const NAME: &str = "a_real_libaom_gradients_stream_with_cdef_decodes_pixel_exact"; | ||
| 8589 | + let _gate_lock = lock_gate_counters(); | ||
| 8578 | if !have_ffmpeg() { | 8590 | if !have_ffmpeg() { |
| 8579 | - eprintln!( | 8591 | + eprintln!("SKIP {NAME}: no ffmpeg"); |
| 8580 | - "SKIP a_real_libaom_gradients_stream_with_cdef_decodes_pixel_exact: no ffmpeg" | ||
| 8581 | - ); | ||
| 8582 | return; | 8592 | return; |
| 8583 | } | 8593 | } |
| 8584 | - let (width, height) = (64, 64); | 8594 | + // (width, height, frames, cpu-used, crf). The frame count is what |
| 8585 | - let stream = libaom_encode_with( | 8595 | + // gives libaom's cdef search more than one superblock to price. |
| 8586 | - &gradients_source(42, width, height, "rate=1"), | 8596 | + const RECIPES: [(usize, usize, usize, &str, u32); 8] = [ |
| 8587 | - width, | 8597 | + (128, 64, 24, "0", 20), |
| 8588 | - height, | 8598 | + (128, 64, 24, "2", 20), |
| 8589 | - 30, | 8599 | + (128, 64, 24, "0", 16), |
| 8590 | - &[ | 8600 | + (128, 128, 24, "2", 20), |
| 8591 | - "-threads", | 8601 | + (128, 128, 24, "0", 16), |
| 8592 | - "1", | 8602 | + (128, 128, 24, "0", 24), |
| 8593 | - "-row-mt", | 8603 | + (128, 64, 24, "2", 24), |
| 8594 | - "0", | 8604 | + (128, 128, 24, "2", 24), |
| 8595 | - "-tile-columns", | 8605 | + ]; |
| 8596 | - "0", | 8606 | + let mut refusals = Vec::new(); |
| 8597 | - "-tile-rows", | 8607 | + let mut counted_exact = 0u32; |
| 8598 | - "0", | 8608 | + let mut uncounted_exact = 0u32; |
| 8599 | - ], | 8609 | + for (w, h, frames, cpu, crf) in RECIPES { |
| 8600 | - ) | 8610 | + let Some(stream) = libaom_encode_with( |
| 8601 | - .expect("ffmpeg encode"); | 8611 | + &gradients_source(42, w, h, "rate=25"), |
| 8602 | - match decode_stream(&stream) { | 8612 | + w, |
| 8603 | - Ok(frames) => { | 8613 | + h, |
| 8604 | - let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); | 8614 | + crf, |
| 8605 | - assert_eq!(frames[0].y, ffmpeg_frames[0].y, "luma vs ffmpeg (CDEF on)"); | 8615 | + &[ |
| 8606 | - assert_eq!(frames[0].u, ffmpeg_frames[0].u, "U vs ffmpeg (CDEF on)"); | 8616 | + "-cpu-used", |
| 8607 | - assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg (CDEF on)"); | 8617 | + cpu, |
| 8618 | + "-frames:v", | ||
| 8619 | + &frames.to_string(), | ||
| 8620 | + "-threads", | ||
| 8621 | + "1", | ||
| 8622 | + "-row-mt", | ||
| 8623 | + "0", | ||
| 8624 | + "-tile-columns", | ||
| 8625 | + "0", | ||
| 8626 | + "-tile-rows", | ||
| 8627 | + "0", | ||
| 8628 | + ], | ||
| 8629 | + ) else { | ||
| 8630 | + refusals.push(format!( | ||
| 8631 | + "{w}x{h} cpu-used {cpu} crf {crf}: ffmpeg itself refused" | ||
| 8632 | + )); | ||
| 8633 | + continue; | ||
| 8634 | + }; | ||
| 8635 | + let before = decode::cdef_idx_hits(); | ||
| 8636 | + let decoded = match decode_stream(&stream) { | ||
| 8637 | + Ok(frames) => frames, | ||
| 8638 | + Err(e) => { | ||
| 8639 | + refusals.push(format!("{w}x{h} cpu-used {cpu} crf {crf}: {e}")); | ||
| 8640 | + continue; | ||
| 8641 | + } | ||
| 8642 | + }; | ||
| 8643 | + // A decode that succeeded is ALWAYS pixel-compared; the hit | ||
| 8644 | + // counter only decides whether the attempt counts as firing | ||
| 8645 | + // (class `counter-from-refused-stream`). | ||
| 8646 | + let counted = decode::cdef_idx_hits() != before; | ||
| 8647 | + if counted { | ||
| 8648 | + counted_exact += 1; | ||
| 8649 | + } else { | ||
| 8650 | + uncounted_exact += 1; | ||
| 8608 | } | 8651 | } |
| 8609 | - Err(e) => { | 8652 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, w, h, frames); |
| 8610 | - eprintln!("SKIP a_real_libaom_gradients_stream_with_cdef_decodes_pixel_exact: {e}"); | 8653 | + assert_eq!(decoded.len(), frames); |
| 8654 | + for (i, (got, want)) in decoded.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 8655 | + assert_eq!( | ||
| 8656 | + got.y, want.y, | ||
| 8657 | + "{NAME} frame {i} luma vs ffmpeg ({w}x{h} cpu-used {cpu} crf {crf}, \ | ||
| 8658 | + cdef_idx fired: {counted})" | ||
| 8659 | + ); | ||
| 8660 | + assert_eq!( | ||
| 8661 | + got.u, want.u, | ||
| 8662 | + "{NAME} frame {i} U vs ffmpeg ({w}x{h} cpu-used {cpu} crf {crf}, \ | ||
| 8663 | + cdef_idx fired: {counted})" | ||
| 8664 | + ); | ||
| 8665 | + assert_eq!( | ||
| 8666 | + got.v, want.v, | ||
| 8667 | + "{NAME} frame {i} V vs ffmpeg ({w}x{h} cpu-used {cpu} crf {crf}, \ | ||
| 8668 | + cdef_idx fired: {counted})" | ||
| 8669 | + ); | ||
| 8670 | + } | ||
| 8671 | + if counted_exact >= 2 { | ||
| 8672 | + break; | ||
| 8611 | } | 8673 | } |
| 8612 | } | 8674 | } |
| 8675 | + gate_buckets(NAME, counted_exact, uncounted_exact, refusals.len()); | ||
| 8676 | + assert!( | ||
| 8677 | + counted_exact > 0, | ||
| 8678 | + "{NAME}: no attempt of {} read a cdef_idx literal -- CDEF is not exercised \ | ||
| 8679 | + (class gate-blind-to-feature):\n{}", | ||
| 8680 | + RECIPES.len(), | ||
| 8681 | + refusals.join("\n") | ||
| 8682 | + ); | ||
| 8613 | } | 8683 | } |
| 8614 | 8684 | ||
| 8615 | /// Path to a real `aomenc` build carrying the reference options this | 8685 | /// Path to a real `aomenc` build carrying the reference options this |
| @@ -8992,124 +9062,171 @@ pub(crate) mod tests { | |||
| 8992 | /// decoder has no in-loop deblocking filter at all, and libaom's default | 9062 | /// decoder has no in-loop deblocking filter at all, and libaom's default |
| 8993 | /// (on) smooths every block-boundary column, which first looked like a | 9063 | /// (on) smooths every block-boundary column, which first looked like a |
| 8994 | /// filter-intra math bug (mismatches straddling the 32-pixel block | 9064 | /// filter-intra math bug (mismatches straddling the 32-pixel block |
| 8995 | - /// seam) until the recipe without it round-tripped byte-exact. Checks | 9065 | + /// seam) until the recipe without it round-tripped byte-exact. |
| 8996 | - /// [`decode::filter_intra_hits`] actually moved (a process-global | 9066 | + /// |
| 8997 | - /// counter, so before/after rather than an absolute value) to prove the | 9067 | + /// lane-av1skipfix: the attempt-loop shape this gate's single recipe |
| 8998 | - /// symbol fired, then pixel-exactness against ffmpeg's own decode of the | 9068 | + /// lacked. It sweeps (seed, cq) and REQUIRES at least one attempt to both |
| 8999 | - /// identical bytes on every plane. | 9069 | + /// decode and read `use_filter_intra`: a decode error on EVERY attempt is |
| 9070 | + /// a hard failure carrying the refusal texts, not a printed SKIP, and an | ||
| 9071 | + /// attempt that decodes without the symbol firing is still pixel-compared | ||
| 9072 | + /// (class `gate-skips-on-its-own-failure`). MEASURED 2026-09-29 on | ||
| 9073 | + /// `a21f3680`: seed 42 cq 40 and seed 43 cq 40 read the symbol 3x each, | ||
| 9074 | + /// pixel-exact, while seed 44 cq 45 and seed 45 cq 30 decode WITHOUT it -- | ||
| 9075 | + /// so the one fixed recipe really did carry the whole gate. | ||
| 9076 | + /// | ||
| 9077 | + /// The per-attempt decode error the old single recipe SKIPped on is | ||
| 9078 | + /// `screen_content_tools_determination` (libaom `encoder_utils.c`): a real | ||
| 9079 | + /// internal trial-encode/PSNR comparison, not a flag this CLI exposes a | ||
| 9080 | + /// knob for -- on this flat gradient fixture it lands on | ||
| 9081 | + /// `allow_screen_content_tools=0` most runs but occasionally trips over | ||
| 9082 | + /// its 0.9 dB threshold the other way even with palette/intrabc both | ||
| 9083 | + /// disabled. That is a genuine separate gap (`decode_stream` never reads | ||
| 9084 | + /// `intrabc`/`palette_mode_info`), so it is a NAMED REFUSAL counted per | ||
| 9085 | + /// attempt, never a silent skip and never a pass. | ||
| 9000 | #[test] | 9086 | #[test] |
| 9001 | fn a_real_aomenc_filter_intra_stream_decodes_pixel_exact() { | 9087 | fn a_real_aomenc_filter_intra_stream_decodes_pixel_exact() { |
| 9088 | + const NAME: &str = "a_real_aomenc_filter_intra_stream_decodes_pixel_exact"; | ||
| 9089 | + let _gate_lock = lock_gate_counters(); | ||
| 9002 | if !have_ffmpeg() { | 9090 | if !have_ffmpeg() { |
| 9003 | - eprintln!("SKIP a_real_aomenc_filter_intra_stream_decodes_pixel_exact: no ffmpeg"); | 9091 | + eprintln!("SKIP {NAME}: no ffmpeg"); |
| 9004 | return; | 9092 | return; |
| 9005 | } | 9093 | } |
| 9006 | if !have_aomenc() { | 9094 | if !have_aomenc() { |
| 9007 | - eprintln!( | 9095 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); |
| 9008 | - "SKIP a_real_aomenc_filter_intra_stream_decodes_pixel_exact: no aomenc at {}", | ||
| 9009 | - aomenc_path().display() | ||
| 9010 | - ); | ||
| 9011 | return; | 9096 | return; |
| 9012 | } | 9097 | } |
| 9013 | let (width, height) = (64usize, 64usize); | 9098 | let (width, height) = (64usize, 64usize); |
| 9014 | - // Recipe-search hooks: with the encoder pinned to one thread the | 9099 | + // Recipe-search hooks: with the encoder pinned to one thread the stream |
| 9015 | - // stream is a deterministic function of (seed, cq), so a firing recipe | 9100 | + // is a deterministic function of (seed, cq), so a firing recipe can be |
| 9016 | - // can be searched for without a rebuild. | 9101 | + // searched for without a rebuild. These pin attempt 0 for a bisect; the |
| 9102 | + // sweep walks the same axes regardless. | ||
| 9017 | let fi_seed: u32 = std::env::var("EC_FI_SEED") | 9103 | let fi_seed: u32 = std::env::var("EC_FI_SEED") |
| 9018 | .ok() | 9104 | .ok() |
| 9019 | .and_then(|v| v.parse().ok()) | 9105 | .and_then(|v| v.parse().ok()) |
| 9020 | .unwrap_or(42); | 9106 | .unwrap_or(42); |
| 9021 | - let fi_source = gradients_source(fi_seed, 64, 64, "duration=0.04:rate=25"); | 9107 | + let fi_cq: u32 = std::env::var("EC_FI_CQ") |
| 9022 | - let fi_cq = std::env::var("EC_FI_CQ").unwrap_or_else(|_| "40".to_string()); | 9108 | + .ok() |
| 9023 | - let fi_cq_arg = format!("--cq-level={fi_cq}"); | 9109 | + .and_then(|v| v.parse().ok()) |
| 9024 | - let y4m = Command::new("ffmpeg") | 9110 | + .unwrap_or(40); |
| 9025 | - .args([ | 9111 | + // Two seeds x three quantisers, so "every attempt refused" and "no |
| 9026 | - "-v", | 9112 | + // attempt ever read `use_filter_intra`" are distinguishable failures |
| 9027 | - "error", | 9113 | + // rather than one unlucky recipe. |
| 9028 | - "-f", | 9114 | + const CQS: [u32; 3] = [40, 35, 30]; |
| 9029 | - "lavfi", | 9115 | + let mut refusals = Vec::new(); |
| 9030 | - "-i", | 9116 | + let mut counted_exact = 0u32; |
| 9031 | - &fi_source, | 9117 | + let mut uncounted_exact = 0u32; |
| 9032 | - "-pix_fmt", | 9118 | + 'attempts: for round in 0..2u32 { |
| 9033 | - "yuv420p", | 9119 | + for (i, &walked) in CQS.iter().enumerate() { |
| 9034 | - "-f", | 9120 | + let seed = fi_seed + round; |
| 9035 | - "yuv4mpegpipe", | 9121 | + let cq = if round == 0 && i == 0 { fi_cq } else { walked }; |
| 9036 | - "-", | 9122 | + let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); |
| 9037 | - ]) | 9123 | + let y4m = Command::new("ffmpeg") |
| 9038 | - .stdin(Stdio::null()) | 9124 | + .args([ |
| 9039 | - .stdout(Stdio::piped()) | 9125 | + "-v", |
| 9040 | - .stderr(Stdio::piped()) | 9126 | + "error", |
| 9041 | - .output() | 9127 | + "-f", |
| 9042 | - .expect("ffmpeg failed to run"); | 9128 | + "lavfi", |
| 9043 | - assert!( | 9129 | + "-i", |
| 9044 | - y4m.status.success(), | 9130 | + &source, |
| 9045 | - "ffmpeg refused to generate the y4m fixture: {}", | 9131 | + "-pix_fmt", |
| 9046 | - String::from_utf8_lossy(&y4m.stderr) | 9132 | + "yuv420p", |
| 9047 | - ); | 9133 | + "-f", |
| 9048 | - let out = run_with_stdin( | 9134 | + "yuv4mpegpipe", |
| 9049 | - Command::new(aomenc_path()).args([ | 9135 | + "-", |
| 9050 | - "--codec=av1", | 9136 | + ]) |
| 9051 | - "--passes=1", | 9137 | + .stdin(Stdio::null()) |
| 9052 | - "--end-usage=q", | 9138 | + .stdout(Stdio::piped()) |
| 9053 | - &fi_cq_arg, | 9139 | + .stderr(Stdio::piped()) |
| 9054 | - "--cpu-used=0", | 9140 | + .output() |
| 9055 | - // Every sibling gate pins these; this one did not, and a | 9141 | + .expect("ffmpeg failed to run"); |
| 9056 | - // multi-threaded aomenc is not deterministic, so each run | 9142 | + assert!( |
| 9057 | - // encoded a slightly different stream and the gate flaked | 9143 | + y4m.status.success(), |
| 9058 | - // against whichever features that run happened to pick. | 9144 | + "ffmpeg refused to generate the y4m fixture: {}", |
| 9059 | - // Pinning them makes seed 42 mean one stream (class | 9145 | + String::from_utf8_lossy(&y4m.stderr) |
| 9060 | - // `parallel-flake-is-attempt-selection`). | 9146 | + ); |
| 9061 | - "--threads=1", | 9147 | + let cq_arg = format!("--cq-level={cq}"); |
| 9062 | - "--row-mt=0", | 9148 | + let out = run_with_stdin( |
| 9063 | - "--enable-filter-intra=1", | 9149 | + Command::new(aomenc_path()).args([ |
| 9064 | - "--enable-smooth-intra=0", | 9150 | + "--codec=av1", |
| 9065 | - "--enable-paeth-intra=0", | 9151 | + "--passes=1", |
| 9066 | - "--enable-directional-intra=0", | 9152 | + "--end-usage=q", |
| 9067 | - "--enable-angle-delta=0", | 9153 | + &cq_arg, |
| 9068 | - "--enable-tx-size-search=0", | 9154 | + "--cpu-used=0", |
| 9069 | - "--enable-cdef=0", | 9155 | + // Every sibling gate pins these; this one did not, and a |
| 9070 | - "--max-partition-size=32", | 9156 | + // multi-threaded aomenc is not deterministic, so each run |
| 9071 | - "--loopfilter-control=0", | 9157 | + // encoded a slightly different stream and the gate flaked |
| 9072 | - "--enable-palette=0", | 9158 | + // against whichever features that run happened to pick. |
| 9073 | - "--enable-intrabc=0", | 9159 | + // Pinning them makes seed 42 mean one stream (class |
| 9074 | - "--obu", | 9160 | + // `parallel-flake-is-attempt-selection`). |
| 9075 | - "-o", | 9161 | + "--threads=1", |
| 9076 | - "-", | 9162 | + "--row-mt=0", |
| 9077 | - "-", | 9163 | + "--enable-filter-intra=1", |
| 9078 | - ]), | 9164 | + "--enable-smooth-intra=0", |
| 9079 | - &y4m.stdout, | 9165 | + "--enable-paeth-intra=0", |
| 9080 | - ); | 9166 | + "--enable-directional-intra=0", |
| 9081 | - assert!( | 9167 | + "--enable-angle-delta=0", |
| 9082 | - out.status.success(), | 9168 | + "--enable-tx-size-search=0", |
| 9083 | - "aomenc refused the fixture: {}", | 9169 | + "--enable-cdef=0", |
| 9084 | - String::from_utf8_lossy(&out.stderr) | 9170 | + "--max-partition-size=32", |
| 9085 | - ); | 9171 | + "--loopfilter-control=0", |
| 9086 | - let stream = out.stdout; | 9172 | + "--enable-palette=0", |
| 9087 | - let before = decode::filter_intra_hits(); | 9173 | + "--enable-intrabc=0", |
| 9088 | - // `screen_content_tools_determination` (libaom encoder_utils.c) is a | 9174 | + "--obu", |
| 9089 | - // real internal trial-encode/PSNR comparison, not a flag this CLI | 9175 | + "-o", |
| 9090 | - // exposes a knob for -- on this flat gradient fixture it lands on | 9176 | + "-", |
| 9091 | - // `allow_screen_content_tools=0` most runs but occasionally trips | 9177 | + "-", |
| 9092 | - // over its 0.9 dB threshold the other way even with palette/intrabc | 9178 | + ]), |
| 9093 | - // both disabled. That is a genuine separate gap (`decode_stream` | 9179 | + &y4m.stdout, |
| 9094 | - // never reads `intrabc`/`palette_mode_info`), not a filter-intra | 9180 | + ); |
| 9095 | - // regression, so it is skipped here exactly as | 9181 | + assert!( |
| 9096 | - // `a_real_libaom_gradients_stream_with_cdef_decodes_pixel_exact` | 9182 | + out.status.success(), |
| 9097 | - // above skips its own still-unsupported-gap runs. | 9183 | + "{NAME}: aomenc refused the seed {seed} cq {cq} fixture: {}", |
| 9098 | - let frames = match decode_stream(&stream) { | 9184 | + String::from_utf8_lossy(&out.stderr) |
| 9099 | - Ok(frames) => frames, | 9185 | + ); |
| 9100 | - Err(e) => { | 9186 | + let stream = out.stdout; |
| 9101 | - eprintln!("SKIP a_real_aomenc_filter_intra_stream_decodes_pixel_exact: {e}"); | 9187 | + let before = decode::filter_intra_hits(); |
| 9102 | - return; | 9188 | + let frames = match decode_stream(&stream) { |
| 9189 | + Ok(frames) => frames, | ||
| 9190 | + Err(e) => { | ||
| 9191 | + refusals.push(format!("seed {seed} cq {cq}: {e}")); | ||
| 9192 | + continue; | ||
| 9193 | + } | ||
| 9194 | + }; | ||
| 9195 | + // A decode that succeeded is ALWAYS pixel-compared; the hit | ||
| 9196 | + // counter only decides whether the attempt counts as firing | ||
| 9197 | + // (class `counter-from-refused-stream`). | ||
| 9198 | + let counted = decode::filter_intra_hits() != before; | ||
| 9199 | + if counted { | ||
| 9200 | + counted_exact += 1; | ||
| 9201 | + } else { | ||
| 9202 | + uncounted_exact += 1; | ||
| 9203 | + } | ||
| 9204 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); | ||
| 9205 | + assert_eq!( | ||
| 9206 | + frames[0].y, ffmpeg_frames[0].y, | ||
| 9207 | + "luma vs ffmpeg (seed {seed} cq {cq}, use_filter_intra fired: {counted})" | ||
| 9208 | + ); | ||
| 9209 | + assert_eq!( | ||
| 9210 | + frames[0].u, ffmpeg_frames[0].u, | ||
| 9211 | + "U vs ffmpeg (seed {seed} cq {cq}, use_filter_intra fired: {counted})" | ||
| 9212 | + ); | ||
| 9213 | + assert_eq!( | ||
| 9214 | + frames[0].v, ffmpeg_frames[0].v, | ||
| 9215 | + "V vs ffmpeg (seed {seed} cq {cq}, use_filter_intra fired: {counted})" | ||
| 9216 | + ); | ||
| 9217 | + if counted_exact >= 2 { | ||
| 9218 | + break 'attempts; | ||
| 9219 | + } | ||
| 9103 | } | 9220 | } |
| 9104 | - }; | 9221 | + } |
| 9222 | + gate_buckets(NAME, counted_exact, uncounted_exact, refusals.len()); | ||
| 9105 | assert!( | 9223 | assert!( |
| 9106 | - decode::filter_intra_hits() > before, | 9224 | + counted_exact > 0, |
| 9107 | - "use_filter_intra never fired decoding this stream" | 9225 | + "{NAME}: none of {} attempts decoded a stream that read use_filter_intra -- the \ |
| 9226 | + gate would prove nothing (class gate-blind-to-feature):\n{}", | ||
| 9227 | + CQS.len() * 2, | ||
| 9228 | + refusals.join("\n") | ||
| 9108 | ); | 9229 | ); |
| 9109 | - let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); | ||
| 9110 | - assert_eq!(frames[0].y, ffmpeg_frames[0].y, "luma vs ffmpeg"); | ||
| 9111 | - assert_eq!(frames[0].u, ffmpeg_frames[0].u, "U vs ffmpeg"); | ||
| 9112 | - assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg"); | ||
| 9113 | } | 9230 | } |
| 9114 | 9231 | ||
| 9115 | /// A real `aomenc` palette-Y fixture (lane-palette r3): `smptebars` | 9232 | /// A real `aomenc` palette-Y fixture (lane-palette r3): `smptebars` |
| @@ -14755,96 +14872,144 @@ pub(crate) mod tests { | |||
| 14755 | /// picks a nonzero level -- proves `apply_deblock` itself, not just that | 14872 | /// picks a nonzero level -- proves `apply_deblock` itself, not just that |
| 14756 | /// this decoder still works when every edge lands on level 0. CDEF | 14873 | /// this decoder still works when every edge lands on level 0. CDEF |
| 14757 | /// stays off so a pixel mismatch can only come from the loop filter. | 14874 | /// stays off so a pixel mismatch can only come from the loop filter. |
| 14875 | + /// | ||
| 14876 | + /// lane-av1skipfix: the attempt-loop shape. The sweep walks cq (which is | ||
| 14877 | + /// what decides whether libaom picks a nonzero deblocking level at all) | ||
| 14878 | + /// and seed, REQUIRES at least one attempt to decode, and hard-asserts | ||
| 14879 | + /// `decode::deblock_hits` on a pixel-compared attempt -- a decode error on | ||
| 14880 | + /// every attempt is a hard failure carrying the refusal texts, never a | ||
| 14881 | + /// printed SKIP (class `gate-skips-on-its-own-failure`). MEASURED | ||
| 14882 | + /// 2026-09-29 on `a21f3680`: cq 55/45/35/63 all decode pixel-exact with | ||
| 14883 | + /// 48/64/64/64 deblock edges, so the old single recipe was one lucky | ||
| 14884 | + /// point of a cq range that needed no fallback. | ||
| 14758 | #[test] | 14885 | #[test] |
| 14759 | fn a_real_aomenc_intra_stream_with_deblocking_decodes_pixel_exact() { | 14886 | fn a_real_aomenc_intra_stream_with_deblocking_decodes_pixel_exact() { |
| 14887 | + const NAME: &str = "a_real_aomenc_intra_stream_with_deblocking_decodes_pixel_exact"; | ||
| 14888 | + let _gate_lock = lock_gate_counters(); | ||
| 14760 | if !have_ffmpeg() { | 14889 | if !have_ffmpeg() { |
| 14761 | - eprintln!( | 14890 | + eprintln!("SKIP {NAME}: no ffmpeg"); |
| 14762 | - "SKIP a_real_aomenc_intra_stream_with_deblocking_decodes_pixel_exact: no ffmpeg" | ||
| 14763 | - ); | ||
| 14764 | return; | 14891 | return; |
| 14765 | } | 14892 | } |
| 14766 | if !have_aomenc() { | 14893 | if !have_aomenc() { |
| 14767 | - eprintln!( | 14894 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); |
| 14768 | - "SKIP a_real_aomenc_intra_stream_with_deblocking_decodes_pixel_exact: no aomenc at {}", | ||
| 14769 | - aomenc_path().display() | ||
| 14770 | - ); | ||
| 14771 | return; | 14895 | return; |
| 14772 | } | 14896 | } |
| 14773 | let (width, height) = (64usize, 64usize); | 14897 | let (width, height) = (64usize, 64usize); |
| 14774 | - let source = gradients_source(42, width, height, "duration=0.04:rate=25"); | 14898 | + // Two seeds x four quantisers. |
| 14775 | - let y4m = Command::new("ffmpeg") | 14899 | + const CQS: [u32; 4] = [55, 45, 35, 63]; |
| 14776 | - .args(["-v", "error", "-f", "lavfi", "-i"]) | 14900 | + let mut refusals = Vec::new(); |
| 14777 | - .arg(&source) | 14901 | + let mut counted_exact = 0u32; |
| 14778 | - .args(["-pix_fmt", "yuv420p", "-f", "yuv4mpegpipe", "-"]) | 14902 | + let mut uncounted_exact = 0u32; |
| 14779 | - .stdin(Stdio::null()) | 14903 | + 'attempts: for round in 0..2u32 { |
| 14780 | - .stdout(Stdio::piped()) | 14904 | + for cq in CQS { |
| 14781 | - .stderr(Stdio::piped()) | 14905 | + let source = gradients_source(42 + round, width, height, "duration=0.04:rate=25"); |
| 14782 | - .output() | 14906 | + let y4m = Command::new("ffmpeg") |
| 14783 | - .expect("ffmpeg failed to run"); | 14907 | + .args(["-v", "error", "-f", "lavfi", "-i"]) |
| 14784 | - assert!( | 14908 | + .arg(&source) |
| 14785 | - y4m.status.success(), | 14909 | + .args(["-pix_fmt", "yuv420p", "-f", "yuv4mpegpipe", "-"]) |
| 14786 | - "ffmpeg fixture: {}", | 14910 | + .stdin(Stdio::null()) |
| 14787 | - String::from_utf8_lossy(&y4m.stderr) | 14911 | + .stdout(Stdio::piped()) |
| 14788 | - ); | 14912 | + .stderr(Stdio::piped()) |
| 14789 | - let out = run_with_stdin( | 14913 | + .output() |
| 14790 | - Command::new(aomenc_path()).args([ | 14914 | + .expect("ffmpeg failed to run"); |
| 14791 | - // lane-defon r1: explicit on-value (aomenc keeps the FIRST | 14915 | + assert!( |
| 14792 | - // occurrence, so overrides go before the base list). | 14916 | + y4m.status.success(), |
| 14793 | - "--loopfilter-control=1", | 14917 | + "{NAME}: ffmpeg fixture (seed {} cq {cq}): {}", |
| 14794 | - "--codec=av1", | 14918 | + 42 + round, |
| 14795 | - "--passes=1", | 14919 | + String::from_utf8_lossy(&y4m.stderr) |
| 14796 | - "--end-usage=q", | ||
| 14797 | - "--cq-level=55", | ||
| 14798 | - "--cpu-used=0", | ||
| 14799 | - "--enable-filter-intra=0", | ||
| 14800 | - "--enable-smooth-intra=0", | ||
| 14801 | - "--enable-paeth-intra=0", | ||
| 14802 | - "--enable-directional-intra=0", | ||
| 14803 | - "--enable-angle-delta=0", | ||
| 14804 | - "--enable-tx-size-search=0", | ||
| 14805 | - "--enable-cdef=0", | ||
| 14806 | - // Loop restoration is a named refusal (aomenc's RD picks | ||
| 14807 | - // Sgrproj on this kind of content) -- off in every recipe | ||
| 14808 | - // whose test targets a different surface. | ||
| 14809 | - "--enable-restoration=0", | ||
| 14810 | - "--max-partition-size=32", | ||
| 14811 | - "--enable-palette=0", | ||
| 14812 | - "--enable-intrabc=0", | ||
| 14813 | - "--enable-cfl-intra=0", | ||
| 14814 | - // use_ref_frame_mvs (temporal MV projection) is unimplemented in mvstack; | ||
| 14815 | - // leaving it on silently desyncs symbols on inter frames (grainfix lesson). | ||
| 14816 | - "--enable-ref-frame-mvs=0", | ||
| 14817 | - "--obu", | ||
| 14818 | - "-o", | ||
| 14819 | - "-", | ||
| 14820 | - "-", | ||
| 14821 | - ]), | ||
| 14822 | - &y4m.stdout, | ||
| 14823 | - ); | ||
| 14824 | - assert!( | ||
| 14825 | - out.status.success(), | ||
| 14826 | - "aomenc refused the fixture: {}", | ||
| 14827 | - String::from_utf8_lossy(&out.stderr) | ||
| 14828 | - ); | ||
| 14829 | - let stream = out.stdout; | ||
| 14830 | - let before = decode::deblock_hits(); | ||
| 14831 | - let frames = match decode_stream(&stream) { | ||
| 14832 | - Ok(frames) => frames, | ||
| 14833 | - Err(e) => { | ||
| 14834 | - eprintln!( | ||
| 14835 | - "SKIP a_real_aomenc_intra_stream_with_deblocking_decodes_pixel_exact: {e}" | ||
| 14836 | ); | 14920 | ); |
| 14837 | - return; | 14921 | + let cq_arg = format!("--cq-level={cq}"); |
| 14922 | + let out = run_with_stdin( | ||
| 14923 | + Command::new(aomenc_path()).args([ | ||
| 14924 | + // lane-defon r1: explicit on-value (aomenc keeps the FIRST | ||
| 14925 | + // occurrence, so overrides go before the base list). | ||
| 14926 | + "--loopfilter-control=1", | ||
| 14927 | + "--codec=av1", | ||
| 14928 | + "--passes=1", | ||
| 14929 | + "--end-usage=q", | ||
| 14930 | + &cq_arg, | ||
| 14931 | + "--cpu-used=0", | ||
| 14932 | + "--enable-filter-intra=0", | ||
| 14933 | + "--enable-smooth-intra=0", | ||
| 14934 | + "--enable-paeth-intra=0", | ||
| 14935 | + "--enable-directional-intra=0", | ||
| 14936 | + "--enable-angle-delta=0", | ||
| 14937 | + "--enable-tx-size-search=0", | ||
| 14938 | + "--enable-cdef=0", | ||
| 14939 | + // Loop restoration is a named refusal (aomenc's RD picks | ||
| 14940 | + // Sgrproj on this kind of content) -- off in every recipe | ||
| 14941 | + // whose test targets a different surface. | ||
| 14942 | + "--enable-restoration=0", | ||
| 14943 | + "--max-partition-size=32", | ||
| 14944 | + "--enable-palette=0", | ||
| 14945 | + "--enable-intrabc=0", | ||
| 14946 | + "--enable-cfl-intra=0", | ||
| 14947 | + // use_ref_frame_mvs (temporal MV projection) is unimplemented in mvstack; | ||
| 14948 | + // leaving it on silently desyncs symbols on inter frames (grainfix lesson). | ||
| 14949 | + "--enable-ref-frame-mvs=0", | ||
| 14950 | + "--obu", | ||
| 14951 | + "-o", | ||
| 14952 | + "-", | ||
| 14953 | + "-", | ||
| 14954 | + ]), | ||
| 14955 | + &y4m.stdout, | ||
| 14956 | + ); | ||
| 14957 | + assert!( | ||
| 14958 | + out.status.success(), | ||
| 14959 | + "{NAME}: aomenc refused the seed {} cq {cq} fixture: {}", | ||
| 14960 | + 42 + round, | ||
| 14961 | + String::from_utf8_lossy(&out.stderr) | ||
| 14962 | + ); | ||
| 14963 | + let stream = out.stdout; | ||
| 14964 | + let before = decode::deblock_hits(); | ||
| 14965 | + let frames = match decode_stream(&stream) { | ||
| 14966 | + Ok(frames) => frames, | ||
| 14967 | + Err(e) => { | ||
| 14968 | + refusals.push(format!("seed {} cq {cq}: {e}", 42 + round)); | ||
| 14969 | + continue; | ||
| 14970 | + } | ||
| 14971 | + }; | ||
| 14972 | + // A decode that succeeded is ALWAYS pixel-compared; the hit | ||
| 14973 | + // counter only decides whether the attempt counts as firing | ||
| 14974 | + // (class `counter-from-refused-stream`). | ||
| 14975 | + let counted = decode::deblock_hits() != before; | ||
| 14976 | + if counted { | ||
| 14977 | + counted_exact += 1; | ||
| 14978 | + } else { | ||
| 14979 | + uncounted_exact += 1; | ||
| 14980 | + } | ||
| 14981 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); | ||
| 14982 | + assert_eq!( | ||
| 14983 | + frames[0].y, | ||
| 14984 | + ffmpeg_frames[0].y, | ||
| 14985 | + "luma vs ffmpeg (seed {} cq {cq}, deblock fired: {counted})", | ||
| 14986 | + 42 + round | ||
| 14987 | + ); | ||
| 14988 | + assert_eq!( | ||
| 14989 | + frames[0].u, | ||
| 14990 | + ffmpeg_frames[0].u, | ||
| 14991 | + "U vs ffmpeg (seed {} cq {cq}, deblock fired: {counted})", | ||
| 14992 | + 42 + round | ||
| 14993 | + ); | ||
| 14994 | + assert_eq!( | ||
| 14995 | + frames[0].v, | ||
| 14996 | + ffmpeg_frames[0].v, | ||
| 14997 | + "V vs ffmpeg (seed {} cq {cq}, deblock fired: {counted})", | ||
| 14998 | + 42 + round | ||
| 14999 | + ); | ||
| 15000 | + if counted_exact >= 2 { | ||
| 15001 | + break 'attempts; | ||
| 15002 | + } | ||
| 14838 | } | 15003 | } |
| 14839 | - }; | 15004 | + } |
| 15005 | + gate_buckets(NAME, counted_exact, uncounted_exact, refusals.len()); | ||
| 14840 | assert!( | 15006 | assert!( |
| 14841 | - decode::deblock_hits() > before, | 15007 | + counted_exact > 0, |
| 14842 | - "no deblocking edge fired decoding this stream -- raise cq-level" | 15008 | + "{NAME}: none of {} attempts decoded a stream with a deblocking edge -- \ |
| 15009 | + apply_deblock is unproven (class gate-blind-to-feature):\n{}", | ||
| 15010 | + CQS.len() * 2, | ||
| 15011 | + refusals.join("\n") | ||
| 14843 | ); | 15012 | ); |
| 14844 | - let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); | ||
| 14845 | - assert_eq!(frames[0].y, ffmpeg_frames[0].y, "luma vs ffmpeg"); | ||
| 14846 | - assert_eq!(frames[0].u, ffmpeg_frames[0].u, "U vs ffmpeg"); | ||
| 14847 | - assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg"); | ||
| 14848 | } | 15013 | } |
| 14849 | 15014 | ||
| 14850 | /// As [`a_real_aomenc_intra_stream_with_deblocking_decodes_pixel_exact`], | 15015 | /// As [`a_real_aomenc_intra_stream_with_deblocking_decodes_pixel_exact`], |
| @@ -21631,133 +21796,174 @@ pub(crate) mod tests { | |||
| 21631 | ); | 21796 | ); |
| 21632 | } | 21797 | } |
| 21633 | 21798 | ||
| 21799 | + /// The inter-frame twin of | ||
| 21800 | + /// [`a_real_aomenc_intra_stream_with_deblocking_decodes_pixel_exact`]: | ||
| 21801 | + /// deblocking left *on* at a crf high enough that libaom picks a nonzero | ||
| 21802 | + /// level, CDEF off, so a pixel mismatch can only come from the loop | ||
| 21803 | + /// filter -- and over a real 4-frame INTER sequence, not one key frame. | ||
| 21804 | + /// | ||
| 21805 | + /// lane-av1skipfix: the attempt-loop shape. The sweep walks cq and seed, | ||
| 21806 | + /// REQUIRES at least one attempt to decode, and hard-asserts | ||
| 21807 | + /// `decode::deblock_hits` on a pixel-compared attempt; a decode error on | ||
| 21808 | + /// every attempt is a hard failure carrying the refusal texts, never a | ||
| 21809 | + /// printed SKIP (class `gate-skips-on-its-own-failure`). MEASURED | ||
| 21810 | + /// 2026-09-29 on `a21f3680`: cq 55/45/35/63 all decode 4 frames | ||
| 21811 | + /// pixel-exact with 208/224/160/208 deblock edges. | ||
| 21634 | #[test] | 21812 | #[test] |
| 21635 | fn a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact() { | 21813 | fn a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact() { |
| 21814 | + const NAME: &str = "a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact"; | ||
| 21815 | + let _gate_lock = lock_gate_counters(); | ||
| 21636 | if !have_ffmpeg() { | 21816 | if !have_ffmpeg() { |
| 21637 | - eprintln!( | 21817 | + eprintln!("SKIP {NAME}: no ffmpeg"); |
| 21638 | - "SKIP a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact: no ffmpeg" | ||
| 21639 | - ); | ||
| 21640 | return; | 21818 | return; |
| 21641 | } | 21819 | } |
| 21642 | if !have_aomenc() { | 21820 | if !have_aomenc() { |
| 21643 | - eprintln!( | 21821 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); |
| 21644 | - "SKIP a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact: no aomenc at {}", | ||
| 21645 | - aomenc_path().display() | ||
| 21646 | - ); | ||
| 21647 | return; | 21822 | return; |
| 21648 | } | 21823 | } |
| 21649 | let (width, height, frame_count) = (64usize, 64usize, 4usize); | 21824 | let (width, height, frame_count) = (64usize, 64usize, 4usize); |
| 21650 | - let source = gradients_source(42, width, height, "duration=0.16:rate=25"); | 21825 | + // Two seeds x four quantisers. |
| 21651 | - let y4m = Command::new("ffmpeg") | 21826 | + const CQS: [u32; 4] = [55, 45, 35, 63]; |
| 21652 | - .args(["-v", "error", "-f", "lavfi", "-i"]) | 21827 | + let mut refusals = Vec::new(); |
| 21653 | - .arg(&source) | 21828 | + let mut counted_exact = 0u32; |
| 21654 | - .args(["-pix_fmt", "yuv420p", "-f", "yuv4mpegpipe", "-"]) | 21829 | + let mut uncounted_exact = 0u32; |
| 21655 | - .stdin(Stdio::null()) | 21830 | + 'attempts: for round in 0..2u32 { |
| 21656 | - .stdout(Stdio::piped()) | 21831 | + for cq in CQS { |
| 21657 | - .stderr(Stdio::piped()) | 21832 | + let source = gradients_source(42 + round, width, height, "duration=0.16:rate=25"); |
| 21658 | - .output() | 21833 | + let y4m = Command::new("ffmpeg") |
| 21659 | - .expect("ffmpeg failed to run"); | 21834 | + .args(["-v", "error", "-f", "lavfi", "-i"]) |
| 21660 | - assert!( | 21835 | + .arg(&source) |
| 21661 | - y4m.status.success(), | 21836 | + .args(["-pix_fmt", "yuv420p", "-f", "yuv4mpegpipe", "-"]) |
| 21662 | - "ffmpeg fixture: {}", | 21837 | + .stdin(Stdio::null()) |
| 21663 | - String::from_utf8_lossy(&y4m.stderr) | 21838 | + .stdout(Stdio::piped()) |
| 21664 | - ); | 21839 | + .stderr(Stdio::piped()) |
| 21665 | - let out = run_with_stdin( | 21840 | + .output() |
| 21666 | - Command::new(aomenc_path()).args([ | 21841 | + .expect("ffmpeg failed to run"); |
| 21667 | - // lane-defon r1: explicit on-value (aomenc keeps the FIRST | 21842 | + assert!( |
| 21668 | - // occurrence, so overrides go before the base list). | 21843 | + y4m.status.success(), |
| 21669 | - "--loopfilter-control=1", | 21844 | + "{NAME}: ffmpeg fixture (seed {} cq {cq}): {}", |
| 21670 | - "--codec=av1", | 21845 | + 42 + round, |
| 21671 | - "--passes=1", | 21846 | + String::from_utf8_lossy(&y4m.stderr) |
| 21672 | - "--end-usage=q", | ||
| 21673 | - "--cq-level=55", | ||
| 21674 | - "--cpu-used=0", | ||
| 21675 | - "--lag-in-frames=0", | ||
| 21676 | - "--auto-alt-ref=0", | ||
| 21677 | - "--kf-max-dist=1000", | ||
| 21678 | - // Forces `primary_ref_frame = PRIMARY_REF_NONE` on every | ||
| 21679 | - // frame (spec 5.9.2): without it a real encoder's inter | ||
| 21680 | - // frame loads its initial CDF state from the previous | ||
| 21681 | - // frame's *adapted* tables (spec 7.20's `load_cdfs`), which | ||
| 21682 | - // this decoder never does -- it always starts each frame's | ||
| 21683 | - // `Cdfs` from the spec defaults (`decode.rs`'s | ||
| 21684 | - // `Cdfs::new(q_ctx)`, called fresh per frame in | ||
| 21685 | - // `decode_stream`). Without this flag the inter frame's | ||
| 21686 | - // very first symbol desyncs immediately (traced 2026-08-27: | ||
| 21687 | - // no coefficient trace at all before the tile's first | ||
| 21688 | - // partition read comes back an out-of-alphabet value). A | ||
| 21689 | - // real decoder needs cross-frame CDF forwarding to handle | ||
| 21690 | - // that stream; this fixture sidesteps it the same way a | ||
| 21691 | - // real broadcast/low-latency encode legitimately can. | ||
| 21692 | - "--error-resilient=1", | ||
| 21693 | - "--enable-rect-partitions=0", | ||
| 21694 | - "--enable-ab-partitions=0", | ||
| 21695 | - "--enable-1to4-partitions=0", | ||
| 21696 | - "--enable-filter-intra=0", | ||
| 21697 | - "--enable-smooth-intra=0", | ||
| 21698 | - "--enable-paeth-intra=0", | ||
| 21699 | - "--enable-directional-intra=0", | ||
| 21700 | - "--enable-angle-delta=0", | ||
| 21701 | - "--enable-tx-size-search=0", | ||
| 21702 | - "--enable-cdef=0", | ||
| 21703 | - // Loop restoration is a named refusal (aomenc's RD picks | ||
| 21704 | - // Sgrproj on this kind of content) -- off in every recipe | ||
| 21705 | - // whose test targets a different surface. | ||
| 21706 | - "--enable-restoration=0", | ||
| 21707 | - "--max-partition-size=32", | ||
| 21708 | - "--enable-palette=0", | ||
| 21709 | - "--enable-intrabc=0", | ||
| 21710 | - "--enable-cfl-intra=0", | ||
| 21711 | - // use_ref_frame_mvs (temporal MV projection) is unimplemented in mvstack; | ||
| 21712 | - // leaving it on silently desyncs symbols on inter frames (grainfix lesson). | ||
| 21713 | - "--enable-ref-frame-mvs=0", | ||
| 21714 | - "--obu", | ||
| 21715 | - "-o", | ||
| 21716 | - "-", | ||
| 21717 | - "-", | ||
| 21718 | - ]), | ||
| 21719 | - &y4m.stdout, | ||
| 21720 | - ); | ||
| 21721 | - assert!( | ||
| 21722 | - out.status.success(), | ||
| 21723 | - "aomenc refused the fixture: {}", | ||
| 21724 | - String::from_utf8_lossy(&out.stderr) | ||
| 21725 | - ); | ||
| 21726 | - let stream = out.stdout; | ||
| 21727 | - if let Ok(dump) = std::env::var("EC_AV1_GATE_DUMP") { | ||
| 21728 | - std::fs::write(dump, &stream).expect("dump stream"); | ||
| 21729 | - } | ||
| 21730 | - let before = decode::deblock_hits(); | ||
| 21731 | - let frames = match decode_stream(&stream) { | ||
| 21732 | - Ok(frames) => frames, | ||
| 21733 | - Err(e) => { | ||
| 21734 | - eprintln!( | ||
| 21735 | - "SKIP a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact: {e}" | ||
| 21736 | ); | 21847 | ); |
| 21737 | - return; | 21848 | + let cq_arg = format!("--cq-level={cq}"); |
| 21738 | - } | 21849 | + let out = run_with_stdin( |
| 21739 | - }; | 21850 | + Command::new(aomenc_path()).args([ |
| 21740 | - assert!( | 21851 | + // lane-defon r1: explicit on-value (aomenc keeps the FIRST |
| 21741 | - decode::deblock_hits() > before, | 21852 | + // occurrence, so overrides go before the base list). |
| 21742 | - "no deblocking edge fired decoding this sequence -- raise cq-level" | 21853 | + "--loopfilter-control=1", |
| 21743 | - ); | 21854 | + "--codec=av1", |
| 21744 | - let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); | 21855 | + "--passes=1", |
| 21745 | - assert_eq!(frames.len(), frame_count); | 21856 | + "--end-usage=q", |
| 21746 | - for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | 21857 | + &cq_arg, |
| 21747 | - // gradients' colors ignore its seed, so this gate encodes fresh | 21858 | + "--cpu-used=0", |
| 21748 | - // content every run -- a mismatch here may never reproduce. | 21859 | + "--lag-in-frames=0", |
| 21749 | - // Self-pin the stream before panicking so the failure is | 21860 | + "--auto-alt-ref=0", |
| 21750 | - // bisectable (replay: EC_AV1_PIN on scratch_isolate_pinned_mismatch). | 21861 | + "--kf-max-dist=1000", |
| 21751 | - let ok = got.y == want.y && got.u == want.u && got.v == want.v; | 21862 | + // Forces `primary_ref_frame = PRIMARY_REF_NONE` on every |
| 21752 | - if !ok { | 21863 | + // frame (spec 5.9.2): without it a real encoder's inter |
| 21753 | - let pin = std::env::temp_dir().join("ec-av1-deblocking-gate-fail.obu"); | 21864 | + // frame loads its initial CDF state from the previous |
| 21754 | - let _ = std::fs::write(&pin, &stream); | 21865 | + // frame's *adapted* tables (spec 7.20's `load_cdfs`), which |
| 21755 | - panic!( | 21866 | + // this decoder never does -- it always starts each frame's |
| 21756 | - "frame {i} mismatch vs ffmpeg -- stream pinned at {}", | 21867 | + // `Cdfs` from the spec defaults (`decode.rs`'s |
| 21757 | - pin.display() | 21868 | + // `Cdfs::new(q_ctx)`, called fresh per frame in |
| 21869 | + // `decode_stream`). Without this flag the inter frame's | ||
| 21870 | + // very first symbol desyncs immediately (traced 2026-08-27: | ||
| 21871 | + // no coefficient trace at all before the tile's first | ||
| 21872 | + // partition read comes back an out-of-alphabet value). A | ||
| 21873 | + // real decoder needs cross-frame CDF forwarding to handle | ||
| 21874 | + // that stream; this fixture sidesteps it the same way a | ||
| 21875 | + // real broadcast/low-latency encode legitimately can. | ||
| 21876 | + "--error-resilient=1", | ||
| 21877 | + "--enable-rect-partitions=0", | ||
| 21878 | + "--enable-ab-partitions=0", | ||
| 21879 | + "--enable-1to4-partitions=0", | ||
| 21880 | + "--enable-filter-intra=0", | ||
| 21881 | + "--enable-smooth-intra=0", | ||
| 21882 | + "--enable-paeth-intra=0", | ||
| 21883 | + "--enable-directional-intra=0", | ||
| 21884 | + "--enable-angle-delta=0", | ||
| 21885 | + "--enable-tx-size-search=0", | ||
| 21886 | + "--enable-cdef=0", | ||
| 21887 | + // Loop restoration is a named refusal (aomenc's RD picks | ||
| 21888 | + // Sgrproj on this kind of content) -- off in every recipe | ||
| 21889 | + // whose test targets a different surface. | ||
| 21890 | + "--enable-restoration=0", | ||
| 21891 | + "--max-partition-size=32", | ||
| 21892 | + "--enable-palette=0", | ||
| 21893 | + "--enable-intrabc=0", | ||
| 21894 | + "--enable-cfl-intra=0", | ||
| 21895 | + // use_ref_frame_mvs (temporal MV projection) is unimplemented in mvstack; | ||
| 21896 | + // leaving it on silently desyncs symbols on inter frames (grainfix lesson). | ||
| 21897 | + "--enable-ref-frame-mvs=0", | ||
| 21898 | + "--obu", | ||
| 21899 | + "-o", | ||
| 21900 | + "-", | ||
| 21901 | + "-", | ||
| 21902 | + ]), | ||
| 21903 | + &y4m.stdout, | ||
| 21904 | + ); | ||
| 21905 | + assert!( | ||
| 21906 | + out.status.success(), | ||
| 21907 | + "{NAME}: aomenc refused the seed {} cq {cq} fixture: {}", | ||
| 21908 | + 42 + round, | ||
| 21909 | + String::from_utf8_lossy(&out.stderr) | ||
| 21758 | ); | 21910 | ); |
| 21911 | + let stream = out.stdout; | ||
| 21912 | + if let Ok(dump) = std::env::var("EC_AV1_GATE_DUMP") { | ||
| 21913 | + std::fs::write(dump, &stream).expect("dump stream"); | ||
| 21914 | + } | ||
| 21915 | + let before = decode::deblock_hits(); | ||
| 21916 | + let frames = match decode_stream(&stream) { | ||
| 21917 | + Ok(frames) => frames, | ||
| 21918 | + Err(e) => { | ||
| 21919 | + refusals.push(format!("seed {} cq {cq}: {e}", 42 + round)); | ||
| 21920 | + continue; | ||
| 21921 | + } | ||
| 21922 | + }; | ||
| 21923 | + // A decode that succeeded is ALWAYS pixel-compared; the hit | ||
| 21924 | + // counter only decides whether the attempt counts as firing | ||
| 21925 | + // (class `counter-from-refused-stream`). | ||
| 21926 | + let counted = decode::deblock_hits() != before; | ||
| 21927 | + if counted { | ||
| 21928 | + counted_exact += 1; | ||
| 21929 | + } else { | ||
| 21930 | + uncounted_exact += 1; | ||
| 21931 | + } | ||
| 21932 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); | ||
| 21933 | + assert_eq!(frames.len(), frame_count); | ||
| 21934 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 21935 | + // gradients' colors ignore its seed, so this gate encodes fresh | ||
| 21936 | + // content every run -- a mismatch here may never reproduce. | ||
| 21937 | + // Self-pin the stream before panicking so the failure is | ||
| 21938 | + // bisectable (replay: EC_AV1_PIN on scratch_isolate_pinned_mismatch). | ||
| 21939 | + let ok = got.y == want.y && got.u == want.u && got.v == want.v; | ||
| 21940 | + if !ok { | ||
| 21941 | + let pin = std::env::temp_dir().join(format!( | ||
| 21942 | + "ec-av1-deblocking-gate-fail-s{}-cq{cq}.obu", | ||
| 21943 | + 42 + round | ||
| 21944 | + )); | ||
| 21945 | + let _ = std::fs::write(&pin, &stream); | ||
| 21946 | + panic!( | ||
| 21947 | + "frame {i} mismatch vs ffmpeg (seed {} cq {cq}, deblock fired: \ | ||
| 21948 | + {counted}) -- stream pinned at {}", | ||
| 21949 | + 42 + round, | ||
| 21950 | + pin.display() | ||
| 21951 | + ); | ||
| 21952 | + } | ||
| 21953 | + } | ||
| 21954 | + if counted_exact >= 2 { | ||
| 21955 | + break 'attempts; | ||
| 21956 | + } | ||
| 21759 | } | 21957 | } |
| 21760 | } | 21958 | } |
| 21959 | + gate_buckets(NAME, counted_exact, uncounted_exact, refusals.len()); | ||
| 21960 | + assert!( | ||
| 21961 | + counted_exact > 0, | ||
| 21962 | + "{NAME}: none of {} attempts decoded a sequence with a deblocking edge -- \ | ||
| 21963 | + apply_deblock is unproven (class gate-blind-to-feature):\n{}", | ||
| 21964 | + CQS.len() * 2, | ||
| 21965 | + refusals.join("\n") | ||
| 21966 | + ); | ||
| 21761 | } | 21967 | } |
| 21762 | 21968 | ||
| 21763 | /// The decisive cross-frame CDF forwarding test: identical to | 21969 | /// The decisive cross-frame CDF forwarding test: identical to |