mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Merge pull request #922 from JasonLG1979/cleanup_list_compatible_devices
Clean up `list_compatible_devices`
This commit is contained in:
commit
92b8476645
1 changed files with 44 additions and 35 deletions
|
@ -62,8 +62,8 @@ enum AlsaError {
|
|||
#[error("<AlsaSink> PCM, {0}")]
|
||||
Pcm(alsa::Error),
|
||||
|
||||
#[error("<AlsaSink> Could Not Parse Ouput Name(s) and/or Description(s)")]
|
||||
Parsing,
|
||||
#[error("<AlsaSink> Could Not Parse Output Name(s) and/or Description(s), {0}")]
|
||||
Parsing(alsa::Error),
|
||||
|
||||
#[error("<AlsaSink>")]
|
||||
NotConnected,
|
||||
|
@ -107,27 +107,23 @@ pub struct AlsaSink {
|
|||
}
|
||||
|
||||
fn list_compatible_devices() -> SinkResult<()> {
|
||||
let i = HintIter::new_str(None, "pcm").map_err(AlsaError::Parsing)?;
|
||||
|
||||
println!("\n\n\tCompatible alsa device(s):\n");
|
||||
println!("\t------------------------------------------------------\n");
|
||||
|
||||
let i = HintIter::new_str(None, "pcm").map_err(|_| AlsaError::Parsing)?;
|
||||
|
||||
for a in i {
|
||||
if let Some(Direction::Playback) = a.direction {
|
||||
let name = a.name.ok_or(AlsaError::Parsing)?;
|
||||
let desc = a.desc.ok_or(AlsaError::Parsing)?;
|
||||
|
||||
if let Some(name) = a.name {
|
||||
if let Ok(pcm) = PCM::new(&name, Direction::Playback, false) {
|
||||
if let Ok(hwp) = HwParams::any(&pcm) {
|
||||
// Only show devices that support
|
||||
// 2 ch 44.1 Interleaved.
|
||||
|
||||
if hwp.set_access(Access::RWInterleaved).is_ok()
|
||||
&& hwp.set_rate(SAMPLE_RATE, ValueOr::Nearest).is_ok()
|
||||
&& hwp.set_channels(NUM_CHANNELS as u32).is_ok()
|
||||
{
|
||||
println!("\tDevice:\n\n\t\t{}\n", name);
|
||||
println!("\tDescription:\n\n\t\t{}\n", desc.replace("\n", "\n\t\t"));
|
||||
|
||||
let mut supported_formats = vec![];
|
||||
|
||||
for f in &[
|
||||
|
@ -143,16 +139,29 @@ fn list_compatible_devices() -> SinkResult<()> {
|
|||
}
|
||||
}
|
||||
|
||||
if !supported_formats.is_empty() {
|
||||
println!("\tDevice:\n\n\t\t{}\n", name);
|
||||
|
||||
println!(
|
||||
"\tDescription:\n\n\t\t{}\n",
|
||||
a.desc.unwrap_or_default().replace("\n", "\n\t\t")
|
||||
);
|
||||
|
||||
println!(
|
||||
"\tSupported Format(s):\n\n\t\t{}\n",
|
||||
supported_formats.join(" ")
|
||||
);
|
||||
println!("\t------------------------------------------------------\n");
|
||||
|
||||
println!(
|
||||
"\t------------------------------------------------------\n"
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue