-
Notifications
You must be signed in to change notification settings - Fork 459
feat: Add support for custom hosts, devices, and streams #1032
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
Conversation
|
Thanks for the PR! I'm off for a little while and will look at it later. It's an interesting feature - however curious for what kind of hosts one would want to add proprietary support instead of contributing it to cpal? |
|
Any hosts written against proprietary code (anything console-specific for example) couldn't be upstreamed for legal reasons There's definitely other reasons not to upstream a host aside from that, certain hosts could be very niche or be designed for very specific use-cases! I wrote this PR after I tried to make a custom cpal backend for the 3ds using libctru and couldn't. In order to upstream it, I'd have to make the host production ready, and after it'd be upstreamed the cpal maintainers would have to maintain a host for a very niche platform |
roderickvd
left a comment
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.
Sorry for the late response and thanks for your earlier explanation.
I think it's interesting to add this as an opt-in feature. Would you also add a changelog entry and an example?
|
I tried to make the example generally show how |
|
Merged. Thank you! |
This PR adds support for writing and using custom
HostTrait,DeviceTrait, andStreamTraitimplementationsThis was already sort of possible before, but
cpal::Datahas no public constructor so writing a custom device implementation wasn't possible.Actually using the custom host wasn't doable either, as crates like
rodioonly accept acpal::Host/cpal::Device, which doesn't supportHosts defined outsidecpalWhy
Currently, adding support for platforms that
cpaldoesn't support requires forkingcpal.Depending on the platform, it might not be possible/desirable to upstream support into
cpaleitherHow
I partially modeled this PR off of wgpu's custom device support and erased-serde.
Custom hosts require everything to be
'static, which is annoying, but relaxing that requirement would've meant introducing lifetimes in a lot of places that didn't have them previouslyThere's also the requirement that custom devices and supported configs be
Cloneas well, because of these derives inplatform/mod.rs:cpal/src/platform/mod.rs
Lines 90 to 96 in 2b7dc14
cpal/src/platform/mod.rs
Lines 122 to 128 in 2b7dc14
cpal/src/platform/mod.rs
Lines 130 to 136 in 2b7dc14
Removing those derives would make the code for custom devices simpler