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 = [
983 "ec-dnxhd",983 "ec-dnxhd",
984 "ec-dsp",984 "ec-dsp",
985 "ec-dts",985 "ec-dts",
986+ "ec-dv",
986 "ec-dvbsub",987 "ec-dvbsub",
987 "ec-dvdsub",988 "ec-dvdsub",
988 "ec-flac",989 "ec-flac",
tools/golden/Cargo.tomlmodified+1 -0
@@ -39,6 +39,7 @@ ec-ogg.workspace = true
39 ec-opus.workspace = true39 ec-opus.workspace = true
40 ec-probe.workspace = true40 ec-probe.workspace = true
41 ec-riff.workspace = true41 ec-riff.workspace = true
42+ec-dv = { path = "../../crates/ec-dv", version = "0.1.0" }
42 ec-truehd.workspace = true43 ec-truehd.workspace = true
43 ec-vorbis.workspace = true44 ec-vorbis.workspace = true
44 ec-vp8.workspace = true45 ec-vp8.workspace = true
tools/golden/src/video.rsmodified+120 -57
@@ -29,77 +29,134 @@ impl Sink {
29 type Run = fn(&Path, usize, &mut Sink) -> Result<(), String>;29 type Run = fn(&Path, usize, &mut Sink) -> Result<(), String>;
30 30
31 pub fn run() {31 pub fn run() {
32- let h264_dirs = [32+ let fx = ec_testkit::root();
33- "bitstreams",33+ let vectors = fx.join("vectors");
34- "vectors/h264-jvt",34+ let av1 = streams(
35- "vectors/h264-jvt-interlaced",35+ &dirs(
36- "vectors/h264-jvt-hi422",36+ &vectors,
37- "vectors/h264-jvt-hi444",
38- ];
39- let hevc_dirs = ["bitstreams", "vectors/hevc-jctvc", "vectors/hevc-rext"];
40- each(
41 "av1",37 "av1",
42- &list(&["bitstreams", "vectors/av1-aom"], "av1", &["ivf", "obu"]),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);
61+ each(
62+ "vp9",
63+ &streams(&dirs(&vectors, "vp9", &[]), &["ivf"]),
43 &[1, 6],64 &[1, 6],
44- av1_run,65+ vp9_run,
45 );66 );
46 each(67 each(
47- "h264",68+ "mpeg2",
48- &list(&h264_dirs, "", &["264", "h264"]),69+ &streams(&[fx.join("codecs")], &["m2v"]),
49 &[0],70 &[0],
50- h264_run,71+ mpeg2_run,
51 );72 );
52 each(73 each(
53- "h265",74+ "mpeg4",
54- &list(&hevc_dirs, "", &["265", "hevc", "bit", "bin"]),75+ &streams(&[fx.join("codecs")], &["m4v"]),
55- &[1, 6],76+ &[0],
56- h265_run,77+ mpeg4_run,
57 );78 );
58- each("vp8", &list(&["vp8"], "", &["ivf"]), &[0], vp8_run);
59 each(79 each(
60- "vp9",80+ "h263",
61- &list(81+ &streams(&[fx.join("codecs")], &["h263"]),
62- &["bitstreams", "vectors/vp9-libvpx", "vp9"],82+ &[0],
63- "vp9",83+ mpeg4_run,
64- &["ivf"],
65- ),
66- &[1, 6],
67- vp9_run,
68 );84 );
69- each("mpeg2", &list(&["codecs"], "", &["m2v"]), &[0], mpeg2_run);
70- each("mpeg4", &list(&["codecs"], "", &["m4v"]), &[0], mpeg4_run);
71 containers();85 containers();
72 }86 }
73 87
74-fn list(dirs: &[&str], prefix: &str, exts: &[&str]) -> Vec<PathBuf> {88+fn repo() -> PathBuf {
75- let mut found = Vec::new();89+ PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../..")
76- for dir in dirs {90+}
77- let Ok(entries) = std::fs::read_dir(ec_testkit::root().join(dir)) else {91+
78- continue;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();
79 };112 };
80- for entry in entries.flatten() {113+ let mut dirs: Vec<PathBuf> = entries
81- let path = entry.path();114+ .flatten()
82- let name_ok = path115+ .map(|entry| entry.path())
116+ .filter(|path| {
117+ path.is_dir()
118+ && path
83 .file_name()119 .file_name()
84 .and_then(|n| n.to_str())120 .and_then(|n| n.to_str())
85- .is_some_and(|n| n.starts_with(prefix));121+ .is_some_and(|n| n.starts_with(prefix))
86- let ext_ok = path122+ })
87- .extension()123+ .collect();
88- .and_then(|e| e.to_str())124+ dirs.sort();
89- .is_some_and(|e| exts.contains(&e));125+ dirs
90- if name_ok && ext_ok {126+}
91- found.push(path);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+ }
92 }139 }
93 }140 }
141+
142+fn streams(dirs: &[PathBuf], exts: &[&str]) -> Vec<PathBuf> {
143+ let mut found = Vec::new();
144+ for dir in dirs {
145+ walk(dir, &mut found);
94 }146 }
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));
96 found.truncate(MAX_STREAMS);153 found.truncate(MAX_STREAMS);
97 found154 found
98 }155 }
99 156
100 fn each(codec: &str, paths: &[PathBuf], threads: &[usize], run: Run) {157 fn each(codec: &str, paths: &[PathBuf], threads: &[usize], run: Run) {
101 for path in paths {158 for path in paths {
102- let rel = name(path);159+ let rel = label(path);
103 for &t in threads {160 for &t in threads {
104 let case = if t == 0 {161 let case = if t == 0 {
105 format!("video/{codec}/{rel}")162 format!("video/{codec}/{rel}")
@@ -378,16 +435,17 @@ fn mpeg4_run(path: &Path, _threads: usize, sink: &mut Sink) -> Result<(), String
378 }435 }
379 436
380 fn containers() {437 fn containers() {
381- let paths = list(438+ let fx = ec_testkit::root();
382- &["codecs", "mp4corpus", "derived", "video"],439+ let mut paths = streams(&[fx.join("codecs")], &["mov", "mp4", "mkv", "dv", "avi"]);
383- "",440+ paths.extend(streams(
441+ &[fx.join("mp4corpus"), fx.join("derived"), fx.join("video")],
384 &["mp4", "mov", "mkv"],442 &["mp4", "mov", "mkv"],
385- );443+ ));
386 for path in &paths {444 for path in &paths {
387- let rel = name(path);445+ let case = format!("video/container/{}", label(path));
388- guard(&format!("video/container/{rel}"), || {446+ guard(&case, || {
389- if let Err(e) = container(path, &rel) {447+ if let Err(e) = container(path) {
390- error(&format!("video/container/{rel}"), e);448+ error(&case, e);
391 }449 }
392 });450 });
393 }451 }
@@ -399,6 +457,8 @@ fn open_demuxer(path: &Path) -> Result<Box<dyn Demuxer>, String> {
399 Some("mkv") => {457 Some("mkv") => {
400 Box::new(ec_matroska::MatroskaDemuxer::new(file).map_err(|e| e.to_string())?)458 Box::new(ec_matroska::MatroskaDemuxer::new(file).map_err(|e| e.to_string())?)
401 }459 }
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())?),
402 _ => Box::new(ec_mp4::Mp4Demuxer::new(file).map_err(|e| e.to_string())?),462 _ => Box::new(ec_mp4::Mp4Demuxer::new(file).map_err(|e| e.to_string())?),
403 };463 };
404 Ok(demux)464 Ok(demux)
@@ -412,7 +472,10 @@ fn make_decoder(params: &CodecParameters) -> Result<Box<dyn Decoder>, String> {
412 CodecId::Dnxhd => Box::new(ec_dnxhd::DnxhdDecoder::new(p).map_err(|e| e.to_string())?),472 CodecId::Dnxhd => Box::new(ec_dnxhd::DnxhdDecoder::new(p).map_err(|e| e.to_string())?),
413 CodecId::Mjpeg => Box::new(ec_mjpeg::MjpegDecoder::new(p).map_err(|e| e.to_string())?),473 CodecId::Mjpeg => Box::new(ec_mjpeg::MjpegDecoder::new(p).map_err(|e| e.to_string())?),
414 CodecId::Mpeg2Video => Box::new(ec_mpeg2::Mpeg2Decoder::new(p).map_err(|e| e.to_string())?),474 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+ }
416 other => return Err(format!("no registry decoder for {other:?}")),479 other => return Err(format!("no registry decoder for {other:?}")),
417 };480 };
418 Ok(decoder)481 Ok(decoder)
@@ -451,7 +514,7 @@ fn decode_container(
451 drain(dec.as_mut(), sink)514 drain(dec.as_mut(), sink)
452 }515 }
453 516
454-fn container(path: &Path, rel: &str) -> Result<(), String> {517+fn container(path: &Path) -> Result<(), String> {
455 let mut demux = open_demuxer(path)?;518 let mut demux = open_demuxer(path)?;
456 let (index, params) = demux519 let (index, params) = demux
457 .streams()520 .streams()
@@ -460,7 +523,7 @@ fn container(path: &Path, rel: &str) -> Result<(), String> {
460 .map(|s| (s.index, s.params.clone()))523 .map(|s| (s.index, s.params.clone()))
461 .ok_or("no video stream")?;524 .ok_or("no video stream")?;
462 let codec = format!("{:?}", params.codec).to_lowercase();525 let codec = format!("{:?}", params.codec).to_lowercase();
463- let case = format!("video/{codec}/{rel}");526+ let case = format!("video/{codec}/{}", label(path));
464 let mut sink = Sink {527 let mut sink = Sink {
465 case: case.clone(),528 case: case.clone(),
466 count: 0,529 count: 0,