diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 7fb70d3d..ea4a8fc4 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -40943,7 +40943,7 @@ mod tests { // duplicating `crate::encode`'s own `#[cfg(test)]` helpers of the same // name (that module is another lane's territory this round, and the // helpers are `#[cfg(test)]`-private to it). - use std::io::Write; + use crate::probe::run_with_stdin; use std::process::{Command, Stdio}; /// Whether ffmpeg is on PATH. Absence normally SKIPs, but @@ -40972,32 +40972,12 @@ mod tests { /// Decodes one AV1 OBU stream with ffmpeg and hands back its one 4:2:0 /// frame's planes, at ffmpeg's own (coded, block-padded) size. fn ffmpeg_decode(stream: &[u8], width: usize, height: usize) -> Picture { - let mut child = Command::new("ffmpeg") - .args([ + let out = run_with_stdin( + Command::new("ffmpeg").args([ "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("ffmpeg failed to start"); - // lane-t900 r10: the stream goes down stdin on ITS OWN THREAD. Writing - // it inline deadlocks the moment ffmpeg's stdout pipe buffer (64 KiB) - // fills before the last input byte is written -- which is exactly what - // a 1.1 MB fixture decoding to 150 MB of raw 10-bit frames does - // (measured: 45 min, both processes at 0% CPU). A write error here is - // swallowed on purpose: ffmpeg's own exit status and stderr, asserted - // below, are the real diagnosis. - let mut stdin = child.stdin.take().expect("ffmpeg stdin"); - let payload = stream.to_vec(); - let writer = std::thread::Builder::new() - .name("ec-av1-ffmpeg-in".into()) - .spawn(move || { - let _ = stdin.write_all(&payload); - }) - .expect("spawning the ffmpeg stdin writer"); - let out = child.wait_with_output().expect("ffmpeg failed to run"); - writer.join().expect("ffmpeg stdin writer thread"); + ]), + stream, + ); assert!( out.status.success(), "ffmpeg refused the stream: {}", @@ -41025,32 +41005,12 @@ mod tests { height: usize, frames: usize, ) -> Vec { - let mut child = Command::new("ffmpeg") - .args([ + let out = run_with_stdin( + Command::new("ffmpeg").args([ "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("ffmpeg failed to start"); - // lane-t900 r10: the stream goes down stdin on ITS OWN THREAD. Writing - // it inline deadlocks the moment ffmpeg's stdout pipe buffer (64 KiB) - // fills before the last input byte is written -- which is exactly what - // a 1.1 MB fixture decoding to 150 MB of raw 10-bit frames does - // (measured: 45 min, both processes at 0% CPU). A write error here is - // swallowed on purpose: ffmpeg's own exit status and stderr, asserted - // below, are the real diagnosis. - let mut stdin = child.stdin.take().expect("ffmpeg stdin"); - let payload = stream.to_vec(); - let writer = std::thread::Builder::new() - .name("ec-av1-ffmpeg-in".into()) - .spawn(move || { - let _ = stdin.write_all(&payload); - }) - .expect("spawning the ffmpeg stdin writer"); - let out = child.wait_with_output().expect("ffmpeg failed to run"); - writer.join().expect("ffmpeg stdin writer thread"); + ]), + stream, + ); assert!( out.status.success(), "ffmpeg refused the stream: {}", diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 7aa68273..0f859a22 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -15101,7 +15101,7 @@ mod tests { } use super::*; use crate::intra::{D45_PRED, D135_PRED, H_PRED, KEY_FRAME_MODES, NON_DIRECTIONAL, V_PRED}; - use std::io::Write; + use crate::probe::run_with_stdin; use std::process::{Command, Stdio}; /// Every rectangular shape this decoder codes, at every position a block @@ -15260,29 +15260,12 @@ mod tests { /// Decodes an AV1 OBU stream with ffmpeg and hands back the three planes. fn ffmpeg_decode(stream: &[u8], width: usize, height: usize) -> Picture { - let mut child = Command::new("ffmpeg") - .args([ + let out = run_with_stdin( + Command::new("ffmpeg").args([ "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("ffmpeg failed to start"); - // lane-t900 r10: the stream goes down stdin on ITS OWN THREAD. Writing - // it inline deadlocks the moment ffmpeg's stdout pipe buffer (64 KiB) - // fills before the last input byte is written -- which is exactly what - // a 1.1 MB fixture decoding to 150 MB of raw 10-bit frames does - // (measured: 45 min, both processes at 0% CPU). A write error here is - // swallowed on purpose: ffmpeg's own exit status and stderr, asserted - // below, are the real diagnosis. - let mut stdin = child.stdin.take().expect("ffmpeg stdin"); - let payload = stream.to_vec(); - let writer = std::thread::spawn(move || { - let _ = stdin.write_all(&payload); - }); - let out = child.wait_with_output().expect("ffmpeg failed to run"); - writer.join().expect("ffmpeg stdin writer thread"); + ]), + stream, + ); assert!( out.status.success(), "ffmpeg refused the stream: {}", @@ -17231,29 +17214,12 @@ mod tests { height: usize, frames: usize, ) -> Vec { - let mut child = Command::new("ffmpeg") - .args([ + let out = run_with_stdin( + Command::new("ffmpeg").args([ "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("ffmpeg failed to start"); - // lane-t900 r10: the stream goes down stdin on ITS OWN THREAD. Writing - // it inline deadlocks the moment ffmpeg's stdout pipe buffer (64 KiB) - // fills before the last input byte is written -- which is exactly what - // a 1.1 MB fixture decoding to 150 MB of raw 10-bit frames does - // (measured: 45 min, both processes at 0% CPU). A write error here is - // swallowed on purpose: ffmpeg's own exit status and stderr, asserted - // below, are the real diagnosis. - let mut stdin = child.stdin.take().expect("ffmpeg stdin"); - let payload = stream.to_vec(); - let writer = std::thread::spawn(move || { - let _ = stdin.write_all(&payload); - }); - let out = child.wait_with_output().expect("ffmpeg failed to run"); - writer.join().expect("ffmpeg stdin writer thread"); + ]), + stream, + ); assert!( out.status.success(), "ffmpeg refused the stream: {}", diff --git a/crates/ec-av1/src/probe.rs b/crates/ec-av1/src/probe.rs index d7159055..10767659 100644 --- a/crates/ec-av1/src/probe.rs +++ b/crates/ec-av1/src/probe.rs @@ -22,7 +22,10 @@ pub fn dims(clip: &str) -> Option<(usize, usize)> { .ok()?; let text = String::from_utf8_lossy(&out.stdout); let mut f = text.trim().split(','); - Some((f.next()?.trim().parse().ok()?, f.next()?.trim().parse().ok()?)) + Some(( + f.next()?.trim().parse().ok()?, + f.next()?.trim().parse().ok()?, + )) } /// The native BD gate's window on `clip`: a whole number of 128-wide @@ -41,7 +44,10 @@ pub fn gate_crop(clip: &str) -> (String, usize, usize) { let (nw, nh) = dims(clip).expect("ffprobe gave no size"); let cw = nw.min(1920) / 128 * 128; let ch = nh.min(1024) / 128 * 128; - assert!(cw >= 128 && ch >= 128, "{nw}x{nh} is smaller than a superblock"); + assert!( + cw >= 128 && ch >= 128, + "{nw}x{nh} is smaller than a superblock" + ); let (x, y) = ((nw - cw) / 2 & !1, (nh - ch) / 2 & !1); (format!("crop={cw}:{ch}:{x}:{y}"), cw, ch) } @@ -67,10 +73,18 @@ pub fn source( .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"]) .output() .expect("ffmpeg failed to run"); - assert!(out.status.success(), "ffmpeg: {}", String::from_utf8_lossy(&out.stderr)); + assert!( + out.status.success(), + "ffmpeg: {}", + String::from_utf8_lossy(&out.stderr) + ); let (luma, chroma) = (width * height, width * height / 4); let frame_len = luma + 2 * chroma; - assert_eq!(out.stdout.len(), frame_len * frames, "expected {frames} 4:2:0 frames"); + assert_eq!( + out.stdout.len(), + frame_len * frames, + "expected {frames} 4:2:0 frames" + ); (0..frames) .map(|i| { let b = &out.stdout[i * frame_len..][..frame_len]; @@ -78,9 +92,54 @@ pub fn source( width, height, y: b[..luma].iter().map(|&v| u16::from(v)).collect(), - u: b[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), + u: b[luma..luma + chroma] + .iter() + .map(|&v| u16::from(v)) + .collect(), v: b[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), } }) .collect() } + +/// Runs a test-harness child (`aomenc`, `ffmpeg`) with `input` on its stdin +/// and all three pipes drained concurrently, returning the child's +/// [`std::process::Output`] (status, stdout, stderr) for the caller to +/// assert on. +/// +/// The ONE spawn path for every test that feeds a child on stdin +/// (lane-av1-pipedrain). Writing the input INLINE before +/// `wait_with_output()` deadlocks as soon as the child's stdout pipe buffer +/// (~64 KiB) fills before the last input byte is written: the child blocks +/// in write(2), the test blocks in `write_all`, both at 0% CPU until the +/// harness timeout -- measured at 45 minutes on a 1.1 MB fixture decoding +/// to 150 MB of raw frames (lane-t900 r10), and four aomenc gates still sat +/// on the inline pattern after that fix. Here a writer thread owns stdin +/// while the parent drains stdout/stderr, so a multi-MB y4m always meets a +/// reader, never a blocked writer. +/// +/// A child that exits early (bad flags, refused input) breaks the writer's +/// pipe: the EPIPE from `write_all` is swallowed on purpose, and the +/// child's own exit status and stderr -- which the caller asserts on -- +/// carry the real diagnosis. +/// +/// # Panics +/// When the child cannot be spawned or reaped, or the writer thread panics. +#[cfg(test)] +pub(crate) fn run_with_stdin(cmd: &mut Command, input: &[u8]) -> std::process::Output { + use std::io::Write; + use std::process::Stdio; + + cmd.stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()); + let mut child = cmd.spawn().expect("encoder failed to start"); + let mut stdin = child.stdin.take().expect("encoder stdin"); + let payload = input.to_vec(); + let writer = std::thread::spawn(move || { + let _ = stdin.write_all(&payload); + }); + let out = child.wait_with_output().expect("encoder failed to run"); + writer.join().expect("encoder stdin writer thread"); + out +} diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 52c63231..1dcca8c2 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -2489,15 +2489,8 @@ pub(crate) mod tests { args.push(limit); args.extend(extra.iter().map(|s| (*s).to_owned())); args.extend(["--obu".to_owned(), "-o".to_owned(), "-".to_owned(), "-".to_owned()]); - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child.stdin.take().expect("aomenc stdin").write_all(&y4m.stdout).expect("write y4m"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!(out.status.success(), "aomenc refused {args:?}: {}", String::from_utf8_lossy(&out.stderr)); let stream = out.stdout; let result = match decode_stream(&stream) { @@ -2578,15 +2571,8 @@ pub(crate) mod tests { .collect(); args.insert(1, limit); args.extend(extra.iter().map(|s| (*s).to_owned())); - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child.stdin.take().expect("aomenc stdin").write_all(&y4m.stdout).expect("write y4m"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "{NAME}: aomenc refused {args:?}: {}", @@ -2614,20 +2600,10 @@ pub(crate) mod tests { mixed_arms += 1; // (3) libaom accepts it: ffmpeg's own libaom decoder produces the // stream without an error. - let mut ff = Command::new("ffmpeg") - .args(["-v", "error", "-f", "obu", "-i", "-", "-f", "null", "-"]) - .stdin(Stdio::piped()) - .stdout(Stdio::null()) - .stderr(Stdio::piped()) - .spawn() - .expect("ffmpeg failed to start"); - let mut stdin = ff.stdin.take().expect("ffmpeg stdin"); - let payload = stream.clone(); - let writer = std::thread::spawn(move || { - let _ = stdin.write_all(&payload); - }); - let out = ff.wait_with_output().expect("ffmpeg failed to run"); - writer.join().expect("ffmpeg stdin writer"); + let out = run_with_stdin( + Command::new("ffmpeg").args(["-v", "error", "-f", "obu", "-i", "-", "-f", "null", "-"]), + &stream, + ); assert!( out.status.success(), "{NAME}: ffmpeg refused a stream with {mixed} mixed-frame(s): {}", @@ -3228,7 +3204,7 @@ pub(crate) mod tests { let input_depth_arg = format!("--input-bit-depth={bit_depth}"); let cq_arg = format!("--cq-level={cq}"); let limit_arg = format!("--limit={frames}"); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, // cpu-used >= 1 keeps libaom on 64x64 superblocks at these @@ -3255,19 +3231,7 @@ pub(crate) mod tests { "--enable-paeth-intra=0", "--enable-filter-intra=0", "--enable-tx-size-search=0", "--obu", "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("write y4m"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused: {}", @@ -3426,20 +3390,13 @@ pub(crate) mod tests { .output() .expect("ffmpeg failed to run"); assert!(y4m.status.success(), "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr)); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32", "--cpu-used=0", "--sb-size=128", "--min-partition-size=16", "--kf-max-dist=0", "--limit=1", "--threads=1", "--row-mt=0", "--obu", "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child.stdin.take().expect("aomenc stdin").write_all(&y4m.stdout).expect("write y4m"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!(out.status.success(), "aomenc refused: {}", String::from_utf8_lossy(&out.stderr)); let stream = out.stdout; @@ -3625,7 +3582,7 @@ pub(crate) mod tests { assert!(format!("{err}").contains("sink says stop"), "{err}"); } - use std::io::Write; + use crate::probe::run_with_stdin; use std::process::{Command, Stdio}; /// Firing-detection gates (single-ref envelope, temporal-MV, `comp_mode`, @@ -3699,32 +3656,12 @@ pub(crate) mod tests { height: usize, frames: usize, ) -> Vec { - let mut child = Command::new("ffmpeg") - .args([ + let out = run_with_stdin( + Command::new("ffmpeg").args([ "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("ffmpeg failed to start"); - // lane-t900 r10: the stream goes down stdin on ITS OWN THREAD. Writing - // it inline deadlocks the moment ffmpeg's stdout pipe buffer (64 KiB) - // fills before the last input byte is written -- which is exactly what - // a 1.1 MB fixture decoding to 150 MB of raw 10-bit frames does - // (measured: 45 min, both processes at 0% CPU). A write error here is - // swallowed on purpose: ffmpeg's own exit status and stderr, asserted - // below, are the real diagnosis. - let mut stdin = child.stdin.take().expect("ffmpeg stdin"); - let payload = stream.to_vec(); - let writer = std::thread::Builder::new() - .name("ec-av1-ffmpeg-in".into()) - .spawn(move || { - let _ = stdin.write_all(&payload); - }) - .expect("spawning the ffmpeg stdin writer"); - let out = child.wait_with_output().expect("ffmpeg failed to run"); - writer.join().expect("ffmpeg stdin writer thread"); + ]), + stream, + ); assert!( out.status.success(), "ffmpeg refused the stream: {}", @@ -3754,33 +3691,20 @@ pub(crate) mod tests { /// As [`ffmpeg_decode_sequence`], for a MONOCHROME stream: one 8-bit luma /// plane per frame, exactly what `ffmpeg -pix_fmt gray -f rawvideo` writes - /// (lane-av1mono). Fed down a stdin writer thread for the reason the 4:2:0 - /// helper documents. + /// (lane-av1mono). Fed through [`run_with_stdin`] for the reason its doc + /// records. fn ffmpeg_decode_gray_sequence( stream: &[u8], width: usize, height: usize, frames: usize, ) -> Vec { - let mut child = Command::new("ffmpeg") - .args([ + let out = run_with_stdin( + Command::new("ffmpeg").args([ "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "gray", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("ffmpeg failed to start"); - let mut stdin = child.stdin.take().expect("ffmpeg stdin"); - let payload = stream.to_vec(); - let writer = std::thread::Builder::new() - .name("ec-av1-ffmpeg-gray-in".into()) - .spawn(move || { - let _ = stdin.write_all(&payload); - }) - .expect("spawning the ffmpeg stdin writer"); - let out = child.wait_with_output().expect("ffmpeg failed to run"); - writer.join().expect("ffmpeg stdin writer thread"); + ]), + stream, + ); assert!( out.status.success(), "ffmpeg refused the monochrome stream: {}", @@ -3806,33 +3730,13 @@ pub(crate) mod tests { height: usize, frames: usize, ) -> Vec { - let mut child = Command::new("ffmpeg") - .args([ + let out = run_with_stdin( + Command::new("ffmpeg").args([ "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p10le", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("ffmpeg failed to start"); - // lane-t900 r10: the stream goes down stdin on ITS OWN THREAD. Writing - // it inline deadlocks the moment ffmpeg's stdout pipe buffer (64 KiB) - // fills before the last input byte is written -- which is exactly what - // a 1.1 MB fixture decoding to 150 MB of raw 10-bit frames does - // (measured: 45 min, both processes at 0% CPU). A write error here is - // swallowed on purpose: ffmpeg's own exit status and stderr, asserted - // below, are the real diagnosis. - let mut stdin = child.stdin.take().expect("ffmpeg stdin"); - let payload = stream.to_vec(); - let writer = std::thread::Builder::new() - .name("ec-av1-ffmpeg-in".into()) - .spawn(move || { - let _ = stdin.write_all(&payload); - }) - .expect("spawning the ffmpeg stdin writer"); - let out = child.wait_with_output().expect("ffmpeg failed to run"); - writer.join().expect("ffmpeg stdin writer thread"); + ]), + stream, + ); assert!( out.status.success(), "ffmpeg refused the stream: {}", @@ -5041,7 +4945,7 @@ pub(crate) mod tests { .expect("ffmpeg failed to run"); assert!(out.status.success(), "ffmpeg failed for testsrc2 {width}x{height}"); let y4m = out.stdout; - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args(["--codec=av1", "--bit-depth=8", "--input-bit-depth=8"]) .args([ "--passes=1", @@ -5056,19 +4960,7 @@ pub(crate) mod tests { "--enable-1to4-partitions=1", ]) .args(extra) - .args(["--obu", "-o", "-", "-"]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m) - .expect("aomenc stdin write"); - let out = child.wait_with_output().expect("aomenc failed to run"); + .args(["--obu", "-o", "-", "-"]), &y4m); assert!(out.status.success(), "aomenc failed: {}", String::from_utf8_lossy(&out.stderr)); out.stdout } @@ -5616,20 +5508,8 @@ pub(crate) mod tests { } let mut arm: Vec<&str> = vec!["--arnr-maxframes=0"]; arm.extend_from_slice(args); - let mut child = Command::new(aomenc_path()) - .args(&arm) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(y4m) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&arm), &y4m); assert!( out.status.success(), "{name} HIDDEN-ARM: aomenc refused its own recipe plus --arnr-maxframes=0: {}", @@ -5700,7 +5580,7 @@ pub(crate) mod tests { ); let depth_arg = format!("--bit-depth={bit_depth}"); let input_depth_arg = format!("--input-bit-depth={bit_depth}"); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ // lane-defon r1: the repo's only gate that decodes hidden // frames is also the only place a FORWARD KEYFRAME can be @@ -5760,19 +5640,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "{NAME}: aomenc refused the {bit_depth}-bit fixture: {}", @@ -5867,7 +5735,7 @@ pub(crate) mod tests { "ffmpeg refused to generate the y4m fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -5897,19 +5765,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing the y4m fixture to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -6021,7 +5877,7 @@ pub(crate) mod tests { "smptebars must render byte-identical across two runs" ); let y4m = y4m_a; - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -6053,19 +5909,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -6156,7 +6000,7 @@ pub(crate) mod tests { let y4m = y4m_a; let depth_arg = format!("--bit-depth={depth}"); let input_depth_arg = format!("--input-bit-depth={depth}"); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -6189,19 +6033,7 @@ pub(crate) mod tests { // Per-arm overrides go AFTER the base recipe: aomenc keeps the // LAST occurrence of a repeated flag. .args([&depth_arg, &input_depth_arg]) - .args(["--obu", "-o", "-", "-"]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + .args(["--obu", "-o", "-", "-"]), &y4m); assert!( out.status.success(), "{NAME}: aomenc refused the {depth}-bit fixture: {}", @@ -6302,7 +6134,7 @@ pub(crate) mod tests { let cq_arg = format!("--cq-level={cq}"); let txs_arg = format!("--enable-tx-size-search={txs}"); let tiles_arg = format!("--tile-columns={tiles}"); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -6324,23 +6156,7 @@ pub(crate) mod tests { // aomenc keeps the LAST occurrence of a repeated flag, // so per-arm overrides go after the base recipe. .args([&depth_arg, &input_depth_arg, &cq_arg, &txs_arg, &tiles_arg]) - .args(["--obu", "-o", "-", "-"]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m) - .or_else(|e| match e.kind() { - std::io::ErrorKind::BrokenPipe => Ok(()), - _ => Err(e), - }) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + .args(["--obu", "-o", "-", "-"]), &y4m); assert!( out.status.success(), "{NAME}: aomenc refused {arm}: {}", @@ -6553,7 +6369,7 @@ pub(crate) mod tests { let y4m_b = render(); assert_eq!(y4m_a, y4m_b, "{NAME}: {arm} must render byte-identical across two runs"); let y4m = y4m_a; - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--bit-depth=8", @@ -6580,23 +6396,7 @@ pub(crate) mod tests { ]) // aomenc keeps the LAST occurrence of a repeated flag. .args(*extra) - .args(["--obu", "-o", "-", "-"]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m) - .or_else(|e| match e.kind() { - std::io::ErrorKind::BrokenPipe => Ok(()), - _ => Err(e), - }) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + .args(["--obu", "-o", "-", "-"]), &y4m); assert!( out.status.success(), "{NAME}: aomenc refused {arm}: {}", @@ -6752,7 +6552,7 @@ pub(crate) mod tests { .output() .expect("ffmpeg") .stdout; - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--bit-depth=8", "--input-bit-depth=8", "--passes=1", "--end-usage=q", "--cpu-used=0", "--lag-in-frames=0", "--kf-max-dist=1", @@ -6761,14 +6561,7 @@ pub(crate) mod tests { "--min-partition-size=4", "--max-partition-size=64", "--sb-size=64", "--tune-content=screen", "--enable-intrabc=1", "--cq-level=60", "--enable-palette=1", "--enable-tx-size-search=0", "--obu", "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc"); - child.stdin.take().unwrap().write_all(&y4m).ok(); - let out = child.wait_with_output().expect("aomenc wait"); + ]), &y4m); assert!(out.status.success(), "{NAME}: aomenc failed"); crate::decode::reset_rect4_16_pair_hits(); let frames = decode_stream(&out.stdout).unwrap_or_else(|e| panic!("{NAME}: {e}")); @@ -6807,20 +6600,13 @@ pub(crate) mod tests { .output() .expect("ffmpeg") .stdout; - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--cpu-used=0", "--lossless=1", "--sb-size=128", "--lag-in-frames=0", "--kf-max-dist=1", "--limit=1", "--threads=1", "--passes=1", "--enable-1to4-partitions=1", "--min-partition-size=4", "--enable-rect-partitions=1", "--obu", "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc"); - child.stdin.take().unwrap().write_all(&y4m).ok(); - let out = child.wait_with_output().expect("aomenc wait"); + ]), &y4m); assert!(out.status.success(), "{NAME}: aomenc failed"); crate::decode::reset_rect4_16_pair_hits(); let frames = decode_stream(&out.stdout).unwrap_or_else(|e| panic!("{NAME}: {e}")); @@ -6916,7 +6702,7 @@ pub(crate) mod tests { out.stdout }; let y4m = render(); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--bit-depth=8", @@ -6939,23 +6725,7 @@ pub(crate) mod tests { ]) // aomenc keeps the LAST occurrence of a repeated flag. .args(*extra) - .args(["--obu", "-o", "-", "-"]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m) - .or_else(|e| match e.kind() { - std::io::ErrorKind::BrokenPipe => Ok(()), - _ => Err(e), - }) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + .args(["--obu", "-o", "-", "-"]), &y4m); assert!( out.status.success(), "{NAME}: aomenc refused {arm}: {}", @@ -7040,7 +6810,7 @@ pub(crate) mod tests { assert!(out.status.success(), "{NAME}: ffmpeg failed for {arm}"); out.stdout }; - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--bit-depth=8", "--input-bit-depth=8", "--passes=1", "--end-usage=q", "--cpu-used=0", "--lag-in-frames=0", "--kf-max-dist=1", @@ -7051,23 +6821,7 @@ pub(crate) mod tests { ]) // aomenc keeps the LAST occurrence of a repeated flag. .args(*extra) - .args(["--obu", "-o", "-", "-"]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m) - .or_else(|e| match e.kind() { - std::io::ErrorKind::BrokenPipe => Ok(()), - _ => Err(e), - }) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + .args(["--obu", "-o", "-", "-"]), &y4m); assert!( out.status.success(), "{NAME}: aomenc refused {arm}: {}", @@ -7181,7 +6935,7 @@ pub(crate) mod tests { .expect("ffmpeg failed to run"); assert!(out.status.success(), "ffmpeg failed for {src}"); let y4m = out.stdout; - let mut child = Command::new(aomenc_path()) + let enc = run_with_stdin(Command::new(aomenc_path()) .args(["--codec=av1"]) .args([format!("--bit-depth={depth}"), format!("--input-bit-depth={depth}")]) .args([ @@ -7208,23 +6962,7 @@ pub(crate) mod tests { &[][..] }) .args(extra) - .args(["--obu", "-o", "-", "-"]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m) - .or_else(|e| match e.kind() { - std::io::ErrorKind::BrokenPipe => Ok(()), - _ => Err(e), - }) - .expect("writing y4m to aomenc"); - let enc = child.wait_with_output().expect("aomenc failed to run"); + .args(["--obu", "-o", "-", "-"]), &y4m); assert!( enc.status.success(), "aomenc refused {src} cq={cq}: {}", @@ -7911,7 +7649,7 @@ pub(crate) mod tests { let y4m = y4m_a; let depth_arg = format!("--bit-depth={depth}"); let in_depth_arg = format!("--input-bit-depth={depth}"); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args(["--codec=av1"]) .args([&depth_arg, &in_depth_arg]) .args([ @@ -7939,25 +7677,7 @@ pub(crate) mod tests { // shape this gate is about; the 10-bit arms are the // untouched pinned recipe. .args(if depth == 8 { &["--sb-size=64"][..] } else { &[][..] }) - .args(["--obu", "-o", "-", "-"]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m) - .or_else(|e| match e.kind() { - // aomenc rejecting the input closes the pipe before we - // finish writing; its own stderr below is the report. - std::io::ErrorKind::BrokenPipe => Ok(()), - _ => Err(e), - }) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + .args(["--obu", "-o", "-", "-"]), &y4m); assert!( out.status.success(), "{NAME}: aomenc refused {arm} at {depth}-bit: {}", @@ -8092,7 +7812,7 @@ pub(crate) mod tests { "ffmpeg failed to render the 10-bit fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -8109,19 +7829,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the 10-bit fixture: {}", @@ -8200,7 +7908,7 @@ pub(crate) mod tests { "ffmpeg failed to render the 10-bit fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ // lane-defon r1: explicit on-value (aomenc keeps the FIRST // occurrence, so overrides go before the base list). @@ -8243,19 +7951,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the 10-bit fixture: {}", @@ -9520,20 +9216,8 @@ pub(crate) mod tests { ]); args.extend_from_slice(extra); args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "{name}: aomenc refused the 10-bit fixture: {}", @@ -9596,7 +9280,7 @@ pub(crate) mod tests { "testsrc2 must render byte-identical across two runs" ); let y4m = y4m_a; - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -9623,19 +9307,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -9716,7 +9388,7 @@ pub(crate) mod tests { String::from_utf8_lossy(&y4m.stderr) ); let cq_arg = format!("--cq-level={cq}"); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -9733,19 +9405,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture ({source} cq={cq}): {}", @@ -9884,7 +9544,7 @@ pub(crate) mod tests { String::from_utf8_lossy(&y4m.stderr) ); let cq_arg = format!("--cq-level={cq}"); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -9901,19 +9561,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture ({source} cq={cq}): {}", @@ -10041,7 +9689,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ // lane-defon r1: explicit on-value (aomenc keeps the FIRST // occurrence, so overrides go before the base list). @@ -10073,19 +9721,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -10192,7 +9828,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -10232,19 +9868,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -10432,7 +10056,7 @@ pub(crate) mod tests { // walks it too, so "no rect strip fired" cannot be an artefact of // one cq. let cq = format!("--cq-level={}", [30u32, 20, 12][(attempt / 5) as usize % 3]); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args(depth_args) .arg(&cpu) .arg(&cq) @@ -10502,19 +10126,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -10720,7 +10332,7 @@ pub(crate) mod tests { } else { &[] }; - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args(depth_args) .args([ // lane-defon r1: explicit on-value (aomenc keeps the FIRST @@ -10771,19 +10383,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -10979,7 +10579,7 @@ pub(crate) mod tests { } else { &[] }; - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args(depth_args) .args([ "--codec=av1", @@ -11035,19 +10635,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -11236,7 +10824,7 @@ pub(crate) mod tests { } else { &[] }; - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args(depth_args) .args([ "--codec=av1", @@ -11292,19 +10880,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -11499,7 +11075,7 @@ pub(crate) mod tests { } else { &[] }; - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args(depth_args) .args([ "--codec=av1", @@ -11555,19 +11131,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -12280,7 +11844,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -12310,19 +11874,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -12427,7 +11979,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -12455,19 +12007,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -12584,7 +12124,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ // lane-defon r1: explicit on-value (aomenc keeps the FIRST // occurrence, so overrides go before the base list). @@ -12627,19 +12167,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -12823,20 +12351,8 @@ pub(crate) mod tests { args.insert(1, "--input-bit-depth=10".to_string()); args.insert(1, "--bit-depth=10".to_string()); } - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "{name}: aomenc refused the fixture: {}", @@ -13160,20 +12676,8 @@ pub(crate) mod tests { args.insert(1, "--input-bit-depth=10".to_string()); args.insert(1, "--bit-depth=10".to_string()); } - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "{name}: aomenc refused the fixture: {}", @@ -13346,20 +12850,8 @@ pub(crate) mod tests { "--max-partition-size=64", "--obu", "-o", "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -13606,28 +13098,7 @@ pub(crate) mod tests { min_part, "--max-partition-size=64", "--obu", "-o", "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - // lane-gaterecipe r1: feed stdin from a THREAD. A - // single-threaded `write_all` then `wait_with_output` deadlocks - // the moment aomenc's stdout pipe fills before it has consumed - // the whole y4m -- exactly what the fine-quantiser firing arm - // does (one 384x256 cq-10 encode hung for 40 minutes). - let mut aom_stdin = child.stdin.take().expect("aomenc stdin"); - let y4m_bytes = y4m.stdout; - let feeder = std::thread::Builder::new() - .name("ec-av1-aomenc-in".into()) - .spawn(move || { - aom_stdin.write_all(&y4m_bytes).expect("writing y4m to aomenc"); - }) - .expect("spawning the aomenc stdin feeder"); - let out = child.wait_with_output().expect("aomenc failed to run"); - feeder.join().expect("y4m feeder thread"); + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -13850,20 +13321,8 @@ pub(crate) mod tests { "--min-partition-size=8", "--max-partition-size=32", "--obu", "-o", "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -14064,20 +13523,8 @@ pub(crate) mod tests { "--max-partition-size=64", "--obu", "-o", "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -14227,20 +13674,8 @@ pub(crate) mod tests { "--enable-intrabc=0", "--enable-cfl-intra=0", "--enable-ref-frame-mvs=0", "--obu", "-o", "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -14432,20 +13867,8 @@ pub(crate) mod tests { "--max-partition-size=32", "--obu", "-o", "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -14572,20 +13995,8 @@ pub(crate) mod tests { "--lag-in-frames=16", "--auto-alt-ref=1", "--arnr-maxframes=0", "--obu", "-o", "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -14731,20 +14142,8 @@ pub(crate) mod tests { "--max-partition-size=32", "--obu", "-o", "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -14941,20 +14340,8 @@ pub(crate) mod tests { &rect_arg, "--obu", "-o", "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "{NAME}: aomenc refused the fixture: {}", @@ -15184,20 +14571,8 @@ pub(crate) mod tests { obmc_arg, "--obu", "-o", "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -15444,20 +14819,8 @@ pub(crate) mod tests { "--max-partition-size=16", "--obu", "-o", "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -15684,20 +15047,8 @@ pub(crate) mod tests { "--max-partition-size=16", "--obu", "-o", "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -16029,20 +15380,8 @@ pub(crate) mod tests { &min_part_arg, "--max-partition-size=16", "--obu", "-o", "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -16297,20 +15636,8 @@ pub(crate) mod tests { "--max-partition-size=64", "--obu", "-o", "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -16443,7 +15770,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ // lane-defon r1: explicit on-value (aomenc keeps the FIRST // occurrence, so overrides go before the base list). @@ -16496,19 +15823,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -16630,7 +15945,7 @@ pub(crate) mod tests { "y4m fixture length mismatch (seed {seed})" ); let y4m_hash = fnv1a64(&y4m.stdout); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -16694,19 +16009,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -16969,7 +16272,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -17047,19 +16350,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -17243,20 +16534,8 @@ pub(crate) mod tests { let tail = args.split_off(args.len() - 3); args.extend_from_slice(extra_args); args.extend_from_slice(&tail); - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -17448,20 +16727,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -17690,20 +16957,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -17892,20 +17147,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -18107,20 +17350,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -18305,20 +17536,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -18474,20 +17693,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -18620,20 +17827,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -18759,20 +17954,8 @@ pub(crate) mod tests { args.push(arm.cq); args.extend_from_slice(&arm.extra); args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "{NAME} {}: aomenc refused the recipe: {}", @@ -18918,20 +18101,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -19010,20 +18181,8 @@ pub(crate) mod tests { "--min-partition-size=8", "--max-partition-size=64", ]); - let mut child = Command::new(aomenc_path()) - .args(&rect_args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&rect_args), &y4m.stdout); assert!( out.status.success(), "{NAME} RECT-ARM: aomenc refused its own recipe plus the rect overrides: {}", @@ -19217,20 +18376,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -19565,20 +18712,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -19792,20 +18927,7 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(affine_aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("affine aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(affine_aomenc_path()).args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -19953,20 +19075,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -20110,7 +19220,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--threads=1", "--row-mt=0", @@ -20123,19 +19233,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -20232,7 +19330,7 @@ pub(crate) mod tests { .expect("ffmpeg failed to run"); assert!(y4m.status.success(), "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr)); let encode = || { - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -20259,19 +19357,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -20349,7 +19435,7 @@ pub(crate) mod tests { let mut total_overrides = 0usize; for (rtx, filter_intra) in [("1", "0"), ("0", "1")] { let encode = || { - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32", "--cpu-used=4", "--threads=1", "--row-mt=0", "--sb-size=64", @@ -20361,19 +19447,7 @@ pub(crate) mod tests { &format!("--reduced-tx-type-set={rtx}"), "--min-partition-size=8", "--max-partition-size=32", "--obu", "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -20475,7 +19549,7 @@ pub(crate) mod tests { String::from_utf8_lossy(&y4m.stderr) ); let encode = || { - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=16", "--cpu-used=4", "--threads=1", "--row-mt=0", "--sb-size=64", @@ -20487,19 +19561,7 @@ pub(crate) mod tests { &format!("--input-bit-depth={depth}"), &format!("--bit-depth={depth}"), "--obu", "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture (depth={depth}): {}", @@ -20646,7 +19708,7 @@ pub(crate) mod tests { String::from_utf8_lossy(&y4m.stderr) ); let encode = || { - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=52", "--cpu-used=0", "--threads=1", "--row-mt=0", "--sb-size=128", @@ -20659,19 +19721,7 @@ pub(crate) mod tests { &format!("--input-bit-depth={depth}"), &format!("--bit-depth={depth}"), "--obu", "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture (depth={depth}): {}", @@ -20869,15 +19919,8 @@ pub(crate) mod tests { args.push("--bit-depth=10".into()); } args.extend(["--obu".into(), "-o".into(), "-".into(), "-".into()]); - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child.stdin.take().expect("aomenc stdin").write_all(&y4m.stdout).expect("y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!(out.status.success(), "aomenc refused {desc}: {}", String::from_utf8_lossy(&out.stderr)); out.stdout }; @@ -20993,7 +20036,7 @@ pub(crate) mod tests { let (width, height) = if start_x.contains("128x128") { (128usize, 128usize) } else { (64usize, 64usize) }; for cq in [16u32, 20, 24, 28, 32, 40, 50] { for rtx in ["0", "1"] { - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", "--end-usage=q", &format!("--cq-level={cq}"), "--cpu-used=4", "--threads=1", @@ -21004,11 +20047,7 @@ pub(crate) mod tests { &format!("--reduced-tx-type-set={rtx}"), "--min-partition-size=8", "--max-partition-size=32", "--obu", "-o", "-", "-", - ]) - .stdin(Stdio::piped()).stdout(Stdio::piped()).stderr(Stdio::piped()) - .spawn().expect("aomenc"); - child.stdin.take().unwrap().write_all(&y4m.stdout).unwrap(); - let out = child.wait_with_output().unwrap(); + ]), &y4m.stdout); assert!(out.status.success()); let stream = out.stdout; let before = crate::decode::rect_leaf_coeff_hits(); @@ -21171,20 +20210,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -21389,20 +20416,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -21592,20 +20607,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture (seed {seed}): {}", @@ -21849,20 +20852,8 @@ pub(crate) mod tests { args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); } args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -22044,20 +21035,8 @@ pub(crate) mod tests { args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); } args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -22289,20 +21268,8 @@ pub(crate) mod tests { args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); } args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -22509,20 +21476,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -22735,20 +21690,8 @@ pub(crate) mod tests { "--min-partition-size=16", "--max-partition-size=32", "--obu", "-o", "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -22903,7 +21846,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -22946,19 +21889,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -23212,20 +22143,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -23386,7 +22305,7 @@ pub(crate) mod tests { let depth_arg = format!("--bit-depth={bit_depth}"); let input_depth_arg = format!("--input-bit-depth={bit_depth}"); let cq_arg = format!("--cq-level={cq}"); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, // cpu-used >= 1 keeps libaom on 64x64 @@ -23424,19 +22343,7 @@ pub(crate) mod tests { "--enable-paeth-intra=0", "--enable-filter-intra=0", "--enable-tx-size-search=0", "--obu", "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("write y4m"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused: {}", @@ -23626,15 +22533,8 @@ pub(crate) mod tests { &max_part_arg, &min_part_arg, "--obu", "-o", "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child.stdin.take().expect("aomenc stdin").write_all(&y4m.stdout).expect("write y4m"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!(out.status.success(), "aomenc refused: {}", String::from_utf8_lossy(&out.stderr)); let stream = out.stdout; let frames = match decode_stream(&stream) { @@ -23755,15 +22655,8 @@ pub(crate) mod tests { "--enable-filter-intra=0", "--obu", "-o", "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child.stdin.take().unwrap().write_all(&y4m.stdout).unwrap(); - let out = child.wait_with_output().unwrap(); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!(out.status.success()); let stream = out.stdout; let frames = decode_stream(&stream).expect("decode"); @@ -24092,20 +22985,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -24269,8 +23150,8 @@ pub(crate) mod tests { let tiles = format!("--tile-columns={tile_columns}"); // class [[aomenc-last-flag-wins]]: every flag appears exactly // once below, so there is no override to order. - let out = { - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin( + Command::new(aomenc_path()) .args(depth_args) .arg(&cq) .arg(&sb) @@ -24320,20 +23201,9 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - child.wait_with_output().expect("aomenc failed to run") - }; + ]), + &y4m.stdout, + ); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -24634,7 +23504,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -24666,19 +23536,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); if !out.status.success() { refusals.push(format!( "cq={cq} period={period}: aomenc itself refused the fixture" @@ -24789,7 +23647,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -24823,19 +23681,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture (depth={depth} cq={cq})" @@ -24965,7 +23811,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -24999,19 +23845,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture (depth={depth} cq={cq})" @@ -25170,7 +24004,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -25206,19 +24040,7 @@ pub(crate) mod tests { "-", "-", ]) - .args(tile_args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + .args(tile_args), &y4m.stdout); if !out.status.success() { refusals.push(format!( "seed={seed} cq={cq}: aomenc itself refused the fixture" @@ -25366,7 +24188,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -25406,19 +24228,7 @@ pub(crate) mod tests { } else { &[][..] }) - .args(tile_args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + .args(tile_args), &y4m.stdout); if !out.status.success() { refusals.push(format!( "seed={seed} cq={cq}: aomenc itself refused the fixture" @@ -25559,7 +24369,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -25594,19 +24404,7 @@ pub(crate) mod tests { &["--input-bit-depth=10", "--bit-depth=10"][..] } else { &[][..] - }) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + }), &y4m.stdout); if !out.status.success() { refusals.push(format!("seed={seed} cq={cq}: aomenc itself refused")); continue; @@ -25782,7 +24580,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -25827,19 +24625,7 @@ pub(crate) mod tests { &["--input-bit-depth=10", "--bit-depth=10"][..] } else { &[][..] - }) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + }), &y4m.stdout); if !out.status.success() { refusals.push(format!( "seed={seed} cq={cq}: aomenc itself refused the fixture" @@ -26165,7 +24951,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -26213,19 +24999,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -26410,7 +25184,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -26448,19 +25222,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -26603,7 +25365,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -26637,19 +25399,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -26737,7 +25487,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -26771,19 +25521,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -26939,7 +25677,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -26973,19 +25711,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -27098,7 +25824,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -27133,19 +25859,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -27315,20 +26029,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -27523,20 +26225,8 @@ pub(crate) mod tests { args.extend(rate_args.iter().copied()); args.extend(depth_args.iter().map(String::as_str)); args.extend(["--obu", "-o", "-", "-"]); - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -27739,7 +26429,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -27788,19 +26478,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -27920,7 +26598,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -27956,19 +26634,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -28090,7 +26756,7 @@ pub(crate) mod tests { "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr) ); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -28125,19 +26791,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -28271,20 +26925,8 @@ pub(crate) mod tests { let mut args = base.clone(); args.extend_from_slice(extra); args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(y4m) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -28490,20 +27132,8 @@ pub(crate) mod tests { args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); } args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -28659,20 +27289,8 @@ pub(crate) mod tests { args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); } args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "{NAME}: aomenc refused the fixture: {}", @@ -28854,20 +27472,8 @@ pub(crate) mod tests { args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); } args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "{NAME}: aomenc refused the fixture: {}", @@ -29015,20 +27621,8 @@ pub(crate) mod tests { args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); } args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "{NAME}: aomenc refused the fixture: {}", @@ -29129,7 +27723,7 @@ pub(crate) mod tests { .stdout(Stdio::piped()) .output() .expect("ffmpeg"); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=40", "--cpu-used=2", "--threads=1", "--row-mt=0", "--sb-size=64", @@ -29138,14 +27732,7 @@ pub(crate) mod tests { "--enable-1to4-partitions=0", "--enable-palette=0", "--enable-intrabc=0", "--enable-tx-size-search=0", "--deltaq-mode=0", "--limit=8", "--obu", "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc"); - child.stdin.take().unwrap().write_all(&y4m.stdout).unwrap(); - let out = child.wait_with_output().expect("aomenc run"); + ]), &y4m.stdout); assert!(out.status.success()); let (frames, hidden) = decode_all_frames_vs_oracle(&out.stdout, "sb128-control-64"); eprintln!("control sb64: {frames} frames exact ({hidden} hidden)"); @@ -29243,20 +27830,8 @@ pub(crate) mod tests { args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); } args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "{NAME}: aomenc refused the fixture: {}", @@ -29416,20 +27991,8 @@ pub(crate) mod tests { args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); } args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "{NAME}: aomenc refused the fixture: {}", @@ -29579,20 +28142,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -29907,20 +28458,8 @@ pub(crate) mod tests { args.push(&tile_arg); } args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "{name}: aomenc refused the fixture: {}", @@ -30126,20 +28665,8 @@ pub(crate) mod tests { let mut args = base_args.clone(); args.extend_from_slice(extra); args.extend_from_slice(&["--obu", "-o", "-", "-"]); - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(y4m) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -30357,20 +28884,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -30579,20 +29094,8 @@ pub(crate) mod tests { "-", "-", ]); - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -30846,20 +29349,8 @@ pub(crate) mod tests { other => panic!("unknown EC_RECTSPLIT_OFF entry {other}"), }); } - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -31200,20 +29691,8 @@ pub(crate) mod tests { other => panic!("unknown EC_FISTRIP_OFF entry {other}"), }); } - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -31386,20 +29865,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -31564,20 +30031,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -31791,20 +30246,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -32028,20 +30471,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -32291,20 +30722,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -32547,20 +30966,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -32823,20 +31230,8 @@ pub(crate) mod tests { "-", "-", ]; - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -33070,20 +31465,8 @@ pub(crate) mod tests { args.extend(extra.iter().copied()); args.extend(depth_args.iter().map(String::as_str)); args.extend(["--obu", "-o", "-", "-"]); - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -33661,7 +32044,7 @@ pub(crate) mod tests { let cq_arg = format!("--cq-level={cq}"); let depth_arg = format!("--bit-depth={bit_depth}"); let input_depth_arg = format!("--input-bit-depth={bit_depth}"); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -33700,19 +32083,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "{NAME}: aomenc refused the fixture: {}", @@ -33828,7 +32199,7 @@ pub(crate) mod tests { ); let depth_arg = format!("--bit-depth={bit_depth}"); let input_depth_arg = format!("--input-bit-depth={bit_depth}"); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -33858,19 +32229,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "{NAME}: aomenc refused the fixture: {}", @@ -34030,7 +32389,7 @@ pub(crate) mod tests { String::from_utf8_lossy(&y4m.stderr) ); let encode = || { - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32", "--cpu-used=3", "--threads=1", "--row-mt=0", "--sb-size=64", @@ -34042,19 +32401,7 @@ pub(crate) mod tests { &format!("--input-bit-depth={depth}"), &format!("--bit-depth={depth}"), "--obu", "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture ({width}x{height}, depth={depth}): {}", @@ -34212,7 +32559,7 @@ pub(crate) mod tests { ); for cq in [20usize, 32, 45] { let encode = || { - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", "--end-usage=q", &format!("--cq-level={cq}"), @@ -34236,19 +32583,7 @@ pub(crate) mod tests { "--enable-smooth-intra=0", "--enable-paeth-intra=0", "--enable-filter-intra=0", "--enable-tx-size-search=0", "--obu", "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture ({width}x{height}, depth={depth}, \ @@ -34470,7 +32805,7 @@ pub(crate) mod tests { // The higher the quantiser the more 1:4 intra strips inside inter // frames, so the sweep walks cq 63 first. let cq = format!("--cq-level={}", [63u32, 55, 45, 35][(attempt / 4) as usize % 4]); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args(depth_args) .arg(&cpu) .arg(&cq) @@ -34536,19 +32871,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -34765,7 +33088,7 @@ pub(crate) mod tests { }; let cq_arg = format!("--cq-level={cq}"); let cpu_arg = format!("--cpu-used={cpu}"); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args(depth_args) .args([ "--codec=av1", @@ -34814,19 +33137,7 @@ pub(crate) mod tests { "-o", "-", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + ]), &y4m.stdout); assert!( out.status.success(), "aomenc refused the fixture: {}", @@ -34987,7 +33298,7 @@ pub(crate) mod tests { // refusal, and the arm's point is the coded syntax, not the input. let depth_arg = format!("--bit-depth={bit_depth}"); let cq_arg = format!("--cq-level={}", if bit_depth == 10 { 45 } else { 40 }); - let mut child = Command::new(aomenc_path()) + let out = run_with_stdin(Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", @@ -35012,23 +33323,7 @@ pub(crate) mod tests { "--enable-intrabc=0", ]) .args([&depth_arg, &cq_arg]) - .args(["--obu", "-o", "-", "-"]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .or_else(|e| match e.kind() { - std::io::ErrorKind::BrokenPipe => Ok(()), - _ => Err(e), - }) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + .args(["--obu", "-o", "-", "-"]), &y4m.stdout); assert!( out.status.success(), "{name}: aomenc refused the fixture: {}", @@ -36407,20 +34702,8 @@ pub(crate) mod tests { // AOMENC FLAG PRECEDENCE (COMMON): the per-arm override goes last. args.push(if tiles { "--tile-columns=1" } else { "--tile-columns=0" }); args.extend(["--obu", "-o", "-", "-"]); - let mut child = Command::new(aomenc_path()) - .args(&args) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("aomenc failed to start"); - child - .stdin - .take() - .expect("aomenc stdin") - .write_all(&y4m.stdout) - .expect("writing y4m to aomenc"); - let out = child.wait_with_output().expect("aomenc failed to run"); + let out = run_with_stdin(Command::new(aomenc_path()) + .args(&args), &y4m.stdout); assert!( out.status.success(), "{NAME}: aomenc refused the fixture (depth={depth} cq={cq} {width}x{height}): {}", diff --git a/crates/ec-av1/src/tile.rs b/crates/ec-av1/src/tile.rs index 93fde6bd..45429874 100644 --- a/crates/ec-av1/src/tile.rs +++ b/crates/ec-av1/src/tile.rs @@ -12,17 +12,17 @@ use std::cell::RefCell; #[cfg(test)] use std::collections::BTreeMap; -use std::sync::LazyLock; use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering}; +use std::sync::LazyLock; use ec_core::{Error, Result}; use crate::cdf; use crate::cdf_state::{Cdfs, MvComponentCdfs, TxbSet, TxbTables}; -use crate::decode::{TXFM_CTX_INIT, txfm_partition_ctx_rect}; +use crate::decode::{txfm_partition_ctx_rect, TXFM_CTX_INIT}; use crate::msac::SymbolEncoder; +use crate::mvstack::{find_mv_stack, mv16, MiGrid, MiInfo, NO_REF1}; use crate::transform::TxType; -use crate::mvstack::{MiGrid, MiInfo, NO_REF1, find_mv_stack, mv16}; // --------------------------------------------------------------------------- // lane-av1lr: per-64x64 `cdef_idx` (spec 5.11.56, `read_cdef`). The decoder @@ -386,9 +386,7 @@ fn write_inter_block_128( let scan32 = default_scan(TX32); let unit_of = |plane: usize, cr: usize, cc: usize| -> Vec { (0..32) - .flat_map(|row| { - packed[plane][(cr * 32 + row) * 64 + cc * 32..][..32].to_vec() - }) + .flat_map(|row| packed[plane][(cr * 32 + row) * 64 + cc * 32..][..32].to_vec()) .collect() }; let mut chroma_units: Vec<((usize, usize), [Vec; 2])> = Vec::new(); @@ -659,9 +657,7 @@ fn write_inter_block_128_rect( let scan32 = default_scan(TX32); let unit_of = |plane: usize, cr: usize, cc: usize| -> Vec { (0..32) - .flat_map(|row| { - packed[plane][(cr * 32 + row) * 64 + cc * 32..][..32].to_vec() - }) + .flat_map(|row| packed[plane][(cr * 32 + row) * 64 + cc * 32..][..32].to_vec()) .collect() }; let mut chroma_units: Vec<((usize, usize), [Vec; 2])> = Vec::new(); @@ -702,7 +698,8 @@ fn write_inter_block_128_rect( &mut cdfs.txb(TxbSet::Chroma32, 0), &grid, &scan32, - usize::from(around.above_coded) + usize::from(around.left_coded) + usize::from(around.above_coded) + + usize::from(around.left_coded) + 3 * usize::from(is_half), dc_sign_ctx(around.dc_vote), Some(plane), @@ -781,8 +778,7 @@ pub fn take_sb128_ab_hits() -> [usize; 4] { /// lane-b128r: how many of those blocks carried a REAL residual (four /// TX_64X64 luma units plus their per-chunk chroma pair) rather than being /// skipped, since the last [`take_sb128_residual_hits`]. -static SB128_RESIDUAL_HITS: std::sync::atomic::AtomicUsize = - std::sync::atomic::AtomicUsize::new(0); +static SB128_RESIDUAL_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); /// The 128x128-with-residual count since the last call, and zero it. pub fn take_sb128_residual_hits() -> usize { @@ -792,8 +788,7 @@ pub fn take_sb128_residual_hits() -> usize { /// [`write_inter_block_128_rect`] codes) carried a REAL residual rather than /// being skipped, since the last [`take_sb128_rectres_hits`] -- the writer /// side of [`crate::encode::take_b128_rectres_hits`]'s search count. -static SB128_RECTRES_HITS: std::sync::atomic::AtomicUsize = - std::sync::atomic::AtomicUsize::new(0); +static SB128_RECTRES_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); /// The rect/AB-piece-with-residual count since the last call, and zero it. pub fn take_sb128_rectres_hits() -> usize { @@ -803,8 +798,7 @@ pub fn take_sb128_rectres_hits() -> usize { /// lane-b128r: how many of those blocks named a SECOND reference (the /// compound arm at the 128 root), since the last /// [`take_sb128_compound_hits`]. -static SB128_COMPOUND_HITS: std::sync::atomic::AtomicUsize = - std::sync::atomic::AtomicUsize::new(0); +static SB128_COMPOUND_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); /// The compound-128 count since the last call, and zero it. pub fn take_sb128_compound_hits() -> usize { @@ -838,12 +832,7 @@ fn write_lr(enc: &mut SymbolEncoder, cdfs: &mut Cdfs, mi_row: u32, mi_col: u32, let info = plan.units[(rcol + rrow * plan.horz_units) as usize]; enc.symbol(usize::from(info.is_some()), &mut cdfs.restore_wiener); if let Some(info) = info { - crate::restoration::write_wiener_filter( - enc, - false, - &mut plan.reference, - &info, - ); + crate::restoration::write_wiener_filter(enc, false, &mut plan.reference, &info); } } } @@ -919,7 +908,10 @@ impl TileLayout { let starts = |total: u32, log2: u32| { let total128 = total.div_ceil(unit); let step = total128.div_ceil(1 << log2).max(1); - let mut v: Vec = (0..total128).step_by(step as usize).map(|s| s * unit).collect(); + let mut v: Vec = (0..total128) + .step_by(step as usize) + .map(|s| s * unit) + .collect(); v.push(total); v }; @@ -1067,11 +1059,9 @@ pub(crate) fn cdef_unit_owner(blocks: &[Quadrant], mi_cols: u32, mi_rows: u32) - // (its two squares are one unit each); only a non-skip one // codes a literal, so only it fires. Quadrant::Ab128(symbol, pieces) => { - for (piece, ((mi_r, mi_c), (w, h))) in - pieces.iter().zip(crate::encode::ab128_pieces( - usize::from(*symbol), - (0, 0), - )) + for (piece, ((mi_r, mi_c), (w, h))) in pieces + .iter() + .zip(crate::encode::ab128_pieces(usize::from(*symbol), (0, 0))) { if piece.skip { continue; @@ -1111,7 +1101,12 @@ thread_local! { /// carries no literal at all). pub(crate) fn arm_cdef_idx(bits: u8, sb_cols: usize, grid: Vec) { CDEF_IDX.with(|c| { - *c.borrow_mut() = (bits > 0).then(|| CdefIdxPlan { bits, sb_cols, grid, last: None }); + *c.borrow_mut() = (bits > 0).then(|| CdefIdxPlan { + bits, + sb_cols, + grid, + last: None, + }); }); } @@ -1143,8 +1138,12 @@ thread_local! { /// lane-deltaq) when `res == 0`. pub(crate) fn arm_delta_q(res: i32, sb_cols: usize, grid: Vec, base: u8) { DELTA_Q.with(|c| { - *c.borrow_mut() = - (res > 0).then(|| DeltaQPlan { res, sb_cols, grid, cur: i32::from(base) }); + *c.borrow_mut() = (res > 0).then(|| DeltaQPlan { + res, + sb_cols, + grid, + cur: i32::from(base), + }); }); } @@ -1285,14 +1284,23 @@ fn write_filter_intra( filter_intra: Option, ) { if !filter_intra_armed() || mode != DC_PRED || has_palette_y { - debug_assert!(filter_intra.is_none(), "no `use_filter_intra` symbol exists here"); + debug_assert!( + filter_intra.is_none(), + "no `use_filter_intra` symbol exists here" + ); return; } let Some(class) = crate::decode::filter_intra_size_class(side) else { - debug_assert!(filter_intra.is_none(), "past av1_filter_intra_allowed_bsize"); + debug_assert!( + filter_intra.is_none(), + "past av1_filter_intra_allowed_bsize" + ); return; }; - enc.symbol(usize::from(filter_intra.is_some()), &mut cdfs.filter_intra[class]); + enc.symbol( + usize::from(filter_intra.is_some()), + &mut cdfs.filter_intra[class], + ); if let Some(fi) = filter_intra { enc.symbol(usize::from(fi), &mut cdfs.filter_intra_mode); FILTER_INTRA_HITS[0].fetch_add(1, std::sync::atomic::Ordering::Relaxed); @@ -1525,7 +1533,12 @@ fn write_motion_mode( /// a single-reference or intra block, and `record_compound_mi`'s overwrite of /// the ALTREF default for a compound one (this writer only codes /// `comp_group_idx == 0`, `compound_idx == 1`). -fn record_block_compound(neighbours: &mut Neighbours, at_mi: (usize, usize), side: usize, block: &BlockCoeffs) { +fn record_block_compound( + neighbours: &mut Neighbours, + at_mi: (usize, usize), + side: usize, + block: &BlockCoeffs, +) { if let Some(r1) = block.inter.and_then(|i| i.ref1) { neighbours.record_compound_mi(at_mi, side, r1, 0, 1); } @@ -1577,14 +1590,19 @@ pub(crate) fn high_precision_mv() -> bool { /// `allow_high_precision_mv`, one per non-zero mv component with it), `[1]` /// counts the ones that came out ZERO -- an eighth-pel vector, i.e. one a /// frame without the flag cannot name at all. -static HP_SYMBOLS: [std::sync::atomic::AtomicU64; 2] = - [std::sync::atomic::AtomicU64::new(0), std::sync::atomic::AtomicU64::new(0)]; +static HP_SYMBOLS: [std::sync::atomic::AtomicU64; 2] = [ + std::sync::atomic::AtomicU64::new(0), + std::sync::atomic::AtomicU64::new(0), +]; /// Reads and clears [`HP_SYMBOLS`]: `(hp symbols coded, eighth-pel ones)`. #[allow(dead_code)] // read only from the `#[cfg(test)]` witness pub(crate) fn take_hp_symbols() -> (u64, u64) { let all = HP_SYMBOLS[0].swap(0, std::sync::atomic::Ordering::Relaxed); - (all, HP_SYMBOLS[1].swap(0, std::sync::atomic::Ordering::Relaxed)) + ( + all, + HP_SYMBOLS[1].swap(0, std::sync::atomic::Ordering::Relaxed), + ) } /// [`take_hp_symbols`] without clearing -- what the NEWMV census prints. @@ -1611,10 +1629,10 @@ fn write_compound_ref_frames( (ref0, ref1): (i8, i8), ) -> Result<()> { use crate::mvstack::{ + comp_reference_type_ctx, single_ref_p1_ctx, single_ref_p2_ctx, single_ref_p3_ctx, + single_ref_p4_ctx, single_ref_p5_ctx, single_ref_p6_ctx, uni_comp_ref_p1_ctx, ALTREF2_FRAME, ALTREF_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST2_FRAME, LAST3_FRAME, - LAST_FRAME, comp_reference_type_ctx, single_ref_p1_ctx, single_ref_p2_ctx, - single_ref_p3_ctx, single_ref_p4_ctx, single_ref_p5_ctx, single_ref_p6_ctx, - uni_comp_ref_p1_ctx, + LAST_FRAME, }; let a = (above_ref > 0).then_some(above_ref); let l = (left_ref > 0).then_some(left_ref); @@ -1810,14 +1828,20 @@ fn write_compound_block( let mut walk = 1usize; while walk < 3 && stack.entries.len() > walk + 1 { let advance = walk < idx; - enc.symbol(usize::from(advance), &mut cdfs.drl_mode[stack.drl_ctx[walk]]); + enc.symbol( + usize::from(advance), + &mut cdfs.drl_mode[stack.drl_ctx[walk]], + ); if !advance { break; } walk += 1; } let near = |i: usize| { - stack.entries.get(i).map_or(stack.near_mv, |e| (e.mv0, e.mv1)) + stack + .entries + .get(i) + .map_or(stack.near_mv, |e| (e.mv0, e.mv1)) }; if walk != idx && near(walk) != near(idx) { note_drl_clamp(idx, walk, stack.entries.len()); @@ -1845,14 +1869,20 @@ fn write_compound_block( let mut walk = 0usize; while walk < 2 && stack.entries.len() > walk + 1 { let advance = walk < idx; - enc.symbol(usize::from(advance), &mut cdfs.drl_mode[stack.drl_ctx[walk]]); + enc.symbol( + usize::from(advance), + &mut cdfs.drl_mode[stack.drl_ctx[walk]], + ); if !advance { break; } walk += 1; } let nearest = |i: usize| { - stack.entries.get(i).map_or(stack.nearest_mv, |e| (e.mv0, e.mv1)) + stack + .entries + .get(i) + .map_or(stack.nearest_mv, |e| (e.mv0, e.mv1)) }; if walk != idx && nearest(walk) != nearest(idx) { note_drl_clamp(idx, walk, stack.entries.len()); @@ -1993,7 +2023,11 @@ fn write_delta_q( // under `EC_AV1_SB128` -- decode.rs `maybe_read_delta_q` gates on // `sb_mi_cur`, and a writer gating on a hardcoded 64 codes three // symbol groups per 128 root the reader never reads. - let sb_mi = if sb128_armed() { SB_MI as usize * 2 } else { SB_MI as usize }; + let sb_mi = if sb128_armed() { + SB_MI as usize * 2 + } else { + SB_MI as usize + }; if mi.0 % sb_mi != 0 || mi.1 % sb_mi != 0 { return; } @@ -2820,9 +2854,9 @@ impl Quadrant { Quadrant::Whole(block) | Quadrant::Whole64(block) | Quadrant::Whole128(block) => { std::slice::from_ref(block) } - Quadrant::Split(blocks) - | Quadrant::Rect128(_, blocks) - | Quadrant::Ab128(_, blocks) => blocks.as_slice(), + Quadrant::Split(blocks) | Quadrant::Rect128(_, blocks) | Quadrant::Ab128(_, blocks) => { + blocks.as_slice() + } Quadrant::Covered => &[], } } @@ -3040,8 +3074,12 @@ impl Neighbours { fn start_row(&mut self) { self.left.iter_mut().for_each(|l| *l = Default::default()); self.left_mode.iter_mut().for_each(|m| *m = DC_PRED); - self.left_side.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE); - self.left_side_mi.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE); + self.left_side + .iter_mut() + .for_each(|s| *s = NO_NEIGHBOUR_SIDE); + self.left_side_mi + .iter_mut() + .for_each(|s| *s = NO_NEIGHBOUR_SIDE); self.left_skip.iter_mut().for_each(|s| *s = false); self.left_inter.iter_mut().for_each(|i| *i = false); self.left_ref.iter_mut().for_each(|r| *r = -1); @@ -3052,7 +3090,9 @@ impl Neighbours { self.left_txfm.iter_mut().for_each(|t| *t = TXFM_CTX_INIT); self.left_palette_size.iter_mut().for_each(|s| *s = 0); self.left_palette_uv_size.iter_mut().for_each(|s| *s = 0); - self.left_palette_uv_colors.iter_mut().for_each(|c| *c = [0u16; 8]); + self.left_palette_uv_colors + .iter_mut() + .for_each(|c| *c = [0u16; 8]); } /// `av1_get_palette_mode_ctx` + `av1_get_palette_cache`, mirrored from @@ -3069,12 +3109,18 @@ impl Neighbours { let above_ok = r % 16 != 0; let above_is_palette = r > 0 && self.above_palette_size[c] > 0; let (above_n, above_colors) = if above_ok && self.above_palette_size[c] > 0 { - (usize::from(self.above_palette_size[c]), self.above_palette_colors[c]) + ( + usize::from(self.above_palette_size[c]), + self.above_palette_colors[c], + ) } else { (0, [0u16; 8]) }; let (left_n, left_colors) = if c > 0 && self.left_palette_size[r] > 0 { - (usize::from(self.left_palette_size[r]), self.left_palette_colors[r]) + ( + usize::from(self.left_palette_size[r]), + self.left_palette_colors[r], + ) } else { (0, [0u16; 8]) }; @@ -3167,7 +3213,13 @@ impl Neighbours { /// [`Self::record_palette_y`] for the chroma bands (decode.rs /// `record_palette_uv_rect`) -- `size == 0` clears stale state the same /// way, and the span is in LUMA pixels for both planes' bands alike. - fn record_palette_uv(&mut self, (r, c): (usize, usize), (w, h): (usize, usize), size: u8, colors: [u16; 8]) { + fn record_palette_uv( + &mut self, + (r, c): (usize, usize), + (w, h): (usize, usize), + size: u8, + colors: [u16; 8], + ) { // lane-b128hv: the above band spans the block's WIDTH and the left // band its HEIGHT; identical to the one loop this replaces at w == h. for cell in 0..(w / MI).max(1) { @@ -3191,7 +3243,13 @@ impl Neighbours { /// What a just-written block leaves in the palette bands (decode.rs /// `record_palette_y_rect`): its size and colours over every 4x4 unit it /// spans, `0` for a block that took no palette. - fn record_palette_y(&mut self, (r, c): (usize, usize), (w, h): (usize, usize), size: u8, colors: [u16; 8]) { + fn record_palette_y( + &mut self, + (r, c): (usize, usize), + (w, h): (usize, usize), + size: u8, + colors: [u16; 8], + ) { // lane-b128hv: the above band spans the block's WIDTH and the left // band its HEIGHT; identical to the one loop this replaces at w == h. for cell in 0..(w / MI).max(1) { @@ -3216,7 +3274,13 @@ impl Neighbours { /// of an INTER frame leaves in the two `TXFM_CONTEXT` bands -- its /// resolved transform size over the span `(w_px, h_px)`, which for a /// SKIPPED inter block is its own block size instead. - fn record_txfm(&mut self, (mi_r, mi_c): (usize, usize), tx_px: usize, w_px: usize, h_px: usize) { + fn record_txfm( + &mut self, + (mi_r, mi_c): (usize, usize), + tx_px: usize, + w_px: usize, + h_px: usize, + ) { for i in 0..h_px / MI { if let Some(cell) = self.left_txfm.get_mut(mi_r + i) { *cell = tx_px as u8; @@ -3492,9 +3556,22 @@ impl Neighbours { /// Writes one inter-frame block's skip flag and inter/intra state into /// every 16x16 column and row it covers, the same span [`Self::record`] /// fills for the coefficient and mode state. - fn record_inter(&mut self, at: (usize, usize), side: usize, skip: bool, is_inter: bool, ref_frame: i8) { + fn record_inter( + &mut self, + at: (usize, usize), + side: usize, + skip: bool, + is_inter: bool, + ref_frame: i8, + ) { let (r, c) = at; - self.record_inter_mi((r * (SUB / MI), c * (SUB / MI)), side, skip, is_inter, ref_frame); + self.record_inter_mi( + (r * (SUB / MI), c * (SUB / MI)), + side, + skip, + is_inter, + ref_frame, + ); } /// lane-b128hv: [`Self::record_inter_mi`] with independent above (width) @@ -3572,7 +3649,14 @@ impl Neighbours { /// [`Self::record_inter`] taking the block's position directly in 4x4 /// mode-info units, for a block finer than one [`SUB`] slot. - fn record_inter_mi(&mut self, (mi_r, mi_c): (usize, usize), side: usize, skip: bool, is_inter: bool, ref_frame: i8) { + fn record_inter_mi( + &mut self, + (mi_r, mi_c): (usize, usize), + side: usize, + skip: bool, + is_inter: bool, + ref_frame: i8, + ) { for cell in 0..side / MI { self.above_skip[mi_c + cell] = skip; self.left_skip[mi_r + cell] = skip; @@ -3838,7 +3922,16 @@ pub(crate) fn sb_coeff_key_frame_tile_cdfs( neighbours.start_row(); } if sb128 && sb_start { - write_sb128_root(&mut enc, &mut cdfs, &neighbours, sb_r, sb_c, mi_cols, mi_rows, PARTITION_SPLIT); + write_sb128_root( + &mut enc, + &mut cdfs, + &neighbours, + sb_r, + sb_c, + mi_cols, + mi_rows, + PARTITION_SPLIT, + ); } { if !sb128 { @@ -4316,7 +4409,12 @@ fn write_palette_colors_y(enc: &mut SymbolEncoder, colors: &[u16], cache: &[u16] /// below sees, so it only ever makes the encoder take FEWER chroma palettes /// than it should -- never a wrong stream. Upgrade path: price both forms /// here and write the cheaper one under its own leading bit. -fn write_palette_colors_uv(enc: &mut SymbolEncoder, u_colors: &[u16], v_colors: &[u16], cache: &[u16]) { +fn write_palette_colors_uv( + enc: &mut SymbolEncoder, + u_colors: &[u16], + v_colors: &[u16], + cache: &[u16], +) { let n = u_colors.len(); let mut cached: Vec = Vec::with_capacity(n); for &c in cache { @@ -4441,7 +4539,14 @@ pub(crate) fn palette_uv_bits(pal: &PaletteUv, side: usize, on: (usize, usize)) enc.symbol(n - 2, &mut size_cdf); write_palette_colors_uv(&mut enc, &pal.u_colors[..n], &pal.v_colors[..n], &[]); let mut idx_cdfs = cdf::PALETTE_UV_COLOR_INDEX[n - 2]; - write_color_index_map(&mut enc, &mut idx_cdfs, &pal.map, palette_uv_side(side), n, on); + write_color_index_map( + &mut enc, + &mut idx_cdfs, + &pal.map, + palette_uv_side(side), + n, + on, + ); enc.bits() } @@ -4552,7 +4657,12 @@ fn write_dv_component(enc: &mut SymbolEncoder, c: &mut MvComponentCdfs, diff: i3 /// One intrabc block's DV as a residual against [`intrabc_dv_pred`], off the /// `dv` nmv context (decode.rs `read_intrabc_dv` -> `read_mv`). -fn write_dv(enc: &mut SymbolEncoder, cdfs: &mut Cdfs, dv: (i32, i32), pred: (i32, i32)) -> Result<()> { +fn write_dv( + enc: &mut SymbolEncoder, + cdfs: &mut Cdfs, + dv: (i32, i32), + pred: (i32, i32), +) -> Result<()> { let diff = (dv.0 - pred.0, dv.1 - pred.1); let joint = match (diff.0 != 0, diff.1 != 0) { (false, false) => 0, @@ -4584,7 +4694,8 @@ fn write_intrabc_block( mi: (usize, usize), side: usize, ) -> Result<()> { - let skip_ctx = usize::from(neighbours.above_skip[mi.1]) + usize::from(neighbours.left_skip[mi.0]); + let skip_ctx = + usize::from(neighbours.above_skip[mi.1]) + usize::from(neighbours.left_skip[mi.0]); enc.symbol(1, &mut cdfs.skip[skip_ctx]); write_cdef_idx(enc, mi, true); enc.symbol(1, &mut cdfs.intrabc); @@ -4705,7 +4816,8 @@ fn write_intra_mode( // above + left. Every block this writer codes outside an `allow_intrabc` // frame is unskipped, so both bands stay false and this stays 0 -- the // literal every stream before this lane was written with. - let skip_ctx = usize::from(neighbours.above_skip[mi.1]) + usize::from(neighbours.left_skip[mi.0]); + let skip_ctx = + usize::from(neighbours.above_skip[mi.1]) + usize::from(neighbours.left_skip[mi.0]); enc.symbol(0, &mut cdfs.skip[skip_ctx]); write_cdef_idx(enc, mi, false); // `read_intrabc_info` (spec 5.11.13): the flag is read for EVERY intra @@ -4737,7 +4849,9 @@ fn write_intra_mode( write_cfl_alphas( enc, cdfs, - block.cfl_alphas.expect("a UV_CFL_PRED block carries its alphas"), + block + .cfl_alphas + .expect("a UV_CFL_PRED block carries its alphas"), ); } // `angle_delta_uv` (spec `read_intra_angle_info`) off the same CDF array @@ -4890,8 +5004,7 @@ static PALETTE_HITS: [std::sync::atomic::AtomicUsize; 9] = /// i.e. palette blocks this writer cut at the frame's right/bottom mi edge. /// A gate asserts it non-zero so it cannot pass on a stream that never cuts /// one (class `gate-blind-to-feature`). -static PALETTE_CUT_MAPS: std::sync::atomic::AtomicUsize = - std::sync::atomic::AtomicUsize::new(0); +static PALETTE_CUT_MAPS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); /// Current value of [`PALETTE_CUT_MAPS`] (colour-index maps). pub fn palette_cut_maps_written() -> usize { @@ -4975,15 +5088,7 @@ fn write_block( } let (above_mode, left_mode) = (neighbours.above_mode[c], neighbours.left_mode[r]); let mode = write_intra_mode( - enc, - cdfs, - neighbours, - block, - above_mode, - left_mode, - cfl, - at_mi, - side, + enc, cdfs, neighbours, block, above_mode, left_mode, cfl, at_mi, side, ); // The coefficient tables read `fimode_to_intradir[filter_intra_mode]`'s // row on a filter-intra block; the neighbour publication below still gets @@ -5085,7 +5190,9 @@ fn write_leaf8( // true first divergence (a differently-sized alphabet under the same // DC_PRED decision desyncs the coder even though the decoded mode is // unchanged). - let mode = write_intra_mode(enc, cdfs, neighbours, block, above_mode, left_mode, true, leaf_mi, 8); + let mode = write_intra_mode( + enc, cdfs, neighbours, block, above_mode, left_mode, true, leaf_mi, 8, + ); let planes = [TxbSet::Luma8, TxbSet::Chroma4, TxbSet::Chroma4]; // As [`write_block`]: the coefficient row follows the filter-intra mode, // the mode this leaf publishes (and returns to the next leaf) does not. @@ -5218,7 +5325,11 @@ fn write_block_planes( /// The single luma transform type a block carries, `DCT_DCT` for one that /// never searched one (lane-txset). fn block_tx_type(block: &BlockCoeffs) -> TxType { - block.luma_tx_types.first().copied().unwrap_or(TxType::DctDct) + block + .luma_tx_types + .first() + .copied() + .unwrap_or(TxType::DctDct) } /// The `(side / tx)^2` transform units of one block's luma residual, raster @@ -5294,9 +5405,7 @@ fn write_luma_tus( grid.to_vec() } else { (0..tx) - .flat_map(|row| { - grid[(tu_row * tx + row) * side + tu_col * tx..][..tx].to_vec() - }) + .flat_map(|row| grid[(tu_row * tx + row) * side + tu_col * tx..][..tx].to_vec()) .collect() }; // spec `get_txb_ctx_general`: a lone transform unit covering its @@ -5381,7 +5490,9 @@ fn write_luma_select( } } let tx = max_tx >> depth; - write_luma_tus(enc, cdfs, neighbours, at_mi, side, tx, grid, mode, scans, false, tx_types)?; + write_luma_tus( + enc, cdfs, neighbours, at_mi, side, tx, grid, mode, scans, false, tx_types, + )?; neighbours.record_tx(at_mi, side, tx); Ok(tx) } @@ -5681,7 +5792,9 @@ pub(crate) fn predicted_coeff_bits(blocks: &[Quadrant], base_q_idx: u8) -> f64 { .map(|tu| { let (r0, c0) = ((tu / 2) * 32, (tu % 2) * 32); let unit: Vec = (0..32) - .flat_map(|row| g[(r0 + row) * 64 + c0..][..32].to_vec()) + .flat_map(|row| { + g[(r0 + row) * 64 + c0..][..32].to_vec() + }) .collect(); coeff_bits(&unit, TxbSet::Luma32Inter, q_ctx, 0, 0) }) @@ -5696,7 +5809,10 @@ pub(crate) fn predicted_coeff_bits(blocks: &[Quadrant], base_q_idx: u8) -> f64 { } Quadrant::Covered => return 0.0, }; - q.blocks().iter().map(|b| block_bits(b, side, q_ctx)).sum::() + q.blocks() + .iter() + .map(|b| block_bits(b, side, q_ctx)) + .sum::() }) .sum() } @@ -5764,7 +5880,7 @@ fn scan_of(side: usize) -> &'static Vec { /// DECODER's own table so the two cannot drift, cached per size and class. fn class_scan_of(side: usize, class: crate::decode::TxClass) -> &'static [u16] { static SCANS: LazyLock<[[Vec; 2]; 4]> = LazyLock::new(|| { - use crate::decode::{TxClass, class_scan_table}; + use crate::decode::{class_scan_table, TxClass}; [TX4, TX8, TX16, TX32].map(|side| { [ class_scan_table(side, TxClass::Horiz), @@ -5846,7 +5962,16 @@ pub(crate) fn coeff_bits_typed( } let scan = scan_of(coding.side); let mut enc = SymbolEncoder::pricer(); - write_coeffs(&mut enc, &mut coding, grid, scan, skip_ctx, sign_ctx, None, tx_type); + write_coeffs( + &mut enc, + &mut coding, + grid, + scan, + skip_ctx, + sign_ctx, + None, + tx_type, + ); enc.bits() }; // lane-av1speed2: 60% of the transform units of an inter stream hold no @@ -5866,12 +5991,20 @@ pub(crate) fn coeff_bits_typed( let all_zero = grid.iter().all(|&level| level == 0); PRICING_BASE.with_borrow_mut(|base| { if let Some(slot) = base.as_deref_mut().filter(|s| s.0.q_ctx == q_ctx) { - return if all_zero { zero_price(slot) } else { price(slot) }; + return if all_zero { + zero_price(slot) + } else { + price(slot) + }; } PRICING.with_borrow_mut(|slots| { let slot = slots[q_ctx.min(3)] .get_or_insert_with(|| Box::new((Cdfs::new(q_ctx), Cdfs::new(q_ctx)))); - if all_zero { zero_price(slot) } else { price(slot) } + if all_zero { + zero_price(slot) + } else { + price(slot) + } }) }) } @@ -5951,7 +6084,11 @@ pub(crate) fn rdoq( // is what the writer and the pricer take (`coded_corner`). let coded = side.min(TX32); let q_ctx = crate::decode::q_ctx_of(base_q_idx); - let mut dense = if coded == side { Vec::new() } else { vec![0i32; coded * coded] }; + let mut dense = if coded == side { + Vec::new() + } else { + vec![0i32; coded * coded] + }; fn price( levels: &[i32], dense: &mut [i32], @@ -5971,7 +6108,9 @@ pub(crate) fn rdoq( } coeff_bits_typed(dense, set, q_ctx, skip_ctx, sign_ctx, tx_type) } - let mut bits = price(levels, &mut dense, side, coded, set, q_ctx, skip_ctx, sign_ctx, tx_type); + let mut bits = price( + levels, &mut dense, side, coded, set, q_ctx, skip_ctx, sign_ctx, tx_type, + ); // The DC has its own quantiser, so its squared error per unit of level is // `(dc_q / ac_q)^2` of an AC coefficient's. let dc = f64::from(crate::quant::dc_q(8, i32::from(base_q_idx))); @@ -6022,9 +6161,11 @@ pub(crate) fn rdoq( let candidate = level - level.signum(); levels[i] = candidate; budget -= 1; - let after = price(levels, &mut dense, side, coded, set, q_ctx, skip_ctx, sign_ctx, tx_type); - let distortion = weight - * ((s - f64::from(candidate)).powi(2) - (s - f64::from(level)).powi(2)); + let after = price( + levels, &mut dense, side, coded, set, q_ctx, skip_ctx, sign_ctx, tx_type, + ); + let distortion = + weight * ((s - f64::from(candidate)).powi(2) - (s - f64::from(level)).powi(2)); if distortion + lambda * (after - bits) < 0.0 { bits = after; if census { @@ -6049,8 +6190,14 @@ pub(crate) fn rdoq( /// at the end of the scan), zeroed coefficients, lowered coefficients, bits /// after the pass * 64, bits before the pass * 64. pub(crate) static RDOQ_STATS: [AtomicU64; 8] = [ - AtomicU64::new(0), AtomicU64::new(0), AtomicU64::new(0), AtomicU64::new(0), - AtomicU64::new(0), AtomicU64::new(0), AtomicU64::new(0), AtomicU64::new(0), + AtomicU64::new(0), + AtomicU64::new(0), + AtomicU64::new(0), + AtomicU64::new(0), + AtomicU64::new(0), + AtomicU64::new(0), + AtomicU64::new(0), + AtomicU64::new(0), ]; /// The pre-pass half of [`RDOQ_STATS`] (`EC_AV1_RDOQ_CENSUS`): what the @@ -6146,11 +6293,13 @@ thread_local! { /// at native, still with every one of its frames armed with the defaults. pub(crate) fn arm_pricing_cdfs(base: Option<&Cdfs>, screen: bool) { static MODE: std::sync::OnceLock = std::sync::OnceLock::new(); - let mode = *MODE.get_or_init(|| match std::env::var("EC_AV1_PRICE_FRAME_CDFS").as_deref() { - Ok("0") => 0, - Ok("1") => 1, - _ => 2, - }); + let mode = *MODE.get_or_init( + || match std::env::var("EC_AV1_PRICE_FRAME_CDFS").as_deref() { + Ok("0") => 0, + Ok("1") => 1, + _ => 2, + }, + ); let on = match mode { 0 => false, 1 => true, @@ -6158,7 +6307,9 @@ pub(crate) fn arm_pricing_cdfs(base: Option<&Cdfs>, screen: bool) { }; PRICING_HITS[usize::from(on && base.is_some())].fetch_add(1, Ordering::Relaxed); PRICING_BASE.with_borrow_mut(|slot| { - *slot = base.filter(|_| on).map(|c| Box::new((c.clone(), c.clone()))); + *slot = base + .filter(|_| on) + .map(|c| Box::new((c.clone(), c.clone()))); }); } @@ -6166,8 +6317,7 @@ pub(crate) fn arm_pricing_cdfs(base: Option<&Cdfs>, screen: bool) { /// many with the frame's REAL starting tables ([`arm_pricing_cdfs`]), so a /// gate can print which side of the screen gate every frame landed on. Counts /// arming calls, not frames: a multi-tile frame arms one worker per tile. -pub(crate) static PRICING_HITS: [AtomicUsize; 2] = - [AtomicUsize::new(0), AtomicUsize::new(0)]; +pub(crate) static PRICING_HITS: [AtomicUsize; 2] = [AtomicUsize::new(0), AtomicUsize::new(0)]; /// Reads and clears [`PRICING_HITS`]: (default-table armings, real-table /// armings). @@ -6389,7 +6539,10 @@ fn write_coeffs( // lane-av1speed3: `side` is 4, 8, 16 or 32, but it is a runtime value -- // `pos / side` compiles to a real integer division, once per coefficient, // in the encoder's largest self-time symbol. Same row and column. - debug_assert!(side.is_power_of_two(), "the scan splits a position by shifting"); + debug_assert!( + side.is_power_of_two(), + "the scan splits a position by shifting" + ); let (shift, mask) = (side.trailing_zeros(), side - 1); for scan_idx in (0..eob).rev() { let pos = scan[scan_idx] as usize; @@ -6649,7 +6802,11 @@ fn br_ctx( if row == 0 && col == 0 { return mag; } - let near_origin = if class == TxClass::Horiz { col == 0 } else { row == 0 }; + let near_origin = if class == TxClass::Horiz { + col == 0 + } else { + row == 0 + }; return if near_origin { mag + 7 } else { mag + 14 }; } let p = row * side + col; @@ -6800,7 +6957,11 @@ pub(crate) fn intra_inter_ctx( /// `CLASS0_SIZE << (class + 2)` (spec 3), the magnitude an `MV_CLASS_n` /// component's own bits start counting from; class zero starts at zero. fn mv_class_base(class: usize) -> i32 { - if class == 0 { 0 } else { 2i32 << (class + 2) } + if class == 0 { + 0 + } else { + 2i32 << (class + 2) + } } /// The class a pre-offset magnitude `z` (`|diff| - 1`) falls in — the inverse @@ -6923,11 +7084,12 @@ fn write_single_ref( left_ref: i8, left_ref1: Option, ) { - REF_HITS[(ref_frame.max(1) - 1) as usize % 7].fetch_add(1, std::sync::atomic::Ordering::Relaxed); + REF_HITS[(ref_frame.max(1) - 1) as usize % 7] + .fetch_add(1, std::sync::atomic::Ordering::Relaxed); use crate::mvstack::{ - ALTREF2_FRAME, ALTREF_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST2_FRAME, LAST3_FRAME, single_ref_p1_ctx, single_ref_p2_ctx, single_ref_p3_ctx, single_ref_p4_ctx, - single_ref_p5_ctx, single_ref_p6_ctx, + single_ref_p5_ctx, single_ref_p6_ctx, ALTREF2_FRAME, ALTREF_FRAME, BWDREF_FRAME, + GOLDEN_FRAME, LAST2_FRAME, LAST3_FRAME, }; let above = (above_ref > 0).then_some(above_ref); let left = (left_ref > 0).then_some(left_ref); @@ -7071,7 +7233,10 @@ pub(crate) fn take_drl_hits() -> [usize; 4] { /// pricer's own offer set is enumerated against this rule by /// `crate::encode::tests::every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal`. pub(crate) fn signalled_drl_idx(entries: usize, start: usize, target: usize) -> usize { - target.min(start + 2).min(entries.saturating_sub(1)).max(start) + target + .min(start + 2) + .min(entries.saturating_sub(1)) + .max(start) } fn write_drl_idx( @@ -7161,7 +7326,7 @@ fn write_inter_mode( enc.symbol(1, &mut cdfs.new_mv[stack.new_mv_ctx]); // not NEWMV enc.symbol(1, &mut cdfs.zero_mv[stack.zero_mv_ctx]); // not GLOBALMV enc.symbol(1, &mut cdfs.ref_mv[stack.ref_mv_ctx]); // NEARMV - // `RefMvIdx` starts at 1 for NEARMV (spec 5.11.24). + // `RefMvIdx` starts at 1 for NEARMV (spec 5.11.24). let idx = idx.max(1); let signalled = write_drl_idx(enc, cdfs, stack, 1, idx); let mv = stack.entries.get(signalled).map_or(stack.near_mv, |e| e.mv); @@ -7335,12 +7500,7 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( let scan4 = default_scan(TX4); // The same four tables again as one array, which is what the per-unit // luma writer indexes by transform side. - let all_scans = [ - scan32.clone(), - scan16.clone(), - scan8.clone(), - scan4.clone(), - ]; + let all_scans = [scan32.clone(), scan16.clone(), scan8.clone(), scan4.clone()]; let zero_grids = [ vec![0i32; TX32 * TX32], vec![0i32; TX16 * TX16], @@ -7431,7 +7591,10 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( // (mi_row, mi_col) and a second one at + hbs (16 mi) along the // cut axis, the second only when it is inside the frame -- the // search only offers a root wholly inside, so both are. - let base_mi = ((sb_r & !1) as usize * SB_MI as usize, (sb_c & !1) as usize * SB_MI as usize); + let base_mi = ( + (sb_r & !1) as usize * SB_MI as usize, + (sb_c & !1) as usize * SB_MI as usize, + ); let (w, h) = if horz { (128usize, 64usize) } else { (64, 128) }; for (i, half) in halves.iter().enumerate() { let at_mi = if horz { @@ -7467,8 +7630,9 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( (sb_r & !1) as usize * SB_MI as usize, (sb_c & !1) as usize * SB_MI as usize, ); - for (((mi_r, mi_c), (w, h)), piece) in - crate::encode::ab128_pieces(symbol, base_mi).iter().zip(pieces) + for (((mi_r, mi_c), (w, h)), piece) in crate::encode::ab128_pieces(symbol, base_mi) + .iter() + .zip(pieces) { write_inter_block_128_rect( &mut enc, @@ -7532,7 +7696,13 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( + usize::from(neighbours.left_skip[mi_r]); enc.symbol(usize::from(block.skip), &mut cdfs.skip[skip_ctx]); write_cdef_idx(&mut enc, (mi_r, mi_c), block.skip); - write_delta_q(&mut enc, &mut cdfs, (mi_r, mi_c), !sb128_armed(), block.skip); + write_delta_q( + &mut enc, + &mut cdfs, + (mi_r, mi_c), + !sb128_armed(), + block.skip, + ); let ii_ctx = intra_inter_ctx( has_above, has_left, @@ -7926,7 +8096,6 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( // caller (r15): the SUB-grid skip/inter arrays // are otherwise left stale for the next // 16x16 slot. - } } continue; @@ -7951,111 +8120,137 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( let mode_for_tx; if let Some(info) = block.inter { - write_comp_mode(&mut enc, &mut cdfs, &neighbours, (mi_r, mi_c), (has_above, has_left), info.ref1.is_some()); + write_comp_mode( + &mut enc, + &mut cdfs, + &neighbours, + (mi_r, mi_c), + (has_above, has_left), + info.ref1.is_some(), + ); let (mi_row, mi_col) = (r32 as usize * 8, c32 as usize * 8); if info.ref1.is_some() { let (mv, mv1, is_new_mv) = write_compound_block( - &mut enc, &mut cdfs, &neighbours, &grid, (mi_row, mi_col), (8, 8), - (has_above, has_left), info, (mi_cols as usize, mi_rows as usize), + &mut enc, + &mut cdfs, + &neighbours, + &grid, + (mi_row, mi_col), + (8, 8), + (has_above, has_left), + info, + (mi_cols as usize, mi_rows as usize), )?; for dr in 0..8 { for dc in 0..8 { - grid.set(mi_row + dr, mi_col + dc, MiInfo { - is_inter: true, - ref_frame: info.ref_frame, - ref_frame1: info.ref1.unwrap_or(NO_REF1), - mv1: mv16(mv1), - mv: mv16(mv), - is_new_mv, - size: 8, - size_h: 8, - is_global_mv0: false, - is_global_mv1: false, - }); + grid.set( + mi_row + dr, + mi_col + dc, + MiInfo { + is_inter: true, + ref_frame: info.ref_frame, + ref_frame1: info.ref1.unwrap_or(NO_REF1), + mv1: mv16(mv1), + mv: mv16(mv), + is_new_mv, + size: 8, + size_h: 8, + is_global_mv0: false, + is_global_mv1: false, + }, + ); } } mode_for_tx = 0; } else { - write_single_ref(&mut enc, &mut cdfs, info.ref_frame, neighbours.above_ref[mi_c], neighbours.above_ref1[mi_c], neighbours.left_ref[mi_r], neighbours.left_ref1[mi_r]); + write_single_ref( + &mut enc, + &mut cdfs, + info.ref_frame, + neighbours.above_ref[mi_c], + neighbours.above_ref1[mi_c], + neighbours.left_ref[mi_r], + neighbours.left_ref1[mi_r], + ); - let stack = find_mv_stack( - &grid, - mi_row, - mi_col, - 8, - 8, - info.ref_frame, - mi_cols as usize, - mi_rows as usize, - ); + let stack = find_mv_stack( + &grid, + mi_row, + mi_col, + 8, + 8, + info.ref_frame, + mi_cols as usize, + mi_rows as usize, + ); - let (mv, is_new_mv) = write_inter_mode(&mut enc, &mut cdfs, info, &stack)?; - if crate::msac::symtrace::dir().is_some() { - crate::msac::symtrace::note(&format!( - " MODE mi=({mi_r},{mi_c}) mode={:?} idx={} mv={mv:?} info_mv={:?}", - info.mode, info.ref_mv_idx, info.mv - )); - } - grid.set( - mi_row, - mi_col, - MiInfo { - is_inter: true, - ref_frame: info.ref_frame, - ref_frame1: NO_REF1, - mv1: (0, 0), - mv: mv16(mv), - is_new_mv, - size: 8, - size_h: 8, - is_global_mv0: false, - is_global_mv1: false, - }, - ); - for dr in 0..8 { - for dc in 0..8 { - if dr == 0 && dc == 0 { - continue; + let (mv, is_new_mv) = write_inter_mode(&mut enc, &mut cdfs, info, &stack)?; + if crate::msac::symtrace::dir().is_some() { + crate::msac::symtrace::note(&format!( + " MODE mi=({mi_r},{mi_c}) mode={:?} idx={} mv={mv:?} info_mv={:?}", + info.mode, info.ref_mv_idx, info.mv + )); + } + grid.set( + mi_row, + mi_col, + MiInfo { + is_inter: true, + ref_frame: info.ref_frame, + ref_frame1: NO_REF1, + mv1: (0, 0), + mv: mv16(mv), + is_new_mv, + size: 8, + size_h: 8, + is_global_mv0: false, + is_global_mv1: false, + }, + ); + for dr in 0..8 { + for dc in 0..8 { + if dr == 0 && dc == 0 { + continue; + } + grid.set( + mi_row + dr, + mi_col + dc, + MiInfo { + is_inter: true, + ref_frame: info.ref_frame, + ref_frame1: NO_REF1, + mv1: (0, 0), + mv: mv16(mv), + is_new_mv, + size: 8, + size_h: 8, + is_global_mv0: false, + is_global_mv1: false, + }, + ); } - grid.set( - mi_row + dr, - mi_col + dc, - MiInfo { - is_inter: true, - ref_frame: info.ref_frame, - ref_frame1: NO_REF1, - mv1: (0, 0), - mv: mv16(mv), - is_new_mv, - size: 8, - size_h: 8, - is_global_mv0: false, - is_global_mv1: false, - }, - ); } - } - write_motion_mode( - &mut enc, - &mut cdfs, - &grid, - (mi_row, mi_col), - (8, 8), - (BLOCK, BLOCK), - (mi_cols as usize, mi_rows as usize), - info.ref_frame, - block.motion_mode, - )?; - mode_for_tx = 0; + write_motion_mode( + &mut enc, + &mut cdfs, + &grid, + (mi_row, mi_col), + (8, 8), + (BLOCK, BLOCK), + (mi_cols as usize, mi_rows as usize), + info.ref_frame, + block.motion_mode, + )?; + mode_for_tx = 0; } } else { let mode = usize::from(block.mode); enc.symbol(mode, &mut cdfs.y_mode[SIZE_GROUP_32]); if (V_PRED..=D67_PRED).contains(&mode) { enc.symbol( - (ANGLE_DELTA_ZERO as i32 + i32::from(block.angle_delta_y)) as usize, - &mut cdfs.angle_delta[mode - V_PRED], - ); + (ANGLE_DELTA_ZERO as i32 + i32::from(block.angle_delta_y)) as usize, + &mut cdfs.angle_delta[mode - V_PRED], + ); } let uv_mode = usize::from(block.uv_mode); enc.symbol(uv_mode, &mut cdfs.uv_mode_cfl[mode]); @@ -8208,7 +8403,8 @@ fn write_inter_frame_leaf( let (r, c) = at; let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); - let skip_ctx = usize::from(neighbours.above_skip[mi_c]) + usize::from(neighbours.left_skip[mi_r]); + let skip_ctx = + usize::from(neighbours.above_skip[mi_c]) + usize::from(neighbours.left_skip[mi_r]); enc.symbol(usize::from(block.skip), &mut cdfs.skip[skip_ctx]); write_cdef_idx(enc, (mi_r, mi_c), block.skip); write_delta_q(enc, cdfs, (mi_r, mi_c), false, block.skip); @@ -8221,87 +8417,113 @@ fn write_inter_frame_leaf( let mode_for_tx; if let Some(info) = block.inter { - write_comp_mode(enc, cdfs, neighbours, (mi_r, mi_c), (has_above, has_left), info.ref1.is_some()); + write_comp_mode( + enc, + cdfs, + neighbours, + (mi_r, mi_c), + (has_above, has_left), + info.ref1.is_some(), + ); let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize); if info.ref1.is_some() { let n = SUB_MI as usize; let (mv, mv1, is_new_mv) = write_compound_block( - enc, cdfs, neighbours, grid, (mi_row, mi_col), (n, n), - (has_above, has_left), info, (mi_cols as usize, mi_rows as usize), + enc, + cdfs, + neighbours, + grid, + (mi_row, mi_col), + (n, n), + (has_above, has_left), + info, + (mi_cols as usize, mi_rows as usize), )?; for dr in 0..n { for dc in 0..n { - grid.set(mi_row + dr, mi_col + dc, MiInfo { - is_inter: true, - ref_frame: info.ref_frame, - ref_frame1: info.ref1.unwrap_or(NO_REF1), - mv1: mv16(mv1), - mv: mv16(mv), - is_new_mv, - size: n as u8, - size_h: n as u8, - is_global_mv0: false, - is_global_mv1: false, - }); + grid.set( + mi_row + dr, + mi_col + dc, + MiInfo { + is_inter: true, + ref_frame: info.ref_frame, + ref_frame1: info.ref1.unwrap_or(NO_REF1), + mv1: mv16(mv1), + mv: mv16(mv), + is_new_mv, + size: n as u8, + size_h: n as u8, + is_global_mv0: false, + is_global_mv1: false, + }, + ); } } mode_for_tx = 0; } else { - write_single_ref(enc, cdfs, info.ref_frame, neighbours.above_ref[mi_c], neighbours.above_ref1[mi_c], neighbours.left_ref[mi_r], neighbours.left_ref1[mi_r]); + write_single_ref( + enc, + cdfs, + info.ref_frame, + neighbours.above_ref[mi_c], + neighbours.above_ref1[mi_c], + neighbours.left_ref[mi_r], + neighbours.left_ref1[mi_r], + ); - let stack = find_mv_stack( - grid, - mi_row, - mi_col, - SUB_MI as usize, - SUB_MI as usize, - info.ref_frame, - mi_cols as usize, - mi_rows as usize, - ); + let stack = find_mv_stack( + grid, + mi_row, + mi_col, + SUB_MI as usize, + SUB_MI as usize, + info.ref_frame, + mi_cols as usize, + mi_rows as usize, + ); - let (mv, is_new_mv) = write_inter_mode(enc, cdfs, info, &stack)?; - for dr in 0..SUB_MI as usize { - for dc in 0..SUB_MI as usize { - grid.set( - mi_row + dr, - mi_col + dc, - MiInfo { - is_inter: true, - ref_frame: info.ref_frame, - ref_frame1: NO_REF1, - mv1: (0, 0), - mv: mv16(mv), - is_new_mv, - size: SUB_MI as usize as u8, - size_h: SUB_MI as usize as u8, - is_global_mv0: false, - is_global_mv1: false, - }, - ); + let (mv, is_new_mv) = write_inter_mode(enc, cdfs, info, &stack)?; + for dr in 0..SUB_MI as usize { + for dc in 0..SUB_MI as usize { + grid.set( + mi_row + dr, + mi_col + dc, + MiInfo { + is_inter: true, + ref_frame: info.ref_frame, + ref_frame1: NO_REF1, + mv1: (0, 0), + mv: mv16(mv), + is_new_mv, + size: SUB_MI as usize as u8, + size_h: SUB_MI as usize as u8, + is_global_mv0: false, + is_global_mv1: false, + }, + ); + } } - } - write_motion_mode( - enc, - cdfs, - grid, - (mi_row, mi_col), - (SUB_MI as usize, SUB_MI as usize), - (SUB, SUB), - (mi_cols as usize, mi_rows as usize), - info.ref_frame, - block.motion_mode, - )?; - mode_for_tx = 0; + write_motion_mode( + enc, + cdfs, + grid, + (mi_row, mi_col), + (SUB_MI as usize, SUB_MI as usize), + (SUB, SUB), + (mi_cols as usize, mi_rows as usize), + info.ref_frame, + block.motion_mode, + )?; + mode_for_tx = 0; } } else { let mode = usize::from(block.mode); enc.symbol(mode, &mut cdfs.y_mode[SIZE_GROUP_16]); if (V_PRED..=D67_PRED).contains(&mode) { enc.symbol( - (ANGLE_DELTA_ZERO as i32 + i32::from(block.angle_delta_y)) as usize, - &mut cdfs.angle_delta[mode - V_PRED], - ); + (ANGLE_DELTA_ZERO as i32 + i32::from(block.angle_delta_y)) as usize, + &mut cdfs.angle_delta[mode - V_PRED], + ); } let uv_mode = usize::from(block.uv_mode); enc.symbol(uv_mode, &mut cdfs.uv_mode_cfl[mode]); @@ -8380,7 +8602,16 @@ fn write_inter_frame_leaf( ]; if split { write_luma_tus( - enc, cdfs, neighbours, at_mi, SUB, tx, &grids[0], mode_for_tx, all_scans, is_inter, + enc, + cdfs, + neighbours, + at_mi, + SUB, + tx, + &grids[0], + mode_for_tx, + all_scans, + is_inter, &block.luma_tx_types, )?; } @@ -8467,93 +8698,122 @@ fn write_inter_frame_leaf8( write_cdef_idx(enc, leaf_mi, block.skip); write_delta_q(enc, cdfs, leaf_mi, false, block.skip); - let (has_above, has_left) = (neighbours.has_above(leaf_mi.0), neighbours.has_left(leaf_mi.1)); + let (has_above, has_left) = ( + neighbours.has_above(leaf_mi.0), + neighbours.has_left(leaf_mi.1), + ); let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter); let is_inter = block.inter.is_some(); enc.symbol(usize::from(is_inter), &mut cdfs.intra_inter[ii_ctx]); let mode_for_tx; if let Some(info) = block.inter { - write_comp_mode(enc, cdfs, neighbours, leaf_mi, (has_above, has_left), info.ref1.is_some()); + write_comp_mode( + enc, + cdfs, + neighbours, + leaf_mi, + (has_above, has_left), + info.ref1.is_some(), + ); let (mi_row, mi_col) = leaf_mi; if info.ref1.is_some() { let (mv, mv1, is_new_mv) = write_compound_block( - enc, cdfs, neighbours, grid, (mi_row, mi_col), (2, 2), - (has_above, has_left), info, (mi_cols as usize, mi_rows as usize), + enc, + cdfs, + neighbours, + grid, + (mi_row, mi_col), + (2, 2), + (has_above, has_left), + info, + (mi_cols as usize, mi_rows as usize), )?; for dr in 0..2 { for dc in 0..2 { - grid.set(mi_row + dr, mi_col + dc, MiInfo { - is_inter: true, - ref_frame: info.ref_frame, - ref_frame1: info.ref1.unwrap_or(NO_REF1), - mv1: mv16(mv1), - mv: mv16(mv), - is_new_mv, - size: 2, - size_h: 2, - is_global_mv0: false, - is_global_mv1: false, - }); + grid.set( + mi_row + dr, + mi_col + dc, + MiInfo { + is_inter: true, + ref_frame: info.ref_frame, + ref_frame1: info.ref1.unwrap_or(NO_REF1), + mv1: mv16(mv1), + mv: mv16(mv), + is_new_mv, + size: 2, + size_h: 2, + is_global_mv0: false, + is_global_mv1: false, + }, + ); } } mode_for_tx = 0; } else { - write_single_ref(enc, cdfs, info.ref_frame, neighbours.above_ref[leaf_mi.1], neighbours.above_ref1[leaf_mi.1], neighbours.left_ref[leaf_mi.0], neighbours.left_ref1[leaf_mi.0]); + write_single_ref( + enc, + cdfs, + info.ref_frame, + neighbours.above_ref[leaf_mi.1], + neighbours.above_ref1[leaf_mi.1], + neighbours.left_ref[leaf_mi.0], + neighbours.left_ref1[leaf_mi.0], + ); - let stack = find_mv_stack( - grid, - mi_row, - mi_col, - 2, - 2, - info.ref_frame, - mi_cols as usize, - mi_rows as usize, - ); + let stack = find_mv_stack( + grid, + mi_row, + mi_col, + 2, + 2, + info.ref_frame, + mi_cols as usize, + mi_rows as usize, + ); - let (mv, is_new_mv) = write_inter_mode(enc, cdfs, info, &stack)?; - for dr in 0..2 { - for dc in 0..2 { - grid.set( - mi_row + dr, - mi_col + dc, - MiInfo { - is_inter: true, - ref_frame: info.ref_frame, - ref_frame1: NO_REF1, - mv1: (0, 0), - mv: mv16(mv), - is_new_mv, - size: 2, - size_h: 2, - is_global_mv0: false, - is_global_mv1: false, - }, - ); + let (mv, is_new_mv) = write_inter_mode(enc, cdfs, info, &stack)?; + for dr in 0..2 { + for dc in 0..2 { + grid.set( + mi_row + dr, + mi_col + dc, + MiInfo { + is_inter: true, + ref_frame: info.ref_frame, + ref_frame1: NO_REF1, + mv1: (0, 0), + mv: mv16(mv), + is_new_mv, + size: 2, + size_h: 2, + is_global_mv0: false, + is_global_mv1: false, + }, + ); + } } - } - write_motion_mode( - enc, - cdfs, - grid, - (mi_row, mi_col), - (2, 2), - (8, 8), - (mi_cols as usize, mi_rows as usize), - info.ref_frame, - block.motion_mode, - )?; - mode_for_tx = 0; + write_motion_mode( + enc, + cdfs, + grid, + (mi_row, mi_col), + (2, 2), + (8, 8), + (mi_cols as usize, mi_rows as usize), + info.ref_frame, + block.motion_mode, + )?; + mode_for_tx = 0; } } else { let mode = usize::from(block.mode); enc.symbol(mode, &mut cdfs.y_mode[SIZE_GROUP_8]); if (V_PRED..=D67_PRED).contains(&mode) { enc.symbol( - (ANGLE_DELTA_ZERO as i32 + i32::from(block.angle_delta_y)) as usize, - &mut cdfs.angle_delta[mode - V_PRED], - ); + (ANGLE_DELTA_ZERO as i32 + i32::from(block.angle_delta_y)) as usize, + &mut cdfs.angle_delta[mode - V_PRED], + ); } let uv_mode = usize::from(block.uv_mode); enc.symbol(uv_mode, &mut cdfs.uv_mode_cfl[mode]); @@ -8606,7 +8866,7 @@ fn write_inter_frame_leaf8( } else { [TxbSet::Luma8, TxbSet::Chroma4, TxbSet::Chroma4] }; - let tx = if tx_select { + let tx = if tx_select { write_tx_syntax_inter( enc, cdfs, @@ -8628,7 +8888,13 @@ fn write_inter_frame_leaf8( vec![0i32; TX4 * TX4], ]; neighbours.record_mi(leaf_mi, 8, &zero_grids); - neighbours.record_inter_mi(leaf_mi, 8, block.skip, block.inter.is_some(), block_ref(block)); + neighbours.record_inter_mi( + leaf_mi, + 8, + block.skip, + block.inter.is_some(), + block_ref(block), + ); record_block_compound(neighbours, leaf_mi, 8, block); } else { let grids = [ @@ -8638,7 +8904,16 @@ fn write_inter_frame_leaf8( ]; if split { write_luma_tus( - enc, cdfs, neighbours, leaf_mi, 8, tx, &grids[0], mode_for_tx, all_scans, is_inter, + enc, + cdfs, + neighbours, + leaf_mi, + 8, + tx, + &grids[0], + mode_for_tx, + all_scans, + is_inter, &block.luma_tx_types, )?; } @@ -8666,13 +8941,13 @@ mod tests { use super::*; use crate::frame::frame_obu; use crate::obu::temporal_delimiter; + use crate::probe::run_with_stdin; use crate::sequence::sequence_header_obu; use ec_av1_syntax::sequence::SequenceHeader; use ec_av1_syntax::{ - FrameHeader, FrameType, LoopFilterParams, PRIMARY_REF_NONE, QuantizationParams, TileInfo, - TxMode, + FrameHeader, FrameType, LoopFilterParams, QuantizationParams, TileInfo, TxMode, + PRIMARY_REF_NONE, }; - use std::io::Write; use std::process::{Command, Stdio}; /// A 64x64 sequence with every tool this writer does not code turned off: @@ -8763,29 +9038,12 @@ mod tests { /// Decodes an AV1 OBU stream with ffmpeg and hands back the planes. fn ffmpeg_decode(stream: &[u8], w: usize, h: usize) -> Vec { - let mut child = Command::new("ffmpeg") - .args([ + let out = run_with_stdin( + Command::new("ffmpeg").args([ "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", - ]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .expect("ffmpeg failed to start"); - // lane-t900 r10: the stream goes down stdin on ITS OWN THREAD. Writing - // it inline deadlocks the moment ffmpeg's stdout pipe buffer (64 KiB) - // fills before the last input byte is written -- which is exactly what - // a 1.1 MB fixture decoding to 150 MB of raw 10-bit frames does - // (measured: 45 min, both processes at 0% CPU). A write error here is - // swallowed on purpose: ffmpeg's own exit status and stderr, asserted - // below, are the real diagnosis. - let mut stdin = child.stdin.take().expect("ffmpeg stdin"); - let payload = stream.to_vec(); - let writer = std::thread::spawn(move || { - let _ = stdin.write_all(&payload); - }); - let out = child.wait_with_output().expect("ffmpeg failed to run"); - writer.join().expect("ffmpeg stdin writer thread"); + ]), + stream, + ); assert!( out.status.success(), "ffmpeg refused the stream: {}", @@ -10327,7 +10585,11 @@ mod tests { .map(|&v| { let m = f64::from(v).abs() + 0.5; let l = if m < 1.0 { 0 } else { m.floor() as i32 }; - if v < 0.0 { -l } else { l } + if v < 0.0 { + -l + } else { + l + } }) .collect(); let before = levels.clone(); @@ -10340,18 +10602,40 @@ mod tests { .zip(&scaled) .enumerate() .map(|(i, (&l, &s))| { - (if i == 0 { dc_weight } else { 1.0 }) - * (f64::from(s) - f64::from(l)).powi(2) + (if i == 0 { dc_weight } else { 1.0 }) * (f64::from(s) - f64::from(l)).powi(2) }) .sum(); d + lambda * coeff_bits(grid, set, crate::decode::q_ctx_of(q), 0, 0) }; - let bits = rdoq(&mut levels, &scaled, side, q, set, 0, 0, lambda, TxType::DctDct); - assert_eq!(bits, coeff_bits(&levels, set, crate::decode::q_ctx_of(q), 0, 0)); - assert!(cost(&levels) <= cost(&before), "{:?} vs {:?}", cost(&levels), cost(&before)); + let bits = rdoq( + &mut levels, + &scaled, + side, + q, + set, + 0, + 0, + lambda, + TxType::DctDct, + ); + assert_eq!( + bits, + coeff_bits(&levels, set, crate::decode::q_ctx_of(q), 0, 0) + ); + assert!( + cost(&levels) <= cost(&before), + "{:?} vs {:?}", + cost(&levels), + cost(&before) + ); // The tail is what it is for: the last coded position moves earlier. let last = |g: &[i32]| scan_of(side).iter().rposition(|&p| g[usize::from(p)] != 0); - assert!(last(&levels) < last(&before), "eob {:?} -> {:?}", last(&before), last(&levels)); + assert!( + last(&levels) < last(&before), + "eob {:?} -> {:?}", + last(&before), + last(&levels) + ); // A 64-point transform is priced on its top-left 32x32 corner, and // the pass has to hand back THAT price (the dense path). let (side, set) = (64usize, TxbSet::Luma64); @@ -10364,14 +10648,31 @@ mod tests { .map(|&v| { let m = f64::from(v).abs() + 0.5; let l = if m < 1.0 { 0 } else { m.floor() as i32 }; - if v < 0.0 { -l } else { l } + if v < 0.0 { + -l + } else { + l + } }) .collect(); - let bits = rdoq(&mut levels, &scaled, side, q, set, 0, 0, lambda, TxType::DctDct); + let bits = rdoq( + &mut levels, + &scaled, + side, + q, + set, + 0, + 0, + lambda, + TxType::DctDct, + ); let corner: Vec = (0..32) .flat_map(|row| levels[row * side..][..32].to_vec()) .collect(); - assert_eq!(bits, coeff_bits(&corner, set, crate::decode::q_ctx_of(q), 0, 0)); + assert_eq!( + bits, + coeff_bits(&corner, set, crate::decode::q_ctx_of(q), 0, 0) + ); } #[test] @@ -10848,7 +11149,11 @@ mod tests { (d << 3) | (fr << 1) | 1 }; let mag = mv_class_base(class) + local as i32 + 1; - if sign == 1 { -mag } else { mag } + if sign == 1 { + -mag + } else { + mag + } } /// Decodes one superblock a [`sb_coeff_inter_frame_tile`] payload wrote, diff --git a/lanes/av1pipedrain.report.md b/lanes/av1pipedrain.report.md new file mode 100644 index 00000000..e5b575b0 --- /dev/null +++ b/lanes/av1pipedrain.report.md @@ -0,0 +1,112 @@ +# lane-av1-pipedrain — test-infra pipe-drain fix + +Branch `lane-av1-pipedrain` @ main `5f5aef9a`. Worktree +`/home/user/Documents/Code/Rust/edith_codecs-av1pipe`. No push. + +## Defect + +Every `a_real_aomenc_*` gate spawned aomenc with piped stdin/stdout/stderr and +wrote the y4m down stdin INLINE before `wait_with_output()`. When aomenc's +stdout pipe buffer (~64 KiB) filled before the last input byte was written, +the child blocked in write(2) on stdout and the test blocked in `write_all` +on stdin — both at 0% CPU until the harness timeout, or EPIPE flakes when the +child was killed. Hit four times across lanes today; the class was already +diagnosed once for the ffmpeg helpers (lane-t900 r10: 45-minute hang on a +1.1 MB fixture; lane-gaterecipe r1: one 384x256 cq-10 encode hung 40 minutes +until a hand-rolled feeder thread fixed that ONE aomenc site). + +## Census (before) + +`crates/ec-av1/src`, piped-stdin spawn sites (child stdin piped AND fed): + +| file | aomenc gates | ffmpeg helpers | total | +|-----------|-------------:|---------------:|------:| +| stream.rs | 139 | 4 | 143 | +| decode.rs | — | 2 | 2 | +| encode.rs | — | 2 | 2 | +| tile.rs | — | 1 | 1 | +| **all** | **139** | **9** | **148** | + +Of the 148: **138 were dangerous** (inline `write_all` before +`wait_with_output`, incl. compact `.unwrap()`/`.ok()` shapes and +EPIPE-tolerant `.or_else(BrokenPipe)` shapes — the latter only help when the +child EXITED, not when it is alive and blocked) and **10 were safe** but +duplicated the feeder-thread pattern (9 ffmpeg decode helpers + 1 aomenc +gate, the lane-gaterecipe r1 site). The intrabc merge-close "~150 sites, one +already feeder-thread-fixed" = these 148. + +Untouched by design: 2 stream.rs aomenc spawns fed by FILE +(`stdin(Stdio::null())`, `.arg(&y4m_path)`) and every ffprobe/ffmpeg +`.output()` / `.status()` site (nothing feeds stdin, so no cycle exists). + +## Fix + +One shared helper, `crates/ec-av1/src/probe.rs` (`#[cfg(test)]`): + +```rust +pub(crate) fn run_with_stdin(cmd: &mut Command, input: &[u8]) -> std::process::Output +``` + +- sets piped stdin/stdout/stderr, spawns the child; +- a writer thread owns stdin (`let _ = stdin.write_all(&payload)` — EPIPE is + swallowed on purpose: the child's exit status and stderr, asserted by the + caller, are the real diagnosis; aomenc refusing early can never panic the + feeder); +- the parent runs `wait_with_output()`, which drains stdout AND stderr + concurrently — no pipe can fill against a blocked writer, so multi-MB y4m + inputs always meet a reader; +- joins the writer thread, returns `Output`. + +Every one of the 148 sites now calls it (the ffmpeg decode helpers keep their +pixel-parsing tails; callers keep their own `assert!(out.status.success(), … +{stderr})` messages). Migration: a bounded, validating Python codemod +(transformed 136 stream.rs sites; runaway guards — bounded window, exactly +one `write_all`, no `assert!`/`decode_stream`/`Command::new` in the replaced +span — left anything non-uniform for hand edits) + 12 hand migrations +(feeder-thread site, `let out = { … }` bare-expression block, affine-oracle +`Command::new(affine_aomenc_path())` site, `.ok()`/`unwrap` compact shapes, +`let enc` binding, 9 ffmpeg helpers). + +Grep proof (final tree): zero `stdin.take()`/child-stdin `write_all` outside +`probe.rs`; `wait_with_output` appears only inside the helper and at the two +file-fed spawns. Zero `stdin(Stdio::piped())` outside `probe.rs`. + +Diff: 5 source files, +1065/−2492 (net −1427 lines of duplicated boilerplate +removed); whitespace-insensitive +871/−2298. + +## Verification + +Toolchain: aomenc oracle `~/.cache/aom-oracle/build/aomenc` + affine oracle +`~/.cache/aom-affine/build/aomenc`, system ffmpeg; release test binary; +`EC_AV1_REQUIRE_AOMENC=1 EC_AV1_REQUIRE_FFMPEG=1` (skips fail the run). + +- `cargo check -p ec-av1 --all-targets`: **0 warnings**. +- Stress, previously-flaked gate + `a_real_aomenc_inter_sequence_with_intra_16x4_strips_in_1to4_partitions_\ +decodes_pixel_exact` × 20 sequential runs: + **20/20 pass, 0 fail** (28.3 min wall; each run does the full multi-attempt + encode sweep + pixel compares). +- Scoped battery, 50 gates through the migrated paths (intrabc unblock set + 13, rect14 16x4/4x16 set 5, loss64/lossless set 4, real-aomenc family + 25 incl. tile-rows/columns, tile-group OBUs, sb128 family, obmc, wedge, + comp-mode, temporal-MV, cdef, filter-intra, 1D-tx rect, palette-on-rect, + 10-bit; plus 3 tile::tests ffmpeg-decode helpers): + **50/50 green** (two initially misnamed entries re-checked by exact name, + both pass; census sweeps among them ran their full 20–40 attempt loops). + +## Notes / follow-ups + +- The repo is NOT rustfmt-clean under default `rustfmt --edition 2024` + (pristine stream.rs shows a 7776-line diff), so no wholesale fmt pass was + applied. One honest exception: tile.rs carries ~600 lines of rustfmt reflow + around the ffmpeg_decode helper migration (raw churn 1051 lines vs 663 + whitespace-insensitive; 388 lines differ by whitespace alone) — format-only + churn, semantically inert, not a defect. Any future + "just cargo fmt it" would churn ~40k-line files wholesale; decide that + separately, never inside a content lane. +- `ec-av1-syntax` and `examples/` spawn no aomenc/ffmpeg on piped stdin; + other ec-* crates are out of this lane's scope but share none of these + helpers. +- The helper names the generic spawn/reap failures ("encoder failed to + start/run"); per-gate diagnosis stays in each gate's own + `assert!(status.success(), …)` on stderr, unchanged.