ec-av1: drain aomenc/ffmpeg stdin via one shared runner (148 piped spawn sites)
Browse files at this commit54cadae02b84586500f847bba4f96bc7bcc2b657Parent: cad19f86 changed files +979 -2298
- crates/ec-av1/src/decode.rs +11 -51
- crates/ec-av1/src/encode.rs +11 -45
- crates/ec-av1/src/probe.rs +64 -5
- crates/ec-av1/src/stream.rs +301 -2018
- crates/ec-av1/src/tile.rs +484 -179
- lanes/av1pipedrain.report.md +108 -0
crates/ec-av1/src/decode.rsmodified+11 -51
| @@ -40943,7 +40943,7 @@ mod tests { | |||
| 40943 | // duplicating `crate::encode`'s own `#[cfg(test)]` helpers of the same | 40943 | // duplicating `crate::encode`'s own `#[cfg(test)]` helpers of the same |
| 40944 | // name (that module is another lane's territory this round, and the | 40944 | // name (that module is another lane's territory this round, and the |
| 40945 | // helpers are `#[cfg(test)]`-private to it). | 40945 | // helpers are `#[cfg(test)]`-private to it). |
| 40946 | - use std::io::Write; | 40946 | + use crate::probe::run_with_stdin; |
| 40947 | use std::process::{Command, Stdio}; | 40947 | use std::process::{Command, Stdio}; |
| 40948 | 40948 | ||
| 40949 | /// Whether ffmpeg is on PATH. Absence normally SKIPs, but | 40949 | /// Whether ffmpeg is on PATH. Absence normally SKIPs, but |
| @@ -40972,32 +40972,12 @@ mod tests { | |||
| 40972 | /// Decodes one AV1 OBU stream with ffmpeg and hands back its one 4:2:0 | 40972 | /// Decodes one AV1 OBU stream with ffmpeg and hands back its one 4:2:0 |
| 40973 | /// frame's planes, at ffmpeg's own (coded, block-padded) size. | 40973 | /// frame's planes, at ffmpeg's own (coded, block-padded) size. |
| 40974 | fn ffmpeg_decode(stream: &[u8], width: usize, height: usize) -> Picture { | 40974 | fn ffmpeg_decode(stream: &[u8], width: usize, height: usize) -> Picture { |
| 40975 | - let mut child = Command::new("ffmpeg") | 40975 | + let out = run_with_stdin( |
| 40976 | - .args([ | 40976 | + Command::new("ffmpeg").args([ |
| 40977 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", | 40977 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", |
| 40978 | - ]) | 40978 | + ]), |
| 40979 | - .stdin(Stdio::piped()) | 40979 | + stream, |
| 40980 | - .stdout(Stdio::piped()) | 40980 | + ); |
| 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"); | ||
| 41001 | assert!( | 40981 | assert!( |
| 41002 | out.status.success(), | 40982 | out.status.success(), |
| 41003 | "ffmpeg refused the stream: {}", | 40983 | "ffmpeg refused the stream: {}", |
| @@ -41025,32 +41005,12 @@ mod tests { | |||
| 41025 | height: usize, | 41005 | height: usize, |
| 41026 | frames: usize, | 41006 | frames: usize, |
| 41027 | ) -> Vec<Picture> { | 41007 | ) -> Vec<Picture> { |
| 41028 | - let mut child = Command::new("ffmpeg") | 41008 | + let out = run_with_stdin( |
| 41029 | - .args([ | 41009 | + Command::new("ffmpeg").args([ |
| 41030 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", | 41010 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", |
| 41031 | - ]) | 41011 | + ]), |
| 41032 | - .stdin(Stdio::piped()) | 41012 | + stream, |
| 41033 | - .stdout(Stdio::piped()) | 41013 | + ); |
| 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"); | ||
| 41054 | assert!( | 41014 | assert!( |
| 41055 | out.status.success(), | 41015 | out.status.success(), |
| 41056 | "ffmpeg refused the stream: {}", | 41016 | "ffmpeg refused the stream: {}", |
crates/ec-av1/src/encode.rsmodified+11 -45
| @@ -15101,7 +15101,7 @@ mod tests { | |||
| 15101 | } | 15101 | } |
| 15102 | use super::*; | 15102 | use super::*; |
| 15103 | use crate::intra::{D45_PRED, D135_PRED, H_PRED, KEY_FRAME_MODES, NON_DIRECTIONAL, V_PRED}; | 15103 | 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; |
| 15105 | use std::process::{Command, Stdio}; | 15105 | use std::process::{Command, Stdio}; |
| 15106 | 15106 | ||
| 15107 | /// Every rectangular shape this decoder codes, at every position a block | 15107 | /// Every rectangular shape this decoder codes, at every position a block |
| @@ -15260,29 +15260,12 @@ mod tests { | |||
| 15260 | 15260 | ||
| 15261 | /// Decodes an AV1 OBU stream with ffmpeg and hands back the three planes. | 15261 | /// Decodes an AV1 OBU stream with ffmpeg and hands back the three planes. |
| 15262 | fn ffmpeg_decode(stream: &[u8], width: usize, height: usize) -> Picture { | 15262 | fn ffmpeg_decode(stream: &[u8], width: usize, height: usize) -> Picture { |
| 15263 | - let mut child = Command::new("ffmpeg") | 15263 | + let out = run_with_stdin( |
| 15264 | - .args([ | 15264 | + Command::new("ffmpeg").args([ |
| 15265 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", | 15265 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", |
| 15266 | - ]) | 15266 | + ]), |
| 15267 | - .stdin(Stdio::piped()) | 15267 | + stream, |
| 15268 | - .stdout(Stdio::piped()) | 15268 | + ); |
| 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"); | ||
| 15286 | assert!( | 15269 | assert!( |
| 15287 | out.status.success(), | 15270 | out.status.success(), |
| 15288 | "ffmpeg refused the stream: {}", | 15271 | "ffmpeg refused the stream: {}", |
| @@ -17231,29 +17214,12 @@ mod tests { | |||
| 17231 | height: usize, | 17214 | height: usize, |
| 17232 | frames: usize, | 17215 | frames: usize, |
| 17233 | ) -> Vec<Picture> { | 17216 | ) -> Vec<Picture> { |
| 17234 | - let mut child = Command::new("ffmpeg") | 17217 | + let out = run_with_stdin( |
| 17235 | - .args([ | 17218 | + Command::new("ffmpeg").args([ |
| 17236 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", | 17219 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", |
| 17237 | - ]) | 17220 | + ]), |
| 17238 | - .stdin(Stdio::piped()) | 17221 | + stream, |
| 17239 | - .stdout(Stdio::piped()) | 17222 | + ); |
| 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"); | ||
| 17257 | assert!( | 17223 | assert!( |
| 17258 | out.status.success(), | 17224 | out.status.success(), |
| 17259 | "ffmpeg refused the stream: {}", | 17225 | "ffmpeg refused the stream: {}", |
crates/ec-av1/src/probe.rsmodified+64 -5
| @@ -22,7 +22,10 @@ pub fn dims(clip: &str) -> Option<(usize, usize)> { | |||
| 22 | .ok()?; | 22 | .ok()?; |
| 23 | let text = String::from_utf8_lossy(&out.stdout); | 23 | let text = String::from_utf8_lossy(&out.stdout); |
| 24 | let mut f = text.trim().split(','); | 24 | 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 | + )) | ||
| 26 | } | 29 | } |
| 27 | 30 | ||
| 28 | /// The native BD gate's window on `clip`: a whole number of 128-wide | 31 | /// 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) { | |||
| 41 | let (nw, nh) = dims(clip).expect("ffprobe gave no size"); | 44 | let (nw, nh) = dims(clip).expect("ffprobe gave no size"); |
| 42 | let cw = nw.min(1920) / 128 * 128; | 45 | let cw = nw.min(1920) / 128 * 128; |
| 43 | let ch = nh.min(1024) / 128 * 128; | 46 | 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 | + ); | ||
| 45 | let (x, y) = ((nw - cw) / 2 & !1, (nh - ch) / 2 & !1); | 51 | let (x, y) = ((nw - cw) / 2 & !1, (nh - ch) / 2 & !1); |
| 46 | (format!("crop={cw}:{ch}:{x}:{y}"), cw, ch) | 52 | (format!("crop={cw}:{ch}:{x}:{y}"), cw, ch) |
| 47 | } | 53 | } |
| @@ -67,10 +73,18 @@ pub fn source( | |||
| 67 | .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"]) | 73 | .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"]) |
| 68 | .output() | 74 | .output() |
| 69 | .expect("ffmpeg failed to run"); | 75 | .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 | + ); | ||
| 71 | let (luma, chroma) = (width * height, width * height / 4); | 81 | let (luma, chroma) = (width * height, width * height / 4); |
| 72 | let frame_len = luma + 2 * chroma; | 82 | 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 | + ); | ||
| 74 | (0..frames) | 88 | (0..frames) |
| 75 | .map(|i| { | 89 | .map(|i| { |
| 76 | let b = &out.stdout[i * frame_len..][..frame_len]; | 90 | let b = &out.stdout[i * frame_len..][..frame_len]; |
| @@ -78,9 +92,54 @@ pub fn source( | |||
| 78 | width, | 92 | width, |
| 79 | height, | 93 | height, |
| 80 | y: b[..luma].iter().map(|&v| u16::from(v)).collect(), | 94 | 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(), | ||
| 82 | v: b[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), | 99 | v: b[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), |
| 83 | } | 100 | } |
| 84 | }) | 101 | }) |
| 85 | .collect() | 102 | .collect() |
| 86 | } | 103 | } |
| 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 { | |||
| 2489 | args.push(limit); | 2489 | args.push(limit); |
| 2490 | args.extend(extra.iter().map(|s| (*s).to_owned())); | 2490 | args.extend(extra.iter().map(|s| (*s).to_owned())); |
| 2491 | args.extend(["--obu".to_owned(), "-o".to_owned(), "-".to_owned(), "-".to_owned()]); | 2491 | args.extend(["--obu".to_owned(), "-o".to_owned(), "-".to_owned(), "-".to_owned()]); |
| 2492 | - let mut child = Command::new(aomenc_path()) | 2492 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 2493 | - .args(&args) | 2493 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 2501 | assert!(out.status.success(), "aomenc refused {args:?}: {}", String::from_utf8_lossy(&out.stderr)); | 2494 | assert!(out.status.success(), "aomenc refused {args:?}: {}", String::from_utf8_lossy(&out.stderr)); |
| 2502 | let stream = out.stdout; | 2495 | let stream = out.stdout; |
| 2503 | let result = match decode_stream(&stream) { | 2496 | let result = match decode_stream(&stream) { |
| @@ -2578,15 +2571,8 @@ pub(crate) mod tests { | |||
| 2578 | .collect(); | 2571 | .collect(); |
| 2579 | args.insert(1, limit); | 2572 | args.insert(1, limit); |
| 2580 | args.extend(extra.iter().map(|s| (*s).to_owned())); | 2573 | args.extend(extra.iter().map(|s| (*s).to_owned())); |
| 2581 | - let mut child = Command::new(aomenc_path()) | 2574 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 2582 | - .args(&args) | 2575 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 2590 | assert!( | 2576 | assert!( |
| 2591 | out.status.success(), | 2577 | out.status.success(), |
| 2592 | "{NAME}: aomenc refused {args:?}: {}", | 2578 | "{NAME}: aomenc refused {args:?}: {}", |
| @@ -2614,20 +2600,10 @@ pub(crate) mod tests { | |||
| 2614 | mixed_arms += 1; | 2600 | mixed_arms += 1; |
| 2615 | // (3) libaom accepts it: ffmpeg's own libaom decoder produces the | 2601 | // (3) libaom accepts it: ffmpeg's own libaom decoder produces the |
| 2616 | // stream without an error. | 2602 | // stream without an error. |
| 2617 | - let mut ff = Command::new("ffmpeg") | 2603 | + let out = run_with_stdin( |
| 2618 | - .args(["-v", "error", "-f", "obu", "-i", "-", "-f", "null", "-"]) | 2604 | + Command::new("ffmpeg").args(["-v", "error", "-f", "obu", "-i", "-", "-f", "null", "-"]), |
| 2619 | - .stdin(Stdio::piped()) | 2605 | + &stream, |
| 2620 | - .stdout(Stdio::null()) | 2606 | + ); |
| 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"); | ||
| 2631 | assert!( | 2607 | assert!( |
| 2632 | out.status.success(), | 2608 | out.status.success(), |
| 2633 | "{NAME}: ffmpeg refused a stream with {mixed} mixed-frame(s): {}", | 2609 | "{NAME}: ffmpeg refused a stream with {mixed} mixed-frame(s): {}", |
| @@ -3228,7 +3204,7 @@ pub(crate) mod tests { | |||
| 3228 | let input_depth_arg = format!("--input-bit-depth={bit_depth}"); | 3204 | let input_depth_arg = format!("--input-bit-depth={bit_depth}"); |
| 3229 | let cq_arg = format!("--cq-level={cq}"); | 3205 | let cq_arg = format!("--cq-level={cq}"); |
| 3230 | let limit_arg = format!("--limit={frames}"); | 3206 | let limit_arg = format!("--limit={frames}"); |
| 3231 | - let mut child = Command::new(aomenc_path()) | 3207 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 3232 | .args([ | 3208 | .args([ |
| 3233 | "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, | 3209 | "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, |
| 3234 | // cpu-used >= 1 keeps libaom on 64x64 superblocks at these | 3210 | // cpu-used >= 1 keeps libaom on 64x64 superblocks at these |
| @@ -3255,19 +3231,7 @@ pub(crate) mod tests { | |||
| 3255 | "--enable-paeth-intra=0", "--enable-filter-intra=0", | 3231 | "--enable-paeth-intra=0", "--enable-filter-intra=0", |
| 3256 | "--enable-tx-size-search=0", | 3232 | "--enable-tx-size-search=0", |
| 3257 | "--obu", "-o", "-", "-", | 3233 | "--obu", "-o", "-", "-", |
| 3258 | - ]) | 3234 | + ]), &y4m.stdout); |
| 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"); | ||
| 3271 | assert!( | 3235 | assert!( |
| 3272 | out.status.success(), | 3236 | out.status.success(), |
| 3273 | "aomenc refused: {}", | 3237 | "aomenc refused: {}", |
| @@ -3426,20 +3390,13 @@ pub(crate) mod tests { | |||
| 3426 | .output() | 3390 | .output() |
| 3427 | .expect("ffmpeg failed to run"); | 3391 | .expect("ffmpeg failed to run"); |
| 3428 | assert!(y4m.status.success(), "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr)); | 3392 | 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()) |
| 3430 | .args([ | 3394 | .args([ |
| 3431 | "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32", | 3395 | "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32", |
| 3432 | "--cpu-used=0", "--sb-size=128", "--min-partition-size=16", | 3396 | "--cpu-used=0", "--sb-size=128", "--min-partition-size=16", |
| 3433 | "--kf-max-dist=0", "--limit=1", | 3397 | "--kf-max-dist=0", "--limit=1", |
| 3434 | "--threads=1", "--row-mt=0", "--obu", "-o", "-", "-", | 3398 | "--threads=1", "--row-mt=0", "--obu", "-o", "-", "-", |
| 3435 | - ]) | 3399 | + ]), &y4m.stdout); |
| 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"); | ||
| 3443 | assert!(out.status.success(), "aomenc refused: {}", String::from_utf8_lossy(&out.stderr)); | 3400 | assert!(out.status.success(), "aomenc refused: {}", String::from_utf8_lossy(&out.stderr)); |
| 3444 | let stream = out.stdout; | 3401 | let stream = out.stdout; |
| 3445 | 3402 | ||
| @@ -3625,7 +3582,7 @@ pub(crate) mod tests { | |||
| 3625 | assert!(format!("{err}").contains("sink says stop"), "{err}"); | 3582 | assert!(format!("{err}").contains("sink says stop"), "{err}"); |
| 3626 | } | 3583 | } |
| 3627 | 3584 | ||
| 3628 | - use std::io::Write; | 3585 | + use crate::probe::run_with_stdin; |
| 3629 | use std::process::{Command, Stdio}; | 3586 | use std::process::{Command, Stdio}; |
| 3630 | 3587 | ||
| 3631 | /// Firing-detection gates (single-ref envelope, temporal-MV, `comp_mode`, | 3588 | /// Firing-detection gates (single-ref envelope, temporal-MV, `comp_mode`, |
| @@ -3699,32 +3656,12 @@ pub(crate) mod tests { | |||
| 3699 | height: usize, | 3656 | height: usize, |
| 3700 | frames: usize, | 3657 | frames: usize, |
| 3701 | ) -> Vec<Pic> { | 3658 | ) -> Vec<Pic> { |
| 3702 | - let mut child = Command::new("ffmpeg") | 3659 | + let out = run_with_stdin( |
| 3703 | - .args([ | 3660 | + Command::new("ffmpeg").args([ |
| 3704 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", | 3661 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", |
| 3705 | - ]) | 3662 | + ]), |
| 3706 | - .stdin(Stdio::piped()) | 3663 | + stream, |
| 3707 | - .stdout(Stdio::piped()) | 3664 | + ); |
| 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"); | ||
| 3728 | assert!( | 3665 | assert!( |
| 3729 | out.status.success(), | 3666 | out.status.success(), |
| 3730 | "ffmpeg refused the stream: {}", | 3667 | "ffmpeg refused the stream: {}", |
| @@ -3754,33 +3691,20 @@ pub(crate) mod tests { | |||
| 3754 | 3691 | ||
| 3755 | /// As [`ffmpeg_decode_sequence`], for a MONOCHROME stream: one 8-bit luma | 3692 | /// As [`ffmpeg_decode_sequence`], for a MONOCHROME stream: one 8-bit luma |
| 3756 | /// plane per frame, exactly what `ffmpeg -pix_fmt gray -f rawvideo` writes | 3693 | /// 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 | 3694 | + /// (lane-av1mono). Fed through [`run_with_stdin`] for the reason its doc |
| 3758 | - /// helper documents. | 3695 | + /// records. |
| 3759 | fn ffmpeg_decode_gray_sequence( | 3696 | fn ffmpeg_decode_gray_sequence( |
| 3760 | stream: &[u8], | 3697 | stream: &[u8], |
| 3761 | width: usize, | 3698 | width: usize, |
| 3762 | height: usize, | 3699 | height: usize, |
| 3763 | frames: usize, | 3700 | frames: usize, |
| 3764 | ) -> Vec<u8> { | 3701 | ) -> Vec<u8> { |
| 3765 | - let mut child = Command::new("ffmpeg") | 3702 | + let out = run_with_stdin( |
| 3766 | - .args([ | 3703 | + Command::new("ffmpeg").args([ |
| 3767 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "gray", "-", | 3704 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "gray", "-", |
| 3768 | - ]) | 3705 | + ]), |
| 3769 | - .stdin(Stdio::piped()) | 3706 | + stream, |
| 3770 | - .stdout(Stdio::piped()) | 3707 | + ); |
| 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"); | ||
| 3784 | assert!( | 3708 | assert!( |
| 3785 | out.status.success(), | 3709 | out.status.success(), |
| 3786 | "ffmpeg refused the monochrome stream: {}", | 3710 | "ffmpeg refused the monochrome stream: {}", |
| @@ -3806,33 +3730,13 @@ pub(crate) mod tests { | |||
| 3806 | height: usize, | 3730 | height: usize, |
| 3807 | frames: usize, | 3731 | frames: usize, |
| 3808 | ) -> Vec<Pic> { | 3732 | ) -> Vec<Pic> { |
| 3809 | - let mut child = Command::new("ffmpeg") | 3733 | + let out = run_with_stdin( |
| 3810 | - .args([ | 3734 | + Command::new("ffmpeg").args([ |
| 3811 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", | 3735 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", |
| 3812 | "yuv420p10le", "-", | 3736 | "yuv420p10le", "-", |
| 3813 | - ]) | 3737 | + ]), |
| 3814 | - .stdin(Stdio::piped()) | 3738 | + stream, |
| 3815 | - .stdout(Stdio::piped()) | 3739 | + ); |
| 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"); | ||
| 3836 | assert!( | 3740 | assert!( |
| 3837 | out.status.success(), | 3741 | out.status.success(), |
| 3838 | "ffmpeg refused the stream: {}", | 3742 | "ffmpeg refused the stream: {}", |
| @@ -5041,7 +4945,7 @@ pub(crate) mod tests { | |||
| 5041 | .expect("ffmpeg failed to run"); | 4945 | .expect("ffmpeg failed to run"); |
| 5042 | assert!(out.status.success(), "ffmpeg failed for testsrc2 {width}x{height}"); | 4946 | assert!(out.status.success(), "ffmpeg failed for testsrc2 {width}x{height}"); |
| 5043 | let y4m = out.stdout; | 4947 | let y4m = out.stdout; |
| 5044 | - let mut child = Command::new(aomenc_path()) | 4948 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 5045 | .args(["--codec=av1", "--bit-depth=8", "--input-bit-depth=8"]) | 4949 | .args(["--codec=av1", "--bit-depth=8", "--input-bit-depth=8"]) |
| 5046 | .args([ | 4950 | .args([ |
| 5047 | "--passes=1", | 4951 | "--passes=1", |
| @@ -5056,19 +4960,7 @@ pub(crate) mod tests { | |||
| 5056 | "--enable-1to4-partitions=1", | 4960 | "--enable-1to4-partitions=1", |
| 5057 | ]) | 4961 | ]) |
| 5058 | .args(extra) | 4962 | .args(extra) |
| 5059 | - .args(["--obu", "-o", "-", "-"]) | 4963 | + .args(["--obu", "-o", "-", "-"]), &y4m); |
| 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"); | ||
| 5072 | assert!(out.status.success(), "aomenc failed: {}", String::from_utf8_lossy(&out.stderr)); | 4964 | assert!(out.status.success(), "aomenc failed: {}", String::from_utf8_lossy(&out.stderr)); |
| 5073 | out.stdout | 4965 | out.stdout |
| 5074 | } | 4966 | } |
| @@ -5616,20 +5508,8 @@ pub(crate) mod tests { | |||
| 5616 | } | 5508 | } |
| 5617 | let mut arm: Vec<&str> = vec!["--arnr-maxframes=0"]; | 5509 | let mut arm: Vec<&str> = vec!["--arnr-maxframes=0"]; |
| 5618 | arm.extend_from_slice(args); | 5510 | arm.extend_from_slice(args); |
| 5619 | - let mut child = Command::new(aomenc_path()) | 5511 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 5620 | - .args(&arm) | 5512 | + .args(&arm), &y4m); |
| 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"); | ||
| 5633 | assert!( | 5513 | assert!( |
| 5634 | out.status.success(), | 5514 | out.status.success(), |
| 5635 | "{name} HIDDEN-ARM: aomenc refused its own recipe plus --arnr-maxframes=0: {}", | 5515 | "{name} HIDDEN-ARM: aomenc refused its own recipe plus --arnr-maxframes=0: {}", |
| @@ -5700,7 +5580,7 @@ pub(crate) mod tests { | |||
| 5700 | ); | 5580 | ); |
| 5701 | let depth_arg = format!("--bit-depth={bit_depth}"); | 5581 | let depth_arg = format!("--bit-depth={bit_depth}"); |
| 5702 | let input_depth_arg = format!("--input-bit-depth={bit_depth}"); | 5582 | 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()) |
| 5704 | .args([ | 5584 | .args([ |
| 5705 | // lane-defon r1: the repo's only gate that decodes hidden | 5585 | // lane-defon r1: the repo's only gate that decodes hidden |
| 5706 | // frames is also the only place a FORWARD KEYFRAME can be | 5586 | // frames is also the only place a FORWARD KEYFRAME can be |
| @@ -5760,19 +5640,7 @@ pub(crate) mod tests { | |||
| 5760 | "-o", | 5640 | "-o", |
| 5761 | "-", | 5641 | "-", |
| 5762 | "-", | 5642 | "-", |
| 5763 | - ]) | 5643 | + ]), &y4m.stdout); |
| 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"); | ||
| 5776 | assert!( | 5644 | assert!( |
| 5777 | out.status.success(), | 5645 | out.status.success(), |
| 5778 | "{NAME}: aomenc refused the {bit_depth}-bit fixture: {}", | 5646 | "{NAME}: aomenc refused the {bit_depth}-bit fixture: {}", |
| @@ -5867,7 +5735,7 @@ pub(crate) mod tests { | |||
| 5867 | "ffmpeg refused to generate the y4m fixture: {}", | 5735 | "ffmpeg refused to generate the y4m fixture: {}", |
| 5868 | String::from_utf8_lossy(&y4m.stderr) | 5736 | String::from_utf8_lossy(&y4m.stderr) |
| 5869 | ); | 5737 | ); |
| 5870 | - let mut child = Command::new(aomenc_path()) | 5738 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 5871 | .args([ | 5739 | .args([ |
| 5872 | "--codec=av1", | 5740 | "--codec=av1", |
| 5873 | "--passes=1", | 5741 | "--passes=1", |
| @@ -5897,19 +5765,7 @@ pub(crate) mod tests { | |||
| 5897 | "-o", | 5765 | "-o", |
| 5898 | "-", | 5766 | "-", |
| 5899 | "-", | 5767 | "-", |
| 5900 | - ]) | 5768 | + ]), &y4m.stdout); |
| 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"); | ||
| 5913 | assert!( | 5769 | assert!( |
| 5914 | out.status.success(), | 5770 | out.status.success(), |
| 5915 | "aomenc refused the fixture: {}", | 5771 | "aomenc refused the fixture: {}", |
| @@ -6021,7 +5877,7 @@ pub(crate) mod tests { | |||
| 6021 | "smptebars must render byte-identical across two runs" | 5877 | "smptebars must render byte-identical across two runs" |
| 6022 | ); | 5878 | ); |
| 6023 | let y4m = y4m_a; | 5879 | let y4m = y4m_a; |
| 6024 | - let mut child = Command::new(aomenc_path()) | 5880 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 6025 | .args([ | 5881 | .args([ |
| 6026 | "--codec=av1", | 5882 | "--codec=av1", |
| 6027 | "--passes=1", | 5883 | "--passes=1", |
| @@ -6053,19 +5909,7 @@ pub(crate) mod tests { | |||
| 6053 | "-o", | 5909 | "-o", |
| 6054 | "-", | 5910 | "-", |
| 6055 | "-", | 5911 | "-", |
| 6056 | - ]) | 5912 | + ]), &y4m); |
| 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"); | ||
| 6069 | assert!( | 5913 | assert!( |
| 6070 | out.status.success(), | 5914 | out.status.success(), |
| 6071 | "aomenc refused the fixture: {}", | 5915 | "aomenc refused the fixture: {}", |
| @@ -6156,7 +6000,7 @@ pub(crate) mod tests { | |||
| 6156 | let y4m = y4m_a; | 6000 | let y4m = y4m_a; |
| 6157 | let depth_arg = format!("--bit-depth={depth}"); | 6001 | let depth_arg = format!("--bit-depth={depth}"); |
| 6158 | let input_depth_arg = format!("--input-bit-depth={depth}"); | 6002 | 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()) |
| 6160 | .args([ | 6004 | .args([ |
| 6161 | "--codec=av1", | 6005 | "--codec=av1", |
| 6162 | "--passes=1", | 6006 | "--passes=1", |
| @@ -6189,19 +6033,7 @@ pub(crate) mod tests { | |||
| 6189 | // Per-arm overrides go AFTER the base recipe: aomenc keeps the | 6033 | // Per-arm overrides go AFTER the base recipe: aomenc keeps the |
| 6190 | // LAST occurrence of a repeated flag. | 6034 | // LAST occurrence of a repeated flag. |
| 6191 | .args([&depth_arg, &input_depth_arg]) | 6035 | .args([&depth_arg, &input_depth_arg]) |
| 6192 | - .args(["--obu", "-o", "-", "-"]) | 6036 | + .args(["--obu", "-o", "-", "-"]), &y4m); |
| 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"); | ||
| 6205 | assert!( | 6037 | assert!( |
| 6206 | out.status.success(), | 6038 | out.status.success(), |
| 6207 | "{NAME}: aomenc refused the {depth}-bit fixture: {}", | 6039 | "{NAME}: aomenc refused the {depth}-bit fixture: {}", |
| @@ -6302,7 +6134,7 @@ pub(crate) mod tests { | |||
| 6302 | let cq_arg = format!("--cq-level={cq}"); | 6134 | let cq_arg = format!("--cq-level={cq}"); |
| 6303 | let txs_arg = format!("--enable-tx-size-search={txs}"); | 6135 | let txs_arg = format!("--enable-tx-size-search={txs}"); |
| 6304 | let tiles_arg = format!("--tile-columns={tiles}"); | 6136 | 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()) |
| 6306 | .args([ | 6138 | .args([ |
| 6307 | "--codec=av1", | 6139 | "--codec=av1", |
| 6308 | "--passes=1", | 6140 | "--passes=1", |
| @@ -6324,23 +6156,7 @@ pub(crate) mod tests { | |||
| 6324 | // aomenc keeps the LAST occurrence of a repeated flag, | 6156 | // aomenc keeps the LAST occurrence of a repeated flag, |
| 6325 | // so per-arm overrides go after the base recipe. | 6157 | // so per-arm overrides go after the base recipe. |
| 6326 | .args([&depth_arg, &input_depth_arg, &cq_arg, &txs_arg, &tiles_arg]) | 6158 | .args([&depth_arg, &input_depth_arg, &cq_arg, &txs_arg, &tiles_arg]) |
| 6327 | - .args(["--obu", "-o", "-", "-"]) | 6159 | + .args(["--obu", "-o", "-", "-"]), &y4m); |
| 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"); | ||
| 6344 | assert!( | 6160 | assert!( |
| 6345 | out.status.success(), | 6161 | out.status.success(), |
| 6346 | "{NAME}: aomenc refused {arm}: {}", | 6162 | "{NAME}: aomenc refused {arm}: {}", |
| @@ -6553,7 +6369,7 @@ pub(crate) mod tests { | |||
| 6553 | let y4m_b = render(); | 6369 | let y4m_b = render(); |
| 6554 | assert_eq!(y4m_a, y4m_b, "{NAME}: {arm} must render byte-identical across two runs"); | 6370 | assert_eq!(y4m_a, y4m_b, "{NAME}: {arm} must render byte-identical across two runs"); |
| 6555 | let y4m = y4m_a; | 6371 | let y4m = y4m_a; |
| 6556 | - let mut child = Command::new(aomenc_path()) | 6372 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 6557 | .args([ | 6373 | .args([ |
| 6558 | "--codec=av1", | 6374 | "--codec=av1", |
| 6559 | "--bit-depth=8", | 6375 | "--bit-depth=8", |
| @@ -6580,23 +6396,7 @@ pub(crate) mod tests { | |||
| 6580 | ]) | 6396 | ]) |
| 6581 | // aomenc keeps the LAST occurrence of a repeated flag. | 6397 | // aomenc keeps the LAST occurrence of a repeated flag. |
| 6582 | .args(*extra) | 6398 | .args(*extra) |
| 6583 | - .args(["--obu", "-o", "-", "-"]) | 6399 | + .args(["--obu", "-o", "-", "-"]), &y4m); |
| 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"); | ||
| 6600 | assert!( | 6400 | assert!( |
| 6601 | out.status.success(), | 6401 | out.status.success(), |
| 6602 | "{NAME}: aomenc refused {arm}: {}", | 6402 | "{NAME}: aomenc refused {arm}: {}", |
| @@ -6752,7 +6552,7 @@ pub(crate) mod tests { | |||
| 6752 | .output() | 6552 | .output() |
| 6753 | .expect("ffmpeg") | 6553 | .expect("ffmpeg") |
| 6754 | .stdout; | 6554 | .stdout; |
| 6755 | - let mut child = Command::new(aomenc_path()) | 6555 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 6756 | .args([ | 6556 | .args([ |
| 6757 | "--codec=av1", "--bit-depth=8", "--input-bit-depth=8", "--passes=1", | 6557 | "--codec=av1", "--bit-depth=8", "--input-bit-depth=8", "--passes=1", |
| 6758 | "--end-usage=q", "--cpu-used=0", "--lag-in-frames=0", "--kf-max-dist=1", | 6558 | "--end-usage=q", "--cpu-used=0", "--lag-in-frames=0", "--kf-max-dist=1", |
| @@ -6761,14 +6561,7 @@ pub(crate) mod tests { | |||
| 6761 | "--min-partition-size=4", "--max-partition-size=64", "--sb-size=64", | 6561 | "--min-partition-size=4", "--max-partition-size=64", "--sb-size=64", |
| 6762 | "--tune-content=screen", "--enable-intrabc=1", "--cq-level=60", | 6562 | "--tune-content=screen", "--enable-intrabc=1", "--cq-level=60", |
| 6763 | "--enable-palette=1", "--enable-tx-size-search=0", "--obu", "-o", "-", "-", | 6563 | "--enable-palette=1", "--enable-tx-size-search=0", "--obu", "-o", "-", "-", |
| 6764 | - ]) | 6564 | + ]), &y4m); |
| 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"); | ||
| 6772 | assert!(out.status.success(), "{NAME}: aomenc failed"); | 6565 | assert!(out.status.success(), "{NAME}: aomenc failed"); |
| 6773 | crate::decode::reset_rect4_16_pair_hits(); | 6566 | crate::decode::reset_rect4_16_pair_hits(); |
| 6774 | let frames = decode_stream(&out.stdout).unwrap_or_else(|e| panic!("{NAME}: {e}")); | 6567 | let frames = decode_stream(&out.stdout).unwrap_or_else(|e| panic!("{NAME}: {e}")); |
| @@ -6807,20 +6600,13 @@ pub(crate) mod tests { | |||
| 6807 | .output() | 6600 | .output() |
| 6808 | .expect("ffmpeg") | 6601 | .expect("ffmpeg") |
| 6809 | .stdout; | 6602 | .stdout; |
| 6810 | - let mut child = Command::new(aomenc_path()) | 6603 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 6811 | .args([ | 6604 | .args([ |
| 6812 | "--codec=av1", "--cpu-used=0", "--lossless=1", "--sb-size=128", | 6605 | "--codec=av1", "--cpu-used=0", "--lossless=1", "--sb-size=128", |
| 6813 | "--lag-in-frames=0", "--kf-max-dist=1", "--limit=1", "--threads=1", | 6606 | "--lag-in-frames=0", "--kf-max-dist=1", "--limit=1", "--threads=1", |
| 6814 | "--passes=1", "--enable-1to4-partitions=1", "--min-partition-size=4", | 6607 | "--passes=1", "--enable-1to4-partitions=1", "--min-partition-size=4", |
| 6815 | "--enable-rect-partitions=1", "--obu", "-o", "-", "-", | 6608 | "--enable-rect-partitions=1", "--obu", "-o", "-", "-", |
| 6816 | - ]) | 6609 | + ]), &y4m); |
| 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"); | ||
| 6824 | assert!(out.status.success(), "{NAME}: aomenc failed"); | 6610 | assert!(out.status.success(), "{NAME}: aomenc failed"); |
| 6825 | crate::decode::reset_rect4_16_pair_hits(); | 6611 | crate::decode::reset_rect4_16_pair_hits(); |
| 6826 | let frames = decode_stream(&out.stdout).unwrap_or_else(|e| panic!("{NAME}: {e}")); | 6612 | let frames = decode_stream(&out.stdout).unwrap_or_else(|e| panic!("{NAME}: {e}")); |
| @@ -6916,7 +6702,7 @@ pub(crate) mod tests { | |||
| 6916 | out.stdout | 6702 | out.stdout |
| 6917 | }; | 6703 | }; |
| 6918 | let y4m = render(); | 6704 | let y4m = render(); |
| 6919 | - let mut child = Command::new(aomenc_path()) | 6705 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 6920 | .args([ | 6706 | .args([ |
| 6921 | "--codec=av1", | 6707 | "--codec=av1", |
| 6922 | "--bit-depth=8", | 6708 | "--bit-depth=8", |
| @@ -6939,23 +6725,7 @@ pub(crate) mod tests { | |||
| 6939 | ]) | 6725 | ]) |
| 6940 | // aomenc keeps the LAST occurrence of a repeated flag. | 6726 | // aomenc keeps the LAST occurrence of a repeated flag. |
| 6941 | .args(*extra) | 6727 | .args(*extra) |
| 6942 | - .args(["--obu", "-o", "-", "-"]) | 6728 | + .args(["--obu", "-o", "-", "-"]), &y4m); |
| 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"); | ||
| 6959 | assert!( | 6729 | assert!( |
| 6960 | out.status.success(), | 6730 | out.status.success(), |
| 6961 | "{NAME}: aomenc refused {arm}: {}", | 6731 | "{NAME}: aomenc refused {arm}: {}", |
| @@ -7040,7 +6810,7 @@ pub(crate) mod tests { | |||
| 7040 | assert!(out.status.success(), "{NAME}: ffmpeg failed for {arm}"); | 6810 | assert!(out.status.success(), "{NAME}: ffmpeg failed for {arm}"); |
| 7041 | out.stdout | 6811 | out.stdout |
| 7042 | }; | 6812 | }; |
| 7043 | - let mut child = Command::new(aomenc_path()) | 6813 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 7044 | .args([ | 6814 | .args([ |
| 7045 | "--codec=av1", "--bit-depth=8", "--input-bit-depth=8", "--passes=1", | 6815 | "--codec=av1", "--bit-depth=8", "--input-bit-depth=8", "--passes=1", |
| 7046 | "--end-usage=q", "--cpu-used=0", "--lag-in-frames=0", "--kf-max-dist=1", | 6816 | "--end-usage=q", "--cpu-used=0", "--lag-in-frames=0", "--kf-max-dist=1", |
| @@ -7051,23 +6821,7 @@ pub(crate) mod tests { | |||
| 7051 | ]) | 6821 | ]) |
| 7052 | // aomenc keeps the LAST occurrence of a repeated flag. | 6822 | // aomenc keeps the LAST occurrence of a repeated flag. |
| 7053 | .args(*extra) | 6823 | .args(*extra) |
| 7054 | - .args(["--obu", "-o", "-", "-"]) | 6824 | + .args(["--obu", "-o", "-", "-"]), &y4m); |
| 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"); | ||
| 7071 | assert!( | 6825 | assert!( |
| 7072 | out.status.success(), | 6826 | out.status.success(), |
| 7073 | "{NAME}: aomenc refused {arm}: {}", | 6827 | "{NAME}: aomenc refused {arm}: {}", |
| @@ -7181,7 +6935,7 @@ pub(crate) mod tests { | |||
| 7181 | .expect("ffmpeg failed to run"); | 6935 | .expect("ffmpeg failed to run"); |
| 7182 | assert!(out.status.success(), "ffmpeg failed for {src}"); | 6936 | assert!(out.status.success(), "ffmpeg failed for {src}"); |
| 7183 | let y4m = out.stdout; | 6937 | let y4m = out.stdout; |
| 7184 | - let mut child = Command::new(aomenc_path()) | 6938 | + let enc = run_with_stdin(Command::new(aomenc_path()) |
| 7185 | .args(["--codec=av1"]) | 6939 | .args(["--codec=av1"]) |
| 7186 | .args([format!("--bit-depth={depth}"), format!("--input-bit-depth={depth}")]) | 6940 | .args([format!("--bit-depth={depth}"), format!("--input-bit-depth={depth}")]) |
| 7187 | .args([ | 6941 | .args([ |
| @@ -7208,23 +6962,7 @@ pub(crate) mod tests { | |||
| 7208 | &[][..] | 6962 | &[][..] |
| 7209 | }) | 6963 | }) |
| 7210 | .args(extra) | 6964 | .args(extra) |
| 7211 | - .args(["--obu", "-o", "-", "-"]) | 6965 | + .args(["--obu", "-o", "-", "-"]), &y4m); |
| 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"); | ||
| 7228 | assert!( | 6966 | assert!( |
| 7229 | enc.status.success(), | 6967 | enc.status.success(), |
| 7230 | "aomenc refused {src} cq={cq}: {}", | 6968 | "aomenc refused {src} cq={cq}: {}", |
| @@ -7911,7 +7649,7 @@ pub(crate) mod tests { | |||
| 7911 | let y4m = y4m_a; | 7649 | let y4m = y4m_a; |
| 7912 | let depth_arg = format!("--bit-depth={depth}"); | 7650 | let depth_arg = format!("--bit-depth={depth}"); |
| 7913 | let in_depth_arg = format!("--input-bit-depth={depth}"); | 7651 | 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()) |
| 7915 | .args(["--codec=av1"]) | 7653 | .args(["--codec=av1"]) |
| 7916 | .args([&depth_arg, &in_depth_arg]) | 7654 | .args([&depth_arg, &in_depth_arg]) |
| 7917 | .args([ | 7655 | .args([ |
| @@ -7939,25 +7677,7 @@ pub(crate) mod tests { | |||
| 7939 | // shape this gate is about; the 10-bit arms are the | 7677 | // shape this gate is about; the 10-bit arms are the |
| 7940 | // untouched pinned recipe. | 7678 | // untouched pinned recipe. |
| 7941 | .args(if depth == 8 { &["--sb-size=64"][..] } else { &[][..] }) | 7679 | .args(if depth == 8 { &["--sb-size=64"][..] } else { &[][..] }) |
| 7942 | - .args(["--obu", "-o", "-", "-"]) | 7680 | + .args(["--obu", "-o", "-", "-"]), &y4m); |
| 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"); | ||
| 7961 | assert!( | 7681 | assert!( |
| 7962 | out.status.success(), | 7682 | out.status.success(), |
| 7963 | "{NAME}: aomenc refused {arm} at {depth}-bit: {}", | 7683 | "{NAME}: aomenc refused {arm} at {depth}-bit: {}", |
| @@ -8092,7 +7812,7 @@ pub(crate) mod tests { | |||
| 8092 | "ffmpeg failed to render the 10-bit fixture: {}", | 7812 | "ffmpeg failed to render the 10-bit fixture: {}", |
| 8093 | String::from_utf8_lossy(&y4m.stderr) | 7813 | String::from_utf8_lossy(&y4m.stderr) |
| 8094 | ); | 7814 | ); |
| 8095 | - let mut child = Command::new(aomenc_path()) | 7815 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 8096 | .args([ | 7816 | .args([ |
| 8097 | "--codec=av1", | 7817 | "--codec=av1", |
| 8098 | "--passes=1", | 7818 | "--passes=1", |
| @@ -8109,19 +7829,7 @@ pub(crate) mod tests { | |||
| 8109 | "-o", | 7829 | "-o", |
| 8110 | "-", | 7830 | "-", |
| 8111 | "-", | 7831 | "-", |
| 8112 | - ]) | 7832 | + ]), &y4m.stdout); |
| 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"); | ||
| 8125 | assert!( | 7833 | assert!( |
| 8126 | out.status.success(), | 7834 | out.status.success(), |
| 8127 | "aomenc refused the 10-bit fixture: {}", | 7835 | "aomenc refused the 10-bit fixture: {}", |
| @@ -8200,7 +7908,7 @@ pub(crate) mod tests { | |||
| 8200 | "ffmpeg failed to render the 10-bit fixture: {}", | 7908 | "ffmpeg failed to render the 10-bit fixture: {}", |
| 8201 | String::from_utf8_lossy(&y4m.stderr) | 7909 | String::from_utf8_lossy(&y4m.stderr) |
| 8202 | ); | 7910 | ); |
| 8203 | - let mut child = Command::new(aomenc_path()) | 7911 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 8204 | .args([ | 7912 | .args([ |
| 8205 | // lane-defon r1: explicit on-value (aomenc keeps the FIRST | 7913 | // lane-defon r1: explicit on-value (aomenc keeps the FIRST |
| 8206 | // occurrence, so overrides go before the base list). | 7914 | // occurrence, so overrides go before the base list). |
| @@ -8243,19 +7951,7 @@ pub(crate) mod tests { | |||
| 8243 | "-o", | 7951 | "-o", |
| 8244 | "-", | 7952 | "-", |
| 8245 | "-", | 7953 | "-", |
| 8246 | - ]) | 7954 | + ]), &y4m.stdout); |
| 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"); | ||
| 8259 | assert!( | 7955 | assert!( |
| 8260 | out.status.success(), | 7956 | out.status.success(), |
| 8261 | "aomenc refused the 10-bit fixture: {}", | 7957 | "aomenc refused the 10-bit fixture: {}", |
| @@ -9520,20 +9216,8 @@ pub(crate) mod tests { | |||
| 9520 | ]); | 9216 | ]); |
| 9521 | args.extend_from_slice(extra); | 9217 | args.extend_from_slice(extra); |
| 9522 | args.extend_from_slice(&["--obu", "-o", "-", "-"]); | 9218 | args.extend_from_slice(&["--obu", "-o", "-", "-"]); |
| 9523 | - let mut child = Command::new(aomenc_path()) | 9219 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 9524 | - .args(&args) | 9220 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 9537 | assert!( | 9221 | assert!( |
| 9538 | out.status.success(), | 9222 | out.status.success(), |
| 9539 | "{name}: aomenc refused the 10-bit fixture: {}", | 9223 | "{name}: aomenc refused the 10-bit fixture: {}", |
| @@ -9596,7 +9280,7 @@ pub(crate) mod tests { | |||
| 9596 | "testsrc2 must render byte-identical across two runs" | 9280 | "testsrc2 must render byte-identical across two runs" |
| 9597 | ); | 9281 | ); |
| 9598 | let y4m = y4m_a; | 9282 | let y4m = y4m_a; |
| 9599 | - let mut child = Command::new(aomenc_path()) | 9283 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 9600 | .args([ | 9284 | .args([ |
| 9601 | "--codec=av1", | 9285 | "--codec=av1", |
| 9602 | "--passes=1", | 9286 | "--passes=1", |
| @@ -9623,19 +9307,7 @@ pub(crate) mod tests { | |||
| 9623 | "-o", | 9307 | "-o", |
| 9624 | "-", | 9308 | "-", |
| 9625 | "-", | 9309 | "-", |
| 9626 | - ]) | 9310 | + ]), &y4m); |
| 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"); | ||
| 9639 | assert!( | 9311 | assert!( |
| 9640 | out.status.success(), | 9312 | out.status.success(), |
| 9641 | "aomenc refused the fixture: {}", | 9313 | "aomenc refused the fixture: {}", |
| @@ -9716,7 +9388,7 @@ pub(crate) mod tests { | |||
| 9716 | String::from_utf8_lossy(&y4m.stderr) | 9388 | String::from_utf8_lossy(&y4m.stderr) |
| 9717 | ); | 9389 | ); |
| 9718 | let cq_arg = format!("--cq-level={cq}"); | 9390 | 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()) |
| 9720 | .args([ | 9392 | .args([ |
| 9721 | "--codec=av1", | 9393 | "--codec=av1", |
| 9722 | "--passes=1", | 9394 | "--passes=1", |
| @@ -9733,19 +9405,7 @@ pub(crate) mod tests { | |||
| 9733 | "-o", | 9405 | "-o", |
| 9734 | "-", | 9406 | "-", |
| 9735 | "-", | 9407 | "-", |
| 9736 | - ]) | 9408 | + ]), &y4m.stdout); |
| 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"); | ||
| 9749 | assert!( | 9409 | assert!( |
| 9750 | out.status.success(), | 9410 | out.status.success(), |
| 9751 | "aomenc refused the fixture ({source} cq={cq}): {}", | 9411 | "aomenc refused the fixture ({source} cq={cq}): {}", |
| @@ -9884,7 +9544,7 @@ pub(crate) mod tests { | |||
| 9884 | String::from_utf8_lossy(&y4m.stderr) | 9544 | String::from_utf8_lossy(&y4m.stderr) |
| 9885 | ); | 9545 | ); |
| 9886 | let cq_arg = format!("--cq-level={cq}"); | 9546 | 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()) |
| 9888 | .args([ | 9548 | .args([ |
| 9889 | "--codec=av1", | 9549 | "--codec=av1", |
| 9890 | "--passes=1", | 9550 | "--passes=1", |
| @@ -9901,19 +9561,7 @@ pub(crate) mod tests { | |||
| 9901 | "-o", | 9561 | "-o", |
| 9902 | "-", | 9562 | "-", |
| 9903 | "-", | 9563 | "-", |
| 9904 | - ]) | 9564 | + ]), &y4m.stdout); |
| 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"); | ||
| 9917 | assert!( | 9565 | assert!( |
| 9918 | out.status.success(), | 9566 | out.status.success(), |
| 9919 | "aomenc refused the fixture ({source} cq={cq}): {}", | 9567 | "aomenc refused the fixture ({source} cq={cq}): {}", |
| @@ -10041,7 +9689,7 @@ pub(crate) mod tests { | |||
| 10041 | "ffmpeg fixture: {}", | 9689 | "ffmpeg fixture: {}", |
| 10042 | String::from_utf8_lossy(&y4m.stderr) | 9690 | String::from_utf8_lossy(&y4m.stderr) |
| 10043 | ); | 9691 | ); |
| 10044 | - let mut child = Command::new(aomenc_path()) | 9692 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 10045 | .args([ | 9693 | .args([ |
| 10046 | // lane-defon r1: explicit on-value (aomenc keeps the FIRST | 9694 | // lane-defon r1: explicit on-value (aomenc keeps the FIRST |
| 10047 | // occurrence, so overrides go before the base list). | 9695 | // occurrence, so overrides go before the base list). |
| @@ -10073,19 +9721,7 @@ pub(crate) mod tests { | |||
| 10073 | "-o", | 9721 | "-o", |
| 10074 | "-", | 9722 | "-", |
| 10075 | "-", | 9723 | "-", |
| 10076 | - ]) | 9724 | + ]), &y4m.stdout); |
| 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"); | ||
| 10089 | assert!( | 9725 | assert!( |
| 10090 | out.status.success(), | 9726 | out.status.success(), |
| 10091 | "aomenc refused the fixture: {}", | 9727 | "aomenc refused the fixture: {}", |
| @@ -10192,7 +9828,7 @@ pub(crate) mod tests { | |||
| 10192 | "ffmpeg fixture: {}", | 9828 | "ffmpeg fixture: {}", |
| 10193 | String::from_utf8_lossy(&y4m.stderr) | 9829 | String::from_utf8_lossy(&y4m.stderr) |
| 10194 | ); | 9830 | ); |
| 10195 | - let mut child = Command::new(aomenc_path()) | 9831 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 10196 | .args([ | 9832 | .args([ |
| 10197 | "--codec=av1", | 9833 | "--codec=av1", |
| 10198 | "--passes=1", | 9834 | "--passes=1", |
| @@ -10232,19 +9868,7 @@ pub(crate) mod tests { | |||
| 10232 | "-o", | 9868 | "-o", |
| 10233 | "-", | 9869 | "-", |
| 10234 | "-", | 9870 | "-", |
| 10235 | - ]) | 9871 | + ]), &y4m.stdout); |
| 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"); | ||
| 10248 | assert!( | 9872 | assert!( |
| 10249 | out.status.success(), | 9873 | out.status.success(), |
| 10250 | "aomenc refused the fixture: {}", | 9874 | "aomenc refused the fixture: {}", |
| @@ -10432,7 +10056,7 @@ pub(crate) mod tests { | |||
| 10432 | // walks it too, so "no rect strip fired" cannot be an artefact of | 10056 | // walks it too, so "no rect strip fired" cannot be an artefact of |
| 10433 | // one cq. | 10057 | // one cq. |
| 10434 | let cq = format!("--cq-level={}", [30u32, 20, 12][(attempt / 5) as usize % 3]); | 10058 | 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()) |
| 10436 | .args(depth_args) | 10060 | .args(depth_args) |
| 10437 | .arg(&cpu) | 10061 | .arg(&cpu) |
| 10438 | .arg(&cq) | 10062 | .arg(&cq) |
| @@ -10502,19 +10126,7 @@ pub(crate) mod tests { | |||
| 10502 | "-o", | 10126 | "-o", |
| 10503 | "-", | 10127 | "-", |
| 10504 | "-", | 10128 | "-", |
| 10505 | - ]) | 10129 | + ]), &y4m.stdout); |
| 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"); | ||
| 10518 | assert!( | 10130 | assert!( |
| 10519 | out.status.success(), | 10131 | out.status.success(), |
| 10520 | "aomenc refused the fixture: {}", | 10132 | "aomenc refused the fixture: {}", |
| @@ -10720,7 +10332,7 @@ pub(crate) mod tests { | |||
| 10720 | } else { | 10332 | } else { |
| 10721 | &[] | 10333 | &[] |
| 10722 | }; | 10334 | }; |
| 10723 | - let mut child = Command::new(aomenc_path()) | 10335 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 10724 | .args(depth_args) | 10336 | .args(depth_args) |
| 10725 | .args([ | 10337 | .args([ |
| 10726 | // lane-defon r1: explicit on-value (aomenc keeps the FIRST | 10338 | // lane-defon r1: explicit on-value (aomenc keeps the FIRST |
| @@ -10771,19 +10383,7 @@ pub(crate) mod tests { | |||
| 10771 | "-o", | 10383 | "-o", |
| 10772 | "-", | 10384 | "-", |
| 10773 | "-", | 10385 | "-", |
| 10774 | - ]) | 10386 | + ]), &y4m.stdout); |
| 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"); | ||
| 10787 | assert!( | 10387 | assert!( |
| 10788 | out.status.success(), | 10388 | out.status.success(), |
| 10789 | "aomenc refused the fixture: {}", | 10389 | "aomenc refused the fixture: {}", |
| @@ -10979,7 +10579,7 @@ pub(crate) mod tests { | |||
| 10979 | } else { | 10579 | } else { |
| 10980 | &[] | 10580 | &[] |
| 10981 | }; | 10581 | }; |
| 10982 | - let mut child = Command::new(aomenc_path()) | 10582 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 10983 | .args(depth_args) | 10583 | .args(depth_args) |
| 10984 | .args([ | 10584 | .args([ |
| 10985 | "--codec=av1", | 10585 | "--codec=av1", |
| @@ -11035,19 +10635,7 @@ pub(crate) mod tests { | |||
| 11035 | "-o", | 10635 | "-o", |
| 11036 | "-", | 10636 | "-", |
| 11037 | "-", | 10637 | "-", |
| 11038 | - ]) | 10638 | + ]), &y4m.stdout); |
| 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"); | ||
| 11051 | assert!( | 10639 | assert!( |
| 11052 | out.status.success(), | 10640 | out.status.success(), |
| 11053 | "aomenc refused the fixture: {}", | 10641 | "aomenc refused the fixture: {}", |
| @@ -11236,7 +10824,7 @@ pub(crate) mod tests { | |||
| 11236 | } else { | 10824 | } else { |
| 11237 | &[] | 10825 | &[] |
| 11238 | }; | 10826 | }; |
| 11239 | - let mut child = Command::new(aomenc_path()) | 10827 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 11240 | .args(depth_args) | 10828 | .args(depth_args) |
| 11241 | .args([ | 10829 | .args([ |
| 11242 | "--codec=av1", | 10830 | "--codec=av1", |
| @@ -11292,19 +10880,7 @@ pub(crate) mod tests { | |||
| 11292 | "-o", | 10880 | "-o", |
| 11293 | "-", | 10881 | "-", |
| 11294 | "-", | 10882 | "-", |
| 11295 | - ]) | 10883 | + ]), &y4m.stdout); |
| 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"); | ||
| 11308 | assert!( | 10884 | assert!( |
| 11309 | out.status.success(), | 10885 | out.status.success(), |
| 11310 | "aomenc refused the fixture: {}", | 10886 | "aomenc refused the fixture: {}", |
| @@ -11499,7 +11075,7 @@ pub(crate) mod tests { | |||
| 11499 | } else { | 11075 | } else { |
| 11500 | &[] | 11076 | &[] |
| 11501 | }; | 11077 | }; |
| 11502 | - let mut child = Command::new(aomenc_path()) | 11078 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 11503 | .args(depth_args) | 11079 | .args(depth_args) |
| 11504 | .args([ | 11080 | .args([ |
| 11505 | "--codec=av1", | 11081 | "--codec=av1", |
| @@ -11555,19 +11131,7 @@ pub(crate) mod tests { | |||
| 11555 | "-o", | 11131 | "-o", |
| 11556 | "-", | 11132 | "-", |
| 11557 | "-", | 11133 | "-", |
| 11558 | - ]) | 11134 | + ]), &y4m.stdout); |
| 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"); | ||
| 11571 | assert!( | 11135 | assert!( |
| 11572 | out.status.success(), | 11136 | out.status.success(), |
| 11573 | "aomenc refused the fixture: {}", | 11137 | "aomenc refused the fixture: {}", |
| @@ -12280,7 +11844,7 @@ pub(crate) mod tests { | |||
| 12280 | "ffmpeg fixture: {}", | 11844 | "ffmpeg fixture: {}", |
| 12281 | String::from_utf8_lossy(&y4m.stderr) | 11845 | String::from_utf8_lossy(&y4m.stderr) |
| 12282 | ); | 11846 | ); |
| 12283 | - let mut child = Command::new(aomenc_path()) | 11847 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 12284 | .args([ | 11848 | .args([ |
| 12285 | "--codec=av1", | 11849 | "--codec=av1", |
| 12286 | "--passes=1", | 11850 | "--passes=1", |
| @@ -12310,19 +11874,7 @@ pub(crate) mod tests { | |||
| 12310 | "-o", | 11874 | "-o", |
| 12311 | "-", | 11875 | "-", |
| 12312 | "-", | 11876 | "-", |
| 12313 | - ]) | 11877 | + ]), &y4m.stdout); |
| 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"); | ||
| 12326 | assert!( | 11878 | assert!( |
| 12327 | out.status.success(), | 11879 | out.status.success(), |
| 12328 | "aomenc refused the fixture: {}", | 11880 | "aomenc refused the fixture: {}", |
| @@ -12427,7 +11979,7 @@ pub(crate) mod tests { | |||
| 12427 | "ffmpeg fixture: {}", | 11979 | "ffmpeg fixture: {}", |
| 12428 | String::from_utf8_lossy(&y4m.stderr) | 11980 | String::from_utf8_lossy(&y4m.stderr) |
| 12429 | ); | 11981 | ); |
| 12430 | - let mut child = Command::new(aomenc_path()) | 11982 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 12431 | .args([ | 11983 | .args([ |
| 12432 | "--codec=av1", | 11984 | "--codec=av1", |
| 12433 | "--passes=1", | 11985 | "--passes=1", |
| @@ -12455,19 +12007,7 @@ pub(crate) mod tests { | |||
| 12455 | "-o", | 12007 | "-o", |
| 12456 | "-", | 12008 | "-", |
| 12457 | "-", | 12009 | "-", |
| 12458 | - ]) | 12010 | + ]), &y4m.stdout); |
| 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"); | ||
| 12471 | assert!( | 12011 | assert!( |
| 12472 | out.status.success(), | 12012 | out.status.success(), |
| 12473 | "aomenc refused the fixture: {}", | 12013 | "aomenc refused the fixture: {}", |
| @@ -12584,7 +12124,7 @@ pub(crate) mod tests { | |||
| 12584 | "ffmpeg fixture: {}", | 12124 | "ffmpeg fixture: {}", |
| 12585 | String::from_utf8_lossy(&y4m.stderr) | 12125 | String::from_utf8_lossy(&y4m.stderr) |
| 12586 | ); | 12126 | ); |
| 12587 | - let mut child = Command::new(aomenc_path()) | 12127 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 12588 | .args([ | 12128 | .args([ |
| 12589 | // lane-defon r1: explicit on-value (aomenc keeps the FIRST | 12129 | // lane-defon r1: explicit on-value (aomenc keeps the FIRST |
| 12590 | // occurrence, so overrides go before the base list). | 12130 | // occurrence, so overrides go before the base list). |
| @@ -12627,19 +12167,7 @@ pub(crate) mod tests { | |||
| 12627 | "-o", | 12167 | "-o", |
| 12628 | "-", | 12168 | "-", |
| 12629 | "-", | 12169 | "-", |
| 12630 | - ]) | 12170 | + ]), &y4m.stdout); |
| 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"); | ||
| 12643 | assert!( | 12171 | assert!( |
| 12644 | out.status.success(), | 12172 | out.status.success(), |
| 12645 | "aomenc refused the fixture: {}", | 12173 | "aomenc refused the fixture: {}", |
| @@ -12823,20 +12351,8 @@ pub(crate) mod tests { | |||
| 12823 | args.insert(1, "--input-bit-depth=10".to_string()); | 12351 | args.insert(1, "--input-bit-depth=10".to_string()); |
| 12824 | args.insert(1, "--bit-depth=10".to_string()); | 12352 | args.insert(1, "--bit-depth=10".to_string()); |
| 12825 | } | 12353 | } |
| 12826 | - let mut child = Command::new(aomenc_path()) | 12354 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 12827 | - .args(&args) | 12355 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 12840 | assert!( | 12356 | assert!( |
| 12841 | out.status.success(), | 12357 | out.status.success(), |
| 12842 | "{name}: aomenc refused the fixture: {}", | 12358 | "{name}: aomenc refused the fixture: {}", |
| @@ -13160,20 +12676,8 @@ pub(crate) mod tests { | |||
| 13160 | args.insert(1, "--input-bit-depth=10".to_string()); | 12676 | args.insert(1, "--input-bit-depth=10".to_string()); |
| 13161 | args.insert(1, "--bit-depth=10".to_string()); | 12677 | args.insert(1, "--bit-depth=10".to_string()); |
| 13162 | } | 12678 | } |
| 13163 | - let mut child = Command::new(aomenc_path()) | 12679 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 13164 | - .args(&args) | 12680 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 13177 | assert!( | 12681 | assert!( |
| 13178 | out.status.success(), | 12682 | out.status.success(), |
| 13179 | "{name}: aomenc refused the fixture: {}", | 12683 | "{name}: aomenc refused the fixture: {}", |
| @@ -13346,20 +12850,8 @@ pub(crate) mod tests { | |||
| 13346 | "--max-partition-size=64", | 12850 | "--max-partition-size=64", |
| 13347 | "--obu", "-o", "-", "-", | 12851 | "--obu", "-o", "-", "-", |
| 13348 | ]; | 12852 | ]; |
| 13349 | - let mut child = Command::new(aomenc_path()) | 12853 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 13350 | - .args(&args) | 12854 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 13363 | assert!( | 12855 | assert!( |
| 13364 | out.status.success(), | 12856 | out.status.success(), |
| 13365 | "aomenc refused the fixture: {}", | 12857 | "aomenc refused the fixture: {}", |
| @@ -13606,28 +13098,7 @@ pub(crate) mod tests { | |||
| 13606 | min_part, "--max-partition-size=64", | 13098 | min_part, "--max-partition-size=64", |
| 13607 | "--obu", "-o", "-", "-", | 13099 | "--obu", "-o", "-", "-", |
| 13608 | ]; | 13100 | ]; |
| 13609 | - let mut child = Command::new(aomenc_path()) | 13101 | + let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout); |
| 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"); | ||
| 13631 | assert!( | 13102 | assert!( |
| 13632 | out.status.success(), | 13103 | out.status.success(), |
| 13633 | "aomenc refused the fixture: {}", | 13104 | "aomenc refused the fixture: {}", |
| @@ -13850,20 +13321,8 @@ pub(crate) mod tests { | |||
| 13850 | "--min-partition-size=8", "--max-partition-size=32", | 13321 | "--min-partition-size=8", "--max-partition-size=32", |
| 13851 | "--obu", "-o", "-", "-", | 13322 | "--obu", "-o", "-", "-", |
| 13852 | ]; | 13323 | ]; |
| 13853 | - let mut child = Command::new(aomenc_path()) | 13324 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 13854 | - .args(&args) | 13325 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 13867 | assert!( | 13326 | assert!( |
| 13868 | out.status.success(), | 13327 | out.status.success(), |
| 13869 | "aomenc refused the fixture: {}", | 13328 | "aomenc refused the fixture: {}", |
| @@ -14064,20 +13523,8 @@ pub(crate) mod tests { | |||
| 14064 | "--max-partition-size=64", | 13523 | "--max-partition-size=64", |
| 14065 | "--obu", "-o", "-", "-", | 13524 | "--obu", "-o", "-", "-", |
| 14066 | ]; | 13525 | ]; |
| 14067 | - let mut child = Command::new(aomenc_path()) | 13526 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 14068 | - .args(&args) | 13527 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 14081 | assert!( | 13528 | assert!( |
| 14082 | out.status.success(), | 13529 | out.status.success(), |
| 14083 | "aomenc refused the fixture: {}", | 13530 | "aomenc refused the fixture: {}", |
| @@ -14227,20 +13674,8 @@ pub(crate) mod tests { | |||
| 14227 | "--enable-intrabc=0", "--enable-cfl-intra=0", "--enable-ref-frame-mvs=0", | 13674 | "--enable-intrabc=0", "--enable-cfl-intra=0", "--enable-ref-frame-mvs=0", |
| 14228 | "--obu", "-o", "-", "-", | 13675 | "--obu", "-o", "-", "-", |
| 14229 | ]; | 13676 | ]; |
| 14230 | - let mut child = Command::new(aomenc_path()) | 13677 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 14231 | - .args(&args) | 13678 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 14244 | assert!( | 13679 | assert!( |
| 14245 | out.status.success(), | 13680 | out.status.success(), |
| 14246 | "aomenc refused the fixture: {}", | 13681 | "aomenc refused the fixture: {}", |
| @@ -14432,20 +13867,8 @@ pub(crate) mod tests { | |||
| 14432 | "--max-partition-size=32", | 13867 | "--max-partition-size=32", |
| 14433 | "--obu", "-o", "-", "-", | 13868 | "--obu", "-o", "-", "-", |
| 14434 | ]; | 13869 | ]; |
| 14435 | - let mut child = Command::new(aomenc_path()) | 13870 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 14436 | - .args(&args) | 13871 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 14449 | assert!( | 13872 | assert!( |
| 14450 | out.status.success(), | 13873 | out.status.success(), |
| 14451 | "aomenc refused the fixture: {}", | 13874 | "aomenc refused the fixture: {}", |
| @@ -14572,20 +13995,8 @@ pub(crate) mod tests { | |||
| 14572 | "--lag-in-frames=16", "--auto-alt-ref=1", "--arnr-maxframes=0", | 13995 | "--lag-in-frames=16", "--auto-alt-ref=1", "--arnr-maxframes=0", |
| 14573 | "--obu", "-o", "-", "-", | 13996 | "--obu", "-o", "-", "-", |
| 14574 | ]; | 13997 | ]; |
| 14575 | - let mut child = Command::new(aomenc_path()) | 13998 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 14576 | - .args(&args) | 13999 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 14589 | assert!( | 14000 | assert!( |
| 14590 | out.status.success(), | 14001 | out.status.success(), |
| 14591 | "aomenc refused the fixture: {}", | 14002 | "aomenc refused the fixture: {}", |
| @@ -14731,20 +14142,8 @@ pub(crate) mod tests { | |||
| 14731 | "--max-partition-size=32", | 14142 | "--max-partition-size=32", |
| 14732 | "--obu", "-o", "-", "-", | 14143 | "--obu", "-o", "-", "-", |
| 14733 | ]; | 14144 | ]; |
| 14734 | - let mut child = Command::new(aomenc_path()) | 14145 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 14735 | - .args(&args) | 14146 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 14748 | assert!( | 14147 | assert!( |
| 14749 | out.status.success(), | 14148 | out.status.success(), |
| 14750 | "aomenc refused the fixture: {}", | 14149 | "aomenc refused the fixture: {}", |
| @@ -14941,20 +14340,8 @@ pub(crate) mod tests { | |||
| 14941 | &rect_arg, | 14340 | &rect_arg, |
| 14942 | "--obu", "-o", "-", "-", | 14341 | "--obu", "-o", "-", "-", |
| 14943 | ]; | 14342 | ]; |
| 14944 | - let mut child = Command::new(aomenc_path()) | 14343 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 14945 | - .args(&args) | 14344 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 14958 | assert!( | 14345 | assert!( |
| 14959 | out.status.success(), | 14346 | out.status.success(), |
| 14960 | "{NAME}: aomenc refused the fixture: {}", | 14347 | "{NAME}: aomenc refused the fixture: {}", |
| @@ -15184,20 +14571,8 @@ pub(crate) mod tests { | |||
| 15184 | obmc_arg, | 14571 | obmc_arg, |
| 15185 | "--obu", "-o", "-", "-", | 14572 | "--obu", "-o", "-", "-", |
| 15186 | ]; | 14573 | ]; |
| 15187 | - let mut child = Command::new(aomenc_path()) | 14574 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 15188 | - .args(&args) | 14575 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 15201 | assert!( | 14576 | assert!( |
| 15202 | out.status.success(), | 14577 | out.status.success(), |
| 15203 | "aomenc refused the fixture: {}", | 14578 | "aomenc refused the fixture: {}", |
| @@ -15444,20 +14819,8 @@ pub(crate) mod tests { | |||
| 15444 | "--max-partition-size=16", | 14819 | "--max-partition-size=16", |
| 15445 | "--obu", "-o", "-", "-", | 14820 | "--obu", "-o", "-", "-", |
| 15446 | ]; | 14821 | ]; |
| 15447 | - let mut child = Command::new(aomenc_path()) | 14822 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 15448 | - .args(&args) | 14823 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 15461 | assert!( | 14824 | assert!( |
| 15462 | out.status.success(), | 14825 | out.status.success(), |
| 15463 | "aomenc refused the fixture: {}", | 14826 | "aomenc refused the fixture: {}", |
| @@ -15684,20 +15047,8 @@ pub(crate) mod tests { | |||
| 15684 | "--max-partition-size=16", | 15047 | "--max-partition-size=16", |
| 15685 | "--obu", "-o", "-", "-", | 15048 | "--obu", "-o", "-", "-", |
| 15686 | ]; | 15049 | ]; |
| 15687 | - let mut child = Command::new(aomenc_path()) | 15050 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 15688 | - .args(&args) | 15051 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 15701 | assert!( | 15052 | assert!( |
| 15702 | out.status.success(), | 15053 | out.status.success(), |
| 15703 | "aomenc refused the fixture: {}", | 15054 | "aomenc refused the fixture: {}", |
| @@ -16029,20 +15380,8 @@ pub(crate) mod tests { | |||
| 16029 | &min_part_arg, "--max-partition-size=16", | 15380 | &min_part_arg, "--max-partition-size=16", |
| 16030 | "--obu", "-o", "-", "-", | 15381 | "--obu", "-o", "-", "-", |
| 16031 | ]; | 15382 | ]; |
| 16032 | - let mut child = Command::new(aomenc_path()) | 15383 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 16033 | - .args(&args) | 15384 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 16046 | assert!( | 15385 | assert!( |
| 16047 | out.status.success(), | 15386 | out.status.success(), |
| 16048 | "aomenc refused the fixture: {}", | 15387 | "aomenc refused the fixture: {}", |
| @@ -16297,20 +15636,8 @@ pub(crate) mod tests { | |||
| 16297 | "--max-partition-size=64", | 15636 | "--max-partition-size=64", |
| 16298 | "--obu", "-o", "-", "-", | 15637 | "--obu", "-o", "-", "-", |
| 16299 | ]; | 15638 | ]; |
| 16300 | - let mut child = Command::new(aomenc_path()) | 15639 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 16301 | - .args(&args) | 15640 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 16314 | assert!( | 15641 | assert!( |
| 16315 | out.status.success(), | 15642 | out.status.success(), |
| 16316 | "aomenc refused the fixture: {}", | 15643 | "aomenc refused the fixture: {}", |
| @@ -16443,7 +15770,7 @@ pub(crate) mod tests { | |||
| 16443 | "ffmpeg fixture: {}", | 15770 | "ffmpeg fixture: {}", |
| 16444 | String::from_utf8_lossy(&y4m.stderr) | 15771 | String::from_utf8_lossy(&y4m.stderr) |
| 16445 | ); | 15772 | ); |
| 16446 | - let mut child = Command::new(aomenc_path()) | 15773 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 16447 | .args([ | 15774 | .args([ |
| 16448 | // lane-defon r1: explicit on-value (aomenc keeps the FIRST | 15775 | // lane-defon r1: explicit on-value (aomenc keeps the FIRST |
| 16449 | // occurrence, so overrides go before the base list). | 15776 | // occurrence, so overrides go before the base list). |
| @@ -16496,19 +15823,7 @@ pub(crate) mod tests { | |||
| 16496 | "-o", | 15823 | "-o", |
| 16497 | "-", | 15824 | "-", |
| 16498 | "-", | 15825 | "-", |
| 16499 | - ]) | 15826 | + ]), &y4m.stdout); |
| 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"); | ||
| 16512 | assert!( | 15827 | assert!( |
| 16513 | out.status.success(), | 15828 | out.status.success(), |
| 16514 | "aomenc refused the fixture: {}", | 15829 | "aomenc refused the fixture: {}", |
| @@ -16630,7 +15945,7 @@ pub(crate) mod tests { | |||
| 16630 | "y4m fixture length mismatch (seed {seed})" | 15945 | "y4m fixture length mismatch (seed {seed})" |
| 16631 | ); | 15946 | ); |
| 16632 | let y4m_hash = fnv1a64(&y4m.stdout); | 15947 | let y4m_hash = fnv1a64(&y4m.stdout); |
| 16633 | - let mut child = Command::new(aomenc_path()) | 15948 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 16634 | .args([ | 15949 | .args([ |
| 16635 | "--codec=av1", | 15950 | "--codec=av1", |
| 16636 | "--passes=1", | 15951 | "--passes=1", |
| @@ -16694,19 +16009,7 @@ pub(crate) mod tests { | |||
| 16694 | "-o", | 16009 | "-o", |
| 16695 | "-", | 16010 | "-", |
| 16696 | "-", | 16011 | "-", |
| 16697 | - ]) | 16012 | + ]), &y4m.stdout); |
| 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"); | ||
| 16710 | assert!( | 16013 | assert!( |
| 16711 | out.status.success(), | 16014 | out.status.success(), |
| 16712 | "aomenc refused the fixture: {}", | 16015 | "aomenc refused the fixture: {}", |
| @@ -16969,7 +16272,7 @@ pub(crate) mod tests { | |||
| 16969 | "ffmpeg fixture: {}", | 16272 | "ffmpeg fixture: {}", |
| 16970 | String::from_utf8_lossy(&y4m.stderr) | 16273 | String::from_utf8_lossy(&y4m.stderr) |
| 16971 | ); | 16274 | ); |
| 16972 | - let mut child = Command::new(aomenc_path()) | 16275 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 16973 | .args([ | 16276 | .args([ |
| 16974 | "--codec=av1", | 16277 | "--codec=av1", |
| 16975 | "--passes=1", | 16278 | "--passes=1", |
| @@ -17047,19 +16350,7 @@ pub(crate) mod tests { | |||
| 17047 | "-o", | 16350 | "-o", |
| 17048 | "-", | 16351 | "-", |
| 17049 | "-", | 16352 | "-", |
| 17050 | - ]) | 16353 | + ]), &y4m.stdout); |
| 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"); | ||
| 17063 | assert!( | 16354 | assert!( |
| 17064 | out.status.success(), | 16355 | out.status.success(), |
| 17065 | "aomenc refused the fixture: {}", | 16356 | "aomenc refused the fixture: {}", |
| @@ -17243,20 +16534,8 @@ pub(crate) mod tests { | |||
| 17243 | let tail = args.split_off(args.len() - 3); | 16534 | let tail = args.split_off(args.len() - 3); |
| 17244 | args.extend_from_slice(extra_args); | 16535 | args.extend_from_slice(extra_args); |
| 17245 | args.extend_from_slice(&tail); | 16536 | args.extend_from_slice(&tail); |
| 17246 | - let mut child = Command::new(aomenc_path()) | 16537 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 17247 | - .args(&args) | 16538 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 17260 | assert!( | 16539 | assert!( |
| 17261 | out.status.success(), | 16540 | out.status.success(), |
| 17262 | "aomenc refused the fixture: {}", | 16541 | "aomenc refused the fixture: {}", |
| @@ -17448,20 +16727,8 @@ pub(crate) mod tests { | |||
| 17448 | "-", | 16727 | "-", |
| 17449 | "-", | 16728 | "-", |
| 17450 | ]; | 16729 | ]; |
| 17451 | - let mut child = Command::new(aomenc_path()) | 16730 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 17452 | - .args(&args) | 16731 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 17465 | assert!( | 16732 | assert!( |
| 17466 | out.status.success(), | 16733 | out.status.success(), |
| 17467 | "aomenc refused the fixture: {}", | 16734 | "aomenc refused the fixture: {}", |
| @@ -17690,20 +16957,8 @@ pub(crate) mod tests { | |||
| 17690 | "-", | 16957 | "-", |
| 17691 | "-", | 16958 | "-", |
| 17692 | ]; | 16959 | ]; |
| 17693 | - let mut child = Command::new(aomenc_path()) | 16960 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 17694 | - .args(&args) | 16961 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 17707 | assert!( | 16962 | assert!( |
| 17708 | out.status.success(), | 16963 | out.status.success(), |
| 17709 | "aomenc refused the fixture: {}", | 16964 | "aomenc refused the fixture: {}", |
| @@ -17892,20 +17147,8 @@ pub(crate) mod tests { | |||
| 17892 | "-", | 17147 | "-", |
| 17893 | "-", | 17148 | "-", |
| 17894 | ]; | 17149 | ]; |
| 17895 | - let mut child = Command::new(aomenc_path()) | 17150 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 17896 | - .args(&args) | 17151 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 17909 | assert!( | 17152 | assert!( |
| 17910 | out.status.success(), | 17153 | out.status.success(), |
| 17911 | "aomenc refused the fixture: {}", | 17154 | "aomenc refused the fixture: {}", |
| @@ -18107,20 +17350,8 @@ pub(crate) mod tests { | |||
| 18107 | "-", | 17350 | "-", |
| 18108 | "-", | 17351 | "-", |
| 18109 | ]; | 17352 | ]; |
| 18110 | - let mut child = Command::new(aomenc_path()) | 17353 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 18111 | - .args(&args) | 17354 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 18124 | assert!( | 17355 | assert!( |
| 18125 | out.status.success(), | 17356 | out.status.success(), |
| 18126 | "aomenc refused the fixture: {}", | 17357 | "aomenc refused the fixture: {}", |
| @@ -18305,20 +17536,8 @@ pub(crate) mod tests { | |||
| 18305 | "-", | 17536 | "-", |
| 18306 | "-", | 17537 | "-", |
| 18307 | ]; | 17538 | ]; |
| 18308 | - let mut child = Command::new(aomenc_path()) | 17539 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 18309 | - .args(&args) | 17540 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 18322 | assert!( | 17541 | assert!( |
| 18323 | out.status.success(), | 17542 | out.status.success(), |
| 18324 | "aomenc refused the fixture: {}", | 17543 | "aomenc refused the fixture: {}", |
| @@ -18474,20 +17693,8 @@ pub(crate) mod tests { | |||
| 18474 | "-", | 17693 | "-", |
| 18475 | "-", | 17694 | "-", |
| 18476 | ]; | 17695 | ]; |
| 18477 | - let mut child = Command::new(aomenc_path()) | 17696 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 18478 | - .args(&args) | 17697 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 18491 | assert!( | 17698 | assert!( |
| 18492 | out.status.success(), | 17699 | out.status.success(), |
| 18493 | "aomenc refused the fixture: {}", | 17700 | "aomenc refused the fixture: {}", |
| @@ -18620,20 +17827,8 @@ pub(crate) mod tests { | |||
| 18620 | "-", | 17827 | "-", |
| 18621 | "-", | 17828 | "-", |
| 18622 | ]; | 17829 | ]; |
| 18623 | - let mut child = Command::new(aomenc_path()) | 17830 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 18624 | - .args(&args) | 17831 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 18637 | assert!( | 17832 | assert!( |
| 18638 | out.status.success(), | 17833 | out.status.success(), |
| 18639 | "aomenc refused the fixture: {}", | 17834 | "aomenc refused the fixture: {}", |
| @@ -18759,20 +17954,8 @@ pub(crate) mod tests { | |||
| 18759 | args.push(arm.cq); | 17954 | args.push(arm.cq); |
| 18760 | args.extend_from_slice(&arm.extra); | 17955 | args.extend_from_slice(&arm.extra); |
| 18761 | args.extend_from_slice(&["--obu", "-o", "-", "-"]); | 17956 | args.extend_from_slice(&["--obu", "-o", "-", "-"]); |
| 18762 | - let mut child = Command::new(aomenc_path()) | 17957 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 18763 | - .args(&args) | 17958 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 18776 | assert!( | 17959 | assert!( |
| 18777 | out.status.success(), | 17960 | out.status.success(), |
| 18778 | "{NAME} {}: aomenc refused the recipe: {}", | 17961 | "{NAME} {}: aomenc refused the recipe: {}", |
| @@ -18918,20 +18101,8 @@ pub(crate) mod tests { | |||
| 18918 | "-", | 18101 | "-", |
| 18919 | "-", | 18102 | "-", |
| 18920 | ]; | 18103 | ]; |
| 18921 | - let mut child = Command::new(aomenc_path()) | 18104 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 18922 | - .args(&args) | 18105 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 18935 | assert!( | 18106 | assert!( |
| 18936 | out.status.success(), | 18107 | out.status.success(), |
| 18937 | "aomenc refused the fixture: {}", | 18108 | "aomenc refused the fixture: {}", |
| @@ -19010,20 +18181,8 @@ pub(crate) mod tests { | |||
| 19010 | "--min-partition-size=8", | 18181 | "--min-partition-size=8", |
| 19011 | "--max-partition-size=64", | 18182 | "--max-partition-size=64", |
| 19012 | ]); | 18183 | ]); |
| 19013 | - let mut child = Command::new(aomenc_path()) | 18184 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 19014 | - .args(&rect_args) | 18185 | + .args(&rect_args), &y4m.stdout); |
| 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"); | ||
| 19027 | assert!( | 18186 | assert!( |
| 19028 | out.status.success(), | 18187 | out.status.success(), |
| 19029 | "{NAME} RECT-ARM: aomenc refused its own recipe plus the rect overrides: {}", | 18188 | "{NAME} RECT-ARM: aomenc refused its own recipe plus the rect overrides: {}", |
| @@ -19217,20 +18376,8 @@ pub(crate) mod tests { | |||
| 19217 | "-", | 18376 | "-", |
| 19218 | "-", | 18377 | "-", |
| 19219 | ]; | 18378 | ]; |
| 19220 | - let mut child = Command::new(aomenc_path()) | 18379 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 19221 | - .args(&args) | 18380 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 19234 | assert!( | 18381 | assert!( |
| 19235 | out.status.success(), | 18382 | out.status.success(), |
| 19236 | "aomenc refused the fixture: {}", | 18383 | "aomenc refused the fixture: {}", |
| @@ -19565,20 +18712,8 @@ pub(crate) mod tests { | |||
| 19565 | "-", | 18712 | "-", |
| 19566 | "-", | 18713 | "-", |
| 19567 | ]; | 18714 | ]; |
| 19568 | - let mut child = Command::new(aomenc_path()) | 18715 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 19569 | - .args(&args) | 18716 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 19582 | assert!( | 18717 | assert!( |
| 19583 | out.status.success(), | 18718 | out.status.success(), |
| 19584 | "aomenc refused the fixture: {}", | 18719 | "aomenc refused the fixture: {}", |
| @@ -19792,20 +18927,7 @@ pub(crate) mod tests { | |||
| 19792 | "-", | 18927 | "-", |
| 19793 | "-", | 18928 | "-", |
| 19794 | ]; | 18929 | ]; |
| 19795 | - let mut child = Command::new(affine_aomenc_path()) | 18930 | + let out = run_with_stdin(Command::new(affine_aomenc_path()).args(&args), &y4m.stdout); |
| 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"); | ||
| 19809 | assert!( | 18931 | assert!( |
| 19810 | out.status.success(), | 18932 | out.status.success(), |
| 19811 | "aomenc refused the fixture: {}", | 18933 | "aomenc refused the fixture: {}", |
| @@ -19953,20 +19075,8 @@ pub(crate) mod tests { | |||
| 19953 | "-", | 19075 | "-", |
| 19954 | "-", | 19076 | "-", |
| 19955 | ]; | 19077 | ]; |
| 19956 | - let mut child = Command::new(aomenc_path()) | 19078 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 19957 | - .args(&args) | 19079 | + .args(&args), &y4m.stdout); |
| 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"); | ||
| 19970 | assert!( | 19080 | assert!( |
| 19971 | out.status.success(), | 19081 | out.status.success(), |
| 19972 | "aomenc refused the fixture: {}", | 19082 | "aomenc refused the fixture: {}", |
| @@ -20110,7 +19220,7 @@ pub(crate) mod tests { | |||
| 20110 | "ffmpeg fixture: {}", | 19220 | "ffmpeg fixture: {}", |
| 20111 | String::from_utf8_lossy(&y4m.stderr) | 19221 | String::from_utf8_lossy(&y4m.stderr) |
| 20112 | ); | 19222 | ); |
| 20113 | - let mut child = Command::new(aomenc_path()) | 19223 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 20114 | .args([ | 19224 | .args([ |
| 20115 | "--threads=1", | 19225 | "--threads=1", |
| 20116 | "--row-mt=0", | 19226 | "--row-mt=0", |
| @@ -20123,19 +19233,7 @@ pub(crate) mod tests { | |||
| 20123 | "-o", | 19233 | "-o", |
| 20124 | "-", | 19234 | "-", |
| 20125 | "-", | 19235 | "-", |
| 20126 | - ]) | 19236 | + ]), &y4m.stdout); |
| 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"); | ||
| 20139 | assert!( | 19237 | assert!( |
| 20140 | out.status.success(), | 19238 | out.status.success(), |
| 20141 | "aomenc refused the fixture: {}", | 19239 | "aomenc refused the fixture: {}", |
| @@ -20232,7 +19330,7 @@ pub(crate) mod tests { | |||
| 20232 | .expect("ffmpeg failed to run"); | 19330 | .expect("ffmpeg failed to run"); |
| 20233 | assert!(y4m.status.success(), "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr)); | 19331 | assert!(y4m.status.success(), "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr)); |
| 20234 | let encode = || { | 19332 | let encode = || { |
| 20235 | - let mut child = Command::new(aomenc_path()) | 19333 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 20236 | .args([ | 19334 | .args([ |
| 20237 | "--codec=av1", | 19335 | "--codec=av1", |
| 20238 | "--passes=1", | 19336 | "--passes=1", |
| @@ -20259,19 +19357,7 @@ pub(crate) mod tests { | |||
| 20259 | "-o", | 19357 | "-o", |
| 20260 | "-", | 19358 | "-", |
| 20261 | "-", | 19359 | "-", |
| 20262 | - ]) | 19360 | + ]), &y4m.stdout); |
| 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"); | ||
| 20275 | assert!( | 19361 | assert!( |
| 20276 | out.status.success(), | 19362 | out.status.success(), |
| 20277 | "aomenc refused the fixture: {}", | 19363 | "aomenc refused the fixture: {}", |
| @@ -20349,7 +19435,7 @@ pub(crate) mod tests { | |||
| 20349 | let mut total_overrides = 0usize; | 19435 | let mut total_overrides = 0usize; |
| 20350 | for (rtx, filter_intra) in [("1", "0"), ("0", "1")] { | 19436 | for (rtx, filter_intra) in [("1", "0"), ("0", "1")] { |
| 20351 | let encode = || { | 19437 | let encode = || { |
| 20352 | - let mut child = Command::new(aomenc_path()) | 19438 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 20353 | .args([ | 19439 | .args([ |
| 20354 | "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32", | 19440 | "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32", |
| 20355 | "--cpu-used=4", "--threads=1", "--row-mt=0", "--sb-size=64", | 19441 | "--cpu-used=4", "--threads=1", "--row-mt=0", "--sb-size=64", |
| @@ -20361,19 +19447,7 @@ pub(crate) mod tests { | |||
| 20361 | &format!("--reduced-tx-type-set={rtx}"), | 19447 | &format!("--reduced-tx-type-set={rtx}"), |
| 20362 | "--min-partition-size=8", "--max-partition-size=32", | 19448 | "--min-partition-size=8", "--max-partition-size=32", |
| 20363 | "--obu", "-o", "-", "-", | 19449 | "--obu", "-o", "-", "-", |
| 20364 | - ]) | 19450 | + ]), &y4m.stdout); |
| 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"); | ||
| 20377 | assert!( | 19451 | assert!( |
| 20378 | out.status.success(), | 19452 | out.status.success(), |
| 20379 | "aomenc refused the fixture: {}", | 19453 | "aomenc refused the fixture: {}", |
| @@ -20475,7 +19549,7 @@ pub(crate) mod tests { | |||
| 20475 | String::from_utf8_lossy(&y4m.stderr) | 19549 | String::from_utf8_lossy(&y4m.stderr) |
| 20476 | ); | 19550 | ); |
| 20477 | let encode = || { | 19551 | let encode = || { |
| 20478 | - let mut child = Command::new(aomenc_path()) | 19552 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 20479 | .args([ | 19553 | .args([ |
| 20480 | "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=16", | 19554 | "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=16", |
| 20481 | "--cpu-used=4", "--threads=1", "--row-mt=0", "--sb-size=64", | 19555 | "--cpu-used=4", "--threads=1", "--row-mt=0", "--sb-size=64", |
| @@ -20487,19 +19561,7 @@ pub(crate) mod tests { | |||
| 20487 | &format!("--input-bit-depth={depth}"), | 19561 | &format!("--input-bit-depth={depth}"), |
| 20488 | &format!("--bit-depth={depth}"), | 19562 | &format!("--bit-depth={depth}"), |
| 20489 | "--obu", "-o", "-", "-", | 19563 | "--obu", "-o", "-", "-", |
| 20490 | - ]) | 19564 | + ]), &y4m.stdout); |
| 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"); | ||
| 20503 | assert!( | 19565 | assert!( |
| 20504 | out.status.success(), | 19566 | out.status.success(), |
| 20505 | "aomenc refused the fixture (depth={depth}): {}", | 19567 | "aomenc refused the fixture (depth={depth}): {}", |
| @@ -20646,7 +19708,7 @@ pub(crate) mod tests { | |||
| 20646 | String::from_utf8_lossy(&y4m.stderr) | 19708 | String::from_utf8_lossy(&y4m.stderr) |
| 20647 | ); | 19709 | ); |
| 20648 | let encode = || { | 19710 | let encode = || { |
| 20649 | - let mut child = Command::new(aomenc_path()) | 19711 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 20650 | .args([ | 19712 | .args([ |
| 20651 | "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=52", | 19713 | "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=52", |
| 20652 | "--cpu-used=0", "--threads=1", "--row-mt=0", "--sb-size=128", | 19714 | "--cpu-used=0", "--threads=1", "--row-mt=0", "--sb-size=128", |
| @@ -20659,19 +19721,7 @@ pub(crate) mod tests { | |||
| 20659 | &format!("--input-bit-depth={depth}"), | 19721 | &format!("--input-bit-depth={depth}"), |
| 20660 | &format!("--bit-depth={depth}"), | 19722 | &format!("--bit-depth={depth}"), |
| 20661 | "--obu", "-o", "-", "-", | 19723 | "--obu", "-o", "-", "-", |
| 20662 | - ]) | 19724 | + ]), &y4m.stdout); |
| 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"); | ||
| 20675 | assert!( | 19725 | assert!( |
| 20676 | out.status.success(), | 19726 | out.status.success(), |
| 20677 | "aomenc refused the fixture (depth={depth}): {}", | 19727 | "aomenc refused the fixture (depth={depth}): {}", |
| @@ -20869,15 +19919,8 @@ pub(crate) mod tests { | |||
| 20869 | args.push("--bit-depth=10".into()); | 19919 | args.push("--bit-depth=10".into()); |
| 20870 | } | 19920 | } |
| 20871 | args.extend(["--obu".into(), "-o".into(), "-".into(), "-".into()]); | 19921 | args.extend(["--obu".into(), "-o".into(), "-".into(), "-".into()]); |
| 20872 | - let mut child = Command::new(aomenc_path()) | 19922 | + let out = run_with_stdin(Command::new(aomenc_path()) |
| 20873 | - .args(&args) | 19923 | + .args(&args), &y4m.stdout); |
| 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"); | ||
crates/ec-av1/src/tile.rsmodified+484 -179
| @@ -12,17 +12,17 @@ | |||
| 12 | use std::cell::RefCell; | 12 | use std::cell::RefCell; |
| 13 | #[cfg(test)] | 13 | #[cfg(test)] |
| 14 | use std::collections::BTreeMap; | 14 | use std::collections::BTreeMap; |
| 15 | -use std::sync::LazyLock; | ||
| 16 | use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering}; | 15 | use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering}; |
| 16 | +use std::sync::LazyLock; | ||
| 17 | 17 | ||
| 18 | use ec_core::{Error, Result}; | 18 | use ec_core::{Error, Result}; |
| 19 | 19 | ||
| 20 | use crate::cdf; | 20 | use crate::cdf; |
| 21 | use crate::cdf_state::{Cdfs, MvComponentCdfs, TxbSet, TxbTables}; | 21 | 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}; |
| 23 | use crate::msac::SymbolEncoder; | 23 | use crate::msac::SymbolEncoder; |
| 24 | +use crate::mvstack::{find_mv_stack, mv16, MiGrid, MiInfo, NO_REF1}; | ||
| 24 | use crate::transform::TxType; | 25 | use crate::transform::TxType; |
| 25 | -use crate::mvstack::{MiGrid, MiInfo, NO_REF1, find_mv_stack, mv16}; | ||
| 26 | 26 | ||
| 27 | // --------------------------------------------------------------------------- | 27 | // --------------------------------------------------------------------------- |
| 28 | // lane-av1lr: per-64x64 `cdef_idx` (spec 5.11.56, `read_cdef`). The decoder | 28 | // lane-av1lr: per-64x64 `cdef_idx` (spec 5.11.56, `read_cdef`). The decoder |
| @@ -386,9 +386,7 @@ fn write_inter_block_128( | |||
| 386 | let scan32 = default_scan(TX32); | 386 | let scan32 = default_scan(TX32); |
| 387 | let unit_of = |plane: usize, cr: usize, cc: usize| -> Vec<i32> { | 387 | let unit_of = |plane: usize, cr: usize, cc: usize| -> Vec<i32> { |
| 388 | (0..32) | 388 | (0..32) |
| 389 | - .flat_map(|row| { | 389 | + .flat_map(|row| packed[plane][(cr * 32 + row) * 64 + cc * 32..][..32].to_vec()) |
| 390 | - packed[plane][(cr * 32 + row) * 64 + cc * 32..][..32].to_vec() | ||
| 391 | - }) | ||
| 392 | .collect() | 390 | .collect() |
| 393 | }; | 391 | }; |
| 394 | let mut chroma_units: Vec<((usize, usize), [Vec<i32>; 2])> = Vec::new(); | 392 | let mut chroma_units: Vec<((usize, usize), [Vec<i32>; 2])> = Vec::new(); |
| @@ -659,9 +657,7 @@ fn write_inter_block_128_rect( | |||
| 659 | let scan32 = default_scan(TX32); | 657 | let scan32 = default_scan(TX32); |
| 660 | let unit_of = |plane: usize, cr: usize, cc: usize| -> Vec<i32> { | 658 | let unit_of = |plane: usize, cr: usize, cc: usize| -> Vec<i32> { |
| 661 | (0..32) | 659 | (0..32) |
| 662 | - .flat_map(|row| { | 660 | + .flat_map(|row| packed[plane][(cr * 32 + row) * 64 + cc * 32..][..32].to_vec()) |
| 663 | - packed[plane][(cr * 32 + row) * 64 + cc * 32..][..32].to_vec() | ||
| 664 | - }) | ||
| 665 | .collect() | 661 | .collect() |
| 666 | }; | 662 | }; |
| 667 | let mut chroma_units: Vec<((usize, usize), [Vec<i32>; 2])> = Vec::new(); | 663 | let mut chroma_units: Vec<((usize, usize), [Vec<i32>; 2])> = Vec::new(); |
| @@ -702,7 +698,8 @@ fn write_inter_block_128_rect( | |||
| 702 | &mut cdfs.txb(TxbSet::Chroma32, 0), | 698 | &mut cdfs.txb(TxbSet::Chroma32, 0), |
| 703 | &grid, | 699 | &grid, |
| 704 | &scan32, | 700 | &scan32, |
| 705 | - usize::from(around.above_coded) + usize::from(around.left_coded) | 701 | + usize::from(around.above_coded) |
| 702 | + + usize::from(around.left_coded) | ||
| 706 | + 3 * usize::from(is_half), | 703 | + 3 * usize::from(is_half), |
| 707 | dc_sign_ctx(around.dc_vote), | 704 | dc_sign_ctx(around.dc_vote), |
| 708 | Some(plane), | 705 | Some(plane), |
| @@ -781,8 +778,7 @@ pub fn take_sb128_ab_hits() -> [usize; 4] { | |||
| 781 | /// lane-b128r: how many of those blocks carried a REAL residual (four | 778 | /// lane-b128r: how many of those blocks carried a REAL residual (four |
| 782 | /// TX_64X64 luma units plus their per-chunk chroma pair) rather than being | 779 | /// TX_64X64 luma units plus their per-chunk chroma pair) rather than being |
| 783 | /// skipped, since the last [`take_sb128_residual_hits`]. | 780 | /// skipped, since the last [`take_sb128_residual_hits`]. |
| 784 | -static SB128_RESIDUAL_HITS: std::sync::atomic::AtomicUsize = | 781 | +static SB128_RESIDUAL_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); |
| 785 | - std::sync::atomic::AtomicUsize::new(0); | ||
| 786 | 782 | ||
| 787 | /// The 128x128-with-residual count since the last call, and zero it. | 783 | /// The 128x128-with-residual count since the last call, and zero it. |
| 788 | pub fn take_sb128_residual_hits() -> usize { | 784 | pub fn take_sb128_residual_hits() -> usize { |
| @@ -792,8 +788,7 @@ pub fn take_sb128_residual_hits() -> usize { | |||
| 792 | /// [`write_inter_block_128_rect`] codes) carried a REAL residual rather than | 788 | /// [`write_inter_block_128_rect`] codes) carried a REAL residual rather than |
| 793 | /// being skipped, since the last [`take_sb128_rectres_hits`] -- the writer | 789 | /// being skipped, since the last [`take_sb128_rectres_hits`] -- the writer |
| 794 | /// side of [`crate::encode::take_b128_rectres_hits`]'s search count. | 790 | /// side of [`crate::encode::take_b128_rectres_hits`]'s search count. |
| 795 | -static SB128_RECTRES_HITS: std::sync::atomic::AtomicUsize = | 791 | +static SB128_RECTRES_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); |
| 796 | - std::sync::atomic::AtomicUsize::new(0); | ||
| 797 | 792 | ||
| 798 | /// The rect/AB-piece-with-residual count since the last call, and zero it. | 793 | /// The rect/AB-piece-with-residual count since the last call, and zero it. |
| 799 | pub fn take_sb128_rectres_hits() -> usize { | 794 | pub fn take_sb128_rectres_hits() -> usize { |
| @@ -803,8 +798,7 @@ pub fn take_sb128_rectres_hits() -> usize { | |||
| 803 | /// lane-b128r: how many of those blocks named a SECOND reference (the | 798 | /// lane-b128r: how many of those blocks named a SECOND reference (the |
| 804 | /// compound arm at the 128 root), since the last | 799 | /// compound arm at the 128 root), since the last |
| 805 | /// [`take_sb128_compound_hits`]. | 800 | /// [`take_sb128_compound_hits`]. |
| 806 | -static SB128_COMPOUND_HITS: std::sync::atomic::AtomicUsize = | 801 | +static SB128_COMPOUND_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); |
| 807 | - std::sync::atomic::AtomicUsize::new(0); | ||
| 808 | 802 | ||
| 809 | /// The compound-128 count since the last call, and zero it. | 803 | /// The compound-128 count since the last call, and zero it. |
| 810 | pub fn take_sb128_compound_hits() -> usize { | 804 | 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, | |||
| 838 | let info = plan.units[(rcol + rrow * plan.horz_units) as usize]; | 832 | let info = plan.units[(rcol + rrow * plan.horz_units) as usize]; |
| 839 | enc.symbol(usize::from(info.is_some()), &mut cdfs.restore_wiener); | 833 | enc.symbol(usize::from(info.is_some()), &mut cdfs.restore_wiener); |
| 840 | if let Some(info) = info { | 834 | if let Some(info) = info { |
| 841 | - crate::restoration::write_wiener_filter( | 835 | + crate::restoration::write_wiener_filter(enc, false, &mut plan.reference, &info); |
| 842 | - enc, | ||
| 843 | - false, | ||
| 844 | - &mut plan.reference, | ||
| 845 | - &info, | ||
| 846 | - ); | ||
| 847 | } | 836 | } |
| 848 | } | 837 | } |
| 849 | } | 838 | } |
| @@ -919,7 +908,10 @@ impl TileLayout { | |||
| 919 | let starts = |total: u32, log2: u32| { | 908 | let starts = |total: u32, log2: u32| { |
| 920 | let total128 = total.div_ceil(unit); | 909 | let total128 = total.div_ceil(unit); |
| 921 | let step = total128.div_ceil(1 << log2).max(1); | 910 | 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(); | ||
| 923 | v.push(total); | 915 | v.push(total); |
| 924 | v | 916 | v |
| 925 | }; | 917 | }; |
| @@ -1067,11 +1059,9 @@ pub(crate) fn cdef_unit_owner(blocks: &[Quadrant], mi_cols: u32, mi_rows: u32) - | |||
| 1067 | // (its two squares are one unit each); only a non-skip one | 1059 | // (its two squares are one unit each); only a non-skip one |
| 1068 | // codes a literal, so only it fires. | 1060 | // codes a literal, so only it fires. |
| 1069 | Quadrant::Ab128(symbol, pieces) => { | 1061 | Quadrant::Ab128(symbol, pieces) => { |
| 1070 | - for (piece, ((mi_r, mi_c), (w, h))) in | 1062 | + for (piece, ((mi_r, mi_c), (w, h))) in pieces |
| 1071 | - pieces.iter().zip(crate::encode::ab128_pieces( | 1063 | + .iter() |
| 1072 | - usize::from(*symbol), | 1064 | + .zip(crate::encode::ab128_pieces(usize::from(*symbol), (0, 0))) |
| 1073 | - (0, 0), | ||
| 1074 | - )) | ||
| 1075 | { | 1065 | { |
| 1076 | if piece.skip { | 1066 | if piece.skip { |
| 1077 | continue; | 1067 | continue; |
| @@ -1111,7 +1101,12 @@ thread_local! { | |||
| 1111 | /// carries no literal at all). | 1101 | /// carries no literal at all). |
| 1112 | pub(crate) fn arm_cdef_idx(bits: u8, sb_cols: usize, grid: Vec<u8>) { | 1102 | pub(crate) fn arm_cdef_idx(bits: u8, sb_cols: usize, grid: Vec<u8>) { |
| 1113 | CDEF_IDX.with(|c| { | 1103 | 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 | + }); | ||
| 1115 | }); | 1110 | }); |
| 1116 | } | 1111 | } |
| 1117 | 1112 | ||
| @@ -1143,8 +1138,12 @@ thread_local! { | |||
| 1143 | /// lane-deltaq) when `res == 0`. | 1138 | /// lane-deltaq) when `res == 0`. |
| 1144 | pub(crate) fn arm_delta_q(res: i32, sb_cols: usize, grid: Vec<u8>, base: u8) { | 1139 | pub(crate) fn arm_delta_q(res: i32, sb_cols: usize, grid: Vec<u8>, base: u8) { |
| 1145 | DELTA_Q.with(|c| { | 1140 | DELTA_Q.with(|c| { |
| 1146 | - *c.borrow_mut() = | 1141 | + *c.borrow_mut() = (res > 0).then(|| DeltaQPlan { |
| 1147 | - (res > 0).then(|| DeltaQPlan { res, sb_cols, grid, cur: i32::from(base) }); | 1142 | + res, |
| 1143 | + sb_cols, | ||
| 1144 | + grid, | ||
| 1145 | + cur: i32::from(base), | ||
| 1146 | + }); | ||
| 1148 | }); | 1147 | }); |
| 1149 | } | 1148 | } |
| 1150 | 1149 | ||
| @@ -1285,14 +1284,23 @@ fn write_filter_intra( | |||
| 1285 | filter_intra: Option<u8>, | 1284 | filter_intra: Option<u8>, |
| 1286 | ) { | 1285 | ) { |
| 1287 | if !filter_intra_armed() || mode != DC_PRED || has_palette_y { | 1286 | 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 | + ); | ||
| 1289 | return; | 1291 | return; |
| 1290 | } | 1292 | } |
| 1291 | let Some(class) = crate::decode::filter_intra_size_class(side) else { | 1293 | 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 | + ); | ||
| 1293 | return; | 1298 | return; |
| 1294 | }; | 1299 | }; |
| 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 | + ); | ||
| 1296 | if let Some(fi) = filter_intra { | 1304 | if let Some(fi) = filter_intra { |
| 1297 | enc.symbol(usize::from(fi), &mut cdfs.filter_intra_mode); | 1305 | enc.symbol(usize::from(fi), &mut cdfs.filter_intra_mode); |
| 1298 | FILTER_INTRA_HITS[0].fetch_add(1, std::sync::atomic::Ordering::Relaxed); | 1306 | FILTER_INTRA_HITS[0].fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| @@ -1525,7 +1533,12 @@ fn write_motion_mode( | |||
| 1525 | /// a single-reference or intra block, and `record_compound_mi`'s overwrite of | 1533 | /// a single-reference or intra block, and `record_compound_mi`'s overwrite of |
| 1526 | /// the ALTREF default for a compound one (this writer only codes | 1534 | /// the ALTREF default for a compound one (this writer only codes |
| 1527 | /// `comp_group_idx == 0`, `compound_idx == 1`). | 1535 | /// `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 | +) { | ||
| 1529 | if let Some(r1) = block.inter.and_then(|i| i.ref1) { | 1542 | if let Some(r1) = block.inter.and_then(|i| i.ref1) { |
| 1530 | neighbours.record_compound_mi(at_mi, side, r1, 0, 1); | 1543 | neighbours.record_compound_mi(at_mi, side, r1, 0, 1); |
| 1531 | } | 1544 | } |
| @@ -1577,14 +1590,19 @@ pub(crate) fn high_precision_mv() -> bool { | |||
| 1577 | /// `allow_high_precision_mv`, one per non-zero mv component with it), `[1]` | 1590 | /// `allow_high_precision_mv`, one per non-zero mv component with it), `[1]` |
| 1578 | /// counts the ones that came out ZERO -- an eighth-pel vector, i.e. one a | 1591 | /// counts the ones that came out ZERO -- an eighth-pel vector, i.e. one a |
| 1579 | /// frame without the flag cannot name at all. | 1592 | /// frame without the flag cannot name at all. |
| 1580 | -static HP_SYMBOLS: [std::sync::atomic::AtomicU64; 2] = | 1593 | +static HP_SYMBOLS: [std::sync::atomic::AtomicU64; 2] = [ |
| 1581 | - [std::sync::atomic::AtomicU64::new(0), std::sync::atomic::AtomicU64::new(0)]; | 1594 | + std::sync::atomic::AtomicU64::new(0), |
| 1595 | + std::sync::atomic::AtomicU64::new(0), | ||
| 1596 | +]; | ||
| 1582 | 1597 | ||
| 1583 | /// Reads and clears [`HP_SYMBOLS`]: `(hp symbols coded, eighth-pel ones)`. | 1598 | /// Reads and clears [`HP_SYMBOLS`]: `(hp symbols coded, eighth-pel ones)`. |
| 1584 | #[allow(dead_code)] // read only from the `#[cfg(test)]` witness | 1599 | #[allow(dead_code)] // read only from the `#[cfg(test)]` witness |
| 1585 | pub(crate) fn take_hp_symbols() -> (u64, u64) { | 1600 | pub(crate) fn take_hp_symbols() -> (u64, u64) { |
| 1586 | let all = HP_SYMBOLS[0].swap(0, std::sync::atomic::Ordering::Relaxed); | 1601 | 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 | + ) | ||
| 1588 | } | 1606 | } |
| 1589 | 1607 | ||
| 1590 | /// [`take_hp_symbols`] without clearing -- what the NEWMV census prints. | 1608 | /// [`take_hp_symbols`] without clearing -- what the NEWMV census prints. |
| @@ -1611,10 +1629,10 @@ fn write_compound_ref_frames( | |||
| 1611 | (ref0, ref1): (i8, i8), | 1629 | (ref0, ref1): (i8, i8), |
| 1612 | ) -> Result<()> { | 1630 | ) -> Result<()> { |
| 1613 | use crate::mvstack::{ | 1631 | 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, | ||
| 1614 | ALTREF2_FRAME, ALTREF_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST2_FRAME, LAST3_FRAME, | 1634 | 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, | 1635 | + LAST_FRAME, |
| 1616 | - single_ref_p3_ctx, single_ref_p4_ctx, single_ref_p5_ctx, single_ref_p6_ctx, | ||
| 1617 | - uni_comp_ref_p1_ctx, | ||
| 1618 | }; | 1636 | }; |
| 1619 | let a = (above_ref > 0).then_some(above_ref); | 1637 | let a = (above_ref > 0).then_some(above_ref); |
| 1620 | let l = (left_ref > 0).then_some(left_ref); | 1638 | let l = (left_ref > 0).then_some(left_ref); |
| @@ -1810,14 +1828,20 @@ fn write_compound_block( | |||
| 1810 | let mut walk = 1usize; | 1828 | let mut walk = 1usize; |
| 1811 | while walk < 3 && stack.entries.len() > walk + 1 { | 1829 | while walk < 3 && stack.entries.len() > walk + 1 { |
| 1812 | let advance = walk < idx; | 1830 | 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 | + ); | ||
| 1814 | if !advance { | 1835 | if !advance { |
| 1815 | break; | 1836 | break; |
| 1816 | } | 1837 | } |
| 1817 | walk += 1; | 1838 | walk += 1; |
| 1818 | } | 1839 | } |
| 1819 | let near = |i: usize| { | 1840 | 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)) | ||
| 1821 | }; | 1845 | }; |
| 1822 | if walk != idx && near(walk) != near(idx) { | 1846 | if walk != idx && near(walk) != near(idx) { |
| 1823 | note_drl_clamp(idx, walk, stack.entries.len()); | 1847 | note_drl_clamp(idx, walk, stack.entries.len()); |
| @@ -1845,14 +1869,20 @@ fn write_compound_block( | |||
| 1845 | let mut walk = 0usize; | 1869 | let mut walk = 0usize; |
| 1846 | while walk < 2 && stack.entries.len() > walk + 1 { | 1870 | while walk < 2 && stack.entries.len() > walk + 1 { |
| 1847 | let advance = walk < idx; | 1871 | 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 | + ); | ||
| 1849 | if !advance { | 1876 | if !advance { |
| 1850 | break; | 1877 | break; |
| 1851 | } | 1878 | } |
| 1852 | walk += 1; | 1879 | walk += 1; |
| 1853 | } | 1880 | } |
| 1854 | let nearest = |i: usize| { | 1881 | 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)) | ||
| 1856 | }; | 1886 | }; |
| 1857 | if walk != idx && nearest(walk) != nearest(idx) { | 1887 | if walk != idx && nearest(walk) != nearest(idx) { |
| 1858 | note_drl_clamp(idx, walk, stack.entries.len()); | 1888 | note_drl_clamp(idx, walk, stack.entries.len()); |
| @@ -1993,7 +2023,11 @@ fn write_delta_q( | |||
| 1993 | // under `EC_AV1_SB128` -- decode.rs `maybe_read_delta_q` gates on | 2023 | // under `EC_AV1_SB128` -- decode.rs `maybe_read_delta_q` gates on |
| 1994 | // `sb_mi_cur`, and a writer gating on a hardcoded 64 codes three | 2024 | // `sb_mi_cur`, and a writer gating on a hardcoded 64 codes three |
| 1995 | // symbol groups per 128 root the reader never reads. | 2025 | // 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 | + }; | ||
| 1997 | if mi.0 % sb_mi != 0 || mi.1 % sb_mi != 0 { | 2031 | if mi.0 % sb_mi != 0 || mi.1 % sb_mi != 0 { |
| 1998 | return; | 2032 | return; |
| 1999 | } | 2033 | } |
| @@ -2820,9 +2854,9 @@ impl Quadrant { | |||
| 2820 | Quadrant::Whole(block) | Quadrant::Whole64(block) | Quadrant::Whole128(block) => { | 2854 | Quadrant::Whole(block) | Quadrant::Whole64(block) | Quadrant::Whole128(block) => { |
| 2821 | std::slice::from_ref(block) | 2855 | std::slice::from_ref(block) |
| 2822 | } | 2856 | } |
| 2823 | - Quadrant::Split(blocks) | 2857 | + Quadrant::Split(blocks) | Quadrant::Rect128(_, blocks) | Quadrant::Ab128(_, blocks) => { |
| 2824 | - | Quadrant::Rect128(_, blocks) | 2858 | + blocks.as_slice() |
| 2825 | - | Quadrant::Ab128(_, blocks) => blocks.as_slice(), | 2859 | + } |
| 2826 | Quadrant::Covered => &[], | 2860 | Quadrant::Covered => &[], |
| 2827 | } | 2861 | } |
| 2828 | } | 2862 | } |
| @@ -3040,8 +3074,12 @@ impl Neighbours { | |||
| 3040 | fn start_row(&mut self) { | 3074 | fn start_row(&mut self) { |
| 3041 | self.left.iter_mut().for_each(|l| *l = Default::default()); | 3075 | self.left.iter_mut().for_each(|l| *l = Default::default()); |
| 3042 | self.left_mode.iter_mut().for_each(|m| *m = DC_PRED); | 3076 | self.left_mode.iter_mut().for_each(|m| *m = DC_PRED); |
| 3043 | - self.left_side.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE); | 3077 | + self.left_side |
| 3044 | - self.left_side_mi.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_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); | ||
| 3045 | self.left_skip.iter_mut().for_each(|s| *s = false); | 3083 | self.left_skip.iter_mut().for_each(|s| *s = false); |
| 3046 | self.left_inter.iter_mut().for_each(|i| *i = false); | 3084 | self.left_inter.iter_mut().for_each(|i| *i = false); |
| 3047 | self.left_ref.iter_mut().for_each(|r| *r = -1); | 3085 | self.left_ref.iter_mut().for_each(|r| *r = -1); |
| @@ -3052,7 +3090,9 @@ impl Neighbours { | |||
| 3052 | self.left_txfm.iter_mut().for_each(|t| *t = TXFM_CTX_INIT); | 3090 | self.left_txfm.iter_mut().for_each(|t| *t = TXFM_CTX_INIT); |
| 3053 | self.left_palette_size.iter_mut().for_each(|s| *s = 0); | 3091 | self.left_palette_size.iter_mut().for_each(|s| *s = 0); |
| 3054 | self.left_palette_uv_size.iter_mut().for_each(|s| *s = 0); | 3092 | 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]); | ||
| 3056 | } | 3096 | } |
| 3057 | 3097 | ||
| 3058 | /// `av1_get_palette_mode_ctx` + `av1_get_palette_cache`, mirrored from | 3098 | /// `av1_get_palette_mode_ctx` + `av1_get_palette_cache`, mirrored from |
| @@ -3069,12 +3109,18 @@ impl Neighbours { | |||
| 3069 | let above_ok = r % 16 != 0; | 3109 | let above_ok = r % 16 != 0; |
| 3070 | let above_is_palette = r > 0 && self.above_palette_size[c] > 0; | 3110 | let above_is_palette = r > 0 && self.above_palette_size[c] > 0; |
| 3071 | let (above_n, above_colors) = if above_ok && self.above_palette_size[c] > 0 { | 3111 | 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 | + ) | ||
| 3073 | } else { | 3116 | } else { |
| 3074 | (0, [0u16; 8]) | 3117 | (0, [0u16; 8]) |
| 3075 | }; | 3118 | }; |
| 3076 | let (left_n, left_colors) = if c > 0 && self.left_palette_size[r] > 0 { | 3119 | 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 | + ) | ||
| 3078 | } else { | 3124 | } else { |
| 3079 | (0, [0u16; 8]) | 3125 | (0, [0u16; 8]) |
| 3080 | }; | 3126 | }; |
| @@ -3167,7 +3213,13 @@ impl Neighbours { | |||
| 3167 | /// [`Self::record_palette_y`] for the chroma bands (decode.rs | 3213 | /// [`Self::record_palette_y`] for the chroma bands (decode.rs |
| 3168 | /// `record_palette_uv_rect`) -- `size == 0` clears stale state the same | 3214 | /// `record_palette_uv_rect`) -- `size == 0` clears stale state the same |
| 3169 | /// way, and the span is in LUMA pixels for both planes' bands alike. | 3215 | /// 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 | + ) { | ||
| 3171 | // lane-b128hv: the above band spans the block's WIDTH and the left | 3223 | // lane-b128hv: the above band spans the block's WIDTH and the left |
| 3172 | // band its HEIGHT; identical to the one loop this replaces at w == h. | 3224 | // band its HEIGHT; identical to the one loop this replaces at w == h. |
| 3173 | for cell in 0..(w / MI).max(1) { | 3225 | for cell in 0..(w / MI).max(1) { |
| @@ -3191,7 +3243,13 @@ impl Neighbours { | |||
| 3191 | /// What a just-written block leaves in the palette bands (decode.rs | 3243 | /// What a just-written block leaves in the palette bands (decode.rs |
| 3192 | /// `record_palette_y_rect`): its size and colours over every 4x4 unit it | 3244 | /// `record_palette_y_rect`): its size and colours over every 4x4 unit it |
| 3193 | /// spans, `0` for a block that took no palette. | 3245 | /// 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 | + ) { | ||
| 3195 | // lane-b128hv: the above band spans the block's WIDTH and the left | 3253 | // lane-b128hv: the above band spans the block's WIDTH and the left |
| 3196 | // band its HEIGHT; identical to the one loop this replaces at w == h. | 3254 | // band its HEIGHT; identical to the one loop this replaces at w == h. |
| 3197 | for cell in 0..(w / MI).max(1) { | 3255 | for cell in 0..(w / MI).max(1) { |
| @@ -3216,7 +3274,13 @@ impl Neighbours { | |||
| 3216 | /// of an INTER frame leaves in the two `TXFM_CONTEXT` bands -- its | 3274 | /// of an INTER frame leaves in the two `TXFM_CONTEXT` bands -- its |
| 3217 | /// resolved transform size over the span `(w_px, h_px)`, which for a | 3275 | /// resolved transform size over the span `(w_px, h_px)`, which for a |
| 3218 | /// SKIPPED inter block is its own block size instead. | 3276 | /// 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 | + ) { | ||
| 3220 | for i in 0..h_px / MI { | 3284 | for i in 0..h_px / MI { |
| 3221 | if let Some(cell) = self.left_txfm.get_mut(mi_r + i) { | 3285 | if let Some(cell) = self.left_txfm.get_mut(mi_r + i) { |
| 3222 | *cell = tx_px as u8; | 3286 | *cell = tx_px as u8; |
| @@ -3492,9 +3556,22 @@ impl Neighbours { | |||
| 3492 | /// Writes one inter-frame block's skip flag and inter/intra state into | 3556 | /// Writes one inter-frame block's skip flag and inter/intra state into |
| 3493 | /// every 16x16 column and row it covers, the same span [`Self::record`] | 3557 | /// every 16x16 column and row it covers, the same span [`Self::record`] |
| 3494 | /// fills for the coefficient and mode state. | 3558 | /// 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 | + ) { | ||
| 3496 | let (r, c) = at; | 3567 | 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 | + ); | ||
| 3498 | } | 3575 | } |
| 3499 | 3576 | ||
| 3500 | /// lane-b128hv: [`Self::record_inter_mi`] with independent above (width) | 3577 | /// lane-b128hv: [`Self::record_inter_mi`] with independent above (width) |
| @@ -3572,7 +3649,14 @@ impl Neighbours { | |||
| 3572 | 3649 | ||
| 3573 | /// [`Self::record_inter`] taking the block's position directly in 4x4 | 3650 | /// [`Self::record_inter`] taking the block's position directly in 4x4 |
| 3574 | /// mode-info units, for a block finer than one [`SUB`] slot. | 3651 | /// 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 | + ) { | ||
| 3576 | for cell in 0..side / MI { | 3660 | for cell in 0..side / MI { |
| 3577 | self.above_skip[mi_c + cell] = skip; | 3661 | self.above_skip[mi_c + cell] = skip; |
| 3578 | self.left_skip[mi_r + cell] = skip; | 3662 | self.left_skip[mi_r + cell] = skip; |
| @@ -3838,7 +3922,16 @@ pub(crate) fn sb_coeff_key_frame_tile_cdfs( | |||
| 3838 | neighbours.start_row(); | 3922 | neighbours.start_row(); |
| 3839 | } | 3923 | } |
| 3840 | if sb128 && sb_start { | 3924 | 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 | + ); | ||
| 3842 | } | 3935 | } |
| 3843 | { | 3936 | { |
| 3844 | if !sb128 { | 3937 | if !sb128 { |
| @@ -4316,7 +4409,12 @@ fn write_palette_colors_y(enc: &mut SymbolEncoder, colors: &[u16], cache: &[u16] | |||
| 4316 | /// below sees, so it only ever makes the encoder take FEWER chroma palettes | 4409 | /// below sees, so it only ever makes the encoder take FEWER chroma palettes |
| 4317 | /// than it should -- never a wrong stream. Upgrade path: price both forms | 4410 | /// than it should -- never a wrong stream. Upgrade path: price both forms |
| 4318 | /// here and write the cheaper one under its own leading bit. | 4411 | /// 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 | +) { | ||
| 4320 | let n = u_colors.len(); | 4418 | let n = u_colors.len(); |
| 4321 | let mut cached: Vec<u16> = Vec::with_capacity(n); | 4419 | let mut cached: Vec<u16> = Vec::with_capacity(n); |
| 4322 | for &c in cache { | 4420 | for &c in cache { |
| @@ -4441,7 +4539,14 @@ pub(crate) fn palette_uv_bits(pal: &PaletteUv, side: usize, on: (usize, usize)) | |||
| 4441 | enc.symbol(n - 2, &mut size_cdf); | 4539 | enc.symbol(n - 2, &mut size_cdf); |
| 4442 | write_palette_colors_uv(&mut enc, &pal.u_colors[..n], &pal.v_colors[..n], &[]); | 4540 | write_palette_colors_uv(&mut enc, &pal.u_colors[..n], &pal.v_colors[..n], &[]); |
| 4443 | let mut idx_cdfs = cdf::PALETTE_UV_COLOR_INDEX[n - 2]; | 4541 | 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 | + ); | ||
| 4445 | enc.bits() | 4550 | enc.bits() |
| 4446 | } | 4551 | } |
| 4447 | 4552 | ||
| @@ -4552,7 +4657,12 @@ fn write_dv_component(enc: &mut SymbolEncoder, c: &mut MvComponentCdfs, diff: i3 | |||
| 4552 | 4657 | ||
| 4553 | /// One intrabc block's DV as a residual against [`intrabc_dv_pred`], off the | 4658 | /// One intrabc block's DV as a residual against [`intrabc_dv_pred`], off the |
| 4554 | /// `dv` nmv context (decode.rs `read_intrabc_dv` -> `read_mv`). | 4659 | /// `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<()> { | ||
| 4556 | let diff = (dv.0 - pred.0, dv.1 - pred.1); | 4666 | let diff = (dv.0 - pred.0, dv.1 - pred.1); |
| 4557 | let joint = match (diff.0 != 0, diff.1 != 0) { | 4667 | let joint = match (diff.0 != 0, diff.1 != 0) { |
| 4558 | (false, false) => 0, | 4668 | (false, false) => 0, |
| @@ -4584,7 +4694,8 @@ fn write_intrabc_block( | |||
| 4584 | mi: (usize, usize), | 4694 | mi: (usize, usize), |
| 4585 | side: usize, | 4695 | side: usize, |
| 4586 | ) -> Result<()> { | 4696 | ) -> 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]); | ||
| 4588 | enc.symbol(1, &mut cdfs.skip[skip_ctx]); | 4699 | enc.symbol(1, &mut cdfs.skip[skip_ctx]); |
| 4589 | write_cdef_idx(enc, mi, true); | 4700 | write_cdef_idx(enc, mi, true); |
| 4590 | enc.symbol(1, &mut cdfs.intrabc); | 4701 | enc.symbol(1, &mut cdfs.intrabc); |
| @@ -4705,7 +4816,8 @@ fn write_intra_mode( | |||
| 4705 | // above + left. Every block this writer codes outside an `allow_intrabc` | 4816 | // above + left. Every block this writer codes outside an `allow_intrabc` |
| 4706 | // frame is unskipped, so both bands stay false and this stays 0 -- the | 4817 | // frame is unskipped, so both bands stay false and this stays 0 -- the |
| 4707 | // literal every stream before this lane was written with. | 4818 | // 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]); | ||
| 4709 | enc.symbol(0, &mut cdfs.skip[skip_ctx]); | 4821 | enc.symbol(0, &mut cdfs.skip[skip_ctx]); |
| 4710 | write_cdef_idx(enc, mi, false); | 4822 | write_cdef_idx(enc, mi, false); |
| 4711 | // `read_intrabc_info` (spec 5.11.13): the flag is read for EVERY intra | 4823 | // `read_intrabc_info` (spec 5.11.13): the flag is read for EVERY intra |
| @@ -4737,7 +4849,9 @@ fn write_intra_mode( | |||
| 4737 | write_cfl_alphas( | 4849 | write_cfl_alphas( |
| 4738 | enc, | 4850 | enc, |
| 4739 | cdfs, | 4851 | 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"), | ||
| 4741 | ); | 4855 | ); |
| 4742 | } | 4856 | } |
| 4743 | // `angle_delta_uv` (spec `read_intra_angle_info`) off the same CDF array | 4857 | // `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] = | |||
| 4890 | /// i.e. palette blocks this writer cut at the frame's right/bottom mi edge. | 5004 | /// i.e. palette blocks this writer cut at the frame's right/bottom mi edge. |
| 4891 | /// A gate asserts it non-zero so it cannot pass on a stream that never cuts | 5005 | /// A gate asserts it non-zero so it cannot pass on a stream that never cuts |
| 4892 | /// one (class `gate-blind-to-feature`). | 5006 | /// one (class `gate-blind-to-feature`). |
| 4893 | -static PALETTE_CUT_MAPS: std::sync::atomic::AtomicUsize = | 5007 | +static PALETTE_CUT_MAPS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); |
| 4894 | - std::sync::atomic::AtomicUsize::new(0); | ||
| 4895 | 5008 | ||
| 4896 | /// Current value of [`PALETTE_CUT_MAPS`] (colour-index maps). | 5009 | /// Current value of [`PALETTE_CUT_MAPS`] (colour-index maps). |
| 4897 | pub fn palette_cut_maps_written() -> usize { | 5010 | pub fn palette_cut_maps_written() -> usize { |
| @@ -4975,15 +5088,7 @@ fn write_block( | |||
| 4975 | } | 5088 | } |
| 4976 | let (above_mode, left_mode) = (neighbours.above_mode[c], neighbours.left_mode[r]); | 5089 | let (above_mode, left_mode) = (neighbours.above_mode[c], neighbours.left_mode[r]); |
| 4977 | let mode = write_intra_mode( | 5090 | let mode = write_intra_mode( |
| 4978 | - enc, | 5091 | + enc, cdfs, neighbours, block, above_mode, left_mode, cfl, at_mi, side, |
| 4979 | - cdfs, | ||
| 4980 | - neighbours, | ||
| 4981 | - block, | ||
| 4982 | - above_mode, | ||
| 4983 | - left_mode, | ||
| 4984 | - cfl, | ||
| 4985 | - at_mi, | ||
| 4986 | - side, | ||
| 4987 | ); | 5092 | ); |
| 4988 | // The coefficient tables read `fimode_to_intradir[filter_intra_mode]`'s | 5093 | // The coefficient tables read `fimode_to_intradir[filter_intra_mode]`'s |
| 4989 | // row on a filter-intra block; the neighbour publication below still gets | 5094 | // row on a filter-intra block; the neighbour publication below still gets |
| @@ -5085,7 +5190,9 @@ fn write_leaf8( | |||
| 5085 | // true first divergence (a differently-sized alphabet under the same | 5190 | // true first divergence (a differently-sized alphabet under the same |
| 5086 | // DC_PRED decision desyncs the coder even though the decoded mode is | 5191 | // DC_PRED decision desyncs the coder even though the decoded mode is |
| 5087 | // unchanged). | 5192 | // 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 | + ); | ||
| 5089 | let planes = [TxbSet::Luma8, TxbSet::Chroma4, TxbSet::Chroma4]; | 5196 | let planes = [TxbSet::Luma8, TxbSet::Chroma4, TxbSet::Chroma4]; |
| 5090 | // As [`write_block`]: the coefficient row follows the filter-intra mode, | 5197 | // As [`write_block`]: the coefficient row follows the filter-intra mode, |
| 5091 | // the mode this leaf publishes (and returns to the next leaf) does not. | 5198 | // the mode this leaf publishes (and returns to the next leaf) does not. |
| @@ -5218,7 +5325,11 @@ fn write_block_planes( | |||
| 5218 | /// The single luma transform type a block carries, `DCT_DCT` for one that | 5325 | /// The single luma transform type a block carries, `DCT_DCT` for one that |
| 5219 | /// never searched one (lane-txset). | 5326 | /// never searched one (lane-txset). |
| 5220 | fn block_tx_type(block: &BlockCoeffs) -> TxType { | 5327 | 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) | ||
| 5222 | } | 5333 | } |
| 5223 | 5334 | ||
| 5224 | /// The `(side / tx)^2` transform units of one block's luma residual, raster | 5335 | /// The `(side / tx)^2` transform units of one block's luma residual, raster |
| @@ -5294,9 +5405,7 @@ fn write_luma_tus( | |||
| 5294 | grid.to_vec() | 5405 | grid.to_vec() |
| 5295 | } else { | 5406 | } else { |
| 5296 | (0..tx) | 5407 | (0..tx) |
| 5297 | - .flat_map(|row| { | 5408 | + .flat_map(|row| grid[(tu_row * tx + row) * side + tu_col * tx..][..tx].to_vec()) |
| 5298 | - grid[(tu_row * tx + row) * side + tu_col * tx..][..tx].to_vec() | ||
| 5299 | - }) | ||
| 5300 | .collect() | 5409 | .collect() |
| 5301 | }; | 5410 | }; |
| 5302 | // spec `get_txb_ctx_general`: a lone transform unit covering its | 5411 | // spec `get_txb_ctx_general`: a lone transform unit covering its |
| @@ -5381,7 +5490,9 @@ fn write_luma_select( | |||
| 5381 | } | 5490 | } |
| 5382 | } | 5491 | } |
| 5383 | let tx = max_tx >> depth; | 5492 | 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 | + )?; | ||
| 5385 | neighbours.record_tx(at_mi, side, tx); | 5496 | neighbours.record_tx(at_mi, side, tx); |
| 5386 | Ok(tx) | 5497 | Ok(tx) |
| 5387 | } | 5498 | } |
| @@ -5681,7 +5792,9 @@ pub(crate) fn predicted_coeff_bits(blocks: &[Quadrant], base_q_idx: u8) -> f64 { | |||
| 5681 | .map(|tu| { | 5792 | .map(|tu| { |
| 5682 | let (r0, c0) = ((tu / 2) * 32, (tu % 2) * 32); | 5793 | let (r0, c0) = ((tu / 2) * 32, (tu % 2) * 32); |
| 5683 | let unit: Vec<i32> = (0..32) | 5794 | 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 | + }) | ||
| 5685 | .collect(); | 5798 | .collect(); |
| 5686 | coeff_bits(&unit, TxbSet::Luma32Inter, q_ctx, 0, 0) | 5799 | coeff_bits(&unit, TxbSet::Luma32Inter, q_ctx, 0, 0) |
| 5687 | }) | 5800 | }) |
| @@ -5696,7 +5809,10 @@ pub(crate) fn predicted_coeff_bits(blocks: &[Quadrant], base_q_idx: u8) -> f64 { | |||
| 5696 | } | 5809 | } |
| 5697 | Quadrant::Covered => return 0.0, | 5810 | Quadrant::Covered => return 0.0, |
| 5698 | }; | 5811 | }; |
| 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>() | ||
| 5700 | }) | 5816 | }) |
| 5701 | .sum() | 5817 | .sum() |
| 5702 | } | 5818 | } |
| @@ -5764,7 +5880,7 @@ fn scan_of(side: usize) -> &'static Vec<u16> { | |||
| 5764 | /// DECODER's own table so the two cannot drift, cached per size and class. | 5880 | /// DECODER's own table so the two cannot drift, cached per size and class. |
| 5765 | fn class_scan_of(side: usize, class: crate::decode::TxClass) -> &'static [u16] { | 5881 | fn class_scan_of(side: usize, class: crate::decode::TxClass) -> &'static [u16] { |
| 5766 | static SCANS: LazyLock<[[Vec<u16>; 2]; 4]> = LazyLock::new(|| { | 5882 | 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}; |
| 5768 | [TX4, TX8, TX16, TX32].map(|side| { | 5884 | [TX4, TX8, TX16, TX32].map(|side| { |
| 5769 | [ | 5885 | [ |
| 5770 | class_scan_table(side, TxClass::Horiz), | 5886 | class_scan_table(side, TxClass::Horiz), |
| @@ -5846,7 +5962,16 @@ pub(crate) fn coeff_bits_typed( | |||
| 5846 | } | 5962 | } |
| 5847 | let scan = scan_of(coding.side); | 5963 | let scan = scan_of(coding.side); |
| 5848 | let mut enc = SymbolEncoder::pricer(); | 5964 | 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 | + ); | ||
| 5850 | enc.bits() | 5975 | enc.bits() |
| 5851 | }; | 5976 | }; |
| 5852 | // lane-av1speed2: 60% of the transform units of an inter stream hold no | 5977 | // lane-av1speed2: 60% of the transform units of an inter stream hold no |
| @@ -5866,12 +5991,20 @@ pub(crate) fn coeff_bits_typed( | |||
| 5866 | let all_zero = grid.iter().all(|&level| level == 0); | 5991 | let all_zero = grid.iter().all(|&level| level == 0); |
| 5867 | PRICING_BASE.with_borrow_mut(|base| { | 5992 | PRICING_BASE.with_borrow_mut(|base| { |
| 5868 | if let Some(slot) = base.as_deref_mut().filter(|s| s.0.q_ctx == q_ctx) { | 5993 | 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 | + }; | ||
| 5870 | } | 5999 | } |
| 5871 | PRICING.with_borrow_mut(|slots| { | 6000 | PRICING.with_borrow_mut(|slots| { |
| 5872 | let slot = slots[q_ctx.min(3)] | 6001 | let slot = slots[q_ctx.min(3)] |
| 5873 | .get_or_insert_with(|| Box::new((Cdfs::new(q_ctx), Cdfs::new(q_ctx)))); | 6002 | .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 | + } | ||
| 5875 | }) | 6008 | }) |
| 5876 | }) | 6009 | }) |
| 5877 | } | 6010 | } |
| @@ -5951,7 +6084,11 @@ pub(crate) fn rdoq( | |||
| 5951 | // is what the writer and the pricer take (`coded_corner`). | 6084 | // is what the writer and the pricer take (`coded_corner`). |
| 5952 | let coded = side.min(TX32); | 6085 | let coded = side.min(TX32); |
| 5953 | let q_ctx = crate::decode::q_ctx_of(base_q_idx); | 6086 | 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 | + }; | ||
| 5955 | fn price( | 6092 | fn price( |
| 5956 | levels: &[i32], | 6093 | levels: &[i32], |
| 5957 | dense: &mut [i32], | 6094 | dense: &mut [i32], |
| @@ -5971,7 +6108,9 @@ pub(crate) fn rdoq( | |||
| 5971 | } | 6108 | } |
| 5972 | coeff_bits_typed(dense, set, q_ctx, skip_ctx, sign_ctx, tx_type) | 6109 | coeff_bits_typed(dense, set, q_ctx, skip_ctx, sign_ctx, tx_type) |
| 5973 | } | 6110 | } |
| 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 | + ); | ||
| 5975 | // The DC has its own quantiser, so its squared error per unit of level is | 6114 | // The DC has its own quantiser, so its squared error per unit of level is |
| 5976 | // `(dc_q / ac_q)^2` of an AC coefficient's. | 6115 | // `(dc_q / ac_q)^2` of an AC coefficient's. |
| 5977 | let dc = f64::from(crate::quant::dc_q(8, i32::from(base_q_idx))); | 6116 | let dc = f64::from(crate::quant::dc_q(8, i32::from(base_q_idx))); |
| @@ -6022,9 +6161,11 @@ pub(crate) fn rdoq( | |||
| 6022 | let candidate = level - level.signum(); | 6161 | let candidate = level - level.signum(); |
| 6023 | levels[i] = candidate; | 6162 | levels[i] = candidate; |
| 6024 | budget -= 1; | 6163 | budget -= 1; |
| 6025 | - let after = price(levels, &mut dense, side, coded, set, q_ctx, skip_ctx, sign_ctx, tx_type); | 6164 | + let after = price( |
| 6026 | - let distortion = weight | 6165 | + levels, &mut dense, side, coded, set, q_ctx, skip_ctx, sign_ctx, tx_type, |
| 6027 | - * ((s - f64::from(candidate)).powi(2) - (s - f64::from(level)).powi(2)); | 6166 | + ); |
| 6167 | + let distortion = | ||
| 6168 | + weight * ((s - f64::from(candidate)).powi(2) - (s - f64::from(level)).powi(2)); | ||
| 6028 | if distortion + lambda * (after - bits) < 0.0 { | 6169 | if distortion + lambda * (after - bits) < 0.0 { |
| 6029 | bits = after; | 6170 | bits = after; |
| 6030 | if census { | 6171 | if census { |
| @@ -6049,8 +6190,14 @@ pub(crate) fn rdoq( | |||
| 6049 | /// at the end of the scan), zeroed coefficients, lowered coefficients, bits | 6190 | /// at the end of the scan), zeroed coefficients, lowered coefficients, bits |
| 6050 | /// after the pass * 64, bits before the pass * 64. | 6191 | /// after the pass * 64, bits before the pass * 64. |
| 6051 | pub(crate) static RDOQ_STATS: [AtomicU64; 8] = [ | 6192 | pub(crate) static RDOQ_STATS: [AtomicU64; 8] = [ |
| 6052 | - AtomicU64::new(0), AtomicU64::new(0), AtomicU64::new(0), AtomicU64::new(0), | 6193 | + AtomicU64::new(0), |
| 6053 | - AtomicU64::new(0), AtomicU64::new(0), AtomicU64::new(0), 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), | ||
| 6054 | ]; | 6201 | ]; |
| 6055 | 6202 | ||
| 6056 | /// The pre-pass half of [`RDOQ_STATS`] (`EC_AV1_RDOQ_CENSUS`): what the | 6203 | /// The pre-pass half of [`RDOQ_STATS`] (`EC_AV1_RDOQ_CENSUS`): what the |
| @@ -6146,11 +6293,13 @@ thread_local! { | |||
| 6146 | /// at native, still with every one of its frames armed with the defaults. | 6293 | /// at native, still with every one of its frames armed with the defaults. |
| 6147 | pub(crate) fn arm_pricing_cdfs(base: Option<&Cdfs>, screen: bool) { | 6294 | pub(crate) fn arm_pricing_cdfs(base: Option<&Cdfs>, screen: bool) { |
| 6148 | static MODE: std::sync::OnceLock<u8> = std::sync::OnceLock::new(); | 6295 | 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() { | 6296 | + let mode = *MODE.get_or_init( |
| 6297 | + || match std::env::var("EC_AV1_PRICE_FRAME_CDFS").as_deref() { | ||
| 6150 | Ok("0") => 0, | 6298 | Ok("0") => 0, |
| 6151 | Ok("1") => 1, | 6299 | Ok("1") => 1, |
| 6152 | _ => 2, | 6300 | _ => 2, |
| 6153 | - }); | 6301 | + }, |
| 6302 | + ); | ||
| 6154 | let on = match mode { | 6303 | let on = match mode { |
| 6155 | 0 => false, | 6304 | 0 => false, |
| 6156 | 1 => true, | 6305 | 1 => true, |
| @@ -6158,7 +6307,9 @@ pub(crate) fn arm_pricing_cdfs(base: Option<&Cdfs>, screen: bool) { | |||
| 6158 | }; | 6307 | }; |
| 6159 | PRICING_HITS[usize::from(on && base.is_some())].fetch_add(1, Ordering::Relaxed); | 6308 | PRICING_HITS[usize::from(on && base.is_some())].fetch_add(1, Ordering::Relaxed); |
| 6160 | PRICING_BASE.with_borrow_mut(|slot| { | 6309 | 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()))); | ||
| 6162 | }); | 6313 | }); |
| 6163 | } | 6314 | } |
| 6164 | 6315 | ||
| @@ -6166,8 +6317,7 @@ pub(crate) fn arm_pricing_cdfs(base: Option<&Cdfs>, screen: bool) { | |||
| 6166 | /// many with the frame's REAL starting tables ([`arm_pricing_cdfs`]), so a | 6317 | /// many with the frame's REAL starting tables ([`arm_pricing_cdfs`]), so a |
| 6167 | /// gate can print which side of the screen gate every frame landed on. Counts | 6318 | /// gate can print which side of the screen gate every frame landed on. Counts |
| 6168 | /// arming calls, not frames: a multi-tile frame arms one worker per tile. | 6319 | /// arming calls, not frames: a multi-tile frame arms one worker per tile. |
| 6169 | -pub(crate) static PRICING_HITS: [AtomicUsize; 2] = | 6320 | +pub(crate) static PRICING_HITS: [AtomicUsize; 2] = [AtomicUsize::new(0), AtomicUsize::new(0)]; |
| 6170 | - [AtomicUsize::new(0), AtomicUsize::new(0)]; | ||
| 6171 | 6321 | ||
| 6172 | /// Reads and clears [`PRICING_HITS`]: (default-table armings, real-table | 6322 | /// Reads and clears [`PRICING_HITS`]: (default-table armings, real-table |
| 6173 | /// armings). | 6323 | /// armings). |
| @@ -6389,7 +6539,10 @@ fn write_coeffs( | |||
| 6389 | // lane-av1speed3: `side` is 4, 8, 16 or 32, but it is a runtime value -- | 6539 | // lane-av1speed3: `side` is 4, 8, 16 or 32, but it is a runtime value -- |
| 6390 | // `pos / side` compiles to a real integer division, once per coefficient, | 6540 | // `pos / side` compiles to a real integer division, once per coefficient, |
| 6391 | // in the encoder's largest self-time symbol. Same row and column. | 6541 | // 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 | + ); | ||
| 6393 | let (shift, mask) = (side.trailing_zeros(), side - 1); | 6546 | let (shift, mask) = (side.trailing_zeros(), side - 1); |
| 6394 | for scan_idx in (0..eob).rev() { | 6547 | for scan_idx in (0..eob).rev() { |
| 6395 | let pos = scan[scan_idx] as usize; | 6548 | let pos = scan[scan_idx] as usize; |
| @@ -6649,7 +6802,11 @@ fn br_ctx( | |||
| 6649 | if row == 0 && col == 0 { | 6802 | if row == 0 && col == 0 { |
| 6650 | return mag; | 6803 | return mag; |
| 6651 | } | 6804 | } |
| 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 | + }; | ||
| 6653 | return if near_origin { mag + 7 } else { mag + 14 }; | 6810 | return if near_origin { mag + 7 } else { mag + 14 }; |
| 6654 | } | 6811 | } |
| 6655 | let p = row * side + col; | 6812 | let p = row * side + col; |
| @@ -6800,7 +6957,11 @@ pub(crate) fn intra_inter_ctx( | |||
| 6800 | /// `CLASS0_SIZE << (class + 2)` (spec 3), the magnitude an `MV_CLASS_n` | 6957 | /// `CLASS0_SIZE << (class + 2)` (spec 3), the magnitude an `MV_CLASS_n` |
| 6801 | /// component's own bits start counting from; class zero starts at zero. | 6958 | /// component's own bits start counting from; class zero starts at zero. |
| 6802 | fn mv_class_base(class: usize) -> i32 { | 6959 | 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 | + } | ||
| 6804 | } | 6965 | } |
| 6805 | 6966 | ||
| 6806 | /// The class a pre-offset magnitude `z` (`|diff| - 1`) falls in — the inverse | 6967 | /// The class a pre-offset magnitude `z` (`|diff| - 1`) falls in — the inverse |
| @@ -6923,11 +7084,12 @@ fn write_single_ref( | |||
| 6923 | left_ref: i8, | 7084 | left_ref: i8, |
| 6924 | left_ref1: Option<i8>, | 7085 | left_ref1: Option<i8>, |
| 6925 | ) { | 7086 | ) { |
| 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); | ||
| 6927 | use crate::mvstack::{ | 7089 | use crate::mvstack::{ |
| 6928 | - ALTREF2_FRAME, ALTREF_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST2_FRAME, LAST3_FRAME, | ||
| 6929 | single_ref_p1_ctx, single_ref_p2_ctx, single_ref_p3_ctx, single_ref_p4_ctx, | 7090 | 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, | ||
| 6931 | }; | 7093 | }; |
| 6932 | let above = (above_ref > 0).then_some(above_ref); | 7094 | let above = (above_ref > 0).then_some(above_ref); |
| 6933 | let left = (left_ref > 0).then_some(left_ref); | 7095 | let left = (left_ref > 0).then_some(left_ref); |
| @@ -7071,7 +7233,10 @@ pub(crate) fn take_drl_hits() -> [usize; 4] { | |||
| 7071 | /// pricer's own offer set is enumerated against this rule by | 7233 | /// pricer's own offer set is enumerated against this rule by |
| 7072 | /// `crate::encode::tests::every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal`. | 7234 | /// `crate::encode::tests::every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal`. |
| 7073 | pub(crate) fn signalled_drl_idx(entries: usize, start: usize, target: usize) -> usize { | 7235 | 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) | ||
| 7075 | } | 7240 | } |
| 7076 | 7241 | ||
| 7077 | fn write_drl_idx( | 7242 | fn write_drl_idx( |
| @@ -7335,12 +7500,7 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 7335 | let scan4 = default_scan(TX4); | 7500 | let scan4 = default_scan(TX4); |
| 7336 | // The same four tables again as one array, which is what the per-unit | 7501 | // The same four tables again as one array, which is what the per-unit |
| 7337 | // luma writer indexes by transform side. | 7502 | // luma writer indexes by transform side. |
| 7338 | - let all_scans = [ | 7503 | + let all_scans = [scan32.clone(), scan16.clone(), scan8.clone(), scan4.clone()]; |
| 7339 | - scan32.clone(), | ||
| 7340 | - scan16.clone(), | ||
| 7341 | - scan8.clone(), | ||
| 7342 | - scan4.clone(), | ||
| 7343 | - ]; | ||
| 7344 | let zero_grids = [ | 7504 | let zero_grids = [ |
| 7345 | vec![0i32; TX32 * TX32], | 7505 | vec![0i32; TX32 * TX32], |
| 7346 | vec![0i32; TX16 * TX16], | 7506 | vec![0i32; TX16 * TX16], |
| @@ -7431,7 +7591,10 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 7431 | // (mi_row, mi_col) and a second one at + hbs (16 mi) along the | 7591 | // (mi_row, mi_col) and a second one at + hbs (16 mi) along the |
| 7432 | // cut axis, the second only when it is inside the frame -- the | 7592 | // cut axis, the second only when it is inside the frame -- the |
| 7433 | // search only offers a root wholly inside, so both are. | 7593 | // 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 | + ); | ||
| 7435 | let (w, h) = if horz { (128usize, 64usize) } else { (64, 128) }; | 7598 | let (w, h) = if horz { (128usize, 64usize) } else { (64, 128) }; |
| 7436 | for (i, half) in halves.iter().enumerate() { | 7599 | for (i, half) in halves.iter().enumerate() { |
| 7437 | let at_mi = if horz { | 7600 | let at_mi = if horz { |
| @@ -7467,8 +7630,9 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 7467 | (sb_r & !1) as usize * SB_MI as usize, | 7630 | (sb_r & !1) as usize * SB_MI as usize, |
| 7468 | (sb_c & !1) as usize * SB_MI as usize, | 7631 | (sb_c & !1) as usize * SB_MI as usize, |
| 7469 | ); | 7632 | ); |
| 7470 | - for (((mi_r, mi_c), (w, h)), piece) in | 7633 | + for (((mi_r, mi_c), (w, h)), piece) in crate::encode::ab128_pieces(symbol, base_mi) |
| 7471 | - crate::encode::ab128_pieces(symbol, base_mi).iter().zip(pieces) | 7634 | + .iter() |
| 7635 | + .zip(pieces) | ||
| 7472 | { | 7636 | { |
| 7473 | write_inter_block_128_rect( | 7637 | write_inter_block_128_rect( |
| 7474 | &mut enc, | 7638 | &mut enc, |
| @@ -7532,7 +7696,13 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 7532 | + usize::from(neighbours.left_skip[mi_r]); | 7696 | + usize::from(neighbours.left_skip[mi_r]); |
| 7533 | enc.symbol(usize::from(block.skip), &mut cdfs.skip[skip_ctx]); | 7697 | enc.symbol(usize::from(block.skip), &mut cdfs.skip[skip_ctx]); |
| 7534 | write_cdef_idx(&mut enc, (mi_r, mi_c), block.skip); | 7698 | 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 | + ); | ||
| 7536 | let ii_ctx = intra_inter_ctx( | 7706 | let ii_ctx = intra_inter_ctx( |
| 7537 | has_above, | 7707 | has_above, |
| 7538 | has_left, | 7708 | has_left, |
| @@ -7926,7 +8096,6 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 7926 | // caller (r15): the SUB-grid skip/inter arrays | 8096 | // caller (r15): the SUB-grid skip/inter arrays |
| 7927 | // are otherwise left stale for the next | 8097 | // are otherwise left stale for the next |
| 7928 | // 16x16 slot. | 8098 | // 16x16 slot. |
| 7929 | - | ||
| 7930 | } | 8099 | } |
| 7931 | } | 8100 | } |
| 7932 | continue; | 8101 | continue; |
| @@ -7951,16 +8120,33 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 7951 | 8120 | ||
| 7952 | let mode_for_tx; | 8121 | let mode_for_tx; |
| 7953 | if let Some(info) = block.inter { | 8122 | 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 | + ); | ||
| 7955 | let (mi_row, mi_col) = (r32 as usize * 8, c32 as usize * 8); | 8131 | let (mi_row, mi_col) = (r32 as usize * 8, c32 as usize * 8); |
| 7956 | if info.ref1.is_some() { | 8132 | if info.ref1.is_some() { |
| 7957 | let (mv, mv1, is_new_mv) = write_compound_block( | 8133 | let (mv, mv1, is_new_mv) = write_compound_block( |
| 7958 | - &mut enc, &mut cdfs, &neighbours, &grid, (mi_row, mi_col), (8, 8), | 8134 | + &mut enc, |
| 7959 | - (has_above, has_left), info, (mi_cols as usize, mi_rows as usize), | 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), | ||
| 7960 | )?; | 8143 | )?; |
| 7961 | for dr in 0..8 { | 8144 | for dr in 0..8 { |
| 7962 | for dc in 0..8 { | 8145 | for dc in 0..8 { |
| 7963 | - grid.set(mi_row + dr, mi_col + dc, MiInfo { | 8146 | + grid.set( |
| 8147 | + mi_row + dr, | ||
| 8148 | + mi_col + dc, | ||
| 8149 | + MiInfo { | ||
| 7964 | is_inter: true, | 8150 | is_inter: true, |
| 7965 | ref_frame: info.ref_frame, | 8151 | ref_frame: info.ref_frame, |
| 7966 | ref_frame1: info.ref1.unwrap_or(NO_REF1), | 8152 | ref_frame1: info.ref1.unwrap_or(NO_REF1), |
| @@ -7971,12 +8157,21 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | |||
| 7971 | size_h: 8, | 8157 | size_h: 8, |
| 7972 | is_global_mv0: false, | 8158 | is_global_mv0: false, |
| 7973 | is_global_mv1: false, | 8159 | is_global_mv1: false, |
| 7974 | - }); | 8160 | + }, |
| 8161 | + ); | ||
| 7975 | } | 8162 | } |
| 7976 | } | 8163 | } |
| 7977 | mode_for_tx = 0; | 8164 | mode_for_tx = 0; |
| 7978 | } else { | 8165 | } 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 | + ); | ||
| 7980 | 8175 | ||
| 7981 | let stack = find_mv_stack( | 8176 | let stack = find_mv_stack( |
| 7982 | &grid, | 8177 | &grid, |
| @@ -8208,7 +8403,8 @@ fn write_inter_frame_leaf( | |||
| 8208 | 8403 | ||
| 8209 | let (r, c) = at; | 8404 | let (r, c) = at; |
| 8210 | let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); | 8405 | 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]); | ||
| 8212 | enc.symbol(usize::from(block.skip), &mut cdfs.skip[skip_ctx]); | 8408 | enc.symbol(usize::from(block.skip), &mut cdfs.skip[skip_ctx]); |
| 8213 | write_cdef_idx(enc, (mi_r, mi_c), block.skip); | 8409 | write_cdef_idx(enc, (mi_r, mi_c), block.skip); |
| 8214 | write_delta_q(enc, cdfs, (mi_r, mi_c), false, block.skip); | 8410 | write_delta_q(enc, cdfs, (mi_r, mi_c), false, block.skip); |
| @@ -8221,17 +8417,34 @@ fn write_inter_frame_leaf( | |||
| 8221 | 8417 | ||
| 8222 | let mode_for_tx; | 8418 | let mode_for_tx; |
| 8223 | if let Some(info) = block.inter { | 8419 | 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 | + ); | ||
| 8225 | let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize); | 8428 | let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize); |
| 8226 | if info.ref1.is_some() { | 8429 | if info.ref1.is_some() { |
| 8227 | let n = SUB_MI as usize; | 8430 | let n = SUB_MI as usize; |
| 8228 | let (mv, mv1, is_new_mv) = write_compound_block( | 8431 | let (mv, mv1, is_new_mv) = write_compound_block( |
| 8229 | - enc, cdfs, neighbours, grid, (mi_row, mi_col), (n, n), | 8432 | + enc, |
| 8230 | - (has_above, has_left), info, (mi_cols as usize, mi_rows as usize), | 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), | ||
| 8231 | )?; | 8441 | )?; |
| 8232 | for dr in 0..n { | 8442 | for dr in 0..n { |
| 8233 | for dc in 0..n { | 8443 | for dc in 0..n { |
| 8234 | - grid.set(mi_row + dr, mi_col + dc, MiInfo { | 8444 | + grid.set( |
| 8445 | + mi_row + dr, | ||
| 8446 | + mi_col + dc, | ||
| 8447 | + MiInfo { | ||
| 8235 | is_inter: true, | 8448 | is_inter: true, |
| 8236 | ref_frame: info.ref_frame, | 8449 | ref_frame: info.ref_frame, |
| 8237 | ref_frame1: info.ref1.unwrap_or(NO_REF1), | 8450 | ref_frame1: info.ref1.unwrap_or(NO_REF1), |
| @@ -8242,12 +8455,21 @@ fn write_inter_frame_leaf( | |||
| 8242 | size_h: n as u8, | 8455 | size_h: n as u8, |
| 8243 | is_global_mv0: false, | 8456 | is_global_mv0: false, |
| 8244 | is_global_mv1: false, | 8457 | is_global_mv1: false, |
| 8245 | - }); | 8458 | + }, |
| 8459 | + ); | ||
| 8246 | } | 8460 | } |
| 8247 | } | 8461 | } |
| 8248 | mode_for_tx = 0; | 8462 | mode_for_tx = 0; |
| 8249 | } else { | 8463 | } 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 | + ); | ||
| 8251 | 8473 | ||
| 8252 | let stack = find_mv_stack( | 8474 | let stack = find_mv_stack( |
| 8253 | grid, | 8475 | grid, |
| @@ -8380,7 +8602,16 @@ fn write_inter_frame_leaf( | |||
| 8380 | ]; | 8602 | ]; |
| 8381 | if split { | 8603 | if split { |
| 8382 | write_luma_tus( | 8604 | 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, | ||
| 8384 | &block.luma_tx_types, | 8615 | &block.luma_tx_types, |
| 8385 | )?; | 8616 | )?; |
| 8386 | } | 8617 | } |
| @@ -8467,23 +8698,43 @@ fn write_inter_frame_leaf8( | |||
| 8467 | write_cdef_idx(enc, leaf_mi, block.skip); | 8698 | write_cdef_idx(enc, leaf_mi, block.skip); |
| 8468 | write_delta_q(enc, cdfs, leaf_mi, false, block.skip); | 8699 | write_delta_q(enc, cdfs, leaf_mi, false, block.skip); |
| 8469 | 8700 | ||
| 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 | + ); | ||
| 8471 | let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter); | 8705 | let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter); |
| 8472 | let is_inter = block.inter.is_some(); | 8706 | let is_inter = block.inter.is_some(); |
| 8473 | enc.symbol(usize::from(is_inter), &mut cdfs.intra_inter[ii_ctx]); | 8707 | enc.symbol(usize::from(is_inter), &mut cdfs.intra_inter[ii_ctx]); |
| 8474 | 8708 | ||
| 8475 | let mode_for_tx; | 8709 | let mode_for_tx; |
| 8476 | if let Some(info) = block.inter { | 8710 | 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 | + ); | ||
| 8478 | let (mi_row, mi_col) = leaf_mi; | 8719 | let (mi_row, mi_col) = leaf_mi; |
| 8479 | if info.ref1.is_some() { | 8720 | if info.ref1.is_some() { |
| 8480 | let (mv, mv1, is_new_mv) = write_compound_block( | 8721 | let (mv, mv1, is_new_mv) = write_compound_block( |
| 8481 | - enc, cdfs, neighbours, grid, (mi_row, mi_col), (2, 2), | 8722 | + enc, |
| 8482 | - (has_above, has_left), info, (mi_cols as usize, mi_rows as usize), | 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), | ||
| 8483 | )?; | 8731 | )?; |
| 8484 | for dr in 0..2 { | 8732 | for dr in 0..2 { |
| 8485 | for dc in 0..2 { | 8733 | for dc in 0..2 { |
| 8486 | - grid.set(mi_row + dr, mi_col + dc, MiInfo { | 8734 | + grid.set( |
| 8735 | + mi_row + dr, | ||
| 8736 | + mi_col + dc, | ||
| 8737 | + MiInfo { | ||
| 8487 | is_inter: true, | 8738 | is_inter: true, |
| 8488 | ref_frame: info.ref_frame, | 8739 | ref_frame: info.ref_frame, |
| 8489 | ref_frame1: info.ref1.unwrap_or(NO_REF1), | 8740 | ref_frame1: info.ref1.unwrap_or(NO_REF1), |
| @@ -8494,12 +8745,21 @@ fn write_inter_frame_leaf8( | |||
| 8494 | size_h: 2, | 8745 | size_h: 2, |
| 8495 | is_global_mv0: false, | 8746 | is_global_mv0: false, |
| 8496 | is_global_mv1: false, | 8747 | is_global_mv1: false, |
| 8497 | - }); | 8748 | + }, |
| 8749 | + ); | ||
| 8498 | } | 8750 | } |
| 8499 | } | 8751 | } |
| 8500 | mode_for_tx = 0; | 8752 | mode_for_tx = 0; |
| 8501 | } else { | 8753 | } 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 | + ); | ||
| 8503 | 8763 | ||
| 8504 | let stack = find_mv_stack( | 8764 | let stack = find_mv_stack( |
| 8505 | grid, | 8765 | grid, |
| @@ -8628,7 +8888,13 @@ fn write_inter_frame_leaf8( | |||
| 8628 | vec![0i32; TX4 * TX4], | 8888 | vec![0i32; TX4 * TX4], |
| 8629 | ]; | 8889 | ]; |
| 8630 | neighbours.record_mi(leaf_mi, 8, &zero_grids); | 8890 | 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 | + ); | ||
| 8632 | record_block_compound(neighbours, leaf_mi, 8, block); | 8898 | record_block_compound(neighbours, leaf_mi, 8, block); |
| 8633 | } else { | 8899 | } else { |
| 8634 | let grids = [ | 8900 | let grids = [ |
| @@ -8638,7 +8904,16 @@ fn write_inter_frame_leaf8( | |||
| 8638 | ]; | 8904 | ]; |
| 8639 | if split { | 8905 | if split { |
| 8640 | write_luma_tus( | 8906 | 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, | ||
| 8642 | &block.luma_tx_types, | 8917 | &block.luma_tx_types, |
| 8643 | )?; | 8918 | )?; |
| 8644 | } | 8919 | } |
| @@ -8666,13 +8941,13 @@ mod tests { | |||
| 8666 | use super::*; | 8941 | use super::*; |
| 8667 | use crate::frame::frame_obu; | 8942 | use crate::frame::frame_obu; |
| 8668 | use crate::obu::temporal_delimiter; | 8943 | use crate::obu::temporal_delimiter; |
| 8944 | + use crate::probe::run_with_stdin; | ||
| 8669 | use crate::sequence::sequence_header_obu; | 8945 | use crate::sequence::sequence_header_obu; |
| 8670 | use ec_av1_syntax::sequence::SequenceHeader; | 8946 | use ec_av1_syntax::sequence::SequenceHeader; |
| 8671 | use ec_av1_syntax::{ | 8947 | use ec_av1_syntax::{ |
| 8672 | - FrameHeader, FrameType, LoopFilterParams, PRIMARY_REF_NONE, QuantizationParams, TileInfo, | 8948 | + FrameHeader, FrameType, LoopFilterParams, QuantizationParams, TileInfo, TxMode, |
| 8673 | - TxMode, | 8949 | + PRIMARY_REF_NONE, |
| 8674 | }; | 8950 | }; |
| 8675 | - use std::io::Write; | ||
| 8676 | use std::process::{Command, Stdio}; | 8951 | use std::process::{Command, Stdio}; |
| 8677 | 8952 | ||
| 8678 | /// A 64x64 sequence with every tool this writer does not code turned off: | 8953 | /// A 64x64 sequence with every tool this writer does not code turned off: |
| @@ -8763,29 +9038,12 @@ mod tests { | |||
| 8763 | 9038 | ||
| 8764 | /// Decodes an AV1 OBU stream with ffmpeg and hands back the planes. | 9039 | /// Decodes an AV1 OBU stream with ffmpeg and hands back the planes. |
| 8765 | fn ffmpeg_decode(stream: &[u8], w: usize, h: usize) -> Vec<u8> { | 9040 | fn ffmpeg_decode(stream: &[u8], w: usize, h: usize) -> Vec<u8> { |
| 8766 | - let mut child = Command::new("ffmpeg") | 9041 | + let out = run_with_stdin( |
| 8767 | - .args([ | 9042 | + Command::new("ffmpeg").args([ |
| 8768 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", | 9043 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", |
| 8769 | - ]) | 9044 | + ]), |
| 8770 | - .stdin(Stdio::piped()) | 9045 | + stream, |
| 8771 | - .stdout(Stdio::piped()) | 9046 | + ); |
| 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"); | ||
| 8789 | assert!( | 9047 | assert!( |
| 8790 | out.status.success(), | 9048 | out.status.success(), |
| 8791 | "ffmpeg refused the stream: {}", | 9049 | "ffmpeg refused the stream: {}", |
| @@ -10327,7 +10585,11 @@ mod tests { | |||
| 10327 | .map(|&v| { | 10585 | .map(|&v| { |
| 10328 | let m = f64::from(v).abs() + 0.5; | 10586 | let m = f64::from(v).abs() + 0.5; |
| 10329 | let l = if m < 1.0 { 0 } else { m.floor() as i32 }; | 10587 | 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 | + } | ||
| 10331 | }) | 10593 | }) |
| 10332 | .collect(); | 10594 | .collect(); |
| 10333 | let before = levels.clone(); | 10595 | let before = levels.clone(); |
| @@ -10340,18 +10602,40 @@ mod tests { | |||
| 10340 | .zip(&scaled) | 10602 | .zip(&scaled) |
| 10341 | .enumerate() | 10603 | .enumerate() |
| 10342 | .map(|(i, (&l, &s))| { | 10604 | .map(|(i, (&l, &s))| { |
| 10343 | - (if i == 0 { dc_weight } else { 1.0 }) | 10605 | + (if i == 0 { dc_weight } else { 1.0 }) * (f64::from(s) - f64::from(l)).powi(2) |
| 10344 | - * (f64::from(s) - f64::from(l)).powi(2) | ||
| 10345 | }) | 10606 | }) |
| 10346 | .sum(); | 10607 | .sum(); |
| 10347 | d + lambda * coeff_bits(grid, set, crate::decode::q_ctx_of(q), 0, 0) | 10608 | d + lambda * coeff_bits(grid, set, crate::decode::q_ctx_of(q), 0, 0) |
| 10348 | }; | 10609 | }; |
| 10349 | - let bits = rdoq(&mut levels, &scaled, side, q, set, 0, 0, lambda, TxType::DctDct); | 10610 | + let bits = rdoq( |
| 10350 | - assert_eq!(bits, coeff_bits(&levels, set, crate::decode::q_ctx_of(q), 0, 0)); | 10611 | + &mut levels, |
| 10351 | - assert!(cost(&levels) <= cost(&before), "{:?} vs {:?}", cost(&levels), cost(&before)); | 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 | + ); | ||
| 10352 | // The tail is what it is for: the last coded position moves earlier. | 10631 | // The tail is what it is for: the last coded position moves earlier. |
| 10353 | let last = |g: &[i32]| scan_of(side).iter().rposition(|&p| g[usize::from(p)] != 0); | 10632 | 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 | + ); | ||
| 10355 | // A 64-point transform is priced on its top-left 32x32 corner, and | 10639 | // A 64-point transform is priced on its top-left 32x32 corner, and |
| 10356 | // the pass has to hand back THAT price (the dense path). | 10640 | // the pass has to hand back THAT price (the dense path). |
| 10357 | let (side, set) = (64usize, TxbSet::Luma64); | 10641 | let (side, set) = (64usize, TxbSet::Luma64); |
| @@ -10364,14 +10648,31 @@ mod tests { | |||
| 10364 | .map(|&v| { | 10648 | .map(|&v| { |
| 10365 | let m = f64::from(v).abs() + 0.5; | 10649 | let m = f64::from(v).abs() + 0.5; |
| 10366 | let l = if m < 1.0 { 0 } else { m.floor() as i32 }; | 10650 | 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 | + } | ||
| 10368 | }) | 10656 | }) |
| 10369 | .collect(); | 10657 | .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 | + ); | ||
| 10371 | let corner: Vec<i32> = (0..32) | 10669 | let corner: Vec<i32> = (0..32) |
| 10372 | .flat_map(|row| levels[row * side..][..32].to_vec()) | 10670 | .flat_map(|row| levels[row * side..][..32].to_vec()) |
| 10373 | .collect(); | 10671 | .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 | + ); | ||
| 10375 | } | 10676 | } |
| 10376 | 10677 | ||
| 10377 | #[test] | 10678 | #[test] |
| @@ -10848,7 +11149,11 @@ mod tests { | |||
| 10848 | (d << 3) | (fr << 1) | 1 | 11149 | (d << 3) | (fr << 1) | 1 |
| 10849 | }; | 11150 | }; |
| 10850 | let mag = mv_class_base(class) + local as i32 + 1; | 11151 | 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 | + } | ||
| 10852 | } | 11157 | } |
| 10853 | 11158 | ||
| 10854 | /// Decodes one superblock a [`sb_coeff_inter_frame_tile`] payload wrote, | 11159 | /// Decodes one superblock a [`sb_coeff_inter_frame_tile`] payload wrote, |
lanes/av1pipedrain.report.mdadded+108 -0
| @@ -0,0 +1,108 @@ | |||
| 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 files, +369/−2137 (net −1768 lines of duplicated boilerplate). | ||
| 75 | + | ||
| 76 | +## Verification | ||
| 77 | + | ||
| 78 | +Toolchain: aomenc oracle `~/.cache/aom-oracle/build/aomenc` + affine oracle | ||
| 79 | +`~/.cache/aom-affine/build/aomenc`, system ffmpeg; release test binary; | ||
| 80 | +`EC_AV1_REQUIRE_AOMENC=1 EC_AV1_REQUIRE_FFMPEG=1` (skips fail the run). | ||
| 81 | + | ||
| 82 | +- `cargo check -p ec-av1 --all-targets`: **0 warnings**. | ||
| 83 | +- Stress, previously-flaked gate | ||
| 84 | + `a_real_aomenc_inter_sequence_with_intra_16x4_strips_in_1to4_partitions_\ | ||
| 85 | +decodes_pixel_exact` × 20 sequential runs: | ||
| 86 | + **20/20 pass, 0 fail** (28.3 min wall; each run does the full multi-attempt | ||
| 87 | + encode sweep + pixel compares). | ||
| 88 | +- Scoped battery, 50 gates through the migrated paths (intrabc unblock set | ||
| 89 | + 13, rect14 16x4/4x16 set 5, loss64/lossless set 4, real-aomenc family | ||
| 90 | + 25 incl. tile-rows/columns, tile-group OBUs, sb128 family, obmc, wedge, | ||
| 91 | + comp-mode, temporal-MV, cdef, filter-intra, 1D-tx rect, palette-on-rect, | ||
| 92 | + 10-bit; plus 3 tile::tests ffmpeg-decode helpers): | ||
| 93 | + **50/50 green** (two initially misnamed entries re-checked by exact name, | ||
| 94 | + both pass; census sweeps among them ran their full 20–40 attempt loops). | ||
| 95 | + | ||
| 96 | +## Notes / follow-ups | ||
| 97 | + | ||
| 98 | +- The repo is NOT rustfmt-clean under default `rustfmt --edition 2024` | ||
| 99 | + (pristine stream.rs shows a 7776-line diff), so NO fmt pass was applied — | ||
| 100 | + the change preserves the surrounding formatting style as-is. Any future | ||
| 101 | + "just cargo fmt it" would churn ~40k-line files wholesale; decide that | ||
| 102 | + separately, never inside a content lane. | ||
| 103 | +- `ec-av1-syntax` and `examples/` spawn no aomenc/ffmpeg on piped stdin; | ||
| 104 | + other ec-* crates are out of this lane's scope but share none of these | ||
| 105 | + helpers. | ||
| 106 | +- The helper names the generic spawn/reap failures ("encoder failed to | ||
| 107 | + start/run"); per-gate diagnosis stays in each gate's own | ||
| 108 | + `assert!(status.success(), …)` on stderr, unchanged. | ||