From a68dfa0287790fa5583f41fcf301e25024f4e4f1 Mon Sep 17 00:00:00 2001 From: sniperrifle2004 Date: Sun, 14 Jun 2020 07:17:46 +0200 Subject: [PATCH] On stop write any chunk(s) left in the period buffer That should prevent a possible sudden stop --- playback/src/audio_backend/alsa.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/playback/src/audio_backend/alsa.rs b/playback/src/audio_backend/alsa.rs index 086bea33..01e9fec4 100644 --- a/playback/src/audio_backend/alsa.rs +++ b/playback/src/audio_backend/alsa.rs @@ -107,7 +107,14 @@ impl Sink for AlsaSink { fn stop(&mut self) -> io::Result<()> { { - let pcm = self.pcm.as_ref().unwrap(); + let pcm = self.pcm.as_mut().unwrap(); + // Write any leftover data in the period buffer + // before draining the actual buffer + let io = pcm.io_i16().unwrap(); + match io.writei(&self.buffer[..self.buffered_data]) { + Ok(_) => (), + Err(err) => pcm.try_recover(err, false).unwrap(), + } pcm.drain().unwrap(); } self.pcm = None;