Browse Source

Merge pull request #194 from brain0/fix_pulseaudio

Fix pulseaudio playback with Lewton
Sasha Hilton 7 years ago
parent
commit
cb61e222d7
2 changed files with 14 additions and 11 deletions
  1. 1 0
      playback/src/audio_backend/pulseaudio.rs
  2. 13 11
      playback/src/player.rs

+ 1 - 0
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::<i16>();
+            assert!(len > 0);
             call_pulseaudio(
                 |err| unsafe { pa_simple_write(self.s, ptr, len, err) },
                 |ret| ret < 0,

+ 13 - 11
playback/src/player.rs

@@ -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 self.config.normalisation && normalisation_factor != 1.0 {
-                    for x in packet.data_mut().iter_mut() {
-                        *x = (*x as f32 * normalisation_factor) as i16;
+                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 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();
+                    }
                 }
             }