From 86079e643998e066843948118c6cc9ed53e18038 Mon Sep 17 00:00:00 2001 From: Richard Dodd Date: Wed, 15 Apr 2020 18:41:40 +0100 Subject: [PATCH 1/3] Rebase off new alsa-rs impl --- src/host/alsa/mod.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/host/alsa/mod.rs b/src/host/alsa/mod.rs index c094bf1..eeae36b 100644 --- a/src/host/alsa/mod.rs +++ b/src/host/alsa/mod.rs @@ -8,7 +8,7 @@ use crate::{ StreamConfig, StreamError, SupportedStreamConfig, SupportedStreamConfigRange, SupportedStreamConfigsError, }; -use std::cmp; +use std::{cmp, mem}; use std::sync::Arc; use std::thread::{self, JoinHandle}; use std::vec::IntoIter as VecIntoIter; @@ -775,7 +775,7 @@ fn set_hw_params_from_format<'a>( config: &StreamConfig, sample_format: SampleFormat, ) -> Result, BackendSpecificError> { - let hw_params = alsa::pcm::HwParams::any(pcm_handle)?; + let mut hw_params = alsa::pcm::HwParams::any(pcm_handle)?; hw_params.set_access(alsa::pcm::Access::RWInterleaved)?; let sample_format = if cfg!(target_endian = "big") { @@ -797,7 +797,10 @@ fn set_hw_params_from_format<'a>( hw_params.set_channels(config.channels as u32)?; // If this isn't set manually a overlarge buffer may be used causing audio delay - hw_params.set_buffer_time_near(100_000, alsa::ValueOr::Nearest)?; + let mut hw_params_copy = hw_params.clone(); + if let Err(_) = hw_params.set_buffer_time_near(100_000, alsa::ValueOr::Nearest) { + mem::swap(&mut hw_params_copy, &mut hw_params); + } pcm_handle.hw_params(&hw_params)?; From 290f464330430ee32b3b854b53b667b387ca18a7 Mon Sep 17 00:00:00 2001 From: Richard Dodd Date: Wed, 15 Apr 2020 18:42:43 +0100 Subject: [PATCH 2/3] Cargo fmt --- src/host/alsa/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/host/alsa/mod.rs b/src/host/alsa/mod.rs index eeae36b..045765b 100644 --- a/src/host/alsa/mod.rs +++ b/src/host/alsa/mod.rs @@ -8,10 +8,10 @@ use crate::{ StreamConfig, StreamError, SupportedStreamConfig, SupportedStreamConfigRange, SupportedStreamConfigsError, }; -use std::{cmp, mem}; use std::sync::Arc; use std::thread::{self, JoinHandle}; use std::vec::IntoIter as VecIntoIter; +use std::{cmp, mem}; use traits::{DeviceTrait, HostTrait, StreamTrait}; pub use self::enumerate::{default_input_device, default_output_device, Devices}; From 3c3349f926a03c02c7c87b6ad0598e1152cb934d Mon Sep 17 00:00:00 2001 From: Richard Dodd Date: Wed, 15 Apr 2020 18:46:54 +0100 Subject: [PATCH 3/3] Add some comments. --- src/host/alsa/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/host/alsa/mod.rs b/src/host/alsa/mod.rs index 045765b..217fb40 100644 --- a/src/host/alsa/mod.rs +++ b/src/host/alsa/mod.rs @@ -799,6 +799,7 @@ fn set_hw_params_from_format<'a>( // If this isn't set manually a overlarge buffer may be used causing audio delay let mut hw_params_copy = hw_params.clone(); if let Err(_) = hw_params.set_buffer_time_near(100_000, alsa::ValueOr::Nearest) { + // Swap out the params with errors for a snapshot taken before the error was introduced. mem::swap(&mut hw_params_copy, &mut hw_params); }