Non-uniform tile spacing gate -- decode already generic, staleness-checked
Browse files at this commit2f03ac7a0c2f7474f3ffb25215165e9aa2463d61Parent: bb6a29d- test
- non-uniform tile spacing gate -- decode already generic, staleness-checked
1 changed file +180 -0
- crates/ec-av1/src/stream.rs +180 -0
crates/ec-av1/src/stream.rsmodified+180 -0
| @@ -8039,4 +8039,184 @@ mod tests { | |||
| 8039 | "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20" | 8039 | "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20" |
| 8040 | ); | 8040 | ); |
| 8041 | } | 8041 | } |
| 8042 | + | ||
| 8043 | + /// lane-tiles r10: non-uniform tile spacing (`uniform_spacing_flag == 0`, | ||
| 8044 | + /// spec 5.9.15). aomenc never sets this from `--tile-columns`/ | ||
| 8045 | + /// `--tile-rows` (those always take the `uniform_spacing = 1` branch in | ||
| 8046 | + /// `set_tile_info`, libaom `encoder.c`), and `--auto-tiles` only takes | ||
| 8047 | + /// the non-uniform balancing path when `g_threads >= 2` -- this charter's | ||
| 8048 | + /// `--threads=1` rules that out. The only CLI surface that reaches | ||
| 8049 | + /// libaom's `else { tiles->uniform_spacing = 0; ... }` arm is the | ||
| 8050 | + /// explicit per-tile size lists `--tile-width=<sb-list>`/ | ||
| 8051 | + /// `--tile-height=<sb-list>` (`av1_cx_iface.c` `set_tile_info`, argument | ||
| 8052 | + /// parsing at `arg_defs.c`'s `.tile_width`/`.tile_height` -- present in | ||
| 8053 | + /// the binary, just not printed by `--help`). Probed live with | ||
| 8054 | + /// `aomenc --tile-width=1,3 --tile-height=1 --sb-size=64` on a 256x64 | ||
| 8055 | + /// source (4 SB columns, 1 SB row): confirmed by hand this round to | ||
| 8056 | + /// produce a real OBU stream aomdec/ffmpeg both decode. | ||
| 8057 | + /// | ||
| 8058 | + /// `decode.rs`'s tile loop was already generic over spacing before this | ||
| 8059 | + /// gate existed -- it walks `tile_info.mi_col_starts`/`mi_row_starts` | ||
| 8060 | + /// (populated identically by `read_tile_info` for both the uniform and | ||
| 8061 | + /// non-uniform branches, spec 5.9.15) and never recomputes tile bounds | ||
| 8062 | + /// from `cols_log2`/`rows_log2`. The only place in this crate that ever | ||
| 8063 | + /// refused non-uniform spacing is `frame.rs`'s OBU *writer* | ||
| 8064 | + /// (`"non-uniform tile spacing is not written"`), an unrelated encode | ||
| 8065 | + /// path this gate does not touch. So this is a staleness check, not new | ||
| 8066 | + /// machinery: prove the already-generic decode path live and pin it. | ||
| 8067 | + #[test] | ||
| 8068 | + fn a_real_aomenc_stream_with_non_uniform_tile_spacing_decodes_pixel_exact() { | ||
| 8069 | + const NAME: &str = "a_real_aomenc_stream_with_non_uniform_tile_spacing_decodes_pixel_exact"; | ||
| 8070 | + if !have_ffmpeg() { | ||
| 8071 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 8072 | + return; | ||
| 8073 | + } | ||
| 8074 | + if !have_aomenc() { | ||
| 8075 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 8076 | + return; | ||
| 8077 | + } | ||
| 8078 | + let (width, height) = (256usize, 64usize); | ||
| 8079 | + let mut matched = 0u32; | ||
| 8080 | + let mut named_refusals = 0u32; | ||
| 8081 | + let mut saw_non_uniform_spacing = false; | ||
| 8082 | + for attempt in 0..20u32 { | ||
| 8083 | + let seed = 42 + attempt; | ||
| 8084 | + let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); | ||
| 8085 | + let y4m = Command::new("ffmpeg") | ||
| 8086 | + .args([ | ||
| 8087 | + "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", | ||
| 8088 | + "yuv4mpegpipe", "-", | ||
| 8089 | + ]) | ||
| 8090 | + .stdin(Stdio::null()) | ||
| 8091 | + .stdout(Stdio::piped()) | ||
| 8092 | + .stderr(Stdio::piped()) | ||
| 8093 | + .output() | ||
| 8094 | + .expect("ffmpeg failed to run"); | ||
| 8095 | + assert!( | ||
| 8096 | + y4m.status.success(), | ||
| 8097 | + "ffmpeg fixture: {}", | ||
| 8098 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 8099 | + ); | ||
| 8100 | + let mut child = Command::new(aomenc_path()) | ||
| 8101 | + .args([ | ||
| 8102 | + "--codec=av1", | ||
| 8103 | + "--passes=1", | ||
| 8104 | + "--end-usage=q", | ||
| 8105 | + "--cq-level=45", | ||
| 8106 | + "--cpu-used=0", | ||
| 8107 | + "--limit=1", | ||
| 8108 | + "--kf-max-dist=1000", | ||
| 8109 | + "--threads=1", | ||
| 8110 | + "--row-mt=0", | ||
| 8111 | + "--sb-size=64", | ||
| 8112 | + "--tile-width=1,3", | ||
| 8113 | + "--tile-height=1", | ||
| 8114 | + "--loopfilter-control=0", | ||
| 8115 | + "--enable-rect-partitions=0", | ||
| 8116 | + "--enable-ab-partitions=0", | ||
| 8117 | + "--enable-1to4-partitions=0", | ||
| 8118 | + "--enable-filter-intra=0", | ||
| 8119 | + "--enable-smooth-intra=0", | ||
| 8120 | + "--enable-paeth-intra=0", | ||
| 8121 | + "--enable-directional-intra=0", | ||
| 8122 | + "--enable-angle-delta=0", | ||
| 8123 | + "--enable-tx-size-search=0", | ||
| 8124 | + "--enable-cdef=0", | ||
| 8125 | + "--enable-restoration=0", | ||
| 8126 | + "--max-partition-size=32", | ||
| 8127 | + "--min-partition-size=32", | ||
| 8128 | + "--enable-palette=0", | ||
| 8129 | + "--enable-intrabc=0", | ||
| 8130 | + "--enable-cfl-intra=0", | ||
| 8131 | + "--obu", | ||
| 8132 | + "-o", | ||
| 8133 | + "-", | ||
| 8134 | + "-", | ||
| 8135 | + ]) | ||
| 8136 | + .stdin(Stdio::piped()) | ||
| 8137 | + .stdout(Stdio::piped()) | ||
| 8138 | + .stderr(Stdio::piped()) | ||
| 8139 | + .spawn() | ||
| 8140 | + .expect("aomenc failed to start"); | ||
| 8141 | + child | ||
| 8142 | + .stdin | ||
| 8143 | + .take() | ||
| 8144 | + .expect("aomenc stdin") | ||
| 8145 | + .write_all(&y4m.stdout) | ||
| 8146 | + .expect("writing y4m to aomenc"); | ||
| 8147 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 8148 | + assert!( | ||
| 8149 | + out.status.success(), | ||
| 8150 | + "aomenc refused the fixture: {}", | ||
| 8151 | + String::from_utf8_lossy(&out.stderr) | ||
| 8152 | + ); | ||
| 8153 | + let stream = out.stdout; | ||
| 8154 | + | ||
| 8155 | + let mut probe = Av1Parser::new(); | ||
| 8156 | + let mut pos = 0usize; | ||
| 8157 | + while pos < stream.len() { | ||
| 8158 | + let obu = probe.parse_obu(&stream[pos..]).unwrap(); | ||
| 8159 | + pos += obu.total_size; | ||
| 8160 | + let tile_info = match &obu.kind { | ||
| 8161 | + ObuKind::Frame(header, _) => Some(&header.tile_info), | ||
| 8162 | + ObuKind::FrameHeader(header) if !header.show_existing_frame => { | ||
| 8163 | + Some(&header.tile_info) | ||
| 8164 | + } | ||
| 8165 | + _ => None, | ||
| 8166 | + }; | ||
| 8167 | + if let Some(info) = tile_info { | ||
| 8168 | + if !info.uniform_spacing { | ||
| 8169 | + saw_non_uniform_spacing = true; | ||
| 8170 | + } | ||
| 8171 | + assert!( | ||
| 8172 | + info.cols > 1 || info.rows > 1, | ||
| 8173 | + "{NAME}: --tile-width=1,3 --tile-height=1 produced only 1 tile \ | ||
| 8174 | + (cols={} rows={}, seed {seed}) -- fixture stopped exercising the case", | ||
| 8175 | + info.cols, | ||
| 8176 | + info.rows | ||
| 8177 | + ); | ||
| 8178 | + } | ||
| 8179 | + } | ||
| 8180 | + | ||
| 8181 | + let before = crate::decode::tile_hits(); | ||
| 8182 | + let pictures = match decode_stream(&stream) { | ||
| 8183 | + Err(e) => { | ||
| 8184 | + let msg = e.to_string(); | ||
| 8185 | + assert!( | ||
| 8186 | + msg.contains("unsupported"), | ||
| 8187 | + "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" | ||
| 8188 | + ); | ||
| 8189 | + named_refusals += 1; | ||
| 8190 | + eprintln!("seed {seed} refusal: {msg}"); | ||
| 8191 | + continue; | ||
| 8192 | + } | ||
| 8193 | + Ok(pictures) => pictures, | ||
| 8194 | + }; | ||
| 8195 | + let hits = crate::decode::tile_hits() - before; | ||
| 8196 | + assert!( | ||
| 8197 | + hits > 0, | ||
| 8198 | + "{NAME}: tile_hits delta was {hits}, expected >0 (seed {seed})" | ||
| 8199 | + ); | ||
| 8200 | + assert_eq!(pictures.len(), 1, "{NAME}: expected exactly 1 picture (seed {seed})"); | ||
| 8201 | + | ||
| 8202 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); | ||
| 8203 | + assert_eq!(pictures[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); | ||
| 8204 | + assert_eq!(pictures[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); | ||
| 8205 | + assert_eq!(pictures[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); | ||
| 8206 | + matched += 1; | ||
| 8207 | + } | ||
| 8208 | + assert!( | ||
| 8209 | + matched > 0, | ||
| 8210 | + "{NAME}: every attempt refused ({named_refusals} refusals); decode_stream never \ | ||
| 8211 | + decoded a non-uniform-tile-spacing stream" | ||
| 8212 | + ); | ||
| 8213 | + assert!( | ||
| 8214 | + saw_non_uniform_spacing, | ||
| 8215 | + "{NAME}: no attempt actually set uniform_spacing_flag == 0 -- this sweep proves \ | ||
| 8216 | + nothing about the non-uniform case" | ||
| 8217 | + ); | ||
| 8218 | + eprintln!( | ||
| 8219 | + "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20" | ||
| 8220 | + ); | ||
| 8221 | + } | ||
| 8042 | } | 8222 | } |