forge
Explore
Log in

Don't you dare go Hollow

The shipped presets decode sample-exact through both decoders

Browse files at this commit

e66bbaa88344cf93f946f04cefbbc88c4b0b0836Ahmet Kaan GümüşParent: ed24ce6
  • test
    • the shipped presets decode sample-exact through both decoders
Show full message
test(av1): the shipped presets decode sample-exact through both decoders

Re-adds the preset gate the crate-wide rustfmt revert took with it, and
records the measured lever table and preset rows in speed.rs's own docs.
crates/ec-av1/src/encoder.rsmodified+71 -0
@@ -2251,6 +2251,77 @@ mod tests {
2251 }2251 }
2252 }2252 }
2253 2253
2254+ /// Every SHIPPED SPEED PRESET codes a stream both decoders reconstruct
2255+ /// sample-exact -- ours and ffmpeg's -- and codes a DIFFERENT stream from
2256+ /// its neighbour (a preset that changes no byte is a preset that buys no
2257+ /// wall: class `gate-blind-to-feature`). Preset 0's bytes are the
2258+ /// full-search ones, which is the cheap in-suite statement of the byte
2259+ /// pins' rule.
2260+ ///
2261+ /// Ignored by default because the preset is PROCESS-GLOBAL
2262+ /// ([`crate::speed`]): flipping it while the suite's other tests encode
2263+ /// in parallel would move their bytes under them. Run it on its own:
2264+ /// `cargo test -p ec-av1 --release -- --ignored every_speed_preset`.
2265+ #[test]
2266+ #[ignore = "sets the process-global speed preset: run it alone"]
2267+ fn every_speed_preset_decodes_sample_exact_through_both_decoders() {
2268+ let _gate_lock = crate::stream::tests::lock_gate_counters();
2269+ let (width, height) = (640usize, 384usize);
2270+ let sources: Vec<Picture> = (0..4).map(|t| test_card(width, height, t * 3)).collect();
2271+ let mut sizes: Vec<(u8, usize)> = Vec::new();
2272+ for speed in [0u8, 3, 6, 10] {
2273+ let config = EncoderConfig {
2274+ width,
2275+ height,
2276+ base_q_idx: 120,
2277+ gop: 4,
2278+ colour: Colour::Bt709Limited,
2279+ tile_cols_log2: 1,
2280+ tile_rows_log2: 0,
2281+ };
2282+ let mut enc = Av1Encoder::with_speed(config, speed).unwrap();
2283+ let mut stream = Vec::new();
2284+ for packet in encode_all(&mut enc, &sources) {
2285+ stream.extend_from_slice(&packet.data);
2286+ }
2287+ let ours = crate::stream::decode_stream(&stream).expect("our decoder");
2288+ assert_eq!(ours.len(), sources.len(), "speed {speed}: our decoder's frames");
2289+ if have_ffmpeg() {
2290+ let theirs = ffmpeg_decode_luma(&stream, width, height);
2291+ assert_eq!(theirs.len(), sources.len(), "speed {speed}: ffmpeg's frames");
2292+ for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() {
2293+ let got: Vec<u8> = a.y.iter().map(|&v| v as u8).collect();
2294+ if let Some(at) = got.iter().zip(b).position(|(x, y)| x != y) {
2295+ panic!(
2296+ "speed {speed} frame {i}: luma differs first at ({}, {}): \
2297+ ours {} vs ffmpeg {}",
2298+ at % width,
2299+ at / width,
2300+ got[at],
2301+ b[at],
2302+ );
2303+ }
2304+ }
2305+ } else {
2306+ eprintln!("SKIP the ffmpeg half of speed {speed}: no ffmpeg");
2307+ }
2308+ eprintln!(
2309+ "speed {speed}: {} bytes [{}]",
2310+ stream.len(),
2311+ crate::speed::levers(speed).join(", ")
2312+ );
2313+ sizes.push((speed, stream.len()));
2314+ }
2315+ crate::speed::set_speed(0);
2316+ for w in sizes.windows(2) {
2317+ assert_ne!(
2318+ w[0].1, w[1].1,
2319+ "speed {} and {} coded the same bytes: the preset changed no decision",
2320+ w[0].0, w[1].0
2321+ );
2322+ }
2323+ }
2324+
2254 /// What tiles and tile threads are worth at the size the editor exports2325 /// What tiles and tile threads are worth at the size the editor exports
2255 /// at: 1920x1080, eight real pictures, two passes per cell (ABAB), wall2326 /// at: 1920x1080, eight real pictures, two passes per cell (ABAB), wall
2256 /// per cell. Ignored by default (minutes).2327 /// per cell. Ignored by default (minutes).