-
Notifications
You must be signed in to change notification settings - Fork 442
use set_buffer_size_near to calculate fixed alsa buffer size #990
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1508ff3
use set_buffer_size_near to calculate fixed alsa buffer size
attackgoat cddb361
ALSA: Fallback to default buffer size on error
attackgoat 0c9c099
ALSA: Add error handling to period/buffer size setup
attackgoat 199b142
Merge branch 'master' into alsa-buffer-size
attackgoat 5086bdb
Fix merge issue
attackgoat 35443ce
Merge branch 'master' into alsa-buffer-size
attackgoat 4da16f1
Clamp ALSA buffer size to valid CPAL values
attackgoat 7910693
Always set ALSA period count
attackgoat a8ef3ef
Fail if unable to set requested buffer size
attackgoat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Oops, something went wrong.
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.
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.
As final polish this would be even more resilient:
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.
Actually, though I marked the review as “changes requested”, keen to know what you think. It has the upside of pretty much always working, but the downside of potentially ignoring the user’s request.
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.
This was been incorporated in b710e04, but after rethinking it I don't think this check is required.
Reasoning: The sub-function
set_hw_params_buffer_size
takes a buffer size and attempts to fit the desired number of periods. If this fails, the fallback in the outer function already gets the period size and attempts to set valid parameters using a period-time approach, thereby handling the proposed check.Also:
snd_pcm_hw_params_set_periods
was only being called in the absolute fallback case, so the desired count of two was never actually respected (fixed)set_hw_params_periods
infallible: if it fails it is already ignored anyways (not fixed)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.
I've been thinking about this as well - thanks for sticking through this difficult undertaking of getting the period / buffer system right.
We need to have a behavior contract that's clear to what a user would reasonable expect:
BufferSize::Fixed(n)
→ "I need aroundn
frames, fail if you can't get close"BufferSize::Default
→ "Give me something reasonable for this hardware"Right now we might be too accommodating for
Fixed(n)
and succeed even when we request 128 frames and fall back to 2048. By analogy, we also fail opening a 48 kHz stream when a device only supports 44.1 or 96 kHz.Should be easy to change, right?
⬇️
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.
Sounds good - the code has been adjusted to return
BackendSpecificError
in case it cannot set the requested buffer size (default or fixed).In the future I think it would be helpful to return a better error type that programs could inspect and use to make decisions, because the string-based error is only helpful for the programmer. The
log
crate would be handy here.