Gate the frame-edge partition bit at all three levels, both depths
Browse files at this commitbb77f0885d871afb63b03f342f61c546dfea05a1Parent: b5166a1- test
- gate the frame-edge partition bit at all three levels, both depths
1 changed file +167 -0
- crates/ec-av1/src/stream.rs +167 -0
crates/ec-av1/src/stream.rsmodified+167 -0
| @@ -19640,4 +19640,171 @@ mod tests { | |||
| 19640 | yuv420p10le)" | 19640 | yuv420p10le)" |
| 19641 | ); | 19641 | ); |
| 19642 | } | 19642 | } |
| 19643 | + | ||
| 19644 | + /// lane-hgkf r1: a frame whose height (or width) is not a multiple of the | ||
| 19645 | + /// block size makes the last superblock row (column) read a GATHERED | ||
| 19646 | + /// partition bit instead of a full alphabet symbol -- and libaom's | ||
| 19647 | + /// `ec_read_partition_impl` answers that bit with `PARTITION_HORZ` | ||
| 19648 | + /// (resp. `VERT`) when it is 0, only `SPLIT` when it is 1. All three | ||
| 19649 | + /// key-frame edge readers (64-, 32- and 16-level) read the bit and threw | ||
| 19650 | + /// it away, forcing SPLIT; every such frame desynced at the first block | ||
| 19651 | + /// of its partial row. 192x136 / 136x192 is the smallest shape that hits | ||
| 19652 | + /// all three levels at once (136 = 2*64 + 8, so mi_rows = 34: the 64-, | ||
| 19653 | + /// 32- and 16-level halves all fall outside), and it is the shape of a | ||
| 19654 | + /// real 3840x1608 10-bit film key frame (1608 mod 64 == 8) that decoded | ||
| 19655 | + /// 51768 samples wrong before this round. | ||
| 19656 | + /// | ||
| 19657 | + /// The counter is sampled per attempt and read only on an attempt that | ||
| 19658 | + /// decoded AND is pixel-compared; slot 0/2 (the bit taken as HORZ/VERT) | ||
| 19659 | + /// must be nonzero or the gate proves nothing -- before this round that | ||
| 19660 | + /// arm was unreachable by construction. | ||
| 19661 | + #[test] | ||
| 19662 | + fn a_real_aomenc_stream_whose_frame_edge_partition_bit_is_horz_decodes_pixel_exact() { | ||
| 19663 | + const NAME: &str = | ||
| 19664 | + "a_real_aomenc_stream_whose_frame_edge_partition_bit_is_horz_decodes_pixel_exact"; | ||
| 19665 | + let _gate_lock = lock_gate_counters(); | ||
| 19666 | + if !have_ffmpeg() { | ||
| 19667 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 19668 | + return; | ||
| 19669 | + } | ||
| 19670 | + if !have_aomenc() { | ||
| 19671 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 19672 | + return; | ||
| 19673 | + } | ||
| 19674 | + let mut compared = 0usize; | ||
| 19675 | + let mut edge_horz_total = 0usize; | ||
| 19676 | + let mut edge_sub_total = 0usize; | ||
| 19677 | + // The last two shapes are the ledger-measured 64-level pair: on a | ||
| 19678 | + // flat band (192x80 / 80x192) real aomenc answers the bottom-edge | ||
| 19679 | + // superblock with the 64-level HORZ/VERT, which the 136 shapes above | ||
| 19680 | + // never produce (their SBs always split down to the 32/16 levels). | ||
| 19681 | + for (width, height, flat) in [ | ||
| 19682 | + (192usize, 136usize, false), | ||
| 19683 | + (136usize, 192usize, false), | ||
| 19684 | + (192usize, 80usize, true), | ||
| 19685 | + (80usize, 192usize, true), | ||
| 19686 | + ] { | ||
| 19687 | + for depth in [8usize, 10] { | ||
| 19688 | + let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; | ||
| 19689 | + let y4m = Command::new("ffmpeg") | ||
| 19690 | + .args([ | ||
| 19691 | + "-v", "error", "-f", "lavfi", "-i", | ||
| 19692 | + &if flat { | ||
| 19693 | + format!("color=c=gray:size={width}x{height}") | ||
| 19694 | + } else { | ||
| 19695 | + format!("mandelbrot=size={width}x{height}:start_x=-0.6") | ||
| 19696 | + }, | ||
| 19697 | + "-pix_fmt", pix, "-strict", "-1", "-t", "1", "-vframes", "1", | ||
| 19698 | + "-f", "yuv4mpegpipe", "-", | ||
| 19699 | + ]) | ||
| 19700 | + .stdin(Stdio::null()) | ||
| 19701 | + .stdout(Stdio::piped()) | ||
| 19702 | + .stderr(Stdio::piped()) | ||
| 19703 | + .output() | ||
| 19704 | + .expect("ffmpeg failed to run"); | ||
| 19705 | + assert!( | ||
| 19706 | + y4m.status.success(), | ||
| 19707 | + "{NAME}: ffmpeg fixture ({width}x{height}, depth={depth}): {}", | ||
| 19708 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 19709 | + ); | ||
| 19710 | + let encode = || { | ||
| 19711 | + let mut child = Command::new(aomenc_path()) | ||
| 19712 | + .args([ | ||
| 19713 | + "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32", | ||
| 19714 | + "--cpu-used=3", "--threads=1", "--row-mt=0", "--sb-size=64", | ||
| 19715 | + "--kf-max-dist=0", "--enable-rect-partitions=1", | ||
| 19716 | + "--enable-ab-partitions=0", "--enable-1to4-partitions=0", | ||
| 19717 | + "--enable-tx-size-search=0", "--reduced-tx-type-set=1", | ||
| 19718 | + "--min-partition-size=8", "--max-partition-size=64", | ||
| 19719 | + &format!("--input-bit-depth={depth}"), | ||
| 19720 | + &format!("--bit-depth={depth}"), | ||
| 19721 | + "--obu", "-o", "-", "-", | ||
| 19722 | + ]) | ||
| 19723 | + .stdin(Stdio::piped()) | ||
| 19724 | + .stdout(Stdio::piped()) | ||
| 19725 | + .stderr(Stdio::piped()) | ||
| 19726 | + .spawn() | ||
| 19727 | + .expect("aomenc failed to start"); | ||
| 19728 | + child | ||
| 19729 | + .stdin | ||
| 19730 | + .take() | ||
| 19731 | + .expect("aomenc stdin") | ||
| 19732 | + .write_all(&y4m.stdout) | ||
| 19733 | + .expect("writing y4m to aomenc"); | ||
| 19734 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 19735 | + assert!( | ||
| 19736 | + out.status.success(), | ||
| 19737 | + "aomenc refused the fixture ({width}x{height}, depth={depth}): {}", | ||
| 19738 | + String::from_utf8_lossy(&out.stderr) | ||
| 19739 | + ); | ||
| 19740 | + out.stdout | ||
| 19741 | + }; | ||
| 19742 | + let stream = encode(); | ||
| 19743 | + assert_eq!( | ||
| 19744 | + stream, | ||
| 19745 | + encode(), | ||
| 19746 | + "{NAME}: aomenc output is not reproducible ({width}x{height}, depth={depth})" | ||
| 19747 | + ); | ||
| 19748 | + crate::decode::reset_edge_part_hits(); | ||
| 19749 | + let frames = match decode_stream(&stream) { | ||
| 19750 | + Ok(frames) => frames, | ||
| 19751 | + Err(e) => { | ||
| 19752 | + let msg = e.to_string(); | ||
| 19753 | + assert!( | ||
| 19754 | + msg.contains("unsupported"), | ||
| 19755 | + "{NAME}: decode failed ({width}x{height}, depth={depth}): {msg}" | ||
| 19756 | + ); | ||
| 19757 | + eprintln!( | ||
| 19758 | + "{NAME}: {width}x{height} depth={depth} arm refused (not compared): {msg}" | ||
| 19759 | + ); | ||
| 19760 | + continue; | ||
| 19761 | + } | ||
| 19762 | + }; | ||
| 19763 | + let hits = crate::decode::edge_part_hits(); | ||
| 19764 | + let ffmpeg_frames = if depth == 10 { | ||
| 19765 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len()) | ||
| 19766 | + } else { | ||
| 19767 | + ffmpeg_decode_sequence(&stream, width, height, frames.len()) | ||
| 19768 | + }; | ||
| 19769 | + assert_eq!(ffmpeg_frames.len(), frames.len(), "{NAME}: ffmpeg frame count"); | ||
| 19770 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 19771 | + assert_eq!( | ||
| 19772 | + got.y, want.y, | ||
| 19773 | + "{NAME} frame {i} luma vs ffmpeg ({width}x{height}, depth={depth}, \ | ||
| 19774 | + edge bits horz/split 64-level {}/{}, sub-level {}/{})", | ||
| 19775 | + hits[0], hits[1], hits[2], hits[3] | ||
| 19776 | + ); | ||
| 19777 | + assert_eq!( | ||
| 19778 | + got.u, want.u, | ||
| 19779 | + "{NAME} frame {i} U vs ffmpeg ({width}x{height}, depth={depth})" | ||
| 19780 | + ); | ||
| 19781 | + assert_eq!( | ||
| 19782 | + got.v, want.v, | ||
| 19783 | + "{NAME} frame {i} V vs ffmpeg ({width}x{height}, depth={depth})" | ||
| 19784 | + ); | ||
| 19785 | + } | ||
| 19786 | + compared += 1; | ||
| 19787 | + edge_horz_total += hits[0]; | ||
| 19788 | + edge_sub_total += hits[2]; | ||
| 19789 | + eprintln!( | ||
| 19790 | + "{NAME}: pixel-exact {width}x{height} at {depth}-bit, edge bits \ | ||
| 19791 | + 64-level horz/vert={} split={} sub-level horz/vert={} split={}", | ||
| 19792 | + hits[0], hits[1], hits[2], hits[3] | ||
| 19793 | + ); | ||
| 19794 | + } | ||
| 19795 | + } | ||
| 19796 | + assert!( | ||
| 19797 | + compared > 0, | ||
| 19798 | + "{NAME}: every arm refused -- the gate compared no pixels at all" | ||
| 19799 | + ); | ||
| 19800 | + assert!( | ||
| 19801 | + edge_horz_total > 0, | ||
| 19802 | + "{NAME}: no 64-level frame-edge bit was ever answered HORZ/VERT -- the arm this \ | ||
| 19803 | + round fixed never fired" | ||
| 19804 | + ); | ||
| 19805 | + assert!( | ||
| 19806 | + edge_sub_total > 0, | ||
| 19807 | + "{NAME}: no 32/16-level frame-edge bit was ever answered HORZ/VERT" | ||
| 19808 | + ); | ||
| 19809 | + } | ||
| 19643 | } | 19810 | } |