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> {
28 samples28 samples
29 }29 }
30 30
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+
31 /// Waits up to `limit` for the clock to report a played position past zero.48 /// Waits up to `limit` for the clock to report a played position past zero.
32 fn wait_for_playback(ao: &AoSession, limit: Duration) -> i64 {49 fn wait_for_playback(ao: &AoSession, limit: Duration) -> i64 {
33 let start = Instant::now();50 let start = Instant::now();
@@ -46,7 +63,7 @@ fn wait_for_playback(ao: &AoSession, limit: Duration) -> i64 {
46 #[ignore = "needs libengine_audio.so and a PipeWire daemon"]63 #[ignore = "needs libengine_audio.so and a PipeWire daemon"]
47 fn plays_and_tracks_position() {64 fn plays_and_tracks_position() {
48 assert!(AoSession::probe(), "plugin not loadable");65 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();
50 67
51 // The ring holds a second, so two halves go in whole -- enough real audio68 // The ring holds a second, so two halves go in whole -- enough real audio
52 // to cover the measurement below without starving.69 // to cover the measurement below without starving.
@@ -96,14 +113,13 @@ fn plays_and_tracks_position() {
96 #[ignore = "needs libengine_audio.so and a PipeWire daemon"]113 #[ignore = "needs libengine_audio.so and a PipeWire daemon"]
97 fn muting_silences_without_stopping_the_clock() {114 fn muting_silences_without_stopping_the_clock() {
98 assert!(AoSession::probe(), "plugin not loadable");115 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();
100 117
101 let samples = tone();118 let samples = tone();
102 assert_eq!(ao.write(&samples), Some(samples.len()), "short write");119 assert_eq!(ao.write(&samples), Some(samples.len()), "short write");
103 let first = wait_for_playback(&ao, Duration::from_secs(2));120 let first = wait_for_playback(&ao, Duration::from_secs(2));
104 121
105- // Mute, then keep it fed: the position must move exactly as it would have.122+ // Muted and fed: the position must move exactly as it would have.
106- assert!(ao.set_volume(0.0), "mute rejected");
107 assert_eq!(ao.write(&samples), Some(samples.len()), "short write");123 assert_eq!(ao.write(&samples), Some(samples.len()), "short write");
108 std::thread::sleep(Duration::from_millis(300));124 std::thread::sleep(Duration::from_millis(300));
109 let muted = ao.position().expect("position went unknown");125 let muted = ao.position().expect("position went unknown");
@@ -115,8 +131,15 @@ fn muting_silences_without_stopping_the_clock() {
115 "the clock stalled while muted: {advanced} samples in 300 ms"131 "the clock stalled while muted: {advanced} samples in 300 ms"
116 );132 );
117 133
118- // Every level in range is taken, and the two ends are in range.134+ // Every level in range is taken, and the two ends are in range. Done on an
119- for gain in [0.0, 0.5, 1.0] {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] {
120 assert!(ao.set_volume(gain), "gain {gain} rejected");143 assert!(ao.set_volume(gain), "gain {gain} rejected");
121 }144 }
122 // Out of range is refused at the ABI rather than multiplied into the145 // 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 {
20 .join(name)20 .join(name)
21 }21 }
22 22
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+
23 /// One render tick of a front-end: advance the clock, take whatever frames are39 /// One render tick of a front-end: advance the clock, take whatever frames are
24 /// due. Returns the highest frame index seen so far.40 /// due. Returns the highest frame index seen so far.
25 fn pump(session: &mut PlaybackSession, last_index: &mut Option<u32>) {41 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
53 69
54 fn plays_at_real_speed(name: &str) {70 fn plays_at_real_speed(name: &str) {
55 let path = asset(name);71 let path = asset(name);
56- let mut session = PlaybackSession::open(&path).expect("open");72+ let mut session = open(&path);
57 assert_eq!(session.now(), 0.0, "a fresh session starts at zero");73 assert_eq!(session.now(), 0.0, "a fresh session starts at zero");
58 assert!(!session.is_playing(), "a fresh session starts paused");74 assert!(!session.is_playing(), "a fresh session starts paused");
59 let mut last_index = None;75 let mut last_index = None;
@@ -161,7 +177,7 @@ fn threads() -> usize {
161 /// Wall-clock seek: no audio track, so this runs anywhere.177 /// Wall-clock seek: no audio track, so this runs anywhere.
162 #[test]178 #[test]
163 fn seek_repositions_video_and_clock() {179 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"));
165 let fps = session.meta().frame_rate;181 let fps = session.meta().frame_rate;
166 let mut last_index = None;182 let mut last_index = None;
167 183
@@ -195,7 +211,7 @@ fn seek_repositions_video_and_clock() {
195 /// device is never fed another sample.211 /// device is never fed another sample.
196 #[test]212 #[test]
197 fn seek_past_the_end_clamps() {213 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"));
199 let meta = *session.meta();215 let meta = *session.meta();
200 let duration = f64::from(meta.frame_count) / meta.frame_rate;216 let duration = f64::from(meta.frame_count) / meta.frame_rate;
201 217
@@ -224,7 +240,7 @@ fn seek_past_the_end_clamps() {
224 /// abandoned workers behind, and the last one still wins.240 /// abandoned workers behind, and the last one still wins.
225 #[test]241 #[test]
226 fn rapid_seeks_settle_on_the_last_one() {242 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"));
228 let fps = session.meta().frame_rate;244 let fps = session.meta().frame_rate;
229 let mut last_index = None;245 let mut last_index = None;
230 246
@@ -254,7 +270,7 @@ fn rapid_seeks_settle_on_the_last_one() {
254 #[test]270 #[test]
255 #[ignore = "needs a running PipeWire daemon"]271 #[ignore = "needs a running PipeWire daemon"]
256 fn seek_keeps_the_audio_clock() {272 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"));
258 let meta = *session.meta();274 let meta = *session.meta();
259 let mut last_index = None;275 let mut last_index = None;
260 276
@@ -309,7 +325,7 @@ fn seek_keeps_the_audio_clock() {
309 #[test]325 #[test]
310 fn edits_traverse_cuts() {326 fn edits_traverse_cuts() {
311 let path = asset("test_baseline.mp4");327 let path = asset("test_baseline.mp4");
312- let mut session = PlaybackSession::open(&path).expect("open");328+ let mut session = open(&path);
313 let (fps, total) = (session.meta().frame_rate, session.meta().frame_count);329 let (fps, total) = (session.meta().frame_rate, session.meta().frame_count);
314 let whole = f64::from(total) / fps;330 let whole = f64::from(total) / fps;
315 assert!((session.timeline_duration() - whole).abs() < 1e-9);331 assert!((session.timeline_duration() - whole).abs() < 1e-9);
@@ -407,7 +423,7 @@ fn edits_traverse_cuts() {
407 #[test]423 #[test]
408 fn paste_duplicates_a_clip_at_the_playhead() {424 fn paste_duplicates_a_clip_at_the_playhead() {
409 let path = asset("test_baseline.mp4");425 let path = asset("test_baseline.mp4");
410- let mut session = PlaybackSession::open(&path).expect("open");426+ let mut session = open(&path);
411 let (fps, total) = (session.meta().frame_rate, session.meta().frame_count);427 let (fps, total) = (session.meta().frame_rate, session.meta().frame_count);
412 let whole = f64::from(total) / fps;428 let whole = f64::from(total) / fps;
413 429
@@ -481,7 +497,7 @@ fn paste_duplicates_a_clip_at_the_playhead() {
481 #[test]497 #[test]
482 fn paste_while_playing_does_not_stall() {498 fn paste_while_playing_does_not_stall() {
483 let path = asset("test_baseline.mp4");499 let path = asset("test_baseline.mp4");
484- let mut session = PlaybackSession::open(&path).expect("open");500+ let mut session = open(&path);
485 let (fps, total) = (session.meta().frame_rate, session.meta().frame_count);501 let (fps, total) = (session.meta().frame_rate, session.meta().frame_count);
486 let mut last_index = None;502 let mut last_index = None;
487 503
@@ -519,7 +535,7 @@ fn paste_while_playing_does_not_stall() {
519 #[test]535 #[test]
520 fn paste_at_eos_revives_the_session() {536 fn paste_at_eos_revives_the_session() {
521 let path = asset("test_baseline.mp4");537 let path = asset("test_baseline.mp4");
522- let mut session = PlaybackSession::open(&path).expect("open");538+ let mut session = open(&path);
523 let total = session.meta().frame_count;539 let total = session.meta().frame_count;
524 540
525 assert!(session.cut_at(2.0), "cut at 2 s");541 assert!(session.cut_at(2.0), "cut at 2 s");
@@ -555,7 +571,7 @@ fn paste_at_eos_revives_the_session() {
555 #[test]571 #[test]
556 #[ignore = "needs a running PipeWire daemon"]572 #[ignore = "needs a running PipeWire daemon"]
557 fn edits_keep_the_audio_clock() {573 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"));
559 let fps = session.meta().frame_rate;575 let fps = session.meta().frame_rate;
560 let mut last_index = None;576 let mut last_index = None;
561 577
@@ -622,7 +638,7 @@ fn frame_count(path: &Path) -> u32 {
622 #[test]638 #[test]
623 fn import_appends_a_second_source_and_plays_across_the_join() {639 fn import_appends_a_second_source_and_plays_across_the_join() {
624 let (av, av2) = (asset("test_av.mp4"), asset("test_av2.mp4"));640 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);
626 let (fps, first) = (session.meta().frame_rate, session.meta().frame_count);642 let (fps, first) = (session.meta().frame_rate, session.meta().frame_count);
627 let second = frame_count(&av2);643 let second = frame_count(&av2);
628 assert_eq!((first, second), (150, 120), "fixtures changed");644 assert_eq!((first, second), (150, 120), "fixtures changed");
@@ -708,7 +724,7 @@ fn import_appends_a_second_source_and_plays_across_the_join() {
708 /// changes nothing.724 /// changes nothing.
709 #[test]725 #[test]
710 fn import_refuses_what_does_not_match() {726 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"));
712 728
713 let err = session729 let err = session
714 .import(&asset("test_mismatch.mp4"))730 .import(&asset("test_mismatch.mp4"))
@@ -731,7 +747,7 @@ fn import_refuses_what_does_not_match() {
731 assert!((session.timeline_duration() - 5.0).abs() < 1e-9);747 assert!((session.timeline_duration() - 5.0).abs() < 1e-9);
732 748
733 // The mirror: audio into a silent timeline is refused just as loudly.749 // 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"));
735 let err = silent751 let err = silent
736 .import(&asset("test_av.mp4"))752 .import(&asset("test_av.mp4"))
737 .expect_err("audio into a silent timeline")753 .expect_err("audio into a silent timeline")
@@ -743,7 +759,7 @@ fn import_refuses_what_does_not_match() {
743 /// out once and reused, which is what keeps clipboard clips valid forever.759 /// out once and reused, which is what keeps clipboard clips valid forever.
744 #[test]760 #[test]
745 fn importing_one_file_twice_reuses_its_source() {761 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"));
747 let av2 = asset("test_av2.mp4");763 let av2 = asset("test_av2.mp4");
748 session.import(&av2).expect("first import");764 session.import(&av2).expect("first import");
749 session.import(&av2).expect("second import");765 session.import(&av2).expect("second import");
@@ -768,7 +784,7 @@ fn importing_one_file_twice_reuses_its_source() {
768 #[test]784 #[test]
769 fn import_at_eos_resumes_into_the_new_clip() {785 fn import_at_eos_resumes_into_the_new_clip() {
770 let av2 = asset("test_av2.mp4");786 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"));
772 let first = session.meta().frame_count;788 let first = session.meta().frame_count;
773 789
774 session.play();790 session.play();
@@ -797,7 +813,7 @@ fn a_vanished_source_is_skipped() {
797 let scratch =813 let scratch =
798 std::env::temp_dir().join(format!("video_editor_vanish_{}.mp4", std::process::id()));814 std::env::temp_dir().join(format!("video_editor_vanish_{}.mp4", std::process::id()));
799 std::fs::copy(asset("test_av2.mp4"), &scratch).expect("copy the fixture");815 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"));
801 let first = session.meta().frame_count;817 let first = session.meta().frame_count;
802 session.import(&scratch).expect("import the copy");818 session.import(&scratch).expect("import the copy");
803 std::fs::remove_file(&scratch).expect("unlink");819 std::fs::remove_file(&scratch).expect("unlink");
@@ -816,7 +832,7 @@ fn a_vanished_source_is_skipped() {
816 #[test]832 #[test]
817 fn import_during_play_does_not_stall() {833 fn import_during_play_does_not_stall() {
818 let (av, av2) = (asset("test_av.mp4"), asset("test_av2.mp4"));834 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);
820 let first = session.meta().frame_count;836 let first = session.meta().frame_count;
821 let mut last_index = None;837 let mut last_index = None;
822 838
@@ -846,7 +862,7 @@ fn import_during_play_does_not_stall() {
846 #[test]862 #[test]
847 fn undo_after_import_is_one_step() {863 fn undo_after_import_is_one_step() {
848 let av2 = asset("test_av2.mp4");864 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"));
850 session.import(&av2).expect("import");866 session.import(&av2).expect("import");
851 assert_eq!(session.clip_spans().len(), 2);867 assert_eq!(session.clip_spans().len(), 2);
852 assert!((session.timeline_duration() - 9.0).abs() < 1e-9);868 assert!((session.timeline_duration() - 9.0).abs() < 1e-9);
@@ -882,7 +898,7 @@ fn undo_after_import_is_one_step() {
882 #[test]898 #[test]
883 #[ignore = "needs a running PipeWire daemon"]899 #[ignore = "needs a running PipeWire daemon"]
884 fn audio_runs_across_a_source_join() {900 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"));
886 session.import(&asset("test_av2.mp4")).expect("import");902 session.import(&asset("test_av2.mp4")).expect("import");
887 let first = session.meta().frame_count;903 let first = session.meta().frame_count;
888 904