mirror of
https://github.com/storytold/filmcraft.git
synced 2026-11-11 02:30:56 +00:00
* Tests: one integration-test binary per crate Each crate with several tests/*.rs files keeps them as modules of tests/it/, so cargo links one test executable per crate instead of one per file. Files that change process-wide state or time a workload stay binaries of their own. * Profiles: line tables for workspace crates, no debug info for dependencies * Windows ARM64: nightly and on release pushes instead of every push to main * xtask ci: clippy and tests in the dev profile The release profile's thin LTO and single codegen unit made linking the test binaries take most of the gate. The codec and audio crates stay at opt-level 3 in the dev profile, so their tests run at release speed. * xtask ci: nextest, doctests, no examples, one wasm check Tests run with cargo nextest when it is installed (cargo test otherwise) and build with --lib --bins --tests, so examples aren't linked; doctests run separately. The wasm check keeps going past the first failing crate. VP8 fixture generation locks across processes, since nextest runs each test in its own. * VP9 synthetic fixtures: write aside and rename A test in another process could read a fixture ffmpeg was still writing. * Fuzz tests: a third of each sweep by default, all of it with FILMCRAFT_FUZZ_ITERS Every seed, mutation kind and thread count still runs. Header bytes each get one overwrite value and two bit flips in rotation, so every value and bit index still occurs across the region. FILMCRAFT_FUZZ_ITERS=N runs the whole sweep plus N random rounds per seed, as before. * Platform fallback tests: one failure point per hybrid path The failure-anywhere test injected a failure at four points around every restart point; the hybrid's paths differ only in the first GOP, around the second and last restart points, at the end and never. The replay test needs the first two GOPs. * Export tests: shorter ranges with the same checks The bitrate test measures 0.5–1.5 s, where each preset reaches its own target (on 0–3 s the simple demo left two presets at the same rate). The every-preset test exports three frames per preset. * Audio tests: effects in parallel, a table-driven FFT for the Opus quality metric The extreme-settings test keeps both settings and the 40 s tail for every effect, one thread each. The Opus quality metric's FFT builds its twiddles once and allocates nothing per transform (same algorithm and summation order). * CI: dev-profile gate with nextest xtask ci no longer builds with --release, so the release-profile overrides go; nextest is installed for the test step. * CI: apt packages through the cached install-apt-packages action * Review fixes: fuzz tests with a panic hook in their own binaries, loud fixture lock The fuzz tests of av1, h264, hevc, mpeg2v, vp8 and vp9 count panics through a process-wide hook, so a panic in another test of the same process would fail them; they are binaries of their own again. The VP8 fixture lock fails the test instead of skipping it silently, and the full-sweep doc comments say how many truncation points the full run samples. * Fuzz tests: rotate the default subset per run (FILMCRAFT_FUZZ_SEED replays one) * platform tests: decode-switch tests in their own binaries, one NVENC lock
179 lines
6.1 KiB
Rust
179 lines
6.1 KiB
Rust
//! Shared helpers for the platform tests: ffmpeg-made fixtures (external generator only, never
|
|
//! linked), MP4 sample reading, and decoding a run of samples to compare decoders.
|
|
#![allow(dead_code)]
|
|
|
|
use std::path::{Path, PathBuf};
|
|
use std::process::{Command, Stdio};
|
|
|
|
use filmcraft_codecs::{DecodedFrame, VideoDecoder};
|
|
use filmcraft_frame::PixelData;
|
|
use filmcraft_isobmff::SampleEntry;
|
|
|
|
/// NVENC sessions are a limited resource on consumer GPUs, and the encoder counters are
|
|
/// process-wide: one NVENC test at a time across every module of the binary.
|
|
pub static NVENC_SERIAL: std::sync::Mutex<()> = std::sync::Mutex::new(());
|
|
|
|
/// The parity fixtures: (file, ffmpeg arguments). B-frames everywhere (reordering), a 360-line
|
|
/// picture (coded 368: cropping), two GOPs or more (seeks), and an open-GOP HEVC stream (CRA with
|
|
/// RASL pictures).
|
|
pub const FIXTURES: &[(&str, &[&str])] = &[
|
|
(
|
|
"h264_high.mp4",
|
|
&[
|
|
"-f",
|
|
"lavfi",
|
|
"-i",
|
|
"testsrc2=s=640x360:r=24:d=3,noise=alls=12:allf=t",
|
|
"-c:v",
|
|
"libx264",
|
|
"-profile:v",
|
|
"high",
|
|
"-preset",
|
|
"fast",
|
|
"-x264-params",
|
|
"bframes=3:b-pyramid=normal:keyint=24:min-keyint=24:scenecut=0",
|
|
"-pix_fmt",
|
|
"yuv420p",
|
|
],
|
|
),
|
|
(
|
|
"hevc_main.mp4",
|
|
&[
|
|
"-f",
|
|
"lavfi",
|
|
"-i",
|
|
"testsrc2=s=640x360:r=24:d=3,noise=alls=12:allf=t",
|
|
"-c:v",
|
|
"libx265",
|
|
"-preset",
|
|
"fast",
|
|
"-tag:v",
|
|
"hvc1",
|
|
"-x265-params",
|
|
"log-level=error:bframes=4:keyint=24:min-keyint=24:scenecut=0:open-gop=1",
|
|
"-pix_fmt",
|
|
"yuv420p",
|
|
],
|
|
),
|
|
(
|
|
"hevc_main10.mp4",
|
|
&[
|
|
"-f",
|
|
"lavfi",
|
|
"-i",
|
|
"testsrc2=s=640x360:r=24:d=3,noise=alls=12:allf=t",
|
|
"-c:v",
|
|
"libx265",
|
|
"-preset",
|
|
"fast",
|
|
"-profile:v",
|
|
"main10",
|
|
"-tag:v",
|
|
"hvc1",
|
|
"-x265-params",
|
|
"log-level=error:bframes=4:keyint=24:min-keyint=24:scenecut=0",
|
|
"-pix_fmt",
|
|
"yuv420p10le",
|
|
],
|
|
),
|
|
];
|
|
|
|
pub fn dir() -> PathBuf {
|
|
filmcraft_testkit::fixtures_dir("platform")
|
|
}
|
|
|
|
/// Generate `name` with `ffmpeg -y -v error <args> <out>` (cached).
|
|
pub fn fixture(ff: &Path, name: &str, args: &[&str]) -> Option<PathBuf> {
|
|
let out = dir().join(name);
|
|
filmcraft_testkit::fixtures::generate(&out, |tmp| {
|
|
let st = Command::new(ff).args(["-y", "-v", "error"]).args(args).arg(tmp).stdin(Stdio::null()).status();
|
|
match st {
|
|
Ok(s) if s.success() => true,
|
|
other => {
|
|
eprintln!("fixture {name}: ffmpeg failed: {other:?}");
|
|
false
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
/// The fixture by name.
|
|
pub fn named(ff: &Path, name: &str) -> Option<PathBuf> {
|
|
let (_, args) = FIXTURES.iter().find(|f| f.0 == name)?;
|
|
fixture(ff, name, args)
|
|
}
|
|
|
|
/// A video track's sample entry, samples (decode order) with pts, and sync flags.
|
|
pub struct Stream {
|
|
pub entry: SampleEntry,
|
|
pub samples: Vec<(Vec<u8>, i64)>,
|
|
pub sync: Vec<bool>,
|
|
}
|
|
|
|
pub fn read_stream(path: &Path) -> Stream {
|
|
let bytes = std::fs::read(path).unwrap();
|
|
let file = filmcraft_isobmff::open(bytes.clone()).unwrap();
|
|
let t = file.track_of_kind(filmcraft_isobmff::TrackKind::Video).unwrap();
|
|
let track = &file.tracks[t];
|
|
let samples = (0..track.samples.len()).map(|i| (file.read_sample(&bytes, t, i).unwrap(), track.samples[i].pts)).collect();
|
|
Stream { entry: track.entries[0].clone(), samples, sync: track.samples.iter().map(|s| s.is_sync).collect() }
|
|
}
|
|
|
|
/// Feed `samples` then flush.
|
|
pub fn decode_all(d: &mut dyn VideoDecoder, samples: &[(Vec<u8>, i64)]) -> Vec<DecodedFrame> {
|
|
let mut out = Vec::new();
|
|
for (s, p) in samples {
|
|
out.extend(d.decode(s, *p).unwrap_or_else(|e| panic!("{}: {e}", d.name())));
|
|
}
|
|
out.extend(d.flush());
|
|
out
|
|
}
|
|
|
|
/// Assert two decoders' outputs are the same pictures (pts order, size, format, colour, aspect
|
|
/// and every sample).
|
|
pub fn assert_same(what: &str, a: &[DecodedFrame], b: &[DecodedFrame]) {
|
|
let pa: Vec<i64> = a.iter().map(|f| f.pts).collect();
|
|
let pb: Vec<i64> = b.iter().map(|f| f.pts).collect();
|
|
assert_eq!(pa, pb, "{what}: pts sequence");
|
|
for (x, y) in a.iter().zip(b) {
|
|
let (fx, fy) = (&x.frame, &y.frame);
|
|
assert_eq!((fx.width, fx.height, fx.par, fx.color), (fy.width, fy.height, fy.par, fy.color), "{what}: pts {} geometry / colour", x.pts);
|
|
match (&fx.data, &fy.data) {
|
|
(PixelData::Yuv8 { planes: p, chroma: c, .. }, PixelData::Yuv8 { planes: q, chroma: d, .. }) => {
|
|
assert_eq!(c, d, "{what}: chroma");
|
|
for i in 0..3 {
|
|
assert!(p[i] == q[i], "{what}: pts {} plane {i} differs (max diff {})", x.pts, max_diff8(&p[i], &q[i]));
|
|
}
|
|
}
|
|
(PixelData::Yuv16 { planes: p, chroma: c, bits: bx, .. }, PixelData::Yuv16 { planes: q, chroma: d, bits: by, .. }) => {
|
|
assert_eq!((c, bx), (d, by), "{what}: chroma / bits");
|
|
for i in 0..3 {
|
|
assert!(p[i] == q[i], "{what}: pts {} plane {i} differs (max diff {})", x.pts, max_diff16(&p[i], &q[i]));
|
|
}
|
|
}
|
|
_ => panic!("{what}: pts {}: pixel formats differ", x.pts),
|
|
}
|
|
}
|
|
}
|
|
|
|
fn max_diff8(a: &[u8], b: &[u8]) -> String {
|
|
if a.len() != b.len() {
|
|
return format!("sizes {} vs {}", a.len(), b.len());
|
|
}
|
|
a.iter().zip(b).map(|(x, y)| x.abs_diff(*y)).max().unwrap_or(0).to_string()
|
|
}
|
|
|
|
fn max_diff16(a: &[u16], b: &[u16]) -> String {
|
|
if a.len() != b.len() {
|
|
return format!("sizes {} vs {}", a.len(), b.len());
|
|
}
|
|
a.iter().zip(b).map(|(x, y)| x.abs_diff(*y)).max().unwrap_or(0).to_string()
|
|
}
|
|
|
|
pub fn xorshift(seed: &mut u64) -> u64 {
|
|
*seed ^= *seed << 13;
|
|
*seed ^= *seed >> 7;
|
|
*seed ^= *seed << 17;
|
|
*seed
|
|
}
|