Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a (serialisable) means to uniquely identify a device #922

Open
abey79 opened this issue Oct 20, 2024 · 2 comments
Open

Add a (serialisable) means to uniquely identify a device #922

abey79 opened this issue Oct 20, 2024 · 2 comments

Comments

@abey79
Copy link
Contributor

abey79 commented Oct 20, 2024

Motivating use case

I'm writing a GUI program where the user is offered a choice of input devices and can pick one. The program should "remember" the user choice across launch, so it must serialise some identifying data about the device such that it can be retrieved again at next launch (assuming it still exists).

As far as I understand, the only piece of identifying data available for a Device is its name().

Problem

Device names are not unique, at least on macOS if you have two identical (e.g.) monitors, both equipped with mics and/or speakers. I happen to be in this situation and this code returns the following result:

let devices: Vec<_> = cpal::default_host().input_devices().unwrap().collect();
for device in devices {
    println!("Input device: {}", device.name().unwrap());
}

Result:

Input device: <iphone name> Microphone
Input device: Studio Display Microphone
Input device: Studio Display Microphone
Input device: MacBook Pro Microphone
Input device: Microsoft Teams Audio
Input device: iPad audio
Input device: ZoomAudioDevice

Solution

Ideally, Devices should have some kind of id that can be stored and checked against when trying to retrieve the same device at a later stage.

Related

@dheijl
Copy link
Contributor

dheijl commented Oct 20, 2024

I simply add the index in the list to the device name when serializing.

@abey79
Copy link
Contributor Author

abey79 commented Oct 20, 2024

I'll probably have to do something like that, though I might save the (name, n), to refer to the nth device named name.

edit: this workaround precludes using the system-defined default input/output device, because if the default is one of the duplicated name, it's currently impossible to know which one it corresponds to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants