forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

r14_probe_undo_streams.rs193 lines, 7.6 KiBHistoryRawDownload
1//! Dogfood round 14 on the engine's file-level answers: what a probe says about
2//! a file's streams and refusals, what an import says about sound it cannot
3//! play, rolling back a just-added source without losing undo, and placing a
4//! clip from a chosen audio track of a multi-audio file.
5//!
6//! ```text
7//! cargo test -p engine --release --test r14_probe_undo_streams -- --nocapture
8//! ```
9
10use std::path::PathBuf;
11
12use engine::demux::{StreamKind, picture_refusal, probe_media};
13use engine::{AudioSession, PlaybackSession};
14
15fn asset(name: &str) -> PathBuf {
16 PathBuf::from(env!("CARGO_MANIFEST_DIR"))
17 .join("../../assets")
18 .join(name)
19}
20
21fn quiet(session: &mut PlaybackSession) {
22 session.set_gain(0.0);
23}
24
25/// Audio languages as ffprobe reads them, in file order.
26#[test]
27fn mp4_audio_languages_match_the_file() {
28 let facts = probe_media(&asset("test_multiaudio.mp4"));
29 let audio: Vec<_> = facts
30 .streams
31 .iter()
32 .filter(|s| s.kind == StreamKind::Audio)
33 .map(|s| s.language.clone())
34 .collect();
35 assert_eq!(
36 audio,
37 [Some("und".into()), Some("fra".into()), Some("und".into())],
38 "the second track is French, read from its mdhd"
39 );
40 let lang = probe_media(&asset("test_multilang.mp4"));
41 let second = lang
42 .streams
43 .iter()
44 .filter(|s| s.kind == StreamKind::Audio)
45 .nth(1)
46 .and_then(|s| s.language.clone());
47 assert_eq!(second.as_deref(), Some("fra"));
48}
49
50/// Codec identifiers for sound-only files, the names ffprobe gives them.
51#[test]
52fn audio_only_files_name_their_codec() {
53 let cases = [
54 ("test_tone.flac", "flac"),
55 ("test_tone.mp3", "mp3"),
56 ("test_tone.opus", "opus"),
57 ("test_tone_cover.mpeg", "mp3"),
58 ];
59 for (name, codec) in cases {
60 let facts = probe_media(&asset(name));
61 let first = facts.streams.first().unwrap_or_else(|| panic!("{name}: no streams"));
62 assert_eq!(first.codec_id.as_deref(), Some(codec), "{name}");
63 }
64}
65
66/// A refused picture still lists its streams, and says why.
67#[test]
68fn refused_pictures_keep_their_streams_and_say_why() {
69 {
70 let name = "test_rotation45.mkv";
71 let facts = probe_media(&asset(name));
72 assert!(facts.video.is_none(), "{name}: the picture is refused");
73 assert!(
74 facts.streams.iter().any(|s| s.kind == StreamKind::Video),
75 "{name}: the video stream is still listed"
76 );
77 let why = picture_refusal(&asset(name)).unwrap_or_else(|| panic!("{name}: no reason"));
78 assert!(!why.is_empty(), "{name}");
79 }
80 assert_eq!(picture_refusal(&asset("test_av.mp4")), None, "a playable picture has no refusal");
81 assert_eq!(picture_refusal(&asset("test_tone.flac")), None, "sound alone has no picture to refuse");
82}
83
84/// Sound the build cannot decode imports with its picture, and the import says
85/// so as a returned warning -- not on stderr, and not as a silent success.
86#[test]
87fn unsupported_sound_on_import_is_a_returned_warning() {
88 let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the picture file");
89 quiet(&mut session);
90 let (source, warnings) = session
91 .import_with_warnings(&asset("test_dts.mkv"))
92 .expect("the picture imports");
93 assert!(session.sources().len() >= 2 && source < session.sources().len());
94 // DTS decodes now (`ec-dts`), so its track imports with sound and no warning.
95 assert!(warnings.is_empty(), "a DTS track that decodes draws no warning: {warnings:?}");
96
97 // A file whose sound plays draws no warning at all.
98 let (_, clean) = session
99 .import_with_warnings(&asset("test_multiaudio.mkv"))
100 .expect("a playable file imports");
101 assert!(clean.is_empty(), "no warning for playable sound: {clean:?}");
102}
103
104/// The rollback door: a source imported and then dropped while it is unused
105/// leaves the undo history as it was, and undo still works afterwards.
106#[test]
107fn removing_an_unused_source_keeps_undo() {
108 let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");
109 quiet(&mut session);
110 let clips_before = session.lane_clips(session.lanes()[0]).len();
111 let depth_before = session.undo_depth();
112
113 // An edit that gives undo something to do: take the first clip off the lane.
114 let lane = session.lanes()[0];
115 session.delete_clip(lane, 0);
116 let depth_after_edit = session.undo_depth();
117 assert!(depth_after_edit > depth_before, "the delete is undoable");
118
119 // Import, then roll the import back.
120 let other = asset("test_multiaudio.mkv");
121 let idx = session.import(&other).expect("import");
122 session.remove_unused_source(&other, 0).expect("the unused last source goes");
123 assert_eq!(session.sources().len(), idx, "back to the library before the import");
124 assert_eq!(
125 session.undo_depth(),
126 depth_after_edit,
127 "the history is not cleared by the rollback"
128 );
129
130 // And undo still restores the clip it removed.
131 assert!(session.undo());
132 assert_eq!(session.lane_clips(lane).len(), clips_before, "undo put the clip back");
133}
134
135/// A source a clip still plays, or an undo step still names, is refused, and
136/// the library is left alone.
137#[test]
138fn an_unused_source_refuses_when_something_still_names_it() {
139 let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");
140 quiet(&mut session);
141 let other = asset("test_multiaudio.mkv");
142 session.import(&other).expect("import");
143 let end = session.timeline_duration();
144 assert!(session.place_stream_at(end, &other, 0, None).expect("place"));
145 let sources = session.sources().len();
146 assert!(
147 session.remove_unused_source(&other, 0).is_err(),
148 "a clip plays it"
149 );
150 assert_eq!(session.sources().len(), sources, "nothing was removed");
151}
152
153/// A chosen audio track of a multi-audio file is placed by importing the file
154/// and then placing the stream: `import` takes stream 0, `place_stream_at` takes
155/// any other. The placed source keeps its stream number through a save.
156#[test]
157fn a_chosen_audio_track_is_placed_and_saved() {
158 let dir = engine::scratch::Scratch::dir("ve_r14_stream_place");
159 let file = dir.join("test_multiaudio.mkv");
160 std::fs::copy(asset("test_multiaudio.mkv"), &file).expect("copy");
161 let mut session = PlaybackSession::open(&file).expect("open the multi-audio file");
162 quiet(&mut session);
163 let end = session.timeline_duration();
164 assert!(
165 session.place_stream_at(end, &file, 1, None).expect("stream 1 is French"),
166 "the French track is placed"
167 );
168 let streams: Vec<usize> = session.sources().iter().map(|s| s.audio_stream).collect();
169 assert_eq!(streams, [0, 1], "stream 1 is its own source");
170
171 let path = dir.join("pick.edith");
172 session.save_project(&path).expect("save");
173 let loaded = PlaybackSession::open_project(&path).expect("reopen");
174 let back: Vec<usize> = loaded.sources().iter().map(|s| s.audio_stream).collect();
175 assert_eq!(back, [0, 1], "the chosen track comes back as the source it was");
176 std::fs::remove_dir_all(&dir).expect("cleanup");
177}
178
179/// The unsupported-sound answer flags only what no decoder here can take: AAC in
180/// an mp4 and DTS in a Matroska file both decode, so neither is flagged.
181#[test]
182fn unsupported_flags_only_what_cannot_decode() {
183 assert_eq!(
184 AudioSession::unsupported(asset("test_av.mp4")).expect("header reads"),
185 None,
186 "AAC in an mp4 plays and is not a refusal"
187 );
188 assert_eq!(
189 AudioSession::unsupported(asset("test_dts.mkv")).expect("header reads"),
190 None,
191 "DTS in a Matroska file decodes and is not a refusal"
192 );
193}