fix: stream config validation for all backends#1215
Merged
Conversation
…ration validations
Contributor
There was a problem hiding this comment.
Pull request overview
This PR centralizes basic StreamConfig input validation across backends (rejecting channels = 0, sample_rate = 0, and BufferSize::Fixed(0) with ErrorKind::InvalidInput) and updates several backends’ reported supported configurations (channels, sample rates, and buffer sizing) to better match real platform behavior.
Changes:
- Add
validate_stream_configcalls across backends’build_*_stream_rawentry points to prevent invalid configs from reaching drivers. - Update WebAudio/AudioWorklet supported config enumeration (channels up to 64; discrete standard rates up to 768 kHz) and update WASAPI/PulseAudio/JACK reporting behavior.
- Extend ASIO bindings to expose buffer size preference/step constraints and validate stepped buffer sizes.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib.rs | Keeps validate_stream_config as the shared guard for invalid StreamConfig values. |
| src/host/webaudio/mod.rs | Switches to discrete sample-rate enumeration and raises channel/rate ceilings; adds validation call. |
| src/host/audioworklet/mod.rs | Updates supported configs/rates; reads back actual quantum size; adds validation call. |
| src/host/wasapi/device.rs | Reports software-stack buffer sizing as Unknown and substitutes device period in frames where possible; adds validation call. |
| src/host/pulseaudio/mod.rs | Corrects playback max buffer sizing for PulseAudio’s double-buffer; adds validation calls and fixed-size checks. |
| src/host/pipewire/device.rs | Adds upfront config validation and quantum-range validation for fixed buffer sizes. |
| src/host/jack/device.rs | Enumerates supported channels based on live system port counts; adds config validation. |
| src/host/coreaudio/macos/device.rs | Adds upfront validation and pre-validates fixed buffer sizes against the device’s reported range. |
| src/host/coreaudio/ios/mod.rs | Adds upfront validation and explicit fixed buffer-size range validation (256–4096). |
| src/host/asio/stream.rs | Adds upfront validation and enforces stepped buffer-size constraints from the driver. |
| src/host/aaudio/mod.rs | Expands channel enumeration up to 8 and switches reported buffer size to Unknown; adds validation call. |
| CHANGELOG.md | Documents the validation sweep and backend reporting/behavior changes. |
| asio-sys/src/bindings/mod.rs | Adds BufferPreference and extends BufferSizeRange to carry preferred/step constraints; fixes some c_char pointer typing. |
| asio-sys/CHANGELOG.md | Documents the BufferPreference/BufferSizeRange API change. |
Comments suppressed due to low confidence (1)
src/host/webaudio/mod.rs:240
- The
UnsupportedConfigmessage here omits the sample rate even thoughvalid_config()can reject configurations due tosample_rate(and/or other constraints). Including the offending sample rate and the supported rate constraints would make failures easier to diagnose.
if !valid_config(config, sample_format) {
return Err(Error::with_message(
ErrorKind::UnsupportedConfig,
format!(
"Sample format {sample_format} or channel count {} is not supported",
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Every backend now calls
validate_stream_config, sochannels: 0,sample_rate: 0, andBufferSize::Fixed(0)returnErrorKind::InvalidInputinstead of reaching the driver and silently doing the wrong thing.Beyond the validation sweep:
renderQuantumSizeback from the AudioContext sobuffer_size()reflects what the browser actually chose.max_length = 2 * tlength).supported_*_configs()now report the device scheduling period instead ofRange { min: 0, max: u32::MAX }.