From 014533a5831f0fa7ca5460a46ff6a87bf06ee5f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20B=C3=A4chler?= Date: Tue, 20 Mar 2018 14:01:15 +0100 Subject: [PATCH 1/2] playback: Only send a packet to the audio backend if it isn't empty The lewton decoder sometimes delivers empty packets, especially after skipping inside a track or switching tracks. This caused the pulseaudio backend to fail since it expects a non-empty packet. There is no need to handle empty packets in the audio backend, so we can skip them entirely. --- playback/src/player.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/playback/src/player.rs b/playback/src/player.rs index 131daf63..9cd874f0 100644 --- a/playback/src/player.rs +++ b/playback/src/player.rs @@ -372,19 +372,21 @@ impl PlayerInternal { fn handle_packet(&mut self, packet: Option, normalisation_factor: f32) { match packet { Some(mut packet) => { - if let Some(ref editor) = self.audio_filter { - editor.modify_stream(&mut packet.data_mut()) - }; + if packet.data().len() > 0 { + if let Some(ref editor) = self.audio_filter { + editor.modify_stream(&mut packet.data_mut()) + }; - if self.config.normalisation && normalisation_factor != 1.0 { - for x in packet.data_mut().iter_mut() { - *x = (*x as f32 * normalisation_factor) as i16; + if self.config.normalisation && normalisation_factor != 1.0 { + for x in packet.data_mut().iter_mut() { + *x = (*x as f32 * normalisation_factor) as i16; + } } - } - if let Err(err) = self.sink.write(&packet.data()) { - error!("Could not write audio: {}", err); - self.stop_sink(); + if let Err(err) = self.sink.write(&packet.data()) { + error!("Could not write audio: {}", err); + self.stop_sink(); + } } } From 0c18aa51adf3abbdc63b393e05b39929191ae6db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20B=C3=A4chler?= Date: Tue, 20 Mar 2018 14:05:50 +0100 Subject: [PATCH 2/2] playback: pulseaudio: Panic in write if data is empty --- playback/src/audio_backend/pulseaudio.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/playback/src/audio_backend/pulseaudio.rs b/playback/src/audio_backend/pulseaudio.rs index 30074c1d..88f62806 100644 --- a/playback/src/audio_backend/pulseaudio.rs +++ b/playback/src/audio_backend/pulseaudio.rs @@ -112,6 +112,7 @@ impl Sink for PulseAudioSink { } else { let ptr = data.as_ptr() as *const libc::c_void; let len = data.len() as usize * mem::size_of::(); + assert!(len > 0); call_pulseaudio( |err| unsafe { pa_simple_write(self.s, ptr, len, err) }, |ret| ret < 0,