From 54a99a836daa02f425894eda0a91917a65555485 Mon Sep 17 00:00:00 2001 From: Yara Date: Wed, 4 Mar 2026 23:41:55 +0100 Subject: [PATCH] filter out null in sink fallback --- src/microphone.rs | 14 ++++++++++---- src/stream.rs | 7 ++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/microphone.rs b/src/microphone.rs index 7b7b7c71..cc9788a7 100644 --- a/src/microphone.rs +++ b/src/microphone.rs @@ -166,13 +166,19 @@ impl fmt::Display for Input { } /// Returns a list of available input devices on the system. +/// +/// Note: this hides the 'null' device which generates zeros. pub fn available_inputs() -> Result, ListError> { - let host = cpal::default_host(); - let devices = host + Ok(cpal::default_host() .input_devices() .map_err(ListError)? - .map(|dev| Input { inner: dev }); - Ok(devices.collect()) + .filter(|dev| { + dev.description() + .map(|descr| descr.driver().is_none_or(|driver| driver != "null")) + .unwrap_or(false) + }) + .map(|dev| Input { inner: dev }) + .collect::>()) } /// A microphone input stream that can be used as `Source`. diff --git a/src/stream.rs b/src/stream.rs index 872bf9d9..c9a4d314 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -234,7 +234,7 @@ impl DeviceSinkBuilder { Self::from_default_device() .and_then(|x| x.open_stream()) .or_else(|original_err| { - let mut devices = match cpal::default_host().output_devices() { + let devices = match cpal::default_host().output_devices() { Ok(devices) => devices, Err(err) => { #[cfg(feature = "tracing")] @@ -245,6 +245,11 @@ impl DeviceSinkBuilder { } }; devices + .filter(|dev| { + dev.description() + .map(|desc| desc.driver().is_some_and(|driver| driver != "null")) + .unwrap_or(false) + }) .find_map(|d| { Self::from_device(d) .and_then(|x| x.open_sink_or_fallback())