Skip to content
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

Do not use cpal errors when rodio runs into an issue #703

Merged
merged 2 commits into from
Feb 18, 2025

Conversation

dvdsk
Copy link
Collaborator

@dvdsk dvdsk commented Feb 17, 2025

This prevents a search for BuildStreamError::StreamConfigNotSupported pointing to rodio code. That puts you on the wrong leg making you think the issue is in rodio where it is in Cpal. This was the only case in rodio where we issue a cpal error.

This prevents a search for BuildStreamError::StreamConfigNotSupported
pointing to rodio code. That puts you on the wrong leg making you think
the issue is in rodio where it is in Cpal. This was the only case in
rodio where we issue a cpal error.
Copy link
Collaborator

@PetrGlad PetrGlad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have submitted my patch yesterday :)

src/stream.rs Outdated
@@ -299,6 +302,7 @@ impl fmt::Display for StreamError {
Self::DefaultStreamConfigError(e) => e.fmt(f),
Self::SupportedStreamConfigsError(e) => e.fmt(f),
Self::NoDevice => write!(f, "NoDevice"),
Self::UnknownSampleFormat => write!(f, "UnknownSampleFormat"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe UnsupportedSampleFormat?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnexpectedSampleFormat? Since its pretty strange if it happens.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like we expected something else instead... "Unknown" in this situation is only unknown to rodio but not cpal :) I like "unsupported" the best here but "unexpected" would also do.

src/stream.rs Outdated
@@ -452,8 +455,9 @@ impl OutputStream {
error_callback,
None,
),
_ => Err(cpal::BuildStreamError::StreamConfigNotSupported),
_ => return Err(StreamError::UnknownSampleFormat),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can only happen with incompatible CPAL version. I wonder why they decided to mark cpal sample format enum as non_exhaustive. This could probably panic instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah had the same thought. But decided they must have done it for a reason. One of their examples (beep) has some commented out sample formats, so they might add those in the future (24bit for example)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I do not understand this is that cargo compiles both rodio and cpal from sources every time, so it can check that all match branches are there. Maybe there are some scenarios where pre-compiled Rust libraries are used, but I have not seen such projects so far.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend reading the RFC for non_exhaustive, it goes through all the reasons for using it. https://rust-lang.github.io/rfcs/2008-non-exhaustive.html

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and cpal is adding 24bit support to this enum it seems. Its non breaking because they have non_exhaustive on the enum. RustAudio/cpal#927

@dvdsk
Copy link
Collaborator Author

dvdsk commented Feb 17, 2025

I should have submitted my patch yesterday :)

I thought about pushing it to main directly 😅 you should have done that 😛

@dvdsk
Copy link
Collaborator Author

dvdsk commented Feb 17, 2025

should be good, if it is please merge it 👍

@dvdsk dvdsk requested a review from PetrGlad February 17, 2025 22:08
@PetrGlad PetrGlad merged commit 1799db8 into master Feb 18, 2025
9 checks passed
@PetrGlad PetrGlad deleted the sampleformat-error branch February 22, 2025 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants