diff --git a/Cargo.lock b/Cargo.lock index 1db25cd3..1b37af80 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -983,6 +983,7 @@ dependencies = [ "ec-dnxhd", "ec-dsp", "ec-dts", + "ec-dv", "ec-dvbsub", "ec-dvdsub", "ec-flac", diff --git a/tools/golden/Cargo.toml b/tools/golden/Cargo.toml index 648ac40e..415065c9 100644 --- a/tools/golden/Cargo.toml +++ b/tools/golden/Cargo.toml @@ -39,6 +39,7 @@ ec-ogg.workspace = true ec-opus.workspace = true ec-probe.workspace = true ec-riff.workspace = true +ec-dv = { path = "../../crates/ec-dv", version = "0.1.0" } ec-truehd.workspace = true ec-vorbis.workspace = true ec-vp8.workspace = true diff --git a/tools/golden/src/video.rs b/tools/golden/src/video.rs index bc5ef547..49541dc5 100644 --- a/tools/golden/src/video.rs +++ b/tools/golden/src/video.rs @@ -29,77 +29,134 @@ impl Sink { type Run = fn(&Path, usize, &mut Sink) -> Result<(), String>; pub fn run() { - let h264_dirs = [ - "bitstreams", - "vectors/h264-jvt", - "vectors/h264-jvt-interlaced", - "vectors/h264-jvt-hi422", - "vectors/h264-jvt-hi444", - ]; - let hevc_dirs = ["bitstreams", "vectors/hevc-jctvc", "vectors/hevc-rext"]; + let fx = ec_testkit::root(); + let vectors = fx.join("vectors"); + let av1 = streams( + &dirs( + &vectors, + "av1", + &[fx.join("bitstreams"), repo().join("crates/ec-av1/fixtures")], + ), + &["ivf", "obu"], + ); + each("av1", &av1, &[1, 6], av1_run); + let h264 = streams( + &dirs(&vectors, "h264-jvt", &[fx.join("bitstreams")]), + &["264", "h264", "avc"], + ); + each("h264", &h264, &[0], h264_run); + let h265 = streams( + &dirs( + &vectors, + "hevc", + &[ + fx.join("bitstreams"), + repo().join("crates/ec-h265/tests/data/rext"), + ], + ), + &["265", "hevc", "bit", "bin"], + ); + each("h265", &h265, &[1, 6], h265_run); + each("vp8", &streams(&[fx.join("vp8")], &["ivf"]), &[0], vp8_run); each( - "av1", - &list(&["bitstreams", "vectors/av1-aom"], "av1", &["ivf", "obu"]), + "vp9", + &streams(&dirs(&vectors, "vp9", &[]), &["ivf"]), &[1, 6], - av1_run, + vp9_run, ); each( - "h264", - &list(&h264_dirs, "", &["264", "h264"]), + "mpeg2", + &streams(&[fx.join("codecs")], &["m2v"]), &[0], - h264_run, + mpeg2_run, ); each( - "h265", - &list(&hevc_dirs, "", &["265", "hevc", "bit", "bin"]), - &[1, 6], - h265_run, + "mpeg4", + &streams(&[fx.join("codecs")], &["m4v"]), + &[0], + mpeg4_run, ); - each("vp8", &list(&["vp8"], "", &["ivf"]), &[0], vp8_run); each( - "vp9", - &list( - &["bitstreams", "vectors/vp9-libvpx", "vp9"], - "vp9", - &["ivf"], - ), - &[1, 6], - vp9_run, + "h263", + &streams(&[fx.join("codecs")], &["h263"]), + &[0], + mpeg4_run, ); - each("mpeg2", &list(&["codecs"], "", &["m2v"]), &[0], mpeg2_run); - each("mpeg4", &list(&["codecs"], "", &["m4v"]), &[0], mpeg4_run); containers(); } -fn list(dirs: &[&str], prefix: &str, exts: &[&str]) -> Vec { +fn repo() -> PathBuf { + PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../..") +} + +fn label(path: &Path) -> String { + if path.starts_with(ec_testkit::root()) { + name(path) + } else { + path.strip_prefix(repo()) + .unwrap_or(path) + .display() + .to_string() + } +} + +fn dirs(parent: &Path, prefix: &str, extra: &[PathBuf]) -> Vec { + let mut all = subdirs(parent, prefix); + all.extend(extra.iter().cloned()); + all +} + +fn subdirs(parent: &Path, prefix: &str) -> Vec { + let Ok(entries) = std::fs::read_dir(parent) else { + return Vec::new(); + }; + let mut dirs: Vec = entries + .flatten() + .map(|entry| entry.path()) + .filter(|path| { + path.is_dir() + && path + .file_name() + .and_then(|n| n.to_str()) + .is_some_and(|n| n.starts_with(prefix)) + }) + .collect(); + dirs.sort(); + dirs +} + +fn walk(dir: &Path, out: &mut Vec) { + let Ok(entries) = std::fs::read_dir(dir) else { + return; + }; + for entry in entries.flatten() { + let path = entry.path(); + if path.is_dir() { + walk(&path, out); + } else { + out.push(path); + } + } +} + +fn streams(dirs: &[PathBuf], exts: &[&str]) -> Vec { let mut found = Vec::new(); for dir in dirs { - let Ok(entries) = std::fs::read_dir(ec_testkit::root().join(dir)) else { - continue; - }; - for entry in entries.flatten() { - let path = entry.path(); - let name_ok = path - .file_name() - .and_then(|n| n.to_str()) - .is_some_and(|n| n.starts_with(prefix)); - let ext_ok = path - .extension() - .and_then(|e| e.to_str()) - .is_some_and(|e| exts.contains(&e)); - if name_ok && ext_ok { - found.push(path); - } - } + walk(dir, &mut found); } - found.sort(); + found.retain(|path| { + path.extension() + .and_then(|e| e.to_str()) + .is_some_and(|e| exts.contains(&e)) + }); + found.sort_by_key(|path| label(path)); found.truncate(MAX_STREAMS); found } fn each(codec: &str, paths: &[PathBuf], threads: &[usize], run: Run) { for path in paths { - let rel = name(path); + let rel = label(path); for &t in threads { let case = if t == 0 { format!("video/{codec}/{rel}") @@ -378,16 +435,17 @@ fn mpeg4_run(path: &Path, _threads: usize, sink: &mut Sink) -> Result<(), String } fn containers() { - let paths = list( - &["codecs", "mp4corpus", "derived", "video"], - "", + let fx = ec_testkit::root(); + let mut paths = streams(&[fx.join("codecs")], &["mov", "mp4", "mkv", "dv", "avi"]); + paths.extend(streams( + &[fx.join("mp4corpus"), fx.join("derived"), fx.join("video")], &["mp4", "mov", "mkv"], - ); + )); for path in &paths { - let rel = name(path); - guard(&format!("video/container/{rel}"), || { - if let Err(e) = container(path, &rel) { - error(&format!("video/container/{rel}"), e); + let case = format!("video/container/{}", label(path)); + guard(&case, || { + if let Err(e) = container(path) { + error(&case, e); } }); } @@ -399,6 +457,8 @@ fn open_demuxer(path: &Path) -> Result, String> { Some("mkv") => { Box::new(ec_matroska::MatroskaDemuxer::new(file).map_err(|e| e.to_string())?) } + Some("avi") => Box::new(ec_riff::AviDemuxer::new(file).map_err(|e| e.to_string())?), + Some("dv") => Box::new(ec_dv::DvDemuxer::new(file).map_err(|e| e.to_string())?), _ => Box::new(ec_mp4::Mp4Demuxer::new(file).map_err(|e| e.to_string())?), }; Ok(demux) @@ -412,7 +472,10 @@ fn make_decoder(params: &CodecParameters) -> Result, String> { CodecId::Dnxhd => Box::new(ec_dnxhd::DnxhdDecoder::new(p).map_err(|e| e.to_string())?), CodecId::Mjpeg => Box::new(ec_mjpeg::MjpegDecoder::new(p).map_err(|e| e.to_string())?), CodecId::Mpeg2Video => Box::new(ec_mpeg2::Mpeg2Decoder::new(p).map_err(|e| e.to_string())?), - CodecId::Mpeg4Part2 => Box::new(ec_mpeg4::Mpeg4Decoder::new(p).map_err(|e| e.to_string())?), + CodecId::DvVideo => Box::new(ec_dv::DvDecoder::new(p).map_err(|e| e.to_string())?), + CodecId::Mpeg4Part2 | CodecId::MsMpeg4V1 | CodecId::MsMpeg4V2 | CodecId::MsMpeg4V3 => { + Box::new(ec_mpeg4::Mpeg4Decoder::new(p).map_err(|e| e.to_string())?) + } other => return Err(format!("no registry decoder for {other:?}")), }; Ok(decoder) @@ -451,7 +514,7 @@ fn decode_container( drain(dec.as_mut(), sink) } -fn container(path: &Path, rel: &str) -> Result<(), String> { +fn container(path: &Path) -> Result<(), String> { let mut demux = open_demuxer(path)?; let (index, params) = demux .streams() @@ -460,7 +523,7 @@ fn container(path: &Path, rel: &str) -> Result<(), String> { .map(|s| (s.index, s.params.clone())) .ok_or("no video stream")?; let codec = format!("{:?}", params.codec).to_lowercase(); - let case = format!("video/{codec}/{rel}"); + let case = format!("video/{codec}/{}", label(path)); let mut sink = Sink { case: case.clone(), count: 0,