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] 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(); + } } }