alsa: update to alsa-rs 0.11 and fix device access issues #1085
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR updates
alsa-rsto 0.11 and fixes several related issues around device enumeration, duplex device queries, and ALSA'sstderrspam during enumeration. This also includes some quality-of-life improvements likeDebugderives and better error handling.1. Reverts device handle caching
Previously, we cached device handles to avoid opening them repeatedly (#506). This seemed efficient, and fixed drivers that have issues with rapidly closing and opening, but it caused two real problems:
EBUSYbecause we already had it openI've reverted the caching: devices are now opened fresh for each operation. For broken drivers where rapid open/close causes issues (like some NVIDIA HDMI cards), applications can use the new
DeviceBusyerror variant to implement retry logic.Fixes:
2. Suppresses ALSA's
stderrspamALSA has the habit of printing error messages directly to
stderrduring normal device enumeration. Users were understandably confused by this. Theenumerate.rsexample now shows how to use the newalsa::Output::local_error_handler()to suppress these messages during enumeration.Fixes:
3. Manages ALSA's global configuration
ALSA maintains a process-global configuration cache that we were never properly initializing or cleaning up. This led to memory leaks that showed up in Valgrind - somewhat false positives, but still.
Now we call
alsa::config::update()when creating the firstHost, andalsa::config::update_free_global()when dropping the last one, after the lastDeviceandStreamare dropped as well. The former reduces Valgrind reports, the latter correctly throws an error when ALSA is configured incorrectly.4. Handling of retriable errors with
DeviceBusyI've added a new
DeviceBusyerror variant to several error types. This lets applications distinguish between retriable errors (likeEBUSYorEAGAIN) and permanent failures (likeENOENTorEPERM). This allows users to implement smart retry logic when it makes sense, and counter the rapid open/close issues described above.5.
DebugimplementationsI've added
Debugderives toHost,Device,Stream, and internal types.6. Breaking changes
The new
DeviceBusyerror variant is technically breaking because the error enums weren't marked as#[non_exhaustive]. Users with match statements that don't have a catch-all pattern will get compilation errors. This will require a semver minor update.