alsa: Calling Host::input_devices() breaks Host::output_devices(), and vice versa
To reproduce: find a device name that supports capture and playback (you can use aplay -L and arecord -L), then pass it as poth input and output to feedback example:
> cargo run --example feedback sysdefault:CARD=sofhdadsp sysdefault:CARD=sofhdadsp
thread 'main' panicked at 'failed to find output device', cpal/examples/feedback.rs:119:6
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Note the device name is same input and output, and it exists when we call input_devices() but not when we call output_devices(). The cause: the second time we iterate Devices, the code calls DeviceHandles::open() on the device and returns EBUSY, so the iterator doesn't return the device.
The code in feedback.rs has not actually opened the device, so perhaps the iterator isn't correctly freeing the handle after opening it.
I am struggling to find how to work around or fix this problem.
Options I've thought of:
- Add duplex API, as in: https://github.com/RustAudio/cpal/pull/553
- Add a 'stream_type' hint to Devices, use it to avoid opening playback handle when we are querying capture devices