forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'main' into worktree-agent-a768f9cc6a31bfa54

Browse files at this commit

2f8f546525ef4b1da89be7c44db74ed8a6a69f42Ahmet Kaan GümüşParent: 07cd3d3522149d
crates/engine/tests/ao_output.rsmodified+29 -6
@@ -28,6 +28,23 @@ fn tone() -> Vec<f32> {
2828 samples
2929 }
3030
31+/// Opens the device the way this suite wants it: connected for real, and
32+/// silent. Everything these tests assert -- that the clock runs, at the right
33+/// rate, and stops when the stream is paused -- is measured from the device's
34+/// own position, which the gain does not touch: the frames are still consumed,
35+/// only the last multiply before the speaker is zero.
36+///
37+/// ponytail: it does mean the suite is deaf, so a plugin that shipped with the
38+/// gain stuck at zero would pass it. Nothing here could ever hear that -- the
39+/// checks that can are `scale`'s unit test in engine-audio (unity leaves the
40+/// bytes alone) and a person with the app open. The upgrade path is recording
41+/// a null sink and asserting on the samples that come back.
42+fn open_silent() -> AoSession {
43+ let ao = AoSession::open(RATE, CHANNELS).expect("no PipeWire playback available");
44+ assert!(ao.set_volume(0.0), "mute rejected");
45+ ao
46+}
47+
3148 /// Waits up to `limit` for the clock to report a played position past zero.
3249 fn wait_for_playback(ao: &AoSession, limit: Duration) -> i64 {
3350 let start = Instant::now();
@@ -46,7 +63,7 @@ fn wait_for_playback(ao: &AoSession, limit: Duration) -> i64 {
4663 #[ignore = "needs libengine_audio.so and a PipeWire daemon"]
4764 fn plays_and_tracks_position() {
4865 assert!(AoSession::probe(), "plugin not loadable");
49- let mut ao = AoSession::open(RATE, CHANNELS).expect("no PipeWire playback available");
66+ let mut ao = open_silent();
5067
5168 // The ring holds a second, so two halves go in whole -- enough real audio
5269 // to cover the measurement below without starving.
@@ -96,14 +113,13 @@ fn plays_and_tracks_position() {
96113 #[ignore = "needs libengine_audio.so and a PipeWire daemon"]
97114 fn muting_silences_without_stopping_the_clock() {
98115 assert!(AoSession::probe(), "plugin not loadable");
99- let mut ao = AoSession::open(RATE, CHANNELS).expect("no PipeWire playback available");
116+ let mut ao = open_silent();
100117
101118 let samples = tone();
102119 assert_eq!(ao.write(&samples), Some(samples.len()), "short write");
103120 let first = wait_for_playback(&ao, Duration::from_secs(2));
104121
105- // Mute, then keep it fed: the position must move exactly as it would have.
106- assert!(ao.set_volume(0.0), "mute rejected");
122+ // Muted and fed: the position must move exactly as it would have.
107123 assert_eq!(ao.write(&samples), Some(samples.len()), "short write");
108124 std::thread::sleep(Duration::from_millis(300));
109125 let muted = ao.position().expect("position went unknown");
@@ -115,8 +131,15 @@ fn muting_silences_without_stopping_the_clock() {
115131 "the clock stalled while muted: {advanced} samples in 300 ms"
116132 );
117133
118- // Every level in range is taken, and the two ends are in range.
119- for gain in [0.0, 0.5, 1.0] {
134+ // Every level in range is taken, and the two ends are in range. Done on an
135+ // emptied ring and left back at zero, so that the audible gains this walks
136+ // through have nothing but the underrun fill to be applied to: whoever runs
137+ // the suite should not have to hear it prove that 1.0 is a legal number.
138+ assert!(ao.flush(), "flush rejected");
139+ // A flush lands on the next callback and the ring refuses writes until it
140+ // does, so give it a couple of quanta before asking for anything else.
141+ std::thread::sleep(Duration::from_millis(50));
142+ for gain in [0.5, 1.0, 0.0] {
120143 assert!(ao.set_volume(gain), "gain {gain} rejected");
121144 }
122145 // Out of range is refused at the ABI rather than multiplied into the
crates/engine/tests/playback.rsmodified+35 -19
@@ -20,6 +20,22 @@ fn asset(name: &str) -> PathBuf {
2020 .join(name)
2121 }
2222
23+/// Opens a session the way every test here wants one: silent. The suite plays
24+/// real files through the real device, so without this a `cargo test` is two
25+/// minutes of noise out of the speakers of whoever ran it.
26+///
27+/// Muting is the gain knob, not a pause and not a fake device: the stream is
28+/// still connected, the daemon still schedules it, the samples are still
29+/// decoded, written, and handed over -- only the last multiply before the
30+/// device is zero. Every clock, `fed` and `played_out` assertion below is
31+/// therefore measuring exactly what it measured when this was audible.
32+fn open(path: impl AsRef<Path>) -> PlaybackSession {
33+ let session = PlaybackSession::open(path).expect("open");
34+ // False for the silent fixtures, which have no device to quieten.
35+ session.set_gain(0.0);
36+ session
37+}
38+
2339 /// One render tick of a front-end: advance the clock, take whatever frames are
2440 /// due. Returns the highest frame index seen so far.
2541 fn pump(session: &mut PlaybackSession, last_index: &mut Option<u32>) {
@@ -53,7 +69,7 @@ fn run_for(session: &mut PlaybackSession, last_index: &mut Option<u32>, duration
5369
5470 fn plays_at_real_speed(name: &str) {
5571 let path = asset(name);
56- let mut session = PlaybackSession::open(&path).expect("open");
72+ let mut session = open(&path);
5773 assert_eq!(session.now(), 0.0, "a fresh session starts at zero");
5874 assert!(!session.is_playing(), "a fresh session starts paused");
5975 let mut last_index = None;
@@ -161,7 +177,7 @@ fn threads() -> usize {
161177 /// Wall-clock seek: no audio track, so this runs anywhere.
162178 #[test]
163179 fn seek_repositions_video_and_clock() {
164- let mut session = PlaybackSession::open(asset("test_baseline.mp4")).expect("open");
180+ let mut session = open(asset("test_baseline.mp4"));
165181 let fps = session.meta().frame_rate;
166182 let mut last_index = None;
167183
@@ -195,7 +211,7 @@ fn seek_repositions_video_and_clock() {
195211 /// device is never fed another sample.
196212 #[test]
197213 fn seek_past_the_end_clamps() {
198- let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");
214+ let mut session = open(asset("test_av.mp4"));
199215 let meta = *session.meta();
200216 let duration = f64::from(meta.frame_count) / meta.frame_rate;
201217
@@ -224,7 +240,7 @@ fn seek_past_the_end_clamps() {
224240 /// abandoned workers behind, and the last one still wins.
225241 #[test]
226242 fn rapid_seeks_settle_on_the_last_one() {
227- let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");
243+ let mut session = open(asset("test_av.mp4"));
228244 let fps = session.meta().frame_rate;
229245 let mut last_index = None;
230246
@@ -254,7 +270,7 @@ fn rapid_seeks_settle_on_the_last_one() {
254270 #[test]
255271 #[ignore = "needs a running PipeWire daemon"]
256272 fn seek_keeps_the_audio_clock() {
257- let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");
273+ let mut session = open(asset("test_av.mp4"));
258274 let meta = *session.meta();
259275 let mut last_index = None;
260276
@@ -309,7 +325,7 @@ fn seek_keeps_the_audio_clock() {
309325 #[test]
310326 fn edits_traverse_cuts() {
311327 let path = asset("test_baseline.mp4");
312- let mut session = PlaybackSession::open(&path).expect("open");
328+ let mut session = open(&path);
313329 let (fps, total) = (session.meta().frame_rate, session.meta().frame_count);
314330 let whole = f64::from(total) / fps;
315331 assert!((session.timeline_duration() - whole).abs() < 1e-9);
@@ -407,7 +423,7 @@ fn edits_traverse_cuts() {
407423 #[test]
408424 fn paste_duplicates_a_clip_at_the_playhead() {
409425 let path = asset("test_baseline.mp4");
410- let mut session = PlaybackSession::open(&path).expect("open");
426+ let mut session = open(&path);
411427 let (fps, total) = (session.meta().frame_rate, session.meta().frame_count);
412428 let whole = f64::from(total) / fps;
413429
@@ -481,7 +497,7 @@ fn paste_duplicates_a_clip_at_the_playhead() {
481497 #[test]
482498 fn paste_while_playing_does_not_stall() {
483499 let path = asset("test_baseline.mp4");
484- let mut session = PlaybackSession::open(&path).expect("open");
500+ let mut session = open(&path);
485501 let (fps, total) = (session.meta().frame_rate, session.meta().frame_count);
486502 let mut last_index = None;
487503
@@ -519,7 +535,7 @@ fn paste_while_playing_does_not_stall() {
519535 #[test]
520536 fn paste_at_eos_revives_the_session() {
521537 let path = asset("test_baseline.mp4");
522- let mut session = PlaybackSession::open(&path).expect("open");
538+ let mut session = open(&path);
523539 let total = session.meta().frame_count;
524540
525541 assert!(session.cut_at(2.0), "cut at 2 s");
@@ -555,7 +571,7 @@ fn paste_at_eos_revives_the_session() {
555571 #[test]
556572 #[ignore = "needs a running PipeWire daemon"]
557573 fn edits_keep_the_audio_clock() {
558- let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");
574+ let mut session = open(asset("test_av.mp4"));
559575 let fps = session.meta().frame_rate;
560576 let mut last_index = None;
561577
@@ -622,7 +638,7 @@ fn frame_count(path: &Path) -> u32 {
622638 #[test]
623639 fn import_appends_a_second_source_and_plays_across_the_join() {
624640 let (av, av2) = (asset("test_av.mp4"), asset("test_av2.mp4"));
625- let mut session = PlaybackSession::open(&av).expect("open");
641+ let mut session = open(&av);
626642 let (fps, first) = (session.meta().frame_rate, session.meta().frame_count);
627643 let second = frame_count(&av2);
628644 assert_eq!((first, second), (150, 120), "fixtures changed");
@@ -708,7 +724,7 @@ fn import_appends_a_second_source_and_plays_across_the_join() {
708724 /// changes nothing.
709725 #[test]
710726 fn import_refuses_what_does_not_match() {
711- let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");
727+ let mut session = open(asset("test_av.mp4"));
712728
713729 let err = session
714730 .import(&asset("test_mismatch.mp4"))
@@ -731,7 +747,7 @@ fn import_refuses_what_does_not_match() {
731747 assert!((session.timeline_duration() - 5.0).abs() < 1e-9);
732748
733749 // The mirror: audio into a silent timeline is refused just as loudly.
734- let mut silent = PlaybackSession::open(asset("test_baseline.mp4")).expect("open");
750+ let mut silent = open(asset("test_baseline.mp4"));
735751 let err = silent
736752 .import(&asset("test_av.mp4"))
737753 .expect_err("audio into a silent timeline")
@@ -743,7 +759,7 @@ fn import_refuses_what_does_not_match() {
743759 /// out once and reused, which is what keeps clipboard clips valid forever.
744760 #[test]
745761 fn importing_one_file_twice_reuses_its_source() {
746- let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");
762+ let mut session = open(asset("test_av.mp4"));
747763 let av2 = asset("test_av2.mp4");
748764 session.import(&av2).expect("first import");
749765 session.import(&av2).expect("second import");
@@ -768,7 +784,7 @@ fn importing_one_file_twice_reuses_its_source() {
768784 #[test]
769785 fn import_at_eos_resumes_into_the_new_clip() {
770786 let av2 = asset("test_av2.mp4");
771- let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");
787+ let mut session = open(asset("test_av.mp4"));
772788 let first = session.meta().frame_count;
773789
774790 session.play();
@@ -797,7 +813,7 @@ fn a_vanished_source_is_skipped() {
797813 let scratch =
798814 std::env::temp_dir().join(format!("video_editor_vanish_{}.mp4", std::process::id()));
799815 std::fs::copy(asset("test_av2.mp4"), &scratch).expect("copy the fixture");
800- let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");
816+ let mut session = open(asset("test_av.mp4"));
801817 let first = session.meta().frame_count;
802818 session.import(&scratch).expect("import the copy");
803819 std::fs::remove_file(&scratch).expect("unlink");
@@ -816,7 +832,7 @@ fn a_vanished_source_is_skipped() {
816832 #[test]
817833 fn import_during_play_does_not_stall() {
818834 let (av, av2) = (asset("test_av.mp4"), asset("test_av2.mp4"));
819- let mut session = PlaybackSession::open(&av).expect("open");
835+ let mut session = open(&av);
820836 let first = session.meta().frame_count;
821837 let mut last_index = None;
822838
@@ -846,7 +862,7 @@ fn import_during_play_does_not_stall() {
846862 #[test]
847863 fn undo_after_import_is_one_step() {
848864 let av2 = asset("test_av2.mp4");
849- let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");
865+ let mut session = open(asset("test_av.mp4"));
850866 session.import(&av2).expect("import");
851867 assert_eq!(session.clip_spans().len(), 2);
852868 assert!((session.timeline_duration() - 9.0).abs() < 1e-9);
@@ -882,7 +898,7 @@ fn undo_after_import_is_one_step() {
882898 #[test]
883899 #[ignore = "needs a running PipeWire daemon"]
884900 fn audio_runs_across_a_source_join() {
885- let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");
901+ let mut session = open(asset("test_av.mp4"));
886902 session.import(&asset("test_av2.mp4")).expect("import");
887903 let first = session.meta().frame_count;
888904