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.
This commit is contained in:
Thomas Bächler 2018-03-20 14:01:15 +01:00
parent e92bb451b5
commit 014533a583

View file

@ -372,19 +372,21 @@ impl PlayerInternal {
fn handle_packet(&mut self, packet: Option<VorbisPacket>, 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();
}
}
}