forge
Explore
Log in

Don't you dare go Hollow

Witness -- a segmented key frame with sub-8x8 intra leaves

Browse files at this commit

6c9362c556ce306d611c00f656a6ef46b211eff7Ahmet Kaan GümüşParent: 120e018
  • test
    • witness -- a segmented key frame with sub-8x8 intra leaves
Show full message
test(av1): witness -- a segmented key frame with sub-8x8 intra leaves
crates/ec-av1/src/stream.rsmodified+87 -0
@@ -35349,4 +35349,91 @@ pub(crate) mod tests {
35349 eprintln!("{NAME}: {checked} straddling reference points decoded sample-exact");35349 eprintln!("{NAME}: {checked} straddling reference points decoded sample-exact");
35350 }35350 }
35351 35351
35352+ /// lane-seg2: a SEGMENTED key frame that also codes sub-8x8 INTRA leaves.
35353+ ///
35354+ /// WHY IT EXISTS: `read_intra_mode_sub8` -- the reader every `BLOCK_4X4`
35355+ /// split leaf and every 8x4/4x8 leaf goes through -- never called spec
35356+ /// 5.11.6's `intra_segment_id` at all. On a stream with segmentation on
35357+ /// it therefore (a) left the block's `segment_id` symbol unread, so the
35358+ /// tile desynced from the frame's first sub-8x8 partition on, and (b)
35359+ /// dequantized the leaf with the PREVIOUS block's `SEG_LVL_ALT_Q`.
35360+ /// Reading it with a hardcoded 1x1 mi footprint was the second half of
35361+ /// the same defect: an 8x4 leaf left its second mi cell at segment 0,
35362+ /// which the next block read back as its spatial prediction and CDF row.
35363+ ///
35364+ /// RECIPE: flat gray + heavy `noise` (the contrast is what turns libaom's
35365+ /// activity segmentation on -- a `testsrc2`/bars source codes ONE segment
35366+ /// and passes with the defect in, ledger dead-end `gate film rows are
35367+ /// colour bars`), at `-crf 5 -cpu-used 2`, which is the measured corner
35368+ /// where libaom answers with sub-8x8 intra partitions. Measured on this
35369+ /// exact stream: red before either half of the fix (134k/134k samples
35370+ /// off), green with both.
35371+ #[test]
35372+ fn a_segmented_key_frame_with_sub_8x8_intra_leaves_decodes_exactly() {
35373+ const NAME: &str = "a_segmented_key_frame_with_sub_8x8_intra_leaves_decodes_exactly";
35374+ let _gate_lock = lock_gate_counters();
35375+ if !have_ffmpeg() {
35376+ eprintln!("SKIP {NAME}: no ffmpeg");
35377+ return;
35378+ }
35379+ const FRAMES: usize = 4;
35380+ let (w, h) = (384usize, 152usize);
35381+ let src = format!(
35382+ "color=c=gray:s={w}x{h}:r=25,noise=alls=80:all_seed=7:allf=t+u"
35383+ );
35384+ let args: Vec<String> = [
35385+ "-v", "error", "-f", "lavfi", "-i", &src, "-frames:v", "4", "-pix_fmt", "yuv420p",
35386+ "-an", "-threads", "1", "-g", "4", "-c:v", "libaom-av1", "-cpu-used", "2", "-b:v",
35387+ "0", "-crf", "5", "-aq-mode", "1", "-f", "obu", "-",
35388+ ]
35389+ .iter()
35390+ .map(|s| (*s).to_string())
35391+ .collect();
35392+ let out = Command::new("ffmpeg")
35393+ .args(&args)
35394+ .stdin(Stdio::null())
35395+ .stdout(Stdio::piped())
35396+ .stderr(Stdio::piped())
35397+ .output()
35398+ .expect("ffmpeg failed to run");
35399+ if !out.status.success() {
35400+ eprintln!(
35401+ "SKIP {NAME}: ffmpeg cannot encode with libaom-av1 ({})",
35402+ String::from_utf8_lossy(&out.stderr).lines().last().unwrap_or("")
35403+ );
35404+ return;
35405+ }
35406+ let stream = out.stdout;
35407+ crate::decode::reset_segment_hits();
35408+ let want = ffmpeg_decode_sequence(&stream, w, h, FRAMES);
35409+ let got = decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME}: refused: {e}"));
35410+ assert_eq!(got.len(), want.len(), "{NAME}: frame count");
35411+ for (f, (o, r)) in got.iter().zip(&want).enumerate() {
35412+ for (plane, a, b) in [("Y", &o.y, &r.y), ("U", &o.u, &r.u), ("V", &o.v, &r.v)] {
35413+ if let Some(i) = a.iter().zip(b.iter()).position(|(x, y)| x != y) {
35414+ let stride = if plane == "Y" { w } else { w / 2 };
35415+ panic!(
35416+ "{NAME}: frame {f} plane {plane} sample ({}, {}): ours {} vs ffmpeg {}",
35417+ i % stride,
35418+ i / stride,
35419+ a[i],
35420+ b[i],
35421+ );
35422+ }
35423+ }
35424+ }
35425+ // The property is asserted, not hoped for: without more than one
35426+ // segment this row would pass with the defect still in.
35427+ assert!(
35428+ crate::decode::segment_ids_seen() >= 2,
35429+ "{NAME}: vacuous run -- {} distinct segment ids",
35430+ crate::decode::segment_ids_seen()
35431+ );
35432+ eprintln!(
35433+ "{NAME}: {FRAMES} frames sample-exact, {} segment_id symbols, {} distinct ids",
35434+ crate::decode::segment_id_hits(),
35435+ crate::decode::segment_ids_seen()
35436+ );
35437+ }
35438+
35352 }35439 }