forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

subsampling_exact.rs138 lines, 4.9 KiBHistoryRawDownload
1//! Non-4:2:0 subsampling and 12-bit witnesses: profiles 1 and 3 (4:4:4 /
2//! 4:2:2 / 4:4:0 at 8 and 10 bits) and profile 2/3 12-bit decode byte-exact
3//! against ffmpeg's libvpx.
4//!
5//! Every fixture under `tests/data/` is committed (see the lane report for
6//! the exact generator commands), so these cases always run; the two
7//! `corpus_*` cases additionally cover the media-gated 4:4:4 corpus streams
8//! and print SKIP when the fixture is absent -- RED instead under
9//! `EC_REQUIRE_FIXTURES=1`, so a drifted fixture library can never read as a
10//! pass.
11//!
12//! The comparison is the whole flattened plane stream (u16 samples) against
13//! ffmpeg's `rawvideo` output for the matching `pix_fmt` — full-resolution
14//! chroma for 4:4:4, half-width for 4:2:2, half-height for 4:4:0, and the
15//! 16-bit LE sample layout for 10/12-bit.
16
17use crate::ivf;
18use crate::common::require_fixture;
19
20use ec_vp9::decode::Decoder;
21use std::path::{Path, PathBuf};
22
23fn data(name: &str) -> PathBuf {
24 Path::new(env!("CARGO_MANIFEST_DIR"))
25 .join("tests/data")
26 .join(name)
27}
28
29fn corpus(name: &str) -> PathBuf {
30 let mut p = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
31 p.pop();
32 p.pop();
33 p.join("fixtures/bitstreams").join(name)
34}
35
36/// ffmpeg's decoded samples as a flat u16 stream (8-bit zero-extended,
37/// 10/12-bit little-endian pairs).
38fn ffmpeg_samples(path: &Path, pix_fmt: &str, bd: u8) -> Vec<u16> {
39 let out = std::process::Command::new("ffmpeg")
40 .args(["-v", "error", "-i"])
41 .arg(path)
42 .args(["-f", "rawvideo", "-pix_fmt", pix_fmt, "-"])
43 .output()
44 .expect("ffmpeg must be on PATH for the witnesses");
45 assert!(out.status.success(), "ffmpeg failed on {path:?}");
46 if bd == 8 {
47 out.stdout.iter().map(|&b| b as u16).collect()
48 } else {
49 out.stdout
50 .as_chunks::<2>().0
51 .iter()
52 .map(|c| u16::from_le_bytes(*c))
53 .collect()
54 }
55}
56
57fn check(path: &Path, pix_fmt: &str, bd: u8) {
58 let bytes = std::fs::read(path).expect("committed fixture");
59 let (_, _, _, frames) = ivf::parse_ivf(&bytes);
60 let want = ffmpeg_samples(path, pix_fmt, bd);
61
62 let mut decoder = Decoder::new();
63 let mut ours: Vec<u16> = Vec::new();
64 let mut shown = 0usize;
65 for (i, frame) in frames.iter().enumerate() {
66 if let Some(pic) = decoder
67 .decode(&frame.data)
68 .unwrap_or_else(|e| panic!("{}: frame {i}: {e}", path.display()))
69 {
70 assert_eq!(pic.bit_depth, bd, "{}: frame {i} bit depth", path.display());
71 ours.extend(pic.y.iter().copied());
72 ours.extend(pic.u.iter().copied());
73 ours.extend(pic.v.iter().copied());
74 shown += 1;
75 }
76 }
77 assert!(shown >= 2, "{}: the stream shows frames", path.display());
78 assert_eq!(
79 ours.len(),
80 want.len(),
81 "{}: plane stream length",
82 path.display()
83 );
84 if let Some(i) = ours.iter().zip(&want).position(|(a, b)| a != b) {
85 panic!(
86 "{}: sample {i} differs (ours {} want {})",
87 path.display(),
88 ours[i],
89 want[i]
90 );
91 }
92}
93
94/// Old per-case test names, fixture, ffmpeg `pix_fmt`, bit depth.
95const PROFILE_CASES: &[(&str, &str, &str, u8)] = &[
96 ("profile1_444_8bit_is_byte_exact", "vp9-profile1-444.ivf", "yuv444p", 8),
97 ("profile3_444_10bit_is_byte_exact", "vp9-profile3-444-10bit.ivf", "yuv444p10le", 10),
98 ("profile3_444_12bit_is_byte_exact", "vp9-profile3-444-12bit.ivf", "yuv444p12le", 12),
99 ("profile1_422_8bit_is_byte_exact", "vp9-profile1-422.ivf", "yuv422p", 8),
100 ("profile3_422_10bit_is_byte_exact", "vp9-profile3-422-10bit.ivf", "yuv422p10le", 10),
101 ("profile1_440_8bit_is_byte_exact", "vp9-profile1-440.ivf", "yuv440p", 8),
102 ("profile3_440_10bit_is_byte_exact", "vp9-profile3-440-10bit.ivf", "yuv440p10le", 10),
103 ("profile2_420_12bit_is_byte_exact", "vp9-profile2-420-12bit.ivf", "yuv420p12le", 12),
104];
105
106/// Runs every profile/subsampling/bit-depth case; a failing case does not
107/// stop the others, and all failing case names are reported together.
108#[test]
109fn profile_matrix_is_byte_exact() {
110 let mut failures = Vec::new();
111 for &(name, file, pix_fmt, bd) in PROFILE_CASES {
112 let case = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
113 check(&data(file), pix_fmt, bd);
114 }));
115 if case.is_err() {
116 failures.push(name);
117 }
118 }
119 assert!(failures.is_empty(), "failed cases: {failures:?}");
120}
121
122#[test]
123fn corpus_profile1_444_matches_ffmpeg() {
124 let p = corpus("vp9-profile1-444.ivf");
125 if !require_fixture(&p, "scripts/gen-bitstream-fixtures.sh") {
126 return;
127 }
128 check(&p, "yuv444p", 8);
129}
130
131#[test]
132fn corpus_profile3_444_10bit_matches_ffmpeg() {
133 let p = corpus("vp9-profile3-444-10bit.ivf");
134 if !require_fixture(&p, "scripts/gen-bitstream-fixtures.sh") {
135 return;
136 }
137 check(&p, "yuv444p10le", 10);
138}