forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

capability_matrix.rs194 lines, 8.2 KiBHistoryRawDownload
1//! The capability matrix against real files: what the unit test in
2//! `demux::tests` asserts about the dispatch tables, this asserts about the
3//! containers themselves — every codec the decoder layer can be handed opens
4//! from *both* an mp4 and a Matroska file, and says its own name.
5//!
6//! The defect class it exists for: VP9 shipped decodable out of an mp4 and
7//! refused out of a `.webm` with the VA-API VP9 decoder compiled in, because one
8//! dispatch arm was missing while the refusal string claimed the capability was
9//! absent. A gap must be a written-down row (`demux::UNSUPPORTED`), never a
10//! silent fall-through.
11//!
12//! Nothing installed is needed: these are container reads, not decodes.
13
14use std::path::PathBuf;
15
16use ec_core::Demuxer as _;
17use engine::AudioSession;
18use engine::demux::{Codec, Demuxer};
19
20fn asset(name: &str) -> PathBuf {
21 PathBuf::from(env!("CARGO_MANIFEST_DIR"))
22 .join("../../assets")
23 .join(name)
24}
25
26/// One row per cell of (codec × container). A cell with no fixture is a hole in
27/// the evidence, so every one of them is filled here.
28const MATRIX: &[(Codec, &str, &str)] = &[
29 (Codec::H264, "test_baseline.mp4", "test_h264.mkv"),
30 (Codec::Hevc, "test_hevc.mp4", "test_hevc.mkv"),
31 (Codec::Vp9, "test_vp9.mp4", "test_vp9.webm"),
32 (Codec::Vp8, "test_vp8.mp4", "test_vp8.webm"),
33 // `mp4 0.14` writes no `av01` sample entry, so there is no AV1 mp4 fixture
34 // to open; the mp4 half of that row is `av01`'s presence in the dispatch
35 // table, which `demux::tests` holds.
36 (Codec::Av1, "", "test_av1.mkv"),
37];
38
39#[test]
40fn every_codec_opens_from_every_container_it_arrives_in() {
41 for (codec, mp4, mkv) in MATRIX {
42 for file in [mp4, mkv].into_iter().filter(|f| !f.is_empty()) {
43 let (meta, _) = Demuxer::open(&asset(file))
44 .unwrap_or_else(|e| panic!("{file} carries {} and was refused: {e}", codec.name()));
45 assert_eq!(meta.codec, *codec, "{file}");
46 assert!(meta.frame_count > 0, "{file} came back with no frames");
47 assert_eq!((meta.width, meta.height), (1280, 720), "{file}");
48 }
49 }
50}
51
52/// The depth cell of the matrix: 10-bit is a property of the stream, and VP9
53/// states it in the one place neither container repeats — the keyframe's
54/// uncompressed header. Assumed 8-bit, a profile 2 stream decodes into an NV12
55/// pool and comes back as garbage.
56#[test]
57fn a_ten_bit_vp9_webm_is_read_as_ten_bit() {
58 let (meta, demuxer) = Demuxer::open(&asset("test_vp9_10.webm")).expect("open a profile 2 webm");
59 assert_eq!(meta.codec, Codec::Vp9);
60 assert_eq!(demuxer.bit_depth(), 10, "profile 2 is 10-bit");
61
62 let (_, eight) = Demuxer::open(&asset("test_vp9.webm")).expect("open a profile 0 webm");
63 assert_eq!(eight.bit_depth(), 8, "profile 0 is 8-bit by definition");
64
65 // ...and the probe put the read cursor back where it opened: frame 0 is the
66 // first picture out, not frame 1.
67 let (meta, mut demuxer) = Demuxer::open(&asset("test_vp9.webm")).expect("open");
68 let mut count = 0;
69 while demuxer.next_access_unit().expect("read").is_some() {
70 count += 1;
71 }
72 assert_eq!(
73 count, meta.frame_count,
74 "the depth probe ate an access unit"
75 );
76}
77
78/// The audio half, and the claim a refusal makes: every codec the "cannot be
79/// decoded" notice names as readable really opens, per container. It read "AAC
80/// and AC-3 only" while FLAC, MP3, Vorbis, ALAC and PCM all decoded out of a
81/// Matroska file — a refusal that undersells sends a user re-encoding a film
82/// whose sound already plays.
83#[test]
84fn every_audio_codec_the_refusal_names_really_decodes() {
85 // The five in one fixture, in the order `gen_fixtures.sh` muxes them, plus
86 // the AAC and AC-3 the older fixtures carry.
87 for (stream, codec) in [
88 (0, "flac"),
89 (1, "mp3"),
90 (2, "vorbis"),
91 (3, "alac"),
92 (4, "pcm"),
93 ] {
94 let probe = AudioSession::probe(asset("test_mkv_audio.mkv"), stream)
95 .unwrap_or_else(|e| panic!("{codec} in a Matroska file: {e}"))
96 .unwrap_or_else(|| panic!("{codec} in a Matroska file came back silent"));
97 assert_eq!(probe.sample_rate, 44_100, "{codec}");
98 }
99 // Opus, every container it arrives in: a `.webm` off the web, the `.mka` a
100 // 5.1 film soundtrack is remuxed into, and the standalone `.opus`. It was
101 // the last codec the notice named as absent while both readers here already
102 // *parsed* it -- `A_OPUS` and `OpusHead` have always mapped to symphonia's
103 // `CODEC_ID_OPUS`; only the decoder was missing, and it is `ec-opus` now.
104 for (file, what, channels) in [
105 ("test_vp9.webm", "opus in a webm", 1),
106 // 5.1 arrives as the stereo fold, exactly as a 5.1 AC-3 track does.
107 ("test_opus_51.mka", "5.1 opus in an mka", 2),
108 // ...and 7.1, the widest layout the fold has a table for and the one
109 // a real remux carries.
110 ("test_opus_71.mka", "7.1 opus in an mka", 2),
111 ("test_tone.opus", "a standalone opus", 2),
112 ] {
113 let probe = AudioSession::probe(asset(file), 0)
114 .unwrap_or_else(|e| panic!("{what}: {e}"))
115 .unwrap_or_else(|| panic!("{what} came back silent"));
116 assert_eq!(probe.sample_rate, 48_000, "{what}");
117 assert_eq!(probe.channels, channels, "{what}");
118 }
119 for (file, codec) in [("test_av1.mkv", "aac"), ("test_ac3.mkv", "ac-3")] {
120 assert!(
121 AudioSession::probe(asset(file), 0).expect(codec).is_some(),
122 "{codec} in a Matroska file came back silent"
123 );
124 }
125 for (file, codec) in [("test_av.mp4", "aac-lc"), ("test_ac3.mp4", "ac-3")] {
126 assert!(
127 AudioSession::probe(asset(file), 0).expect(codec).is_some(),
128 "{codec} in an mp4 came back silent"
129 );
130 }
131
132 // DTS is decoded by `ec-dts` now: its track is sound, not a refusal.
133 assert_eq!(
134 AudioSession::unsupported(asset("test_dts.mkv")).expect("read the header"),
135 None,
136 "a DTS track that decodes is not a refusal"
137 );
138 assert!(
139 AudioSession::probe(asset("test_dts.mkv"), 0).expect("probe DTS").is_some(),
140 "DTS came back silent"
141 );
142 // The other half of that claim, and the one a stale refusal string cannot
143 // fake: a file whose track really does decode has nothing to excuse.
144 assert_eq!(
145 AudioSession::unsupported(asset("test_vp9.webm")).expect("read the header"),
146 None,
147 "an Opus track that decodes is not a refusal"
148 );
149}
150
151/// Which of two video tracks an mp4 opens on may not depend on hash order: it is
152/// the first in `moov.traks`, file order, the same box the audio side numbers its
153/// streams out of. A `HashMap` walk here made a saved `.edith` reopen on the
154/// other picture from one launch to the next.
155#[test]
156fn the_video_track_of_an_mp4_is_the_first_one_in_file_order() {
157 let path = asset("test_two_video.mp4");
158 let file = std::fs::File::open(&path).expect("open the fixture");
159 let reader = ec_mp4::Mp4Demuxer::new(std::io::BufReader::new(file)).expect("header");
160
161 // What file order says, read straight off the movie box rather than through
162 // the map: the test may not share the code it is checking.
163 let first = reader
164 .tracks()
165 .iter()
166 .find(|t| t.media == Some(ec_core::MediaType::Video))
167 .and_then(|t| t.stream)
168 .expect("the fixture has two video tracks");
169 let stream = reader
170 .streams()
171 .iter()
172 .find(|s| s.index == first)
173 .expect("its stream");
174 let ec_core::MediaParameters::Video(video) = &stream.params.media else {
175 panic!("the first video track is a video stream");
176 };
177 let expected = (video.width, video.height);
178 assert_eq!(
179 expected,
180 (1280, 720),
181 "the fixture is the one it says it is"
182 );
183
184 // Repeated, because the failure this guards against is a *random* one: the
185 // hash order that picked the 320x240 track is a different order each run.
186 for _ in 0..8 {
187 let (meta, _) = Demuxer::open(&path).expect("open the two-track fixture");
188 assert_eq!(
189 (meta.width, meta.height),
190 expected,
191 "the demuxer opened the second video track"
192 );
193 }
194}