feat: Add support for custom hosts, devices, and streams #1032
+457
−20
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.
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