forge
Explore
Log in

Don't you dare go Hollow

Merge lane-av1-pipedrain: shared pipe-draining spawn runner (148 sites, suite EPIPE class fixed)

Browse files at this commit

c6c64c8b8af3e5e0c7592f693fb073a1fceeebedAhmet Kaan GümüşParent: cad19f8d022bcf

6 changed files +1177 -2492

crates/ec-av1/src/decode.rsmodified+11 -51
@@ -40943,7 +40943,7 @@ mod tests {
4094340943 // duplicating `crate::encode`'s own `#[cfg(test)]` helpers of the same
4094440944 // name (that module is another lane's territory this round, and the
4094540945 // helpers are `#[cfg(test)]`-private to it).
40946- use std::io::Write;
40946+ use crate::probe::run_with_stdin;
4094740947 use std::process::{Command, Stdio};
4094840948
4094940949 /// Whether ffmpeg is on PATH. Absence normally SKIPs, but
@@ -40972,32 +40972,12 @@ mod tests {
4097240972 /// Decodes one AV1 OBU stream with ffmpeg and hands back its one 4:2:0
4097340973 /// frame's planes, at ffmpeg's own (coded, block-padded) size.
4097440974 fn ffmpeg_decode(stream: &[u8], width: usize, height: usize) -> Picture {
40975- let mut child = Command::new("ffmpeg")
40976- .args([
40975+ let out = run_with_stdin(
40976+ Command::new("ffmpeg").args([
4097740977 "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-",
40978- ])
40979- .stdin(Stdio::piped())
40980- .stdout(Stdio::piped())
40981- .stderr(Stdio::piped())
40982- .spawn()
40983- .expect("ffmpeg failed to start");
40984- // lane-t900 r10: the stream goes down stdin on ITS OWN THREAD. Writing
40985- // it inline deadlocks the moment ffmpeg's stdout pipe buffer (64 KiB)
40986- // fills before the last input byte is written -- which is exactly what
40987- // a 1.1 MB fixture decoding to 150 MB of raw 10-bit frames does
40988- // (measured: 45 min, both processes at 0% CPU). A write error here is
40989- // swallowed on purpose: ffmpeg's own exit status and stderr, asserted
40990- // below, are the real diagnosis.
40991- let mut stdin = child.stdin.take().expect("ffmpeg stdin");
40992- let payload = stream.to_vec();
40993- let writer = std::thread::Builder::new()
40994- .name("ec-av1-ffmpeg-in".into())
40995- .spawn(move || {
40996- let _ = stdin.write_all(&payload);
40997- })
40998- .expect("spawning the ffmpeg stdin writer");
40999- let out = child.wait_with_output().expect("ffmpeg failed to run");
41000- writer.join().expect("ffmpeg stdin writer thread");
40978+ ]),
40979+ stream,
40980+ );
4100140981 assert!(
4100240982 out.status.success(),
4100340983 "ffmpeg refused the stream: {}",
@@ -41025,32 +41005,12 @@ mod tests {
4102541005 height: usize,
4102641006 frames: usize,
4102741007 ) -> Vec<Picture> {
41028- let mut child = Command::new("ffmpeg")
41029- .args([
41008+ let out = run_with_stdin(
41009+ Command::new("ffmpeg").args([
4103041010 "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-",
41031- ])
41032- .stdin(Stdio::piped())
41033- .stdout(Stdio::piped())
41034- .stderr(Stdio::piped())
41035- .spawn()
41036- .expect("ffmpeg failed to start");
41037- // lane-t900 r10: the stream goes down stdin on ITS OWN THREAD. Writing
41038- // it inline deadlocks the moment ffmpeg's stdout pipe buffer (64 KiB)
41039- // fills before the last input byte is written -- which is exactly what
41040- // a 1.1 MB fixture decoding to 150 MB of raw 10-bit frames does
41041- // (measured: 45 min, both processes at 0% CPU). A write error here is
41042- // swallowed on purpose: ffmpeg's own exit status and stderr, asserted
41043- // below, are the real diagnosis.
41044- let mut stdin = child.stdin.take().expect("ffmpeg stdin");
41045- let payload = stream.to_vec();
41046- let writer = std::thread::Builder::new()
41047- .name("ec-av1-ffmpeg-in".into())
41048- .spawn(move || {
41049- let _ = stdin.write_all(&payload);
41050- })
41051- .expect("spawning the ffmpeg stdin writer");
41052- let out = child.wait_with_output().expect("ffmpeg failed to run");
41053- writer.join().expect("ffmpeg stdin writer thread");
41011+ ]),
41012+ stream,
41013+ );
4105441014 assert!(
4105541015 out.status.success(),
4105641016 "ffmpeg refused the stream: {}",
crates/ec-av1/src/encode.rsmodified+11 -45
@@ -15101,7 +15101,7 @@ mod tests {
1510115101 }
1510215102 use super::*;
1510315103 use crate::intra::{D45_PRED, D135_PRED, H_PRED, KEY_FRAME_MODES, NON_DIRECTIONAL, V_PRED};
15104- use std::io::Write;
15104+ use crate::probe::run_with_stdin;
1510515105 use std::process::{Command, Stdio};
1510615106
1510715107 /// Every rectangular shape this decoder codes, at every position a block
@@ -15260,29 +15260,12 @@ mod tests {
1526015260
1526115261 /// Decodes an AV1 OBU stream with ffmpeg and hands back the three planes.
1526215262 fn ffmpeg_decode(stream: &[u8], width: usize, height: usize) -> Picture {
15263- let mut child = Command::new("ffmpeg")
15264- .args([
15263+ let out = run_with_stdin(
15264+ Command::new("ffmpeg").args([
1526515265 "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-",
15266- ])
15267- .stdin(Stdio::piped())
15268- .stdout(Stdio::piped())
15269- .stderr(Stdio::piped())
15270- .spawn()
15271- .expect("ffmpeg failed to start");
15272- // lane-t900 r10: the stream goes down stdin on ITS OWN THREAD. Writing
15273- // it inline deadlocks the moment ffmpeg's stdout pipe buffer (64 KiB)
15274- // fills before the last input byte is written -- which is exactly what
15275- // a 1.1 MB fixture decoding to 150 MB of raw 10-bit frames does
15276- // (measured: 45 min, both processes at 0% CPU). A write error here is
15277- // swallowed on purpose: ffmpeg's own exit status and stderr, asserted
15278- // below, are the real diagnosis.
15279- let mut stdin = child.stdin.take().expect("ffmpeg stdin");
15280- let payload = stream.to_vec();
15281- let writer = std::thread::spawn(move || {
15282- let _ = stdin.write_all(&payload);
15283- });
15284- let out = child.wait_with_output().expect("ffmpeg failed to run");
15285- writer.join().expect("ffmpeg stdin writer thread");
15266+ ]),
15267+ stream,
15268+ );
1528615269 assert!(
1528715270 out.status.success(),
1528815271 "ffmpeg refused the stream: {}",
@@ -17231,29 +17214,12 @@ mod tests {
1723117214 height: usize,
1723217215 frames: usize,
1723317216 ) -> Vec<Picture> {
17234- let mut child = Command::new("ffmpeg")
17235- .args([
17217+ let out = run_with_stdin(
17218+ Command::new("ffmpeg").args([
1723617219 "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-",
17237- ])
17238- .stdin(Stdio::piped())
17239- .stdout(Stdio::piped())
17240- .stderr(Stdio::piped())
17241- .spawn()
17242- .expect("ffmpeg failed to start");
17243- // lane-t900 r10: the stream goes down stdin on ITS OWN THREAD. Writing
17244- // it inline deadlocks the moment ffmpeg's stdout pipe buffer (64 KiB)
17245- // fills before the last input byte is written -- which is exactly what
17246- // a 1.1 MB fixture decoding to 150 MB of raw 10-bit frames does
17247- // (measured: 45 min, both processes at 0% CPU). A write error here is
17248- // swallowed on purpose: ffmpeg's own exit status and stderr, asserted
17249- // below, are the real diagnosis.
17250- let mut stdin = child.stdin.take().expect("ffmpeg stdin");
17251- let payload = stream.to_vec();
17252- let writer = std::thread::spawn(move || {
17253- let _ = stdin.write_all(&payload);
17254- });
17255- let out = child.wait_with_output().expect("ffmpeg failed to run");
17256- writer.join().expect("ffmpeg stdin writer thread");
17220+ ]),
17221+ stream,
17222+ );
1725717223 assert!(
1725817224 out.status.success(),
1725917225 "ffmpeg refused the stream: {}",
crates/ec-av1/src/probe.rsmodified+64 -5
@@ -22,7 +22,10 @@ pub fn dims(clip: &str) -> Option<(usize, usize)> {
2222 .ok()?;
2323 let text = String::from_utf8_lossy(&out.stdout);
2424 let mut f = text.trim().split(',');
25- Some((f.next()?.trim().parse().ok()?, f.next()?.trim().parse().ok()?))
25+ Some((
26+ f.next()?.trim().parse().ok()?,
27+ f.next()?.trim().parse().ok()?,
28+ ))
2629 }
2730
2831 /// 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) {
4144 let (nw, nh) = dims(clip).expect("ffprobe gave no size");
4245 let cw = nw.min(1920) / 128 * 128;
4346 let ch = nh.min(1024) / 128 * 128;
44- assert!(cw >= 128 && ch >= 128, "{nw}x{nh} is smaller than a superblock");
47+ assert!(
48+ cw >= 128 && ch >= 128,
49+ "{nw}x{nh} is smaller than a superblock"
50+ );
4551 let (x, y) = ((nw - cw) / 2 & !1, (nh - ch) / 2 & !1);
4652 (format!("crop={cw}:{ch}:{x}:{y}"), cw, ch)
4753 }
@@ -67,10 +73,18 @@ pub fn source(
6773 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"])
6874 .output()
6975 .expect("ffmpeg failed to run");
70- assert!(out.status.success(), "ffmpeg: {}", String::from_utf8_lossy(&out.stderr));
76+ assert!(
77+ out.status.success(),
78+ "ffmpeg: {}",
79+ String::from_utf8_lossy(&out.stderr)
80+ );
7181 let (luma, chroma) = (width * height, width * height / 4);
7282 let frame_len = luma + 2 * chroma;
73- assert_eq!(out.stdout.len(), frame_len * frames, "expected {frames} 4:2:0 frames");
83+ assert_eq!(
84+ out.stdout.len(),
85+ frame_len * frames,
86+ "expected {frames} 4:2:0 frames"
87+ );
7488 (0..frames)
7589 .map(|i| {
7690 let b = &out.stdout[i * frame_len..][..frame_len];
@@ -78,9 +92,54 @@ pub fn source(
7892 width,
7993 height,
8094 y: b[..luma].iter().map(|&v| u16::from(v)).collect(),
81- u: b[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(),
95+ u: b[luma..luma + chroma]
96+ .iter()
97+ .map(|&v| u16::from(v))
98+ .collect(),
8299 v: b[luma + chroma..].iter().map(|&v| u16::from(v)).collect(),
83100 }
84101 })
85102 .collect()
86103 }
104+
105+/// Runs a test-harness child (`aomenc`, `ffmpeg`) with `input` on its stdin
106+/// and all three pipes drained concurrently, returning the child's
107+/// [`std::process::Output`] (status, stdout, stderr) for the caller to
108+/// assert on.
109+///
110+/// The ONE spawn path for every test that feeds a child on stdin
111+/// (lane-av1-pipedrain). Writing the input INLINE before
112+/// `wait_with_output()` deadlocks as soon as the child's stdout pipe buffer
113+/// (~64 KiB) fills before the last input byte is written: the child blocks
114+/// in write(2), the test blocks in `write_all`, both at 0% CPU until the
115+/// harness timeout -- measured at 45 minutes on a 1.1 MB fixture decoding
116+/// to 150 MB of raw frames (lane-t900 r10), and four aomenc gates still sat
117+/// on the inline pattern after that fix. Here a writer thread owns stdin
118+/// while the parent drains stdout/stderr, so a multi-MB y4m always meets a
119+/// reader, never a blocked writer.
120+///
121+/// A child that exits early (bad flags, refused input) breaks the writer's
122+/// pipe: the EPIPE from `write_all` is swallowed on purpose, and the
123+/// child's own exit status and stderr -- which the caller asserts on --
124+/// carry the real diagnosis.
125+///
126+/// # Panics
127+/// When the child cannot be spawned or reaped, or the writer thread panics.
128+#[cfg(test)]
129+pub(crate) fn run_with_stdin(cmd: &mut Command, input: &[u8]) -> std::process::Output {
130+ use std::io::Write;
131+ use std::process::Stdio;
132+
133+ cmd.stdin(Stdio::piped())
134+ .stdout(Stdio::piped())
135+ .stderr(Stdio::piped());
136+ let mut child = cmd.spawn().expect("encoder failed to start");
137+ let mut stdin = child.stdin.take().expect("encoder stdin");
138+ let payload = input.to_vec();
139+ let writer = std::thread::spawn(move || {
140+ let _ = stdin.write_all(&payload);
141+ });
142+ let out = child.wait_with_output().expect("encoder failed to run");
143+ writer.join().expect("encoder stdin writer thread");
144+ out
145+}
crates/ec-av1/src/stream.rsmodified+301 -2018

Diff too large; view file

@@ -2489,15 +2489,8 @@ pub(crate) mod tests {
24892489 args.push(limit);
24902490 args.extend(extra.iter().map(|s| (*s).to_owned()));
24912491 args.extend(["--obu".to_owned(), "-o".to_owned(), "-".to_owned(), "-".to_owned()]);
2492- let mut child = Command::new(aomenc_path())
2493- .args(&args)
2494- .stdin(Stdio::piped())
2495- .stdout(Stdio::piped())
2496- .stderr(Stdio::piped())
2497- .spawn()
2498- .expect("aomenc failed to start");
2499- child.stdin.take().expect("aomenc stdin").write_all(&y4m.stdout).expect("write y4m");
2500- let out = child.wait_with_output().expect("aomenc failed to run");
2492+ let out = run_with_stdin(Command::new(aomenc_path())
2493+ .args(&args), &y4m.stdout);
25012494 assert!(out.status.success(), "aomenc refused {args:?}: {}", String::from_utf8_lossy(&out.stderr));
25022495 let stream = out.stdout;
25032496 let result = match decode_stream(&stream) {
@@ -2578,15 +2571,8 @@ pub(crate) mod tests {
25782571 .collect();
25792572 args.insert(1, limit);
25802573 args.extend(extra.iter().map(|s| (*s).to_owned()));
2581- let mut child = Command::new(aomenc_path())
2582- .args(&args)
2583- .stdin(Stdio::piped())
2584- .stdout(Stdio::piped())
2585- .stderr(Stdio::piped())
2586- .spawn()
2587- .expect("aomenc failed to start");
2588- child.stdin.take().expect("aomenc stdin").write_all(&y4m.stdout).expect("write y4m");
2589- let out = child.wait_with_output().expect("aomenc failed to run");
2574+ let out = run_with_stdin(Command::new(aomenc_path())
2575+ .args(&args), &y4m.stdout);
25902576 assert!(
25912577 out.status.success(),
25922578 "{NAME}: aomenc refused {args:?}: {}",
@@ -2614,20 +2600,10 @@ pub(crate) mod tests {
26142600 mixed_arms += 1;
26152601 // (3) libaom accepts it: ffmpeg's own libaom decoder produces the
26162602 // stream without an error.
2617- let mut ff = Command::new("ffmpeg")
2618- .args(["-v", "error", "-f", "obu", "-i", "-", "-f", "null", "-"])
2619- .stdin(Stdio::piped())
2620- .stdout(Stdio::null())
2621- .stderr(Stdio::piped())
2622- .spawn()
2623- .expect("ffmpeg failed to start");
2624- let mut stdin = ff.stdin.take().expect("ffmpeg stdin");
2625- let payload = stream.clone();
2626- let writer = std::thread::spawn(move || {
2627- let _ = stdin.write_all(&payload);
2628- });
2629- let out = ff.wait_with_output().expect("ffmpeg failed to run");
2630- writer.join().expect("ffmpeg stdin writer");
2603+ let out = run_with_stdin(
2604+ Command::new("ffmpeg").args(["-v", "error", "-f", "obu", "-i", "-", "-f", "null", "-"]),
2605+ &stream,
2606+ );
26312607 assert!(
26322608 out.status.success(),
26332609 "{NAME}: ffmpeg refused a stream with {mixed} mixed-frame(s): {}",
@@ -3228,7 +3204,7 @@ pub(crate) mod tests {
32283204 let input_depth_arg = format!("--input-bit-depth={bit_depth}");
32293205 let cq_arg = format!("--cq-level={cq}");
32303206 let limit_arg = format!("--limit={frames}");
3231- let mut child = Command::new(aomenc_path())
3207+ let out = run_with_stdin(Command::new(aomenc_path())
32323208 .args([
32333209 "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg,
32343210 // cpu-used >= 1 keeps libaom on 64x64 superblocks at these
@@ -3255,19 +3231,7 @@ pub(crate) mod tests {
32553231 "--enable-paeth-intra=0", "--enable-filter-intra=0",
32563232 "--enable-tx-size-search=0",
32573233 "--obu", "-o", "-", "-",
3258- ])
3259- .stdin(Stdio::piped())
3260- .stdout(Stdio::piped())
3261- .stderr(Stdio::piped())
3262- .spawn()
3263- .expect("aomenc failed to start");
3264- child
3265- .stdin
3266- .take()
3267- .expect("aomenc stdin")
3268- .write_all(&y4m.stdout)
3269- .expect("write y4m");
3270- let out = child.wait_with_output().expect("aomenc failed to run");
3234+ ]), &y4m.stdout);
32713235 assert!(
32723236 out.status.success(),
32733237 "aomenc refused: {}",
@@ -3426,20 +3390,13 @@ pub(crate) mod tests {
34263390 .output()
34273391 .expect("ffmpeg failed to run");
34283392 assert!(y4m.status.success(), "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr));
3429- let mut child = Command::new(aomenc_path())
3393+ let out = run_with_stdin(Command::new(aomenc_path())
34303394 .args([
34313395 "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32",
34323396 "--cpu-used=0", "--sb-size=128", "--min-partition-size=16",
34333397 "--kf-max-dist=0", "--limit=1",
34343398 "--threads=1", "--row-mt=0", "--obu", "-o", "-", "-",
3435- ])
3436- .stdin(Stdio::piped())
3437- .stdout(Stdio::piped())
3438- .stderr(Stdio::piped())
3439- .spawn()
3440- .expect("aomenc failed to start");
3441- child.stdin.take().expect("aomenc stdin").write_all(&y4m.stdout).expect("write y4m");
3442- let out = child.wait_with_output().expect("aomenc failed to run");
3399+ ]), &y4m.stdout);
34433400 assert!(out.status.success(), "aomenc refused: {}", String::from_utf8_lossy(&out.stderr));
34443401 let stream = out.stdout;
34453402
@@ -3625,7 +3582,7 @@ pub(crate) mod tests {
36253582 assert!(format!("{err}").contains("sink says stop"), "{err}");
36263583 }
36273584
3628- use std::io::Write;
3585+ use crate::probe::run_with_stdin;
36293586 use std::process::{Command, Stdio};
36303587
36313588 /// Firing-detection gates (single-ref envelope, temporal-MV, `comp_mode`,
@@ -3699,32 +3656,12 @@ pub(crate) mod tests {
36993656 height: usize,
37003657 frames: usize,
37013658 ) -> Vec<Pic> {
3702- let mut child = Command::new("ffmpeg")
3703- .args([
3659+ let out = run_with_stdin(
3660+ Command::new("ffmpeg").args([
37043661 "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-",
3705- ])
3706- .stdin(Stdio::piped())
3707- .stdout(Stdio::piped())
3708- .stderr(Stdio::piped())
3709- .spawn()
3710- .expect("ffmpeg failed to start");
3711- // lane-t900 r10: the stream goes down stdin on ITS OWN THREAD. Writing
3712- // it inline deadlocks the moment ffmpeg's stdout pipe buffer (64 KiB)
3713- // fills before the last input byte is written -- which is exactly what
3714- // a 1.1 MB fixture decoding to 150 MB of raw 10-bit frames does
3715- // (measured: 45 min, both processes at 0% CPU). A write error here is
3716- // swallowed on purpose: ffmpeg's own exit status and stderr, asserted
3717- // below, are the real diagnosis.
3718- let mut stdin = child.stdin.take().expect("ffmpeg stdin");
3719- let payload = stream.to_vec();
3720- let writer = std::thread::Builder::new()
3721- .name("ec-av1-ffmpeg-in".into())
3722- .spawn(move || {
3723- let _ = stdin.write_all(&payload);
3724- })
3725- .expect("spawning the ffmpeg stdin writer");
3726- let out = child.wait_with_output().expect("ffmpeg failed to run");
3727- writer.join().expect("ffmpeg stdin writer thread");
3662+ ]),
3663+ stream,
3664+ );
37283665 assert!(
37293666 out.status.success(),
37303667 "ffmpeg refused the stream: {}",
@@ -3754,33 +3691,20 @@ pub(crate) mod tests {
37543691
37553692 /// As [`ffmpeg_decode_sequence`], for a MONOCHROME stream: one 8-bit luma
37563693 /// plane per frame, exactly what `ffmpeg -pix_fmt gray -f rawvideo` writes
3757- /// (lane-av1mono). Fed down a stdin writer thread for the reason the 4:2:0
3758- /// helper documents.
3694+ /// (lane-av1mono). Fed through [`run_with_stdin`] for the reason its doc
3695+ /// records.
37593696 fn ffmpeg_decode_gray_sequence(
37603697 stream: &[u8],
37613698 width: usize,
37623699 height: usize,
37633700 frames: usize,
37643701 ) -> Vec<u8> {
3765- let mut child = Command::new("ffmpeg")
3766- .args([
3702+ let out = run_with_stdin(
3703+ Command::new("ffmpeg").args([
37673704 "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "gray", "-",
3768- ])
3769- .stdin(Stdio::piped())
3770- .stdout(Stdio::piped())
3771- .stderr(Stdio::piped())
3772- .spawn()
3773- .expect("ffmpeg failed to start");
3774- let mut stdin = child.stdin.take().expect("ffmpeg stdin");
3775- let payload = stream.to_vec();
3776- let writer = std::thread::Builder::new()
3777- .name("ec-av1-ffmpeg-gray-in".into())
3778- .spawn(move || {
3779- let _ = stdin.write_all(&payload);
3780- })
3781- .expect("spawning the ffmpeg stdin writer");
3782- let out = child.wait_with_output().expect("ffmpeg failed to run");
3783- writer.join().expect("ffmpeg stdin writer thread");
3705+ ]),
3706+ stream,
3707+ );
37843708 assert!(
37853709 out.status.success(),
37863710 "ffmpeg refused the monochrome stream: {}",
@@ -3806,33 +3730,13 @@ pub(crate) mod tests {
38063730 height: usize,
38073731 frames: usize,
38083732 ) -> Vec<Pic> {
3809- let mut child = Command::new("ffmpeg")
3810- .args([
3733+ let out = run_with_stdin(
3734+ Command::new("ffmpeg").args([
38113735 "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt",
38123736 "yuv420p10le", "-",
3813- ])
3814- .stdin(Stdio::piped())
3815- .stdout(Stdio::piped())
3816- .stderr(Stdio::piped())
3817- .spawn()
3818- .expect("ffmpeg failed to start");
3819- // lane-t900 r10: the stream goes down stdin on ITS OWN THREAD. Writing
3820- // it inline deadlocks the moment ffmpeg's stdout pipe buffer (64 KiB)
3821- // fills before the last input byte is written -- which is exactly what
3822- // a 1.1 MB fixture decoding to 150 MB of raw 10-bit frames does
3823- // (measured: 45 min, both processes at 0% CPU). A write error here is
3824- // swallowed on purpose: ffmpeg's own exit status and stderr, asserted
3825- // below, are the real diagnosis.
3826- let mut stdin = child.stdin.take().expect("ffmpeg stdin");
3827- let payload = stream.to_vec();
3828- let writer = std::thread::Builder::new()
3829- .name("ec-av1-ffmpeg-in".into())
3830- .spawn(move || {
3831- let _ = stdin.write_all(&payload);
3832- })
3833- .expect("spawning the ffmpeg stdin writer");
3834- let out = child.wait_with_output().expect("ffmpeg failed to run");
3835- writer.join().expect("ffmpeg stdin writer thread");
3737+ ]),
3738+ stream,
3739+ );
38363740 assert!(
38373741 out.status.success(),
38383742 "ffmpeg refused the stream: {}",
@@ -5041,7 +4945,7 @@ pub(crate) mod tests {
50414945 .expect("ffmpeg failed to run");
50424946 assert!(out.status.success(), "ffmpeg failed for testsrc2 {width}x{height}");
50434947 let y4m = out.stdout;
5044- let mut child = Command::new(aomenc_path())
4948+ let out = run_with_stdin(Command::new(aomenc_path())
50454949 .args(["--codec=av1", "--bit-depth=8", "--input-bit-depth=8"])
50464950 .args([
50474951 "--passes=1",
@@ -5056,19 +4960,7 @@ pub(crate) mod tests {
50564960 "--enable-1to4-partitions=1",
50574961 ])
50584962 .args(extra)
5059- .args(["--obu", "-o", "-", "-"])
5060- .stdin(Stdio::piped())
5061- .stdout(Stdio::piped())
5062- .stderr(Stdio::piped())
5063- .spawn()
5064- .expect("aomenc failed to start");
5065- child
5066- .stdin
5067- .take()
5068- .expect("aomenc stdin")
5069- .write_all(&y4m)
5070- .expect("aomenc stdin write");
5071- let out = child.wait_with_output().expect("aomenc failed to run");
4963+ .args(["--obu", "-o", "-", "-"]), &y4m);
50724964 assert!(out.status.success(), "aomenc failed: {}", String::from_utf8_lossy(&out.stderr));
50734965 out.stdout
50744966 }
@@ -5616,20 +5508,8 @@ pub(crate) mod tests {
56165508 }
56175509 let mut arm: Vec<&str> = vec!["--arnr-maxframes=0"];
56185510 arm.extend_from_slice(args);
5619- let mut child = Command::new(aomenc_path())
5620- .args(&arm)
5621- .stdin(Stdio::piped())
5622- .stdout(Stdio::piped())
5623- .stderr(Stdio::piped())
5624- .spawn()
5625- .expect("aomenc failed to start");
5626- child
5627- .stdin
5628- .take()
5629- .expect("aomenc stdin")
5630- .write_all(y4m)
5631- .expect("writing y4m to aomenc");
5632- let out = child.wait_with_output().expect("aomenc failed to run");
5511+ let out = run_with_stdin(Command::new(aomenc_path())
5512+ .args(&arm), &y4m);
56335513 assert!(
56345514 out.status.success(),
56355515 "{name} HIDDEN-ARM: aomenc refused its own recipe plus --arnr-maxframes=0: {}",
@@ -5700,7 +5580,7 @@ pub(crate) mod tests {
57005580 );
57015581 let depth_arg = format!("--bit-depth={bit_depth}");
57025582 let input_depth_arg = format!("--input-bit-depth={bit_depth}");
5703- let mut child = Command::new(aomenc_path())
5583+ let out = run_with_stdin(Command::new(aomenc_path())
57045584 .args([
57055585 // lane-defon r1: the repo's only gate that decodes hidden
57065586 // frames is also the only place a FORWARD KEYFRAME can be
@@ -5760,19 +5640,7 @@ pub(crate) mod tests {
57605640 "-o",
57615641 "-",
57625642 "-",
5763- ])
5764- .stdin(Stdio::piped())
5765- .stdout(Stdio::piped())
5766- .stderr(Stdio::piped())
5767- .spawn()
5768- .expect("aomenc failed to start");
5769- child
5770- .stdin
5771- .take()
5772- .expect("aomenc stdin")
5773- .write_all(&y4m.stdout)
5774- .expect("writing y4m to aomenc");
5775- let out = child.wait_with_output().expect("aomenc failed to run");
5643+ ]), &y4m.stdout);
57765644 assert!(
57775645 out.status.success(),
57785646 "{NAME}: aomenc refused the {bit_depth}-bit fixture: {}",
@@ -5867,7 +5735,7 @@ pub(crate) mod tests {
58675735 "ffmpeg refused to generate the y4m fixture: {}",
58685736 String::from_utf8_lossy(&y4m.stderr)
58695737 );
5870- let mut child = Command::new(aomenc_path())
5738+ let out = run_with_stdin(Command::new(aomenc_path())
58715739 .args([
58725740 "--codec=av1",
58735741 "--passes=1",
@@ -5897,19 +5765,7 @@ pub(crate) mod tests {
58975765 "-o",
58985766 "-",
58995767 "-",
5900- ])
5901- .stdin(Stdio::piped())
5902- .stdout(Stdio::piped())
5903- .stderr(Stdio::piped())
5904- .spawn()
5905- .expect("aomenc failed to start");
5906- child
5907- .stdin
5908- .take()
5909- .expect("aomenc stdin")
5910- .write_all(&y4m.stdout)
5911- .expect("writing the y4m fixture to aomenc");
5912- let out = child.wait_with_output().expect("aomenc failed to run");
5768+ ]), &y4m.stdout);
59135769 assert!(
59145770 out.status.success(),
59155771 "aomenc refused the fixture: {}",
@@ -6021,7 +5877,7 @@ pub(crate) mod tests {
60215877 "smptebars must render byte-identical across two runs"
60225878 );
60235879 let y4m = y4m_a;
6024- let mut child = Command::new(aomenc_path())
5880+ let out = run_with_stdin(Command::new(aomenc_path())
60255881 .args([
60265882 "--codec=av1",
60275883 "--passes=1",
@@ -6053,19 +5909,7 @@ pub(crate) mod tests {
60535909 "-o",
60545910 "-",
60555911 "-",
6056- ])
6057- .stdin(Stdio::piped())
6058- .stdout(Stdio::piped())
6059- .stderr(Stdio::piped())
6060- .spawn()
6061- .expect("aomenc failed to start");
6062- child
6063- .stdin
6064- .take()
6065- .expect("aomenc stdin")
6066- .write_all(&y4m)
6067- .expect("writing y4m to aomenc");
6068- let out = child.wait_with_output().expect("aomenc failed to run");
5912+ ]), &y4m);
60695913 assert!(
60705914 out.status.success(),
60715915 "aomenc refused the fixture: {}",
@@ -6156,7 +6000,7 @@ pub(crate) mod tests {
61566000 let y4m = y4m_a;
61576001 let depth_arg = format!("--bit-depth={depth}");
61586002 let input_depth_arg = format!("--input-bit-depth={depth}");
6159- let mut child = Command::new(aomenc_path())
6003+ let out = run_with_stdin(Command::new(aomenc_path())
61606004 .args([
61616005 "--codec=av1",
61626006 "--passes=1",
@@ -6189,19 +6033,7 @@ pub(crate) mod tests {
61896033 // Per-arm overrides go AFTER the base recipe: aomenc keeps the
61906034 // LAST occurrence of a repeated flag.
61916035 .args([&depth_arg, &input_depth_arg])
6192- .args(["--obu", "-o", "-", "-"])
6193- .stdin(Stdio::piped())
6194- .stdout(Stdio::piped())
6195- .stderr(Stdio::piped())
6196- .spawn()
6197- .expect("aomenc failed to start");
6198- child
6199- .stdin
6200- .take()
6201- .expect("aomenc stdin")
6202- .write_all(&y4m)
6203- .expect("writing y4m to aomenc");
6204- let out = child.wait_with_output().expect("aomenc failed to run");
6036+ .args(["--obu", "-o", "-", "-"]), &y4m);
62056037 assert!(
62066038 out.status.success(),
62076039 "{NAME}: aomenc refused the {depth}-bit fixture: {}",
@@ -6302,7 +6134,7 @@ pub(crate) mod tests {
63026134 let cq_arg = format!("--cq-level={cq}");
63036135 let txs_arg = format!("--enable-tx-size-search={txs}");
63046136 let tiles_arg = format!("--tile-columns={tiles}");
6305- let mut child = Command::new(aomenc_path())
6137+ let out = run_with_stdin(Command::new(aomenc_path())
63066138 .args([
63076139 "--codec=av1",
63086140 "--passes=1",
@@ -6324,23 +6156,7 @@ pub(crate) mod tests {
63246156 // aomenc keeps the LAST occurrence of a repeated flag,
63256157 // so per-arm overrides go after the base recipe.
63266158 .args([&depth_arg, &input_depth_arg, &cq_arg, &txs_arg, &tiles_arg])
6327- .args(["--obu", "-o", "-", "-"])
6328- .stdin(Stdio::piped())
6329- .stdout(Stdio::piped())
6330- .stderr(Stdio::piped())
6331- .spawn()
6332- .expect("aomenc failed to start");
6333- child
6334- .stdin
6335- .take()
6336- .expect("aomenc stdin")
6337- .write_all(&y4m)
6338- .or_else(|e| match e.kind() {
6339- std::io::ErrorKind::BrokenPipe => Ok(()),
6340- _ => Err(e),
6341- })
6342- .expect("writing y4m to aomenc");
6343- let out = child.wait_with_output().expect("aomenc failed to run");
6159+ .args(["--obu", "-o", "-", "-"]), &y4m);
63446160 assert!(
63456161 out.status.success(),
63466162 "{NAME}: aomenc refused {arm}: {}",
@@ -6553,7 +6369,7 @@ pub(crate) mod tests {
65536369 let y4m_b = render();
65546370 assert_eq!(y4m_a, y4m_b, "{NAME}: {arm} must render byte-identical across two runs");
65556371 let y4m = y4m_a;
6556- let mut child = Command::new(aomenc_path())
6372+ let out = run_with_stdin(Command::new(aomenc_path())
65576373 .args([
65586374 "--codec=av1",
65596375 "--bit-depth=8",
@@ -6580,23 +6396,7 @@ pub(crate) mod tests {
65806396 ])
65816397 // aomenc keeps the LAST occurrence of a repeated flag.
65826398 .args(*extra)
6583- .args(["--obu", "-o", "-", "-"])
6584- .stdin(Stdio::piped())
6585- .stdout(Stdio::piped())
6586- .stderr(Stdio::piped())
6587- .spawn()
6588- .expect("aomenc failed to start");
6589- child
6590- .stdin
6591- .take()
6592- .expect("aomenc stdin")
6593- .write_all(&y4m)
6594- .or_else(|e| match e.kind() {
6595- std::io::ErrorKind::BrokenPipe => Ok(()),
6596- _ => Err(e),
6597- })
6598- .expect("writing y4m to aomenc");
6599- let out = child.wait_with_output().expect("aomenc failed to run");
6399+ .args(["--obu", "-o", "-", "-"]), &y4m);
66006400 assert!(
66016401 out.status.success(),
66026402 "{NAME}: aomenc refused {arm}: {}",
@@ -6752,7 +6552,7 @@ pub(crate) mod tests {
67526552 .output()
67536553 .expect("ffmpeg")
67546554 .stdout;
6755- let mut child = Command::new(aomenc_path())
6555+ let out = run_with_stdin(Command::new(aomenc_path())
67566556 .args([
67576557 "--codec=av1", "--bit-depth=8", "--input-bit-depth=8", "--passes=1",
67586558 "--end-usage=q", "--cpu-used=0", "--lag-in-frames=0", "--kf-max-dist=1",
@@ -6761,14 +6561,7 @@ pub(crate) mod tests {
67616561 "--min-partition-size=4", "--max-partition-size=64", "--sb-size=64",
67626562 "--tune-content=screen", "--enable-intrabc=1", "--cq-level=60",
67636563 "--enable-palette=1", "--enable-tx-size-search=0", "--obu", "-o", "-", "-",
6764- ])
6765- .stdin(Stdio::piped())
6766- .stdout(Stdio::piped())
6767- .stderr(Stdio::piped())
6768- .spawn()
6769- .expect("aomenc");
6770- child.stdin.take().unwrap().write_all(&y4m).ok();
6771- let out = child.wait_with_output().expect("aomenc wait");
6564+ ]), &y4m);
67726565 assert!(out.status.success(), "{NAME}: aomenc failed");
67736566 crate::decode::reset_rect4_16_pair_hits();
67746567 let frames = decode_stream(&out.stdout).unwrap_or_else(|e| panic!("{NAME}: {e}"));
@@ -6807,20 +6600,13 @@ pub(crate) mod tests {
68076600 .output()
68086601 .expect("ffmpeg")
68096602 .stdout;
6810- let mut child = Command::new(aomenc_path())
6603+ let out = run_with_stdin(Command::new(aomenc_path())
68116604 .args([
68126605 "--codec=av1", "--cpu-used=0", "--lossless=1", "--sb-size=128",
68136606 "--lag-in-frames=0", "--kf-max-dist=1", "--limit=1", "--threads=1",
68146607 "--passes=1", "--enable-1to4-partitions=1", "--min-partition-size=4",
68156608 "--enable-rect-partitions=1", "--obu", "-o", "-", "-",
6816- ])
6817- .stdin(Stdio::piped())
6818- .stdout(Stdio::piped())
6819- .stderr(Stdio::piped())
6820- .spawn()
6821- .expect("aomenc");
6822- child.stdin.take().unwrap().write_all(&y4m).ok();
6823- let out = child.wait_with_output().expect("aomenc wait");
6609+ ]), &y4m);
68246610 assert!(out.status.success(), "{NAME}: aomenc failed");
68256611 crate::decode::reset_rect4_16_pair_hits();
68266612 let frames = decode_stream(&out.stdout).unwrap_or_else(|e| panic!("{NAME}: {e}"));
@@ -6916,7 +6702,7 @@ pub(crate) mod tests {
69166702 out.stdout
69176703 };
69186704 let y4m = render();
6919- let mut child = Command::new(aomenc_path())
6705+ let out = run_with_stdin(Command::new(aomenc_path())
69206706 .args([
69216707 "--codec=av1",
69226708 "--bit-depth=8",
@@ -6939,23 +6725,7 @@ pub(crate) mod tests {
69396725 ])
69406726 // aomenc keeps the LAST occurrence of a repeated flag.
69416727 .args(*extra)
6942- .args(["--obu", "-o", "-", "-"])
6943- .stdin(Stdio::piped())
6944- .stdout(Stdio::piped())
6945- .stderr(Stdio::piped())
6946- .spawn()
6947- .expect("aomenc failed to start");
6948- child
6949- .stdin
6950- .take()
6951- .expect("aomenc stdin")
6952- .write_all(&y4m)
6953- .or_else(|e| match e.kind() {
6954- std::io::ErrorKind::BrokenPipe => Ok(()),
6955- _ => Err(e),
6956- })
6957- .expect("writing y4m to aomenc");
6958- let out = child.wait_with_output().expect("aomenc failed to run");
6728+ .args(["--obu", "-o", "-", "-"]), &y4m);
69596729 assert!(
69606730 out.status.success(),
69616731 "{NAME}: aomenc refused {arm}: {}",
@@ -7040,7 +6810,7 @@ pub(crate) mod tests {
70406810 assert!(out.status.success(), "{NAME}: ffmpeg failed for {arm}");
70416811 out.stdout
70426812 };
7043- let mut child = Command::new(aomenc_path())
6813+ let out = run_with_stdin(Command::new(aomenc_path())
70446814 .args([
70456815 "--codec=av1", "--bit-depth=8", "--input-bit-depth=8", "--passes=1",
70466816 "--end-usage=q", "--cpu-used=0", "--lag-in-frames=0", "--kf-max-dist=1",
@@ -7051,23 +6821,7 @@ pub(crate) mod tests {
70516821 ])
70526822 // aomenc keeps the LAST occurrence of a repeated flag.
70536823 .args(*extra)
7054- .args(["--obu", "-o", "-", "-"])
7055- .stdin(Stdio::piped())
7056- .stdout(Stdio::piped())
7057- .stderr(Stdio::piped())
7058- .spawn()
7059- .expect("aomenc failed to start");
7060- child
7061- .stdin
7062- .take()
7063- .expect("aomenc stdin")
7064- .write_all(&y4m)
7065- .or_else(|e| match e.kind() {
7066- std::io::ErrorKind::BrokenPipe => Ok(()),
7067- _ => Err(e),
7068- })
7069- .expect("writing y4m to aomenc");
7070- let out = child.wait_with_output().expect("aomenc failed to run");
6824+ .args(["--obu", "-o", "-", "-"]), &y4m);
70716825 assert!(
70726826 out.status.success(),
70736827 "{NAME}: aomenc refused {arm}: {}",
@@ -7181,7 +6935,7 @@ pub(crate) mod tests {
71816935 .expect("ffmpeg failed to run");
71826936 assert!(out.status.success(), "ffmpeg failed for {src}");
71836937 let y4m = out.stdout;
7184- let mut child = Command::new(aomenc_path())
6938+ let enc = run_with_stdin(Command::new(aomenc_path())
71856939 .args(["--codec=av1"])
71866940 .args([format!("--bit-depth={depth}"), format!("--input-bit-depth={depth}")])
71876941 .args([
@@ -7208,23 +6962,7 @@ pub(crate) mod tests {
72086962 &[][..]
72096963 })
72106964 .args(extra)
7211- .args(["--obu", "-o", "-", "-"])
7212- .stdin(Stdio::piped())
7213- .stdout(Stdio::piped())
7214- .stderr(Stdio::piped())
7215- .spawn()
7216- .expect("aomenc failed to start");
7217- child
7218- .stdin
7219- .take()
7220- .expect("aomenc stdin")
7221- .write_all(&y4m)
7222- .or_else(|e| match e.kind() {
7223- std::io::ErrorKind::BrokenPipe => Ok(()),
7224- _ => Err(e),
7225- })
7226- .expect("writing y4m to aomenc");
7227- let enc = child.wait_with_output().expect("aomenc failed to run");
6965+ .args(["--obu", "-o", "-", "-"]), &y4m);
72286966 assert!(
72296967 enc.status.success(),
72306968 "aomenc refused {src} cq={cq}: {}",
@@ -7911,7 +7649,7 @@ pub(crate) mod tests {
79117649 let y4m = y4m_a;
79127650 let depth_arg = format!("--bit-depth={depth}");
79137651 let in_depth_arg = format!("--input-bit-depth={depth}");
7914- let mut child = Command::new(aomenc_path())
7652+ let out = run_with_stdin(Command::new(aomenc_path())
79157653 .args(["--codec=av1"])
79167654 .args([&depth_arg, &in_depth_arg])
79177655 .args([
@@ -7939,25 +7677,7 @@ pub(crate) mod tests {
79397677 // shape this gate is about; the 10-bit arms are the
79407678 // untouched pinned recipe.
79417679 .args(if depth == 8 { &["--sb-size=64"][..] } else { &[][..] })
7942- .args(["--obu", "-o", "-", "-"])
7943- .stdin(Stdio::piped())
7944- .stdout(Stdio::piped())
7945- .stderr(Stdio::piped())
7946- .spawn()
7947- .expect("aomenc failed to start");
7948- child
7949- .stdin
7950- .take()
7951- .expect("aomenc stdin")
7952- .write_all(&y4m)
7953- .or_else(|e| match e.kind() {
7954- // aomenc rejecting the input closes the pipe before we
7955- // finish writing; its own stderr below is the report.
7956- std::io::ErrorKind::BrokenPipe => Ok(()),
7957- _ => Err(e),
7958- })
7959- .expect("writing y4m to aomenc");
7960- let out = child.wait_with_output().expect("aomenc failed to run");
7680+ .args(["--obu", "-o", "-", "-"]), &y4m);
79617681 assert!(
79627682 out.status.success(),
79637683 "{NAME}: aomenc refused {arm} at {depth}-bit: {}",
@@ -8092,7 +7812,7 @@ pub(crate) mod tests {
80927812 "ffmpeg failed to render the 10-bit fixture: {}",
80937813 String::from_utf8_lossy(&y4m.stderr)
80947814 );
8095- let mut child = Command::new(aomenc_path())
7815+ let out = run_with_stdin(Command::new(aomenc_path())
80967816 .args([
80977817 "--codec=av1",
80987818 "--passes=1",
@@ -8109,19 +7829,7 @@ pub(crate) mod tests {
81097829 "-o",
81107830 "-",
81117831 "-",
8112- ])
8113- .stdin(Stdio::piped())
8114- .stdout(Stdio::piped())
8115- .stderr(Stdio::piped())
8116- .spawn()
8117- .expect("aomenc failed to start");
8118- child
8119- .stdin
8120- .take()
8121- .expect("aomenc stdin")
8122- .write_all(&y4m.stdout)
8123- .expect("writing y4m to aomenc");
8124- let out = child.wait_with_output().expect("aomenc failed to run");
7832+ ]), &y4m.stdout);
81257833 assert!(
81267834 out.status.success(),
81277835 "aomenc refused the 10-bit fixture: {}",
@@ -8200,7 +7908,7 @@ pub(crate) mod tests {
82007908 "ffmpeg failed to render the 10-bit fixture: {}",
82017909 String::from_utf8_lossy(&y4m.stderr)
82027910 );
8203- let mut child = Command::new(aomenc_path())
7911+ let out = run_with_stdin(Command::new(aomenc_path())
82047912 .args([
82057913 // lane-defon r1: explicit on-value (aomenc keeps the FIRST
82067914 // occurrence, so overrides go before the base list).
@@ -8243,19 +7951,7 @@ pub(crate) mod tests {
82437951 "-o",
82447952 "-",
82457953 "-",
8246- ])
8247- .stdin(Stdio::piped())
8248- .stdout(Stdio::piped())
8249- .stderr(Stdio::piped())
8250- .spawn()
8251- .expect("aomenc failed to start");
8252- child
8253- .stdin
8254- .take()
8255- .expect("aomenc stdin")
8256- .write_all(&y4m.stdout)
8257- .expect("writing y4m to aomenc");
8258- let out = child.wait_with_output().expect("aomenc failed to run");
7954+ ]), &y4m.stdout);
82597955 assert!(
82607956 out.status.success(),
82617957 "aomenc refused the 10-bit fixture: {}",
@@ -9520,20 +9216,8 @@ pub(crate) mod tests {
95209216 ]);
95219217 args.extend_from_slice(extra);
95229218 args.extend_from_slice(&["--obu", "-o", "-", "-"]);
9523- let mut child = Command::new(aomenc_path())
9524- .args(&args)
9525- .stdin(Stdio::piped())
9526- .stdout(Stdio::piped())
9527- .stderr(Stdio::piped())
9528- .spawn()
9529- .expect("aomenc failed to start");
9530- child
9531- .stdin
9532- .take()
9533- .expect("aomenc stdin")
9534- .write_all(&y4m.stdout)
9535- .expect("writing y4m to aomenc");
9536- let out = child.wait_with_output().expect("aomenc failed to run");
9219+ let out = run_with_stdin(Command::new(aomenc_path())
9220+ .args(&args), &y4m.stdout);
95379221 assert!(
95389222 out.status.success(),
95399223 "{name}: aomenc refused the 10-bit fixture: {}",
@@ -9596,7 +9280,7 @@ pub(crate) mod tests {
95969280 "testsrc2 must render byte-identical across two runs"
95979281 );
95989282 let y4m = y4m_a;
9599- let mut child = Command::new(aomenc_path())
9283+ let out = run_with_stdin(Command::new(aomenc_path())
96009284 .args([
96019285 "--codec=av1",
96029286 "--passes=1",
@@ -9623,19 +9307,7 @@ pub(crate) mod tests {
96239307 "-o",
96249308 "-",
96259309 "-",
9626- ])
9627- .stdin(Stdio::piped())
9628- .stdout(Stdio::piped())
9629- .stderr(Stdio::piped())
9630- .spawn()
9631- .expect("aomenc failed to start");
9632- child
9633- .stdin
9634- .take()
9635- .expect("aomenc stdin")
9636- .write_all(&y4m)
9637- .expect("writing y4m to aomenc");
9638- let out = child.wait_with_output().expect("aomenc failed to run");
9310+ ]), &y4m);
96399311 assert!(
96409312 out.status.success(),
96419313 "aomenc refused the fixture: {}",
@@ -9716,7 +9388,7 @@ pub(crate) mod tests {
97169388 String::from_utf8_lossy(&y4m.stderr)
97179389 );
97189390 let cq_arg = format!("--cq-level={cq}");
9719- let mut child = Command::new(aomenc_path())
9391+ let out = run_with_stdin(Command::new(aomenc_path())
97209392 .args([
97219393 "--codec=av1",
97229394 "--passes=1",
@@ -9733,19 +9405,7 @@ pub(crate) mod tests {
97339405 "-o",
97349406 "-",
97359407 "-",
9736- ])
9737- .stdin(Stdio::piped())
9738- .stdout(Stdio::piped())
9739- .stderr(Stdio::piped())
9740- .spawn()
9741- .expect("aomenc failed to start");
9742- child
9743- .stdin
9744- .take()
9745- .expect("aomenc stdin")
9746- .write_all(&y4m.stdout)
9747- .expect("writing y4m to aomenc");
9748- let out = child.wait_with_output().expect("aomenc failed to run");
9408+ ]), &y4m.stdout);
97499409 assert!(
97509410 out.status.success(),
97519411 "aomenc refused the fixture ({source} cq={cq}): {}",
@@ -9884,7 +9544,7 @@ pub(crate) mod tests {
98849544 String::from_utf8_lossy(&y4m.stderr)
98859545 );
98869546 let cq_arg = format!("--cq-level={cq}");
9887- let mut child = Command::new(aomenc_path())
9547+ let out = run_with_stdin(Command::new(aomenc_path())
98889548 .args([
98899549 "--codec=av1",
98909550 "--passes=1",
@@ -9901,19 +9561,7 @@ pub(crate) mod tests {
99019561 "-o",
99029562 "-",
99039563 "-",
9904- ])
9905- .stdin(Stdio::piped())
9906- .stdout(Stdio::piped())
9907- .stderr(Stdio::piped())
9908- .spawn()
9909- .expect("aomenc failed to start");
9910- child
9911- .stdin
9912- .take()
9913- .expect("aomenc stdin")
9914- .write_all(&y4m.stdout)
9915- .expect("writing y4m to aomenc");
9916- let out = child.wait_with_output().expect("aomenc failed to run");
9564+ ]), &y4m.stdout);
99179565 assert!(
99189566 out.status.success(),
99199567 "aomenc refused the fixture ({source} cq={cq}): {}",
@@ -10041,7 +9689,7 @@ pub(crate) mod tests {
100419689 "ffmpeg fixture: {}",
100429690 String::from_utf8_lossy(&y4m.stderr)
100439691 );
10044- let mut child = Command::new(aomenc_path())
9692+ let out = run_with_stdin(Command::new(aomenc_path())
100459693 .args([
100469694 // lane-defon r1: explicit on-value (aomenc keeps the FIRST
100479695 // occurrence, so overrides go before the base list).
@@ -10073,19 +9721,7 @@ pub(crate) mod tests {
100739721 "-o",
100749722 "-",
100759723 "-",
10076- ])
10077- .stdin(Stdio::piped())
10078- .stdout(Stdio::piped())
10079- .stderr(Stdio::piped())
10080- .spawn()
10081- .expect("aomenc failed to start");
10082- child
10083- .stdin
10084- .take()
10085- .expect("aomenc stdin")
10086- .write_all(&y4m.stdout)
10087- .expect("writing y4m to aomenc");
10088- let out = child.wait_with_output().expect("aomenc failed to run");
9724+ ]), &y4m.stdout);
100899725 assert!(
100909726 out.status.success(),
100919727 "aomenc refused the fixture: {}",
@@ -10192,7 +9828,7 @@ pub(crate) mod tests {
101929828 "ffmpeg fixture: {}",
101939829 String::from_utf8_lossy(&y4m.stderr)
101949830 );
10195- let mut child = Command::new(aomenc_path())
9831+ let out = run_with_stdin(Command::new(aomenc_path())
101969832 .args([
101979833 "--codec=av1",
101989834 "--passes=1",
@@ -10232,19 +9868,7 @@ pub(crate) mod tests {
102329868 "-o",
102339869 "-",
102349870 "-",
10235- ])
10236- .stdin(Stdio::piped())
10237- .stdout(Stdio::piped())
10238- .stderr(Stdio::piped())
10239- .spawn()
10240- .expect("aomenc failed to start");
10241- child
10242- .stdin
10243- .take()
10244- .expect("aomenc stdin")
10245- .write_all(&y4m.stdout)
10246- .expect("writing y4m to aomenc");
10247- let out = child.wait_with_output().expect("aomenc failed to run");
9871+ ]), &y4m.stdout);
102489872 assert!(
102499873 out.status.success(),
102509874 "aomenc refused the fixture: {}",
@@ -10432,7 +10056,7 @@ pub(crate) mod tests {
1043210056 // walks it too, so "no rect strip fired" cannot be an artefact of
1043310057 // one cq.
1043410058 let cq = format!("--cq-level={}", [30u32, 20, 12][(attempt / 5) as usize % 3]);
10435- let mut child = Command::new(aomenc_path())
10059+ let out = run_with_stdin(Command::new(aomenc_path())
1043610060 .args(depth_args)
1043710061 .arg(&cpu)
1043810062 .arg(&cq)
@@ -10502,19 +10126,7 @@ pub(crate) mod tests {
1050210126 "-o",
1050310127 "-",
1050410128 "-",
10505- ])
10506- .stdin(Stdio::piped())
10507- .stdout(Stdio::piped())
10508- .stderr(Stdio::piped())
10509- .spawn()
10510- .expect("aomenc failed to start");
10511- child
10512- .stdin
10513- .take()
10514- .expect("aomenc stdin")
10515- .write_all(&y4m.stdout)
10516- .expect("writing y4m to aomenc");
10517- let out = child.wait_with_output().expect("aomenc failed to run");
10129+ ]), &y4m.stdout);
1051810130 assert!(
1051910131 out.status.success(),
1052010132 "aomenc refused the fixture: {}",
@@ -10720,7 +10332,7 @@ pub(crate) mod tests {
1072010332 } else {
1072110333 &[]
1072210334 };
10723- let mut child = Command::new(aomenc_path())
10335+ let out = run_with_stdin(Command::new(aomenc_path())
1072410336 .args(depth_args)
1072510337 .args([
1072610338 // lane-defon r1: explicit on-value (aomenc keeps the FIRST
@@ -10771,19 +10383,7 @@ pub(crate) mod tests {
1077110383 "-o",
1077210384 "-",
1077310385 "-",
10774- ])
10775- .stdin(Stdio::piped())
10776- .stdout(Stdio::piped())
10777- .stderr(Stdio::piped())
10778- .spawn()
10779- .expect("aomenc failed to start");
10780- child
10781- .stdin
10782- .take()
10783- .expect("aomenc stdin")
10784- .write_all(&y4m.stdout)
10785- .expect("writing y4m to aomenc");
10786- let out = child.wait_with_output().expect("aomenc failed to run");
10386+ ]), &y4m.stdout);
1078710387 assert!(
1078810388 out.status.success(),
1078910389 "aomenc refused the fixture: {}",
@@ -10979,7 +10579,7 @@ pub(crate) mod tests {
1097910579 } else {
1098010580 &[]
1098110581 };
10982- let mut child = Command::new(aomenc_path())
10582+ let out = run_with_stdin(Command::new(aomenc_path())
1098310583 .args(depth_args)
1098410584 .args([
1098510585 "--codec=av1",
@@ -11035,19 +10635,7 @@ pub(crate) mod tests {
1103510635 "-o",
1103610636 "-",
1103710637 "-",
11038- ])
11039- .stdin(Stdio::piped())
11040- .stdout(Stdio::piped())
11041- .stderr(Stdio::piped())
11042- .spawn()
11043- .expect("aomenc failed to start");
11044- child
11045- .stdin
11046- .take()
11047- .expect("aomenc stdin")
11048- .write_all(&y4m.stdout)
11049- .expect("writing y4m to aomenc");
11050- let out = child.wait_with_output().expect("aomenc failed to run");
10638+ ]), &y4m.stdout);
1105110639 assert!(
1105210640 out.status.success(),
1105310641 "aomenc refused the fixture: {}",
@@ -11236,7 +10824,7 @@ pub(crate) mod tests {
1123610824 } else {
1123710825 &[]
1123810826 };
11239- let mut child = Command::new(aomenc_path())
10827+ let out = run_with_stdin(Command::new(aomenc_path())
1124010828 .args(depth_args)
1124110829 .args([
1124210830 "--codec=av1",
@@ -11292,19 +10880,7 @@ pub(crate) mod tests {
1129210880 "-o",
1129310881 "-",
1129410882 "-",
11295- ])
11296- .stdin(Stdio::piped())
11297- .stdout(Stdio::piped())
11298- .stderr(Stdio::piped())
11299- .spawn()
11300- .expect("aomenc failed to start");
11301- child
11302- .stdin
11303- .take()
11304- .expect("aomenc stdin")
11305- .write_all(&y4m.stdout)
11306- .expect("writing y4m to aomenc");
11307- let out = child.wait_with_output().expect("aomenc failed to run");
10883+ ]), &y4m.stdout);
1130810884 assert!(
1130910885 out.status.success(),
1131010886 "aomenc refused the fixture: {}",
@@ -11499,7 +11075,7 @@ pub(crate) mod tests {
1149911075 } else {
1150011076 &[]
1150111077 };
11502- let mut child = Command::new(aomenc_path())
11078+ let out = run_with_stdin(Command::new(aomenc_path())
1150311079 .args(depth_args)
1150411080 .args([
1150511081 "--codec=av1",
@@ -11555,19 +11131,7 @@ pub(crate) mod tests {
1155511131 "-o",
1155611132 "-",
1155711133 "-",
11558- ])
11559- .stdin(Stdio::piped())
11560- .stdout(Stdio::piped())
11561- .stderr(Stdio::piped())
11562- .spawn()
11563- .expect("aomenc failed to start");
11564- child
11565- .stdin
11566- .take()
11567- .expect("aomenc stdin")
11568- .write_all(&y4m.stdout)
11569- .expect("writing y4m to aomenc");
11570- let out = child.wait_with_output().expect("aomenc failed to run");
11134+ ]), &y4m.stdout);
1157111135 assert!(
1157211136 out.status.success(),
1157311137 "aomenc refused the fixture: {}",
@@ -12280,7 +11844,7 @@ pub(crate) mod tests {
1228011844 "ffmpeg fixture: {}",
1228111845 String::from_utf8_lossy(&y4m.stderr)
1228211846 );
12283- let mut child = Command::new(aomenc_path())
11847+ let out = run_with_stdin(Command::new(aomenc_path())
1228411848 .args([
1228511849 "--codec=av1",
1228611850 "--passes=1",
@@ -12310,19 +11874,7 @@ pub(crate) mod tests {
1231011874 "-o",
1231111875 "-",
1231211876 "-",
12313- ])
12314- .stdin(Stdio::piped())
12315- .stdout(Stdio::piped())
12316- .stderr(Stdio::piped())
12317- .spawn()
12318- .expect("aomenc failed to start");
12319- child
12320- .stdin
12321- .take()
12322- .expect("aomenc stdin")
12323- .write_all(&y4m.stdout)
12324- .expect("writing y4m to aomenc");
12325- let out = child.wait_with_output().expect("aomenc failed to run");
11877+ ]), &y4m.stdout);
1232611878 assert!(
1232711879 out.status.success(),
1232811880 "aomenc refused the fixture: {}",
@@ -12427,7 +11979,7 @@ pub(crate) mod tests {
1242711979 "ffmpeg fixture: {}",
1242811980 String::from_utf8_lossy(&y4m.stderr)
1242911981 );
12430- let mut child = Command::new(aomenc_path())
11982+ let out = run_with_stdin(Command::new(aomenc_path())
1243111983 .args([
1243211984 "--codec=av1",
1243311985 "--passes=1",
@@ -12455,19 +12007,7 @@ pub(crate) mod tests {
1245512007 "-o",
1245612008 "-",
1245712009 "-",
12458- ])
12459- .stdin(Stdio::piped())
12460- .stdout(Stdio::piped())
12461- .stderr(Stdio::piped())
12462- .spawn()
12463- .expect("aomenc failed to start");
12464- child
12465- .stdin
12466- .take()
12467- .expect("aomenc stdin")
12468- .write_all(&y4m.stdout)
12469- .expect("writing y4m to aomenc");
12470- let out = child.wait_with_output().expect("aomenc failed to run");
12010+ ]), &y4m.stdout);
1247112011 assert!(
1247212012 out.status.success(),
1247312013 "aomenc refused the fixture: {}",
@@ -12584,7 +12124,7 @@ pub(crate) mod tests {
1258412124 "ffmpeg fixture: {}",
1258512125 String::from_utf8_lossy(&y4m.stderr)
1258612126 );
12587- let mut child = Command::new(aomenc_path())
12127+ let out = run_with_stdin(Command::new(aomenc_path())
1258812128 .args([
1258912129 // lane-defon r1: explicit on-value (aomenc keeps the FIRST
1259012130 // occurrence, so overrides go before the base list).
@@ -12627,19 +12167,7 @@ pub(crate) mod tests {
1262712167 "-o",
1262812168 "-",
1262912169 "-",
12630- ])
12631- .stdin(Stdio::piped())
12632- .stdout(Stdio::piped())
12633- .stderr(Stdio::piped())
12634- .spawn()
12635- .expect("aomenc failed to start");
12636- child
12637- .stdin
12638- .take()
12639- .expect("aomenc stdin")
12640- .write_all(&y4m.stdout)
12641- .expect("writing y4m to aomenc");
12642- let out = child.wait_with_output().expect("aomenc failed to run");
12170+ ]), &y4m.stdout);
1264312171 assert!(
1264412172 out.status.success(),
1264512173 "aomenc refused the fixture: {}",
@@ -12823,20 +12351,8 @@ pub(crate) mod tests {
1282312351 args.insert(1, "--input-bit-depth=10".to_string());
1282412352 args.insert(1, "--bit-depth=10".to_string());
1282512353 }
12826- let mut child = Command::new(aomenc_path())
12827- .args(&args)
12828- .stdin(Stdio::piped())
12829- .stdout(Stdio::piped())
12830- .stderr(Stdio::piped())
12831- .spawn()
12832- .expect("aomenc failed to start");
12833- child
12834- .stdin
12835- .take()
12836- .expect("aomenc stdin")
12837- .write_all(&y4m.stdout)
12838- .expect("writing y4m to aomenc");
12839- let out = child.wait_with_output().expect("aomenc failed to run");
12354+ let out = run_with_stdin(Command::new(aomenc_path())
12355+ .args(&args), &y4m.stdout);
1284012356 assert!(
1284112357 out.status.success(),
1284212358 "{name}: aomenc refused the fixture: {}",
@@ -13160,20 +12676,8 @@ pub(crate) mod tests {
1316012676 args.insert(1, "--input-bit-depth=10".to_string());
1316112677 args.insert(1, "--bit-depth=10".to_string());
1316212678 }
13163- let mut child = Command::new(aomenc_path())
13164- .args(&args)
13165- .stdin(Stdio::piped())
13166- .stdout(Stdio::piped())
13167- .stderr(Stdio::piped())
13168- .spawn()
13169- .expect("aomenc failed to start");
13170- child
13171- .stdin
13172- .take()
13173- .expect("aomenc stdin")
13174- .write_all(&y4m.stdout)
13175- .expect("writing y4m to aomenc");
13176- let out = child.wait_with_output().expect("aomenc failed to run");
12679+ let out = run_with_stdin(Command::new(aomenc_path())
12680+ .args(&args), &y4m.stdout);
1317712681 assert!(
1317812682 out.status.success(),
1317912683 "{name}: aomenc refused the fixture: {}",
@@ -13346,20 +12850,8 @@ pub(crate) mod tests {
1334612850 "--max-partition-size=64",
1334712851 "--obu", "-o", "-", "-",
1334812852 ];
13349- let mut child = Command::new(aomenc_path())
13350- .args(&args)
13351- .stdin(Stdio::piped())
13352- .stdout(Stdio::piped())
13353- .stderr(Stdio::piped())
13354- .spawn()
13355- .expect("aomenc failed to start");
13356- child
13357- .stdin
13358- .take()
13359- .expect("aomenc stdin")
13360- .write_all(&y4m.stdout)
13361- .expect("writing y4m to aomenc");
13362- let out = child.wait_with_output().expect("aomenc failed to run");
12853+ let out = run_with_stdin(Command::new(aomenc_path())
12854+ .args(&args), &y4m.stdout);
1336312855 assert!(
1336412856 out.status.success(),
1336512857 "aomenc refused the fixture: {}",
@@ -13606,28 +13098,7 @@ pub(crate) mod tests {
1360613098 min_part, "--max-partition-size=64",
1360713099 "--obu", "-o", "-", "-",
1360813100 ];
13609- let mut child = Command::new(aomenc_path())
13610- .args(&args)
13611- .stdin(Stdio::piped())
13612- .stdout(Stdio::piped())
13613- .stderr(Stdio::piped())
13614- .spawn()
13615- .expect("aomenc failed to start");
13616- // lane-gaterecipe r1: feed stdin from a THREAD. A
13617- // single-threaded `write_all` then `wait_with_output` deadlocks
13618- // the moment aomenc's stdout pipe fills before it has consumed
13619- // the whole y4m -- exactly what the fine-quantiser firing arm
13620- // does (one 384x256 cq-10 encode hung for 40 minutes).
13621- let mut aom_stdin = child.stdin.take().expect("aomenc stdin");
13622- let y4m_bytes = y4m.stdout;
13623- let feeder = std::thread::Builder::new()
13624- .name("ec-av1-aomenc-in".into())
13625- .spawn(move || {
13626- aom_stdin.write_all(&y4m_bytes).expect("writing y4m to aomenc");
13627- })
13628- .expect("spawning the aomenc stdin feeder");
13629- let out = child.wait_with_output().expect("aomenc failed to run");
13630- feeder.join().expect("y4m feeder thread");
13101+ let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
1363113102 assert!(
1363213103 out.status.success(),
1363313104 "aomenc refused the fixture: {}",
@@ -13850,20 +13321,8 @@ pub(crate) mod tests {
1385013321 "--min-partition-size=8", "--max-partition-size=32",
1385113322 "--obu", "-o", "-", "-",
1385213323 ];
13853- let mut child = Command::new(aomenc_path())
13854- .args(&args)
13855- .stdin(Stdio::piped())
13856- .stdout(Stdio::piped())
13857- .stderr(Stdio::piped())
13858- .spawn()
13859- .expect("aomenc failed to start");
13860- child
13861- .stdin
13862- .take()
13863- .expect("aomenc stdin")
13864- .write_all(&y4m.stdout)
13865- .expect("writing y4m to aomenc");
13866- let out = child.wait_with_output().expect("aomenc failed to run");
13324+ let out = run_with_stdin(Command::new(aomenc_path())
13325+ .args(&args), &y4m.stdout);
1386713326 assert!(
1386813327 out.status.success(),
1386913328 "aomenc refused the fixture: {}",
@@ -14064,20 +13523,8 @@ pub(crate) mod tests {
1406413523 "--max-partition-size=64",
1406513524 "--obu", "-o", "-", "-",
1406613525 ];
14067- let mut child = Command::new(aomenc_path())
14068- .args(&args)
14069- .stdin(Stdio::piped())
14070- .stdout(Stdio::piped())
14071- .stderr(Stdio::piped())
14072- .spawn()
14073- .expect("aomenc failed to start");
14074- child
14075- .stdin
14076- .take()
14077- .expect("aomenc stdin")
14078- .write_all(&y4m.stdout)
14079- .expect("writing y4m to aomenc");
14080- let out = child.wait_with_output().expect("aomenc failed to run");
13526+ let out = run_with_stdin(Command::new(aomenc_path())
13527+ .args(&args), &y4m.stdout);
1408113528 assert!(
1408213529 out.status.success(),
1408313530 "aomenc refused the fixture: {}",
@@ -14227,20 +13674,8 @@ pub(crate) mod tests {
1422713674 "--enable-intrabc=0", "--enable-cfl-intra=0", "--enable-ref-frame-mvs=0",
1422813675 "--obu", "-o", "-", "-",
1422913676 ];
14230- let mut child = Command::new(aomenc_path())
14231- .args(&args)
14232- .stdin(Stdio::piped())
14233- .stdout(Stdio::piped())
14234- .stderr(Stdio::piped())
14235- .spawn()
14236- .expect("aomenc failed to start");
14237- child
14238- .stdin
14239- .take()
14240- .expect("aomenc stdin")
14241- .write_all(&y4m.stdout)
14242- .expect("writing y4m to aomenc");
14243- let out = child.wait_with_output().expect("aomenc failed to run");
13677+ let out = run_with_stdin(Command::new(aomenc_path())
13678+ .args(&args), &y4m.stdout);
1424413679 assert!(
1424513680 out.status.success(),
1424613681 "aomenc refused the fixture: {}",
@@ -14432,20 +13867,8 @@ pub(crate) mod tests {
1443213867 "--max-partition-size=32",
1443313868 "--obu", "-o", "-", "-",
1443413869 ];
14435- let mut child = Command::new(aomenc_path())
14436- .args(&args)
14437- .stdin(Stdio::piped())
14438- .stdout(Stdio::piped())
14439- .stderr(Stdio::piped())
14440- .spawn()
14441- .expect("aomenc failed to start");
14442- child
14443- .stdin
14444- .take()
14445- .expect("aomenc stdin")
14446- .write_all(&y4m.stdout)
14447- .expect("writing y4m to aomenc");
14448- let out = child.wait_with_output().expect("aomenc failed to run");
13870+ let out = run_with_stdin(Command::new(aomenc_path())
13871+ .args(&args), &y4m.stdout);
1444913872 assert!(
1445013873 out.status.success(),
1445113874 "aomenc refused the fixture: {}",
@@ -14572,20 +13995,8 @@ pub(crate) mod tests {
1457213995 "--lag-in-frames=16", "--auto-alt-ref=1", "--arnr-maxframes=0",
1457313996 "--obu", "-o", "-", "-",
1457413997 ];
14575- let mut child = Command::new(aomenc_path())
14576- .args(&args)
14577- .stdin(Stdio::piped())
14578- .stdout(Stdio::piped())
14579- .stderr(Stdio::piped())
14580- .spawn()
14581- .expect("aomenc failed to start");
14582- child
14583- .stdin
14584- .take()
14585- .expect("aomenc stdin")
14586- .write_all(&y4m.stdout)
14587- .expect("writing y4m to aomenc");
14588- let out = child.wait_with_output().expect("aomenc failed to run");
13998+ let out = run_with_stdin(Command::new(aomenc_path())
13999+ .args(&args), &y4m.stdout);
1458914000 assert!(
1459014001 out.status.success(),
1459114002 "aomenc refused the fixture: {}",
@@ -14731,20 +14142,8 @@ pub(crate) mod tests {
1473114142 "--max-partition-size=32",
1473214143 "--obu", "-o", "-", "-",
1473314144 ];
14734- let mut child = Command::new(aomenc_path())
14735- .args(&args)
14736- .stdin(Stdio::piped())
14737- .stdout(Stdio::piped())
14738- .stderr(Stdio::piped())
14739- .spawn()
14740- .expect("aomenc failed to start");
14741- child
14742- .stdin
14743- .take()
14744- .expect("aomenc stdin")
14745- .write_all(&y4m.stdout)
14746- .expect("writing y4m to aomenc");
14747- let out = child.wait_with_output().expect("aomenc failed to run");
14145+ let out = run_with_stdin(Command::new(aomenc_path())
14146+ .args(&args), &y4m.stdout);
1474814147 assert!(
1474914148 out.status.success(),
1475014149 "aomenc refused the fixture: {}",
@@ -14941,20 +14340,8 @@ pub(crate) mod tests {
1494114340 &rect_arg,
1494214341 "--obu", "-o", "-", "-",
1494314342 ];
14944- let mut child = Command::new(aomenc_path())
14945- .args(&args)
14946- .stdin(Stdio::piped())
14947- .stdout(Stdio::piped())
14948- .stderr(Stdio::piped())
14949- .spawn()
14950- .expect("aomenc failed to start");
14951- child
14952- .stdin
14953- .take()
14954- .expect("aomenc stdin")
14955- .write_all(&y4m.stdout)
14956- .expect("writing y4m to aomenc");
14957- let out = child.wait_with_output().expect("aomenc failed to run");
14343+ let out = run_with_stdin(Command::new(aomenc_path())
14344+ .args(&args), &y4m.stdout);
1495814345 assert!(
1495914346 out.status.success(),
1496014347 "{NAME}: aomenc refused the fixture: {}",
@@ -15184,20 +14571,8 @@ pub(crate) mod tests {
1518414571 obmc_arg,
1518514572 "--obu", "-o", "-", "-",
1518614573 ];
15187- let mut child = Command::new(aomenc_path())
15188- .args(&args)
15189- .stdin(Stdio::piped())
15190- .stdout(Stdio::piped())
15191- .stderr(Stdio::piped())
15192- .spawn()
15193- .expect("aomenc failed to start");
15194- child
15195- .stdin
15196- .take()
15197- .expect("aomenc stdin")
15198- .write_all(&y4m.stdout)
15199- .expect("writing y4m to aomenc");
15200- let out = child.wait_with_output().expect("aomenc failed to run");
14574+ let out = run_with_stdin(Command::new(aomenc_path())
14575+ .args(&args), &y4m.stdout);
1520114576 assert!(
1520214577 out.status.success(),
1520314578 "aomenc refused the fixture: {}",
@@ -15444,20 +14819,8 @@ pub(crate) mod tests {
1544414819 "--max-partition-size=16",
1544514820 "--obu", "-o", "-", "-",
1544614821 ];
15447- let mut child = Command::new(aomenc_path())
15448- .args(&args)
15449- .stdin(Stdio::piped())
15450- .stdout(Stdio::piped())
15451- .stderr(Stdio::piped())
15452- .spawn()
15453- .expect("aomenc failed to start");
15454- child
15455- .stdin
15456- .take()
15457- .expect("aomenc stdin")
15458- .write_all(&y4m.stdout)
15459- .expect("writing y4m to aomenc");
15460- let out = child.wait_with_output().expect("aomenc failed to run");
14822+ let out = run_with_stdin(Command::new(aomenc_path())
14823+ .args(&args), &y4m.stdout);
1546114824 assert!(
1546214825 out.status.success(),
1546314826 "aomenc refused the fixture: {}",
@@ -15684,20 +15047,8 @@ pub(crate) mod tests {
1568415047 "--max-partition-size=16",
1568515048 "--obu", "-o", "-", "-",
1568615049 ];
15687- let mut child = Command::new(aomenc_path())
15688- .args(&args)
15689- .stdin(Stdio::piped())
15690- .stdout(Stdio::piped())
15691- .stderr(Stdio::piped())
15692- .spawn()
15693- .expect("aomenc failed to start");
15694- child
15695- .stdin
15696- .take()
15697- .expect("aomenc stdin")
15698- .write_all(&y4m.stdout)
15699- .expect("writing y4m to aomenc");
15700- let out = child.wait_with_output().expect("aomenc failed to run");
15050+ let out = run_with_stdin(Command::new(aomenc_path())
15051+ .args(&args), &y4m.stdout);
1570115052 assert!(
1570215053 out.status.success(),
1570315054 "aomenc refused the fixture: {}",
@@ -16029,20 +15380,8 @@ pub(crate) mod tests {
1602915380 &min_part_arg, "--max-partition-size=16",
1603015381 "--obu", "-o", "-", "-",
1603115382 ];
16032- let mut child = Command::new(aomenc_path())
16033- .args(&args)
16034- .stdin(Stdio::piped())
16035- .stdout(Stdio::piped())
16036- .stderr(Stdio::piped())
16037- .spawn()
16038- .expect("aomenc failed to start");
16039- child
16040- .stdin
16041- .take()
16042- .expect("aomenc stdin")
16043- .write_all(&y4m.stdout)
16044- .expect("writing y4m to aomenc");
16045- let out = child.wait_with_output().expect("aomenc failed to run");
15383+ let out = run_with_stdin(Command::new(aomenc_path())
15384+ .args(&args), &y4m.stdout);
1604615385 assert!(
1604715386 out.status.success(),
1604815387 "aomenc refused the fixture: {}",
@@ -16297,20 +15636,8 @@ pub(crate) mod tests {
1629715636 "--max-partition-size=64",
1629815637 "--obu", "-o", "-", "-",
1629915638 ];
16300- let mut child = Command::new(aomenc_path())
16301- .args(&args)
16302- .stdin(Stdio::piped())
16303- .stdout(Stdio::piped())
16304- .stderr(Stdio::piped())
16305- .spawn()
16306- .expect("aomenc failed to start");
16307- child
16308- .stdin
16309- .take()
16310- .expect("aomenc stdin")
16311- .write_all(&y4m.stdout)
16312- .expect("writing y4m to aomenc");
16313- let out = child.wait_with_output().expect("aomenc failed to run");
15639+ let out = run_with_stdin(Command::new(aomenc_path())
15640+ .args(&args), &y4m.stdout);
1631415641 assert!(
1631515642 out.status.success(),
1631615643 "aomenc refused the fixture: {}",
@@ -16443,7 +15770,7 @@ pub(crate) mod tests {
1644315770 "ffmpeg fixture: {}",
1644415771 String::from_utf8_lossy(&y4m.stderr)
1644515772 );
16446- let mut child = Command::new(aomenc_path())
15773+ let out = run_with_stdin(Command::new(aomenc_path())
1644715774 .args([
1644815775 // lane-defon r1: explicit on-value (aomenc keeps the FIRST
1644915776 // occurrence, so overrides go before the base list).
@@ -16496,19 +15823,7 @@ pub(crate) mod tests {
1649615823 "-o",
1649715824 "-",
1649815825 "-",
16499- ])
16500- .stdin(Stdio::piped())
16501- .stdout(Stdio::piped())
16502- .stderr(Stdio::piped())
16503- .spawn()
16504- .expect("aomenc failed to start");
16505- child
16506- .stdin
16507- .take()
16508- .expect("aomenc stdin")
16509- .write_all(&y4m.stdout)
16510- .expect("writing y4m to aomenc");
16511- let out = child.wait_with_output().expect("aomenc failed to run");
15826+ ]), &y4m.stdout);
1651215827 assert!(
1651315828 out.status.success(),
1651415829 "aomenc refused the fixture: {}",
@@ -16630,7 +15945,7 @@ pub(crate) mod tests {
1663015945 "y4m fixture length mismatch (seed {seed})"
1663115946 );
1663215947 let y4m_hash = fnv1a64(&y4m.stdout);
16633- let mut child = Command::new(aomenc_path())
15948+ let out = run_with_stdin(Command::new(aomenc_path())
1663415949 .args([
1663515950 "--codec=av1",
1663615951 "--passes=1",
@@ -16694,19 +16009,7 @@ pub(crate) mod tests {
1669416009 "-o",
1669516010 "-",
1669616011 "-",
16697- ])
16698- .stdin(Stdio::piped())
16699- .stdout(Stdio::piped())
16700- .stderr(Stdio::piped())
16701- .spawn()
16702- .expect("aomenc failed to start");
16703- child
16704- .stdin
16705- .take()
16706- .expect("aomenc stdin")
16707- .write_all(&y4m.stdout)
16708- .expect("writing y4m to aomenc");
16709- let out = child.wait_with_output().expect("aomenc failed to run");
16012+ ]), &y4m.stdout);
1671016013 assert!(
1671116014 out.status.success(),
1671216015 "aomenc refused the fixture: {}",
@@ -16969,7 +16272,7 @@ pub(crate) mod tests {
1696916272 "ffmpeg fixture: {}",
1697016273 String::from_utf8_lossy(&y4m.stderr)
1697116274 );
16972- let mut child = Command::new(aomenc_path())
16275+ let out = run_with_stdin(Command::new(aomenc_path())
1697316276 .args([
1697416277 "--codec=av1",
1697516278 "--passes=1",
@@ -17047,19 +16350,7 @@ pub(crate) mod tests {
1704716350 "-o",
1704816351 "-",
1704916352 "-",
17050- ])
17051- .stdin(Stdio::piped())
17052- .stdout(Stdio::piped())
17053- .stderr(Stdio::piped())
17054- .spawn()
17055- .expect("aomenc failed to start");
17056- child
17057- .stdin
17058- .take()
17059- .expect("aomenc stdin")
17060- .write_all(&y4m.stdout)
17061- .expect("writing y4m to aomenc");
17062- let out = child.wait_with_output().expect("aomenc failed to run");
16353+ ]), &y4m.stdout);
1706316354 assert!(
1706416355 out.status.success(),
1706516356 "aomenc refused the fixture: {}",
@@ -17243,20 +16534,8 @@ pub(crate) mod tests {
1724316534 let tail = args.split_off(args.len() - 3);
1724416535 args.extend_from_slice(extra_args);
1724516536 args.extend_from_slice(&tail);
17246- let mut child = Command::new(aomenc_path())
17247- .args(&args)
17248- .stdin(Stdio::piped())
17249- .stdout(Stdio::piped())
17250- .stderr(Stdio::piped())
17251- .spawn()
17252- .expect("aomenc failed to start");
17253- child
17254- .stdin
17255- .take()
17256- .expect("aomenc stdin")
17257- .write_all(&y4m.stdout)
17258- .expect("writing y4m to aomenc");
17259- let out = child.wait_with_output().expect("aomenc failed to run");
16537+ let out = run_with_stdin(Command::new(aomenc_path())
16538+ .args(&args), &y4m.stdout);
1726016539 assert!(
1726116540 out.status.success(),
1726216541 "aomenc refused the fixture: {}",
@@ -17448,20 +16727,8 @@ pub(crate) mod tests {
1744816727 "-",
1744916728 "-",
1745016729 ];
17451- let mut child = Command::new(aomenc_path())
17452- .args(&args)
17453- .stdin(Stdio::piped())
17454- .stdout(Stdio::piped())
17455- .stderr(Stdio::piped())
17456- .spawn()
17457- .expect("aomenc failed to start");
17458- child
17459- .stdin
17460- .take()
17461- .expect("aomenc stdin")
17462- .write_all(&y4m.stdout)
17463- .expect("writing y4m to aomenc");
17464- let out = child.wait_with_output().expect("aomenc failed to run");
16730+ let out = run_with_stdin(Command::new(aomenc_path())
16731+ .args(&args), &y4m.stdout);
1746516732 assert!(
1746616733 out.status.success(),
1746716734 "aomenc refused the fixture: {}",
@@ -17690,20 +16957,8 @@ pub(crate) mod tests {
1769016957 "-",
1769116958 "-",
1769216959 ];
17693- let mut child = Command::new(aomenc_path())
17694- .args(&args)
17695- .stdin(Stdio::piped())
17696- .stdout(Stdio::piped())
17697- .stderr(Stdio::piped())
17698- .spawn()
17699- .expect("aomenc failed to start");
17700- child
17701- .stdin
17702- .take()
17703- .expect("aomenc stdin")
17704- .write_all(&y4m.stdout)
17705- .expect("writing y4m to aomenc");
17706- let out = child.wait_with_output().expect("aomenc failed to run");
16960+ let out = run_with_stdin(Command::new(aomenc_path())
16961+ .args(&args), &y4m.stdout);
1770716962 assert!(
1770816963 out.status.success(),
1770916964 "aomenc refused the fixture: {}",
@@ -17892,20 +17147,8 @@ pub(crate) mod tests {
1789217147 "-",
1789317148 "-",
1789417149 ];
17895- let mut child = Command::new(aomenc_path())
17896- .args(&args)
17897- .stdin(Stdio::piped())
17898- .stdout(Stdio::piped())
17899- .stderr(Stdio::piped())
17900- .spawn()
17901- .expect("aomenc failed to start");
17902- child
17903- .stdin
17904- .take()
17905- .expect("aomenc stdin")
17906- .write_all(&y4m.stdout)
17907- .expect("writing y4m to aomenc");
17908- let out = child.wait_with_output().expect("aomenc failed to run");
17150+ let out = run_with_stdin(Command::new(aomenc_path())
17151+ .args(&args), &y4m.stdout);
1790917152 assert!(
1791017153 out.status.success(),
1791117154 "aomenc refused the fixture: {}",
@@ -18107,20 +17350,8 @@ pub(crate) mod tests {
1810717350 "-",
1810817351 "-",
1810917352 ];
18110- let mut child = Command::new(aomenc_path())
18111- .args(&args)
18112- .stdin(Stdio::piped())
18113- .stdout(Stdio::piped())
18114- .stderr(Stdio::piped())
18115- .spawn()
18116- .expect("aomenc failed to start");
18117- child
18118- .stdin
18119- .take()
18120- .expect("aomenc stdin")
18121- .write_all(&y4m.stdout)
18122- .expect("writing y4m to aomenc");
18123- let out = child.wait_with_output().expect("aomenc failed to run");
17353+ let out = run_with_stdin(Command::new(aomenc_path())
17354+ .args(&args), &y4m.stdout);
1812417355 assert!(
1812517356 out.status.success(),
1812617357 "aomenc refused the fixture: {}",
@@ -18305,20 +17536,8 @@ pub(crate) mod tests {
1830517536 "-",
1830617537 "-",
1830717538 ];
18308- let mut child = Command::new(aomenc_path())
18309- .args(&args)
18310- .stdin(Stdio::piped())
18311- .stdout(Stdio::piped())
18312- .stderr(Stdio::piped())
18313- .spawn()
18314- .expect("aomenc failed to start");
18315- child
18316- .stdin
18317- .take()
18318- .expect("aomenc stdin")
18319- .write_all(&y4m.stdout)
18320- .expect("writing y4m to aomenc");
18321- let out = child.wait_with_output().expect("aomenc failed to run");
17539+ let out = run_with_stdin(Command::new(aomenc_path())
17540+ .args(&args), &y4m.stdout);
1832217541 assert!(
1832317542 out.status.success(),
1832417543 "aomenc refused the fixture: {}",
@@ -18474,20 +17693,8 @@ pub(crate) mod tests {
1847417693 "-",
1847517694 "-",
1847617695 ];
18477- let mut child = Command::new(aomenc_path())
18478- .args(&args)
18479- .stdin(Stdio::piped())
18480- .stdout(Stdio::piped())
18481- .stderr(Stdio::piped())
18482- .spawn()
18483- .expect("aomenc failed to start");
18484- child
18485- .stdin
18486- .take()
18487- .expect("aomenc stdin")
18488- .write_all(&y4m.stdout)
18489- .expect("writing y4m to aomenc");
18490- let out = child.wait_with_output().expect("aomenc failed to run");
17696+ let out = run_with_stdin(Command::new(aomenc_path())
17697+ .args(&args), &y4m.stdout);
1849117698 assert!(
1849217699 out.status.success(),
1849317700 "aomenc refused the fixture: {}",
@@ -18620,20 +17827,8 @@ pub(crate) mod tests {
1862017827 "-",
1862117828 "-",
1862217829 ];
18623- let mut child = Command::new(aomenc_path())
18624- .args(&args)
18625- .stdin(Stdio::piped())
18626- .stdout(Stdio::piped())
18627- .stderr(Stdio::piped())
18628- .spawn()
18629- .expect("aomenc failed to start");
18630- child
18631- .stdin
18632- .take()
18633- .expect("aomenc stdin")
18634- .write_all(&y4m.stdout)
18635- .expect("writing y4m to aomenc");
18636- let out = child.wait_with_output().expect("aomenc failed to run");
17830+ let out = run_with_stdin(Command::new(aomenc_path())
17831+ .args(&args), &y4m.stdout);
1863717832 assert!(
1863817833 out.status.success(),
1863917834 "aomenc refused the fixture: {}",
@@ -18759,20 +17954,8 @@ pub(crate) mod tests {
1875917954 args.push(arm.cq);
1876017955 args.extend_from_slice(&arm.extra);
1876117956 args.extend_from_slice(&["--obu", "-o", "-", "-"]);
18762- let mut child = Command::new(aomenc_path())
18763- .args(&args)
18764- .stdin(Stdio::piped())
18765- .stdout(Stdio::piped())
18766- .stderr(Stdio::piped())
18767- .spawn()
18768- .expect("aomenc failed to start");
18769- child
18770- .stdin
18771- .take()
18772- .expect("aomenc stdin")
18773- .write_all(&y4m.stdout)
18774- .expect("writing y4m to aomenc");
18775- let out = child.wait_with_output().expect("aomenc failed to run");
17957+ let out = run_with_stdin(Command::new(aomenc_path())
17958+ .args(&args), &y4m.stdout);
1877617959 assert!(
1877717960 out.status.success(),
1877817961 "{NAME} {}: aomenc refused the recipe: {}",
@@ -18918,20 +18101,8 @@ pub(crate) mod tests {
1891818101 "-",
1891918102 "-",
1892018103 ];
18921- let mut child = Command::new(aomenc_path())
18922- .args(&args)
18923- .stdin(Stdio::piped())
18924- .stdout(Stdio::piped())
18925- .stderr(Stdio::piped())
18926- .spawn()
18927- .expect("aomenc failed to start");
18928- child
18929- .stdin
18930- .take()
18931- .expect("aomenc stdin")
18932- .write_all(&y4m.stdout)
18933- .expect("writing y4m to aomenc");
18934- let out = child.wait_with_output().expect("aomenc failed to run");
18104+ let out = run_with_stdin(Command::new(aomenc_path())
18105+ .args(&args), &y4m.stdout);
1893518106 assert!(
1893618107 out.status.success(),
1893718108 "aomenc refused the fixture: {}",
@@ -19010,20 +18181,8 @@ pub(crate) mod tests {
1901018181 "--min-partition-size=8",
1901118182 "--max-partition-size=64",
1901218183 ]);
19013- let mut child = Command::new(aomenc_path())
19014- .args(&rect_args)
19015- .stdin(Stdio::piped())
19016- .stdout(Stdio::piped())
19017- .stderr(Stdio::piped())
19018- .spawn()
19019- .expect("aomenc failed to start");
19020- child
19021- .stdin
19022- .take()
19023- .expect("aomenc stdin")
19024- .write_all(&y4m.stdout)
19025- .expect("writing y4m to aomenc");
19026- let out = child.wait_with_output().expect("aomenc failed to run");
18184+ let out = run_with_stdin(Command::new(aomenc_path())
18185+ .args(&rect_args), &y4m.stdout);
1902718186 assert!(
1902818187 out.status.success(),
1902918188 "{NAME} RECT-ARM: aomenc refused its own recipe plus the rect overrides: {}",
@@ -19217,20 +18376,8 @@ pub(crate) mod tests {
1921718376 "-",
1921818377 "-",
1921918378 ];
19220- let mut child = Command::new(aomenc_path())
19221- .args(&args)
19222- .stdin(Stdio::piped())
19223- .stdout(Stdio::piped())
19224- .stderr(Stdio::piped())
19225- .spawn()
19226- .expect("aomenc failed to start");
19227- child
19228- .stdin
19229- .take()
19230- .expect("aomenc stdin")
19231- .write_all(&y4m.stdout)
19232- .expect("writing y4m to aomenc");
19233- let out = child.wait_with_output().expect("aomenc failed to run");
18379+ let out = run_with_stdin(Command::new(aomenc_path())
18380+ .args(&args), &y4m.stdout);
1923418381 assert!(
1923518382 out.status.success(),
1923618383 "aomenc refused the fixture: {}",
@@ -19565,20 +18712,8 @@ pub(crate) mod tests {
1956518712 "-",
1956618713 "-",
1956718714 ];
19568- let mut child = Command::new(aomenc_path())
19569- .args(&args)
19570- .stdin(Stdio::piped())
19571- .stdout(Stdio::piped())
19572- .stderr(Stdio::piped())
19573- .spawn()
19574- .expect("aomenc failed to start");
19575- child
19576- .stdin
19577- .take()
19578- .expect("aomenc stdin")
19579- .write_all(&y4m.stdout)
19580- .expect("writing y4m to aomenc");
19581- let out = child.wait_with_output().expect("aomenc failed to run");
18715+ let out = run_with_stdin(Command::new(aomenc_path())
18716+ .args(&args), &y4m.stdout);
1958218717 assert!(
1958318718 out.status.success(),
1958418719 "aomenc refused the fixture: {}",
@@ -19792,20 +18927,7 @@ pub(crate) mod tests {
1979218927 "-",
1979318928 "-",
1979418929 ];
19795- let mut child = Command::new(affine_aomenc_path())
19796- .args(&args)
19797- .stdin(Stdio::piped())
19798- .stdout(Stdio::piped())
19799- .stderr(Stdio::piped())
19800- .spawn()
19801- .expect("affine aomenc failed to start");
19802- child
19803- .stdin
19804- .take()
19805- .expect("aomenc stdin")
19806- .write_all(&y4m.stdout)
19807- .expect("writing y4m to aomenc");
19808- let out = child.wait_with_output().expect("aomenc failed to run");
18930+ let out = run_with_stdin(Command::new(affine_aomenc_path()).args(&args), &y4m.stdout);
1980918931 assert!(
1981018932 out.status.success(),
1981118933 "aomenc refused the fixture: {}",
@@ -19953,20 +19075,8 @@ pub(crate) mod tests {
1995319075 "-",
1995419076 "-",
1995519077 ];
19956- let mut child = Command::new(aomenc_path())
19957- .args(&args)
19958- .stdin(Stdio::piped())
19959- .stdout(Stdio::piped())
19960- .stderr(Stdio::piped())
19961- .spawn()
19962- .expect("aomenc failed to start");
19963- child
19964- .stdin
19965- .take()
19966- .expect("aomenc stdin")
19967- .write_all(&y4m.stdout)
19968- .expect("writing y4m to aomenc");
19969- let out = child.wait_with_output().expect("aomenc failed to run");
19078+ let out = run_with_stdin(Command::new(aomenc_path())
19079+ .args(&args), &y4m.stdout);
1997019080 assert!(
1997119081 out.status.success(),
1997219082 "aomenc refused the fixture: {}",
@@ -20110,7 +19220,7 @@ pub(crate) mod tests {
2011019220 "ffmpeg fixture: {}",
2011119221 String::from_utf8_lossy(&y4m.stderr)
2011219222 );
20113- let mut child = Command::new(aomenc_path())
19223+ let out = run_with_stdin(Command::new(aomenc_path())
2011419224 .args([
2011519225 "--threads=1",
2011619226 "--row-mt=0",
@@ -20123,19 +19233,7 @@ pub(crate) mod tests {
2012319233 "-o",
2012419234 "-",
2012519235 "-",
20126- ])
20127- .stdin(Stdio::piped())
20128- .stdout(Stdio::piped())
20129- .stderr(Stdio::piped())
20130- .spawn()
20131- .expect("aomenc failed to start");
20132- child
20133- .stdin
20134- .take()
20135- .expect("aomenc stdin")
20136- .write_all(&y4m.stdout)
20137- .expect("writing y4m to aomenc");
20138- let out = child.wait_with_output().expect("aomenc failed to run");
19236+ ]), &y4m.stdout);
2013919237 assert!(
2014019238 out.status.success(),
2014119239 "aomenc refused the fixture: {}",
@@ -20232,7 +19330,7 @@ pub(crate) mod tests {
2023219330 .expect("ffmpeg failed to run");
2023319331 assert!(y4m.status.success(), "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr));
2023419332 let encode = || {
20235- let mut child = Command::new(aomenc_path())
19333+ let out = run_with_stdin(Command::new(aomenc_path())
2023619334 .args([
2023719335 "--codec=av1",
2023819336 "--passes=1",
@@ -20259,19 +19357,7 @@ pub(crate) mod tests {
2025919357 "-o",
2026019358 "-",
2026119359 "-",
20262- ])
20263- .stdin(Stdio::piped())
20264- .stdout(Stdio::piped())
20265- .stderr(Stdio::piped())
20266- .spawn()
20267- .expect("aomenc failed to start");
20268- child
20269- .stdin
20270- .take()
20271- .expect("aomenc stdin")
20272- .write_all(&y4m.stdout)
20273- .expect("writing y4m to aomenc");
20274- let out = child.wait_with_output().expect("aomenc failed to run");
19360+ ]), &y4m.stdout);
2027519361 assert!(
2027619362 out.status.success(),
2027719363 "aomenc refused the fixture: {}",
@@ -20349,7 +19435,7 @@ pub(crate) mod tests {
2034919435 let mut total_overrides = 0usize;
2035019436 for (rtx, filter_intra) in [("1", "0"), ("0", "1")] {
2035119437 let encode = || {
20352- let mut child = Command::new(aomenc_path())
19438+ let out = run_with_stdin(Command::new(aomenc_path())
2035319439 .args([
2035419440 "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32",
2035519441 "--cpu-used=4", "--threads=1", "--row-mt=0", "--sb-size=64",
@@ -20361,19 +19447,7 @@ pub(crate) mod tests {
2036119447 &format!("--reduced-tx-type-set={rtx}"),
2036219448 "--min-partition-size=8", "--max-partition-size=32",
2036319449 "--obu", "-o", "-", "-",
20364- ])
20365- .stdin(Stdio::piped())
20366- .stdout(Stdio::piped())
20367- .stderr(Stdio::piped())
20368- .spawn()
20369- .expect("aomenc failed to start");
20370- child
20371- .stdin
20372- .take()
20373- .expect("aomenc stdin")
20374- .write_all(&y4m.stdout)
20375- .expect("writing y4m to aomenc");
20376- let out = child.wait_with_output().expect("aomenc failed to run");
19450+ ]), &y4m.stdout);
2037719451 assert!(
2037819452 out.status.success(),
2037919453 "aomenc refused the fixture: {}",
@@ -20475,7 +19549,7 @@ pub(crate) mod tests {
2047519549 String::from_utf8_lossy(&y4m.stderr)
2047619550 );
2047719551 let encode = || {
20478- let mut child = Command::new(aomenc_path())
19552+ let out = run_with_stdin(Command::new(aomenc_path())
2047919553 .args([
2048019554 "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=16",
2048119555 "--cpu-used=4", "--threads=1", "--row-mt=0", "--sb-size=64",
@@ -20487,19 +19561,7 @@ pub(crate) mod tests {
2048719561 &format!("--input-bit-depth={depth}"),
2048819562 &format!("--bit-depth={depth}"),
2048919563 "--obu", "-o", "-", "-",
20490- ])
20491- .stdin(Stdio::piped())
20492- .stdout(Stdio::piped())
20493- .stderr(Stdio::piped())
20494- .spawn()
20495- .expect("aomenc failed to start");
20496- child
20497- .stdin
20498- .take()
20499- .expect("aomenc stdin")
20500- .write_all(&y4m.stdout)
20501- .expect("writing y4m to aomenc");
20502- let out = child.wait_with_output().expect("aomenc failed to run");
19564+ ]), &y4m.stdout);
2050319565 assert!(
2050419566 out.status.success(),
2050519567 "aomenc refused the fixture (depth={depth}): {}",
@@ -20646,7 +19708,7 @@ pub(crate) mod tests {
2064619708 String::from_utf8_lossy(&y4m.stderr)
2064719709 );
2064819710 let encode = || {
20649- let mut child = Command::new(aomenc_path())
19711+ let out = run_with_stdin(Command::new(aomenc_path())
2065019712 .args([
2065119713 "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=52",
2065219714 "--cpu-used=0", "--threads=1", "--row-mt=0", "--sb-size=128",
@@ -20659,19 +19721,7 @@ pub(crate) mod tests {
2065919721 &format!("--input-bit-depth={depth}"),
2066019722 &format!("--bit-depth={depth}"),
2066119723 "--obu", "-o", "-", "-",
20662- ])
20663- .stdin(Stdio::piped())
20664- .stdout(Stdio::piped())
20665- .stderr(Stdio::piped())
20666- .spawn()
20667- .expect("aomenc failed to start");
20668- child
20669- .stdin
20670- .take()
20671- .expect("aomenc stdin")
20672- .write_all(&y4m.stdout)
20673- .expect("writing y4m to aomenc");
20674- let out = child.wait_with_output().expect("aomenc failed to run");
19724+ ]), &y4m.stdout);
2067519725 assert!(
2067619726 out.status.success(),
2067719727 "aomenc refused the fixture (depth={depth}): {}",
@@ -20869,15 +19919,8 @@ pub(crate) mod tests {
2086919919 args.push("--bit-depth=10".into());
2087019920 }
2087119921 args.extend(["--obu".into(), "-o".into(), "-".into(), "-".into()]);
20872- let mut child = Command::new(aomenc_path())
20873- .args(&args)
20874- .stdin(Stdio::piped())
20875- .stdout(Stdio::piped())
20876- .stderr(Stdio::piped())
20877- .spawn()
20878- .expect("aomenc failed to start");
20879- child.stdin.take().expect("aomenc stdin").write_all(&y4m.stdout).expect("y4m to aomenc");
20880- let out = child.wait_with_output().expect("aomenc failed to run");
19922+ let out = run_with_stdin(Command::new(aomenc_path())
19923+ .args(&args), &y4m.stdout);
crates/ec-av1/src/tile.rsmodified+678 -373
@@ -12,17 +12,17 @@
1212 use std::cell::RefCell;
1313 #[cfg(test)]
1414 use std::collections::BTreeMap;
15-use std::sync::LazyLock;
1615 use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
16+use std::sync::LazyLock;
1717
1818 use ec_core::{Error, Result};
1919
2020 use crate::cdf;
2121 use crate::cdf_state::{Cdfs, MvComponentCdfs, TxbSet, TxbTables};
22-use crate::decode::{TXFM_CTX_INIT, txfm_partition_ctx_rect};
22+use crate::decode::{txfm_partition_ctx_rect, TXFM_CTX_INIT};
2323 use crate::msac::SymbolEncoder;
24+use crate::mvstack::{find_mv_stack, mv16, MiGrid, MiInfo, NO_REF1};
2425 use crate::transform::TxType;
25-use crate::mvstack::{MiGrid, MiInfo, NO_REF1, find_mv_stack, mv16};
2626
2727 // ---------------------------------------------------------------------------
2828 // lane-av1lr: per-64x64 `cdef_idx` (spec 5.11.56, `read_cdef`). The decoder
@@ -386,9 +386,7 @@ fn write_inter_block_128(
386386 let scan32 = default_scan(TX32);
387387 let unit_of = |plane: usize, cr: usize, cc: usize| -> Vec<i32> {
388388 (0..32)
389- .flat_map(|row| {
390- packed[plane][(cr * 32 + row) * 64 + cc * 32..][..32].to_vec()
391- })
389+ .flat_map(|row| packed[plane][(cr * 32 + row) * 64 + cc * 32..][..32].to_vec())
392390 .collect()
393391 };
394392 let mut chroma_units: Vec<((usize, usize), [Vec<i32>; 2])> = Vec::new();
@@ -659,9 +657,7 @@ fn write_inter_block_128_rect(
659657 let scan32 = default_scan(TX32);
660658 let unit_of = |plane: usize, cr: usize, cc: usize| -> Vec<i32> {
661659 (0..32)
662- .flat_map(|row| {
663- packed[plane][(cr * 32 + row) * 64 + cc * 32..][..32].to_vec()
664- })
660+ .flat_map(|row| packed[plane][(cr * 32 + row) * 64 + cc * 32..][..32].to_vec())
665661 .collect()
666662 };
667663 let mut chroma_units: Vec<((usize, usize), [Vec<i32>; 2])> = Vec::new();
@@ -702,7 +698,8 @@ fn write_inter_block_128_rect(
702698 &mut cdfs.txb(TxbSet::Chroma32, 0),
703699 &grid,
704700 &scan32,
705- usize::from(around.above_coded) + usize::from(around.left_coded)
701+ usize::from(around.above_coded)
702+ + usize::from(around.left_coded)
706703 + 3 * usize::from(is_half),
707704 dc_sign_ctx(around.dc_vote),
708705 Some(plane),
@@ -781,8 +778,7 @@ pub fn take_sb128_ab_hits() -> [usize; 4] {
781778 /// lane-b128r: how many of those blocks carried a REAL residual (four
782779 /// TX_64X64 luma units plus their per-chunk chroma pair) rather than being
783780 /// skipped, since the last [`take_sb128_residual_hits`].
784-static SB128_RESIDUAL_HITS: std::sync::atomic::AtomicUsize =
785- std::sync::atomic::AtomicUsize::new(0);
781+static SB128_RESIDUAL_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
786782
787783 /// The 128x128-with-residual count since the last call, and zero it.
788784 pub fn take_sb128_residual_hits() -> usize {
@@ -792,8 +788,7 @@ pub fn take_sb128_residual_hits() -> usize {
792788 /// [`write_inter_block_128_rect`] codes) carried a REAL residual rather than
793789 /// being skipped, since the last [`take_sb128_rectres_hits`] -- the writer
794790 /// side of [`crate::encode::take_b128_rectres_hits`]'s search count.
795-static SB128_RECTRES_HITS: std::sync::atomic::AtomicUsize =
796- std::sync::atomic::AtomicUsize::new(0);
791+static SB128_RECTRES_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
797792
798793 /// The rect/AB-piece-with-residual count since the last call, and zero it.
799794 pub fn take_sb128_rectres_hits() -> usize {
@@ -803,8 +798,7 @@ pub fn take_sb128_rectres_hits() -> usize {
803798 /// lane-b128r: how many of those blocks named a SECOND reference (the
804799 /// compound arm at the 128 root), since the last
805800 /// [`take_sb128_compound_hits`].
806-static SB128_COMPOUND_HITS: std::sync::atomic::AtomicUsize =
807- std::sync::atomic::AtomicUsize::new(0);
801+static SB128_COMPOUND_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
808802
809803 /// The compound-128 count since the last call, and zero it.
810804 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,
838832 let info = plan.units[(rcol + rrow * plan.horz_units) as usize];
839833 enc.symbol(usize::from(info.is_some()), &mut cdfs.restore_wiener);
840834 if let Some(info) = info {
841- crate::restoration::write_wiener_filter(
842- enc,
843- false,
844- &mut plan.reference,
845- &info,
846- );
835+ crate::restoration::write_wiener_filter(enc, false, &mut plan.reference, &info);
847836 }
848837 }
849838 }
@@ -919,7 +908,10 @@ impl TileLayout {
919908 let starts = |total: u32, log2: u32| {
920909 let total128 = total.div_ceil(unit);
921910 let step = total128.div_ceil(1 << log2).max(1);
922- let mut v: Vec<u32> = (0..total128).step_by(step as usize).map(|s| s * unit).collect();
911+ let mut v: Vec<u32> = (0..total128)
912+ .step_by(step as usize)
913+ .map(|s| s * unit)
914+ .collect();
923915 v.push(total);
924916 v
925917 };
@@ -1067,11 +1059,9 @@ pub(crate) fn cdef_unit_owner(blocks: &[Quadrant], mi_cols: u32, mi_rows: u32) -
10671059 // (its two squares are one unit each); only a non-skip one
10681060 // codes a literal, so only it fires.
10691061 Quadrant::Ab128(symbol, pieces) => {
1070- for (piece, ((mi_r, mi_c), (w, h))) in
1071- pieces.iter().zip(crate::encode::ab128_pieces(
1072- usize::from(*symbol),
1073- (0, 0),
1074- ))
1062+ for (piece, ((mi_r, mi_c), (w, h))) in pieces
1063+ .iter()
1064+ .zip(crate::encode::ab128_pieces(usize::from(*symbol), (0, 0)))
10751065 {
10761066 if piece.skip {
10771067 continue;
@@ -1111,7 +1101,12 @@ thread_local! {
11111101 /// carries no literal at all).
11121102 pub(crate) fn arm_cdef_idx(bits: u8, sb_cols: usize, grid: Vec<u8>) {
11131103 CDEF_IDX.with(|c| {
1114- *c.borrow_mut() = (bits > 0).then(|| CdefIdxPlan { bits, sb_cols, grid, last: None });
1104+ *c.borrow_mut() = (bits > 0).then(|| CdefIdxPlan {
1105+ bits,
1106+ sb_cols,
1107+ grid,
1108+ last: None,
1109+ });
11151110 });
11161111 }
11171112
@@ -1143,8 +1138,12 @@ thread_local! {
11431138 /// lane-deltaq) when `res == 0`.
11441139 pub(crate) fn arm_delta_q(res: i32, sb_cols: usize, grid: Vec<u8>, base: u8) {
11451140 DELTA_Q.with(|c| {
1146- *c.borrow_mut() =
1147- (res > 0).then(|| DeltaQPlan { res, sb_cols, grid, cur: i32::from(base) });
1141+ *c.borrow_mut() = (res > 0).then(|| DeltaQPlan {
1142+ res,
1143+ sb_cols,
1144+ grid,
1145+ cur: i32::from(base),
1146+ });
11481147 });
11491148 }
11501149
@@ -1285,14 +1284,23 @@ fn write_filter_intra(
12851284 filter_intra: Option<u8>,
12861285 ) {
12871286 if !filter_intra_armed() || mode != DC_PRED || has_palette_y {
1288- debug_assert!(filter_intra.is_none(), "no `use_filter_intra` symbol exists here");
1287+ debug_assert!(
1288+ filter_intra.is_none(),
1289+ "no `use_filter_intra` symbol exists here"
1290+ );
12891291 return;
12901292 }
12911293 let Some(class) = crate::decode::filter_intra_size_class(side) else {
1292- debug_assert!(filter_intra.is_none(), "past av1_filter_intra_allowed_bsize");
1294+ debug_assert!(
1295+ filter_intra.is_none(),
1296+ "past av1_filter_intra_allowed_bsize"
1297+ );
12931298 return;
12941299 };
1295- enc.symbol(usize::from(filter_intra.is_some()), &mut cdfs.filter_intra[class]);
1300+ enc.symbol(
1301+ usize::from(filter_intra.is_some()),
1302+ &mut cdfs.filter_intra[class],
1303+ );
12961304 if let Some(fi) = filter_intra {
12971305 enc.symbol(usize::from(fi), &mut cdfs.filter_intra_mode);
12981306 FILTER_INTRA_HITS[0].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
@@ -1525,7 +1533,12 @@ fn write_motion_mode(
15251533 /// a single-reference or intra block, and `record_compound_mi`'s overwrite of
15261534 /// the ALTREF default for a compound one (this writer only codes
15271535 /// `comp_group_idx == 0`, `compound_idx == 1`).
1528-fn record_block_compound(neighbours: &mut Neighbours, at_mi: (usize, usize), side: usize, block: &BlockCoeffs) {
1536+fn record_block_compound(
1537+ neighbours: &mut Neighbours,
1538+ at_mi: (usize, usize),
1539+ side: usize,
1540+ block: &BlockCoeffs,
1541+) {
15291542 if let Some(r1) = block.inter.and_then(|i| i.ref1) {
15301543 neighbours.record_compound_mi(at_mi, side, r1, 0, 1);
15311544 }
@@ -1577,14 +1590,19 @@ pub(crate) fn high_precision_mv() -> bool {
15771590 /// `allow_high_precision_mv`, one per non-zero mv component with it), `[1]`
15781591 /// counts the ones that came out ZERO -- an eighth-pel vector, i.e. one a
15791592 /// frame without the flag cannot name at all.
1580-static HP_SYMBOLS: [std::sync::atomic::AtomicU64; 2] =
1581- [std::sync::atomic::AtomicU64::new(0), std::sync::atomic::AtomicU64::new(0)];
1593+static HP_SYMBOLS: [std::sync::atomic::AtomicU64; 2] = [
1594+ std::sync::atomic::AtomicU64::new(0),
1595+ std::sync::atomic::AtomicU64::new(0),
1596+];
15821597
15831598 /// Reads and clears [`HP_SYMBOLS`]: `(hp symbols coded, eighth-pel ones)`.
15841599 #[allow(dead_code)] // read only from the `#[cfg(test)]` witness
15851600 pub(crate) fn take_hp_symbols() -> (u64, u64) {
15861601 let all = HP_SYMBOLS[0].swap(0, std::sync::atomic::Ordering::Relaxed);
1587- (all, HP_SYMBOLS[1].swap(0, std::sync::atomic::Ordering::Relaxed))
1602+ (
1603+ all,
1604+ HP_SYMBOLS[1].swap(0, std::sync::atomic::Ordering::Relaxed),
1605+ )
15881606 }
15891607
15901608 /// [`take_hp_symbols`] without clearing -- what the NEWMV census prints.
@@ -1611,10 +1629,10 @@ fn write_compound_ref_frames(
16111629 (ref0, ref1): (i8, i8),
16121630 ) -> Result<()> {
16131631 use crate::mvstack::{
1632+ comp_reference_type_ctx, single_ref_p1_ctx, single_ref_p2_ctx, single_ref_p3_ctx,
1633+ single_ref_p4_ctx, single_ref_p5_ctx, single_ref_p6_ctx, uni_comp_ref_p1_ctx,
16141634 ALTREF2_FRAME, ALTREF_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST2_FRAME, LAST3_FRAME,
1615- LAST_FRAME, comp_reference_type_ctx, single_ref_p1_ctx, single_ref_p2_ctx,
1616- single_ref_p3_ctx, single_ref_p4_ctx, single_ref_p5_ctx, single_ref_p6_ctx,
1617- uni_comp_ref_p1_ctx,
1635+ LAST_FRAME,
16181636 };
16191637 let a = (above_ref > 0).then_some(above_ref);
16201638 let l = (left_ref > 0).then_some(left_ref);
@@ -1810,14 +1828,20 @@ fn write_compound_block(
18101828 let mut walk = 1usize;
18111829 while walk < 3 && stack.entries.len() > walk + 1 {
18121830 let advance = walk < idx;
1813- enc.symbol(usize::from(advance), &mut cdfs.drl_mode[stack.drl_ctx[walk]]);
1831+ enc.symbol(
1832+ usize::from(advance),
1833+ &mut cdfs.drl_mode[stack.drl_ctx[walk]],
1834+ );
18141835 if !advance {
18151836 break;
18161837 }
18171838 walk += 1;
18181839 }
18191840 let near = |i: usize| {
1820- stack.entries.get(i).map_or(stack.near_mv, |e| (e.mv0, e.mv1))
1841+ stack
1842+ .entries
1843+ .get(i)
1844+ .map_or(stack.near_mv, |e| (e.mv0, e.mv1))
18211845 };
18221846 if walk != idx && near(walk) != near(idx) {
18231847 note_drl_clamp(idx, walk, stack.entries.len());
@@ -1845,14 +1869,20 @@ fn write_compound_block(
18451869 let mut walk = 0usize;
18461870 while walk < 2 && stack.entries.len() > walk + 1 {
18471871 let advance = walk < idx;
1848- enc.symbol(usize::from(advance), &mut cdfs.drl_mode[stack.drl_ctx[walk]]);
1872+ enc.symbol(
1873+ usize::from(advance),
1874+ &mut cdfs.drl_mode[stack.drl_ctx[walk]],
1875+ );
18491876 if !advance {
18501877 break;
18511878 }
18521879 walk += 1;
18531880 }
18541881 let nearest = |i: usize| {
1855- stack.entries.get(i).map_or(stack.nearest_mv, |e| (e.mv0, e.mv1))
1882+ stack
1883+ .entries
1884+ .get(i)
1885+ .map_or(stack.nearest_mv, |e| (e.mv0, e.mv1))
18561886 };
18571887 if walk != idx && nearest(walk) != nearest(idx) {
18581888 note_drl_clamp(idx, walk, stack.entries.len());
@@ -1993,7 +2023,11 @@ fn write_delta_q(
19932023 // under `EC_AV1_SB128` -- decode.rs `maybe_read_delta_q` gates on
19942024 // `sb_mi_cur`, and a writer gating on a hardcoded 64 codes three
19952025 // symbol groups per 128 root the reader never reads.
1996- let sb_mi = if sb128_armed() { SB_MI as usize * 2 } else { SB_MI as usize };
2026+ let sb_mi = if sb128_armed() {
2027+ SB_MI as usize * 2
2028+ } else {
2029+ SB_MI as usize
2030+ };
19972031 if mi.0 % sb_mi != 0 || mi.1 % sb_mi != 0 {
19982032 return;
19992033 }
@@ -2820,9 +2854,9 @@ impl Quadrant {
28202854 Quadrant::Whole(block) | Quadrant::Whole64(block) | Quadrant::Whole128(block) => {
28212855 std::slice::from_ref(block)
28222856 }
2823- Quadrant::Split(blocks)
2824- | Quadrant::Rect128(_, blocks)
2825- | Quadrant::Ab128(_, blocks) => blocks.as_slice(),
2857+ Quadrant::Split(blocks) | Quadrant::Rect128(_, blocks) | Quadrant::Ab128(_, blocks) => {
2858+ blocks.as_slice()
2859+ }
28262860 Quadrant::Covered => &[],
28272861 }
28282862 }
@@ -3040,8 +3074,12 @@ impl Neighbours {
30403074 fn start_row(&mut self) {
30413075 self.left.iter_mut().for_each(|l| *l = Default::default());
30423076 self.left_mode.iter_mut().for_each(|m| *m = DC_PRED);
3043- self.left_side.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE);
3044- self.left_side_mi.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE);
3077+ self.left_side
3078+ .iter_mut()
3079+ .for_each(|s| *s = NO_NEIGHBOUR_SIDE);
3080+ self.left_side_mi
3081+ .iter_mut()
3082+ .for_each(|s| *s = NO_NEIGHBOUR_SIDE);
30453083 self.left_skip.iter_mut().for_each(|s| *s = false);
30463084 self.left_inter.iter_mut().for_each(|i| *i = false);
30473085 self.left_ref.iter_mut().for_each(|r| *r = -1);
@@ -3052,7 +3090,9 @@ impl Neighbours {
30523090 self.left_txfm.iter_mut().for_each(|t| *t = TXFM_CTX_INIT);
30533091 self.left_palette_size.iter_mut().for_each(|s| *s = 0);
30543092 self.left_palette_uv_size.iter_mut().for_each(|s| *s = 0);
3055- self.left_palette_uv_colors.iter_mut().for_each(|c| *c = [0u16; 8]);
3093+ self.left_palette_uv_colors
3094+ .iter_mut()
3095+ .for_each(|c| *c = [0u16; 8]);
30563096 }
30573097
30583098 /// `av1_get_palette_mode_ctx` + `av1_get_palette_cache`, mirrored from
@@ -3069,12 +3109,18 @@ impl Neighbours {
30693109 let above_ok = r % 16 != 0;
30703110 let above_is_palette = r > 0 && self.above_palette_size[c] > 0;
30713111 let (above_n, above_colors) = if above_ok && self.above_palette_size[c] > 0 {
3072- (usize::from(self.above_palette_size[c]), self.above_palette_colors[c])
3112+ (
3113+ usize::from(self.above_palette_size[c]),
3114+ self.above_palette_colors[c],
3115+ )
30733116 } else {
30743117 (0, [0u16; 8])
30753118 };
30763119 let (left_n, left_colors) = if c > 0 && self.left_palette_size[r] > 0 {
3077- (usize::from(self.left_palette_size[r]), self.left_palette_colors[r])
3120+ (
3121+ usize::from(self.left_palette_size[r]),
3122+ self.left_palette_colors[r],
3123+ )
30783124 } else {
30793125 (0, [0u16; 8])
30803126 };
@@ -3167,7 +3213,13 @@ impl Neighbours {
31673213 /// [`Self::record_palette_y`] for the chroma bands (decode.rs
31683214 /// `record_palette_uv_rect`) -- `size == 0` clears stale state the same
31693215 /// way, and the span is in LUMA pixels for both planes' bands alike.
3170- fn record_palette_uv(&mut self, (r, c): (usize, usize), (w, h): (usize, usize), size: u8, colors: [u16; 8]) {
3216+ fn record_palette_uv(
3217+ &mut self,
3218+ (r, c): (usize, usize),
3219+ (w, h): (usize, usize),
3220+ size: u8,
3221+ colors: [u16; 8],
3222+ ) {
31713223 // lane-b128hv: the above band spans the block's WIDTH and the left
31723224 // band its HEIGHT; identical to the one loop this replaces at w == h.
31733225 for cell in 0..(w / MI).max(1) {
@@ -3191,7 +3243,13 @@ impl Neighbours {
31913243 /// What a just-written block leaves in the palette bands (decode.rs
31923244 /// `record_palette_y_rect`): its size and colours over every 4x4 unit it
31933245 /// spans, `0` for a block that took no palette.
3194- fn record_palette_y(&mut self, (r, c): (usize, usize), (w, h): (usize, usize), size: u8, colors: [u16; 8]) {
3246+ fn record_palette_y(
3247+ &mut self,
3248+ (r, c): (usize, usize),
3249+ (w, h): (usize, usize),
3250+ size: u8,
3251+ colors: [u16; 8],
3252+ ) {
31953253 // lane-b128hv: the above band spans the block's WIDTH and the left
31963254 // band its HEIGHT; identical to the one loop this replaces at w == h.
31973255 for cell in 0..(w / MI).max(1) {
@@ -3216,7 +3274,13 @@ impl Neighbours {
32163274 /// of an INTER frame leaves in the two `TXFM_CONTEXT` bands -- its
32173275 /// resolved transform size over the span `(w_px, h_px)`, which for a
32183276 /// SKIPPED inter block is its own block size instead.
3219- fn record_txfm(&mut self, (mi_r, mi_c): (usize, usize), tx_px: usize, w_px: usize, h_px: usize) {
3277+ fn record_txfm(
3278+ &mut self,
3279+ (mi_r, mi_c): (usize, usize),
3280+ tx_px: usize,
3281+ w_px: usize,
3282+ h_px: usize,
3283+ ) {
32203284 for i in 0..h_px / MI {
32213285 if let Some(cell) = self.left_txfm.get_mut(mi_r + i) {
32223286 *cell = tx_px as u8;
@@ -3492,9 +3556,22 @@ impl Neighbours {
34923556 /// Writes one inter-frame block's skip flag and inter/intra state into
34933557 /// every 16x16 column and row it covers, the same span [`Self::record`]
34943558 /// fills for the coefficient and mode state.
3495- fn record_inter(&mut self, at: (usize, usize), side: usize, skip: bool, is_inter: bool, ref_frame: i8) {
3559+ fn record_inter(
3560+ &mut self,
3561+ at: (usize, usize),
3562+ side: usize,
3563+ skip: bool,
3564+ is_inter: bool,
3565+ ref_frame: i8,
3566+ ) {
34963567 let (r, c) = at;
3497- self.record_inter_mi((r * (SUB / MI), c * (SUB / MI)), side, skip, is_inter, ref_frame);
3568+ self.record_inter_mi(
3569+ (r * (SUB / MI), c * (SUB / MI)),
3570+ side,
3571+ skip,
3572+ is_inter,
3573+ ref_frame,
3574+ );
34983575 }
34993576
35003577 /// lane-b128hv: [`Self::record_inter_mi`] with independent above (width)
@@ -3572,7 +3649,14 @@ impl Neighbours {
35723649
35733650 /// [`Self::record_inter`] taking the block's position directly in 4x4
35743651 /// mode-info units, for a block finer than one [`SUB`] slot.
3575- fn record_inter_mi(&mut self, (mi_r, mi_c): (usize, usize), side: usize, skip: bool, is_inter: bool, ref_frame: i8) {
3652+ fn record_inter_mi(
3653+ &mut self,
3654+ (mi_r, mi_c): (usize, usize),
3655+ side: usize,
3656+ skip: bool,
3657+ is_inter: bool,
3658+ ref_frame: i8,
3659+ ) {
35763660 for cell in 0..side / MI {
35773661 self.above_skip[mi_c + cell] = skip;
35783662 self.left_skip[mi_r + cell] = skip;
@@ -3838,7 +3922,16 @@ pub(crate) fn sb_coeff_key_frame_tile_cdfs(
38383922 neighbours.start_row();
38393923 }
38403924 if sb128 && sb_start {
3841- write_sb128_root(&mut enc, &mut cdfs, &neighbours, sb_r, sb_c, mi_cols, mi_rows, PARTITION_SPLIT);
3925+ write_sb128_root(
3926+ &mut enc,
3927+ &mut cdfs,
3928+ &neighbours,
3929+ sb_r,
3930+ sb_c,
3931+ mi_cols,
3932+ mi_rows,
3933+ PARTITION_SPLIT,
3934+ );
38423935 }
38433936 {
38443937 if !sb128 {
@@ -4316,7 +4409,12 @@ fn write_palette_colors_y(enc: &mut SymbolEncoder, colors: &[u16], cache: &[u16]
43164409 /// below sees, so it only ever makes the encoder take FEWER chroma palettes
43174410 /// than it should -- never a wrong stream. Upgrade path: price both forms
43184411 /// here and write the cheaper one under its own leading bit.
4319-fn write_palette_colors_uv(enc: &mut SymbolEncoder, u_colors: &[u16], v_colors: &[u16], cache: &[u16]) {
4412+fn write_palette_colors_uv(
4413+ enc: &mut SymbolEncoder,
4414+ u_colors: &[u16],
4415+ v_colors: &[u16],
4416+ cache: &[u16],
4417+) {
43204418 let n = u_colors.len();
43214419 let mut cached: Vec<u16> = Vec::with_capacity(n);
43224420 for &c in cache {
@@ -4441,7 +4539,14 @@ pub(crate) fn palette_uv_bits(pal: &PaletteUv, side: usize, on: (usize, usize))
44414539 enc.symbol(n - 2, &mut size_cdf);
44424540 write_palette_colors_uv(&mut enc, &pal.u_colors[..n], &pal.v_colors[..n], &[]);
44434541 let mut idx_cdfs = cdf::PALETTE_UV_COLOR_INDEX[n - 2];
4444- write_color_index_map(&mut enc, &mut idx_cdfs, &pal.map, palette_uv_side(side), n, on);
4542+ write_color_index_map(
4543+ &mut enc,
4544+ &mut idx_cdfs,
4545+ &pal.map,
4546+ palette_uv_side(side),
4547+ n,
4548+ on,
4549+ );
44454550 enc.bits()
44464551 }
44474552
@@ -4552,7 +4657,12 @@ fn write_dv_component(enc: &mut SymbolEncoder, c: &mut MvComponentCdfs, diff: i3
45524657
45534658 /// One intrabc block's DV as a residual against [`intrabc_dv_pred`], off the
45544659 /// `dv` nmv context (decode.rs `read_intrabc_dv` -> `read_mv`).
4555-fn write_dv(enc: &mut SymbolEncoder, cdfs: &mut Cdfs, dv: (i32, i32), pred: (i32, i32)) -> Result<()> {
4660+fn write_dv(
4661+ enc: &mut SymbolEncoder,
4662+ cdfs: &mut Cdfs,
4663+ dv: (i32, i32),
4664+ pred: (i32, i32),
4665+) -> Result<()> {
45564666 let diff = (dv.0 - pred.0, dv.1 - pred.1);
45574667 let joint = match (diff.0 != 0, diff.1 != 0) {
45584668 (false, false) => 0,
@@ -4584,7 +4694,8 @@ fn write_intrabc_block(
45844694 mi: (usize, usize),
45854695 side: usize,
45864696 ) -> Result<()> {
4587- let skip_ctx = usize::from(neighbours.above_skip[mi.1]) + usize::from(neighbours.left_skip[mi.0]);
4697+ let skip_ctx =
4698+ usize::from(neighbours.above_skip[mi.1]) + usize::from(neighbours.left_skip[mi.0]);
45884699 enc.symbol(1, &mut cdfs.skip[skip_ctx]);
45894700 write_cdef_idx(enc, mi, true);
45904701 enc.symbol(1, &mut cdfs.intrabc);
@@ -4705,7 +4816,8 @@ fn write_intra_mode(
47054816 // above + left. Every block this writer codes outside an `allow_intrabc`
47064817 // frame is unskipped, so both bands stay false and this stays 0 -- the
47074818 // literal every stream before this lane was written with.
4708- let skip_ctx = usize::from(neighbours.above_skip[mi.1]) + usize::from(neighbours.left_skip[mi.0]);
4819+ let skip_ctx =
4820+ usize::from(neighbours.above_skip[mi.1]) + usize::from(neighbours.left_skip[mi.0]);
47094821 enc.symbol(0, &mut cdfs.skip[skip_ctx]);
47104822 write_cdef_idx(enc, mi, false);
47114823 // `read_intrabc_info` (spec 5.11.13): the flag is read for EVERY intra
@@ -4737,7 +4849,9 @@ fn write_intra_mode(
47374849 write_cfl_alphas(
47384850 enc,
47394851 cdfs,
4740- block.cfl_alphas.expect("a UV_CFL_PRED block carries its alphas"),
4852+ block
4853+ .cfl_alphas
4854+ .expect("a UV_CFL_PRED block carries its alphas"),
47414855 );
47424856 }
47434857 // `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] =
48905004 /// i.e. palette blocks this writer cut at the frame's right/bottom mi edge.
48915005 /// A gate asserts it non-zero so it cannot pass on a stream that never cuts
48925006 /// one (class `gate-blind-to-feature`).
4893-static PALETTE_CUT_MAPS: std::sync::atomic::AtomicUsize =
4894- std::sync::atomic::AtomicUsize::new(0);
5007+static PALETTE_CUT_MAPS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
48955008
48965009 /// Current value of [`PALETTE_CUT_MAPS`] (colour-index maps).
48975010 pub fn palette_cut_maps_written() -> usize {
@@ -4975,15 +5088,7 @@ fn write_block(
49755088 }
49765089 let (above_mode, left_mode) = (neighbours.above_mode[c], neighbours.left_mode[r]);
49775090 let mode = write_intra_mode(
4978- enc,
4979- cdfs,
4980- neighbours,
4981- block,
4982- above_mode,
4983- left_mode,
4984- cfl,
4985- at_mi,
4986- side,
5091+ enc, cdfs, neighbours, block, above_mode, left_mode, cfl, at_mi, side,
49875092 );
49885093 // The coefficient tables read `fimode_to_intradir[filter_intra_mode]`'s
49895094 // row on a filter-intra block; the neighbour publication below still gets
@@ -5085,7 +5190,9 @@ fn write_leaf8(
50855190 // true first divergence (a differently-sized alphabet under the same
50865191 // DC_PRED decision desyncs the coder even though the decoded mode is
50875192 // unchanged).
5088- let mode = write_intra_mode(enc, cdfs, neighbours, block, above_mode, left_mode, true, leaf_mi, 8);
5193+ let mode = write_intra_mode(
5194+ enc, cdfs, neighbours, block, above_mode, left_mode, true, leaf_mi, 8,
5195+ );
50895196 let planes = [TxbSet::Luma8, TxbSet::Chroma4, TxbSet::Chroma4];
50905197 // As [`write_block`]: the coefficient row follows the filter-intra mode,
50915198 // the mode this leaf publishes (and returns to the next leaf) does not.
@@ -5218,7 +5325,11 @@ fn write_block_planes(
52185325 /// The single luma transform type a block carries, `DCT_DCT` for one that
52195326 /// never searched one (lane-txset).
52205327 fn block_tx_type(block: &BlockCoeffs) -> TxType {
5221- block.luma_tx_types.first().copied().unwrap_or(TxType::DctDct)
5328+ block
5329+ .luma_tx_types
5330+ .first()
5331+ .copied()
5332+ .unwrap_or(TxType::DctDct)
52225333 }
52235334
52245335 /// The `(side / tx)^2` transform units of one block's luma residual, raster
@@ -5294,9 +5405,7 @@ fn write_luma_tus(
52945405 grid.to_vec()
52955406 } else {
52965407 (0..tx)
5297- .flat_map(|row| {
5298- grid[(tu_row * tx + row) * side + tu_col * tx..][..tx].to_vec()
5299- })
5408+ .flat_map(|row| grid[(tu_row * tx + row) * side + tu_col * tx..][..tx].to_vec())
53005409 .collect()
53015410 };
53025411 // spec `get_txb_ctx_general`: a lone transform unit covering its
@@ -5381,7 +5490,9 @@ fn write_luma_select(
53815490 }
53825491 }
53835492 let tx = max_tx >> depth;
5384- write_luma_tus(enc, cdfs, neighbours, at_mi, side, tx, grid, mode, scans, false, tx_types)?;
5493+ write_luma_tus(
5494+ enc, cdfs, neighbours, at_mi, side, tx, grid, mode, scans, false, tx_types,
5495+ )?;
53855496 neighbours.record_tx(at_mi, side, tx);
53865497 Ok(tx)
53875498 }
@@ -5681,7 +5792,9 @@ pub(crate) fn predicted_coeff_bits(blocks: &[Quadrant], base_q_idx: u8) -> f64 {
56815792 .map(|tu| {
56825793 let (r0, c0) = ((tu / 2) * 32, (tu % 2) * 32);
56835794 let unit: Vec<i32> = (0..32)
5684- .flat_map(|row| g[(r0 + row) * 64 + c0..][..32].to_vec())
5795+ .flat_map(|row| {
5796+ g[(r0 + row) * 64 + c0..][..32].to_vec()
5797+ })
56855798 .collect();
56865799 coeff_bits(&unit, TxbSet::Luma32Inter, q_ctx, 0, 0)
56875800 })
@@ -5696,7 +5809,10 @@ pub(crate) fn predicted_coeff_bits(blocks: &[Quadrant], base_q_idx: u8) -> f64 {
56965809 }
56975810 Quadrant::Covered => return 0.0,
56985811 };
5699- q.blocks().iter().map(|b| block_bits(b, side, q_ctx)).sum::<f64>()
5812+ q.blocks()
5813+ .iter()
5814+ .map(|b| block_bits(b, side, q_ctx))
5815+ .sum::<f64>()
57005816 })
57015817 .sum()
57025818 }
@@ -5764,7 +5880,7 @@ fn scan_of(side: usize) -> &'static Vec<u16> {
57645880 /// DECODER's own table so the two cannot drift, cached per size and class.
57655881 fn class_scan_of(side: usize, class: crate::decode::TxClass) -> &'static [u16] {
57665882 static SCANS: LazyLock<[[Vec<u16>; 2]; 4]> = LazyLock::new(|| {
5767- use crate::decode::{TxClass, class_scan_table};
5883+ use crate::decode::{class_scan_table, TxClass};
57685884 [TX4, TX8, TX16, TX32].map(|side| {
57695885 [
57705886 class_scan_table(side, TxClass::Horiz),
@@ -5846,7 +5962,16 @@ pub(crate) fn coeff_bits_typed(
58465962 }
58475963 let scan = scan_of(coding.side);
58485964 let mut enc = SymbolEncoder::pricer();
5849- write_coeffs(&mut enc, &mut coding, grid, scan, skip_ctx, sign_ctx, None, tx_type);
5965+ write_coeffs(
5966+ &mut enc,
5967+ &mut coding,
5968+ grid,
5969+ scan,
5970+ skip_ctx,
5971+ sign_ctx,
5972+ None,
5973+ tx_type,
5974+ );
58505975 enc.bits()
58515976 };
58525977 // lane-av1speed2: 60% of the transform units of an inter stream hold no
@@ -5866,12 +5991,20 @@ pub(crate) fn coeff_bits_typed(
58665991 let all_zero = grid.iter().all(|&level| level == 0);
58675992 PRICING_BASE.with_borrow_mut(|base| {
58685993 if let Some(slot) = base.as_deref_mut().filter(|s| s.0.q_ctx == q_ctx) {
5869- return if all_zero { zero_price(slot) } else { price(slot) };
5994+ return if all_zero {
5995+ zero_price(slot)
5996+ } else {
5997+ price(slot)
5998+ };
58705999 }
58716000 PRICING.with_borrow_mut(|slots| {
58726001 let slot = slots[q_ctx.min(3)]
58736002 .get_or_insert_with(|| Box::new((Cdfs::new(q_ctx), Cdfs::new(q_ctx))));
5874- if all_zero { zero_price(slot) } else { price(slot) }
6003+ if all_zero {
6004+ zero_price(slot)
6005+ } else {
6006+ price(slot)
6007+ }
58756008 })
58766009 })
58776010 }
@@ -5951,7 +6084,11 @@ pub(crate) fn rdoq(
59516084 // is what the writer and the pricer take (`coded_corner`).
59526085 let coded = side.min(TX32);
59536086 let q_ctx = crate::decode::q_ctx_of(base_q_idx);
5954- let mut dense = if coded == side { Vec::new() } else { vec![0i32; coded * coded] };
6087+ let mut dense = if coded == side {
6088+ Vec::new()
6089+ } else {
6090+ vec![0i32; coded * coded]
6091+ };
59556092 fn price(
59566093 levels: &[i32],
59576094 dense: &mut [i32],
@@ -5971,7 +6108,9 @@ pub(crate) fn rdoq(
59716108 }
59726109 coeff_bits_typed(dense, set, q_ctx, skip_ctx, sign_ctx, tx_type)
59736110 }
5974- let mut bits = price(levels, &mut dense, side, coded, set, q_ctx, skip_ctx, sign_ctx, tx_type);
6111+ let mut bits = price(
6112+ levels, &mut dense, side, coded, set, q_ctx, skip_ctx, sign_ctx, tx_type,
6113+ );
59756114 // The DC has its own quantiser, so its squared error per unit of level is
59766115 // `(dc_q / ac_q)^2` of an AC coefficient's.
59776116 let dc = f64::from(crate::quant::dc_q(8, i32::from(base_q_idx)));
@@ -6022,9 +6161,11 @@ pub(crate) fn rdoq(
60226161 let candidate = level - level.signum();
60236162 levels[i] = candidate;
60246163 budget -= 1;
6025- let after = price(levels, &mut dense, side, coded, set, q_ctx, skip_ctx, sign_ctx, tx_type);
6026- let distortion = weight
6027- * ((s - f64::from(candidate)).powi(2) - (s - f64::from(level)).powi(2));
6164+ let after = price(
6165+ levels, &mut dense, side, coded, set, q_ctx, skip_ctx, sign_ctx, tx_type,
6166+ );
6167+ let distortion =
6168+ weight * ((s - f64::from(candidate)).powi(2) - (s - f64::from(level)).powi(2));
60286169 if distortion + lambda * (after - bits) < 0.0 {
60296170 bits = after;
60306171 if census {
@@ -6049,8 +6190,14 @@ pub(crate) fn rdoq(
60496190 /// at the end of the scan), zeroed coefficients, lowered coefficients, bits
60506191 /// after the pass * 64, bits before the pass * 64.
60516192 pub(crate) static RDOQ_STATS: [AtomicU64; 8] = [
6052- AtomicU64::new(0), AtomicU64::new(0), AtomicU64::new(0), AtomicU64::new(0),
6053- AtomicU64::new(0), AtomicU64::new(0), AtomicU64::new(0), AtomicU64::new(0),
6193+ AtomicU64::new(0),
6194+ AtomicU64::new(0),
6195+ AtomicU64::new(0),
6196+ AtomicU64::new(0),
6197+ AtomicU64::new(0),
6198+ AtomicU64::new(0),
6199+ AtomicU64::new(0),
6200+ AtomicU64::new(0),
60546201 ];
60556202
60566203 /// The pre-pass half of [`RDOQ_STATS`] (`EC_AV1_RDOQ_CENSUS`): what the
@@ -6146,11 +6293,13 @@ thread_local! {
61466293 /// at native, still with every one of its frames armed with the defaults.
61476294 pub(crate) fn arm_pricing_cdfs(base: Option<&Cdfs>, screen: bool) {
61486295 static MODE: std::sync::OnceLock<u8> = std::sync::OnceLock::new();
6149- let mode = *MODE.get_or_init(|| match std::env::var("EC_AV1_PRICE_FRAME_CDFS").as_deref() {
6150- Ok("0") => 0,
6151- Ok("1") => 1,
6152- _ => 2,
6153- });
6296+ let mode = *MODE.get_or_init(
6297+ || match std::env::var("EC_AV1_PRICE_FRAME_CDFS").as_deref() {
6298+ Ok("0") => 0,
6299+ Ok("1") => 1,
6300+ _ => 2,
6301+ },
6302+ );
61546303 let on = match mode {
61556304 0 => false,
61566305 1 => true,
@@ -6158,7 +6307,9 @@ pub(crate) fn arm_pricing_cdfs(base: Option<&Cdfs>, screen: bool) {
61586307 };
61596308 PRICING_HITS[usize::from(on && base.is_some())].fetch_add(1, Ordering::Relaxed);
61606309 PRICING_BASE.with_borrow_mut(|slot| {
6161- *slot = base.filter(|_| on).map(|c| Box::new((c.clone(), c.clone())));
6310+ *slot = base
6311+ .filter(|_| on)
6312+ .map(|c| Box::new((c.clone(), c.clone())));
61626313 });
61636314 }
61646315
@@ -6166,8 +6317,7 @@ pub(crate) fn arm_pricing_cdfs(base: Option<&Cdfs>, screen: bool) {
61666317 /// many with the frame's REAL starting tables ([`arm_pricing_cdfs`]), so a
61676318 /// gate can print which side of the screen gate every frame landed on. Counts
61686319 /// arming calls, not frames: a multi-tile frame arms one worker per tile.
6169-pub(crate) static PRICING_HITS: [AtomicUsize; 2] =
6170- [AtomicUsize::new(0), AtomicUsize::new(0)];
6320+pub(crate) static PRICING_HITS: [AtomicUsize; 2] = [AtomicUsize::new(0), AtomicUsize::new(0)];
61716321
61726322 /// Reads and clears [`PRICING_HITS`]: (default-table armings, real-table
61736323 /// armings).
@@ -6389,7 +6539,10 @@ fn write_coeffs(
63896539 // lane-av1speed3: `side` is 4, 8, 16 or 32, but it is a runtime value --
63906540 // `pos / side` compiles to a real integer division, once per coefficient,
63916541 // in the encoder's largest self-time symbol. Same row and column.
6392- debug_assert!(side.is_power_of_two(), "the scan splits a position by shifting");
6542+ debug_assert!(
6543+ side.is_power_of_two(),
6544+ "the scan splits a position by shifting"
6545+ );
63936546 let (shift, mask) = (side.trailing_zeros(), side - 1);
63946547 for scan_idx in (0..eob).rev() {
63956548 let pos = scan[scan_idx] as usize;
@@ -6649,7 +6802,11 @@ fn br_ctx(
66496802 if row == 0 && col == 0 {
66506803 return mag;
66516804 }
6652- let near_origin = if class == TxClass::Horiz { col == 0 } else { row == 0 };
6805+ let near_origin = if class == TxClass::Horiz {
6806+ col == 0
6807+ } else {
6808+ row == 0
6809+ };
66536810 return if near_origin { mag + 7 } else { mag + 14 };
66546811 }
66556812 let p = row * side + col;
@@ -6800,7 +6957,11 @@ pub(crate) fn intra_inter_ctx(
68006957 /// `CLASS0_SIZE << (class + 2)` (spec 3), the magnitude an `MV_CLASS_n`
68016958 /// component's own bits start counting from; class zero starts at zero.
68026959 fn mv_class_base(class: usize) -> i32 {
6803- if class == 0 { 0 } else { 2i32 << (class + 2) }
6960+ if class == 0 {
6961+ 0
6962+ } else {
6963+ 2i32 << (class + 2)
6964+ }
68046965 }
68056966
68066967 /// The class a pre-offset magnitude `z` (`|diff| - 1`) falls in — the inverse
@@ -6923,11 +7084,12 @@ fn write_single_ref(
69237084 left_ref: i8,
69247085 left_ref1: Option<i8>,
69257086 ) {
6926- REF_HITS[(ref_frame.max(1) - 1) as usize % 7].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
7087+ REF_HITS[(ref_frame.max(1) - 1) as usize % 7]
7088+ .fetch_add(1, std::sync::atomic::Ordering::Relaxed);
69277089 use crate::mvstack::{
6928- ALTREF2_FRAME, ALTREF_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST2_FRAME, LAST3_FRAME,
69297090 single_ref_p1_ctx, single_ref_p2_ctx, single_ref_p3_ctx, single_ref_p4_ctx,
6930- single_ref_p5_ctx, single_ref_p6_ctx,
7091+ single_ref_p5_ctx, single_ref_p6_ctx, ALTREF2_FRAME, ALTREF_FRAME, BWDREF_FRAME,
7092+ GOLDEN_FRAME, LAST2_FRAME, LAST3_FRAME,
69317093 };
69327094 let above = (above_ref > 0).then_some(above_ref);
69337095 let left = (left_ref > 0).then_some(left_ref);
@@ -7071,7 +7233,10 @@ pub(crate) fn take_drl_hits() -> [usize; 4] {
70717233 /// pricer's own offer set is enumerated against this rule by
70727234 /// `crate::encode::tests::every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal`.
70737235 pub(crate) fn signalled_drl_idx(entries: usize, start: usize, target: usize) -> usize {
7074- target.min(start + 2).min(entries.saturating_sub(1)).max(start)
7236+ target
7237+ .min(start + 2)
7238+ .min(entries.saturating_sub(1))
7239+ .max(start)
70757240 }
70767241
70777242 fn write_drl_idx(
@@ -7161,7 +7326,7 @@ fn write_inter_mode(
71617326 enc.symbol(1, &mut cdfs.new_mv[stack.new_mv_ctx]); // not NEWMV
71627327 enc.symbol(1, &mut cdfs.zero_mv[stack.zero_mv_ctx]); // not GLOBALMV
71637328 enc.symbol(1, &mut cdfs.ref_mv[stack.ref_mv_ctx]); // NEARMV
7164- // `RefMvIdx` starts at 1 for NEARMV (spec 5.11.24).
7329+ // `RefMvIdx` starts at 1 for NEARMV (spec 5.11.24).
71657330 let idx = idx.max(1);
71667331 let signalled = write_drl_idx(enc, cdfs, stack, 1, idx);
71677332 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(
73357500 let scan4 = default_scan(TX4);
73367501 // The same four tables again as one array, which is what the per-unit
73377502 // luma writer indexes by transform side.
7338- let all_scans = [
7339- scan32.clone(),
7340- scan16.clone(),
7341- scan8.clone(),
7342- scan4.clone(),
7343- ];
7503+ let all_scans = [scan32.clone(), scan16.clone(), scan8.clone(), scan4.clone()];
73447504 let zero_grids = [
73457505 vec![0i32; TX32 * TX32],
73467506 vec![0i32; TX16 * TX16],
@@ -7431,7 +7591,10 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs(
74317591 // (mi_row, mi_col) and a second one at + hbs (16 mi) along the
74327592 // cut axis, the second only when it is inside the frame -- the
74337593 // search only offers a root wholly inside, so both are.
7434- let base_mi = ((sb_r & !1) as usize * SB_MI as usize, (sb_c & !1) as usize * SB_MI as usize);
7594+ let base_mi = (
7595+ (sb_r & !1) as usize * SB_MI as usize,
7596+ (sb_c & !1) as usize * SB_MI as usize,
7597+ );
74357598 let (w, h) = if horz { (128usize, 64usize) } else { (64, 128) };
74367599 for (i, half) in halves.iter().enumerate() {
74377600 let at_mi = if horz {
@@ -7467,8 +7630,9 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs(
74677630 (sb_r & !1) as usize * SB_MI as usize,
74687631 (sb_c & !1) as usize * SB_MI as usize,
74697632 );
7470- for (((mi_r, mi_c), (w, h)), piece) in
7471- crate::encode::ab128_pieces(symbol, base_mi).iter().zip(pieces)
7633+ for (((mi_r, mi_c), (w, h)), piece) in crate::encode::ab128_pieces(symbol, base_mi)
7634+ .iter()
7635+ .zip(pieces)
74727636 {
74737637 write_inter_block_128_rect(
74747638 &mut enc,
@@ -7532,7 +7696,13 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs(
75327696 + usize::from(neighbours.left_skip[mi_r]);
75337697 enc.symbol(usize::from(block.skip), &mut cdfs.skip[skip_ctx]);
75347698 write_cdef_idx(&mut enc, (mi_r, mi_c), block.skip);
7535- write_delta_q(&mut enc, &mut cdfs, (mi_r, mi_c), !sb128_armed(), block.skip);
7699+ write_delta_q(
7700+ &mut enc,
7701+ &mut cdfs,
7702+ (mi_r, mi_c),
7703+ !sb128_armed(),
7704+ block.skip,
7705+ );
75367706 let ii_ctx = intra_inter_ctx(
75377707 has_above,
75387708 has_left,
@@ -7926,7 +8096,6 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs(
79268096 // caller (r15): the SUB-grid skip/inter arrays
79278097 // are otherwise left stale for the next
79288098 // 16x16 slot.
7929-
79308099 }
79318100 }
79328101 continue;
@@ -7951,111 +8120,137 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs(
79518120
79528121 let mode_for_tx;
79538122 if let Some(info) = block.inter {
7954- write_comp_mode(&mut enc, &mut cdfs, &neighbours, (mi_r, mi_c), (has_above, has_left), info.ref1.is_some());
8123+ write_comp_mode(
8124+ &mut enc,
8125+ &mut cdfs,
8126+ &neighbours,
8127+ (mi_r, mi_c),
8128+ (has_above, has_left),
8129+ info.ref1.is_some(),
8130+ );
79558131 let (mi_row, mi_col) = (r32 as usize * 8, c32 as usize * 8);
79568132 if info.ref1.is_some() {
79578133 let (mv, mv1, is_new_mv) = write_compound_block(
7958- &mut enc, &mut cdfs, &neighbours, &grid, (mi_row, mi_col), (8, 8),
7959- (has_above, has_left), info, (mi_cols as usize, mi_rows as usize),
8134+ &mut enc,
8135+ &mut cdfs,
8136+ &neighbours,
8137+ &grid,
8138+ (mi_row, mi_col),
8139+ (8, 8),
8140+ (has_above, has_left),
8141+ info,
8142+ (mi_cols as usize, mi_rows as usize),
79608143 )?;
79618144 for dr in 0..8 {
79628145 for dc in 0..8 {
7963- grid.set(mi_row + dr, mi_col + dc, MiInfo {
7964- is_inter: true,
7965- ref_frame: info.ref_frame,
7966- ref_frame1: info.ref1.unwrap_or(NO_REF1),
7967- mv1: mv16(mv1),
7968- mv: mv16(mv),
7969- is_new_mv,
7970- size: 8,
7971- size_h: 8,
7972- is_global_mv0: false,
7973- is_global_mv1: false,
7974- });
8146+ grid.set(
8147+ mi_row + dr,
8148+ mi_col + dc,
8149+ MiInfo {
8150+ is_inter: true,
8151+ ref_frame: info.ref_frame,
8152+ ref_frame1: info.ref1.unwrap_or(NO_REF1),
8153+ mv1: mv16(mv1),
8154+ mv: mv16(mv),
8155+ is_new_mv,
8156+ size: 8,
8157+ size_h: 8,
8158+ is_global_mv0: false,
8159+ is_global_mv1: false,
8160+ },
8161+ );
79758162 }
79768163 }
79778164 mode_for_tx = 0;
79788165 } else {
7979- 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]);
8166+ write_single_ref(
8167+ &mut enc,
8168+ &mut cdfs,
8169+ info.ref_frame,
8170+ neighbours.above_ref[mi_c],
8171+ neighbours.above_ref1[mi_c],
8172+ neighbours.left_ref[mi_r],
8173+ neighbours.left_ref1[mi_r],
8174+ );
79808175
7981- let stack = find_mv_stack(
7982- &grid,
7983- mi_row,
7984- mi_col,
7985- 8,
7986- 8,
7987- info.ref_frame,
7988- mi_cols as usize,
7989- mi_rows as usize,
7990- );
8176+ let stack = find_mv_stack(
8177+ &grid,
8178+ mi_row,
8179+ mi_col,
8180+ 8,
8181+ 8,
8182+ info.ref_frame,
8183+ mi_cols as usize,
8184+ mi_rows as usize,
8185+ );
79918186
7992- let (mv, is_new_mv) = write_inter_mode(&mut enc, &mut cdfs, info, &stack)?;
7993- if crate::msac::symtrace::dir().is_some() {
7994- crate::msac::symtrace::note(&format!(
7995- " MODE mi=({mi_r},{mi_c}) mode={:?} idx={} mv={mv:?} info_mv={:?}",
7996- info.mode, info.ref_mv_idx, info.mv
7997- ));
7998- }
7999- grid.set(
8000- mi_row,
8001- mi_col,
8002- MiInfo {
8003- is_inter: true,
8004- ref_frame: info.ref_frame,
8005- ref_frame1: NO_REF1,
8006- mv1: (0, 0),
8007- mv: mv16(mv),
8008- is_new_mv,
8009- size: 8,
8010- size_h: 8,
8011- is_global_mv0: false,
8012- is_global_mv1: false,
8013- },
8014- );
8015- for dr in 0..8 {
8016- for dc in 0..8 {
8017- if dr == 0 && dc == 0 {
8018- continue;
8187+ let (mv, is_new_mv) = write_inter_mode(&mut enc, &mut cdfs, info, &stack)?;
8188+ if crate::msac::symtrace::dir().is_some() {
8189+ crate::msac::symtrace::note(&format!(
8190+ " MODE mi=({mi_r},{mi_c}) mode={:?} idx={} mv={mv:?} info_mv={:?}",
8191+ info.mode, info.ref_mv_idx, info.mv
8192+ ));
8193+ }
8194+ grid.set(
8195+ mi_row,
8196+ mi_col,
8197+ MiInfo {
8198+ is_inter: true,
8199+ ref_frame: info.ref_frame,
8200+ ref_frame1: NO_REF1,
8201+ mv1: (0, 0),
8202+ mv: mv16(mv),
8203+ is_new_mv,
8204+ size: 8,
8205+ size_h: 8,
8206+ is_global_mv0: false,
8207+ is_global_mv1: false,
8208+ },
8209+ );
8210+ for dr in 0..8 {
8211+ for dc in 0..8 {
8212+ if dr == 0 && dc == 0 {
8213+ continue;
8214+ }
8215+ grid.set(
8216+ mi_row + dr,
8217+ mi_col + dc,
8218+ MiInfo {
8219+ is_inter: true,
8220+ ref_frame: info.ref_frame,
8221+ ref_frame1: NO_REF1,
8222+ mv1: (0, 0),
8223+ mv: mv16(mv),
8224+ is_new_mv,
8225+ size: 8,
8226+ size_h: 8,
8227+ is_global_mv0: false,
8228+ is_global_mv1: false,
8229+ },
8230+ );
80198231 }
8020- grid.set(
8021- mi_row + dr,
8022- mi_col + dc,
8023- MiInfo {
8024- is_inter: true,
8025- ref_frame: info.ref_frame,
8026- ref_frame1: NO_REF1,
8027- mv1: (0, 0),
8028- mv: mv16(mv),
8029- is_new_mv,
8030- size: 8,
8031- size_h: 8,
8032- is_global_mv0: false,
8033- is_global_mv1: false,
8034- },
8035- );
80368232 }
8037- }
8038- write_motion_mode(
8039- &mut enc,
8040- &mut cdfs,
8041- &grid,
8042- (mi_row, mi_col),
8043- (8, 8),
8044- (BLOCK, BLOCK),
8045- (mi_cols as usize, mi_rows as usize),
8046- info.ref_frame,
8047- block.motion_mode,
8048- )?;
8049- mode_for_tx = 0;
8233+ write_motion_mode(
8234+ &mut enc,
8235+ &mut cdfs,
8236+ &grid,
8237+ (mi_row, mi_col),
8238+ (8, 8),
8239+ (BLOCK, BLOCK),
8240+ (mi_cols as usize, mi_rows as usize),
8241+ info.ref_frame,
8242+ block.motion_mode,
8243+ )?;
8244+ mode_for_tx = 0;
80508245 }
80518246 } else {
80528247 let mode = usize::from(block.mode);
80538248 enc.symbol(mode, &mut cdfs.y_mode[SIZE_GROUP_32]);
80548249 if (V_PRED..=D67_PRED).contains(&mode) {
80558250 enc.symbol(
8056- (ANGLE_DELTA_ZERO as i32 + i32::from(block.angle_delta_y)) as usize,
8057- &mut cdfs.angle_delta[mode - V_PRED],
8058- );
8251+ (ANGLE_DELTA_ZERO as i32 + i32::from(block.angle_delta_y)) as usize,
8252+ &mut cdfs.angle_delta[mode - V_PRED],
8253+ );
80598254 }
80608255 let uv_mode = usize::from(block.uv_mode);
80618256 enc.symbol(uv_mode, &mut cdfs.uv_mode_cfl[mode]);
@@ -8208,7 +8403,8 @@ fn write_inter_frame_leaf(
82088403
82098404 let (r, c) = at;
82108405 let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI));
8211- let skip_ctx = usize::from(neighbours.above_skip[mi_c]) + usize::from(neighbours.left_skip[mi_r]);
8406+ let skip_ctx =
8407+ usize::from(neighbours.above_skip[mi_c]) + usize::from(neighbours.left_skip[mi_r]);
82128408 enc.symbol(usize::from(block.skip), &mut cdfs.skip[skip_ctx]);
82138409 write_cdef_idx(enc, (mi_r, mi_c), block.skip);
82148410 write_delta_q(enc, cdfs, (mi_r, mi_c), false, block.skip);
@@ -8221,87 +8417,113 @@ fn write_inter_frame_leaf(
82218417
82228418 let mode_for_tx;
82238419 if let Some(info) = block.inter {
8224- write_comp_mode(enc, cdfs, neighbours, (mi_r, mi_c), (has_above, has_left), info.ref1.is_some());
8420+ write_comp_mode(
8421+ enc,
8422+ cdfs,
8423+ neighbours,
8424+ (mi_r, mi_c),
8425+ (has_above, has_left),
8426+ info.ref1.is_some(),
8427+ );
82258428 let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize);
82268429 if info.ref1.is_some() {
82278430 let n = SUB_MI as usize;
82288431 let (mv, mv1, is_new_mv) = write_compound_block(
8229- enc, cdfs, neighbours, grid, (mi_row, mi_col), (n, n),
8230- (has_above, has_left), info, (mi_cols as usize, mi_rows as usize),
8432+ enc,
8433+ cdfs,
8434+ neighbours,
8435+ grid,
8436+ (mi_row, mi_col),
8437+ (n, n),
8438+ (has_above, has_left),
8439+ info,
8440+ (mi_cols as usize, mi_rows as usize),
82318441 )?;
82328442 for dr in 0..n {
82338443 for dc in 0..n {
8234- grid.set(mi_row + dr, mi_col + dc, MiInfo {
8235- is_inter: true,
8236- ref_frame: info.ref_frame,
8237- ref_frame1: info.ref1.unwrap_or(NO_REF1),
8238- mv1: mv16(mv1),
8239- mv: mv16(mv),
8240- is_new_mv,
8241- size: n as u8,
8242- size_h: n as u8,
8243- is_global_mv0: false,
8244- is_global_mv1: false,
8245- });
8444+ grid.set(
8445+ mi_row + dr,
8446+ mi_col + dc,
8447+ MiInfo {
8448+ is_inter: true,
8449+ ref_frame: info.ref_frame,
8450+ ref_frame1: info.ref1.unwrap_or(NO_REF1),
8451+ mv1: mv16(mv1),
8452+ mv: mv16(mv),
8453+ is_new_mv,
8454+ size: n as u8,
8455+ size_h: n as u8,
8456+ is_global_mv0: false,
8457+ is_global_mv1: false,
8458+ },
8459+ );
82468460 }
82478461 }
82488462 mode_for_tx = 0;
82498463 } else {
8250- 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]);
8464+ write_single_ref(
8465+ enc,
8466+ cdfs,
8467+ info.ref_frame,
8468+ neighbours.above_ref[mi_c],
8469+ neighbours.above_ref1[mi_c],
8470+ neighbours.left_ref[mi_r],
8471+ neighbours.left_ref1[mi_r],
8472+ );
82518473
8252- let stack = find_mv_stack(
8253- grid,
8254- mi_row,
8255- mi_col,
8256- SUB_MI as usize,
8257- SUB_MI as usize,
8258- info.ref_frame,
8259- mi_cols as usize,
8260- mi_rows as usize,
8261- );
8474+ let stack = find_mv_stack(
8475+ grid,
8476+ mi_row,
8477+ mi_col,
8478+ SUB_MI as usize,
8479+ SUB_MI as usize,
8480+ info.ref_frame,
8481+ mi_cols as usize,
8482+ mi_rows as usize,
8483+ );
82628484
8263- let (mv, is_new_mv) = write_inter_mode(enc, cdfs, info, &stack)?;
8264- for dr in 0..SUB_MI as usize {
8265- for dc in 0..SUB_MI as usize {
8266- grid.set(
8267- mi_row + dr,
8268- mi_col + dc,
8269- MiInfo {
8270- is_inter: true,
8271- ref_frame: info.ref_frame,
8272- ref_frame1: NO_REF1,
8273- mv1: (0, 0),
8274- mv: mv16(mv),
8275- is_new_mv,
8276- size: SUB_MI as usize as u8,
8277- size_h: SUB_MI as usize as u8,
8278- is_global_mv0: false,
8279- is_global_mv1: false,
8280- },
8281- );
8485+ let (mv, is_new_mv) = write_inter_mode(enc, cdfs, info, &stack)?;
8486+ for dr in 0..SUB_MI as usize {
8487+ for dc in 0..SUB_MI as usize {
8488+ grid.set(
8489+ mi_row + dr,
8490+ mi_col + dc,
8491+ MiInfo {
8492+ is_inter: true,
8493+ ref_frame: info.ref_frame,
8494+ ref_frame1: NO_REF1,
8495+ mv1: (0, 0),
8496+ mv: mv16(mv),
8497+ is_new_mv,
8498+ size: SUB_MI as usize as u8,
8499+ size_h: SUB_MI as usize as u8,
8500+ is_global_mv0: false,
8501+ is_global_mv1: false,
8502+ },
8503+ );
8504+ }
82828505 }
8283- }
8284- write_motion_mode(
8285- enc,
8286- cdfs,
8287- grid,
8288- (mi_row, mi_col),
8289- (SUB_MI as usize, SUB_MI as usize),
8290- (SUB, SUB),
8291- (mi_cols as usize, mi_rows as usize),
8292- info.ref_frame,
8293- block.motion_mode,
8294- )?;
8295- mode_for_tx = 0;
8506+ write_motion_mode(
8507+ enc,
8508+ cdfs,
8509+ grid,
8510+ (mi_row, mi_col),
8511+ (SUB_MI as usize, SUB_MI as usize),
8512+ (SUB, SUB),
8513+ (mi_cols as usize, mi_rows as usize),
8514+ info.ref_frame,
8515+ block.motion_mode,
8516+ )?;
8517+ mode_for_tx = 0;
82968518 }
82978519 } else {
82988520 let mode = usize::from(block.mode);
82998521 enc.symbol(mode, &mut cdfs.y_mode[SIZE_GROUP_16]);
83008522 if (V_PRED..=D67_PRED).contains(&mode) {
83018523 enc.symbol(
8302- (ANGLE_DELTA_ZERO as i32 + i32::from(block.angle_delta_y)) as usize,
8303- &mut cdfs.angle_delta[mode - V_PRED],
8304- );
8524+ (ANGLE_DELTA_ZERO as i32 + i32::from(block.angle_delta_y)) as usize,
8525+ &mut cdfs.angle_delta[mode - V_PRED],
8526+ );
83058527 }
83068528 let uv_mode = usize::from(block.uv_mode);
83078529 enc.symbol(uv_mode, &mut cdfs.uv_mode_cfl[mode]);
@@ -8380,7 +8602,16 @@ fn write_inter_frame_leaf(
83808602 ];
83818603 if split {
83828604 write_luma_tus(
8383- enc, cdfs, neighbours, at_mi, SUB, tx, &grids[0], mode_for_tx, all_scans, is_inter,
8605+ enc,
8606+ cdfs,
8607+ neighbours,
8608+ at_mi,
8609+ SUB,
8610+ tx,
8611+ &grids[0],
8612+ mode_for_tx,
8613+ all_scans,
8614+ is_inter,
83848615 &block.luma_tx_types,
83858616 )?;
83868617 }
@@ -8467,93 +8698,122 @@ fn write_inter_frame_leaf8(
84678698 write_cdef_idx(enc, leaf_mi, block.skip);
84688699 write_delta_q(enc, cdfs, leaf_mi, false, block.skip);
84698700
8470- let (has_above, has_left) = (neighbours.has_above(leaf_mi.0), neighbours.has_left(leaf_mi.1));
8701+ let (has_above, has_left) = (
8702+ neighbours.has_above(leaf_mi.0),
8703+ neighbours.has_left(leaf_mi.1),
8704+ );
84718705 let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter);
84728706 let is_inter = block.inter.is_some();
84738707 enc.symbol(usize::from(is_inter), &mut cdfs.intra_inter[ii_ctx]);
84748708
84758709 let mode_for_tx;
84768710 if let Some(info) = block.inter {
8477- write_comp_mode(enc, cdfs, neighbours, leaf_mi, (has_above, has_left), info.ref1.is_some());
8711+ write_comp_mode(
8712+ enc,
8713+ cdfs,
8714+ neighbours,
8715+ leaf_mi,
8716+ (has_above, has_left),
8717+ info.ref1.is_some(),
8718+ );
84788719 let (mi_row, mi_col) = leaf_mi;
84798720 if info.ref1.is_some() {
84808721 let (mv, mv1, is_new_mv) = write_compound_block(
8481- enc, cdfs, neighbours, grid, (mi_row, mi_col), (2, 2),
8482- (has_above, has_left), info, (mi_cols as usize, mi_rows as usize),
8722+ enc,
8723+ cdfs,
8724+ neighbours,
8725+ grid,
8726+ (mi_row, mi_col),
8727+ (2, 2),
8728+ (has_above, has_left),
8729+ info,
8730+ (mi_cols as usize, mi_rows as usize),
84838731 )?;
84848732 for dr in 0..2 {
84858733 for dc in 0..2 {
8486- grid.set(mi_row + dr, mi_col + dc, MiInfo {
8487- is_inter: true,
8488- ref_frame: info.ref_frame,
8489- ref_frame1: info.ref1.unwrap_or(NO_REF1),
8490- mv1: mv16(mv1),
8491- mv: mv16(mv),
8492- is_new_mv,
8493- size: 2,
8494- size_h: 2,
8495- is_global_mv0: false,
8496- is_global_mv1: false,
8497- });
8734+ grid.set(
8735+ mi_row + dr,
8736+ mi_col + dc,
8737+ MiInfo {
8738+ is_inter: true,
8739+ ref_frame: info.ref_frame,
8740+ ref_frame1: info.ref1.unwrap_or(NO_REF1),
8741+ mv1: mv16(mv1),
8742+ mv: mv16(mv),
8743+ is_new_mv,
8744+ size: 2,
8745+ size_h: 2,
8746+ is_global_mv0: false,
8747+ is_global_mv1: false,
8748+ },
8749+ );
84988750 }
84998751 }
85008752 mode_for_tx = 0;
85018753 } else {
8502- 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]);
8754+ write_single_ref(
8755+ enc,
8756+ cdfs,
8757+ info.ref_frame,
8758+ neighbours.above_ref[leaf_mi.1],
8759+ neighbours.above_ref1[leaf_mi.1],
8760+ neighbours.left_ref[leaf_mi.0],
8761+ neighbours.left_ref1[leaf_mi.0],
8762+ );
85038763
8504- let stack = find_mv_stack(
8505- grid,
8506- mi_row,
8507- mi_col,
8508- 2,
8509- 2,
8510- info.ref_frame,
8511- mi_cols as usize,
8512- mi_rows as usize,
8513- );
8764+ let stack = find_mv_stack(
8765+ grid,
8766+ mi_row,
8767+ mi_col,
8768+ 2,
8769+ 2,
8770+ info.ref_frame,
8771+ mi_cols as usize,
8772+ mi_rows as usize,
8773+ );
85148774
8515- let (mv, is_new_mv) = write_inter_mode(enc, cdfs, info, &stack)?;
8516- for dr in 0..2 {
8517- for dc in 0..2 {
8518- grid.set(
8519- mi_row + dr,
8520- mi_col + dc,
8521- MiInfo {
8522- is_inter: true,
8523- ref_frame: info.ref_frame,
8524- ref_frame1: NO_REF1,
8525- mv1: (0, 0),
8526- mv: mv16(mv),
8527- is_new_mv,
8528- size: 2,
8529- size_h: 2,
8530- is_global_mv0: false,
8531- is_global_mv1: false,
8532- },
8533- );
8775+ let (mv, is_new_mv) = write_inter_mode(enc, cdfs, info, &stack)?;
8776+ for dr in 0..2 {
8777+ for dc in 0..2 {
8778+ grid.set(
8779+ mi_row + dr,
8780+ mi_col + dc,
8781+ MiInfo {
8782+ is_inter: true,
8783+ ref_frame: info.ref_frame,
8784+ ref_frame1: NO_REF1,
8785+ mv1: (0, 0),
8786+ mv: mv16(mv),
8787+ is_new_mv,
8788+ size: 2,
8789+ size_h: 2,
8790+ is_global_mv0: false,
8791+ is_global_mv1: false,
8792+ },
8793+ );
8794+ }
85348795 }
8535- }
8536- write_motion_mode(
8537- enc,
8538- cdfs,
8539- grid,
8540- (mi_row, mi_col),
8541- (2, 2),
8542- (8, 8),
8543- (mi_cols as usize, mi_rows as usize),
8544- info.ref_frame,
8545- block.motion_mode,
8546- )?;
8547- mode_for_tx = 0;
8796+ write_motion_mode(
8797+ enc,
8798+ cdfs,
8799+ grid,
8800+ (mi_row, mi_col),
8801+ (2, 2),
8802+ (8, 8),
8803+ (mi_cols as usize, mi_rows as usize),
8804+ info.ref_frame,
8805+ block.motion_mode,
8806+ )?;
8807+ mode_for_tx = 0;
85488808 }
85498809 } else {
85508810 let mode = usize::from(block.mode);
85518811 enc.symbol(mode, &mut cdfs.y_mode[SIZE_GROUP_8]);
85528812 if (V_PRED..=D67_PRED).contains(&mode) {
85538813 enc.symbol(
8554- (ANGLE_DELTA_ZERO as i32 + i32::from(block.angle_delta_y)) as usize,
8555- &mut cdfs.angle_delta[mode - V_PRED],
8556- );
8814+ (ANGLE_DELTA_ZERO as i32 + i32::from(block.angle_delta_y)) as usize,
8815+ &mut cdfs.angle_delta[mode - V_PRED],
8816+ );
85578817 }
85588818 let uv_mode = usize::from(block.uv_mode);
85598819 enc.symbol(uv_mode, &mut cdfs.uv_mode_cfl[mode]);
@@ -8606,7 +8866,7 @@ fn write_inter_frame_leaf8(
86068866 } else {
86078867 [TxbSet::Luma8, TxbSet::Chroma4, TxbSet::Chroma4]
86088868 };
8609- let tx = if tx_select {
8869+ let tx = if tx_select {
86108870 write_tx_syntax_inter(
86118871 enc,
86128872 cdfs,
@@ -8628,7 +8888,13 @@ fn write_inter_frame_leaf8(
86288888 vec![0i32; TX4 * TX4],
86298889 ];
86308890 neighbours.record_mi(leaf_mi, 8, &zero_grids);
8631- neighbours.record_inter_mi(leaf_mi, 8, block.skip, block.inter.is_some(), block_ref(block));
8891+ neighbours.record_inter_mi(
8892+ leaf_mi,
8893+ 8,
8894+ block.skip,
8895+ block.inter.is_some(),
8896+ block_ref(block),
8897+ );
86328898 record_block_compound(neighbours, leaf_mi, 8, block);
86338899 } else {
86348900 let grids = [
@@ -8638,7 +8904,16 @@ fn write_inter_frame_leaf8(
86388904 ];
86398905 if split {
86408906 write_luma_tus(
8641- enc, cdfs, neighbours, leaf_mi, 8, tx, &grids[0], mode_for_tx, all_scans, is_inter,
8907+ enc,
8908+ cdfs,
8909+ neighbours,
8910+ leaf_mi,
8911+ 8,
8912+ tx,
8913+ &grids[0],
8914+ mode_for_tx,
8915+ all_scans,
8916+ is_inter,
86428917 &block.luma_tx_types,
86438918 )?;
86448919 }
@@ -8666,13 +8941,13 @@ mod tests {
86668941 use super::*;
86678942 use crate::frame::frame_obu;
86688943 use crate::obu::temporal_delimiter;
8944+ use crate::probe::run_with_stdin;
86698945 use crate::sequence::sequence_header_obu;
86708946 use ec_av1_syntax::sequence::SequenceHeader;
86718947 use ec_av1_syntax::{
8672- FrameHeader, FrameType, LoopFilterParams, PRIMARY_REF_NONE, QuantizationParams, TileInfo,
8673- TxMode,
8948+ FrameHeader, FrameType, LoopFilterParams, QuantizationParams, TileInfo, TxMode,
8949+ PRIMARY_REF_NONE,
86748950 };
8675- use std::io::Write;
86768951 use std::process::{Command, Stdio};
86778952
86788953 /// A 64x64 sequence with every tool this writer does not code turned off:
@@ -8763,29 +9038,12 @@ mod tests {
87639038
87649039 /// Decodes an AV1 OBU stream with ffmpeg and hands back the planes.
87659040 fn ffmpeg_decode(stream: &[u8], w: usize, h: usize) -> Vec<u8> {
8766- let mut child = Command::new("ffmpeg")
8767- .args([
9041+ let out = run_with_stdin(
9042+ Command::new("ffmpeg").args([
87689043 "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-",
8769- ])
8770- .stdin(Stdio::piped())
8771- .stdout(Stdio::piped())
8772- .stderr(Stdio::piped())
8773- .spawn()
8774- .expect("ffmpeg failed to start");
8775- // lane-t900 r10: the stream goes down stdin on ITS OWN THREAD. Writing
8776- // it inline deadlocks the moment ffmpeg's stdout pipe buffer (64 KiB)
8777- // fills before the last input byte is written -- which is exactly what
8778- // a 1.1 MB fixture decoding to 150 MB of raw 10-bit frames does
8779- // (measured: 45 min, both processes at 0% CPU). A write error here is
8780- // swallowed on purpose: ffmpeg's own exit status and stderr, asserted
8781- // below, are the real diagnosis.
8782- let mut stdin = child.stdin.take().expect("ffmpeg stdin");
8783- let payload = stream.to_vec();
8784- let writer = std::thread::spawn(move || {
8785- let _ = stdin.write_all(&payload);
8786- });
8787- let out = child.wait_with_output().expect("ffmpeg failed to run");
8788- writer.join().expect("ffmpeg stdin writer thread");
9044+ ]),
9045+ stream,
9046+ );
87899047 assert!(
87909048 out.status.success(),
87919049 "ffmpeg refused the stream: {}",
@@ -10327,7 +10585,11 @@ mod tests {
1032710585 .map(|&v| {
1032810586 let m = f64::from(v).abs() + 0.5;
1032910587 let l = if m < 1.0 { 0 } else { m.floor() as i32 };
10330- if v < 0.0 { -l } else { l }
10588+ if v < 0.0 {
10589+ -l
10590+ } else {
10591+ l
10592+ }
1033110593 })
1033210594 .collect();
1033310595 let before = levels.clone();
@@ -10340,18 +10602,40 @@ mod tests {
1034010602 .zip(&scaled)
1034110603 .enumerate()
1034210604 .map(|(i, (&l, &s))| {
10343- (if i == 0 { dc_weight } else { 1.0 })
10344- * (f64::from(s) - f64::from(l)).powi(2)
10605+ (if i == 0 { dc_weight } else { 1.0 }) * (f64::from(s) - f64::from(l)).powi(2)
1034510606 })
1034610607 .sum();
1034710608 d + lambda * coeff_bits(grid, set, crate::decode::q_ctx_of(q), 0, 0)
1034810609 };
10349- let bits = rdoq(&mut levels, &scaled, side, q, set, 0, 0, lambda, TxType::DctDct);
10350- assert_eq!(bits, coeff_bits(&levels, set, crate::decode::q_ctx_of(q), 0, 0));
10351- assert!(cost(&levels) <= cost(&before), "{:?} vs {:?}", cost(&levels), cost(&before));
10610+ let bits = rdoq(
10611+ &mut levels,
10612+ &scaled,
10613+ side,
10614+ q,
10615+ set,
10616+ 0,
10617+ 0,
10618+ lambda,
10619+ TxType::DctDct,
10620+ );
10621+ assert_eq!(
10622+ bits,
10623+ coeff_bits(&levels, set, crate::decode::q_ctx_of(q), 0, 0)
10624+ );
10625+ assert!(
10626+ cost(&levels) <= cost(&before),
10627+ "{:?} vs {:?}",
10628+ cost(&levels),
10629+ cost(&before)
10630+ );
1035210631 // The tail is what it is for: the last coded position moves earlier.
1035310632 let last = |g: &[i32]| scan_of(side).iter().rposition(|&p| g[usize::from(p)] != 0);
10354- assert!(last(&levels) < last(&before), "eob {:?} -> {:?}", last(&before), last(&levels));
10633+ assert!(
10634+ last(&levels) < last(&before),
10635+ "eob {:?} -> {:?}",
10636+ last(&before),
10637+ last(&levels)
10638+ );
1035510639 // A 64-point transform is priced on its top-left 32x32 corner, and
1035610640 // the pass has to hand back THAT price (the dense path).
1035710641 let (side, set) = (64usize, TxbSet::Luma64);
@@ -10364,14 +10648,31 @@ mod tests {
1036410648 .map(|&v| {
1036510649 let m = f64::from(v).abs() + 0.5;
1036610650 let l = if m < 1.0 { 0 } else { m.floor() as i32 };
10367- if v < 0.0 { -l } else { l }
10651+ if v < 0.0 {
10652+ -l
10653+ } else {
10654+ l
10655+ }
1036810656 })
1036910657 .collect();
10370- let bits = rdoq(&mut levels, &scaled, side, q, set, 0, 0, lambda, TxType::DctDct);
10658+ let bits = rdoq(
10659+ &mut levels,
10660+ &scaled,
10661+ side,
10662+ q,
10663+ set,
10664+ 0,
10665+ 0,
10666+ lambda,
10667+ TxType::DctDct,
10668+ );
1037110669 let corner: Vec<i32> = (0..32)
1037210670 .flat_map(|row| levels[row * side..][..32].to_vec())
1037310671 .collect();
10374- assert_eq!(bits, coeff_bits(&corner, set, crate::decode::q_ctx_of(q), 0, 0));
10672+ assert_eq!(
10673+ bits,
10674+ coeff_bits(&corner, set, crate::decode::q_ctx_of(q), 0, 0)
10675+ );
1037510676 }
1037610677
1037710678 #[test]
@@ -10848,7 +11149,11 @@ mod tests {
1084811149 (d << 3) | (fr << 1) | 1
1084911150 };
1085011151 let mag = mv_class_base(class) + local as i32 + 1;
10851- if sign == 1 { -mag } else { mag }
11152+ if sign == 1 {
11153+ -mag
11154+ } else {
11155+ mag
11156+ }
1085211157 }
1085311158
1085411159 /// Decodes one superblock a [`sb_coeff_inter_frame_tile`] payload wrote,
lanes/av1pipedrain.report.mdadded+112 -0
@@ -0,0 +1,112 @@
1+# lane-av1-pipedrain — test-infra pipe-drain fix
2+
3+Branch `lane-av1-pipedrain` @ main `5f5aef9a`. Worktree
4+`/home/user/Documents/Code/Rust/edith_codecs-av1pipe`. No push.
5+
6+## Defect
7+
8+Every `a_real_aomenc_*` gate spawned aomenc with piped stdin/stdout/stderr and
9+wrote the y4m down stdin INLINE before `wait_with_output()`. When aomenc's
10+stdout pipe buffer (~64 KiB) filled before the last input byte was written,
11+the child blocked in write(2) on stdout and the test blocked in `write_all`
12+on stdin — both at 0% CPU until the harness timeout, or EPIPE flakes when the
13+child was killed. Hit four times across lanes today; the class was already
14+diagnosed once for the ffmpeg helpers (lane-t900 r10: 45-minute hang on a
15+1.1 MB fixture; lane-gaterecipe r1: one 384x256 cq-10 encode hung 40 minutes
16+until a hand-rolled feeder thread fixed that ONE aomenc site).
17+
18+## Census (before)
19+
20+`crates/ec-av1/src`, piped-stdin spawn sites (child stdin piped AND fed):
21+
22+| file | aomenc gates | ffmpeg helpers | total |
23+|-----------|-------------:|---------------:|------:|
24+| stream.rs | 139 | 4 | 143 |
25+| decode.rs | — | 2 | 2 |
26+| encode.rs | — | 2 | 2 |
27+| tile.rs | — | 1 | 1 |
28+| **all** | **139** | **9** | **148** |
29+
30+Of the 148: **138 were dangerous** (inline `write_all` before
31+`wait_with_output`, incl. compact `.unwrap()`/`.ok()` shapes and
32+EPIPE-tolerant `.or_else(BrokenPipe)` shapes — the latter only help when the
33+child EXITED, not when it is alive and blocked) and **10 were safe** but
34+duplicated the feeder-thread pattern (9 ffmpeg decode helpers + 1 aomenc
35+gate, the lane-gaterecipe r1 site). The intrabc merge-close "~150 sites, one
36+already feeder-thread-fixed" = these 148.
37+
38+Untouched by design: 2 stream.rs aomenc spawns fed by FILE
39+(`stdin(Stdio::null())`, `.arg(&y4m_path)`) and every ffprobe/ffmpeg
40+`.output()` / `.status()` site (nothing feeds stdin, so no cycle exists).
41+
42+## Fix
43+
44+One shared helper, `crates/ec-av1/src/probe.rs` (`#[cfg(test)]`):
45+
46+```rust
47+pub(crate) fn run_with_stdin(cmd: &mut Command, input: &[u8]) -> std::process::Output
48+```
49+
50+- sets piped stdin/stdout/stderr, spawns the child;
51+- a writer thread owns stdin (`let _ = stdin.write_all(&payload)` — EPIPE is
52+ swallowed on purpose: the child's exit status and stderr, asserted by the
53+ caller, are the real diagnosis; aomenc refusing early can never panic the
54+ feeder);
55+- the parent runs `wait_with_output()`, which drains stdout AND stderr
56+ concurrently — no pipe can fill against a blocked writer, so multi-MB y4m
57+ inputs always meet a reader;
58+- joins the writer thread, returns `Output`.
59+
60+Every one of the 148 sites now calls it (the ffmpeg decode helpers keep their
61+pixel-parsing tails; callers keep their own `assert!(out.status.success(), …
62+{stderr})` messages). Migration: a bounded, validating Python codemod
63+(transformed 136 stream.rs sites; runaway guards — bounded window, exactly
64+one `write_all`, no `assert!`/`decode_stream`/`Command::new` in the replaced
65+span — left anything non-uniform for hand edits) + 12 hand migrations
66+(feeder-thread site, `let out = { … }` bare-expression block, affine-oracle
67+`Command::new(affine_aomenc_path())` site, `.ok()`/`unwrap` compact shapes,
68+`let enc` binding, 9 ffmpeg helpers).
69+
70+Grep proof (final tree): zero `stdin.take()`/child-stdin `write_all` outside
71+`probe.rs`; `wait_with_output` appears only inside the helper and at the two
72+file-fed spawns. Zero `stdin(Stdio::piped())` outside `probe.rs`.
73+
74+Diff: 5 source files, +1065/−2492 (net −1427 lines of duplicated boilerplate
75+removed); whitespace-insensitive +871/−2298.
76+
77+## Verification
78+
79+Toolchain: aomenc oracle `~/.cache/aom-oracle/build/aomenc` + affine oracle
80+`~/.cache/aom-affine/build/aomenc`, system ffmpeg; release test binary;
81+`EC_AV1_REQUIRE_AOMENC=1 EC_AV1_REQUIRE_FFMPEG=1` (skips fail the run).
82+
83+- `cargo check -p ec-av1 --all-targets`: **0 warnings**.
84+- Stress, previously-flaked gate
85+ `a_real_aomenc_inter_sequence_with_intra_16x4_strips_in_1to4_partitions_\
86+decodes_pixel_exact` × 20 sequential runs:
87+ **20/20 pass, 0 fail** (28.3 min wall; each run does the full multi-attempt
88+ encode sweep + pixel compares).
89+- Scoped battery, 50 gates through the migrated paths (intrabc unblock set
90+ 13, rect14 16x4/4x16 set 5, loss64/lossless set 4, real-aomenc family
91+ 25 incl. tile-rows/columns, tile-group OBUs, sb128 family, obmc, wedge,
92+ comp-mode, temporal-MV, cdef, filter-intra, 1D-tx rect, palette-on-rect,
93+ 10-bit; plus 3 tile::tests ffmpeg-decode helpers):
94+ **50/50 green** (two initially misnamed entries re-checked by exact name,
95+ both pass; census sweeps among them ran their full 20–40 attempt loops).
96+
97+## Notes / follow-ups
98+
99+- The repo is NOT rustfmt-clean under default `rustfmt --edition 2024`
100+ (pristine stream.rs shows a 7776-line diff), so no wholesale fmt pass was
101+ applied. One honest exception: tile.rs carries ~600 lines of rustfmt reflow
102+ around the ffmpeg_decode helper migration (raw churn 1051 lines vs 663
103+ whitespace-insensitive; 388 lines differ by whitespace alone) — format-only
104+ churn, semantically inert, not a defect. Any future
105+ "just cargo fmt it" would churn ~40k-line files wholesale; decide that
106+ separately, never inside a content lane.
107+- `ec-av1-syntax` and `examples/` spawn no aomenc/ffmpeg on piped stdin;
108+ other ec-* crates are out of this lane's scope but share none of these
109+ helpers.
110+- The helper names the generic spawn/reap failures ("encoder failed to
111+ start/run"); per-gate diagnosis stays in each gate's own
112+ `assert!(status.success(), …)` on stderr, unchanged.