Skip to content

General Clean-up - #1411

Merged
Marco-Farruggio merged 35 commits into
RustAudio:masterfrom
Marco-Farruggio:general-cleanup
Oct 28, 2026
Merged

Marco-Farruggio merged 35 commits into
RustAudio:masterfrom
Marco-Farruggio:general-cleanup

Conversation

@Marco-Farruggio

@Marco-Farruggio Marco-Farruggio commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

As I code a keep a notepad window open and jot down anything I want to think about later, these were a few small tweaks which I've decided to squash into one PR

- Rename DeviceNotAvailable -> DeviceUnavailable:
- Why?: Better English, less words, shorter, matches HostUnavailable
Cancelled due to not wanting the API breakage.

  • Normalize thread names:
    • server clients: cpal_<host>_client_<pid>
    • worker threads: cpal_<host>_<dir> (in/out/dup)
  • Ensure all thread names sit within OS length restrictions.
  • Remove unused frames_to_duration on Windows
  • Remove unused try_emit_error in aaudio, when not --feature realtime
  • Clean up From<ndk::audio::AudioError> for Error.
  • Clean up From<jack::Error> for Error.
  • Remove any legacy extern crate syntax.
    • I've left the ones in the examples, as I assume they're there on purpose to show what the example requires at a glance.
  • Neaten up some imports.
  • Remove a redundant import for some trait scoping.
  • Consistently return ErrorKind::ResourceExhausted when failing to spawn a worker thread
    • Before: Some hosts did (correctly), others just used unwrap().
  • Use "{text}" rather than "{}", text.
  • Explicitly document where xruns are not reported.
  • Move some duplicated duplex stream config validation into a new crate::duplex::validate_duplex_config
    • A New OSS Host for FreeBSD #1404 will also use this
    • Some hosts have host-specific requirements which make it more logical to write their own duplex config validation checks, instead of using duplex::validate_duplex_config then checking their own reqs

@roderickvd roderickvd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changelog has other entries referencing DeviceNotAvailable that should be updated (if we decide to indeed change). The upgrade guide should be updated as well for anything that breaks the public API.

I'd like to think over if it's worth breaking it.

Comment thread src/host/alsa/device.rs Resolved
Comment thread src/host/jack.rs Resolved
let start = std::time::Instant::now();
let handle = thread::Builder::new()
.name("pw_in".to_owned())
.name("cpal_pw_in".to_owned())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (and others) will cause existing WirePlumber rules and stream-restore entries to break, and should be logged.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right I've just gone off and done some (Edit: A lot now) research regarding PipeWire persistence (I've rewritten this reply a couple of times, after realizing I was completely wrong multiple times), the change you replied to just changes the thread name, which PipeWire is oblivious to.

The actual places where the stream's name is set is here (and the corresponding input path):

// Before
let stream = StreamRc::new(
   core.clone(),
   &format!("cpal-playback-{}", std::process::id()),
   properties,
)?;

// After
let stream = StreamRc::new(
    core.clone(),
    &format!("cpal_pw_out_{}", std::process::id()),
    properties,
)?;

The only thing which changed was the naming, the stream name itself was never a stable persistence key beforehand, it included the PID before and still does. So this rename doesn't change whether WirePlumber can match it.

Client Naming

Host Before After Persistence Name Char Limits (Worst-Case Scenario)
JACK "cpal_client_{pid}" "cpal_jack_client_{pid}" X 27/64
PulseAudio "cpal-pulseaudio-{pid}" "cpal_pulseaudio_client_{pid}" X 33/128
PipeWire unset unset ?

The longest possible PID is 10 digits, on Windows.

I've added a note in the CHANGELOG.md mentioning the thread and client/node etc naming convention normalization. However, I haven't added anything to UPGRADING.md, because there was no promise of persistence beforehand.

Please let me know if you'd still like anything changed :)

Comment thread src/host/pipewire/rt_promote.rs Resolved
@Marco-Farruggio

Copy link
Copy Markdown
Collaborator Author

I noticed the tests in src/host/coreaudio/macos.rs are actual audio tests, shouldn't those be removed in favour of the ones in the actual --examples suite?

@LastExceed

Copy link
Copy Markdown
Collaborator

I just merged #1382 , which already included the fix for frames_to_duration's config gate. Take care to account for this when rebasing

@Marco-Farruggio

Copy link
Copy Markdown
Collaborator Author

I've rebased onto master again then, anything else before I can merge? (I presume Squash is the best option here, due to reverting some things etc.?)

@LastExceed

Copy link
Copy Markdown
Collaborator

I haven't done a thorough review of this branch yet, lemme do that now

@Marco-Farruggio

Marco-Farruggio commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator Author
unsafe impl Send for Devices {}
unsafe impl Sync for Devices {}

Found this in wasapi/device.rs when grepping for "{}", is this required? I thought only Device required Send + Sync, this seems unused, and I can't find an alternative for any of the other hosts.


pub trait HostTrait {
    /// The type used for enumerating available devices by the host.
    type Devices: Iterator<Item = Self::Device>;

It doesn't seem to require Send or Sync here, and here's from_host:

/// Construct a custom host from an arbitrary [`HostTrait`] implementation.
    pub fn from_host<T>(host: T) -> Self
    where
        T: HostTrait + Send + Sync + 'static,
        T::Device: Clone,
        <T::Device as DeviceTrait>::SupportedInputConfigs: Clone,
        <T::Device as DeviceTrait>::SupportedOutputConfigs: Clone,
    {

I don't see why this can't be removed, @LastExceed ?

@LastExceed

Copy link
Copy Markdown
Collaborator

Alright, LGTM. As for merge strategy, I'd personally prefer a merge commit, as the result is ultimately the same as squash merging (namely a single commit on master), except that the reference to the source branch is preserved. Squashing is typically done to reduce complexity in the git history, but since your branch is already sitting at the top of master, I don't see any complexity emerging (also modern git clients typically have a "first parent" option which effectively visualizes the history as if all merge commits were squash merges).

@LastExceed

Copy link
Copy Markdown
Collaborator

Regarding the unsafe impls, you can just remove them and see if the code still compiles.

@Marco-Farruggio

Copy link
Copy Markdown
Collaborator Author

Local cargo check/build and CI still pass just fine, so I guess they were just unused leftovers.

@LastExceed

Copy link
Copy Markdown
Collaborator

wait I totally forgot, Devices is part of the public API, we should absolutely keep them 😅

@Marco-Farruggio

Copy link
Copy Markdown
Collaborator Author

Aaandddd back they go 😄

@Marco-Farruggio
Marco-Farruggio merged commit 4bedd4e into RustAudio:master Oct 28, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants