forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

committed.rs61 lines, 2.4 KiBHistoryRawDownload
1//! The committed tiny fixtures (`tests/data`, made by `data/gen.sh` from synthetic
2//! sources) against the hashes of ffmpeg's own bytes in `expected.txt`. No ffmpeg
3//! needed.
4
5use std::collections::BTreeMap;
6use std::fs::File;
7use std::io::BufReader;
8
9use crate::common::*;
10use ec_core::registry::Demuxer;
11use ec_mpegts::TsDemuxer;
12
13#[test]
14fn bytes_match_ffmpeg() {
15 let text = std::fs::read_to_string(data().join("expected.txt")).unwrap();
16 let mut by_file: BTreeMap<&str, Vec<(u32, usize, usize, u64)>> = BTreeMap::new();
17 for l in text.lines() {
18 let f: Vec<&str> = l.split(' ').collect();
19 by_file.entry(f[0]).or_default().push((
20 f[1].parse().unwrap(),
21 f[2].parse().unwrap(),
22 f[3].parse().unwrap(),
23 u64::from_str_radix(f[4], 16).unwrap(),
24 ));
25 }
26 assert_eq!(by_file.len(), 5);
27 for (file, rows) in by_file {
28 let mut d = TsDemuxer::new(BufReader::new(File::open(data().join(file)).unwrap())).unwrap();
29 let mut per: BTreeMap<u32, Vec<u8>> = BTreeMap::new();
30 let mut counts: BTreeMap<u32, usize> = BTreeMap::new();
31 while let Ok(p) = d.next_packet() {
32 per.entry(p.stream).or_default().extend_from_slice(&p.data);
33 *counts.entry(p.stream).or_default() += 1;
34 }
35 assert_eq!(d.streams().len(), 2, "{file}");
36 for (idx, packets, bytes, hash) in rows {
37 // ffmpeg's second audio packet count for LPCM is its own framing; the
38 // demuxer's is one packet per PES.
39 if !file.contains("lpcm") || idx == 0 {
40 assert_eq!(counts[&idx], packets, "{file} stream {idx} packets");
41 }
42 let got = &per[&idx];
43 assert_eq!(got.len(), bytes, "{file} stream {idx} bytes");
44 assert_eq!(fnv(got.iter().copied()), hash, "{file} stream {idx} hash");
45 }
46 assert!(d.duration_secs().unwrap() > 0.2, "{file}");
47 }
48}
49
50#[test]
51fn m2ts_is_detected_and_probed() {
52 let head = std::fs::read(data().join("tiny_h264_ac3.m2ts")).unwrap();
53 assert!(ec_mpegts::is_mpegts(&head[..4096]));
54 let d = TsDemuxer::new(BufReader::new(
55 File::open(data().join("tiny_h264_ac3.m2ts")).unwrap(),
56 ))
57 .unwrap();
58 assert_eq!((d.packet_size(), d.is_bdav()), (192, true));
59 assert!(!ec_mpegts::is_mpegts(b"RIFFxxxxWAVEfmt "));
60 assert!(!ec_mpegts::is_mpegts(&[]));
61}