From 66714fe401fae3ae758698cd6bb46b79114f49c3 Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Wed, 21 Oct 2026 17:53:00 +0100 Subject: [PATCH 01/35] rename DeviceNotAvailable to DeviceUnavailable globally, and updated docs accordingly --- CHANGELOG.md | 1 + src/error.rs | 16 ++--- src/host.rs | 2 +- src/host/aaudio/convert.rs | 2 +- src/host/alsa.rs | 2 +- src/host/alsa/device.rs | 8 +-- src/host/alsa/duplex.rs | 6 +- src/host/alsa/worker.rs | 8 +-- src/host/asio/stream.rs | 8 +-- src/host/audioworklet.rs | 12 ++-- src/host/coreaudio.rs | 2 +- .../coreaudio/ios/session_event_manager.rs | 4 +- src/host/coreaudio/macos.rs | 8 +-- src/host/coreaudio/macos/device.rs | 2 +- src/host/coreaudio/macos/format.rs | 4 +- src/host/coreaudio/macos/loopback.rs | 2 +- src/host/jack.rs | 12 ++-- src/host/jack/device.rs | 2 +- src/host/jack/stream.rs | 4 +- src/host/pipewire/device.rs | 2 +- src/host/pipewire/stream.rs | 8 +-- src/host/pulseaudio.rs | 6 +- src/host/wasapi.rs | 2 +- src/host/wasapi/device.rs | 6 +- src/host/wasapi/stream.rs | 2 +- src/host/webaudio.rs | 16 ++--- src/traits.rs | 68 +++++++++---------- 27 files changed, 108 insertions(+), 107 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70a8d9ac9..34b1ab6ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bump `audio_thread_priority` dependency to 0.36. - `DeviceTrait` and `StreamTrait` now require `Send + Sync` as supertrait bounds. - `StreamTrait::play` is renamed to `start`. +- `DeviceNotAvailable` is renamed to `DeviceUnavailable`. - `InputCallbackInfo`/`OutputCallbackInfo` merged into `CallbackInfo`. - `InputStreamTimestamp`/`OutputStreamTimestamp` merged into `StreamTimestamp`; `capture`/`playback` renamed `device`. - `StreamInstant` creation is now `const`. diff --git a/src/error.rs b/src/error.rs index b6242a056..fa9032e72 100644 --- a/src/error.rs +++ b/src/error.rs @@ -17,23 +17,23 @@ pub enum ErrorKind { /// /// Only fires for a stream built from the default device, on backends that support following /// it. A stream built from a specific device does not follow a replacement; if that device - /// disappears, it reports [`DeviceNotAvailable`] instead. + /// disappears, it reports [`DeviceUnavailable`] instead. /// - /// [`DeviceNotAvailable`]: ErrorKind::DeviceNotAvailable + /// [`DeviceUnavailable`]: ErrorKind::DeviceUnavailable DeviceChanged, /// The requested audio device is not available. /// /// This can happen if the device has been disconnected while the program is running, or if /// the device identifier refers to a device that does not exist on this system. - DeviceNotAvailable, + DeviceUnavailable, /// The audio host (server or subsystem) is not available on this system. /// - /// This is distinct from [`DeviceNotAvailable`]: when a host (e.g. PulseAudio, PipeWire, JACK, + /// This is distinct from [`DeviceUnavailable`]: when a host (e.g. PulseAudio, PipeWire, JACK, /// or kernel subsystem) is absent or not running, no devices can be reached through it. /// - /// [`DeviceNotAvailable`]: ErrorKind::DeviceNotAvailable + /// [`DeviceUnavailable`]: ErrorKind::DeviceUnavailable HostUnavailable, /// Invalid input or argument. @@ -45,10 +45,10 @@ pub enum ErrorKind { /// permission to use it. Common causes include microphone privacy settings (iOS, macOS), /// missing audio group membership (Linux), or file permission errors. /// - /// Unlike [`DeviceNotAvailable`], which signals absence, this variant signals an + /// Unlike [`DeviceUnavailable`], which signals absence, this variant signals an /// authorization failure. /// - /// [`DeviceNotAvailable`]: ErrorKind::DeviceNotAvailable + /// [`DeviceUnavailable`]: ErrorKind::DeviceUnavailable PermissionDenied, /// A real-time scheduling promotion or equivalent platform performance mode was refused. @@ -97,7 +97,7 @@ impl Display for ErrorKind { Self::DeviceChanged => f.write_str( "The audio route changed. The stream was automatically rerouted to a different device.", ), - Self::DeviceNotAvailable => f.write_str( + Self::DeviceUnavailable => f.write_str( "The requested audio device is not available. It may have been disconnected.", ), Self::HostUnavailable => f.write_str( diff --git a/src/host.rs b/src/host.rs index 56ec2d68b..13a039a1c 100644 --- a/src/host.rs +++ b/src/host.rs @@ -393,7 +393,7 @@ pub(crate) fn get_user_media_error(js_err: &wasm_bindgen::JsValue) -> crate::Err let kind = match name.as_deref() { Some("NotAllowedError" | "SecurityError") => ErrorKind::PermissionDenied, - Some("NotFoundError") => ErrorKind::DeviceNotAvailable, + Some("NotFoundError") => ErrorKind::DeviceUnavailable, Some("OverconstrainedError") => ErrorKind::UnsupportedConfig, Some("NotReadableError") => ErrorKind::DeviceBusy, Some("TypeError") => ErrorKind::InvalidInput, diff --git a/src/host/aaudio/convert.rs b/src/host/aaudio/convert.rs index 0b54a4e76..e57ff568e 100644 --- a/src/host/aaudio/convert.rs +++ b/src/host/aaudio/convert.rs @@ -60,7 +60,7 @@ impl From for Error { use ndk::audio::AudioError::*; match error { Disconnected | Unavailable | NoService | InvalidHandle => { - Error::with_message(ErrorKind::DeviceNotAvailable, error.to_string()) + Error::with_message(ErrorKind::DeviceUnavailable, error.to_string()) } NoFreeHandles | NoMemory => { Error::with_message(ErrorKind::ResourceExhausted, error.to_string()) diff --git a/src/host/alsa.rs b/src/host/alsa.rs index 8898e3b4a..cce8dcf24 100644 --- a/src/host/alsa.rs +++ b/src/host/alsa.rs @@ -229,7 +229,7 @@ fn canonical_pcm_id(pcm_id: &str) -> String { impl From for Error { fn from(err: alsa::Error) -> Self { match err.errno() { - libc::ENODEV | libc::ENOENT | LIBC_ENOTSUPP => ErrorKind::DeviceNotAvailable.into(), + libc::ENODEV | libc::ENOENT | LIBC_ENOTSUPP => ErrorKind::DeviceUnavailable.into(), libc::EPERM | libc::EACCES => ErrorKind::PermissionDenied.into(), libc::EBUSY | libc::EAGAIN => ErrorKind::DeviceBusy.into(), libc::EINVAL => ErrorKind::UnsupportedConfig.into(), diff --git a/src/host/alsa/device.rs b/src/host/alsa/device.rs index 8c251980b..b70177d7b 100644 --- a/src/host/alsa/device.rs +++ b/src/host/alsa/device.rs @@ -183,13 +183,13 @@ impl Device { }; let (buffer_size, period_size) = set_sw_params_from_format(&handle, start_threshold)?; if buffer_size == 0 || period_size == 0 { - return Err(ErrorKind::DeviceNotAvailable.into()); + return Err(ErrorKind::DeviceUnavailable.into()); } handle.prepare()?; if handle.count() == 0 { - return Err(ErrorKind::DeviceNotAvailable.into()); + return Err(ErrorKind::DeviceUnavailable.into()); } let (creation_ts, timestamp_mode) = creation_timestamp(&handle, hw_params)?; @@ -257,7 +257,7 @@ impl Device { || playback_buffer_size == 0 || playback_period_size == 0 { - return Err(ErrorKind::DeviceNotAvailable.into()); + return Err(ErrorKind::DeviceUnavailable.into()); } // Duplex drives both directions from one worker cycle; period sizes must match. if capture_period_size != playback_period_size { @@ -273,7 +273,7 @@ impl Device { playback_handle.prepare()?; if capture_handle.count() == 0 || playback_handle.count() == 0 { - return Err(ErrorKind::DeviceNotAvailable.into()); + return Err(ErrorKind::DeviceUnavailable.into()); } let (capture_creation_ts, capture_timestamp_mode) = diff --git a/src/host/alsa/duplex.rs b/src/host/alsa/duplex.rs index ee8a24a8e..3bf0eaa27 100644 --- a/src/host/alsa/duplex.rs +++ b/src/host/alsa/duplex.rs @@ -97,7 +97,7 @@ pub(super) fn duplex_stream_worker( }; if let Err(err) = result { match err.kind() { - ErrorKind::DeviceNotAvailable => { + ErrorKind::DeviceUnavailable => { error_callback(err); stream.control.signal_worker_exit(); return; @@ -256,7 +256,7 @@ fn poll_for_duplex_period( match handle.state() { alsa::pcm::State::Disconnected => { return Err(Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Device disconnected", )); } @@ -290,7 +290,7 @@ fn poll_for_duplex_period( || playback_revents.intersects(alsa::poll::Flags::HUP | alsa::poll::Flags::NVAL) { return Err(Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Device disconnected", )); } diff --git a/src/host/alsa/worker.rs b/src/host/alsa/worker.rs index e35795c7b..a58cc1b46 100644 --- a/src/host/alsa/worker.rs +++ b/src/host/alsa/worker.rs @@ -59,7 +59,7 @@ pub(super) fn input_stream_worker( }; if let Err(err) = result { match err.kind() { - ErrorKind::DeviceNotAvailable => { + ErrorKind::DeviceUnavailable => { error_callback(err); stream.control.signal_worker_exit(); return; @@ -114,7 +114,7 @@ pub(super) fn output_stream_worker( }; if let Err(err) = result { match err.kind() { - ErrorKind::DeviceNotAvailable => { + ErrorKind::DeviceUnavailable => { error_callback(err); stream.control.signal_worker_exit(); return; @@ -244,7 +244,7 @@ fn poll_for_period( match stream.handle.state() { alsa::pcm::State::Disconnected => { return Err(Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Device disconnected", )); } @@ -276,7 +276,7 @@ fn poll_for_period( // POLLHUP/POLLNVAL: the device has been disconnected. if revents.intersects(alsa::poll::Flags::HUP | alsa::poll::Flags::NVAL) { return Err(Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Device disconnected", )); } diff --git a/src/host/asio/stream.rs b/src/host/asio/stream.rs index 505ad1c87..35c35750a 100644 --- a/src/host/asio/stream.rs +++ b/src/host/asio/stream.rs @@ -150,7 +150,7 @@ impl Device { .get() .ok_or_else(|| { Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "ASIO driver is not initialized", ) })? @@ -508,7 +508,7 @@ impl Device { .get() .ok_or_else(|| { Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "ASIO driver is not initialized", ) })? @@ -1307,7 +1307,7 @@ unsafe fn asio_channel_slice_mut( fn load_driver_err(e: sys::LoadDriverError) -> Error { match e { sys::LoadDriverError::LoadDriverFailed | sys::LoadDriverError::DriverAlreadyExists => { - Error::with_message(ErrorKind::DeviceNotAvailable, e.to_string()) + Error::with_message(ErrorKind::DeviceUnavailable, e.to_string()) } sys::LoadDriverError::InitializationFailed(asio_err) => build_stream_err(asio_err), } @@ -1316,7 +1316,7 @@ fn load_driver_err(e: sys::LoadDriverError) -> Error { fn build_stream_err(e: sys::AsioError) -> Error { match e { sys::AsioError::NoDrivers | sys::AsioError::HardwareMalfunction => { - Error::with_message(ErrorKind::DeviceNotAvailable, e.to_string()) + Error::with_message(ErrorKind::DeviceUnavailable, e.to_string()) } sys::AsioError::InvalidInput | sys::AsioError::BadMode => { Error::with_message(ErrorKind::InvalidInput, e.to_string()) diff --git a/src/host/audioworklet.rs b/src/host/audioworklet.rs index d10048210..0a2e480f0 100644 --- a/src/host/audioworklet.rs +++ b/src/host/audioworklet.rs @@ -521,7 +521,7 @@ impl DeviceTrait for Device { Command::Play => { if audio_context.resume().is_err() { (error_callback.borrow_mut())(Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Failed to resume audio context", )); } @@ -529,7 +529,7 @@ impl DeviceTrait for Device { Command::Pause => { if audio_context.suspend().is_err() { (error_callback.borrow_mut())(Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Failed to suspend audio context", )); } @@ -760,7 +760,7 @@ impl DeviceTrait for Device { Command::Play => { if audio_context.resume().is_err() { (error_callback.borrow_mut())(Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Failed to resume audio context", )); } @@ -768,7 +768,7 @@ impl DeviceTrait for Device { Command::Pause => { if audio_context.suspend().is_err() { (error_callback.borrow_mut())(Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Failed to suspend audio context", )); } @@ -1049,7 +1049,7 @@ impl DeviceTrait for Device { Command::Play => { if audio_context.resume().is_err() { (error_callback.borrow_mut())(Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Failed to resume audio context", )); } @@ -1057,7 +1057,7 @@ impl DeviceTrait for Device { Command::Pause => { if audio_context.suspend().is_err() { (error_callback.borrow_mut())(Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Failed to suspend audio context", )); } diff --git a/src/host/coreaudio.rs b/src/host/coreaudio.rs index 730bc7240..8ce8c660c 100644 --- a/src/host/coreaudio.rs +++ b/src/host/coreaudio.rs @@ -108,7 +108,7 @@ impl From for Error { | coreaudio::Error::AudioUnit(AudioUnitError::NoConnection) | coreaudio::Error::AudioUnit(AudioUnitError::FailedInitialization) | coreaudio::Error::Audio(AudioError::FileNotFound) => { - Error::with_message(ErrorKind::DeviceNotAvailable, msg) + Error::with_message(ErrorKind::DeviceUnavailable, msg) } coreaudio::Error::AudioUnit(AudioUnitError::Unauthorized) diff --git a/src/host/coreaudio/ios/session_event_manager.rs b/src/host/coreaudio/ios/session_event_manager.rs index 1ca497966..467ccfe5e 100644 --- a/src/host/coreaudio/ios/session_event_manager.rs +++ b/src/host/coreaudio/ios/session_event_manager.rs @@ -62,7 +62,7 @@ fn route_change_error(notification: &NSNotification) -> Option { )), AVAudioSessionRouteChangeReason::NoSuitableRouteForCategory => Some(Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "No suitable audio route for the session category", )), @@ -166,7 +166,7 @@ impl SessionEventManager { emit_error( &cb, Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Audio media services were lost", ), ); diff --git a/src/host/coreaudio/macos.rs b/src/host/coreaudio/macos.rs index 2dc242448..7afe80e10 100644 --- a/src/host/coreaudio/macos.rs +++ b/src/host/coreaudio/macos.rs @@ -220,7 +220,7 @@ pub(super) trait Monitor: Send + Sync { /// /// When a device disconnects, this manager: /// 1. Attempts to pause the stream to stop audio I/O -/// 2. Calls the error callback with `ErrorKind::DeviceNotAvailable` +/// 2. Calls the error callback with `ErrorKind::DeviceUnavailable` /// /// The dedicated thread architecture ensures `Stream` can implement `Send`. struct DisconnectManager { @@ -251,7 +251,7 @@ impl DisconnectManager { device_address(kAudioDevicePropertyDeviceIsAlive), move || { let _ = disconnect_tx_alive.send(MonitorEvent::Lost(Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Device disconnected", ))); }, @@ -339,7 +339,7 @@ impl Monitor for DisconnectManager { /// /// When the system default output device changes: /// - If a new valid default exists, AudioUnit reroutes and `DeviceChanged` is reported. -/// - If there is no new default, the stream is paused and `DeviceNotAvailable` is reported. +/// - If there is no new default, the stream is paused and `DeviceUnavailable` is reported. struct DefaultOutputMonitor { latch: Latch, _shutdown_tx: mpsc::Sender<()>, @@ -454,7 +454,7 @@ impl DefaultOutputMonitor { stream, &error_callback, Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "no default output device", ), ); diff --git a/src/host/coreaudio/macos/device.rs b/src/host/coreaudio/macos/device.rs index 7e489567a..d9529d4ff 100644 --- a/src/host/coreaudio/macos/device.rs +++ b/src/host/coreaudio/macos/device.rs @@ -307,7 +307,7 @@ impl Device { uid_string, )) } else { - Err(ErrorKind::DeviceNotAvailable.into()) + Err(ErrorKind::DeviceUnavailable.into()) } } diff --git a/src/host/coreaudio/macos/format.rs b/src/host/coreaudio/macos/format.rs index 9b9cb509a..3e625b3de 100644 --- a/src/host/coreaudio/macos/format.rs +++ b/src/host/coreaudio/macos/format.rs @@ -275,7 +275,7 @@ fn wait_for_property( ) -> Result<(), Error> { let timed_out = || { Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, format!("Timed out waiting for the {what} to change"), ) }; @@ -300,7 +300,7 @@ fn wait_for_property( } Ok(PropertyEvent::Unavailable) => { return Err(Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, format!("Device disconnected while updating the {what}"), )); } diff --git a/src/host/coreaudio/macos/loopback.rs b/src/host/coreaudio/macos/loopback.rs index 1029cc34d..e972e86c2 100644 --- a/src/host/coreaudio/macos/loopback.rs +++ b/src/host/coreaudio/macos/loopback.rs @@ -53,7 +53,7 @@ impl Device { check_os_status(status)?; if cfstring.is_null() { - return Err(ErrorKind::DeviceNotAvailable.into()); + return Err(ErrorKind::DeviceUnavailable.into()); } let ns_string: Retained = unsafe { diff --git a/src/host/jack.rs b/src/host/jack.rs index 1315aeda2..1bf6c0882 100644 --- a/src/host/jack.rs +++ b/src/host/jack.rs @@ -186,7 +186,7 @@ impl From for Error { | jack::Error::LibraryError(_) | jack::Error::WeakFunctionNotFound(_) | jack::Error::RingbufferCreateFailed => { - Error::with_message(ErrorKind::DeviceNotAvailable, msg) + Error::with_message(ErrorKind::DeviceUnavailable, msg) } jack::Error::ClientIsNoLongerAlive | jack::Error::ClientPanicked => { @@ -224,27 +224,27 @@ fn get_client(name: &str, client_options: jack::ClientOptions) -> Result Result<(), Er let _ = client.disconnect_ports_by_name(prev_from, prev_to); } return Err(Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, format!("JACK failed to connect port '{from}' to '{to}': {e}"), )); } @@ -740,7 +740,7 @@ impl jack::NotificationHandler for JackNotificationHandler { emit_error( &self.error_callback_ptr, Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, format!("JACK server shut down: {reason}"), ), ); diff --git a/src/host/pipewire/device.rs b/src/host/pipewire/device.rs index a57503f78..179550e64 100644 --- a/src/host/pipewire/device.rs +++ b/src/host/pipewire/device.rs @@ -762,7 +762,7 @@ fn recv_init( received.unwrap_or_else(|err| { Err(match err { mpsc::RecvTimeoutError::Timeout => { - Error::with_message(ErrorKind::DeviceNotAvailable, "PipeWire timed out") + Error::with_message(ErrorKind::DeviceUnavailable, "PipeWire timed out") } mpsc::RecvTimeoutError::Disconnected => Error::with_message( ErrorKind::BackendError, diff --git a/src/host/pipewire/stream.rs b/src/host/pipewire/stream.rs index 3946d1e61..5d98b886b 100644 --- a/src/host/pipewire/stream.rs +++ b/src/host/pipewire/stream.rs @@ -335,7 +335,7 @@ impl UserData { { emit_error( &self.error_callback, - Error::with_message(ErrorKind::DeviceNotAvailable, "Device disconnected"), + Error::with_message(ErrorKind::DeviceUnavailable, "Device disconnected"), ); } } @@ -591,7 +591,7 @@ pub(super) fn watch_default_device( emit_error( &error_callback_cb, Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "default device removed", ), ); @@ -611,7 +611,7 @@ pub(super) fn watch_default_device( } /// Watches the registry for the node going away, and fires `error_callback` with -/// [`ErrorKind::DeviceNotAvailable`] when it does. +/// [`ErrorKind::DeviceUnavailable`] when it does. /// /// The watch lasts as long as the returned listener is held. pub(super) fn watch_target_node( @@ -645,7 +645,7 @@ pub(super) fn watch_target_node( if node_id.get() == Some(id) && !invalidated.swap(true, Ordering::Relaxed) { emit_error( &error_callback, - Error::with_message(ErrorKind::DeviceNotAvailable, "Device disconnected"), + Error::with_message(ErrorKind::DeviceUnavailable, "Device disconnected"), ); } }) diff --git a/src/host/pulseaudio.rs b/src/host/pulseaudio.rs index 6a0280b78..463cbb015 100644 --- a/src/host/pulseaudio.rs +++ b/src/host/pulseaudio.rs @@ -85,7 +85,7 @@ impl From for Error { match e { AccessDenied | AuthKey => ErrorKind::PermissionDenied, ConnectionRefused | InvalidServer | ModInitFailed => ErrorKind::HostUnavailable, - NoEntity => ErrorKind::DeviceNotAvailable, + NoEntity => ErrorKind::DeviceUnavailable, Timeout | Busy => ErrorKind::DeviceBusy, NotSupported | Obsolete | NotImplemented | Version | NoExtension => { ErrorKind::UnsupportedOperation @@ -392,7 +392,7 @@ impl DeviceTrait for Device { match rx.recv_timeout(dur) { Ok(result) => result, Err(_) => Err(Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Stream creation timed out", )), } @@ -487,7 +487,7 @@ impl DeviceTrait for Device { match rx.recv_timeout(dur) { Ok(result) => result, Err(_) => Err(Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Stream creation timed out", )), } diff --git a/src/host/wasapi.rs b/src/host/wasapi.rs index 999d1ab86..72ce443e6 100644 --- a/src/host/wasapi.rs +++ b/src/host/wasapi.rs @@ -66,7 +66,7 @@ impl From for Error { Audio::AUDCLNT_E_SERVICE_NOT_RUNNING => ErrorKind::HostUnavailable, Audio::AUDCLNT_E_DEVICE_INVALIDATED | Audio::AUDCLNT_E_ENDPOINT_CREATE_FAILED => { - ErrorKind::DeviceNotAvailable + ErrorKind::DeviceUnavailable } Audio::AUDCLNT_E_DEVICE_IN_USE => ErrorKind::DeviceBusy, diff --git a/src/host/wasapi/device.rs b/src/host/wasapi/device.rs index 85290fe85..41ba3c00e 100644 --- a/src/host/wasapi/device.rs +++ b/src/host/wasapi/device.rs @@ -414,7 +414,7 @@ unsafe fn activate_audio_interface_sync( impl Device { pub fn description(&self) -> Result { let device = self.immdevice().ok_or_else(|| { - Error::with_message(ErrorKind::DeviceNotAvailable, "Default device not found") + Error::with_message(ErrorKind::DeviceUnavailable, "Default device not found") })?; unsafe { // Open the device's property store. @@ -456,7 +456,7 @@ impl Device { // Prefer FriendlyName for name (e.g., "Speakers (XYZ Audio Adapter)"), fall back to DeviceDesc let name = friendly_name.or(device_desc).ok_or_else(|| { Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Failed to retrieve device name", ) })?; @@ -502,7 +502,7 @@ impl Device { fn id(&self) -> Result { let device = self.immdevice().ok_or_else(|| { - Error::with_message(ErrorKind::DeviceNotAvailable, "Default device not found") + Error::with_message(ErrorKind::DeviceUnavailable, "Default device not found") })?; unsafe { match device.GetId().map(ComString) { diff --git a/src/host/wasapi/stream.rs b/src/host/wasapi/stream.rs index 80169fd71..94b05e205 100644 --- a/src/host/wasapi/stream.rs +++ b/src/host/wasapi/stream.rs @@ -831,7 +831,7 @@ fn boost_current_thread_priority( fn default_device_change_error(flow: Option) -> Error { match flow.and_then(get_current_default) { - None => ErrorKind::DeviceNotAvailable.into(), + None => ErrorKind::DeviceUnavailable.into(), Some(_) => ErrorKind::DeviceChanged.into(), } } diff --git a/src/host/webaudio.rs b/src/host/webaudio.rs index 422fa26de..8394ec025 100644 --- a/src/host/webaudio.rs +++ b/src/host/webaudio.rs @@ -514,7 +514,7 @@ impl DeviceTrait for Device { if ctx_task.resume().is_err() { error_callback.lock().unwrap_or_else(|e| e.into_inner())( Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Failed to resume audio context", ), ); @@ -524,7 +524,7 @@ impl DeviceTrait for Device { if ctx_task.suspend().is_err() { error_callback.lock().unwrap_or_else(|e| e.into_inner())( Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Failed to suspend audio context", ), ); @@ -926,7 +926,7 @@ impl DeviceTrait for Device { if ctx.resume().is_err() { error_callback.lock().unwrap_or_else(|e| e.into_inner())( Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Failed to resume audio context", ), ); @@ -944,7 +944,7 @@ impl DeviceTrait for Device { if ctx.suspend().is_err() { error_callback.lock().unwrap_or_else(|e| e.into_inner())( Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Failed to suspend audio context", ), ); @@ -1301,7 +1301,7 @@ impl DeviceTrait for Device { if ctx_task.resume().is_err() { error_callback.lock().unwrap_or_else(|e| e.into_inner())( Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Failed to resume audio context", ), ); @@ -1311,7 +1311,7 @@ impl DeviceTrait for Device { if ctx_task.suspend().is_err() { error_callback.lock().unwrap_or_else(|e| e.into_inner())( Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Failed to suspend audio context", ), ); @@ -1385,7 +1385,7 @@ impl StreamTrait for Stream { Ok(()) } Err(_) => Err(Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Failed to resume audio context", )), } @@ -1405,7 +1405,7 @@ impl StreamTrait for Stream { match self.ctx.suspend() { Ok(_) => Ok(()), Err(_) => Err(Error::with_message( - ErrorKind::DeviceNotAvailable, + ErrorKind::DeviceUnavailable, "Failed to suspend audio context", )), } diff --git a/src/traits.rs b/src/traits.rs index beeff09d2..a4db006f0 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -77,11 +77,11 @@ pub trait HostTrait { /// /// Some backends reroute a stream built from this device to the new default device when it /// changes; capture continues there, and [`ErrorKind::DeviceChanged`] is reported. Other - /// backends report [`ErrorKind::DeviceNotAvailable`] instead, and the caller must rebuild the + /// backends report [`ErrorKind::DeviceUnavailable`] instead, and the caller must rebuild the /// stream. /// /// [`ErrorKind::DeviceChanged`]: crate::ErrorKind::DeviceChanged - /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable + /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable fn default_input_device(&self) -> Option; /// The default output audio device on the system. @@ -90,11 +90,11 @@ pub trait HostTrait { /// /// Some backends reroute a stream built from this device to the new default device when it /// changes; playback continues there, and [`ErrorKind::DeviceChanged`] is reported. Other - /// backends report [`ErrorKind::DeviceNotAvailable`] instead, and the caller must rebuild the + /// backends report [`ErrorKind::DeviceUnavailable`] instead, and the caller must rebuild the /// stream. /// /// [`ErrorKind::DeviceChanged`]: crate::ErrorKind::DeviceChanged - /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable + /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable fn default_output_device(&self) -> Option; /// An iterator yielding all `Device`s currently available to the system that support one or more @@ -150,9 +150,9 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// /// # Errors /// - /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. /// - /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable + /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable fn description(&self) -> Result; /// The ID of the device. @@ -162,9 +162,9 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// /// # Errors /// - /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. /// - /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable + /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable fn id(&self) -> Result; /// True if the device supports audio input, otherwise false @@ -192,12 +192,12 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// /// # Errors /// - /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. /// - [`ErrorKind::UnsupportedConfig`] if the backend could not determine what the device /// supports. /// - [`ErrorKind::UnsupportedOperation`] if the device does not support input. /// - /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable + /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable /// [`ErrorKind::UnsupportedConfig`]: crate::ErrorKind::UnsupportedConfig /// [`ErrorKind::UnsupportedOperation`]: crate::ErrorKind::UnsupportedOperation fn supported_input_configs(&self) -> Result; @@ -206,12 +206,12 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// /// # Errors /// - /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. /// - [`ErrorKind::UnsupportedConfig`] if the backend could not determine what the device /// supports. /// - [`ErrorKind::UnsupportedOperation`] if the device does not support output. /// - /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable + /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable /// [`ErrorKind::UnsupportedConfig`]: crate::ErrorKind::UnsupportedConfig /// [`ErrorKind::UnsupportedOperation`]: crate::ErrorKind::UnsupportedOperation fn supported_output_configs(&self) -> Result; @@ -220,11 +220,11 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// /// # Errors /// - /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. /// - [`ErrorKind::UnsupportedConfig`] if the device has no default input configuration. /// - [`ErrorKind::UnsupportedOperation`] if the device does not support input. /// - /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable + /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable /// [`ErrorKind::UnsupportedConfig`]: crate::ErrorKind::UnsupportedConfig /// [`ErrorKind::UnsupportedOperation`]: crate::ErrorKind::UnsupportedOperation fn default_input_config(&self) -> Result; @@ -233,11 +233,11 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// /// # Errors /// - /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. /// - [`ErrorKind::UnsupportedConfig`] if the device has no default output configuration. /// - [`ErrorKind::UnsupportedOperation`] if the device does not support output. /// - /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable + /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable /// [`ErrorKind::UnsupportedConfig`]: crate::ErrorKind::UnsupportedConfig /// [`ErrorKind::UnsupportedOperation`]: crate::ErrorKind::UnsupportedOperation fn default_output_config(&self) -> Result; @@ -257,12 +257,12 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// /// # Errors /// - /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. /// - [`ErrorKind::UnsupportedConfig`] if no sample rate is supported by both directions. /// - [`ErrorKind::UnsupportedOperation`] if the host or device does not support duplex /// streams. /// - /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable + /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable /// [`ErrorKind::UnsupportedConfig`]: crate::ErrorKind::UnsupportedConfig /// [`ErrorKind::UnsupportedOperation`]: crate::ErrorKind::UnsupportedOperation fn default_duplex_config(&self) -> Result { @@ -377,14 +377,14 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// - [`ErrorKind::UnsupportedConfig`] if the sample rate, channel count, buffer size, or /// sample format is not supported by the device. /// - [`ErrorKind::UnsupportedOperation`] if the device does not support input streams. - /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. /// - [`ErrorKind::DeviceBusy`] if the device is temporarily in use by another application. /// - [`ErrorKind::PermissionDenied`] if the process lacks permission to access the device. /// - [`ErrorKind::InvalidInput`] if the configuration parameters are invalid. /// /// [`ErrorKind::UnsupportedConfig`]: crate::ErrorKind::UnsupportedConfig /// [`ErrorKind::UnsupportedOperation`]: crate::ErrorKind::UnsupportedOperation - /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable + /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable /// [`ErrorKind::DeviceBusy`]: crate::ErrorKind::DeviceBusy /// [`ErrorKind::PermissionDenied`]: crate::ErrorKind::PermissionDenied /// [`ErrorKind::InvalidInput`]: crate::ErrorKind::InvalidInput @@ -435,14 +435,14 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// - [`ErrorKind::UnsupportedConfig`] if the sample rate, channel count, buffer size, or /// sample format is not supported by the device. /// - [`ErrorKind::UnsupportedOperation`] if the device does not support output streams. - /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. /// - [`ErrorKind::DeviceBusy`] if the device is temporarily in use by another application. /// - [`ErrorKind::PermissionDenied`] if the process lacks permission to access the device. /// - [`ErrorKind::InvalidInput`] if the configuration parameters are invalid. /// /// [`ErrorKind::UnsupportedConfig`]: crate::ErrorKind::UnsupportedConfig /// [`ErrorKind::UnsupportedOperation`]: crate::ErrorKind::UnsupportedOperation - /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable + /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable /// [`ErrorKind::DeviceBusy`]: crate::ErrorKind::DeviceBusy /// [`ErrorKind::PermissionDenied`]: crate::ErrorKind::PermissionDenied /// [`ErrorKind::InvalidInput`]: crate::ErrorKind::InvalidInput @@ -495,14 +495,14 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// - [`ErrorKind::UnsupportedConfig`] if the sample rate, channel count, buffer size, or /// sample format is not supported by the device. /// - [`ErrorKind::UnsupportedOperation`] if the device does not support input streams. - /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. /// - [`ErrorKind::DeviceBusy`] if the device is temporarily in use by another application. /// - [`ErrorKind::PermissionDenied`] if the process lacks permission to access the device. /// - [`ErrorKind::InvalidInput`] if the configuration parameters are invalid. /// /// [`ErrorKind::UnsupportedConfig`]: crate::ErrorKind::UnsupportedConfig /// [`ErrorKind::UnsupportedOperation`]: crate::ErrorKind::UnsupportedOperation - /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable + /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable /// [`ErrorKind::DeviceBusy`]: crate::ErrorKind::DeviceBusy /// [`ErrorKind::PermissionDenied`]: crate::ErrorKind::PermissionDenied /// [`ErrorKind::InvalidInput`]: crate::ErrorKind::InvalidInput @@ -542,14 +542,14 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// - [`ErrorKind::UnsupportedConfig`] if the sample rate, channel count, buffer size, or /// sample format is not supported by the device. /// - [`ErrorKind::UnsupportedOperation`] if the device does not support output streams. - /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. /// - [`ErrorKind::DeviceBusy`] if the device is temporarily in use by another application. /// - [`ErrorKind::PermissionDenied`] if the process lacks permission to access the device. /// - [`ErrorKind::InvalidInput`] if the configuration parameters are invalid. /// /// [`ErrorKind::UnsupportedConfig`]: crate::ErrorKind::UnsupportedConfig /// [`ErrorKind::UnsupportedOperation`]: crate::ErrorKind::UnsupportedOperation - /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable + /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable /// [`ErrorKind::DeviceBusy`]: crate::ErrorKind::DeviceBusy /// [`ErrorKind::PermissionDenied`]: crate::ErrorKind::PermissionDenied /// [`ErrorKind::InvalidInput`]: crate::ErrorKind::InvalidInput @@ -587,7 +587,7 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// streams. /// - [`ErrorKind::UnsupportedConfig`] if the sample rate, channel counts, buffer size, or /// sample format is not supported by the device. - /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. /// - [`ErrorKind::DeviceBusy`] if the device is temporarily in use by another application. /// - [`ErrorKind::PermissionDenied`] if the process lacks permission to access the device /// (e.g. microphone access on macOS). @@ -600,7 +600,7 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// /// [`ErrorKind::UnsupportedOperation`]: crate::ErrorKind::UnsupportedOperation /// [`ErrorKind::UnsupportedConfig`]: crate::ErrorKind::UnsupportedConfig - /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable + /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable /// [`ErrorKind::DeviceBusy`]: crate::ErrorKind::DeviceBusy /// [`ErrorKind::PermissionDenied`]: crate::ErrorKind::PermissionDenied /// [`ErrorKind::InvalidInput`]: crate::ErrorKind::InvalidInput @@ -682,11 +682,11 @@ pub trait StreamTrait: Send + Sync { /// /// # Errors /// - /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. /// - [`ErrorKind::StreamInvalidated`] if the stream configuration has changed and the stream /// must be rebuilt. /// - /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable + /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable /// [`ErrorKind::StreamInvalidated`]: crate::ErrorKind::StreamInvalidated fn start(&self) -> Result<(), Error>; @@ -710,12 +710,12 @@ pub trait StreamTrait: Send + Sync { /// # Errors /// /// - [`ErrorKind::UnsupportedOperation`] if the backend does not support pausing this stream. - /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. /// - [`ErrorKind::StreamInvalidated`] if the stream configuration has changed and the stream /// must be rebuilt. /// /// [`ErrorKind::UnsupportedOperation`]: crate::ErrorKind::UnsupportedOperation - /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable + /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable /// [`ErrorKind::StreamInvalidated`]: crate::ErrorKind::StreamInvalidated fn pause(&self) -> Result<(), Error>; @@ -746,11 +746,11 @@ pub trait StreamTrait: Send + Sync { /// /// # Errors /// - /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. /// - [`ErrorKind::StreamInvalidated`] if the stream configuration has changed and the stream /// must be rebuilt. /// - /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable + /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable /// [`ErrorKind::StreamInvalidated`]: crate::ErrorKind::StreamInvalidated fn stop(&self, timeout: Option) -> Result<(), Error>; From f3a172b0454453a820a008cf20517fd2d3d1d9b4 Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Wed, 21 Oct 2026 18:06:35 +0100 Subject: [PATCH 02/35] remove a legacy "extern crate" --- src/host/alsa.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/host/alsa.rs b/src/host/alsa.rs index cce8dcf24..914920c35 100644 --- a/src/host/alsa.rs +++ b/src/host/alsa.rs @@ -5,7 +5,6 @@ extern crate alsa; #[cfg(feature = "realtime")] extern crate alsa_sys; -extern crate libc; use std::{ mem, From 76a0ebe9afd1e1fa38783f593ead027e928718cd Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Wed, 21 Oct 2026 18:16:19 +0100 Subject: [PATCH 03/35] normalize cpal-spawned thread naming convention --- src/host/asio/stream.rs | 2 +- src/host/coreaudio/macos.rs | 4 ++-- src/host/jack.rs | 2 +- src/host/pipewire/device.rs | 6 +++--- src/host/pipewire/rt_promote.rs | 2 +- src/host/pipewire/stream.rs | 4 ++-- src/host/pulseaudio.rs | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/host/asio/stream.rs b/src/host/asio/stream.rs index 35c35750a..955406f97 100644 --- a/src/host/asio/stream.rs +++ b/src/host/asio/stream.rs @@ -1022,7 +1022,7 @@ impl Device { let (timer_tx, timer_rx) = mpsc::channel::(); let error_cb_for_timer = Arc::clone(&error_callback_shared); std::thread::Builder::new() - .name("cpal-asio-event-timer".into()) + .name("cpal_asio_event_timer".into()) .spawn(move || { let mut pending: Option = None; loop { diff --git a/src/host/coreaudio/macos.rs b/src/host/coreaudio/macos.rs index 7afe80e10..20affa2cf 100644 --- a/src/host/coreaudio/macos.rs +++ b/src/host/coreaudio/macos.rs @@ -312,7 +312,7 @@ impl DisconnectManager { let mut latch = Latch::new(); spawn_delivery_thread( - "cpal-coreaudio-disconnect", + "cpal_coreaudio_disconnect", &mut latch, disconnect_rx, stream_weak, @@ -435,7 +435,7 @@ impl DefaultOutputMonitor { let mut latch = Latch::new(); spawn_delivery_thread( - "cpal-coreaudio-default-output", + "cpal_coreaudio_default_out", &mut latch, change_rx, stream_weak, diff --git a/src/host/jack.rs b/src/host/jack.rs index 1bf6c0882..6c7ac0df0 100644 --- a/src/host/jack.rs +++ b/src/host/jack.rs @@ -46,7 +46,7 @@ pub struct Host { impl Host { pub fn new() -> Result { let mut host = Host { - name: format!("cpal_client_{}", std::process::id()), + name: format!("cpal_jack_{}", std::process::id()), connect_ports_automatically: true, start_server_automatically: false, devices_created: vec![], diff --git a/src/host/pipewire/device.rs b/src/host/pipewire/device.rs index 179550e64..0a163030a 100644 --- a/src/host/pipewire/device.rs +++ b/src/host/pipewire/device.rs @@ -175,7 +175,7 @@ impl Device { // preventing phase drift between simultaneous input/output streams. properties.insert( *pw::keys::NODE_GROUP, - format!("cpal-{}", std::process::id()), + format!("cpal_pw_node_{}", std::process::id()), ); properties.insert(*pw::keys::NODE_RATE, format!("1/{}", config.sample_rate)); @@ -385,7 +385,7 @@ impl DeviceTrait for Device { let data_callback = crate::host::monotonic_input_callback(data_callback); let start = std::time::Instant::now(); let handle = thread::Builder::new() - .name("pw_in".to_owned()) + .name("cpal_pw_in".to_owned()) .spawn(move || { let _pw = PwInitGuard::new(); let properties = device.pw_properties(DeviceDirection::Input, &config); @@ -583,7 +583,7 @@ impl DeviceTrait for Device { let data_callback = crate::host::monotonic_output_callback(data_callback); let start = std::time::Instant::now(); let handle = thread::Builder::new() - .name("pw_out".to_owned()) + .name("cpal_pw_out".to_owned()) .spawn(move || { let _pw = PwInitGuard::new(); let properties = device.pw_properties(DeviceDirection::Output, &config); diff --git a/src/host/pipewire/rt_promote.rs b/src/host/pipewire/rt_promote.rs index 43aeffab3..c3939ad41 100644 --- a/src/host/pipewire/rt_promote.rs +++ b/src/host/pipewire/rt_promote.rs @@ -39,7 +39,7 @@ impl RtPromoter { let error_callback_bg = error_callback.clone(); let join = thread::Builder::new() - .name("cpal_rt_promote".to_owned()) + .name("cpal_pw_rt_promote".to_owned()) .spawn(move || { let mut promoted = false; loop { diff --git a/src/host/pipewire/stream.rs b/src/host/pipewire/stream.rs index 5d98b886b..32e5d91fb 100644 --- a/src/host/pipewire/stream.rs +++ b/src/host/pipewire/stream.rs @@ -738,7 +738,7 @@ where let rate = config.sample_rate as _; let stream = StreamRc::new( core.clone(), - &format!("cpal-playback-{}", std::process::id()), + &format!("cpal_pw_out_{}", std::process::id()), properties, )?; @@ -1013,7 +1013,7 @@ where let rate = config.sample_rate as _; let stream = StreamRc::new( core.clone(), - &format!("cpal-capture-{}", std::process::id()), + &format!("cpal_pw_in_{}", std::process::id()), properties, )?; let listener = stream diff --git a/src/host/pulseaudio.rs b/src/host/pulseaudio.rs index 463cbb015..7d8ddba6e 100644 --- a/src/host/pulseaudio.rs +++ b/src/host/pulseaudio.rs @@ -134,7 +134,7 @@ impl Host { // returns, fall through to the next host with no other option than to leak the thread. let (tx, rx) = mpsc::channel(); std::thread::spawn(move || { - let name = CString::new(format!("cpal-pulseaudio-{}", std::process::id())).unwrap(); + let name = CString::new(format!("cpal_pulseaudio_{}", std::process::id())).unwrap(); let _ = tx.send(pulseaudio::Client::from_env(&name)); }); let client = rx From cabc751a7d08219601d8cd5b7cf5b4be78fb3fa0 Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Wed, 21 Oct 2026 18:22:12 +0100 Subject: [PATCH 04/35] neaten up/remove duplicaton in ndk AudioError to cpal error conversion --- src/host/aaudio/convert.rs | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/src/host/aaudio/convert.rs b/src/host/aaudio/convert.rs index e57ff568e..fea7a3e49 100644 --- a/src/host/aaudio/convert.rs +++ b/src/host/aaudio/convert.rs @@ -58,27 +58,17 @@ pub fn input_stream_instant(stream: &ndk::audio::AudioStream, sample_rate: u32) impl From for Error { fn from(error: ndk::audio::AudioError) -> Self { use ndk::audio::AudioError::*; - match error { - Disconnected | Unavailable | NoService | InvalidHandle => { - Error::with_message(ErrorKind::DeviceUnavailable, error.to_string()) - } - NoFreeHandles | NoMemory => { - Error::with_message(ErrorKind::ResourceExhausted, error.to_string()) - } - WouldBlock | Timeout => Error::with_message(ErrorKind::DeviceBusy, error.to_string()), - InvalidFormat | InvalidRate => { - Error::with_message(ErrorKind::UnsupportedConfig, error.to_string()) - } - IllegalArgument | Null | OutOfRange => { - Error::with_message(ErrorKind::InvalidInput, error.to_string()) - } - Internal | InvalidState => { - Error::with_message(ErrorKind::StreamInvalidated, error.to_string()) - } - Unimplemented => { - Error::with_message(ErrorKind::UnsupportedOperation, error.to_string()) - } - _ => Error::with_message(ErrorKind::BackendError, error.to_string()), - } + let kind = match error { + Disconnected | Unavailable | NoService | InvalidHandle => ErrorKind::DeviceUnavailable, + NoFreeHandles | NoMemory => ErrorKind::ResourceExhausted, + WouldBlock | Timeout => ErrorKind::DeviceBusy, + InvalidFormat | InvalidRate => ErrorKind::UnsupportedConfig, + IllegalArgument | Null | OutOfRange => ErrorKind::InvalidInput, + Internal | InvalidState => ErrorKind::StreamInvalidated, + Unimplemented => ErrorKind::UnsupportedOperation, + _ => ErrorKind::BackendError, + }; + + Error::with_message(kind, error.to_string()) } } From 3ffb97b412a5cc7fcfa5f3df90099dc5d12ecc0f Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Fri, 23 Oct 2026 12:02:39 +0100 Subject: [PATCH 05/35] move validate_duplex_config into duplex.rs (shared logic) --- src/duplex.rs | 19 ++++++++++++++++++- src/host/jack/device.rs | 25 ++++--------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/duplex.rs b/src/duplex.rs index b98394f18..ccce205c6 100644 --- a/src/duplex.rs +++ b/src/duplex.rs @@ -1,4 +1,4 @@ -use crate::{BufferSize, CallbackInfo, ChannelCount, SampleRate}; +use crate::{BufferSize, CallbackInfo, ChannelCount, SampleRate, StreamConfig}; /// Information relevant to a single call to the user's duplex stream data callback. /// @@ -40,3 +40,20 @@ pub struct DuplexStreamConfig { /// The desired buffer size, in frames per callback. pub buffer_size: BufferSize, } + +/// Applies [`validate_config`] to each direction of a duplex configuration. +pub(crate) fn validate_duplex_config(config: &DuplexStreamConfig) -> Result<(), crate::Error> { + let input = StreamConfig { + channels: config.input_channels, + sample_rate: config.sample_rate, + buffer_size: config.buffer_size, + }; + validate_stream_config(&input)?; + + let output = StreamConfig { + channels: config.output_channels, + sample_rate: config.sample_rate, + buffer_size: config.buffer_size, + }; + validate_stream_config(&output) +} diff --git a/src/host/jack/device.rs b/src/host/jack/device.rs index e95587f0b..984e9eb42 100644 --- a/src/host/jack/device.rs +++ b/src/host/jack/device.rs @@ -10,7 +10,7 @@ use crate::{ BufferSize, CallbackInfo, ChannelCount, Data, DeviceDescription, DeviceDescriptionBuilder, DeviceDirection, DeviceId, DuplexCallbackInfo, DuplexStreamConfig, Error, ErrorKind, SampleFormat, SampleRate, StreamConfig, SupportedBufferSize, SupportedStreamConfig, - SupportedStreamConfigRange, traits::DeviceTrait, + SupportedStreamConfigRange, duplex::validate_duplex_config, traits::DeviceTrait, }; const DEFAULT_NUM_CHANNELS: ChannelCount = 2; @@ -351,7 +351,9 @@ impl DeviceTrait for Device { "Device does not support duplex streams", )); } - validate_duplex_stream_config(&config, input_sample_format, output_sample_format)?; + validate_duplex_config(&config)?; + validate_sample_rate(&input_sample_format)?; + validate_sample_rate(&output_sample_format)?; // Keep both `capture` and `playback` monotonic: re-patching cpal's ports to a // different hardware port can move either direction's latency, pulling `device` @@ -440,25 +442,6 @@ fn build_with_timeout( }) } -/// Applies the sample rate/buffer size/channel checks from [`crate::validate_stream_config`] to -/// each direction of a duplex configuration, and checks each direction's sample format. -fn validate_duplex_stream_config( - config: &DuplexStreamConfig, - input_sample_format: SampleFormat, - output_sample_format: SampleFormat, -) -> Result<(), Error> { - let per_direction = |channels| StreamConfig { - channels, - sample_rate: config.sample_rate, - buffer_size: config.buffer_size, - }; - crate::validate_stream_config(&per_direction(config.input_channels))?; - validate_sample_format(input_sample_format)?; - crate::validate_stream_config(&per_direction(config.output_channels))?; - validate_sample_format(output_sample_format)?; - Ok(()) -} - fn validate_sample_format(sample_format: SampleFormat) -> Result<(), Error> { if sample_format != JACK_SAMPLE_FORMAT { return Err(Error::with_message( From 2c2beb251ab8d30018fb6e384cf48712e888b542 Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Fri, 23 Oct 2026 13:24:31 +0100 Subject: [PATCH 06/35] add "client" to sound server names --- src/host/jack.rs | 2 +- src/host/pulseaudio.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/host/jack.rs b/src/host/jack.rs index 6c7ac0df0..de9064b3d 100644 --- a/src/host/jack.rs +++ b/src/host/jack.rs @@ -46,7 +46,7 @@ pub struct Host { impl Host { pub fn new() -> Result { let mut host = Host { - name: format!("cpal_jack_{}", std::process::id()), + name: format!("cpal_jack_client_{}", std::process::id()), connect_ports_automatically: true, start_server_automatically: false, devices_created: vec![], diff --git a/src/host/pulseaudio.rs b/src/host/pulseaudio.rs index 7d8ddba6e..23452ad0d 100644 --- a/src/host/pulseaudio.rs +++ b/src/host/pulseaudio.rs @@ -134,7 +134,7 @@ impl Host { // returns, fall through to the next host with no other option than to leak the thread. let (tx, rx) = mpsc::channel(); std::thread::spawn(move || { - let name = CString::new(format!("cpal_pulseaudio_{}", std::process::id())).unwrap(); + let name = CString::new(format!("cpal_pulseaudio_client_{}", std::process::id())).unwrap(); let _ = tx.send(pulseaudio::Client::from_env(&name)); }); let client = rx From 85f68d5c78b3348a38de50a50cda2130373abb03 Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Fri, 23 Oct 2026 13:25:15 +0100 Subject: [PATCH 07/35] cargo fmt --- src/host/pulseaudio.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/host/pulseaudio.rs b/src/host/pulseaudio.rs index 23452ad0d..4ac6fc35a 100644 --- a/src/host/pulseaudio.rs +++ b/src/host/pulseaudio.rs @@ -134,7 +134,8 @@ impl Host { // returns, fall through to the next host with no other option than to leak the thread. let (tx, rx) = mpsc::channel(); std::thread::spawn(move || { - let name = CString::new(format!("cpal_pulseaudio_client_{}", std::process::id())).unwrap(); + let name = + CString::new(format!("cpal_pulseaudio_client_{}", std::process::id())).unwrap(); let _ = tx.send(pulseaudio::Client::from_env(&name)); }); let client = rx From a831ea9ba445750d27f811d2fb450c91d3dce8d9 Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Fri, 23 Oct 2026 13:54:57 +0100 Subject: [PATCH 08/35] add required funcs for validate_duplex_config --- src/duplex.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/duplex.rs b/src/duplex.rs index ccce205c6..e3783d852 100644 --- a/src/duplex.rs +++ b/src/duplex.rs @@ -1,4 +1,6 @@ -use crate::{BufferSize, CallbackInfo, ChannelCount, SampleRate, StreamConfig}; +use crate::{ + BufferSize, CallbackInfo, ChannelCount, Error, SampleRate, StreamConfig, validate_stream_config, +}; /// Information relevant to a single call to the user's duplex stream data callback. /// @@ -42,7 +44,7 @@ pub struct DuplexStreamConfig { } /// Applies [`validate_config`] to each direction of a duplex configuration. -pub(crate) fn validate_duplex_config(config: &DuplexStreamConfig) -> Result<(), crate::Error> { +pub(crate) fn validate_duplex_config(config: &DuplexStreamConfig) -> Result<(), Error> { let input = StreamConfig { channels: config.input_channels, sample_rate: config.sample_rate, From 4f05967d3e865b255dd2dc8e3786d0bf11afe347 Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Fri, 23 Oct 2026 14:01:37 +0100 Subject: [PATCH 09/35] fix: call the right function to check for jack's sampleformat --- src/host/jack/device.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/host/jack/device.rs b/src/host/jack/device.rs index 984e9eb42..012c67f30 100644 --- a/src/host/jack/device.rs +++ b/src/host/jack/device.rs @@ -352,8 +352,8 @@ impl DeviceTrait for Device { )); } validate_duplex_config(&config)?; - validate_sample_rate(&input_sample_format)?; - validate_sample_rate(&output_sample_format)?; + validate_sample_format(&input_sample_format)?; + validate_sample_format(&output_sample_format)?; // Keep both `capture` and `playback` monotonic: re-patching cpal's ports to a // different hardware port can move either direction's latency, pulling `device` From cc96c9ce4179a07a039ab01513ee581eb96c1d21 Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Fri, 23 Oct 2026 14:05:18 +0100 Subject: [PATCH 10/35] cfg gate validate_duplex_config --- src/duplex.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/duplex.rs b/src/duplex.rs index e3783d852..602c4145f 100644 --- a/src/duplex.rs +++ b/src/duplex.rs @@ -43,6 +43,17 @@ pub struct DuplexStreamConfig { pub buffer_size: BufferSize, } +#[cfg(all( + feature = "jack", + any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "macos", + target_os = "windows", + ) +))] /// Applies [`validate_config`] to each direction of a duplex configuration. pub(crate) fn validate_duplex_config(config: &DuplexStreamConfig) -> Result<(), Error> { let input = StreamConfig { From 856a1db6caf6a771fa2c0f01a89a5b47f42e2a0f Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Fri, 23 Oct 2026 14:28:08 +0100 Subject: [PATCH 11/35] fix unused imports --- src/duplex.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/duplex.rs b/src/duplex.rs index 602c4145f..719301c26 100644 --- a/src/duplex.rs +++ b/src/duplex.rs @@ -1,5 +1,5 @@ use crate::{ - BufferSize, CallbackInfo, ChannelCount, Error, SampleRate, StreamConfig, validate_stream_config, + BufferSize, CallbackInfo, ChannelCount, SampleRate, }; /// Information relevant to a single call to the user's duplex stream data callback. @@ -55,18 +55,18 @@ pub struct DuplexStreamConfig { ) ))] /// Applies [`validate_config`] to each direction of a duplex configuration. -pub(crate) fn validate_duplex_config(config: &DuplexStreamConfig) -> Result<(), Error> { - let input = StreamConfig { +pub(crate) fn validate_duplex_config(config: &DuplexStreamConfig) -> Result<(), crate::Error> { + let input = crate::StreamConfig { channels: config.input_channels, sample_rate: config.sample_rate, buffer_size: config.buffer_size, }; - validate_stream_config(&input)?; + crate::validate_stream_config(&input)?; - let output = StreamConfig { + let output = crate::StreamConfig { channels: config.output_channels, sample_rate: config.sample_rate, buffer_size: config.buffer_size, }; - validate_stream_config(&output) + crate::validate_stream_config(&output) } From aa8f10c010d9365e32db94a2e5a62c796054fbfb Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Fri, 23 Oct 2026 15:00:05 +0100 Subject: [PATCH 12/35] remove borrow --- src/duplex.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/duplex.rs b/src/duplex.rs index 719301c26..6a83ca28a 100644 --- a/src/duplex.rs +++ b/src/duplex.rs @@ -61,12 +61,12 @@ pub(crate) fn validate_duplex_config(config: &DuplexStreamConfig) -> Result<(), sample_rate: config.sample_rate, buffer_size: config.buffer_size, }; - crate::validate_stream_config(&input)?; + crate::validate_stream_config(input)?; let output = crate::StreamConfig { channels: config.output_channels, sample_rate: config.sample_rate, buffer_size: config.buffer_size, }; - crate::validate_stream_config(&output) + crate::validate_stream_config(output) } From 1cf33c5d513305a1fe5eb7f7d4e4d61605f5a72d Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Fri, 23 Oct 2026 15:20:04 +0100 Subject: [PATCH 13/35] undo last and fix the actual error --- src/duplex.rs | 4 ++-- src/host/jack/device.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/duplex.rs b/src/duplex.rs index 6a83ca28a..719301c26 100644 --- a/src/duplex.rs +++ b/src/duplex.rs @@ -61,12 +61,12 @@ pub(crate) fn validate_duplex_config(config: &DuplexStreamConfig) -> Result<(), sample_rate: config.sample_rate, buffer_size: config.buffer_size, }; - crate::validate_stream_config(input)?; + crate::validate_stream_config(&input)?; let output = crate::StreamConfig { channels: config.output_channels, sample_rate: config.sample_rate, buffer_size: config.buffer_size, }; - crate::validate_stream_config(output) + crate::validate_stream_config(&output) } diff --git a/src/host/jack/device.rs b/src/host/jack/device.rs index 012c67f30..572ab8b9e 100644 --- a/src/host/jack/device.rs +++ b/src/host/jack/device.rs @@ -352,8 +352,8 @@ impl DeviceTrait for Device { )); } validate_duplex_config(&config)?; - validate_sample_format(&input_sample_format)?; - validate_sample_format(&output_sample_format)?; + validate_sample_format(input_sample_format)?; + validate_sample_format(output_sample_format)?; // Keep both `capture` and `playback` monotonic: re-patching cpal's ports to a // different hardware port can move either direction's latency, pulling `device` From 5af45e6b71b9ecb2e1938870fbca820f1feb691b Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Fri, 23 Oct 2026 15:22:26 +0100 Subject: [PATCH 14/35] neaten up jack error to cpal error conversion --- src/duplex.rs | 4 +--- src/host/jack.rs | 26 +++++++++----------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/duplex.rs b/src/duplex.rs index 719301c26..3d4bb9ef2 100644 --- a/src/duplex.rs +++ b/src/duplex.rs @@ -1,6 +1,4 @@ -use crate::{ - BufferSize, CallbackInfo, ChannelCount, SampleRate, -}; +use crate::{BufferSize, CallbackInfo, ChannelCount, SampleRate}; /// Information relevant to a single call to the user's duplex stream data callback. /// diff --git a/src/host/jack.rs b/src/host/jack.rs index de9064b3d..8eab3ff63 100644 --- a/src/host/jack.rs +++ b/src/host/jack.rs @@ -178,35 +178,27 @@ fn get_client_options(start_server_automatically: bool) -> jack::ClientOptions { impl From for Error { fn from(err: jack::Error) -> Self { - let msg = format!("{err}"); - match err { + let kind = match err { jack::Error::ClientError(_) | jack::Error::ClientActivationError | jack::Error::ClientDeactivationError | jack::Error::LibraryError(_) | jack::Error::WeakFunctionNotFound(_) - | jack::Error::RingbufferCreateFailed => { - Error::with_message(ErrorKind::DeviceUnavailable, msg) - } + | jack::Error::RingbufferCreateFailed => ErrorKind::DeviceUnavailable, jack::Error::ClientIsNoLongerAlive | jack::Error::ClientPanicked => { - Error::with_message(ErrorKind::StreamInvalidated, msg) + ErrorKind::StreamInvalidated } - jack::Error::SetBufferSizeError | jack::Error::NotEnoughSpace => { - Error::with_message(ErrorKind::UnsupportedConfig, msg) + ErrorKind::UnsupportedConfig } - jack::Error::InvalidDeactivation | jack::Error::FreewheelError => { - Error::with_message(ErrorKind::UnsupportedOperation, msg) - } - - jack::Error::PortNamingError | jack::Error::PortAliasError => { - Error::with_message(ErrorKind::InvalidInput, msg) + ErrorKind::UnsupportedOperation } - - _ => Error::with_message(ErrorKind::BackendError, msg), - } + jack::Error::PortNamingError | jack::Error::PortAliasError => ErrorKind::InvalidInput, + _ => ErrorKind::BackendError, + }; + Error::with_message(kind, format!("{err}")) } } From dbd194af3f961ddd8117bfe49182b51d3daa5c94 Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Fri, 23 Oct 2026 15:34:09 +0100 Subject: [PATCH 15/35] add frames_to_duration back when needed --- src/host.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/host.rs b/src/host.rs index 13a039a1c..0fb306b08 100644 --- a/src/host.rs +++ b/src/host.rs @@ -227,6 +227,13 @@ pub(crate) use error_emit::try_emit_error; target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", + all( + target_os = "windows", + any( + feature = "asio", + feature = "jack", + ) + ), target_vendor = "apple", all(target_os = "windows", any(feature = "asio", feature = "jack")), all( From 26b2703ffbe6df92621743b9b18aa02a94804bfe Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Fri, 23 Oct 2026 15:45:10 +0100 Subject: [PATCH 16/35] cargo fmt --- src/host.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/host.rs b/src/host.rs index 0fb306b08..ebf300930 100644 --- a/src/host.rs +++ b/src/host.rs @@ -227,13 +227,7 @@ pub(crate) use error_emit::try_emit_error; target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", - all( - target_os = "windows", - any( - feature = "asio", - feature = "jack", - ) - ), + all(target_os = "windows", any(feature = "asio", feature = "jack",)), target_vendor = "apple", all(target_os = "windows", any(feature = "asio", feature = "jack")), all( From b8a60d247722c6d4c63d1a6a074118a29c83b778 Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Mon, 26 Oct 2026 10:10:02 +0000 Subject: [PATCH 17/35] remove unused try_emit_error on aaudio when not using the realtime feature --- src/host.rs | 2 +- src/host/aaudio.rs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/host.rs b/src/host.rs index ebf300930..e3a629de1 100644 --- a/src/host.rs +++ b/src/host.rs @@ -197,7 +197,7 @@ pub(crate) use error_emit::emit_error; #[cfg(any( target_vendor = "apple", - target_os = "android", + all(target_os = "android", feature = "realtime",), all( feature = "jack", any( diff --git a/src/host/aaudio.rs b/src/host/aaudio.rs index 2de6551bb..72f1a9d82 100644 --- a/src/host/aaudio.rs +++ b/src/host/aaudio.rs @@ -24,6 +24,8 @@ use crate::{ extern crate ndk; use self::ndk::audio::AudioStream; + +#[cfg(feature = "realtime")] use crate::host::try_emit_error; mod convert; From 0ea6c81f23af88b5f7fd3d35d1d97ce798a095c8 Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Mon, 26 Oct 2026 13:08:17 +0000 Subject: [PATCH 18/35] remove all legacy extern crate syntax --- src/host/aaudio.rs | 3 +-- src/host/aaudio/convert.rs | 2 -- src/host/alsa.rs | 12 +++++------- src/host/alsa/device.rs | 4 ++-- src/host/alsa/duplex.rs | 5 ++--- src/host/alsa/enumerate.rs | 2 +- src/host/alsa/hw_params.rs | 2 +- src/host/alsa/stream.rs | 5 ++--- src/host/alsa/timestamp.rs | 2 +- src/host/alsa/worker.rs | 4 +--- src/host/asio.rs | 2 +- src/host/asio/stream.rs | 5 ++--- src/host/jack.rs | 2 -- src/host/jack/stream.rs | 3 +-- src/host/webaudio.rs | 17 ++++++----------- src/lib.rs | 20 -------------------- 16 files changed, 26 insertions(+), 64 deletions(-) diff --git a/src/host/aaudio.rs b/src/host/aaudio.rs index 72f1a9d82..faa2713d5 100644 --- a/src/host/aaudio.rs +++ b/src/host/aaudio.rs @@ -22,8 +22,7 @@ use crate::{ traits::{DeviceTrait, HostTrait, StreamTrait}, }; -extern crate ndk; -use self::ndk::audio::AudioStream; +use ndk::audio::AudioStream; #[cfg(feature = "realtime")] use crate::host::try_emit_error; diff --git a/src/host/aaudio/convert.rs b/src/host/aaudio/convert.rs index fea7a3e49..bed019ec1 100644 --- a/src/host/aaudio/convert.rs +++ b/src/host/aaudio/convert.rs @@ -1,7 +1,5 @@ //! Time-conversion helpers for the AAudio backend. -extern crate ndk; - use crate::{Error, ErrorKind, StreamInstant}; /// Returns a [`StreamInstant`] for the current moment. diff --git a/src/host/alsa.rs b/src/host/alsa.rs index 914920c35..09fc0e36c 100644 --- a/src/host/alsa.rs +++ b/src/host/alsa.rs @@ -2,19 +2,17 @@ //! //! Default backend on Linux and BSD systems. -extern crate alsa; -#[cfg(feature = "realtime")] -extern crate alsa_sys; - use std::{ mem, sync::{Arc, Mutex}, time::Duration, }; -pub use self::device::Device; -pub use self::enumerate::Devices; -pub use self::stream::Stream; +pub use self::{ + device::Device, + enumerate::Devices, + stream::Stream, +}; use crate::{ DeviceDirection, DeviceId, Error, ErrorKind, traits::{DeviceTrait, HostTrait}, diff --git a/src/host/alsa/device.rs b/src/host/alsa/device.rs index b70177d7b..7922c7e88 100644 --- a/src/host/alsa/device.rs +++ b/src/host/alsa/device.rs @@ -5,10 +5,10 @@ use std::{ time::Duration, vec::IntoIter as VecIntoIter, }; +use alsa::poll::Descriptors; use super::{ - AlsaContext, DEFAULT_PERIODS, Stream, alsa, - alsa::poll::Descriptors, + AlsaContext, DEFAULT_PERIODS, Stream, hw_params::{ StartThreshold, set_hw_params_from_format, set_sw_params_from_format, supported_period_size_range, diff --git a/src/host/alsa/duplex.rs b/src/host/alsa/duplex.rs index 3bf0eaa27..acc54185d 100644 --- a/src/host/alsa/duplex.rs +++ b/src/host/alsa/duplex.rs @@ -2,10 +2,9 @@ use std::{ sync::{Arc, atomic::Ordering}, time::Duration, }; - +use alsa::poll::Descriptors; use super::{ - DEFAULT_PERIODS, alsa, - alsa::poll::Descriptors, + DEFAULT_PERIODS, poll_timeout_millis, stream::{DuplexDataCallback, DuplexStreamInner, ErrorCallback}, timestamp::{callback_instant_for, status_with_timestamp}, diff --git a/src/host/alsa/enumerate.rs b/src/host/alsa/enumerate.rs index 8d076b20a..8ef44a577 100644 --- a/src/host/alsa/enumerate.rs +++ b/src/host/alsa/enumerate.rs @@ -1,6 +1,6 @@ use std::collections::HashSet; -use super::{Device, Host, alsa}; +use super::{Device, Host}; use crate::{DeviceDirection, Error}; const HW_PREFIX: &str = "hw"; diff --git a/src/host/alsa/hw_params.rs b/src/host/alsa/hw_params.rs index 22a13be17..7f5231188 100644 --- a/src/host/alsa/hw_params.rs +++ b/src/host/alsa/hw_params.rs @@ -1,4 +1,4 @@ -use super::{DEFAULT_PERIODS, alsa}; +use super::DEFAULT_PERIODS; use crate::{ BufferSize, ChannelCount, Error, ErrorKind, FrameCount, SampleFormat, StreamConfig, SupportedBufferSize, diff --git a/src/host/alsa/stream.rs b/src/host/alsa/stream.rs index bcba11e87..d6071ce30 100644 --- a/src/host/alsa/stream.rs +++ b/src/host/alsa/stream.rs @@ -6,10 +6,9 @@ use std::{ thread::{self, JoinHandle}, time::{Duration, Instant}, }; - +use alsa::poll::Descriptors; use super::{ - AlsaContext, POLL_INFINITE, alsa, - alsa::poll::Descriptors, + AlsaContext, POLL_INFINITE, duplex::{duplex_stream_worker, start_duplex}, timestamp::{callback_instant_for, status_with_timestamp}, trigger::{TriggerReceiver, TriggerSender, trigger}, diff --git a/src/host/alsa/timestamp.rs b/src/host/alsa/timestamp.rs index 59dfc4957..8ca6c7138 100644 --- a/src/host/alsa/timestamp.rs +++ b/src/host/alsa/timestamp.rs @@ -1,4 +1,4 @@ -use super::{alsa, stream::TimestampMode}; +use super::stream::TimestampMode; use crate::{Error, StreamInstant}; #[inline] diff --git a/src/host/alsa/worker.rs b/src/host/alsa/worker.rs index a58cc1b46..e3da9517d 100644 --- a/src/host/alsa/worker.rs +++ b/src/host/alsa/worker.rs @@ -2,10 +2,8 @@ use std::{ sync::{Arc, atomic::Ordering}, time::Duration, }; - +use alsa::poll::Descriptors; use super::{ - alsa, - alsa::poll::Descriptors, poll_timeout_millis, stream::{ErrorCallback, InputDataCallback, OutputDataCallback, StreamInner}, timestamp::status_with_timestamp, diff --git a/src/host/asio.rs b/src/host/asio.rs index 055fa7125..caeaae885 100644 --- a/src/host/asio.rs +++ b/src/host/asio.rs @@ -3,7 +3,7 @@ //! ASIO is available on Windows with the `asio` feature. //! See the project README for setup instructions. -extern crate asio_sys as sys; +use asio_sys as sys; use std::{ sync::{Arc, OnceLock}, diff --git a/src/host/asio/stream.rs b/src/host/asio/stream.rs index 955406f97..912eefcd7 100644 --- a/src/host/asio/stream.rs +++ b/src/host/asio/stream.rs @@ -1,5 +1,4 @@ -extern crate asio_sys as sys; -extern crate num_traits; +use asio_sys as sys; use std::{ sync::{ @@ -10,7 +9,7 @@ use std::{ time::Duration, }; -use self::num_traits::{FromPrimitive, PrimInt}; +use num_traits::{FromPrimitive, PrimInt}; use super::Device; use crate::{ BufferSize, CallbackInfo, Data, Error, ErrorKind, FrameCount, I24, Sample, SampleFormat, diff --git a/src/host/jack.rs b/src/host/jack.rs index 8eab3ff63..16fa239e1 100644 --- a/src/host/jack.rs +++ b/src/host/jack.rs @@ -2,8 +2,6 @@ //! //! Available on all platforms with the `jack` feature. Requires JACK server and client libraries. -extern crate jack; - use crate::{Error, ErrorKind, SampleFormat, traits::HostTrait}; mod device; diff --git a/src/host/jack/stream.rs b/src/host/jack/stream.rs index f2d244fd5..747b33171 100644 --- a/src/host/jack/stream.rs +++ b/src/host/jack/stream.rs @@ -4,11 +4,10 @@ use std::sync::{ }; use super::JACK_SAMPLE_FORMAT; -use crate::host::try_emit_error; use crate::{ CallbackInfo, ChannelCount, Data, DuplexCallbackInfo, Error, ErrorKind, FrameCount, ResultExt, Sample, SampleRate, StreamInstant, StreamTimestamp, - host::{ErrorCallbackArc, emit_error, frames_to_duration, wait_for_drain}, + host::{ErrorCallbackArc, try_emit_error, emit_error, frames_to_duration, wait_for_drain}, traits::StreamTrait, }; diff --git a/src/host/webaudio.rs b/src/host/webaudio.rs index 8394ec025..33a1c8f07 100644 --- a/src/host/webaudio.rs +++ b/src/host/webaudio.rs @@ -2,10 +2,6 @@ //! //! Default backend on WebAssembly. -extern crate js_sys; -extern crate wasm_bindgen; -extern crate web_sys; - #[cfg(target_feature = "atomics")] use std::sync::atomic::AtomicU64; use std::{ @@ -38,14 +34,13 @@ type CaptureGraphResult = Result< >; #[cfg(not(target_feature = "atomics"))] -use self::web_sys::MediaStream; -use self::{ - wasm_bindgen::{JsCast, prelude::*}, - web_sys::{ - AudioContext, AudioContextOptions, AudioProcessingEvent, GainNode, - MediaStreamAudioSourceNode, ScriptProcessorNode, - }, +use web_sys::MediaStream; +use wasm_bindgen::{JsCast, prelude::*}; +use web_sys::{ + AudioContext, AudioContextOptions, AudioProcessingEvent, GainNode, + MediaStreamAudioSourceNode, ScriptProcessorNode, }; + use crate::{ BufferSize, CallbackInfo, ChannelCount, Data, DeviceDescription, DeviceDescriptionBuilder, DeviceDirection, DeviceId, DuplexCallbackInfo, DuplexStreamConfig, Error, ErrorKind, diff --git a/src/lib.rs b/src/lib.rs index 1ece644f3..d697c3e60 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -195,26 +195,6 @@ #![cfg_attr(docsrs, feature(doc_cfg))] -// Extern crate declarations with `#[macro_use]` must unfortunately be at crate root. -#[cfg(all( - target_arch = "wasm32", - any(target_os = "emscripten", target_os = "unknown"), - feature = "wasm-bindgen" -))] -extern crate js_sys; -#[cfg(all( - target_arch = "wasm32", - any(target_os = "emscripten", target_os = "unknown"), - feature = "wasm-bindgen" -))] -extern crate wasm_bindgen; -#[cfg(all( - target_arch = "wasm32", - any(target_os = "emscripten", target_os = "unknown"), - feature = "wasm-bindgen" -))] -extern crate web_sys; - pub use device_description::{ DeviceDescription, DeviceDescriptionBuilder, DeviceDirection, DeviceType, InterfaceType, }; From aba26b31ab7bb7d2a7ea132fa65152036bb1b22b Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Mon, 26 Oct 2026 13:12:06 +0000 Subject: [PATCH 19/35] let cargo fmt rejig import ordering --- src/host/alsa.rs | 6 +----- src/host/alsa/device.rs | 2 +- src/host/alsa/duplex.rs | 13 ++++++------- src/host/alsa/stream.rs | 18 +++++++++--------- src/host/alsa/worker.rs | 10 +++++----- src/host/asio/stream.rs | 2 +- src/host/jack/stream.rs | 2 +- src/host/webaudio.rs | 6 +++--- 8 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/host/alsa.rs b/src/host/alsa.rs index 09fc0e36c..78545b3fd 100644 --- a/src/host/alsa.rs +++ b/src/host/alsa.rs @@ -8,11 +8,7 @@ use std::{ time::Duration, }; -pub use self::{ - device::Device, - enumerate::Devices, - stream::Stream, -}; +pub use self::{device::Device, enumerate::Devices, stream::Stream}; use crate::{ DeviceDirection, DeviceId, Error, ErrorKind, traits::{DeviceTrait, HostTrait}, diff --git a/src/host/alsa/device.rs b/src/host/alsa/device.rs index 7922c7e88..77e283498 100644 --- a/src/host/alsa/device.rs +++ b/src/host/alsa/device.rs @@ -1,3 +1,4 @@ +use alsa::poll::Descriptors; use std::{ collections::HashMap, fmt, @@ -5,7 +6,6 @@ use std::{ time::Duration, vec::IntoIter as VecIntoIter, }; -use alsa::poll::Descriptors; use super::{ AlsaContext, DEFAULT_PERIODS, Stream, diff --git a/src/host/alsa/duplex.rs b/src/host/alsa/duplex.rs index acc54185d..eb4a423f7 100644 --- a/src/host/alsa/duplex.rs +++ b/src/host/alsa/duplex.rs @@ -1,11 +1,5 @@ -use std::{ - sync::{Arc, atomic::Ordering}, - time::Duration, -}; -use alsa::poll::Descriptors; use super::{ - DEFAULT_PERIODS, - poll_timeout_millis, + DEFAULT_PERIODS, poll_timeout_millis, stream::{DuplexDataCallback, DuplexStreamInner, ErrorCallback}, timestamp::{callback_instant_for, status_with_timestamp}, trigger::TriggerReceiver, @@ -14,6 +8,11 @@ use crate::{ CallbackInfo, Data, DuplexCallbackInfo, Error, ErrorKind, FrameCount, StreamInstant, StreamTimestamp, host::frames_to_duration, }; +use alsa::poll::Descriptors; +use std::{ + sync::{Arc, atomic::Ordering}, + time::Duration, +}; pub(super) fn start_duplex(stream: &DuplexStreamInner) -> Result<(), Error> { match stream.capture.handle.state() { diff --git a/src/host/alsa/stream.rs b/src/host/alsa/stream.rs index d6071ce30..35e59bb0e 100644 --- a/src/host/alsa/stream.rs +++ b/src/host/alsa/stream.rs @@ -1,12 +1,3 @@ -use std::{ - sync::{ - Arc, - atomic::{AtomicBool, Ordering}, - }, - thread::{self, JoinHandle}, - time::{Duration, Instant}, -}; -use alsa::poll::Descriptors; use super::{ AlsaContext, POLL_INFINITE, duplex::{duplex_stream_worker, start_duplex}, @@ -24,6 +15,15 @@ use crate::{ }, traits::StreamTrait, }; +use alsa::poll::Descriptors; +use std::{ + sync::{ + Arc, + atomic::{AtomicBool, Ordering}, + }, + thread::{self, JoinHandle}, + time::{Duration, Instant}, +}; pub(super) type InputDataCallback = dyn FnMut(&Data, &CallbackInfo) + Send + 'static; pub(super) type OutputDataCallback = dyn FnMut(&mut Data, &CallbackInfo) + Send + 'static; diff --git a/src/host/alsa/worker.rs b/src/host/alsa/worker.rs index e3da9517d..69e176a67 100644 --- a/src/host/alsa/worker.rs +++ b/src/host/alsa/worker.rs @@ -1,8 +1,3 @@ -use std::{ - sync::{Arc, atomic::Ordering}, - time::Duration, -}; -use alsa::poll::Descriptors; use super::{ poll_timeout_millis, stream::{ErrorCallback, InputDataCallback, OutputDataCallback, StreamInner}, @@ -13,6 +8,11 @@ use crate::{ CallbackInfo, Data, Error, ErrorKind, FrameCount, StreamInstant, StreamTimestamp, host::frames_to_duration, }; +use alsa::poll::Descriptors; +use std::{ + sync::{Arc, atomic::Ordering}, + time::Duration, +}; pub(super) fn input_stream_worker( rx: Arc, diff --git a/src/host/asio/stream.rs b/src/host/asio/stream.rs index 912eefcd7..20c1224b0 100644 --- a/src/host/asio/stream.rs +++ b/src/host/asio/stream.rs @@ -9,7 +9,6 @@ use std::{ time::Duration, }; -use num_traits::{FromPrimitive, PrimInt}; use super::Device; use crate::{ BufferSize, CallbackInfo, Data, Error, ErrorKind, FrameCount, I24, Sample, SampleFormat, @@ -19,6 +18,7 @@ use crate::{ wait_for_drain, }, }; +use num_traits::{FromPrimitive, PrimInt}; /// Shared state for extending the 32-bit `timeGetTime()` millisecond counter into a /// monotonic 64-bit nanosecond value, shared between `now()` and audio callbacks. diff --git a/src/host/jack/stream.rs b/src/host/jack/stream.rs index 747b33171..df0e408d3 100644 --- a/src/host/jack/stream.rs +++ b/src/host/jack/stream.rs @@ -7,7 +7,7 @@ use super::JACK_SAMPLE_FORMAT; use crate::{ CallbackInfo, ChannelCount, Data, DuplexCallbackInfo, Error, ErrorKind, FrameCount, ResultExt, Sample, SampleRate, StreamInstant, StreamTimestamp, - host::{ErrorCallbackArc, try_emit_error, emit_error, frames_to_duration, wait_for_drain}, + host::{ErrorCallbackArc, emit_error, frames_to_duration, try_emit_error, wait_for_drain}, traits::StreamTrait, }; diff --git a/src/host/webaudio.rs b/src/host/webaudio.rs index 33a1c8f07..da7cd289d 100644 --- a/src/host/webaudio.rs +++ b/src/host/webaudio.rs @@ -33,12 +33,12 @@ type CaptureGraphResult = Result< JsValue, >; +use wasm_bindgen::{JsCast, prelude::*}; #[cfg(not(target_feature = "atomics"))] use web_sys::MediaStream; -use wasm_bindgen::{JsCast, prelude::*}; use web_sys::{ - AudioContext, AudioContextOptions, AudioProcessingEvent, GainNode, - MediaStreamAudioSourceNode, ScriptProcessorNode, + AudioContext, AudioContextOptions, AudioProcessingEvent, GainNode, MediaStreamAudioSourceNode, + ScriptProcessorNode, }; use crate::{ From 58317c5c17841186c43fbe499a4a49d8ebf304f7 Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Mon, 26 Oct 2026 13:31:36 +0000 Subject: [PATCH 20/35] fix doc comment for validate_duplex_config --- src/duplex.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/duplex.rs b/src/duplex.rs index 3d4bb9ef2..8da26f42c 100644 --- a/src/duplex.rs +++ b/src/duplex.rs @@ -52,7 +52,7 @@ pub struct DuplexStreamConfig { target_os = "windows", ) ))] -/// Applies [`validate_config`] to each direction of a duplex configuration. +/// Applies [`validate_stream_config`] to each direction of a duplex configuration. pub(crate) fn validate_duplex_config(config: &DuplexStreamConfig) -> Result<(), crate::Error> { let input = crate::StreamConfig { channels: config.input_channels, From 0d463443de950a357324ea915394f485f4aea43e Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Mon, 26 Oct 2026 13:41:48 +0000 Subject: [PATCH 21/35] remove a redundant std error being pulled into scope --- src/error.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index fa9032e72..0e7bd68b3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -194,7 +194,6 @@ impl From for Error { ))] impl From for Error { fn from(err: audio_thread_priority::AudioThreadPriorityError) -> Self { - use std::error::Error as StdError; let msg = match err.source() { Some(inner) => { format!("Failed to promote audio thread to real-time priority: {err}: {inner}") From 402eca919ea714821763da935ceabd2b9e07a262 Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Mon, 26 Oct 2026 14:10:55 +0000 Subject: [PATCH 22/35] shorten a linux thread name to <= 15chars --- src/host/pipewire/rt_promote.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/host/pipewire/rt_promote.rs b/src/host/pipewire/rt_promote.rs index c3939ad41..528906c21 100644 --- a/src/host/pipewire/rt_promote.rs +++ b/src/host/pipewire/rt_promote.rs @@ -39,7 +39,7 @@ impl RtPromoter { let error_callback_bg = error_callback.clone(); let join = thread::Builder::new() - .name("cpal_pw_rt_promote".to_owned()) + .name("cpal_pw_rt_prom".to_owned()) .spawn(move || { let mut promoted = false; loop { From 79e8d77de7dff8d4c09f3165731f9bdc21024d5f Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Mon, 26 Oct 2026 15:16:37 +0000 Subject: [PATCH 23/35] shorten an alsa thread name to <= 15chars for linux --- src/host/alsa/stream.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/host/alsa/stream.rs b/src/host/alsa/stream.rs index 35e59bb0e..56b65ad64 100644 --- a/src/host/alsa/stream.rs +++ b/src/host/alsa/stream.rs @@ -182,7 +182,7 @@ impl Stream { let waiter = latch.waiter(); let thread = thread::Builder::new() - .name("cpal_alsa_duplex".to_owned()) + .name("cpal_alsa_dup".to_owned()) .spawn(move || { waiter.wait(); duplex_stream_worker( From 6bab7ea951bfa8045e13f09888cd877c8fba40d4 Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Mon, 26 Oct 2026 16:47:42 +0000 Subject: [PATCH 24/35] docs: add thread/client naming normalization to the changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34b1ab6ca..bd8a252a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Migrated to Rust 2024. - Bump minimum Windows version to 10 (since 0.17.2). - Bump `audio_thread_priority` dependency to 0.36. +- Normalized thread and client naming across all backends. - `DeviceTrait` and `StreamTrait` now require `Send + Sync` as supertrait bounds. - `StreamTrait::play` is renamed to `start`. - `DeviceNotAvailable` is renamed to `DeviceUnavailable`. From 4b0fc3a64b4cd27a2528b027545980ecdc5ffe40 Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Mon, 26 Oct 2026 18:01:03 +0000 Subject: [PATCH 25/35] use "{text}", rather than "{}", text where applicable --- src/host/alsa/enumerate.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/host/alsa/enumerate.rs b/src/host/alsa/enumerate.rs index 8ef44a577..2661b7fe3 100644 --- a/src/host/alsa/enumerate.rs +++ b/src/host/alsa/enumerate.rs @@ -57,8 +57,8 @@ impl Host { for phys_dev in physical_devices { for prefix in [HW_PREFIX, PLUGHW_PREFIX] { let pcm_id = format!( - "{}:CARD={},DEV={}", - prefix, phys_dev.card_index, phys_dev.device_index + "{prefix}:CARD={},DEV={}", + phys_dev.card_index, phys_dev.device_index ); if seen_pcm_ids.insert(pcm_id.clone()) { From 728f3d91766ef960ffb4fb10ea61d0894cb22e52 Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Mon, 26 Oct 2026 18:15:08 +0000 Subject: [PATCH 26/35] explicitely document which hosts don't support xrun detection, note: pulseaudio can but is awaiting a PR merge --- src/timestamp.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/timestamp.rs b/src/timestamp.rs index a6a961210..4f35fa0e7 100644 --- a/src/timestamp.rs +++ b/src/timestamp.rs @@ -61,6 +61,7 @@ pub struct StreamTimestamp { /// | Same-cycle | AAudio, ALSA, PipeWire, WASAPI (capture) | /// | Next-cycle | CoreAudio | /// | No ordering guarantee | ASIO, JACK | +/// | No reporting | PulseAudio, iOS, WebAudio, AudioWorklet | #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)] pub struct CallbackInfo { pub(crate) timestamp: StreamTimestamp, From 6064133f12077837b4e0cf2440834434576175c8 Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Mon, 26 Oct 2026 20:28:10 +0000 Subject: [PATCH 27/35] consistently return specific errors with consistently styled messages for failing to spawn a thread rather than unwraping --- src/host/alsa/stream.rs | 21 ++++++++++++++++++--- src/host/wasapi/stream.rs | 4 ++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/host/alsa/stream.rs b/src/host/alsa/stream.rs index 56b65ad64..f2a2009ef 100644 --- a/src/host/alsa/stream.rs +++ b/src/host/alsa/stream.rs @@ -107,7 +107,12 @@ impl Stream { timeout, ); }) - .unwrap(); + .map_err(|e| { + Error::with_message( + ErrorKind::ResourceExhausted, + format!("Failed to create ALSA input worker thread: {e}"), + ) + })?; latch.add_thread(thread.thread().clone()); Self { @@ -150,7 +155,12 @@ impl Stream { timeout, ); }) - .unwrap(); + .map_err(|e| { + Error::with_message( + ErrorKind::ResourceExhausted, + format!("Failed to create ALSA output worker thread: {e}"), + ) + })?; latch.add_thread(thread.thread().clone()); Self { @@ -193,7 +203,12 @@ impl Stream { timeout, ); }) - .unwrap(); + .map_err(|e| { + Error::with_message( + ErrorKind::ResourceExhausted, + format!("Failed to create ALSA duplex worker thread: {e}"), + ) + })?; latch.add_thread(thread.thread().clone()); Self { diff --git a/src/host/wasapi/stream.rs b/src/host/wasapi/stream.rs index 94b05e205..ac3b7f239 100644 --- a/src/host/wasapi/stream.rs +++ b/src/host/wasapi/stream.rs @@ -379,7 +379,7 @@ impl Stream { .map_err(|e| { Error::with_message( ErrorKind::ResourceExhausted, - format!("Failed to create audio thread: {e}"), + format!("Failed to create WASAPI input worker thread: {e}"), ) })?; @@ -455,7 +455,7 @@ impl Stream { .map_err(|e| { Error::with_message( ErrorKind::ResourceExhausted, - format!("Failed to create audio thread: {e}"), + format!("Failed to create WASAPI output worker thread: {e}"), ) })?; From 0e9d09e31b211cb17855ad38e27f3b21660564b8 Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Mon, 26 Oct 2026 20:40:52 +0000 Subject: [PATCH 28/35] fix making alsa worker thread spawning falliable by return a Result --- src/host/alsa/device.rs | 18 +++++++++--------- src/host/alsa/stream.rs | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/host/alsa/device.rs b/src/host/alsa/device.rs index 77e283498..bb61db3cf 100644 --- a/src/host/alsa/device.rs +++ b/src/host/alsa/device.rs @@ -105,13 +105,13 @@ impl DeviceTrait for Device { let data_callback = crate::host::monotonic_input_callback(data_callback); let stream_inner = self.build_stream_inner(conf, sample_format, alsa::Direction::Capture)?; - let stream = Self::Stream::new_input( + + Self::Stream::new_input( Arc::new(stream_inner), data_callback, error_callback, timeout, - ); - Ok(stream) + ) } fn build_output_stream_raw( @@ -131,13 +131,13 @@ impl DeviceTrait for Device { let data_callback = crate::host::monotonic_output_callback(data_callback); let stream_inner = self.build_stream_inner(conf, sample_format, alsa::Direction::Playback)?; - let stream = Self::Stream::new_output( + + Self::Stream::new_output( Arc::new(stream_inner), data_callback, error_callback, timeout, - ); - Ok(stream) + ) } fn build_duplex_stream_raw( @@ -155,13 +155,13 @@ impl DeviceTrait for Device { { let stream_inner = self.build_duplex_stream_inner(config, input_sample_format, output_sample_format)?; - let stream = Self::Stream::new_duplex( + + Self::Stream::new_duplex( Arc::new(stream_inner), data_callback, error_callback, timeout, - ); - Ok(stream) + ) } } diff --git a/src/host/alsa/stream.rs b/src/host/alsa/stream.rs index f2a2009ef..f8a21d7af 100644 --- a/src/host/alsa/stream.rs +++ b/src/host/alsa/stream.rs @@ -81,7 +81,7 @@ impl Stream { mut data_callback: D, mut error_callback: E, timeout: Option, - ) -> Stream + ) -> Result where D: FnMut(&Data, &CallbackInfo) + Send + 'static, E: FnMut(Error) + Send + 'static, @@ -115,13 +115,13 @@ impl Stream { })?; latch.add_thread(thread.thread().clone()); - Self { + Ok(Self { thread: Some(thread), kind: StreamKind::Single(inner), trigger: tx, _rx: rx, latch, - } + }) } pub(super) fn new_output( @@ -129,7 +129,7 @@ impl Stream { mut data_callback: D, mut error_callback: E, timeout: Option, - ) -> Stream + ) -> Result where D: FnMut(&mut Data, &CallbackInfo) + Send + 'static, E: FnMut(Error) + Send + 'static, @@ -163,13 +163,13 @@ impl Stream { })?; latch.add_thread(thread.thread().clone()); - Self { + Ok(Self { thread: Some(thread), kind: StreamKind::Single(inner), trigger: tx, _rx: rx, latch, - } + }) } pub(super) fn new_duplex( @@ -177,7 +177,7 @@ impl Stream { mut data_callback: D, mut error_callback: E, timeout: Option, - ) -> Stream + ) -> Result where D: FnMut(&Data, &mut Data, &DuplexCallbackInfo) + Send + 'static, E: FnMut(Error) + Send + 'static, @@ -211,13 +211,13 @@ impl Stream { })?; latch.add_thread(thread.thread().clone()); - Self { + Ok(Self { thread: Some(thread), kind: StreamKind::Duplex(inner), trigger: tx, _rx: rx, latch, - } + }) } fn suspend_pcm(&self, inner: &StreamInner) -> Result<(), Error> { From 6aab12f8e212dfea5780d0e1366abbe0f76764b8 Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Mon, 26 Oct 2026 20:42:52 +0000 Subject: [PATCH 29/35] bring ErrorKind into scope --- src/host/alsa/stream.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/host/alsa/stream.rs b/src/host/alsa/stream.rs index f8a21d7af..ef508cd7d 100644 --- a/src/host/alsa/stream.rs +++ b/src/host/alsa/stream.rs @@ -6,7 +6,7 @@ use super::{ worker::{input_stream_worker, output_stream_worker}, }; use crate::{ - CallbackInfo, Data, DeviceDirection, DuplexCallbackInfo, Error, FrameCount, SampleFormat, + CallbackInfo, Data, DeviceDirection, DuplexCallbackInfo, Error, ErrorKind, FrameCount, SampleFormat, SampleRate, StreamInstant, host::{ Notify, From 2c2ad8daa8addadb9fdac128ce2baa1fb70f72cc Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Mon, 26 Oct 2026 20:44:39 +0000 Subject: [PATCH 30/35] cargo fmt --- src/host/alsa/stream.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/host/alsa/stream.rs b/src/host/alsa/stream.rs index ef508cd7d..652397a86 100644 --- a/src/host/alsa/stream.rs +++ b/src/host/alsa/stream.rs @@ -6,8 +6,8 @@ use super::{ worker::{input_stream_worker, output_stream_worker}, }; use crate::{ - CallbackInfo, Data, DeviceDirection, DuplexCallbackInfo, Error, ErrorKind, FrameCount, SampleFormat, - SampleRate, StreamInstant, + CallbackInfo, Data, DeviceDirection, DuplexCallbackInfo, Error, ErrorKind, FrameCount, + SampleFormat, SampleRate, StreamInstant, host::{ Notify, equilibrium::{DSD_EQUILIBRIUM_BYTE, U8_EQUILIBRIUM_BYTE, fill_equilibrium}, From 08230e7aaeed4e0e1f8d9378e91c0446b5413a1e Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Tue, 27 Oct 2026 20:53:31 +0000 Subject: [PATCH 31/35] revert DeviceNotAvailable renaming --- CHANGELOG.md | 1 - src/error.rs | 16 ++--- src/host.rs | 2 +- src/host/aaudio/convert.rs | 2 +- src/host/alsa.rs | 2 +- src/host/alsa/device.rs | 8 +-- src/host/alsa/duplex.rs | 6 +- src/host/alsa/worker.rs | 8 +-- src/host/asio/stream.rs | 8 +-- src/host/audioworklet.rs | 12 ++-- src/host/coreaudio.rs | 2 +- .../coreaudio/ios/session_event_manager.rs | 4 +- src/host/coreaudio/macos.rs | 8 +-- src/host/coreaudio/macos/device.rs | 2 +- src/host/coreaudio/macos/format.rs | 4 +- src/host/coreaudio/macos/loopback.rs | 2 +- src/host/jack.rs | 12 ++-- src/host/jack/device.rs | 2 +- src/host/jack/stream.rs | 4 +- src/host/pipewire/device.rs | 2 +- src/host/pipewire/stream.rs | 8 +-- src/host/pulseaudio.rs | 6 +- src/host/wasapi.rs | 2 +- src/host/wasapi/device.rs | 6 +- src/host/wasapi/stream.rs | 2 +- src/host/webaudio.rs | 16 ++--- src/traits.rs | 68 +++++++++---------- 27 files changed, 107 insertions(+), 108 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd8a252a9..e072bdc84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,7 +26,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Normalized thread and client naming across all backends. - `DeviceTrait` and `StreamTrait` now require `Send + Sync` as supertrait bounds. - `StreamTrait::play` is renamed to `start`. -- `DeviceNotAvailable` is renamed to `DeviceUnavailable`. - `InputCallbackInfo`/`OutputCallbackInfo` merged into `CallbackInfo`. - `InputStreamTimestamp`/`OutputStreamTimestamp` merged into `StreamTimestamp`; `capture`/`playback` renamed `device`. - `StreamInstant` creation is now `const`. diff --git a/src/error.rs b/src/error.rs index 0e7bd68b3..4f6ddb396 100644 --- a/src/error.rs +++ b/src/error.rs @@ -17,23 +17,23 @@ pub enum ErrorKind { /// /// Only fires for a stream built from the default device, on backends that support following /// it. A stream built from a specific device does not follow a replacement; if that device - /// disappears, it reports [`DeviceUnavailable`] instead. + /// disappears, it reports [`DeviceNotAvailable`] instead. /// - /// [`DeviceUnavailable`]: ErrorKind::DeviceUnavailable + /// [`DeviceNotAvailable`]: ErrorKind::DeviceNotAvailable DeviceChanged, /// The requested audio device is not available. /// /// This can happen if the device has been disconnected while the program is running, or if /// the device identifier refers to a device that does not exist on this system. - DeviceUnavailable, + DeviceNotAvailable, /// The audio host (server or subsystem) is not available on this system. /// - /// This is distinct from [`DeviceUnavailable`]: when a host (e.g. PulseAudio, PipeWire, JACK, + /// This is distinct from [`DeviceNotAvailable`]: when a host (e.g. PulseAudio, PipeWire, JACK, /// or kernel subsystem) is absent or not running, no devices can be reached through it. /// - /// [`DeviceUnavailable`]: ErrorKind::DeviceUnavailable + /// [`DeviceNotAvailable`]: ErrorKind::DeviceNotAvailable HostUnavailable, /// Invalid input or argument. @@ -45,10 +45,10 @@ pub enum ErrorKind { /// permission to use it. Common causes include microphone privacy settings (iOS, macOS), /// missing audio group membership (Linux), or file permission errors. /// - /// Unlike [`DeviceUnavailable`], which signals absence, this variant signals an + /// Unlike [`DeviceNotAvailable`], which signals absence, this variant signals an /// authorization failure. /// - /// [`DeviceUnavailable`]: ErrorKind::DeviceUnavailable + /// [`DeviceNotAvailable`]: ErrorKind::DeviceNotAvailable PermissionDenied, /// A real-time scheduling promotion or equivalent platform performance mode was refused. @@ -97,7 +97,7 @@ impl Display for ErrorKind { Self::DeviceChanged => f.write_str( "The audio route changed. The stream was automatically rerouted to a different device.", ), - Self::DeviceUnavailable => f.write_str( + Self::DeviceNotAvailable => f.write_str( "The requested audio device is not available. It may have been disconnected.", ), Self::HostUnavailable => f.write_str( diff --git a/src/host.rs b/src/host.rs index e3a629de1..8c9b635fb 100644 --- a/src/host.rs +++ b/src/host.rs @@ -394,7 +394,7 @@ pub(crate) fn get_user_media_error(js_err: &wasm_bindgen::JsValue) -> crate::Err let kind = match name.as_deref() { Some("NotAllowedError" | "SecurityError") => ErrorKind::PermissionDenied, - Some("NotFoundError") => ErrorKind::DeviceUnavailable, + Some("NotFoundError") => ErrorKind::DeviceNotAvailable, Some("OverconstrainedError") => ErrorKind::UnsupportedConfig, Some("NotReadableError") => ErrorKind::DeviceBusy, Some("TypeError") => ErrorKind::InvalidInput, diff --git a/src/host/aaudio/convert.rs b/src/host/aaudio/convert.rs index bed019ec1..1b2c496ff 100644 --- a/src/host/aaudio/convert.rs +++ b/src/host/aaudio/convert.rs @@ -57,7 +57,7 @@ impl From for Error { fn from(error: ndk::audio::AudioError) -> Self { use ndk::audio::AudioError::*; let kind = match error { - Disconnected | Unavailable | NoService | InvalidHandle => ErrorKind::DeviceUnavailable, + Disconnected | Unavailable | NoService | InvalidHandle => ErrorKind::DeviceNotAvailable, NoFreeHandles | NoMemory => ErrorKind::ResourceExhausted, WouldBlock | Timeout => ErrorKind::DeviceBusy, InvalidFormat | InvalidRate => ErrorKind::UnsupportedConfig, diff --git a/src/host/alsa.rs b/src/host/alsa.rs index 78545b3fd..bf6d201b0 100644 --- a/src/host/alsa.rs +++ b/src/host/alsa.rs @@ -222,7 +222,7 @@ fn canonical_pcm_id(pcm_id: &str) -> String { impl From for Error { fn from(err: alsa::Error) -> Self { match err.errno() { - libc::ENODEV | libc::ENOENT | LIBC_ENOTSUPP => ErrorKind::DeviceUnavailable.into(), + libc::ENODEV | libc::ENOENT | LIBC_ENOTSUPP => ErrorKind::DeviceNotAvailable.into(), libc::EPERM | libc::EACCES => ErrorKind::PermissionDenied.into(), libc::EBUSY | libc::EAGAIN => ErrorKind::DeviceBusy.into(), libc::EINVAL => ErrorKind::UnsupportedConfig.into(), diff --git a/src/host/alsa/device.rs b/src/host/alsa/device.rs index bb61db3cf..771ef862a 100644 --- a/src/host/alsa/device.rs +++ b/src/host/alsa/device.rs @@ -183,13 +183,13 @@ impl Device { }; let (buffer_size, period_size) = set_sw_params_from_format(&handle, start_threshold)?; if buffer_size == 0 || period_size == 0 { - return Err(ErrorKind::DeviceUnavailable.into()); + return Err(ErrorKind::DeviceNotAvailable.into()); } handle.prepare()?; if handle.count() == 0 { - return Err(ErrorKind::DeviceUnavailable.into()); + return Err(ErrorKind::DeviceNotAvailable.into()); } let (creation_ts, timestamp_mode) = creation_timestamp(&handle, hw_params)?; @@ -257,7 +257,7 @@ impl Device { || playback_buffer_size == 0 || playback_period_size == 0 { - return Err(ErrorKind::DeviceUnavailable.into()); + return Err(ErrorKind::DeviceNotAvailable.into()); } // Duplex drives both directions from one worker cycle; period sizes must match. if capture_period_size != playback_period_size { @@ -273,7 +273,7 @@ impl Device { playback_handle.prepare()?; if capture_handle.count() == 0 || playback_handle.count() == 0 { - return Err(ErrorKind::DeviceUnavailable.into()); + return Err(ErrorKind::DeviceNotAvailable.into()); } let (capture_creation_ts, capture_timestamp_mode) = diff --git a/src/host/alsa/duplex.rs b/src/host/alsa/duplex.rs index eb4a423f7..d23d96e8a 100644 --- a/src/host/alsa/duplex.rs +++ b/src/host/alsa/duplex.rs @@ -95,7 +95,7 @@ pub(super) fn duplex_stream_worker( }; if let Err(err) = result { match err.kind() { - ErrorKind::DeviceUnavailable => { + ErrorKind::DeviceNotAvailable => { error_callback(err); stream.control.signal_worker_exit(); return; @@ -254,7 +254,7 @@ fn poll_for_duplex_period( match handle.state() { alsa::pcm::State::Disconnected => { return Err(Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Device disconnected", )); } @@ -288,7 +288,7 @@ fn poll_for_duplex_period( || playback_revents.intersects(alsa::poll::Flags::HUP | alsa::poll::Flags::NVAL) { return Err(Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Device disconnected", )); } diff --git a/src/host/alsa/worker.rs b/src/host/alsa/worker.rs index 69e176a67..ff257b204 100644 --- a/src/host/alsa/worker.rs +++ b/src/host/alsa/worker.rs @@ -57,7 +57,7 @@ pub(super) fn input_stream_worker( }; if let Err(err) = result { match err.kind() { - ErrorKind::DeviceUnavailable => { + ErrorKind::DeviceNotAvailable => { error_callback(err); stream.control.signal_worker_exit(); return; @@ -112,7 +112,7 @@ pub(super) fn output_stream_worker( }; if let Err(err) = result { match err.kind() { - ErrorKind::DeviceUnavailable => { + ErrorKind::DeviceNotAvailable => { error_callback(err); stream.control.signal_worker_exit(); return; @@ -242,7 +242,7 @@ fn poll_for_period( match stream.handle.state() { alsa::pcm::State::Disconnected => { return Err(Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Device disconnected", )); } @@ -274,7 +274,7 @@ fn poll_for_period( // POLLHUP/POLLNVAL: the device has been disconnected. if revents.intersects(alsa::poll::Flags::HUP | alsa::poll::Flags::NVAL) { return Err(Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Device disconnected", )); } diff --git a/src/host/asio/stream.rs b/src/host/asio/stream.rs index 20c1224b0..3c1b07828 100644 --- a/src/host/asio/stream.rs +++ b/src/host/asio/stream.rs @@ -149,7 +149,7 @@ impl Device { .get() .ok_or_else(|| { Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "ASIO driver is not initialized", ) })? @@ -507,7 +507,7 @@ impl Device { .get() .ok_or_else(|| { Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "ASIO driver is not initialized", ) })? @@ -1306,7 +1306,7 @@ unsafe fn asio_channel_slice_mut( fn load_driver_err(e: sys::LoadDriverError) -> Error { match e { sys::LoadDriverError::LoadDriverFailed | sys::LoadDriverError::DriverAlreadyExists => { - Error::with_message(ErrorKind::DeviceUnavailable, e.to_string()) + Error::with_message(ErrorKind::DeviceNotAvailable, e.to_string()) } sys::LoadDriverError::InitializationFailed(asio_err) => build_stream_err(asio_err), } @@ -1315,7 +1315,7 @@ fn load_driver_err(e: sys::LoadDriverError) -> Error { fn build_stream_err(e: sys::AsioError) -> Error { match e { sys::AsioError::NoDrivers | sys::AsioError::HardwareMalfunction => { - Error::with_message(ErrorKind::DeviceUnavailable, e.to_string()) + Error::with_message(ErrorKind::DeviceNotAvailable, e.to_string()) } sys::AsioError::InvalidInput | sys::AsioError::BadMode => { Error::with_message(ErrorKind::InvalidInput, e.to_string()) diff --git a/src/host/audioworklet.rs b/src/host/audioworklet.rs index 0a2e480f0..d10048210 100644 --- a/src/host/audioworklet.rs +++ b/src/host/audioworklet.rs @@ -521,7 +521,7 @@ impl DeviceTrait for Device { Command::Play => { if audio_context.resume().is_err() { (error_callback.borrow_mut())(Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Failed to resume audio context", )); } @@ -529,7 +529,7 @@ impl DeviceTrait for Device { Command::Pause => { if audio_context.suspend().is_err() { (error_callback.borrow_mut())(Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Failed to suspend audio context", )); } @@ -760,7 +760,7 @@ impl DeviceTrait for Device { Command::Play => { if audio_context.resume().is_err() { (error_callback.borrow_mut())(Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Failed to resume audio context", )); } @@ -768,7 +768,7 @@ impl DeviceTrait for Device { Command::Pause => { if audio_context.suspend().is_err() { (error_callback.borrow_mut())(Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Failed to suspend audio context", )); } @@ -1049,7 +1049,7 @@ impl DeviceTrait for Device { Command::Play => { if audio_context.resume().is_err() { (error_callback.borrow_mut())(Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Failed to resume audio context", )); } @@ -1057,7 +1057,7 @@ impl DeviceTrait for Device { Command::Pause => { if audio_context.suspend().is_err() { (error_callback.borrow_mut())(Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Failed to suspend audio context", )); } diff --git a/src/host/coreaudio.rs b/src/host/coreaudio.rs index 8ce8c660c..730bc7240 100644 --- a/src/host/coreaudio.rs +++ b/src/host/coreaudio.rs @@ -108,7 +108,7 @@ impl From for Error { | coreaudio::Error::AudioUnit(AudioUnitError::NoConnection) | coreaudio::Error::AudioUnit(AudioUnitError::FailedInitialization) | coreaudio::Error::Audio(AudioError::FileNotFound) => { - Error::with_message(ErrorKind::DeviceUnavailable, msg) + Error::with_message(ErrorKind::DeviceNotAvailable, msg) } coreaudio::Error::AudioUnit(AudioUnitError::Unauthorized) diff --git a/src/host/coreaudio/ios/session_event_manager.rs b/src/host/coreaudio/ios/session_event_manager.rs index 467ccfe5e..1ca497966 100644 --- a/src/host/coreaudio/ios/session_event_manager.rs +++ b/src/host/coreaudio/ios/session_event_manager.rs @@ -62,7 +62,7 @@ fn route_change_error(notification: &NSNotification) -> Option { )), AVAudioSessionRouteChangeReason::NoSuitableRouteForCategory => Some(Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "No suitable audio route for the session category", )), @@ -166,7 +166,7 @@ impl SessionEventManager { emit_error( &cb, Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Audio media services were lost", ), ); diff --git a/src/host/coreaudio/macos.rs b/src/host/coreaudio/macos.rs index 20affa2cf..77f1f58c1 100644 --- a/src/host/coreaudio/macos.rs +++ b/src/host/coreaudio/macos.rs @@ -220,7 +220,7 @@ pub(super) trait Monitor: Send + Sync { /// /// When a device disconnects, this manager: /// 1. Attempts to pause the stream to stop audio I/O -/// 2. Calls the error callback with `ErrorKind::DeviceUnavailable` +/// 2. Calls the error callback with `ErrorKind::DeviceNotAvailable` /// /// The dedicated thread architecture ensures `Stream` can implement `Send`. struct DisconnectManager { @@ -251,7 +251,7 @@ impl DisconnectManager { device_address(kAudioDevicePropertyDeviceIsAlive), move || { let _ = disconnect_tx_alive.send(MonitorEvent::Lost(Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Device disconnected", ))); }, @@ -339,7 +339,7 @@ impl Monitor for DisconnectManager { /// /// When the system default output device changes: /// - If a new valid default exists, AudioUnit reroutes and `DeviceChanged` is reported. -/// - If there is no new default, the stream is paused and `DeviceUnavailable` is reported. +/// - If there is no new default, the stream is paused and `DeviceNotAvailable` is reported. struct DefaultOutputMonitor { latch: Latch, _shutdown_tx: mpsc::Sender<()>, @@ -454,7 +454,7 @@ impl DefaultOutputMonitor { stream, &error_callback, Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "no default output device", ), ); diff --git a/src/host/coreaudio/macos/device.rs b/src/host/coreaudio/macos/device.rs index d9529d4ff..7e489567a 100644 --- a/src/host/coreaudio/macos/device.rs +++ b/src/host/coreaudio/macos/device.rs @@ -307,7 +307,7 @@ impl Device { uid_string, )) } else { - Err(ErrorKind::DeviceUnavailable.into()) + Err(ErrorKind::DeviceNotAvailable.into()) } } diff --git a/src/host/coreaudio/macos/format.rs b/src/host/coreaudio/macos/format.rs index 3e625b3de..9b9cb509a 100644 --- a/src/host/coreaudio/macos/format.rs +++ b/src/host/coreaudio/macos/format.rs @@ -275,7 +275,7 @@ fn wait_for_property( ) -> Result<(), Error> { let timed_out = || { Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, format!("Timed out waiting for the {what} to change"), ) }; @@ -300,7 +300,7 @@ fn wait_for_property( } Ok(PropertyEvent::Unavailable) => { return Err(Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, format!("Device disconnected while updating the {what}"), )); } diff --git a/src/host/coreaudio/macos/loopback.rs b/src/host/coreaudio/macos/loopback.rs index e972e86c2..1029cc34d 100644 --- a/src/host/coreaudio/macos/loopback.rs +++ b/src/host/coreaudio/macos/loopback.rs @@ -53,7 +53,7 @@ impl Device { check_os_status(status)?; if cfstring.is_null() { - return Err(ErrorKind::DeviceUnavailable.into()); + return Err(ErrorKind::DeviceNotAvailable.into()); } let ns_string: Retained = unsafe { diff --git a/src/host/jack.rs b/src/host/jack.rs index 16fa239e1..42f5fa1da 100644 --- a/src/host/jack.rs +++ b/src/host/jack.rs @@ -182,7 +182,7 @@ impl From for Error { | jack::Error::ClientDeactivationError | jack::Error::LibraryError(_) | jack::Error::WeakFunctionNotFound(_) - | jack::Error::RingbufferCreateFailed => ErrorKind::DeviceUnavailable, + | jack::Error::RingbufferCreateFailed => ErrorKind::DeviceNotAvailable, jack::Error::ClientIsNoLongerAlive | jack::Error::ClientPanicked => { ErrorKind::StreamInvalidated @@ -214,27 +214,27 @@ fn get_client(name: &str, client_options: jack::ClientOptions) -> Result Result<(), Er let _ = client.disconnect_ports_by_name(prev_from, prev_to); } return Err(Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, format!("JACK failed to connect port '{from}' to '{to}': {e}"), )); } @@ -739,7 +739,7 @@ impl jack::NotificationHandler for JackNotificationHandler { emit_error( &self.error_callback_ptr, Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, format!("JACK server shut down: {reason}"), ), ); diff --git a/src/host/pipewire/device.rs b/src/host/pipewire/device.rs index 0a163030a..c014ca37a 100644 --- a/src/host/pipewire/device.rs +++ b/src/host/pipewire/device.rs @@ -762,7 +762,7 @@ fn recv_init( received.unwrap_or_else(|err| { Err(match err { mpsc::RecvTimeoutError::Timeout => { - Error::with_message(ErrorKind::DeviceUnavailable, "PipeWire timed out") + Error::with_message(ErrorKind::DeviceNotAvailable, "PipeWire timed out") } mpsc::RecvTimeoutError::Disconnected => Error::with_message( ErrorKind::BackendError, diff --git a/src/host/pipewire/stream.rs b/src/host/pipewire/stream.rs index 32e5d91fb..cb4d22fb0 100644 --- a/src/host/pipewire/stream.rs +++ b/src/host/pipewire/stream.rs @@ -335,7 +335,7 @@ impl UserData { { emit_error( &self.error_callback, - Error::with_message(ErrorKind::DeviceUnavailable, "Device disconnected"), + Error::with_message(ErrorKind::DeviceNotAvailable, "Device disconnected"), ); } } @@ -591,7 +591,7 @@ pub(super) fn watch_default_device( emit_error( &error_callback_cb, Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "default device removed", ), ); @@ -611,7 +611,7 @@ pub(super) fn watch_default_device( } /// Watches the registry for the node going away, and fires `error_callback` with -/// [`ErrorKind::DeviceUnavailable`] when it does. +/// [`ErrorKind::DeviceNotAvailable`] when it does. /// /// The watch lasts as long as the returned listener is held. pub(super) fn watch_target_node( @@ -645,7 +645,7 @@ pub(super) fn watch_target_node( if node_id.get() == Some(id) && !invalidated.swap(true, Ordering::Relaxed) { emit_error( &error_callback, - Error::with_message(ErrorKind::DeviceUnavailable, "Device disconnected"), + Error::with_message(ErrorKind::DeviceNotAvailable, "Device disconnected"), ); } }) diff --git a/src/host/pulseaudio.rs b/src/host/pulseaudio.rs index 4ac6fc35a..c82346fd8 100644 --- a/src/host/pulseaudio.rs +++ b/src/host/pulseaudio.rs @@ -85,7 +85,7 @@ impl From for Error { match e { AccessDenied | AuthKey => ErrorKind::PermissionDenied, ConnectionRefused | InvalidServer | ModInitFailed => ErrorKind::HostUnavailable, - NoEntity => ErrorKind::DeviceUnavailable, + NoEntity => ErrorKind::DeviceNotAvailable, Timeout | Busy => ErrorKind::DeviceBusy, NotSupported | Obsolete | NotImplemented | Version | NoExtension => { ErrorKind::UnsupportedOperation @@ -393,7 +393,7 @@ impl DeviceTrait for Device { match rx.recv_timeout(dur) { Ok(result) => result, Err(_) => Err(Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Stream creation timed out", )), } @@ -488,7 +488,7 @@ impl DeviceTrait for Device { match rx.recv_timeout(dur) { Ok(result) => result, Err(_) => Err(Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Stream creation timed out", )), } diff --git a/src/host/wasapi.rs b/src/host/wasapi.rs index 72ce443e6..999d1ab86 100644 --- a/src/host/wasapi.rs +++ b/src/host/wasapi.rs @@ -66,7 +66,7 @@ impl From for Error { Audio::AUDCLNT_E_SERVICE_NOT_RUNNING => ErrorKind::HostUnavailable, Audio::AUDCLNT_E_DEVICE_INVALIDATED | Audio::AUDCLNT_E_ENDPOINT_CREATE_FAILED => { - ErrorKind::DeviceUnavailable + ErrorKind::DeviceNotAvailable } Audio::AUDCLNT_E_DEVICE_IN_USE => ErrorKind::DeviceBusy, diff --git a/src/host/wasapi/device.rs b/src/host/wasapi/device.rs index 41ba3c00e..85290fe85 100644 --- a/src/host/wasapi/device.rs +++ b/src/host/wasapi/device.rs @@ -414,7 +414,7 @@ unsafe fn activate_audio_interface_sync( impl Device { pub fn description(&self) -> Result { let device = self.immdevice().ok_or_else(|| { - Error::with_message(ErrorKind::DeviceUnavailable, "Default device not found") + Error::with_message(ErrorKind::DeviceNotAvailable, "Default device not found") })?; unsafe { // Open the device's property store. @@ -456,7 +456,7 @@ impl Device { // Prefer FriendlyName for name (e.g., "Speakers (XYZ Audio Adapter)"), fall back to DeviceDesc let name = friendly_name.or(device_desc).ok_or_else(|| { Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Failed to retrieve device name", ) })?; @@ -502,7 +502,7 @@ impl Device { fn id(&self) -> Result { let device = self.immdevice().ok_or_else(|| { - Error::with_message(ErrorKind::DeviceUnavailable, "Default device not found") + Error::with_message(ErrorKind::DeviceNotAvailable, "Default device not found") })?; unsafe { match device.GetId().map(ComString) { diff --git a/src/host/wasapi/stream.rs b/src/host/wasapi/stream.rs index ac3b7f239..b62f35ee9 100644 --- a/src/host/wasapi/stream.rs +++ b/src/host/wasapi/stream.rs @@ -831,7 +831,7 @@ fn boost_current_thread_priority( fn default_device_change_error(flow: Option) -> Error { match flow.and_then(get_current_default) { - None => ErrorKind::DeviceUnavailable.into(), + None => ErrorKind::DeviceNotAvailable.into(), Some(_) => ErrorKind::DeviceChanged.into(), } } diff --git a/src/host/webaudio.rs b/src/host/webaudio.rs index da7cd289d..ca8363da3 100644 --- a/src/host/webaudio.rs +++ b/src/host/webaudio.rs @@ -509,7 +509,7 @@ impl DeviceTrait for Device { if ctx_task.resume().is_err() { error_callback.lock().unwrap_or_else(|e| e.into_inner())( Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Failed to resume audio context", ), ); @@ -519,7 +519,7 @@ impl DeviceTrait for Device { if ctx_task.suspend().is_err() { error_callback.lock().unwrap_or_else(|e| e.into_inner())( Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Failed to suspend audio context", ), ); @@ -921,7 +921,7 @@ impl DeviceTrait for Device { if ctx.resume().is_err() { error_callback.lock().unwrap_or_else(|e| e.into_inner())( Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Failed to resume audio context", ), ); @@ -939,7 +939,7 @@ impl DeviceTrait for Device { if ctx.suspend().is_err() { error_callback.lock().unwrap_or_else(|e| e.into_inner())( Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Failed to suspend audio context", ), ); @@ -1296,7 +1296,7 @@ impl DeviceTrait for Device { if ctx_task.resume().is_err() { error_callback.lock().unwrap_or_else(|e| e.into_inner())( Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Failed to resume audio context", ), ); @@ -1306,7 +1306,7 @@ impl DeviceTrait for Device { if ctx_task.suspend().is_err() { error_callback.lock().unwrap_or_else(|e| e.into_inner())( Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Failed to suspend audio context", ), ); @@ -1380,7 +1380,7 @@ impl StreamTrait for Stream { Ok(()) } Err(_) => Err(Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Failed to resume audio context", )), } @@ -1400,7 +1400,7 @@ impl StreamTrait for Stream { match self.ctx.suspend() { Ok(_) => Ok(()), Err(_) => Err(Error::with_message( - ErrorKind::DeviceUnavailable, + ErrorKind::DeviceNotAvailable, "Failed to suspend audio context", )), } diff --git a/src/traits.rs b/src/traits.rs index a4db006f0..beeff09d2 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -77,11 +77,11 @@ pub trait HostTrait { /// /// Some backends reroute a stream built from this device to the new default device when it /// changes; capture continues there, and [`ErrorKind::DeviceChanged`] is reported. Other - /// backends report [`ErrorKind::DeviceUnavailable`] instead, and the caller must rebuild the + /// backends report [`ErrorKind::DeviceNotAvailable`] instead, and the caller must rebuild the /// stream. /// /// [`ErrorKind::DeviceChanged`]: crate::ErrorKind::DeviceChanged - /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable + /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable fn default_input_device(&self) -> Option; /// The default output audio device on the system. @@ -90,11 +90,11 @@ pub trait HostTrait { /// /// Some backends reroute a stream built from this device to the new default device when it /// changes; playback continues there, and [`ErrorKind::DeviceChanged`] is reported. Other - /// backends report [`ErrorKind::DeviceUnavailable`] instead, and the caller must rebuild the + /// backends report [`ErrorKind::DeviceNotAvailable`] instead, and the caller must rebuild the /// stream. /// /// [`ErrorKind::DeviceChanged`]: crate::ErrorKind::DeviceChanged - /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable + /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable fn default_output_device(&self) -> Option; /// An iterator yielding all `Device`s currently available to the system that support one or more @@ -150,9 +150,9 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// /// # Errors /// - /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. /// - /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable + /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable fn description(&self) -> Result; /// The ID of the device. @@ -162,9 +162,9 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// /// # Errors /// - /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. /// - /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable + /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable fn id(&self) -> Result; /// True if the device supports audio input, otherwise false @@ -192,12 +192,12 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// /// # Errors /// - /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. /// - [`ErrorKind::UnsupportedConfig`] if the backend could not determine what the device /// supports. /// - [`ErrorKind::UnsupportedOperation`] if the device does not support input. /// - /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable + /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable /// [`ErrorKind::UnsupportedConfig`]: crate::ErrorKind::UnsupportedConfig /// [`ErrorKind::UnsupportedOperation`]: crate::ErrorKind::UnsupportedOperation fn supported_input_configs(&self) -> Result; @@ -206,12 +206,12 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// /// # Errors /// - /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. /// - [`ErrorKind::UnsupportedConfig`] if the backend could not determine what the device /// supports. /// - [`ErrorKind::UnsupportedOperation`] if the device does not support output. /// - /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable + /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable /// [`ErrorKind::UnsupportedConfig`]: crate::ErrorKind::UnsupportedConfig /// [`ErrorKind::UnsupportedOperation`]: crate::ErrorKind::UnsupportedOperation fn supported_output_configs(&self) -> Result; @@ -220,11 +220,11 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// /// # Errors /// - /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. /// - [`ErrorKind::UnsupportedConfig`] if the device has no default input configuration. /// - [`ErrorKind::UnsupportedOperation`] if the device does not support input. /// - /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable + /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable /// [`ErrorKind::UnsupportedConfig`]: crate::ErrorKind::UnsupportedConfig /// [`ErrorKind::UnsupportedOperation`]: crate::ErrorKind::UnsupportedOperation fn default_input_config(&self) -> Result; @@ -233,11 +233,11 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// /// # Errors /// - /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. /// - [`ErrorKind::UnsupportedConfig`] if the device has no default output configuration. /// - [`ErrorKind::UnsupportedOperation`] if the device does not support output. /// - /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable + /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable /// [`ErrorKind::UnsupportedConfig`]: crate::ErrorKind::UnsupportedConfig /// [`ErrorKind::UnsupportedOperation`]: crate::ErrorKind::UnsupportedOperation fn default_output_config(&self) -> Result; @@ -257,12 +257,12 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// /// # Errors /// - /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. /// - [`ErrorKind::UnsupportedConfig`] if no sample rate is supported by both directions. /// - [`ErrorKind::UnsupportedOperation`] if the host or device does not support duplex /// streams. /// - /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable + /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable /// [`ErrorKind::UnsupportedConfig`]: crate::ErrorKind::UnsupportedConfig /// [`ErrorKind::UnsupportedOperation`]: crate::ErrorKind::UnsupportedOperation fn default_duplex_config(&self) -> Result { @@ -377,14 +377,14 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// - [`ErrorKind::UnsupportedConfig`] if the sample rate, channel count, buffer size, or /// sample format is not supported by the device. /// - [`ErrorKind::UnsupportedOperation`] if the device does not support input streams. - /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. /// - [`ErrorKind::DeviceBusy`] if the device is temporarily in use by another application. /// - [`ErrorKind::PermissionDenied`] if the process lacks permission to access the device. /// - [`ErrorKind::InvalidInput`] if the configuration parameters are invalid. /// /// [`ErrorKind::UnsupportedConfig`]: crate::ErrorKind::UnsupportedConfig /// [`ErrorKind::UnsupportedOperation`]: crate::ErrorKind::UnsupportedOperation - /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable + /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable /// [`ErrorKind::DeviceBusy`]: crate::ErrorKind::DeviceBusy /// [`ErrorKind::PermissionDenied`]: crate::ErrorKind::PermissionDenied /// [`ErrorKind::InvalidInput`]: crate::ErrorKind::InvalidInput @@ -435,14 +435,14 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// - [`ErrorKind::UnsupportedConfig`] if the sample rate, channel count, buffer size, or /// sample format is not supported by the device. /// - [`ErrorKind::UnsupportedOperation`] if the device does not support output streams. - /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. /// - [`ErrorKind::DeviceBusy`] if the device is temporarily in use by another application. /// - [`ErrorKind::PermissionDenied`] if the process lacks permission to access the device. /// - [`ErrorKind::InvalidInput`] if the configuration parameters are invalid. /// /// [`ErrorKind::UnsupportedConfig`]: crate::ErrorKind::UnsupportedConfig /// [`ErrorKind::UnsupportedOperation`]: crate::ErrorKind::UnsupportedOperation - /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable + /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable /// [`ErrorKind::DeviceBusy`]: crate::ErrorKind::DeviceBusy /// [`ErrorKind::PermissionDenied`]: crate::ErrorKind::PermissionDenied /// [`ErrorKind::InvalidInput`]: crate::ErrorKind::InvalidInput @@ -495,14 +495,14 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// - [`ErrorKind::UnsupportedConfig`] if the sample rate, channel count, buffer size, or /// sample format is not supported by the device. /// - [`ErrorKind::UnsupportedOperation`] if the device does not support input streams. - /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. /// - [`ErrorKind::DeviceBusy`] if the device is temporarily in use by another application. /// - [`ErrorKind::PermissionDenied`] if the process lacks permission to access the device. /// - [`ErrorKind::InvalidInput`] if the configuration parameters are invalid. /// /// [`ErrorKind::UnsupportedConfig`]: crate::ErrorKind::UnsupportedConfig /// [`ErrorKind::UnsupportedOperation`]: crate::ErrorKind::UnsupportedOperation - /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable + /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable /// [`ErrorKind::DeviceBusy`]: crate::ErrorKind::DeviceBusy /// [`ErrorKind::PermissionDenied`]: crate::ErrorKind::PermissionDenied /// [`ErrorKind::InvalidInput`]: crate::ErrorKind::InvalidInput @@ -542,14 +542,14 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// - [`ErrorKind::UnsupportedConfig`] if the sample rate, channel count, buffer size, or /// sample format is not supported by the device. /// - [`ErrorKind::UnsupportedOperation`] if the device does not support output streams. - /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. /// - [`ErrorKind::DeviceBusy`] if the device is temporarily in use by another application. /// - [`ErrorKind::PermissionDenied`] if the process lacks permission to access the device. /// - [`ErrorKind::InvalidInput`] if the configuration parameters are invalid. /// /// [`ErrorKind::UnsupportedConfig`]: crate::ErrorKind::UnsupportedConfig /// [`ErrorKind::UnsupportedOperation`]: crate::ErrorKind::UnsupportedOperation - /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable + /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable /// [`ErrorKind::DeviceBusy`]: crate::ErrorKind::DeviceBusy /// [`ErrorKind::PermissionDenied`]: crate::ErrorKind::PermissionDenied /// [`ErrorKind::InvalidInput`]: crate::ErrorKind::InvalidInput @@ -587,7 +587,7 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// streams. /// - [`ErrorKind::UnsupportedConfig`] if the sample rate, channel counts, buffer size, or /// sample format is not supported by the device. - /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. /// - [`ErrorKind::DeviceBusy`] if the device is temporarily in use by another application. /// - [`ErrorKind::PermissionDenied`] if the process lacks permission to access the device /// (e.g. microphone access on macOS). @@ -600,7 +600,7 @@ pub trait DeviceTrait: PartialEq + Eq + Hash + Debug + Display + Send + Sync { /// /// [`ErrorKind::UnsupportedOperation`]: crate::ErrorKind::UnsupportedOperation /// [`ErrorKind::UnsupportedConfig`]: crate::ErrorKind::UnsupportedConfig - /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable + /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable /// [`ErrorKind::DeviceBusy`]: crate::ErrorKind::DeviceBusy /// [`ErrorKind::PermissionDenied`]: crate::ErrorKind::PermissionDenied /// [`ErrorKind::InvalidInput`]: crate::ErrorKind::InvalidInput @@ -682,11 +682,11 @@ pub trait StreamTrait: Send + Sync { /// /// # Errors /// - /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. /// - [`ErrorKind::StreamInvalidated`] if the stream configuration has changed and the stream /// must be rebuilt. /// - /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable + /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable /// [`ErrorKind::StreamInvalidated`]: crate::ErrorKind::StreamInvalidated fn start(&self) -> Result<(), Error>; @@ -710,12 +710,12 @@ pub trait StreamTrait: Send + Sync { /// # Errors /// /// - [`ErrorKind::UnsupportedOperation`] if the backend does not support pausing this stream. - /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. /// - [`ErrorKind::StreamInvalidated`] if the stream configuration has changed and the stream /// must be rebuilt. /// /// [`ErrorKind::UnsupportedOperation`]: crate::ErrorKind::UnsupportedOperation - /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable + /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable /// [`ErrorKind::StreamInvalidated`]: crate::ErrorKind::StreamInvalidated fn pause(&self) -> Result<(), Error>; @@ -746,11 +746,11 @@ pub trait StreamTrait: Send + Sync { /// /// # Errors /// - /// - [`ErrorKind::DeviceUnavailable`] if the device has been disconnected. + /// - [`ErrorKind::DeviceNotAvailable`] if the device has been disconnected. /// - [`ErrorKind::StreamInvalidated`] if the stream configuration has changed and the stream /// must be rebuilt. /// - /// [`ErrorKind::DeviceUnavailable`]: crate::ErrorKind::DeviceUnavailable + /// [`ErrorKind::DeviceNotAvailable`]: crate::ErrorKind::DeviceNotAvailable /// [`ErrorKind::StreamInvalidated`]: crate::ErrorKind::StreamInvalidated fn stop(&self, timeout: Option) -> Result<(), Error>; From 85767cef09843a253065844807b3f9dfb3935d4b Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Wed, 28 Oct 2026 14:25:08 +0000 Subject: [PATCH 32/35] fix artifact from rebasing manually --- src/host.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/host.rs b/src/host.rs index 8c9b635fb..9c8c17811 100644 --- a/src/host.rs +++ b/src/host.rs @@ -227,7 +227,6 @@ pub(crate) use error_emit::try_emit_error; target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", - all(target_os = "windows", any(feature = "asio", feature = "jack",)), target_vendor = "apple", all(target_os = "windows", any(feature = "asio", feature = "jack")), all( From 9e2b2a427cf12017744a329d4243be58ad4823b4 Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Wed, 28 Oct 2026 14:45:05 +0000 Subject: [PATCH 33/35] consistently use "{text}" rather than "{}, text" everywhere (excluding asio-sys) --- examples/enumerate.rs | 8 +++----- src/host/aaudio.rs | 2 +- src/host/alsa/enumerate.rs | 4 ++-- src/host/webaudio.rs | 4 ++-- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/examples/enumerate.rs b/examples/enumerate.rs index 6e2680961..9135043cc 100644 --- a/examples/enumerate.rs +++ b/examples/enumerate.rs @@ -45,7 +45,7 @@ fn main() -> Result<(), anyhow::Error> { .id() .map_or("Unknown ID".to_string(), |id| id.to_string()); if let Ok(desc) = device.description() { - println!(" {}. {id} ({})", device_index + 1, desc); + println!(" {}. {id} ({desc})", device_index + 1); } else { println!(" {}. {id}", device_index + 1); } @@ -65,10 +65,9 @@ fn main() -> Result<(), anyhow::Error> { println!(" All supported input stream configs:"); for (config_index, config) in input_configs.into_iter().enumerate() { println!( - " {}.{}. {:?}", + " {}.{}. {config:?}", device_index + 1, config_index + 1, - config ); } } @@ -88,10 +87,9 @@ fn main() -> Result<(), anyhow::Error> { println!(" All supported output stream configs:"); for (config_index, config) in output_configs.into_iter().enumerate() { println!( - " {}.{}. {:?}", + " {}.{}. {config:?}", device_index + 1, config_index + 1, - config ); } } diff --git a/src/host/aaudio.rs b/src/host/aaudio.rs index faa2713d5..9f00560a5 100644 --- a/src/host/aaudio.rs +++ b/src/host/aaudio.rs @@ -578,7 +578,7 @@ impl DeviceTrait for Device { let device_type: DeviceType = info.device_type.into(); let name = match device_type { DeviceType::Unknown => info.product_name.clone(), - _ => format!("{} ({})", info.product_name, device_type), + _ => format!("{} ({device_type})", info.product_name), }; let mut builder = DeviceDescriptionBuilder::new(name) .device_type(device_type) diff --git a/src/host/alsa/enumerate.rs b/src/host/alsa/enumerate.rs index 2661b7fe3..4ad01ced9 100644 --- a/src/host/alsa/enumerate.rs +++ b/src/host/alsa/enumerate.rs @@ -80,7 +80,7 @@ impl Host { fn format_device_description(phys_dev: &PhysicalDevice, prefix: &str) -> String { // "Card Name, Device Name" or variations let first_line = match (&phys_dev.card_name, &phys_dev.device_name) { - (Some(card), Some(device)) => format!("{}, {}", card, device), + (Some(card), Some(device)) => format!("{card}, {device}"), (Some(card), None) => card.clone(), (None, Some(device)) => device.clone(), (None, None) => format!("Card {}", phys_dev.card_index), @@ -100,7 +100,7 @@ fn physical_devices() -> Vec { let mut devices = Vec::new(); for card in alsa::card::Iter::new().filter_map(Result::ok) { let card_index = card.get_index() as u32; - let ctl = match alsa::Ctl::new(&format!("{}:{}", HW_PREFIX, card_index), false) { + let ctl = match alsa::Ctl::new(&format!("{HW_PREFIX}:{card_index}"), false) { Ok(ctl) => ctl, Err(_) => continue, }; diff --git a/src/host/webaudio.rs b/src/host/webaudio.rs index ca8363da3..1388782c3 100644 --- a/src/host/webaudio.rs +++ b/src/host/webaudio.rs @@ -583,8 +583,8 @@ impl DeviceTrait for Device { Error::with_message( ErrorKind::UnsupportedConfig, format!( - "Buffer size {} * channel count {} overflows on this platform", - buffer_size_frames, config.channels + "Buffer size {buffer_size_frames} * channel count {} overflows on this platform", + config.channels ), ) })?; From c84b0790024f8a440cac5512d7dfde2f470cf2c8 Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Wed, 28 Oct 2026 15:09:36 +0000 Subject: [PATCH 34/35] remove unused unsafe Send/Sync for wasapi Devices (iter) --- src/host/wasapi/device.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/host/wasapi/device.rs b/src/host/wasapi/device.rs index 85290fe85..0b35ac0fd 100644 --- a/src/host/wasapi/device.rs +++ b/src/host/wasapi/device.rs @@ -1297,9 +1297,6 @@ impl Devices { } } -unsafe impl Send for Devices {} -unsafe impl Sync for Devices {} - impl Iterator for Devices { type Item = Device; From d6d77e14b1f065d562f58714baef2d367e94ba12 Mon Sep 17 00:00:00 2001 From: Marco Farruggio Date: Wed, 28 Oct 2026 15:32:17 +0000 Subject: [PATCH 35/35] revert removal of send/sync for Devices --- src/host/wasapi/device.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/host/wasapi/device.rs b/src/host/wasapi/device.rs index 0b35ac0fd..85290fe85 100644 --- a/src/host/wasapi/device.rs +++ b/src/host/wasapi/device.rs @@ -1297,6 +1297,9 @@ impl Devices { } } +unsafe impl Send for Devices {} +unsafe impl Sync for Devices {} + impl Iterator for Devices { type Item = Device;