forge
Explore
Log in

Don't you dare go Hollow

A straddling-frame gate on both reference encoders' ladders, with two pinned rav1e streams the defect actually reproduces on

Browse files at this commit

7ba3fac9471af582cedb197ff66b1c0232ea6cf5Ahmet Kaan GümüşParent: cd170cb
  • test
    • a straddling-frame gate on both reference encoders' ladders, with two pinned rav1e streams the defect actually reproduces on
Show full message
test(av1): a straddling-frame gate on both reference encoders' ladders, with two pinned rav1e streams the defect actually reproduces on
crates/ec-av1/src/stream.rsmodified+176 -0
@@ -35173,4 +35173,180 @@ pub(crate) mod tests {
35173 );35173 );
35174 }35174 }
35175 35175
35176+
35177+ /// lane-d792: a frame whose height the superblock grid CUTS, decoded
35178+ /// against ffmpeg on every ladder point of BOTH reference encoders.
35179+ ///
35180+ /// WHY IT EXISTS: the reference encoders answer a straddling frame with
35181+ /// rectangular partitions in the cut superblock row -- the only place
35182+ /// these streams code a 16x8/8x4 transform unit at all -- and the rect
35183+ /// intra dequant path was reading the FRAME's quantizer index where every
35184+ /// square path reads the block's segment-adjusted one
35185+ /// (`SEG_LVL_ALT_Q`, class `parsed-then-discarded`). Every gate size
35186+ /// before this one was a whole number of superblocks, so no gate ever
35187+ /// decoded such a unit: the 1920x792 native BD arm's reference-decode
35188+ /// assertion was red on all four rav1e points and this is its small,
35189+ /// fast, encoder-independent form.
35190+ ///
35191+ /// 384x152 is 2 superblocks + 24 px (the 1920x792 straddle, film A's own
35192+ /// coded size) and 384x184 is 2 + 56 px (the 1920x1080 straddle), so both
35193+ /// the "less than half inside" and the "more than half inside" edge
35194+ /// superblock shapes are covered.
35195+ #[test]
35196+ fn a_straddling_frame_decodes_exactly_on_both_reference_encoders_ladders() {
35197+ const NAME: &str = "a_straddling_frame_decodes_exactly_on_both_reference_encoders_ladders";
35198+ if !have_ffmpeg() {
35199+ eprintln!("SKIP {NAME}: no ffmpeg");
35200+ return;
35201+ }
35202+ const FRAMES: usize = 4;
35203+ let mut checked = 0usize;
35204+ // The PINNED half of this gate. The generated rows below are the
35205+ // general regression; these two files are rav1e's own answer to a
35206+ // 384x152 crop of a REAL film (`speed=6`, quantizer 100 and 150,
35207+ // `-g 4`), which is the only recipe measured to turn on the
35208+ // activity segmentation whose `SEG_LVL_ALT_Q` the rect dequant path
35209+ // dropped -- a `testsrc2` or repo-fixture source codes one segment
35210+ // and passes this gate with the defect still in (both verified by
35211+ // reverting the fix under it). Bytes live in the shared `fixtures`
35212+ // directory, which is gitignored, so a missing file SKIPs.
35213+ for name in [
35214+ "d792_straddle_rav1e_384x152_q100.obu",
35215+ "d792_straddle_rav1e_384x152_q150.obu",
35216+ ] {
35217+ let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
35218+ .join("../../fixtures")
35219+ .join(name);
35220+ let Ok(stream) = std::fs::read(&path) else {
35221+ eprintln!("SKIP {NAME}: {name} missing");
35222+ continue;
35223+ };
35224+ let (w, h) = (384usize, 152usize);
35225+ let want = ffmpeg_decode_sequence(&stream, w, h, FRAMES);
35226+ let got = decode_stream(&stream)
35227+ .unwrap_or_else(|e| panic!("{NAME}: {name} refused: {e}"));
35228+ assert_eq!(got.len(), want.len(), "{NAME}: {name} frame count");
35229+ for (f, (o, r)) in got.iter().zip(&want).enumerate() {
35230+ for (plane, a, b) in [("Y", &o.y, &r.y), ("U", &o.u, &r.u), ("V", &o.v, &r.v)] {
35231+ if let Some(i) = a.iter().zip(b.iter()).position(|(x, y)| x != y) {
35232+ let stride = if plane == "Y" { w } else { w / 2 };
35233+ panic!(
35234+ "{NAME}: {name}, frame {f} plane {plane} sample ({}, {}): ours {} \
35235+ vs ffmpeg {}",
35236+ i % stride,
35237+ i / stride,
35238+ a[i],
35239+ b[i],
35240+ );
35241+ }
35242+ }
35243+ }
35244+ checked += 1;
35245+ }
35246+ for (w, h) in [(384usize, 152usize), (384, 184)] {
35247+ // REAL content, not colour bars (class `gate film rows are colour
35248+ // bars`): both encoders only turn segmentation on -- the feature
35249+ // this gate is about -- when the picture's activity varies, and
35250+ // `testsrc2` codes one segment, so a bars source passes this gate
35251+ // with the defect still in (verified by reverting the fix under
35252+ // it).
35253+ let clip = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
35254+ .join("../../fixtures/video/h264-1080p-23.976-8bit.mp4");
35255+ if !clip.exists() {
35256+ eprintln!("SKIP {NAME}: {} missing", clip.display());
35257+ return;
35258+ }
35259+ for (encoder, points) in [
35260+ ("librav1e", ["50", "100", "150", "200"]),
35261+ ("libaom-av1", ["5", "20", "35", "45"]),
35262+ ] {
35263+ for point in points {
35264+ let mut args: Vec<String> =
35265+ ["-v", "error", "-i", clip.to_str().expect("fixture path")]
35266+ .iter()
35267+ .map(|s| (*s).to_string())
35268+ .collect();
35269+ args.extend(
35270+ [
35271+ "-frames:v",
35272+ &FRAMES.to_string(),
35273+ "-vf",
35274+ &format!("crop={w}:{h}:768:400"),
35275+ "-pix_fmt",
35276+ "yuv420p",
35277+ "-an",
35278+ ]
35279+ .iter()
35280+ .map(|s| (*s).to_string()),
35281+ );
35282+ args.extend(
35283+ ["-threads", "1", "-g", &FRAMES.to_string(), "-c:v", encoder]
35284+ .iter()
35285+ .map(|s| (*s).to_string()),
35286+ );
35287+ if encoder == "librav1e" {
35288+ args.push("-rav1e-params".into());
35289+ args.push(format!(
35290+ "speed=6:quantizer={point}:tile_cols=1:tile_rows=1:threads=1"
35291+ ));
35292+ } else {
35293+ args.extend(
35294+ // `-aq-mode 1`: libaom's activity segmentation,
35295+ // i.e. `SEG_LVL_ALT_Q` -- the feature the rect
35296+ // dequant path used to drop.
35297+ ["-cpu-used", "6", "-b:v", "0", "-crf", point, "-aq-mode", "1"]
35298+ .iter()
35299+ .map(|s| (*s).to_string()),
35300+ );
35301+ }
35302+ args.extend(["-f", "obu", "-"].iter().map(|s| (*s).to_string()));
35303+ let out = Command::new("ffmpeg")
35304+ .args(&args)
35305+ .stdin(Stdio::null())
35306+ .stdout(Stdio::piped())
35307+ .stderr(Stdio::piped())
35308+ .output()
35309+ .expect("ffmpeg failed to run");
35310+ if !out.status.success() {
35311+ eprintln!(
35312+ "SKIP {NAME}: ffmpeg cannot encode {w}x{h} with {encoder} ({})",
35313+ String::from_utf8_lossy(&out.stderr).lines().last().unwrap_or("")
35314+ );
35315+ continue;
35316+ }
35317+ let stream = out.stdout;
35318+ let want = ffmpeg_decode_sequence(&stream, w, h, FRAMES);
35319+ let got = decode_stream(&stream).unwrap_or_else(|e| {
35320+ panic!("{NAME}: {encoder} {point} at {w}x{h} refused: {e}")
35321+ });
35322+ assert_eq!(
35323+ got.len(),
35324+ want.len(),
35325+ "{NAME}: {encoder} {point} at {w}x{h} frame count"
35326+ );
35327+ for (f, (o, r)) in got.iter().zip(&want).enumerate() {
35328+ for (plane, a, b) in
35329+ [("Y", &o.y, &r.y), ("U", &o.u, &r.u), ("V", &o.v, &r.v)]
35330+ {
35331+ if let Some(i) = a.iter().zip(b.iter()).position(|(x, y)| x != y) {
35332+ let stride = if plane == "Y" { w } else { w / 2 };
35333+ panic!(
35334+ "{NAME}: {encoder} {point} at {w}x{h}, frame {f} plane \
35335+ {plane} sample ({}, {}): ours {} vs ffmpeg {}",
35336+ i % stride,
35337+ i / stride,
35338+ a[i],
35339+ b[i],
35340+ );
35341+ }
35342+ }
35343+ }
35344+ checked += 1;
35345+ }
35346+ }
35347+ }
35348+ assert!(checked > 0, "{NAME}: neither reference encoder was available");
35349+ eprintln!("{NAME}: {checked} straddling reference points decoded sample-exact");
35350+ }
35351+
35176 }35352 }