-
Notifications
You must be signed in to change notification settings - Fork 351
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
Switch from vendored alsa-sys to alsa crate #386
Conversation
Related PR by @mitchmindtree : #375 |
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.
Thanks @alexmoon ! I agree it makes sense to share this work between the two projects, rather than have CPAL roll its own high-level solution.
One concern I have is the CPAL/RustAudio maintainers having access to the alsa
crate in the case that we need to make changes or fixes. @diwic, is providing access to RustAudio maintainers something you might be open to if cpal were to switch over to alsa
as in this PR? We would still of course await your review on PRs etc, but this would at least give us a path forward in the case that you become unexpectedly unavailable or busy for example.
Alternatively, would you be interested in moving the project under the RustAudio umbrella and continuing to lead the project as a RustAudio admin? @est31 @piedoom would this be OK with you?
Also @diwic I noticed you brought up alsa
integration in the past at #346 , thanks for that! And sorry you haven't had a proper response until now!
@alexmoon also, it's probably best not to remove the alsa-sys
crate as I believe alsa
depends on this crate :)
I'll revisit the work in #375 once we've made a decision on this PR. If we do decide to go with alsa
, I'll update #375 to only update alsa-sys
itself and not touch any cpal
code.
alsa-sys = { version = "0.1", path = "alsa-sys" } | ||
libc = "0.2" | ||
alsa = "0.4.1" | ||
nix = "0.15.0" |
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.
Do we need nix
here? It looks like it's only used to check some errno's - could we get away with using libc
for this?
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.
nix wraps the errno's in an enum, so I think it makes more sense to match against that enum than to cast the value to an i32 and then compare to libc's constant. The alsa crate already pulls in nix as a dependency so it doesn't increase the overall dependency count to include it here. It would be more convenient if the alsa crate would re-export nix's Error and Errno types to avoid any issues with version conflicts.
Thanks!
I believe the |
Oh wow I wasn't aware of this second repository. Even more surprising, both repos describe the same package and their authors publish access to the same crates.io instance. Would definitely be good to resolve this, I would have been quite surprised to run into this when attempting to publish #375! |
Hi! So let's start with
I asked for co-maintainership in #222 - and since, I've been maintaining
So I'm definitely interested in collaborating more with you, but I need to know a little bit more of what I'm getting myself into :-) |
Ahhh thanks for sharing, this does ring a bell! I guess we just forgot to eventually move the crate itself out! I would be more than happy to add you as a maintainer to CPAL by the way too! I think it would be nice for you to have the freedom to downstream your
Of course! Perhaps unsurprisingly, RustAudio is a community of devs interested in audio development in Rust :) The intention is to attempt to share the burden and reduce the bus-factor for a variety of crates across the rust audio ecosystem by working together. Another side-goal is to improve the visibility of crates, proviidng a sort of one-stop-shop where folks interested in Rust audio dev can find a suite of useful tools in one place under the RustAudio org. If you have any other Qs feel free to ask (you can also find my email on my github user if you prefer). All that said, I'm equally happy for the crates to remain under your personal repo and would totally understand if you'd prefer it that way! My main concern was whether or not it might be tricky to upstream patches etc when necessary, but it's clear to me that you're welcoming of collaboration having requested to do so here in the past 😅 I'll test and have a closer look at this PR tonight and then maybe we can land it and move forward if no-one else has any concerns? |
This all sounds like good goals to me! I hope I'm not hijacking the PR by asking: Are there any prerequisites to moving crates to under the RustAudio umbrella? E g, must have clippy, rustfmt, free of rustc warnings, CI setup, a specific code of conduct, etc etc.. or is the individual maintainer free to choose? |
The organisation itself is quite ad-hoc and we've no official standards of this kind at the org level, currently it's very much up to the individual maintainer to take responsibility for these things for each repository. |
@alexmoon are you able to confirm each of the examples work for you locally? If so, would you mind sharing your current linux setup? When attempting to run the
Any idea what might be going on here? I imagine there's a chance that cpal might have been doing something incorrectly unchecked that perhaps |
Okay, let's go for it! 🙂 Could you invite/add me to rustaudio:cpal-administrators and I'll add that team as owner to the |
} | ||
) -> Result<alsa::pcm::HwParams<'a>, BackendSpecificError> { | ||
let hw_params = alsa::pcm::HwParams::any(pcm_handle)?; | ||
hw_params.set_access(alsa::pcm::Access::RWInterleaved)?; | ||
|
||
let sample_format = if cfg!(target_endian = "big") { |
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.
alsa::pcm::Format::S16()
(and U32()
and U16
) returns the native endian, so this can be simplified.
You're right. Previously Stream::play() and Stream::pause() were ignoring errors and my patch added a ? to propagate the errors (it seems like most ALSA devices don't support pausing). I've added a quick fix to just ignore the errors to match previous behavior. All the samples work for me with this change. Sorry for the oversight. It would probably be better to use the can_pause field. I also have a more extensive update in progress that, among other things, implements play and pause within the Stream so it works for all ALSA devices. |
I was debugging this in parallel. ALSA devices do support pausing, but you were calling "play" when the device was already running (i e not paused), which is why the function fails. |
@diwic sounds great to me! And thank you both for diving into the play/pause stuff! |
Interesting, and that makes sense. So are you saying that the PCM::pause() call should succeed even if HwParams::can_pause() returns false? In that case it's be easy enough to test the stream state before calling PCM::pause(). My suggestion would be to keep the behavior that matches what the current implementation is doing in this pull request (i.e. ignore the error) and then do a follow-up pull request to clean up some of these corners of the implementation. That way if we run into any compatibility issues with users of cpal it'll be easier to bisect if it's due to the change to the alsa crate or due to changes in how cpal interfaces with alsa. |
Investigating further, the beep example calls But the stream is explicitly started inside So (at least) three things are causing the stream to start:
The best behaviour (IMO) is to fill the buffer completely first and then start the stream. I'm not sure how to change things around in order not to break existing code though.
Sounds good to me. |
@mitchmindtree Do you know what's up with the CircleCI build error? I don't think it has anything to do with these changes... |
I think it's left over from the days when we used CircleCI to test windows. I believe the CircleCI configuration file was removed, but never disabled on the site itself. It looks like a recent update must have caused it to start getting picked up again regardless of missing the config. I'll see if I can disable it later on. I'm busy with some contract work atm but will test this PR again asap! |
OK this is looking great! All the examples seem to be running well. Happy to land this :) |
The `alsa-sys` crate repository has lived [here][1] for quite a while. This commit removes the unnecessary step from the CI workflow now that alsa-sys has finally been removed as of RustAudio#386. [1]: https://github.com/diwic/alsa-sys
This is another attempt to switch to the alsa crate fixing #346 (see also #308). I've attempted to change as little code as possible and keep consistency with the calls to the underlying library.
This change removes a lot of unsafe from cpal (though it still exists in the alsa crate itself) and enables RAII for the ALSA resources. It also fixes #377, allowing the use of the alsa crate and cpal in the same program.