Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
66714fe
rename DeviceNotAvailable to DeviceUnavailable globally, and updated …
Marco-Farruggio Oct 21, 2026
f3a172b
remove a legacy "extern crate"
Marco-Farruggio Oct 21, 2026
76a0ebe
normalize cpal-spawned thread naming convention
Marco-Farruggio Oct 21, 2026
cabc751
neaten up/remove duplicaton in ndk AudioError to cpal error conversion
Marco-Farruggio Oct 21, 2026
3ffb97b
move validate_duplex_config into duplex.rs (shared logic)
Marco-Farruggio Oct 23, 2026
2c2beb2
add "client" to sound server names
Marco-Farruggio Oct 23, 2026
85f68d5
cargo fmt
Marco-Farruggio Oct 23, 2026
a831ea9
add required funcs for validate_duplex_config
Marco-Farruggio Oct 23, 2026
4f05967
fix: call the right function to check for jack's sampleformat
Marco-Farruggio Oct 23, 2026
cc96c9c
cfg gate validate_duplex_config
Marco-Farruggio Oct 23, 2026
856a1db
fix unused imports
Marco-Farruggio Oct 23, 2026
aa8f10c
remove borrow
Marco-Farruggio Oct 23, 2026
1cf33c5
undo last and fix the actual error
Marco-Farruggio Oct 23, 2026
5af45e6
neaten up jack error to cpal error conversion
Marco-Farruggio Oct 23, 2026
dbd194a
add frames_to_duration back when needed
Marco-Farruggio Oct 23, 2026
26b2703
cargo fmt
Marco-Farruggio Oct 23, 2026
b8a60d2
remove unused try_emit_error on aaudio when not using the realtime fe…
Marco-Farruggio Oct 26, 2026
0ea6c81
remove all legacy extern crate syntax
Marco-Farruggio Oct 26, 2026
aba26b3
let cargo fmt rejig import ordering
Marco-Farruggio Oct 26, 2026
58317c5
fix doc comment for validate_duplex_config
Marco-Farruggio Oct 26, 2026
0d46344
remove a redundant std error being pulled into scope
Marco-Farruggio Oct 26, 2026
402eca9
shorten a linux thread name to <= 15chars
Marco-Farruggio Oct 26, 2026
79e8d77
shorten an alsa thread name to <= 15chars for linux
Marco-Farruggio Oct 26, 2026
6bab7ea
docs: add thread/client naming normalization to the changelog
Marco-Farruggio Oct 26, 2026
4b0fc3a
use "{text}", rather than "{}", text where applicable
Marco-Farruggio Oct 26, 2026
728f3d9
explicitely document which hosts don't support xrun detection, note: …
Marco-Farruggio Oct 26, 2026
6064133
consistently return specific errors with consistently styled messages…
Marco-Farruggio Oct 26, 2026
0e9d09e
fix making alsa worker thread spawning falliable by return a Result
Marco-Farruggio Oct 26, 2026
6aab12f
bring ErrorKind into scope
Marco-Farruggio Oct 26, 2026
2c2ad8d
cargo fmt
Marco-Farruggio Oct 26, 2026
08230e7
revert DeviceNotAvailable renaming
Marco-Farruggio Oct 27, 2026
85767ce
fix artifact from rebasing manually
Marco-Farruggio Oct 28, 2026
9e2b2a4
consistently use "{text}" rather than "{}, text" everywhere (excludin…
Marco-Farruggio Oct 28, 2026
c84b079
remove unused unsafe Send/Sync for wasapi Devices (iter)
Marco-Farruggio Oct 28, 2026
d6d77e1
revert removal of send/sync for Devices
Marco-Farruggio Oct 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
- `InputCallbackInfo`/`OutputCallbackInfo` merged into `CallbackInfo`.
Expand Down
8 changes: 3 additions & 5 deletions examples/enumerate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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
);
}
}
Expand All @@ -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
);
}
}
Expand Down
28 changes: 28 additions & 0 deletions src/duplex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,31 @@ pub struct DuplexStreamConfig {
/// The desired buffer size, in frames per callback.
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_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,
sample_rate: config.sample_rate,
buffer_size: config.buffer_size,
};
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)
}
1 change: 0 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ impl From<ErrorKind> for Error {
))]
impl From<audio_thread_priority::AudioThreadPriorityError> 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}")
Expand Down
2 changes: 1 addition & 1 deletion src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 4 additions & 3 deletions src/host/aaudio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ 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;

mod convert;
Expand Down Expand Up @@ -577,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)
Expand Down
36 changes: 12 additions & 24 deletions src/host/aaudio/convert.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -58,27 +56,17 @@ pub fn input_stream_instant(stream: &ndk::audio::AudioStream, sample_rate: u32)
impl From<ndk::audio::AudioError> for Error {
fn from(error: ndk::audio::AudioError) -> Self {
use ndk::audio::AudioError::*;
match error {
Disconnected | Unavailable | NoService | InvalidHandle => {
Error::with_message(ErrorKind::DeviceNotAvailable, 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::DeviceNotAvailable,
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())
}
}
9 changes: 1 addition & 8 deletions src/host/alsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@
//!
//! Default backend on Linux and BSD systems.

extern crate alsa;
#[cfg(feature = "realtime")]
extern crate alsa_sys;
extern crate libc;

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},
Expand Down
22 changes: 11 additions & 11 deletions src/host/alsa/device.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alsa::poll::Descriptors;
use std::{
collections::HashMap,
fmt,
Expand All @@ -7,8 +8,7 @@ use std::{
};

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,
Expand Down Expand Up @@ -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<D, E>(
Expand All @@ -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<D, E>(
Expand All @@ -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)
)
}
}

Expand Down
14 changes: 6 additions & 8 deletions src/host/alsa/duplex.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
use std::{
sync::{Arc, atomic::Ordering},
time::Duration,
};

use super::{
DEFAULT_PERIODS, alsa,
alsa::poll::Descriptors,
poll_timeout_millis,
DEFAULT_PERIODS, poll_timeout_millis,
stream::{DuplexDataCallback, DuplexStreamInner, ErrorCallback},
timestamp::{callback_instant_for, status_with_timestamp},
trigger::TriggerReceiver,
Expand All @@ -15,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() {
Expand Down
10 changes: 5 additions & 5 deletions src/host/alsa/enumerate.rs
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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()) {
Expand All @@ -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),
Expand All @@ -100,7 +100,7 @@ fn physical_devices() -> Vec<PhysicalDevice> {
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,
};
Expand Down
2 changes: 1 addition & 1 deletion src/host/alsa/hw_params.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{DEFAULT_PERIODS, alsa};
use super::DEFAULT_PERIODS;
use crate::{
BufferSize, ChannelCount, Error, ErrorKind, FrameCount, SampleFormat, StreamConfig,
SupportedBufferSize,
Expand Down
Loading
Loading