forge
Explore
Log in

Don't you dare go Hollow

tools/golden video: av1/h264/h265/vp8/vp9/mpeg2/mpeg4/h263 elementary + mp4/mov/mkv/avi/dv registry decode, recursive fixture discovery, per-frame plane hashes

Browse files at this commit

7c94faae2baa261a77b0a3854c31c396da501f5eAhmet Kaan GümüşParent: 7a5eb82
Cargo.lockmodified+1 -0
@@ -983,6 +983,7 @@ dependencies = [
983983 "ec-dnxhd",
984984 "ec-dsp",
985985 "ec-dts",
986+ "ec-dv",
986987 "ec-dvbsub",
987988 "ec-dvdsub",
988989 "ec-flac",
tools/golden/Cargo.tomlmodified+1 -0
@@ -39,6 +39,7 @@ ec-ogg.workspace = true
3939 ec-opus.workspace = true
4040 ec-probe.workspace = true
4141 ec-riff.workspace = true
42+ec-dv = { path = "../../crates/ec-dv", version = "0.1.0" }
4243 ec-truehd.workspace = true
4344 ec-vorbis.workspace = true
4445 ec-vp8.workspace = true
tools/golden/src/video.rsmodified+123 -60
@@ -29,77 +29,134 @@ impl Sink {
2929 type Run = fn(&Path, usize, &mut Sink) -> Result<(), String>;
3030
3131 pub fn run() {
32- let h264_dirs = [
33- "bitstreams",
34- "vectors/h264-jvt",
35- "vectors/h264-jvt-interlaced",
36- "vectors/h264-jvt-hi422",
37- "vectors/h264-jvt-hi444",
38- ];
39- let hevc_dirs = ["bitstreams", "vectors/hevc-jctvc", "vectors/hevc-rext"];
32+ let fx = ec_testkit::root();
33+ let vectors = fx.join("vectors");
34+ let av1 = streams(
35+ &dirs(
36+ &vectors,
37+ "av1",
38+ &[fx.join("bitstreams"), repo().join("crates/ec-av1/fixtures")],
39+ ),
40+ &["ivf", "obu"],
41+ );
42+ each("av1", &av1, &[1, 6], av1_run);
43+ let h264 = streams(
44+ &dirs(&vectors, "h264-jvt", &[fx.join("bitstreams")]),
45+ &["264", "h264", "avc"],
46+ );
47+ each("h264", &h264, &[0], h264_run);
48+ let h265 = streams(
49+ &dirs(
50+ &vectors,
51+ "hevc",
52+ &[
53+ fx.join("bitstreams"),
54+ repo().join("crates/ec-h265/tests/data/rext"),
55+ ],
56+ ),
57+ &["265", "hevc", "bit", "bin"],
58+ );
59+ each("h265", &h265, &[1, 6], h265_run);
60+ each("vp8", &streams(&[fx.join("vp8")], &["ivf"]), &[0], vp8_run);
4061 each(
41- "av1",
42- &list(&["bitstreams", "vectors/av1-aom"], "av1", &["ivf", "obu"]),
62+ "vp9",
63+ &streams(&dirs(&vectors, "vp9", &[]), &["ivf"]),
4364 &[1, 6],
44- av1_run,
65+ vp9_run,
4566 );
4667 each(
47- "h264",
48- &list(&h264_dirs, "", &["264", "h264"]),
68+ "mpeg2",
69+ &streams(&[fx.join("codecs")], &["m2v"]),
4970 &[0],
50- h264_run,
71+ mpeg2_run,
5172 );
5273 each(
53- "h265",
54- &list(&hevc_dirs, "", &["265", "hevc", "bit", "bin"]),
55- &[1, 6],
56- h265_run,
74+ "mpeg4",
75+ &streams(&[fx.join("codecs")], &["m4v"]),
76+ &[0],
77+ mpeg4_run,
5778 );
58- each("vp8", &list(&["vp8"], "", &["ivf"]), &[0], vp8_run);
5979 each(
60- "vp9",
61- &list(
62- &["bitstreams", "vectors/vp9-libvpx", "vp9"],
63- "vp9",
64- &["ivf"],
65- ),
66- &[1, 6],
67- vp9_run,
80+ "h263",
81+ &streams(&[fx.join("codecs")], &["h263"]),
82+ &[0],
83+ mpeg4_run,
6884 );
69- each("mpeg2", &list(&["codecs"], "", &["m2v"]), &[0], mpeg2_run);
70- each("mpeg4", &list(&["codecs"], "", &["m4v"]), &[0], mpeg4_run);
7185 containers();
7286 }
7387
74-fn list(dirs: &[&str], prefix: &str, exts: &[&str]) -> Vec<PathBuf> {
88+fn repo() -> PathBuf {
89+ PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../..")
90+}
91+
92+fn label(path: &Path) -> String {
93+ if path.starts_with(ec_testkit::root()) {
94+ name(path)
95+ } else {
96+ path.strip_prefix(repo())
97+ .unwrap_or(path)
98+ .display()
99+ .to_string()
100+ }
101+}
102+
103+fn dirs(parent: &Path, prefix: &str, extra: &[PathBuf]) -> Vec<PathBuf> {
104+ let mut all = subdirs(parent, prefix);
105+ all.extend(extra.iter().cloned());
106+ all
107+}
108+
109+fn subdirs(parent: &Path, prefix: &str) -> Vec<PathBuf> {
110+ let Ok(entries) = std::fs::read_dir(parent) else {
111+ return Vec::new();
112+ };
113+ let mut dirs: Vec<PathBuf> = entries
114+ .flatten()
115+ .map(|entry| entry.path())
116+ .filter(|path| {
117+ path.is_dir()
118+ && path
119+ .file_name()
120+ .and_then(|n| n.to_str())
121+ .is_some_and(|n| n.starts_with(prefix))
122+ })
123+ .collect();
124+ dirs.sort();
125+ dirs
126+}
127+
128+fn walk(dir: &Path, out: &mut Vec<PathBuf>) {
129+ let Ok(entries) = std::fs::read_dir(dir) else {
130+ return;
131+ };
132+ for entry in entries.flatten() {
133+ let path = entry.path();
134+ if path.is_dir() {
135+ walk(&path, out);
136+ } else {
137+ out.push(path);
138+ }
139+ }
140+}
141+
142+fn streams(dirs: &[PathBuf], exts: &[&str]) -> Vec<PathBuf> {
75143 let mut found = Vec::new();
76144 for dir in dirs {
77- let Ok(entries) = std::fs::read_dir(ec_testkit::root().join(dir)) else {
78- continue;
79- };
80- for entry in entries.flatten() {
81- let path = entry.path();
82- let name_ok = path
83- .file_name()
84- .and_then(|n| n.to_str())
85- .is_some_and(|n| n.starts_with(prefix));
86- let ext_ok = path
87- .extension()
88- .and_then(|e| e.to_str())
89- .is_some_and(|e| exts.contains(&e));
90- if name_ok && ext_ok {
91- found.push(path);
92- }
93- }
145+ walk(dir, &mut found);
94146 }
95- found.sort();
147+ found.retain(|path| {
148+ path.extension()
149+ .and_then(|e| e.to_str())
150+ .is_some_and(|e| exts.contains(&e))
151+ });
152+ found.sort_by_key(|path| label(path));
96153 found.truncate(MAX_STREAMS);
97154 found
98155 }
99156
100157 fn each(codec: &str, paths: &[PathBuf], threads: &[usize], run: Run) {
101158 for path in paths {
102- let rel = name(path);
159+ let rel = label(path);
103160 for &t in threads {
104161 let case = if t == 0 {
105162 format!("video/{codec}/{rel}")
@@ -378,16 +435,17 @@ fn mpeg4_run(path: &Path, _threads: usize, sink: &mut Sink) -> Result<(), String
378435 }
379436
380437 fn containers() {
381- let paths = list(
382- &["codecs", "mp4corpus", "derived", "video"],
383- "",
438+ let fx = ec_testkit::root();
439+ let mut paths = streams(&[fx.join("codecs")], &["mov", "mp4", "mkv", "dv", "avi"]);
440+ paths.extend(streams(
441+ &[fx.join("mp4corpus"), fx.join("derived"), fx.join("video")],
384442 &["mp4", "mov", "mkv"],
385- );
443+ ));
386444 for path in &paths {
387- let rel = name(path);
388- guard(&format!("video/container/{rel}"), || {
389- if let Err(e) = container(path, &rel) {
390- error(&format!("video/container/{rel}"), e);
445+ let case = format!("video/container/{}", label(path));
446+ guard(&case, || {
447+ if let Err(e) = container(path) {
448+ error(&case, e);
391449 }
392450 });
393451 }
@@ -399,6 +457,8 @@ fn open_demuxer(path: &Path) -> Result<Box<dyn Demuxer>, String> {
399457 Some("mkv") => {
400458 Box::new(ec_matroska::MatroskaDemuxer::new(file).map_err(|e| e.to_string())?)
401459 }
460+ Some("avi") => Box::new(ec_riff::AviDemuxer::new(file).map_err(|e| e.to_string())?),
461+ Some("dv") => Box::new(ec_dv::DvDemuxer::new(file).map_err(|e| e.to_string())?),
402462 _ => Box::new(ec_mp4::Mp4Demuxer::new(file).map_err(|e| e.to_string())?),
403463 };
404464 Ok(demux)
@@ -412,7 +472,10 @@ fn make_decoder(params: &CodecParameters) -> Result<Box<dyn Decoder>, String> {
412472 CodecId::Dnxhd => Box::new(ec_dnxhd::DnxhdDecoder::new(p).map_err(|e| e.to_string())?),
413473 CodecId::Mjpeg => Box::new(ec_mjpeg::MjpegDecoder::new(p).map_err(|e| e.to_string())?),
414474 CodecId::Mpeg2Video => Box::new(ec_mpeg2::Mpeg2Decoder::new(p).map_err(|e| e.to_string())?),
415- CodecId::Mpeg4Part2 => Box::new(ec_mpeg4::Mpeg4Decoder::new(p).map_err(|e| e.to_string())?),
475+ CodecId::DvVideo => Box::new(ec_dv::DvDecoder::new(p).map_err(|e| e.to_string())?),
476+ CodecId::Mpeg4Part2 | CodecId::MsMpeg4V1 | CodecId::MsMpeg4V2 | CodecId::MsMpeg4V3 => {
477+ Box::new(ec_mpeg4::Mpeg4Decoder::new(p).map_err(|e| e.to_string())?)
478+ }
416479 other => return Err(format!("no registry decoder for {other:?}")),
417480 };
418481 Ok(decoder)
@@ -451,7 +514,7 @@ fn decode_container(
451514 drain(dec.as_mut(), sink)
452515 }
453516
454-fn container(path: &Path, rel: &str) -> Result<(), String> {
517+fn container(path: &Path) -> Result<(), String> {
455518 let mut demux = open_demuxer(path)?;
456519 let (index, params) = demux
457520 .streams()
@@ -460,7 +523,7 @@ fn container(path: &Path, rel: &str) -> Result<(), String> {
460523 .map(|s| (s.index, s.params.clone()))
461524 .ok_or("no video stream")?;
462525 let codec = format!("{:?}", params.codec).to_lowercase();
463- let case = format!("video/{codec}/{rel}");
526+ let case = format!("video/{codec}/{}", label(path));
464527 let mut sink = Sink {
465528 case: case.clone(),
466529 count: 0,