Merge pull request #275 from desttinghim/invalid-params-fix
Don't panic when setting hardware params in alsa
This commit is contained in:
commit
ba4a29ae6c
|
@ -789,13 +789,15 @@ unsafe fn set_hw_params_from_format(
|
||||||
pcm_handle: *mut alsa::snd_pcm_t,
|
pcm_handle: *mut alsa::snd_pcm_t,
|
||||||
hw_params: &HwParams,
|
hw_params: &HwParams,
|
||||||
format: &Format,
|
format: &Format,
|
||||||
) {
|
) -> Result<(), String> {
|
||||||
check_errors(alsa::snd_pcm_hw_params_any(pcm_handle, hw_params.0))
|
if let Err(e) = check_errors(alsa::snd_pcm_hw_params_any(pcm_handle, hw_params.0)) {
|
||||||
.expect("Errors on pcm handle");
|
return Err("Errors on pcm handle".to_string());
|
||||||
check_errors(alsa::snd_pcm_hw_params_set_access(pcm_handle,
|
}
|
||||||
|
if let Err(e) = check_errors(alsa::snd_pcm_hw_params_set_access(pcm_handle,
|
||||||
hw_params.0,
|
hw_params.0,
|
||||||
alsa::SND_PCM_ACCESS_RW_INTERLEAVED))
|
alsa::SND_PCM_ACCESS_RW_INTERLEAVED)) {
|
||||||
.expect("handle not acessible");
|
return Err("Handle not acessible".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
let data_type = if cfg!(target_endian = "big") {
|
let data_type = if cfg!(target_endian = "big") {
|
||||||
match format.data_type {
|
match format.data_type {
|
||||||
|
@ -811,20 +813,23 @@ unsafe fn set_hw_params_from_format(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
check_errors(alsa::snd_pcm_hw_params_set_format(pcm_handle,
|
if let Err(e) = check_errors(alsa::snd_pcm_hw_params_set_format(pcm_handle,
|
||||||
hw_params.0,
|
hw_params.0,
|
||||||
data_type))
|
data_type)) {
|
||||||
.expect("format could not be set");
|
return Err("Format could not be set".to_string());
|
||||||
check_errors(alsa::snd_pcm_hw_params_set_rate(pcm_handle,
|
}
|
||||||
|
if let Err(e) = check_errors(alsa::snd_pcm_hw_params_set_rate(pcm_handle,
|
||||||
hw_params.0,
|
hw_params.0,
|
||||||
format.sample_rate.0 as libc::c_uint,
|
format.sample_rate.0 as libc::c_uint,
|
||||||
0))
|
0)) {
|
||||||
.expect("sample rate could not be set");
|
return Err("Sample rate could not be set".to_string());
|
||||||
check_errors(alsa::snd_pcm_hw_params_set_channels(pcm_handle,
|
}
|
||||||
|
if let Err(e) = check_errors(alsa::snd_pcm_hw_params_set_channels(pcm_handle,
|
||||||
hw_params.0,
|
hw_params.0,
|
||||||
format.channels as
|
format.channels as
|
||||||
libc::c_uint))
|
libc::c_uint)) {
|
||||||
.expect("channel count could not be set");
|
return Err("Channel count could not be set".to_string());
|
||||||
|
}
|
||||||
let mut max_buffer_size = format.sample_rate.0 as alsa::snd_pcm_uframes_t /
|
let mut max_buffer_size = format.sample_rate.0 as alsa::snd_pcm_uframes_t /
|
||||||
format.channels as alsa::snd_pcm_uframes_t /
|
format.channels as alsa::snd_pcm_uframes_t /
|
||||||
5; // 200ms of buffer
|
5; // 200ms of buffer
|
||||||
|
@ -832,8 +837,11 @@ unsafe fn set_hw_params_from_format(
|
||||||
hw_params.0,
|
hw_params.0,
|
||||||
&mut max_buffer_size))
|
&mut max_buffer_size))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
check_errors(alsa::snd_pcm_hw_params(pcm_handle, hw_params.0))
|
if let Err(e) = check_errors(alsa::snd_pcm_hw_params(pcm_handle, hw_params.0)) {
|
||||||
.expect("hardware params could not be set");
|
return Err("Hardware params could not be set.".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn set_sw_params_from_format(
|
unsafe fn set_sw_params_from_format(
|
||||||
|
|
Loading…
Reference in New Issue