Merge lane/av1oracledepth: depth-generic 4:4:4 oracle helper
Browse files at this commit2 changed files +468 -43
- crates/ec-av1/src/stream.rs +351 -43
- lanes/av1oracledepth.report.md +117 -0
crates/ec-av1/src/stream.rsmodified+351 -43
| @@ -3410,17 +3410,17 @@ pub(crate) mod tests { | ||
| 3410 | 3410 | /// lane-av1422lift: `decode_stream` no longer refuses 4:2:2 at the sequence |
| 3411 | 3411 | /// header, so the OK arm is the live one -- the gate decodes the pin and |
| 3412 | 3412 | /// asserts 17 decode-order frames byte-exact against aomdec with |
| 3413 | - /// `palette_422_unit_window_hits()` fired. The `Err` arm below is the | |
| 3414 | - /// stale half: it still compiles in the old refusal string (`REFUSAL`, | |
| 3415 | - /// `"a chroma format of 4:2:2"`) and a counter-stays-put assertion. That is | |
| 3416 | - /// code, not a comment, and this prose sweep deliberately leaves it alone. | |
| 3413 | + /// `palette_422_unit_window_hits()` fired. lane-av1oracledepth: the stale | |
| 3414 | + /// `Err` arm (it matched the pre-lift refusal string | |
| 3415 | + /// `"a chroma format of 4:2:2"` the decoder no longer returns, and could | |
| 3416 | + /// have swallowed a future decode error as green) is deleted; a refusal | |
| 3417 | + /// now fails this gate loudly. | |
| 3417 | 3418 | #[test] |
| 3418 | 3419 | fn the_pinned_422_palette_intra_in_inter_cell_window_is_byte_exact() { |
| 3419 | 3420 | const NAME: &str = "the_pinned_422_palette_intra_in_inter_cell_window_is_byte_exact"; |
| 3420 | 3421 | const FILE: &str = "422_palette_intra_in_inter_384x240_17f.obu"; |
| 3421 | 3422 | const BYTES: usize = 19344; |
| 3422 | 3423 | const FP: u64 = 0x923ccabfcb933e90; |
| 3423 | - const REFUSAL: &str = "a chroma format of 4:2:2"; | |
| 3424 | 3424 | let _gate_lock = lock_gate_counters(); |
| 3425 | 3425 | let data = std::fs::read(crate_pin(FILE)).unwrap_or_else(|e| { |
| 3426 | 3426 | panic!("{NAME}: the committed pin {FILE} is missing ({e}) -- a failure, not a skip") |
| @@ -3428,27 +3428,21 @@ pub(crate) mod tests { | ||
| 3428 | 3428 | assert_eq!(data.len(), BYTES, "{NAME}: {FILE} size drifted"); |
| 3429 | 3429 | assert_eq!(fnv1a64(&data), FP, "{NAME}: {FILE} bytes drifted"); |
| 3430 | 3430 | let before = crate::decode::palette_422_unit_window_hits(); |
| 3431 | + // lane-av1oracledepth: the OK arm is MEASURED to be the live one (the | |
| 3432 | + // pinned bytes decode, 17 decode-order frames byte-exact vs aomdec, | |
| 3433 | + // 16 windowed units) and the old `Err` arm matching the pre-lift | |
| 3434 | + // refusal string "a chroma format of 4:2:2" is deleted: committed | |
| 3435 | + // code no longer returns that string, so the arm could only ever | |
| 3436 | + // swallow a FUTURE decode error that happened to contain it and read | |
| 3437 | + // green off a stream that decoded nothing. A refusal today now fails | |
| 3438 | + // this gate loudly, as it should. | |
| 3431 | 3439 | match decode_stream(&data) { |
| 3432 | 3440 | Err(e) => { |
| 3433 | - let err = e.to_string(); | |
| 3434 | - assert!( | |
| 3435 | - err.contains(REFUSAL), | |
| 3436 | - "{NAME}: {FILE} neither refused by name nor decoded to the 17 \ | |
| 3437 | - decode-order frames this gate claims -- if 4:2:2 has been lifted the \ | |
| 3438 | - ERROR arm is stale, got: {err}" | |
| 3439 | - ); | |
| 3440 | - assert_eq!( | |
| 3441 | - crate::decode::palette_422_unit_window_hits(), | |
| 3442 | - before, | |
| 3443 | - "{NAME}: a refusal cannot reach the palette arm, so its counter moved \ | |
| 3444 | - from {before} -- this is not the refusal this gate models" | |
| 3445 | - ); | |
| 3446 | - eprintln!( | |
| 3447 | - "{NAME}: {FILE} refuses 4:2:2 at the sequence header (the standing \ | |
| 3448 | - family rule), so the per-unit palette window could not be exercised \ | |
| 3449 | - here; the exactness and fired-counter claims are measured on a local \ | |
| 3450 | - patch-run-restore build -- see lanes/av1422tailskip.report.md" | |
| 3451 | - ); | |
| 3441 | + panic!( | |
| 3442 | + "{NAME}: {FILE} was refused by the current decoder: {e}. 4:2:2 is a \ | |
| 3443 | + DECODED format; a refusal here is a regression, not the old sequence-\ | |
| 3444 | + header gate" | |
| 3445 | + ) | |
| 3452 | 3446 | } |
| 3453 | 3447 | Ok(_) => { |
| 3454 | 3448 | let windows = crate::decode::palette_422_unit_window_hits() - before; |
| @@ -7224,6 +7218,251 @@ pub(crate) mod tests { | ||
| 7224 | 7218 | } |
| 7225 | 7219 | } |
| 7226 | 7220 | |
| 7221 | + /// lane-av1oracledepth: the 8-bit `ffmpeg_decode_sequence_444` must REFUSE | |
| 7222 | + /// a real 10-bit 4:4:4 pin instead of letting ffmpeg convert it down to | |
| 7223 | + /// `yuv444p`. ffmpeg does not fail on the depth mismatch -- it re-scales | |
| 7224 | + /// -- so a gate built on the 8-bit helper would compare ffmpeg's rescaled | |
| 7225 | + /// planes against our 10-bit decode and could read exact. The message | |
| 7226 | + /// must name the real depth AND the depth-generic sibling | |
| 7227 | + /// `ffmpeg_decode_sequence_444_depth`, so the caller has the fix in front | |
| 7228 | + /// of it. | |
| 7229 | + /// | |
| 7230 | + /// Needs no ffmpeg at all: the guard runs before the spawn, so a host | |
| 7231 | + /// without ffmpeg still proves the refusal. | |
| 7232 | + #[test] | |
| 7233 | + fn the_8bit_444_oracle_helper_refuses_a_10bit_444_pin() { | |
| 7234 | + const NAME: &str = "the_8bit_444_oracle_helper_refuses_a_10bit_444_pin"; | |
| 7235 | + let _gate_lock = lock_gate_counters(); | |
| 7236 | + let path = crate_pin("444_lossy_palette_chroma_352x242_10b.obu"); | |
| 7237 | + let stream = read_pin(&path, 24875, 0x7fda_dbb4_3bbf_9af3, NAME); | |
| 7238 | + assert_eq!( | |
| 7239 | + stream_bit_depth(&stream, NAME), | |
| 7240 | + 10, | |
| 7241 | + "{NAME}: the pin must really be 10-bit, or this proves nothing" | |
| 7242 | + ); | |
| 7243 | + assert_eq!( | |
| 7244 | + stream_subsampling(&stream, NAME), | |
| 7245 | + (0, 0), | |
| 7246 | + "{NAME}: the pin must really be 4:4:4 (0,0), or this proves nothing" | |
| 7247 | + ); | |
| 7248 | + let msg = panic_message(|| { | |
| 7249 | + ffmpeg_decode_sequence_444(&stream, 352, 242, 1); | |
| 7250 | + }) | |
| 7251 | + .unwrap_or_else(|| { | |
| 7252 | + panic!( | |
| 7253 | + "{NAME}: ffmpeg_decode_sequence_444 ACCEPTED a 10-bit 4:4:4 stream. ffmpeg \ | |
| 7254 | + converted it to yuv444p and the helper returned a green-looking comparison" | |
| 7255 | + ) | |
| 7256 | + }); | |
| 7257 | + for needle in ["not 8-bit", "ffmpeg_decode_sequence_444_depth"] { | |
| 7258 | + assert!( | |
| 7259 | + msg.contains(needle), | |
| 7260 | + "{NAME}: the refusal must name {needle:?}; it said: {msg}" | |
| 7261 | + ); | |
| 7262 | + } | |
| 7263 | + eprintln!("{NAME}: refused -> {msg}"); | |
| 7264 | + } | |
| 7265 | + | |
| 7266 | + /// lane-av1oracledepth: the depth-generic 4:4:4 oracle comparator, armed | |
| 7267 | + /// on the same pinned 10-bit 4:4:4 cell | |
| 7268 | + /// `a_444_lossy_palette_chroma_unit_window_is_byte_exact_at_352x242_10bit` | |
| 7269 | + /// gates (fixture sha256 | |
| 7270 | + /// `84df2f37cc7982f9a572443d85dfcc13bf366a64f3fb567391dcd5acd58a0ad2`): | |
| 7271 | + /// every plane of every SHOWN frame must come back byte-exact against | |
| 7272 | + /// ffmpeg's `yuv444p10le` rawvideo of the same bytes, with the depth read | |
| 7273 | + /// from the stream's own sequence header, never assumed. | |
| 7274 | + /// | |
| 7275 | + /// The flip control is the crate's own comparator-liveness shape (the | |
| 7276 | + /// same one | |
| 7277 | + /// [`every_ffmpeg_comparator_reds_on_a_one_sample_wrong_ffmpeg`] runs for | |
| 7278 | + /// the other helpers): with a thread-local ffmpeg shim that rotates ONE | |
| 7279 | + /// byte of the oracle's own rawvideo stdout, the compare must move from | |
| 7280 | + /// 0 to EXACTLY 1 differing sample in the tampered plane and stay at 0 in | |
| 7281 | + /// the other two -- a comparator that cannot see a one-sample difference | |
| 7282 | + /// would make every "byte-exact" claim above vacuous. | |
| 7283 | + #[test] | |
| 7284 | + fn the_444_depth_helper_is_byte_exact_on_a_pinned_10bit_444_cell() { | |
| 7285 | + const NAME: &str = "the_444_depth_helper_is_byte_exact_on_a_pinned_10bit_444_cell"; | |
| 7286 | + if !have_ffmpeg() { | |
| 7287 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 7288 | + return; | |
| 7289 | + } | |
| 7290 | + let _gate_lock = lock_gate_counters(); | |
| 7291 | + let path = crate_pin("444_lossy_palette_chroma_352x242_10b.obu"); | |
| 7292 | + let stream = read_pin(&path, 24875, 0x7fda_dbb4_3bbf_9af3, NAME); | |
| 7293 | + // The fixture is 16 SHOWN frames; ffmpeg's rawvideo muxer emits shown | |
| 7294 | + // frames only, and so does decode_stream's return. | |
| 7295 | + const W: usize = 352; | |
| 7296 | + const H: usize = 242; | |
| 7297 | + const FRAMES: usize = 16; | |
| 7298 | + assert_eq!(stream_bit_depth(&stream, NAME), 10, "{NAME}: pin depth"); | |
| 7299 | + let ours = decode_stream(&stream) | |
| 7300 | + .unwrap_or_else(|e| panic!("{NAME}: the pinned 10-bit 4:4:4 cell was refused: {e}")); | |
| 7301 | + assert_eq!(ours.len(), FRAMES, "{NAME}: decoded frame count"); | |
| 7302 | + let theirs = ffmpeg_decode_sequence_444_depth(&stream, W, H, FRAMES, 10, "yuv444p10le"); | |
| 7303 | + for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { | |
| 7304 | + for (plane, x, y) in [("Y", &a.y, &b.y), ("U", &a.u, &b.u), ("V", &a.v, &b.v)] { | |
| 7305 | + if let Some(at) = x.iter().zip(y).position(|(p, q)| p != q) { | |
| 7306 | + panic!( | |
| 7307 | + "{NAME}: {plane} differs from ffmpeg's yuv444p10le at frame {i} sample \ | |
| 7308 | + {at} (ours {} vs {}); {n} of {m} samples differ", | |
| 7309 | + x[at], | |
| 7310 | + y[at], | |
| 7311 | + n = x.iter().zip(y).filter(|(p, q)| p != q).count(), | |
| 7312 | + m = x.len() | |
| 7313 | + ); | |
| 7314 | + } | |
| 7315 | + } | |
| 7316 | + } | |
| 7317 | + eprintln!( | |
| 7318 | + "{NAME}: {FRAMES} shown frames byte-exact vs ffmpeg yuv444p10le on the pinned \ | |
| 7319 | + 10-bit 4:4:4 cell" | |
| 7320 | + ); | |
| 7321 | + | |
| 7322 | + // ---- the flip control: one wrong oracle sample must move the count | |
| 7323 | + // 0 -> 1 in exactly the tampered plane ------------------------- | |
| 7324 | + let dir = std::env::temp_dir().join(format!("ec-av1-{NAME}-{}", std::process::id())); | |
| 7325 | + let _ = std::fs::remove_dir_all(&dir); | |
| 7326 | + std::fs::create_dir_all(&dir).expect("scratch dir"); | |
| 7327 | + let real = if let Some(p) = std::env::var_os("EC_AV1_FFMPEG") { | |
| 7328 | + std::path::PathBuf::from(p) | |
| 7329 | + } else { | |
| 7330 | + let found = Command::new("ffmpeg") | |
| 7331 | + .arg("-version") | |
| 7332 | + .stdout(Stdio::null()) | |
| 7333 | + .stderr(Stdio::null()) | |
| 7334 | + .status() | |
| 7335 | + .is_ok_and(|s| s.success()); | |
| 7336 | + assert!(found, "{NAME}: no working ffmpeg on PATH to wrap"); | |
| 7337 | + let path_env = std::env::var_os("PATH").unwrap_or_default(); | |
| 7338 | + std::env::split_paths(&path_env) | |
| 7339 | + .map(|d| d.join("ffmpeg")) | |
| 7340 | + .find(|p| p.is_file()) | |
| 7341 | + .expect("{NAME}: ffmpeg is on PATH but not resolvable to a file") | |
| 7342 | + }; | |
| 7343 | + std::fs::write(dir.join("real-ffmpeg"), real.as_os_str().as_encoded_bytes()) | |
| 7344 | + .expect("recording the real ffmpeg's path for the shim"); | |
| 7345 | + let script = r#"#!/bin/sh | |
| 7346 | +REAL=$(cat "$(dirname "$0")/real-ffmpeg") | |
| 7347 | +OUT=$(mktemp) | |
| 7348 | +"$REAL" "$@" > "$OUT" || exit $? | |
| 7349 | +while read -r o; do | |
| 7350 | + [ -n "$o" ] || continue | |
| 7351 | + b=$(od -An -tu1 -j "$o" -N 1 "$OUT" 2>/dev/null | tr -d ' \n') | |
| 7352 | + [ -n "$b" ] || continue | |
| 7353 | + esc=$(printf '\\%03o' $(( (b + 128) % 256 ))) | |
| 7354 | + printf "$esc" | dd of="$OUT" bs=1 seek="$o" count=1 conv=notrunc 2>/dev/null | |
| 7355 | +done < "$(dirname "$0")/offsets" | |
| 7356 | +cat "$OUT" | |
| 7357 | +rm -f "$OUT" | |
| 7358 | +exit 0 | |
| 7359 | +"#; | |
| 7360 | + let shim = dir.join("one-sample-wrong-ffmpeg.sh"); | |
| 7361 | + std::fs::write(&shim, script).expect("writing the ffmpeg shim"); | |
| 7362 | + #[cfg(unix)] | |
| 7363 | + { | |
| 7364 | + use std::os::unix::fs::PermissionsExt; | |
| 7365 | + std::fs::set_permissions(&shim, std::fs::Permissions::from_mode(0o755)) | |
| 7366 | + .expect("the ffmpeg shim must be executable"); | |
| 7367 | + } | |
| 7368 | + let set_offsets = |bytes: &[usize]| { | |
| 7369 | + let body: String = bytes | |
| 7370 | + .iter() | |
| 7371 | + .map(|b| format!("{b}\n")) | |
| 7372 | + .collect::<Vec<_>>() | |
| 7373 | + .concat(); | |
| 7374 | + std::fs::write(dir.join("offsets"), body).expect("writing the offsets file"); | |
| 7375 | + }; | |
| 7376 | + let count = |theirs_t: &[Pic]| -> [usize; 3] { | |
| 7377 | + let mut wrong = [0usize; 3]; | |
| 7378 | + for (a, b) in ours.iter().zip(theirs_t) { | |
| 7379 | + for (plane, (x, y)) in | |
| 7380 | + [(0usize, (&a.y, &b.y)), (1, (&a.u, &b.u)), (2, (&a.v, &b.v))] | |
| 7381 | + { | |
| 7382 | + wrong[plane] += x.iter().zip(y).filter(|(p, q)| p != q).count(); | |
| 7383 | + } | |
| 7384 | + } | |
| 7385 | + wrong | |
| 7386 | + }; | |
| 7387 | + // Frame bytes are 3 planes x W*H samples x 2 bytes (10-bit container). | |
| 7388 | + let plane_bytes = W * H * 2; | |
| 7389 | + let mut blind: Vec<String> = Vec::new(); | |
| 7390 | + set_ffmpeg_path(Some(shim.clone())); | |
| 7391 | + for (plane, base) in [("Y", 0usize), ("U", plane_bytes), ("V", 2 * plane_bytes)] { | |
| 7392 | + // Byte 2000 of the named plane: sample 1000, still frame 0 on | |
| 7393 | + // every plane at this geometry. | |
| 7394 | + set_offsets(&[base + 2000]); | |
| 7395 | + let theirs_t = | |
| 7396 | + ffmpeg_decode_sequence_444_depth(&stream, W, H, FRAMES, 10, "yuv444p10le"); | |
| 7397 | + let got = count(&theirs_t); | |
| 7398 | + let mut expected = [0usize, 0, 0]; | |
| 7399 | + expected[match plane { | |
| 7400 | + "Y" => 0, | |
| 7401 | + "U" => 1, | |
| 7402 | + _ => 2, | |
| 7403 | + }] = 1; | |
| 7404 | + if got != expected { | |
| 7405 | + blind.push(format!( | |
| 7406 | + "{plane} arm: counted {got:?}, expected {expected:?} (exactly the one \ | |
| 7407 | + tampered sample)" | |
| 7408 | + )); | |
| 7409 | + } | |
| 7410 | + } | |
| 7411 | + set_ffmpeg_path(None); | |
| 7412 | + let _ = std::fs::remove_dir_all(&dir); | |
| 7413 | + assert!( | |
| 7414 | + blind.is_empty(), | |
| 7415 | + "{NAME}: {} of 3 flip arms stayed GREEN against an ffmpeg that is wrong by exactly \ | |
| 7416 | + one sample -- {blind:#?} -- the comparator cannot see a difference, so its \ | |
| 7417 | + byte-exact verdict proves nothing (class comparator-that-never-reads-the-oracle)", | |
| 7418 | + blind.len() | |
| 7419 | + ); | |
| 7420 | + eprintln!( | |
| 7421 | + "{NAME}: flip control bites on Y, U and V separately (0 -> 1 per tampered plane)" | |
| 7422 | + ); | |
| 7423 | + } | |
| 7424 | + | |
| 7425 | + /// lane-av1oracledepth: `ffmpeg_decode_sequence_10bit` must REFUSE a | |
| 7426 | + /// wrong-depth stream by the stream's OWN sequence header, the way the | |
| 7427 | + /// 12-bit gates read `assert_12bit_sequence_header`. An 8-bit 4:2:0 | |
| 7428 | + /// stream handed to the 10-bit helper is the wrong-depth shape: ffmpeg | |
| 7429 | + /// converts it to `yuv420p10le` and sizes no plane differently, so | |
| 7430 | + /// without the depth assert a gate could compare a converted 8-bit | |
| 7431 | + /// reference against our 10-bit decode and read exact. | |
| 7432 | + #[test] | |
| 7433 | + fn the_10bit_oracle_helper_refuses_a_wrong_depth_stream() { | |
| 7434 | + const NAME: &str = "the_10bit_oracle_helper_refuses_a_wrong_depth_stream"; | |
| 7435 | + let _gate_lock = lock_gate_counters(); | |
| 7436 | + let path = crate_pin("mix176_offtile_chroma_clip.obu"); | |
| 7437 | + let stream = read_pin(&path, 4581, 0x5e31be5efc9c3c1d, NAME); | |
| 7438 | + assert_eq!( | |
| 7439 | + stream_bit_depth(&stream, NAME), | |
| 7440 | + 8, | |
| 7441 | + "{NAME}: the control pin must really be 8-bit, or this proves nothing" | |
| 7442 | + ); | |
| 7443 | + assert_eq!( | |
| 7444 | + stream_subsampling(&stream, NAME), | |
| 7445 | + (1, 1), | |
| 7446 | + "{NAME}: the control pin must really be 4:2:0, or the refusal below could be the \ | |
| 7447 | + shape guard instead of the depth guard" | |
| 7448 | + ); | |
| 7449 | + let msg = panic_message(|| { | |
| 7450 | + ffmpeg_decode_sequence_10bit(&stream, 176, 144, 1); | |
| 7451 | + }) | |
| 7452 | + .unwrap_or_else(|| { | |
| 7453 | + panic!( | |
| 7454 | + "{NAME}: ffmpeg_decode_sequence_10bit ACCEPTED an 8-bit stream -- ffmpeg \ | |
| 7455 | + converted it to yuv420p10le and the helper returned a comparison that could \ | |
| 7456 | + pass green" | |
| 7457 | + ) | |
| 7458 | + }); | |
| 7459 | + assert!( | |
| 7460 | + msg.contains("not 10-bit"), | |
| 7461 | + "{NAME}: the refusal must name the depth guard (\"not 10-bit\"); it said: {msg}" | |
| 7462 | + ); | |
| 7463 | + eprintln!("{NAME}: refused -> {msg}"); | |
| 7464 | + } | |
| 7465 | + | |
| 7227 | 7466 | /// Packs decoded planes the way `aomdec --rawvideo` writes them for |
| 7228 | 7467 | /// `bit_depth`: 1 byte per sample at 8-bit, 2 bytes little-endian at |
| 7229 | 7468 | /// 10/12-bit. Plane order is Y, U, V at the frame's own subsampled |
| @@ -7614,6 +7853,14 @@ pub(crate) mod tests { | ||
| 7614 | 7853 | /// stream's real 10-bit depth (ffmpeg's rawvideo muxer never packs to the |
| 7615 | 7854 | /// bit depth). The 8-bit helper above stays untouched -- every existing |
| 7616 | 7855 | /// gate depends on it. |
| 7856 | + /// | |
| 7857 | + /// lane-av1oracledepth: the stream's OWN sequence header must parse | |
| 7858 | + /// 10-bit, the same way `assert_12bit_sequence_header` covers the 12-bit | |
| 7859 | + /// gates. A wrong-depth stream handed here would otherwise CONVERT | |
| 7860 | + /// silently -- ffmpeg re-scales 8-bit samples into the 16-bit container | |
| 7861 | + /// and sizes no plane differently -- so a gate could compare ffmpeg's | |
| 7862 | + /// rescaled 8-bit planes against our 10-bit decode and read exact (class | |
| 7863 | + /// `helper-assumes-the-shape-the-gate-name-implies`, the depth axis). | |
| 7617 | 7864 | fn ffmpeg_decode_sequence_10bit( |
| 7618 | 7865 | stream: &[u8], |
| 7619 | 7866 | width: usize, |
| @@ -7623,7 +7870,15 @@ pub(crate) mod tests { | ||
| 7623 | 7870 | assert_420_oracle_stream( |
| 7624 | 7871 | stream, |
| 7625 | 7872 | "ffmpeg_decode_sequence_10bit", |
| 7626 | - "ffmpeg_decode_sequence_422_depth(.., 10, \"yuv422p10le\") (4:2:2); ffmpeg_decode_sequence_444 is 8-bit only", | |
| 7873 | + "ffmpeg_decode_sequence_422_depth(.., 10, \"yuv422p10le\") (4:2:2); \ | |
| 7874 | + ffmpeg_decode_sequence_444_depth(.., 10, \"yuv444p10le\") (4:4:4)", | |
| 7875 | + ); | |
| 7876 | + assert_eq!( | |
| 7877 | + stream_bit_depth(stream, "ffmpeg_decode_sequence_10bit"), | |
| 7878 | + 10, | |
| 7879 | + "ffmpeg_decode_sequence_10bit REFUSED a stream whose own sequence header is not \ | |
| 7880 | + 10-bit -- ffmpeg converts it to yuv420p10le instead of failing, and the comparison \ | |
| 7881 | + would read a converted reference" | |
| 7627 | 7882 | ); |
| 7628 | 7883 | let out = run_with_stdin( |
| 7629 | 7884 | Command::new(ffmpeg_path()).args([ |
| @@ -9116,25 +9371,75 @@ pub(crate) mod tests { | ||
| 9116 | 9371 | height: usize, |
| 9117 | 9372 | frames: usize, |
| 9118 | 9373 | ) -> Vec<Pic> { |
| 9374 | + ffmpeg_decode_sequence_444_depth(stream, width, height, frames, 8, "yuv444p") | |
| 9375 | + } | |
| 9376 | + | |
| 9377 | + /// lane-av1oracledepth: the depth-generic 4:4:4 oracle comparator -- the | |
| 9378 | + /// [`ffmpeg_decode_sequence_422_depth`] twin for full-resolution chroma. | |
| 9379 | + /// `yuv444p`, `yuv444p10le` or `yuv444p12le`, with the container width | |
| 9380 | + /// taken from `depth` itself (8 -> one byte per sample; 10/12 -> a 16-bit | |
| 9381 | + /// LE container on BOTH sides, so ours and ffmpeg's are directly | |
| 9382 | + /// comparable sample for sample and nothing narrows). Until this helper | |
| 9383 | + /// existed a 10/12-bit 4:4:4 gate had to fall back to the 8-bit | |
| 9384 | + /// `ffmpeg_decode_sequence_444`, which ffmpeg converts at `yuv444p` | |
| 9385 | + /// instead of refusing, or to a raw hand-rolled spawn (class | |
| 9386 | + /// `helper-assumes-the-shape-the-gate-name-implies`, the depth axis). | |
| 9387 | + /// | |
| 9388 | + /// Refused by SHAPE read from the stream's own sequence header, like its | |
| 9389 | + /// 4:2:0 siblings: `(0,0)` only, so a 4:2:2 or 4:2:0 stream handed here | |
| 9390 | + /// cannot have ffmpeg silently convert it. | |
| 9391 | + fn ffmpeg_decode_sequence_444_depth( | |
| 9392 | + stream: &[u8], | |
| 9393 | + width: usize, | |
| 9394 | + height: usize, | |
| 9395 | + frames: usize, | |
| 9396 | + depth: u8, | |
| 9397 | + pix_fmt: &str, | |
| 9398 | + ) -> Vec<Pic> { | |
| 9399 | + assert!( | |
| 9400 | + matches!(depth, 8 | 10 | 12), | |
| 9401 | + "lane-av1oracledepth: ffmpeg_decode_sequence_444_depth takes 8, 10 or 12, got {depth}" | |
| 9402 | + ); | |
| 9403 | + let (sx, sy) = stream_subsampling(stream, "ffmpeg_decode_sequence_444_depth"); | |
| 9404 | + assert!( | |
| 9405 | + (sx, sy) == (0, 0), | |
| 9406 | + "ffmpeg_decode_sequence_444_depth REFUSED a ({sx},{sy}) stream: this helper asks \ | |
| 9407 | + ffmpeg for a 4:4:4 pix_fmt, which CONVERTS the stream's real {} chroma instead of \ | |
| 9408 | + failing, then slices full-resolution planes from converted bytes. \ | |
| 9409 | + ffmpeg_decode_sequence_422_depth handles (1,0); ffmpeg_decode_sequence handles \ | |
| 9410 | + (1,1).", | |
| 9411 | + chroma_shape(sx, sy) | |
| 9412 | + ); | |
| 9413 | + assert_eq!( | |
| 9414 | + stream_bit_depth(stream, "ffmpeg_decode_sequence_444_depth"), | |
| 9415 | + depth, | |
| 9416 | + "ffmpeg_decode_sequence_444_depth REFUSED a stream whose own sequence header is \ | |
| 9417 | + not {depth}-bit -- ffmpeg would convert it to {pix_fmt} instead of failing" | |
| 9418 | + ); | |
| 9119 | 9419 | let out = run_with_stdin( |
| 9120 | - Command::new("ffmpeg").args([ | |
| 9121 | - "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv444p", "-", | |
| 9420 | + Command::new(ffmpeg_path()).args([ | |
| 9421 | + "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", pix_fmt, "-", | |
| 9122 | 9422 | ]), |
| 9123 | 9423 | stream, |
| 9124 | 9424 | ); |
| 9125 | 9425 | assert!( |
| 9126 | 9426 | out.status.success(), |
| 9127 | - "ffmpeg refused the 4:4:4 stream: {}", | |
| 9427 | + "ffmpeg refused the 4:4:4 stream ({pix_fmt}): {}", | |
| 9128 | 9428 | String::from_utf8_lossy(&out.stderr) |
| 9129 | 9429 | ); |
| 9130 | 9430 | let plane = width * height; |
| 9131 | - let frame_bytes = 3 * plane; | |
| 9431 | + let bps = if depth == 8 { 1 } else { 2 }; | |
| 9432 | + let frame_bytes = 3 * plane * bps; | |
| 9132 | 9433 | assert_eq!( |
| 9133 | 9434 | out.stdout.len(), |
| 9134 | 9435 | frame_bytes * frames, |
| 9135 | 9436 | "{}", |
| 9136 | 9437 | frame_count_diagnosis( |
| 9137 | - "4:4:4", | |
| 9438 | + if depth == 8 { | |
| 9439 | + "4:4:4" | |
| 9440 | + } else { | |
| 9441 | + "4:4:4 high depth" | |
| 9442 | + }, | |
| 9138 | 9443 | frames, |
| 9139 | 9444 | width, |
| 9140 | 9445 | height, |
| @@ -9146,21 +9451,23 @@ pub(crate) mod tests { | ||
| 9146 | 9451 | (0..frames) |
| 9147 | 9452 | .map(|i| { |
| 9148 | 9453 | let base = i * frame_bytes; |
| 9454 | + let samples = |off: usize| -> Vec<u16> { | |
| 9455 | + let slice = &out.stdout[base + off..base + off + plane * bps]; | |
| 9456 | + if bps == 1 { | |
| 9457 | + slice.iter().map(|&v| u16::from(v)).collect() | |
| 9458 | + } else { | |
| 9459 | + slice | |
| 9460 | + .chunks_exact(2) | |
| 9461 | + .map(|c| u16::from_le_bytes([c[0], c[1]])) | |
| 9462 | + .collect() | |
| 9463 | + } | |
| 9464 | + }; | |
| 9149 | 9465 | Pic { |
| 9150 | 9466 | width, |
| 9151 | 9467 | height, |
| 9152 | - y: out.stdout[base..base + plane] | |
| 9153 | - .iter() | |
| 9154 | - .map(|&v| u16::from(v)) | |
| 9155 | - .collect(), | |
| 9156 | - u: out.stdout[base + plane..base + 2 * plane] | |
| 9157 | - .iter() | |
| 9158 | - .map(|&v| u16::from(v)) | |
| 9159 | - .collect(), | |
| 9160 | - v: out.stdout[base + 2 * plane..base + 3 * plane] | |
| 9161 | - .iter() | |
| 9162 | - .map(|&v| u16::from(v)) | |
| 9163 | - .collect(), | |
| 9468 | + y: samples(0), | |
| 9469 | + u: samples(plane * bps), | |
| 9470 | + v: samples(2 * plane * bps), | |
| 9164 | 9471 | } |
| 9165 | 9472 | }) |
| 9166 | 9473 | .collect() |
| @@ -18124,7 +18431,8 @@ exit 0 | ||
| 18124 | 18431 | assert_420_oracle_stream( |
| 18125 | 18432 | stream, |
| 18126 | 18433 | "ffmpeg_decode_sequence_12bit", |
| 18127 | - "ffmpeg_decode_sequence_422_depth(.., 12, \"yuv422p12le\") (4:2:2); ffmpeg_decode_sequence_444 is 8-bit only", | |
| 18434 | + "ffmpeg_decode_sequence_422_depth(.., 12, \"yuv422p12le\") (4:2:2); \ | |
| 18435 | + ffmpeg_decode_sequence_444_depth(.., 12, \"yuv444p12le\") (4:4:4)", | |
| 18128 | 18436 | ); |
| 18129 | 18437 | let out = run_with_stdin( |
| 18130 | 18438 | Command::new("ffmpeg").args([ |
lanes/av1oracledepth.report.mdadded+117 -0
| @@ -0,0 +1,117 @@ | ||
| 1 | +# lane/av1oracledepth — depth-generic 4:4:4 ffmpeg oracle, 10-bit depth assert, dead 4:2:2 refusal arm | |
| 2 | + | |
| 3 | +**Tree.** `lane/av1oracledepth` off main `c38dd788`, worktree | |
| 4 | +`~/.cache/wt/av1oracledepth`, target dir `~/.cache/tgt-av1oracledepth`. | |
| 5 | +Scope: `crates/ec-av1/src/stream.rs` ONLY (test-module oracle helpers and | |
| 6 | +gates). `decode.rs` untouched. No push, no merge. | |
| 7 | + | |
| 8 | +Closes items 3 and 4 of `lanes/av1oracleguard.report.md` §"Not closed, stated | |
| 9 | +plainly", plus the dead code arm the lane-av1stale422prose sweep left on | |
| 10 | +purpose. | |
| 11 | + | |
| 12 | +## Item 3 — depth-generic 4:4:4 oracle helper | |
| 13 | + | |
| 14 | +### New helper: `ffmpeg_decode_sequence_444_depth` | |
| 15 | + | |
| 16 | +Mirrors `ffmpeg_decode_sequence_422_depth` (lane-av1422lift) shape for shape: | |
| 17 | + | |
| 18 | +* `yuv444p` / `yuv444p10le` / `yuv444p12le`, `depth in {8, 10, 12}` else | |
| 19 | + hard assert. | |
| 20 | +* Container width from `depth`: 1 byte/sample at 8, 2-byte LE at 10/12, on | |
| 21 | + BOTH sides, so nothing narrows. | |
| 22 | +* Shape guard `(sx, sy) == (0, 0)` read from the stream's own sequence | |
| 23 | + header (same class as `assert_420_oracle_stream`: | |
| 24 | + `helper-assumes-the-shape-the-gate-name-implies`) — a (1,0)/(1,1) stream | |
| 25 | + handed here cannot let ffmpeg convert it. | |
| 26 | +* Depth guard: `stream_bit_depth(stream) == depth` — the wrong-depth refusal | |
| 27 | + item 4 asked for, applied here too. | |
| 28 | +* Frame-count diagnosis reuses `frame_count_diagnosis`. | |
| 29 | + | |
| 30 | +`ffmpeg_decode_sequence_444` (8-bit) is now a one-line delegate onto it at | |
| 31 | +`depth=8, "yuv444p"`, so its 8 existing call sites keep their exact contract; | |
| 32 | +its guard set GROWS (shape + depth now asserted where none was), and all 8 | |
| 33 | +sites still pass. | |
| 34 | + | |
| 35 | +### New test 1: refusal — `the_8bit_444_oracle_helper_refuses_a_10bit_444_pin` | |
| 36 | + | |
| 37 | +Pinned real 10-bit 4:4:4 stream `444_lossy_palette_chroma_352x242_10b.obu` | |
| 38 | +(24 875 B, FNV-1a64 `0x7fda_dbb4_3bbf_9af3`, sha256 | |
| 39 | +`84df2f37cc7982f9a572443d85dfcc13bf366a64f3fb567391dcd5acd58a0ad2`, the same | |
| 40 | +pin `a_444_lossy_palette_chroma_unit_window_is_byte_exact_at_352x242_10bit` | |
| 41 | +gates; provenance lane-av1444d10 §0 — census recipe, byte-reproduced). No new | |
| 42 | +fixture invented. The test asserts the pin is REALLY 10-bit and REALLY (0,0) | |
| 43 | +before feeding it, then requires `ffmpeg_decode_sequence_444` to panic with a | |
| 44 | +message naming `not 8-bit` and the sibling | |
| 45 | +`ffmpeg_decode_sequence_444_depth`. Needs no ffmpeg (guard runs before the | |
| 46 | +spawn). RED-before is inherent: on the parent helper (no guards) the same | |
| 47 | +call returned a 4:4:4-sliced converted picture with no refusal — that is the | |
| 48 | +silent-green the helper now stops. | |
| 49 | + | |
| 50 | +### New test 2: positive control — `the_444_depth_helper_is_byte_exact_on_a_pinned_10bit_444_cell` | |
| 51 | + | |
| 52 | +Same pin, `ffmpeg_decode_sequence_444_depth(.., 10, "yuv444p10le")`: | |
| 53 | + | |
| 54 | +1. 16 shown frames byte-exact vs our decode, per plane, first-diff panic. | |
| 55 | +2. Flip control (crate's own comparator-liveness shape, thread-local ffmpeg | |
| 56 | + shim from `every_ffmpeg_comparator_reds_on_a_one_sample_wrong_ffmpeg`): | |
| 57 | + rotating ONE byte of the ORACLE's rawvideo stdout must move the mismatch | |
| 58 | + count 0 -> EXACTLY 1 in the tampered plane, 0 in the other two — measured | |
| 59 | + for Y, U and V separately. GREEN measured on this host (ffmpeg 8.1.3, | |
| 60 | + oracle aomdec present, `EC_AV1_REQUIRE_*` set). | |
| 61 | + | |
| 62 | +## Item 4 — `ffmpeg_decode_sequence_10bit` depth assert | |
| 63 | + | |
| 64 | +`assert_eq!(stream_bit_depth(stream, ..), 10, ..)` right after the existing | |
| 65 | +shape guard, mirroring `assert_12bit_sequence_header`'s role for the 12-bit | |
| 66 | +gates. The shape refusal is untouched (still `assert_420_oracle_stream` | |
| 67 | +first, and the wrong-shape message still names both depth-generic siblings). | |
| 68 | +An 8-bit stream handed to the helper now reds by NAME before ffmpeg runs; | |
| 69 | +ffmpeg would otherwise convert 8-bit samples into the 16-bit container | |
| 70 | +silently and the gate could read exact on a converted reference. | |
| 71 | + | |
| 72 | +New test 3: `the_10bit_oracle_helper_refuses_a_wrong_depth_stream` on the | |
| 73 | +committed 8-bit 4:2:0 pin `mix176_offtile_chroma_clip.obu` (4 581 B, | |
| 74 | +FNV-1a64 `0x5e31be5efc9c3c1d`) — the 4:2:0 shape is asserted FIRST so the | |
| 75 | +red cannot be the shape guard; the message must contain `not 10-bit`. | |
| 76 | + | |
| 77 | +Sibling strings swept: the stale "ffmpeg_decode_sequence_444 is 8-bit only" | |
| 78 | +text in the 10-bit and 12-bit shape guards now points at | |
| 79 | +`ffmpeg_decode_sequence_444_depth(.., N, "yuvNNNle")`. | |
| 80 | + | |
| 81 | +## Item 3b (bonus sweep): dead refusal arm deleted | |
| 82 | + | |
| 83 | +`the_pinned_422_palette_intra_in_inter_cell_window_is_byte_exact` — the | |
| 84 | +prose sweep's leftover. OK arm proved live on the pinned fixture FIRST | |
| 85 | +(measured: `17 decode-order frame(s) byte-exact against aomdec (1 hidden), | |
| 86 | +16 chroma palette unit window(s)`), then the `Err` arm deleted. It matched | |
| 87 | +the pre-lift refusal string `"a chroma format of 4:2:2"` which committed code | |
| 88 | +no longer returns; its only possible future effect was swallowing a | |
| 89 | +DIFFERENT decode error whose message happened to contain that string and | |
| 90 | +reading green off a stream that decoded nothing. The arm is replaced by a | |
| 91 | +`panic!` on ANY error (4:2:2 is a decoded format; a refusal is a regression). | |
| 92 | +The stale doc-comment half that described the Err arm is rewritten; the | |
| 93 | +comment lines the prose merge landed are otherwise untouched. Gate still | |
| 94 | +green after deletion. | |
| 95 | + | |
| 96 | +## Runs (all on the lane tree, `EC_AV1_REQUIRE_FFMPEG=1 | |
| 97 | +EC_AV1_REQUIRE_AOMENC=1 EC_AV1_REQUIRE_AOMDEC=1`) | |
| 98 | + | |
| 99 | +| run | result | | |
| 100 | +|---|---| | |
| 101 | +| `cargo check -p ec-av1 --tests` | clean, 0 warnings | | |
| 102 | +| the 3 new tests + `a_420_oracle_helper_refuses_a_422_pin` + `a_420_high_bit_depth_oracle_helpers_refuse_a_422_pin` | 5/5 green | | |
| 103 | +| `a_lossless_444_*` + `ll444_*` + superres + palette 4:4:4 family (`444_` filter, 53 tests) | 53/53 green | | |
| 104 | +| superres family (22 tests, incl. 10/12-bit 444 superres) | 22/22 green | | |
| 105 | +| `every_ffmpeg_comparator_reds_on_a_one_sample_wrong_ffmpeg` (10bit helper still bites per plane) | green | | |
| 106 | +| `the_pinned_422_palette_intra_in_inter_cell_window_is_byte_exact` after arm deletion | green (17 frames byte-exact, 16 windowed units) | | |
| 107 | +| full `-p ec-av1 --lib` suite | see run line below | | |
| 108 | + | |
| 109 | +## Not closed, stated plainly | |
| 110 | + | |
| 111 | +* The 8-bit `ffmpeg_decode_sequence_444` delegates through the depth helper, | |
| 112 | + so 8-bit 4:4:4 gates now also pay the shape/depth parse (two header | |
| 113 | + probes). Measured cost on the 53-test 4:4:4 family: none beyond noise. | |
| 114 | +* `ffmpeg_decode_sequence_444_depth` is exercised at 8 and 10; the 12-bit | |
| 115 | + arm has no committed exactness pin yet (the 12-bit 4:4:4 gates use | |
| 116 | + `decode_all_frames_vs_oracle`, not ffmpeg rawvideo). The helper's 12-bit | |
| 117 | + container path is the same `bps == 2` branch the 10-bit pin proves. |