-
Notifications
You must be signed in to change notification settings - Fork 447
fix(alsa): buffering behavior on PipeWire-ALSA #1033
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
base: master
Are you sure you want to change the base?
Conversation
Avoid setting period count when BufferSize::Default is used, allowing PipeWire-ALSA to select optimal buffer and period sizes. This prevents excessively large periods and high latency on PipeWire-ALSA devices.
|
Note to self: drop should wait for two periods worth of time, not the full buffer. |
Set buffer_size_near before period_size_near for Fixed buffer sizes to constrain total latency and avoid extremely large allocations (eg. PipeWire-ALSA creating ~1M-frame buffers). Then set period_size to keep double-buffering semantics. Adjust avail_min by direction: for playback wake when level drops to one period (buffer - period); for capture wake when one period is available (period) to prevent excessive capture latency.
Revert to v0.16 behavior: always terminate stream without attempting state-based drain or wait. Remove buffer-duration calculation and snd_pcm_wait usage to avoid delays during drop.
Query the device's period size and set buffer_size to 2 * period for BufferSize::Default. This prevents excessive memory allocation (e.g. PipeWire-ALSA) while respecting the device's period preference.
This should always align with the two-period double-buffering strategy that we use anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested it against pulse audio and some hardware. Seems to work. The changes to the buffering logic look fine to me. I didn't dig into the changes to drop, so can't comment on those.
| // buffer_size = 2x and period_size = x. This provides consistent low-latency | ||
| // behavior across different ALSA implementations and hardware. | ||
| if let BufferSize::Fixed(buffer_frames) = config.buffer_size { | ||
| hw_params.set_buffer_size_near((2 * buffer_frames) as _)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be better to use into here so there is a compile time error in case the types become incompatible.
Fixes high latency with
BufferSize::Defaulton PipeWire-ALSA by avoiding period count constraints that cause pathologically large periods.Fixes