wip(sub8): the sub8-split gate, uncompiled
Browse files at this commit224ed165cf28a007b4c606ee8c54958f7a2f55fdParent: c7ed79b1 changed file +144 -0
- crates/ec-av1/src/stream.rs +144 -0
crates/ec-av1/src/stream.rsmodified+144 -0
| @@ -7174,6 +7174,150 @@ mod tests { | |||
| 7174 | ); | 7174 | ); |
| 7175 | } | 7175 | } |
| 7176 | 7176 | ||
| 7177 | + /// lane-sub8 r1: `--min-partition-size=4` on fine-detail noisy gradients | ||
| 7178 | + /// at low cq reliably makes aomenc split an 8x8 block all the way to | ||
| 7179 | + /// four `BLOCK_4X4` leaves (`PARTITION_SPLIT` below 8x8, spec | ||
| 7180 | + /// `decode_partition`'s recursion bottom) -- confirmed with | ||
| 7181 | + /// `EC_AV1_TRACE=1` against `examples/decode_probe` before this gate was | ||
| 7182 | + /// written (`partition_w8 ... value=3` at mi=(0,0) on the very first | ||
| 7183 | + /// block). [`decode::sub8_split_hits`] hard-asserts the path actually | ||
| 7184 | + /// ran rather than every attempt landing on `PARTITION_NONE`. | ||
| 7185 | + #[test] | ||
| 7186 | + fn a_real_aomenc_stream_with_a_sub8_split_decodes_pixel_exact() { | ||
| 7187 | + if !have_ffmpeg() { | ||
| 7188 | + eprintln!("SKIP a_real_aomenc_stream_with_a_sub8_split_decodes_pixel_exact: no ffmpeg"); | ||
| 7189 | + return; | ||
| 7190 | + } | ||
| 7191 | + if !have_aomenc() { | ||
| 7192 | + let msg = format!( | ||
| 7193 | + "no aomenc at {}", | ||
| 7194 | + aomenc_path().display() | ||
| 7195 | + ); | ||
| 7196 | + assert!( | ||
| 7197 | + std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none(), | ||
| 7198 | + "EC_AV1_REQUIRE_AOMENC is set but {msg}" | ||
| 7199 | + ); | ||
| 7200 | + eprintln!("SKIP a_real_aomenc_stream_with_a_sub8_split_decodes_pixel_exact: {msg}"); | ||
| 7201 | + return; | ||
| 7202 | + } | ||
| 7203 | + let (width, height) = (64usize, 64usize); | ||
| 7204 | + let mut refusals = Vec::new(); | ||
| 7205 | + let mut fired_runs = 0u32; | ||
| 7206 | + for attempt in 0..40u32 { | ||
| 7207 | + let seed = 100 + attempt; | ||
| 7208 | + let cq = 6 + (attempt % 4) * 2; | ||
| 7209 | + let y4m = Command::new("ffmpeg") | ||
| 7210 | + .args([ | ||
| 7211 | + "-v", | ||
| 7212 | + "error", | ||
| 7213 | + "-f", | ||
| 7214 | + "lavfi", | ||
| 7215 | + "-i", | ||
| 7216 | + &gradients_source(seed, width, height, "rate=25"), | ||
| 7217 | + "-vf", | ||
| 7218 | + "noise=alls=40:allf=t,format=yuv420p", | ||
| 7219 | + "-t", | ||
| 7220 | + "0.04", | ||
| 7221 | + "-f", | ||
| 7222 | + "yuv4mpegpipe", | ||
| 7223 | + "-", | ||
| 7224 | + ]) | ||
| 7225 | + .stdin(Stdio::null()) | ||
| 7226 | + .stdout(Stdio::piped()) | ||
| 7227 | + .stderr(Stdio::piped()) | ||
| 7228 | + .output() | ||
| 7229 | + .expect("ffmpeg failed to run"); | ||
| 7230 | + assert!( | ||
| 7231 | + y4m.status.success(), | ||
| 7232 | + "ffmpeg fixture: {}", | ||
| 7233 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 7234 | + ); | ||
| 7235 | + let mut child = Command::new(aomenc_path()) | ||
| 7236 | + .args([ | ||
| 7237 | + "--codec=av1", | ||
| 7238 | + "--passes=1", | ||
| 7239 | + "--end-usage=q", | ||
| 7240 | + &format!("--cq-level={cq}"), | ||
| 7241 | + "--cpu-used=0", | ||
| 7242 | + "--threads=1", | ||
| 7243 | + "--row-mt=0", | ||
| 7244 | + "--sb-size=64", | ||
| 7245 | + "--min-partition-size=4", | ||
| 7246 | + "--max-partition-size=8", | ||
| 7247 | + "--enable-ab-partitions=0", | ||
| 7248 | + "--enable-1to4-partitions=1", | ||
| 7249 | + "--enable-palette=0", | ||
| 7250 | + "--enable-intrabc=0", | ||
| 7251 | + "--enable-restoration=0", | ||
| 7252 | + "--enable-cdef=0", | ||
| 7253 | + "--loopfilter-control=0", | ||
| 7254 | + // use_ref_frame_mvs (temporal MV projection) is unimplemented in | ||
| 7255 | + // mvstack; this is a key-frame-only fixture, but keep it off for | ||
| 7256 | + // safety against a run that emits a second frame. | ||
| 7257 | + "--enable-ref-frame-mvs=0", | ||
| 7258 | + "--limit=1", | ||
| 7259 | + "--obu", | ||
| 7260 | + "-o", | ||
| 7261 | + "-", | ||
| 7262 | + "-", | ||
| 7263 | + ]) | ||
| 7264 | + .stdin(Stdio::piped()) | ||
| 7265 | + .stdout(Stdio::piped()) | ||
| 7266 | + .stderr(Stdio::piped()) | ||
| 7267 | + .spawn() | ||
| 7268 | + .expect("aomenc failed to start"); | ||
| 7269 | + child | ||
| 7270 | + .stdin | ||
| 7271 | + .take() | ||
| 7272 | + .expect("aomenc stdin") | ||
| 7273 | + .write_all(&y4m.stdout) | ||
| 7274 | + .expect("writing y4m to aomenc"); | ||
| 7275 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 7276 | + if !out.status.success() { | ||
| 7277 | + refusals.push(format!( | ||
| 7278 | + "seed={seed} cq={cq}: aomenc itself refused the fixture" | ||
| 7279 | + )); | ||
| 7280 | + continue; | ||
| 7281 | + } | ||
| 7282 | + let stream = out.stdout; | ||
| 7283 | + let before = decode::sub8_split_hits(); | ||
| 7284 | + let frames = match decode_stream(&stream) { | ||
| 7285 | + Ok(frames) => frames, | ||
| 7286 | + Err(e) => { | ||
| 7287 | + refusals.push(format!("seed={seed} cq={cq}: {e}")); | ||
| 7288 | + continue; | ||
| 7289 | + } | ||
| 7290 | + }; | ||
| 7291 | + if decode::sub8_split_hits() == before { | ||
| 7292 | + refusals.push(format!( | ||
| 7293 | + "seed={seed} cq={cq}: decoded, but no block read a real PARTITION_SPLIT below 8x8" | ||
| 7294 | + )); | ||
| 7295 | + continue; | ||
| 7296 | + } | ||
| 7297 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); | ||
| 7298 | + assert_eq!( | ||
| 7299 | + frames[0].y, ffmpeg_frames[0].y, | ||
| 7300 | + "luma vs ffmpeg (seed={seed} cq={cq})" | ||
| 7301 | + ); | ||
| 7302 | + assert_eq!( | ||
| 7303 | + frames[0].u, ffmpeg_frames[0].u, | ||
| 7304 | + "U vs ffmpeg (seed={seed} cq={cq})" | ||
| 7305 | + ); | ||
| 7306 | + assert_eq!( | ||
| 7307 | + frames[0].v, ffmpeg_frames[0].v, | ||
| 7308 | + "V vs ffmpeg (seed={seed} cq={cq})" | ||
| 7309 | + ); | ||
| 7310 | + fired_runs += 1; | ||
| 7311 | + if fired_runs >= 4 { | ||
| 7312 | + return; | ||
| 7313 | + } | ||
| 7314 | + } | ||
| 7315 | + panic!( | ||
| 7316 | + "fewer than 4 firing+pixel-exact runs out of 40 attempts:\n{}", | ||
| 7317 | + refusals.join("\n") | ||
| 7318 | + ); | ||
| 7319 | + } | ||
| 7320 | + | ||
| 7177 | /// lane-av1golden7 r9's decisive fixture: a real aomenc stream (seed 59, | 7321 | /// lane-av1golden7 r9's decisive fixture: a real aomenc stream (seed 59, |
| 7178 | /// `--tune-content=film`, GOLDEN_FRAME firing downstream) whose frame-0 | 7322 | /// `--tune-content=film`, GOLDEN_FRAME firing downstream) whose frame-0 |
| 7179 | /// *intra keyframe* mismatched ffmpeg on 3855/4096 luma pixels -- traced | 7323 | /// *intra keyframe* mismatched ffmpeg on 3855/4096 luma pixels -- traced |