From 752a6b1df444cae138f946ed13eca80e498b1e7b Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 26 Jan 2018 01:42:24 +0100 Subject: [PATCH 1/2] Prevent crash in audio_backend/alsa.rs when switching from Kodi audio to librespot --- src/audio_backend/alsa.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/audio_backend/alsa.rs b/src/audio_backend/alsa.rs index ce459380..42f590bf 100644 --- a/src/audio_backend/alsa.rs +++ b/src/audio_backend/alsa.rs @@ -18,10 +18,17 @@ impl Sink for AlsaSink { fn start(&mut self) -> io::Result<()> { if self.0.is_some() { } else { - self.0 = Some(PCM::open(&*self.1, + match PCM::open(&*self.1, Stream::Playback, Mode::Blocking, Format::Signed16, Access::Interleaved, - 2, 44100).ok().unwrap()); + 2, 44100) { + Ok(f) => self.0 = Some(f), + Err(e) => { + self.0 = None; + error!("Alsa error PCM open {}", e); + return Err(io::Error::new(io::ErrorKind::Other, "Alsa error: PCM open failed")); + } + } } Ok(()) } From b03430a0575653b6d84d7abe8bc3bd34c7cc76e5 Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 5 Feb 2018 00:33:17 +0100 Subject: [PATCH 2/2] minor code cleanup --- src/audio_backend/alsa.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/audio_backend/alsa.rs b/src/audio_backend/alsa.rs index 42f590bf..517c8f0a 100644 --- a/src/audio_backend/alsa.rs +++ b/src/audio_backend/alsa.rs @@ -16,15 +16,13 @@ impl Open for AlsaSink { impl Sink for AlsaSink { fn start(&mut self) -> io::Result<()> { - if self.0.is_some() { - } else { + if self.0.is_none() { match PCM::open(&*self.1, Stream::Playback, Mode::Blocking, Format::Signed16, Access::Interleaved, 2, 44100) { Ok(f) => self.0 = Some(f), Err(e) => { - self.0 = None; error!("Alsa error PCM open {}", e); return Err(io::Error::new(io::ErrorKind::Other, "Alsa error: PCM open failed")); }