diff --git a/crates/ec-mp4/tests/it/edith_parity.rs b/crates/ec-mp4/tests/it/edith_parity.rs deleted file mode 100644 index c982f99c..00000000 --- a/crates/ec-mp4/tests/it/edith_parity.rs +++ /dev/null @@ -1,402 +0,0 @@ -//! Parity with ffprobe, file by file: what ec-mp4 reads out of an mp4 or mov has -//! to be what ffprobe reads out of the same bytes, sample for sample and field -//! for field. This is the swap criterion for edith's `mp4::` demuxer: identical -//! packet bytes, identical timestamps, identical stream metadata. -//! -//! -//! Per track, the comparison is: codec, coded size, sample rate, channels, -//! timebase, rotation, and per sample the byte offset, size, presentation time -//! (`cts` against ffprobe `pts`), the sync flag, and the decode time up to one -//! constant. ffmpeg's `dts` carries a constant shift of its own (the largest -//! composition delay), so only its differences are the same claim. Edit lists -//! are applied on both sides, the same way ffmpeg applies them. -//! -//! Where edith's engine reads the file differently on purpose (it trims the -//! picture by the edit list where ffprobe shifts it, and ignores empty edits), -//! the edith-only values are printed in the table, not compared. See -//! `lanes/mp4demux.report.md`. - -use std::collections::HashMap; -use std::fs::File; -use std::io::BufReader; -use std::path::{Path, PathBuf}; - -use ec_core::{CodecId, Demuxer, MediaParameters}; -use ec_mp4::{Mp4Demuxer, Sample}; - -use crate::common::ffmpeg_name; - -/// One ffprobe `key=value` record block, keyed by field name. -type Record = HashMap; - -/// Every `stream=`/`packet=` block of `default=nw=1` output, split where the -/// `first` key starts a new block. -fn records(text: &str, first: &str) -> Vec { - let mut out: Vec = Vec::new(); - for line in text.lines() { - let Some((key, value)) = line.split_once('=') else { - continue; - }; - if key == first { - out.push(Record::new()); - } - if let Some(record) = out.last_mut() { - record.insert(key.to_string(), value.to_string()); - } - } - out -} - -fn ffprobe(path: &Path, entries: &str, first: &str) -> Vec { - let out = ec_testkit::ffprobe() - .args(["-v", "error", "-show_entries", entries, "-of", "default=nw=1"]) - .arg(path) - .output() - .expect("ffprobe runs"); - assert!( - out.status.success(), - "ffprobe refused {}: {}", - path.display(), - String::from_utf8_lossy(&out.stderr) - ); - records(&String::from_utf8_lossy(&out.stdout), first) -} - -/// What ffprobe says about one stream, `None` where a field is `N/A` or absent. -#[derive(Debug, Default)] -struct ProbeStream { - codec: String, - width: Option, - height: Option, - sample_rate: Option, - channels: Option, - time_base: String, - duration_ts: Option, - rotation: Option, - attached_pic: bool, -} - -#[derive(Debug, Clone, Copy)] -struct ProbePacket { - pts: Option, - dts: Option, - size: u64, - pos: Option, - key: bool, -} - -fn number(value: Option<&String>) -> Option { - value.and_then(|v| v.parse().ok()) -} - -fn probe_streams(path: &Path, rotations: &HashMap) -> Vec { - ffprobe( - path, - "stream=index,codec_name,codec_type,width,height,sample_rate,channels,time_base,duration_ts:stream_disposition=attached_pic", - "index", - ) - .into_iter() - .map(|r| { - let index = number::(r.get("index")).unwrap_or(u32::MAX); - ProbeStream { - codec: r.get("codec_name").cloned().unwrap_or_default(), - width: number(r.get("width")), - height: number(r.get("height")), - sample_rate: number(r.get("sample_rate")), - channels: number(r.get("channels")), - time_base: r.get("time_base").cloned().unwrap_or_default(), - duration_ts: number(r.get("duration_ts")), - rotation: rotations.get(&index).copied(), - attached_pic: r - .get("DISPOSITION:attached_pic") - .is_some_and(|v| v == "1"), - } - }) - .collect() -} - -/// Display rotation per stream index, from the `side_data_list` of the JSON -/// stream dump. The `side_data=rotation` entry query is not used: on a 2 GB film -/// ffprobe spends minutes decoding for it, while the JSON dump is immediate. -fn rotations(path: &Path) -> HashMap { - let out = ec_testkit::ffprobe() - .args(["-v", "error", "-show_streams", "-of", "json"]) - .arg(path) - .output() - .expect("ffprobe runs"); - let mut found = HashMap::new(); - let mut current = None; - for line in String::from_utf8_lossy(&out.stdout).lines() { - let line = line.trim(); - // Stream objects open with `"index": n,` at the stream's own indent. - if let Some(rest) = line.strip_prefix("\"index\": ") { - current = rest.trim_end_matches(',').parse::().ok(); - } else if let Some(rest) = line.strip_prefix("\"rotation\": ") - && let (Some(index), Ok(r)) = (current, rest.trim_end_matches(',').parse::()) - { - found.insert(index, r); - } - } - found -} - -/// Packets per ffprobe stream index, each list in the order ffprobe demuxes -/// them, which for one stream is decode order. -fn probe_packets(path: &Path) -> HashMap> { - let mut by_stream: HashMap> = HashMap::new(); - for r in ffprobe( - path, - "packet=stream_index,pts,dts,size,pos,flags", - "stream_index", - ) { - let Some(index) = number::(r.get("stream_index")) else { - continue; - }; - by_stream.entry(index).or_default().push(ProbePacket { - pts: number(r.get("pts")), - dts: number(r.get("dts")), - size: number(r.get("size")).unwrap_or(0), - pos: number(r.get("pos")), - key: r.get("flags").is_some_and(|f| f.starts_with('K')), - }); - } - by_stream -} - -/// ffprobe's rotation (counter-clockwise degrees) as this crate's clockwise -/// quarter turn: the same matrix, the other direction. -fn expected_rotation(rotation: Option) -> Option { - match rotation { - None => Some(0), - Some(r) if r % 90 == 0 => Some((-r / 90).rem_euclid(4) as u8), - Some(_) => None, - } -} - -/// One file, compared. Returns the table row and every mismatch it found. -fn compare(path: &Path) -> (String, Vec) { - let mut problems = Vec::new(); - let file = File::open(path).unwrap_or_else(|e| panic!("{}: {e}", path.display())); - let demuxer = Mp4Demuxer::new(BufReader::new(file)) - .unwrap_or_else(|e| panic!("{}: {e}", path.display())); - let name = path.file_name().unwrap_or_default().to_string_lossy().into_owned(); - // Cover art is not a track: ffprobe lists an `covr` picture as a video stream - // with `attached_pic` set, and this crate does not list it (a player that - // shows an album cover as a video stream is the bug). Dropped on both sides. - let rotations = rotations(path); - let all_probed = probe_streams(path, &rotations); - let probed: Vec = all_probed.into_iter().filter(|p| !p.attached_pic).collect(); - let packets = probe_packets(path); - let tracks = demuxer.tracks().to_vec(); - if probed.len() != tracks.len() { - // The track position is the only index the two share, so the counts agree - // or the rest of the comparison is meaningless. - problems.push(format!("track count: ec {} ffprobe {}", tracks.len(), probed.len())); - } - let mut rows = Vec::new(); - for (position, track) in tracks.iter().enumerate() { - let Some(stream) = track.stream else { - continue; - }; - let Some(p) = probed.get(position) else { - problems.push(format!("track {position}: no ffprobe stream")); - continue; - }; - let info = demuxer.streams()[stream as usize].clone(); - let samples: Vec = demuxer.samples(stream).to_vec(); - let tag = format!("track {position} ({})", ffmpeg_name(info.params.codec)); - if ffmpeg_name(info.params.codec) != p.codec { - problems.push(format!("{tag}: codec, ffprobe says {}", p.codec)); - } - let tb = format!("{}/{}", info.time_base.num(), info.time_base.den()); - if tb != p.time_base { - problems.push(format!("{tag}: timebase {tb} vs {}", p.time_base)); - } - match &info.params.media { - MediaParameters::Video(v) => { - if Some((v.width, v.height)) != p.width.zip(p.height) { - problems.push(format!( - "{tag}: coded size {}x{} vs ffprobe {:?}x{:?}", - v.width, v.height, p.width, p.height - )); - } - // Both sides name the same matrix; ffprobe counts counter-clockwise. - if info.rotation.steps() != expected_rotation(p.rotation) { - problems.push(format!( - "{tag}: rotation {:?} vs ffprobe {:?}", - info.rotation, p.rotation - )); - } - } - MediaParameters::Audio(a) => { - // Implicit HE-AAC (SBR with no extension frequency in the config): - // ffprobe decodes the first frames for the doubled output rate, - // and so does edith (`mp4_aac_prime`); this reader reports the core's. - let implicit_sbr = info.params.codec == CodecId::Aac - && p.sample_rate == Some(a.sample_rate * 2); - if Some(a.sample_rate) != p.sample_rate && !implicit_sbr { - problems.push(format!("{tag}: rate {} vs {:?}", a.sample_rate, p.sample_rate)); - } - if Some(a.layout.channel_count() as u32) != p.channels { - problems.push(format!( - "{tag}: channels {} vs {:?}", - a.layout.channel_count(), - p.channels - )); - } - } - MediaParameters::Subtitle => {} - } - // Per sample, against ffprobe's packets of the same stream. - let theirs = packets.get(&(position as u32)).cloned().unwrap_or_default(); - // A subtitle track ends in a zero-duration sample at the movie's end, an - // end marker ffprobe does not hand out as a packet. Dropped on this side - // for the comparison only; the sample is still in the table. - let mut samples = samples; - if matches!(info.params.media, MediaParameters::Subtitle) - && samples.len() == theirs.len() + 1 - && samples.last().is_some_and(|s| s.duration == 0) - { - samples.pop(); - } - if theirs.len() != samples.len() { - problems.push(format!( - "{tag}: {} samples vs {} packets", - samples.len(), - theirs.len() - )); - } - // VP8 and VP9 carry no `stss` in these files, so the box makes every - // sample a sync sample, while ffprobe reads the key flag out of the - // bitstream. The box is what edith follows; the flag difference is named. - let box_says_all_sync = samples.iter().all(|s| s.sync); - let bitstream_keys = theirs.iter().filter(|p| p.key).count(); - let vp_box_only = matches!(info.params.codec, CodecId::Vp8 | CodecId::Vp9) - && box_says_all_sync - && bitstream_keys < samples.len(); - let mut dts_shift: Option = None; - let (mut bad_pos, mut bad_size, mut bad_pts, mut bad_sync, mut bad_dts) = (0, 0, 0, 0, 0); - for (ours, theirs) in samples.iter().zip(&theirs) { - if theirs.pos != Some(ours.offset) { - bad_pos += 1; - } - if u64::from(ours.size) != theirs.size { - bad_size += 1; - } - if theirs.pts != Some(ours.cts) { - bad_pts += 1; - } - if theirs.key != ours.sync && !vp_box_only { - bad_sync += 1; - } - match (theirs.dts, dts_shift) { - (Some(d), None) => dts_shift = Some(ours.dts - d), - (Some(d), Some(k)) if ours.dts - d != k => bad_dts += 1, - (None, _) => bad_dts += 1, - _ => {} - } - } - for (what, n) in [ - ("offset", bad_pos), - ("size", bad_size), - ("pts", bad_pts), - ("sync", bad_sync), - ("dts", bad_dts), - ] { - if n > 0 { - problems.push(format!("{tag}: {n} samples differ in {what}")); - } - } - let syncs = demuxer.sync_in_display_order(stream).len(); - rows.push(format!( - " t{position} {:<7} n={:<6} trim={:<8} first={:<6} dts-shift={:<6} edits={:?} display-syncs={syncs} duration_ts={:?}/{:?}", - ffmpeg_name(info.params.codec), - samples.len(), - format!("{:?}", demuxer.presentation_trim(stream)), - demuxer.first_frame_sample(stream), - dts_shift.map_or("-".into(), |k| k.to_string()), - track.edits.iter().map(|e| (e.segment_duration, e.media_time)).collect::>(), - p.duration_ts, - info.duration, - )); - } - let row = format!("{name}\n{}", rows.join("\n")); - (row, problems) -} - -/// Every mp4-family file under `dir`, recursively, into `files`. -fn collect(dir: &Path, files: &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() { - collect(&path, files); - continue; - } - let name = path.to_string_lossy().to_ascii_lowercase(); - if [".mp4", ".m4a", ".m4v", ".mov"].iter().any(|ext| name.ends_with(ext)) { - files.push(path); - } - } -} - -fn corpus() -> Vec { - let mut files = Vec::new(); - collect(&ec_testkit::root().join("mp4corpus"), &mut files); - files.sort(); - files.dedup(); - files -} - -#[test] -fn every_corpus_file_matches_ffprobe_sample_for_sample() { - let files = corpus(); - assert!(!files.is_empty(), "no mp4/mov corpus; run scripts/fixtures.sh"); - let mut report = Vec::new(); - let mut failures = Vec::new(); - for path in &files { - let (row, problems) = compare(path); - report.push(row); - if !problems.is_empty() { - failures.push(format!("{}:\n {}", path.display(), problems.join("\n "))); - } - } - println!("{}", report.join("\n")); - assert!( - failures.is_empty(), - "{} of {} files differ from ffprobe:\n{}", - failures.len(), - files.len(), - failures.join("\n") - ); -} - -/// The edith-side reading of the edit list and the sample table, on fixtures -/// whose answers are known: an AAC track whose edit list trims one 1024-sample -/// priming packet, and an open-GOP stream whose keyframes sit out of display -/// order. -#[test] -fn edith_trim_and_display_order_read_the_known_fixtures() { - let aac = ec_testkit::fixture("audio/aac-mp4-stereo-48000.mp4"); - let demuxer = Mp4Demuxer::new(BufReader::new(File::open(&aac).expect("fixture"))) - .expect("the fixture demuxes"); - assert_eq!(demuxer.presentation_trim(0), Some(1024)); - assert_eq!(demuxer.first_frame_sample(0), 2, "the trim lands on packet 2"); - assert!(demuxer.sync_in_display_order(0).is_empty(), "no ctts, no reorder"); - - let gop = ec_testkit::fixture("video/h264-open-gop.mp4"); - let demuxer = Mp4Demuxer::new(BufReader::new(File::open(&gop).expect("fixture"))) - .expect("the fixture demuxes"); - let syncs = demuxer.sync_in_display_order(0); - assert!(!syncs.is_empty(), "B-frames: the display table answers"); - assert!( - syncs.windows(2).all(|w| w[0].0 < w[1].0 && w[0].1 != w[1].1), - "display indices ascend: {syncs:?}" - ); - let samples = demuxer.samples(0); - for &(_, decode) in &syncs { - assert!(samples[decode as usize].sync, "decode {decode} is a sync sample"); - } -} diff --git a/crates/ec-mp4/tests/it/main.rs b/crates/ec-mp4/tests/it/main.rs index e76f617b..952cd984 100644 --- a/crates/ec-mp4/tests/it/main.rs +++ b/crates/ec-mp4/tests/it/main.rs @@ -7,7 +7,6 @@ mod chapters; mod common; mod dts; mod edit_trim; -mod edith_parity; mod fuzz_regressions; mod mp4; mod mux_entries; diff --git a/crates/ec-ogg/tests/real_library.rs b/crates/ec-ogg/tests/real_library.rs deleted file mode 100644 index c2666f28..00000000 --- a/crates/ec-ogg/tests/real_library.rs +++ /dev/null @@ -1,315 +0,0 @@ -//! -//! Per file the oracle checks: -//! - packet count and every packet's size (ffprobe, audio stream 0); -//! - the concatenated packet payloads (ffmpeg `-c copy -f data`), byte for byte; -//! - the header block: Opus's `OpusHead` against ffprobe's `extradata_size` -//! exactly; Vorbis's three Xiph-laced packets by their lacing and magic (see -//! below for why the size is not compared); -//! - timing: where a packet carries a pts, it equals ffprobe's pts after the -//! Opus pre-skip shift; where a page ends on a packet, the granule position -//! equals that packet's ffprobe end (pts + duration) after the same shift. -//! -//! Timing rule, as ffmpeg's Ogg demuxer applies it (measured on these files): -//! - Vorbis: granule = the sample position at the packet's end, at the stream -//! rate; ffmpeg's pts = granule - duration. No shift. The first packet is the -//! one exception: ffmpeg starts it at minus its own length, while ec-ogg, by -//! its documented convention, starts the stream at zero and states no -//! duration for a Vorbis packet. Its pts is therefore not compared; its -//! granule still is. -//! - Opus: granule counts 48 kHz samples *including* the pre-skip; ffmpeg's pts -//! = granule - pre_skip - duration, so the end is `granule - pre_skip`. Our -//! packet pts start at zero, so ours = ffmpeg's pts + pre_skip. -//! -//! Header block: ffmpeg's stated Vorbis extradata size differs from ours on -//! some files (ours keeps the comment header verbatim, which the remux path -//! relies on for bit-identical output). ffprobe does not expose the extradata -//! bytes, so the Vorbis block is checked structurally and the size difference -//! is reported, not failed. -//! -//! Scope: demux only. The decoded PCM is not compared here. -//! - -use std::path::Path; - -use ec_core::Demuxer; -use ec_ogg::{Mapping, OggDemuxer, granule_of}; - -/// One packet as ffprobe reports it. -struct Probed { - pts: Option, - duration: Option, - size: usize, -} - -/// The verdict for one file, with the text the table prints. -enum Verdict { - Match(String), - Refused(String), - Failed(String), -} - -/// Parses an ffprobe csv cell: `N/A` and blanks are absent. -fn cell(s: &str) -> Option { - let s = s.trim(); - if s.is_empty() || s == "N/A" { - None - } else { - s.parse().ok() - } -} - -/// Audio stream 0's packets: header packets are not among them, as with ours. -fn ffprobe_packets(path: &Path) -> Result, String> { - let out = ec_testkit::ffprobe() - .args([ - "-v", - "error", - "-select_streams", - "a:0", - "-show_entries", - "packet=pts,duration,size", - "-of", - "csv=p=0", - ]) - .arg(path) - .output() - .map_err(|e| format!("ffprobe: {e}"))?; - if !out.status.success() { - return Err("ffprobe failed on the packets".into()); - } - let mut packets = Vec::new(); - for line in String::from_utf8_lossy(&out.stdout).lines() { - let f: Vec<&str> = line.split(',').collect(); - if f.len() < 3 { - return Err(format!("unexpected ffprobe packet row: {line}")); - } - let size = cell(f[2]).ok_or_else(|| format!("no packet size in: {line}"))?; - packets.push(Probed { - pts: cell(f[0]), - duration: cell(f[1]), - size: size as usize, - }); - } - Ok(packets) -} - -/// ffprobe's stated extradata size for audio stream 0. -fn ffprobe_extradata_size(path: &Path) -> Result { - let out = ec_testkit::ffprobe() - .args([ - "-v", - "error", - "-select_streams", - "a:0", - "-show_entries", - "stream=extradata_size", - "-of", - "csv=p=0", - ]) - .arg(path) - .output() - .map_err(|e| format!("ffprobe: {e}"))?; - let text = String::from_utf8_lossy(&out.stdout); - let first = text.lines().next().unwrap_or_default().trim_matches(','); - cell(first) - .map(|n| n as usize) - .ok_or_else(|| format!("no extradata_size: {text:?}")) -} - -/// ffmpeg's concatenated audio packet payloads, copied and not decoded. -fn ffmpeg_payload(path: &Path) -> Result, String> { - let out = ec_testkit::ffmpeg() - .args(["-v", "error", "-i"]) - .arg(path) - .args(["-map", "0:a:0", "-c", "copy", "-f", "data", "-"]) - .output() - .map_err(|e| format!("ffmpeg: {e}"))?; - if !out.status.success() { - return Err(format!( - "ffmpeg failed to copy the packets: {}", - String::from_utf8_lossy(&out.stderr).trim() - )); - } - Ok(out.stdout) -} - -/// Reads one file with ec-ogg and compares it with the oracle. -fn check_file(path: &Path) -> Verdict { - let file = match std::fs::File::open(path) { - Ok(f) => f, - Err(e) => return Verdict::Failed(format!("open: {e}")), - }; - let mut demuxer = match OggDemuxer::open(file) { - Ok(d) => d, - Err(e) => { - let text = e.to_string(); - if text.contains("no logical stream with a known mapping") { - return Verdict::Refused(text); - } - return Verdict::Failed(format!("open: {text}")); - } - }; - let Some(mapping) = demuxer.mapping(0) else { - return Verdict::Refused("no audio stream with a known mapping".into()); - }; - let pre_skip = match mapping { - Mapping::Opus { pre_skip, .. } => i64::from(pre_skip), - _ => 0, - }; - let streams = demuxer.streams().to_vec(); - let block: &[u8] = streams[0].params.extradata.as_ref().map_or(&[], |b| &b[..]); - let vorbis = matches!(mapping, Mapping::Vorbis { .. }); - - let mut ours = Vec::new(); - loop { - match demuxer.next_packet() { - Ok(p) if p.stream == 0 => ours.push(p), - Ok(_) => {} - Err(e) if e.is_eof() => break, - Err(e) => return Verdict::Failed(format!("demux: {e}")), - } - } - if demuxer.damaged_pages() != 0 { - return Verdict::Failed(format!("{} damaged pages", demuxer.damaged_pages())); - } - - let probed = match ffprobe_packets(path) { - Ok(p) => p, - Err(e) => return Verdict::Failed(e), - }; - let payload = match ffmpeg_payload(path) { - Ok(p) => p, - Err(e) => return Verdict::Failed(e), - }; - let header_len = match ffprobe_extradata_size(path) { - Ok(n) => n, - Err(e) => return Verdict::Failed(e), - }; - - let mut problems: Vec = Vec::new(); - if ours.len() != probed.len() { - problems.push(format!( - "packet count {} (ffprobe {})", - ours.len(), - probed.len() - )); - } - let size_bad = ours - .iter() - .zip(&probed) - .filter(|(p, q)| p.data.len() != q.size) - .count(); - if size_bad > 0 { - problems.push(format!("{size_bad} packet sizes differ")); - } - let ours_payload: Vec = ours.iter().flat_map(|p| p.data.iter().copied()).collect(); - if ours_payload != payload { - let at = ours_payload - .iter() - .zip(&payload) - .position(|(a, b)| a != b) - .unwrap_or(ours_payload.len().min(payload.len())); - problems.push(format!( - "payload differs: {} bytes vs ffmpeg {}, first difference at byte {at}", - ours_payload.len(), - payload.len() - )); - } - if vorbis { - if let Some(p) = vorbis_header_problem(block) { - problems.push(p); - } - } else if block.len() != header_len { - problems.push(format!( - "header block {} bytes (ffprobe extradata {header_len})", - block.len() - )); - } - - // Timing, checked on the pairs both sides state. - let mut pts_checked = 0usize; - let mut pts_bad = 0usize; - let mut granule_checked = 0usize; - let mut granule_bad = 0usize; - let mut first_timing: Option = None; - for (i, (p, q)) in ours.iter().zip(&probed).enumerate() { - // The Vorbis first packet's start is the convention exception (see the - // module doc): not compared. - if let Some(pts) = p.pts.filter(|_| i > 0 || !vorbis) { - pts_checked += 1; - if q.pts.map(|f| f + pre_skip) != Some(pts) { - pts_bad += 1; - first_timing.get_or_insert(format!( - "packet {i}: pts {pts}, ffmpeg pts {:?} (+{pre_skip})", - q.pts - )); - } - } - if let Some(g) = granule_of(p) { - granule_checked += 1; - let end = q.pts.zip(q.duration).map(|(a, b)| a + b); - if end != Some(g - pre_skip) { - granule_bad += 1; - first_timing.get_or_insert(format!( - "packet {i}: granule {g}, ffmpeg end {end:?} (-{pre_skip})" - )); - } - } - } - if pts_bad > 0 { - problems.push(format!("{pts_bad} of {pts_checked} pts differ")); - } - if granule_bad > 0 { - problems.push(format!( - "{granule_bad} of {granule_checked} granule ends differ" - )); - } - if let Some(t) = first_timing { - problems.push(format!("first timing difference: {t}")); - } - - let summary = format!( - "{} packets, {} bytes, {} pts and {} granules checked", - ours.len(), - payload.len(), - pts_checked, - granule_checked - ); - if problems.is_empty() { - Verdict::Match(summary) - } else { - Verdict::Failed(format!("{summary}; {}", problems.join("; "))) - } -} - -/// Our Vorbis header block: three Xiph-laced packets, identification, -/// comment and setup, each carrying its own magic. `None` when it is sound. -fn vorbis_header_problem(block: &[u8]) -> Option { - let Ok(parts) = ec_ogg::xiph_unlace(block) else { - return Some("header block is not Xiph-laced".into()); - }; - if parts.len() != 3 { - return Some(format!("{} header packets, want 3", parts.len())); - } - for (part, kind) in parts.iter().zip([1u8, 3, 5]) { - if part.len() < 7 || part[0] != kind || &part[1..7] != b"vorbis" { - return Some(format!("header packet of kind {kind} lacks its magic")); - } - } - if parts[0].len() != 30 { - return Some(format!( - "identification header is {} bytes, want 30", - parts[0].len() - )); - } - None -} - -#[test] -fn real_library_ogg_streams_match_ffmpeg() { - let path = ec_testkit::fixture("open/sintel_trailer-480p.ogv"); - match check_file(&path) { - Verdict::Match(s) => eprintln!("{}: match: {s}", path.display()), - Verdict::Refused(e) | Verdict::Failed(e) => panic!("{}: {e}", path.display()), - } -}