Merge pull request #393 from derekdreery/recover_if_set_buffer_time_failed
Recover if hw_params_set_buffer_time failed.
This commit is contained in:
commit
624ba659da
|
@ -8,10 +8,10 @@ use crate::{
|
|||
StreamConfig, StreamError, SupportedStreamConfig, SupportedStreamConfigRange,
|
||||
SupportedStreamConfigsError,
|
||||
};
|
||||
use std::cmp;
|
||||
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};
|
||||
|
@ -775,7 +775,7 @@ fn set_hw_params_from_format<'a>(
|
|||
config: &StreamConfig,
|
||||
sample_format: SampleFormat,
|
||||
) -> Result<alsa::pcm::HwParams<'a>, 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,11 @@ 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) {
|
||||
// Swap out the params with errors for a snapshot taken before the error was introduced.
|
||||
mem::swap(&mut hw_params_copy, &mut hw_params);
|
||||
}
|
||||
|
||||
pcm_handle.hw_params(&hw_params)?;
|
||||
|
||||
|
|
Loading…
Reference in New Issue