forge
Explore
Log in

Don't you dare go Hollow

Silence the suites that reach the speaker

Browse files at this commit

522149da9cf3e1bea23bdc924b0ae016050dd142Ahmet Kaan GümüşParent: bb07bdc
  • test
    • silence the suites that reach the speaker
Show full message
🔇 test(audio): silence the suites that reach the speaker

`cargo test` played real files out of the real device: measured 0.37 of
full scale on the sink monitor, 818k nonzero samples, for as long as the
playback suite ran. That is somebody's desk, every run.

Both suites now open through a helper that sets the gain to zero. Nothing
else changes: the stream is still connected and scheduled, the samples are
still decoded, written and handed over, and every assertion here is
measured from the device's own position, which the gain does not touch.
The one test that walks through audible gains does it on a flushed ring,
where there is nothing but the underrun fill to apply them to.

Measured after: peak 0, not one nonzero sample, all three suites green.
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
@@ -19,6 +19,22 @@ fn asset(name: &str) -> PathBuf {
19 .join(name)19 .join(name)
20 }20 }
21 21
22+/// Opens a session the way every test here wants one: silent. The suite plays
23+/// real files through the real device, so without this a `cargo test` is two
24+/// minutes of noise out of the speakers of whoever ran it.
25+///
26+/// Muting is the gain knob, not a pause and not a fake device: the stream is
27+/// still connected, the daemon still schedules it, the samples are still
28+/// decoded, written, and handed over -- only the last multiply before the
29+/// device is zero. Every clock, `fed` and `played_out` assertion below is
30+/// therefore measuring exactly what it measured when this was audible.
31+fn open(path: impl AsRef<Path>) -> PlaybackSession {
32+ let session = PlaybackSession::open(path).expect("open");
33+ // False for the silent fixtures, which have no device to quieten.
34+ session.set_gain(0.0);
35+ session
36+}
37+
22 /// One render tick of a front-end: advance the clock, take whatever frames are38 /// One render tick of a front-end: advance the clock, take whatever frames are
23 /// due. Returns the highest frame index seen so far.39 /// due. Returns the highest frame index seen so far.
24 fn pump(session: &mut PlaybackSession, last_index: &mut Option<u32>) {40 fn pump(session: &mut PlaybackSession, last_index: &mut Option<u32>) {
@@ -52,7 +68,7 @@ fn run_for(session: &mut PlaybackSession, last_index: &mut Option<u32>, duration
52 68
53 fn plays_at_real_speed(name: &str) {69 fn plays_at_real_speed(name: &str) {
54 let path = asset(name);70 let path = asset(name);
55- let mut session = PlaybackSession::open(&path).expect("open");71+ let mut session = open(&path);
56 assert_eq!(session.now(), 0.0, "a fresh session starts at zero");72 assert_eq!(session.now(), 0.0, "a fresh session starts at zero");
57 assert!(!session.is_playing(), "a fresh session starts paused");73 assert!(!session.is_playing(), "a fresh session starts paused");
58 let mut last_index = None;74 let mut last_index = None;
@@ -160,7 +176,7 @@ fn threads() -> usize {
160 /// Wall-clock seek: no audio track, so this runs anywhere.176 /// Wall-clock seek: no audio track, so this runs anywhere.
161 #[test]177 #[test]
162 fn seek_repositions_video_and_clock() {178 fn seek_repositions_video_and_clock() {
163- let mut session = PlaybackSession::open(asset("test_baseline.mp4")).expect("open");179+ let mut session = open(asset("test_baseline.mp4"));
164 let fps = session.meta().frame_rate;180 let fps = session.meta().frame_rate;
165 let mut last_index = None;181 let mut last_index = None;
166 182
@@ -194,7 +210,7 @@ fn seek_repositions_video_and_clock() {
194 /// device is never fed another sample.210 /// device is never fed another sample.
195 #[test]211 #[test]
196 fn seek_past_the_end_clamps() {212 fn seek_past_the_end_clamps() {
197- let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");213+ let mut session = open(asset("test_av.mp4"));
198 let meta = *session.meta();214 let meta = *session.meta();
199 let duration = f64::from(meta.frame_count) / meta.frame_rate;215 let duration = f64::from(meta.frame_count) / meta.frame_rate;
200 216
@@ -223,7 +239,7 @@ fn seek_past_the_end_clamps() {
223 /// abandoned workers behind, and the last one still wins.239 /// abandoned workers behind, and the last one still wins.
224 #[test]240 #[test]
225 fn rapid_seeks_settle_on_the_last_one() {241 fn rapid_seeks_settle_on_the_last_one() {
226- let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");242+ let mut session = open(asset("test_av.mp4"));
227 let fps = session.meta().frame_rate;243 let fps = session.meta().frame_rate;
228 let mut last_index = None;244 let mut last_index = None;
229 245
@@ -253,7 +269,7 @@ fn rapid_seeks_settle_on_the_last_one() {
253 #[test]269 #[test]
254 #[ignore = "needs a running PipeWire daemon"]270 #[ignore = "needs a running PipeWire daemon"]
255 fn seek_keeps_the_audio_clock() {271 fn seek_keeps_the_audio_clock() {
256- let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");272+ let mut session = open(asset("test_av.mp4"));
257 let meta = *session.meta();273 let meta = *session.meta();
258 let mut last_index = None;274 let mut last_index = None;
259 275
@@ -308,7 +324,7 @@ fn seek_keeps_the_audio_clock() {
308 #[test]324 #[test]
309 fn edits_traverse_cuts() {325 fn edits_traverse_cuts() {
310 let path = asset("test_baseline.mp4");326 let path = asset("test_baseline.mp4");
311- let mut session = PlaybackSession::open(&path).expect("open");327+ let mut session = open(&path);
312 let (fps, total) = (session.meta().frame_rate, session.meta().frame_count);328 let (fps, total) = (session.meta().frame_rate, session.meta().frame_count);
313 let whole = f64::from(total) / fps;329 let whole = f64::from(total) / fps;
314 assert!((session.timeline_duration() - whole).abs() < 1e-9);330 assert!((session.timeline_duration() - whole).abs() < 1e-9);
@@ -406,7 +422,7 @@ fn edits_traverse_cuts() {
406 #[test]422 #[test]
407 fn paste_duplicates_a_clip_at_the_playhead() {423 fn paste_duplicates_a_clip_at_the_playhead() {
408 let path = asset("test_baseline.mp4");424 let path = asset("test_baseline.mp4");
409- let mut session = PlaybackSession::open(&path).expect("open");425+ let mut session = open(&path);
410 let (fps, total) = (session.meta().frame_rate, session.meta().frame_count);426 let (fps, total) = (session.meta().frame_rate, session.meta().frame_count);
411 let whole = f64::from(total) / fps;427 let whole = f64::from(total) / fps;
412 428
@@ -480,7 +496,7 @@ fn paste_duplicates_a_clip_at_the_playhead() {
480 #[test]496 #[test]
481 fn paste_while_playing_does_not_stall() {497 fn paste_while_playing_does_not_stall() {
482 let path = asset("test_baseline.mp4");498 let path = asset("test_baseline.mp4");
483- let mut session = PlaybackSession::open(&path).expect("open");499+ let mut session = open(&path);
484 let (fps, total) = (session.meta().frame_rate, session.meta().frame_count);500 let (fps, total) = (session.meta().frame_rate, session.meta().frame_count);
485 let mut last_index = None;501 let mut last_index = None;
486 502
@@ -518,7 +534,7 @@ fn paste_while_playing_does_not_stall() {
518 #[test]534 #[test]
519 fn paste_at_eos_revives_the_session() {535 fn paste_at_eos_revives_the_session() {
520 let path = asset("test_baseline.mp4");536 let path = asset("test_baseline.mp4");
521- let mut session = PlaybackSession::open(&path).expect("open");537+ let mut session = open(&path);
522 let total = session.meta().frame_count;538 let total = session.meta().frame_count;
523 539
524 assert!(session.cut_at(2.0), "cut at 2 s");540 assert!(session.cut_at(2.0), "cut at 2 s");
@@ -554,7 +570,7 @@ fn paste_at_eos_revives_the_session() {
554 #[test]570 #[test]
555 #[ignore = "needs a running PipeWire daemon"]571 #[ignore = "needs a running PipeWire daemon"]
556 fn edits_keep_the_audio_clock() {572 fn edits_keep_the_audio_clock() {
557- let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");573+ let mut session = open(asset("test_av.mp4"));
558 let fps = session.meta().frame_rate;574 let fps = session.meta().frame_rate;
559 let mut last_index = None;575 let mut last_index = None;
560 576
@@ -621,7 +637,7 @@ fn frame_count(path: &Path) -> u32 {
621 #[test]637 #[test]
622 fn import_appends_a_second_source_and_plays_across_the_join() {638 fn import_appends_a_second_source_and_plays_across_the_join() {
623 let (av, av2) = (asset("test_av.mp4"), asset("test_av2.mp4"));639 let (av, av2) = (asset("test_av.mp4"), asset("test_av2.mp4"));
624- let mut session = PlaybackSession::open(&av).expect("open");640+ let mut session = open(&av);
625 let (fps, first) = (session.meta().frame_rate, session.meta().frame_count);641 let (fps, first) = (session.meta().frame_rate, session.meta().frame_count);
626 let second = frame_count(&av2);642 let second = frame_count(&av2);
627 assert_eq!((first, second), (150, 120), "fixtures changed");643 assert_eq!((first, second), (150, 120), "fixtures changed");
@@ -707,7 +723,7 @@ fn import_appends_a_second_source_and_plays_across_the_join() {
707 /// changes nothing.723 /// changes nothing.
708 #[test]724 #[test]
709 fn import_refuses_what_does_not_match() {725 fn import_refuses_what_does_not_match() {
710- let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");726+ let mut session = open(asset("test_av.mp4"));
711 727
712 let err = session728 let err = session
713 .import(&asset("test_mismatch.mp4"))729 .import(&asset("test_mismatch.mp4"))
@@ -730,7 +746,7 @@ fn import_refuses_what_does_not_match() {
730 assert!((session.timeline_duration() - 5.0).abs() < 1e-9);746 assert!((session.timeline_duration() - 5.0).abs() < 1e-9);
731 747
732 // The mirror: audio into a silent timeline is refused just as loudly.748 // The mirror: audio into a silent timeline is refused just as loudly.
733- let mut silent = PlaybackSession::open(asset("test_baseline.mp4")).expect("open");749+ let mut silent = open(asset("test_baseline.mp4"));
734 let err = silent750 let err = silent
735 .import(&asset("test_av.mp4"))751 .import(&asset("test_av.mp4"))
736 .expect_err("audio into a silent timeline")752 .expect_err("audio into a silent timeline")
@@ -742,7 +758,7 @@ fn import_refuses_what_does_not_match() {
742 /// out once and reused, which is what keeps clipboard clips valid forever.758 /// out once and reused, which is what keeps clipboard clips valid forever.
743 #[test]759 #[test]
744 fn importing_one_file_twice_reuses_its_source() {760 fn importing_one_file_twice_reuses_its_source() {
745- let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");761+ let mut session = open(asset("test_av.mp4"));
746 let av2 = asset("test_av2.mp4");762 let av2 = asset("test_av2.mp4");
747 session.import(&av2).expect("first import");763 session.import(&av2).expect("first import");
748 session.import(&av2).expect("second import");764 session.import(&av2).expect("second import");
@@ -767,7 +783,7 @@ fn importing_one_file_twice_reuses_its_source() {
767 #[test]783 #[test]
768 fn import_at_eos_resumes_into_the_new_clip() {784 fn import_at_eos_resumes_into_the_new_clip() {
769 let av2 = asset("test_av2.mp4");785 let av2 = asset("test_av2.mp4");
770- let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");786+ let mut session = open(asset("test_av.mp4"));
771 let first = session.meta().frame_count;787 let first = session.meta().frame_count;
772 788
773 session.play();789 session.play();
@@ -796,7 +812,7 @@ fn a_vanished_source_is_skipped() {
796 let scratch =812 let scratch =
797 std::env::temp_dir().join(format!("video_editor_vanish_{}.mp4", std::process::id()));813 std::env::temp_dir().join(format!("video_editor_vanish_{}.mp4", std::process::id()));
798 std::fs::copy(asset("test_av2.mp4"), &scratch).expect("copy the fixture");814 std::fs::copy(asset("test_av2.mp4"), &scratch).expect("copy the fixture");
799- let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");815+ let mut session = open(asset("test_av.mp4"));
800 let first = session.meta().frame_count;816 let first = session.meta().frame_count;
801 session.import(&scratch).expect("import the copy");817 session.import(&scratch).expect("import the copy");
802 std::fs::remove_file(&scratch).expect("unlink");818 std::fs::remove_file(&scratch).expect("unlink");
@@ -815,7 +831,7 @@ fn a_vanished_source_is_skipped() {
815 #[test]831 #[test]
816 fn import_during_play_does_not_stall() {832 fn import_during_play_does_not_stall() {
817 let (av, av2) = (asset("test_av.mp4"), asset("test_av2.mp4"));833 let (av, av2) = (asset("test_av.mp4"), asset("test_av2.mp4"));
818- let mut session = PlaybackSession::open(&av).expect("open");834+ let mut session = open(&av);
819 let first = session.meta().frame_count;835 let first = session.meta().frame_count;
820 let mut last_index = None;836 let mut last_index = None;
821 837
@@ -845,7 +861,7 @@ fn import_during_play_does_not_stall() {
845 #[test]861 #[test]
846 fn undo_after_import_is_one_step() {862 fn undo_after_import_is_one_step() {
847 let av2 = asset("test_av2.mp4");863 let av2 = asset("test_av2.mp4");
848- let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");864+ let mut session = open(asset("test_av.mp4"));
849 session.import(&av2).expect("import");865 session.import(&av2).expect("import");
850 assert_eq!(session.clip_spans().len(), 2);866 assert_eq!(session.clip_spans().len(), 2);
851 assert!((session.timeline_duration() - 9.0).abs() < 1e-9);867 assert!((session.timeline_duration() - 9.0).abs() < 1e-9);
@@ -881,7 +897,7 @@ fn undo_after_import_is_one_step() {
881 #[test]897 #[test]
882 #[ignore = "needs a running PipeWire daemon"]898 #[ignore = "needs a running PipeWire daemon"]
883 fn audio_runs_across_a_source_join() {899 fn audio_runs_across_a_source_join() {
884- let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open");900+ let mut session = open(asset("test_av.mp4"));
885 session.import(&asset("test_av2.mp4")).expect("import");901 session.import(&asset("test_av2.mp4")).expect("import");
886 let first = session.meta().frame_count;902 let first = session.meta().frame_count;
887 903