fix(audio): match output stream sample format to device, never panic#24
Merged
Conversation
RDP server->client audio crashed the launcher: get_stream_config picked the first supported config (e.g. U8 on some USB headsets) while the stream was always built with an f32 callback. In WASAPI shared mode the stream sample format must match the device mix format, so the mismatch returned UnsupportedConfig, and the .unwrap() turned it into a panic that killed the whole launcher. - get_stream_config now prefers an F32 config (the usual shared-mode mix format and what our f32 buffer feeds), falling back to any supported one. - New build_output_stream_typed::<T> builds a stream typed to the device's actual sample format, converting the f32 buffer via FromSample. - Build failures now disable audio and log instead of panicking.
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.
This pull request improves the robustness and compatibility of audio output stream creation in
crates/channels/src/audio/output.rs. The main changes ensure that the audio output stream matches the device's supported sample format, preventing runtime errors and improving support for a wider range of audio hardware.Key improvements to audio output stream handling:
F32sample format when available, matching the internal buffer and common device defaults, but gracefully fall back to any supported format if necessary. (AudioHandle::get_stream_configlogic)build_output_stream_typed<T>to generically build output streams for any sample format, converting the internalf32buffer to the required device format on the fly.SampleFormat, supportingF32,I16,U16,U8,I32, andF64formats, and logging an error if the format is unsupported.Dependency and import updates:
FromSample,SampleFormat, andSizedSamplefrom thecpalcrate to support the new generic stream-building logic.