Skip to content

Conversation

@mitchmindtree
Copy link
Member

@mitchmindtree mitchmindtree commented Jan 28, 2020

This implements the changes described at #370.

Closes #370.

Backends implemented:

  • null
  • emscripten
  • asio
  • wasapi
  • alsa
  • coreaudio
  • docs updated
  • examples updated

Edit: here is the full list of renamings to make it easier for downstream crates to adapt:

  • Format type's data_type field renamed to sample_format.
  • Shape -> StreamConfig - The configuration input required to build a stream.
  • Format -> SupportedStreamConfig - Describes a single supported stream configuration.
  • SupportedFormat -> SupportedStreamConfigRange - Describes a range of supported configurations.
  • Device::default_input/output_format -> Device::default_input/output_config.
  • Device::supported_input/output_formats -> Device::supported_input/output_configs.
  • Device::SupportedInput/OutputFormats -> Device::SupportedInput/OutputConfigs.
  • SupportedFormatsError -> SupportedStreamConfigsError
  • DefaultFormatError -> DefaultStreamConfigError
  • BuildStreamError::FormatNotSupported -> BuildStreamError::StreamConfigNotSupported

@mitchmindtree
Copy link
Member Author

I've also added a

impl From<SupportedStreamConfig> for StreamConfig

implementation, but I'm unsure if it would be better to have an inherent impl on SupportedStreamConfig along the lines of

fn config(&self) -> StreamConfig

instead? Perhaps both? My thinking is the inherent impl may 1. make it easier to avoid type inference ambiguity and 2. reduce the need for .clone() calls on SupportedStreamConfig seeing as it does not impl Copy (even though it could in theory).

Copy link
Contributor

@msiglreith msiglreith left a comment

Choose a reason for hiding this comment

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

No strong opinion here on the name changes, even though aligning it with khronos speech would be appealing (Info/Properties/Capabilities)

/// Please note that `Device`s may become invalid if they get disconnected. Therefore all the
/// methods that involve a device return a `Result` allowing the user to handle this case.
pub trait DeviceTrait {
/// The iterator type yielding supported input stream formats.
Copy link
Contributor

Choose a reason for hiding this comment

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

format should be replaced, same below

Copy link
Member Author

Choose a reason for hiding this comment

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

Agh I knew I'd miss one somewhere

src/lib.rs Outdated

impl SupportedStreamConfig {
/// Construct a `SupportedStreamConfig` from an existing `StreamConfig`.
pub fn from_config(conf: &StreamConfig, fmt: SampleFormat) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

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

supported confuses me a bit here as is it guarenteed that it is actually supported by the backend if I can just craft it myself?

Copy link
Member Author

@mitchmindtree mitchmindtree Jan 30, 2020

Choose a reason for hiding this comment

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

Good point! I remember this crossing my mind also now that you mention it, but I didn't get around to addressing it.

Perhaps we should make it so that SupportedStreamConfig's can only be constructed via either the Device or SupportedStreamConfigRange, make this from_config constructor pub(crate), and expose the fields via methods instead? This way any instance of a SupportedStreamConfig can assumed to actually be supported (edit: from the Device that created it that is... nothing stopping the user using it with a non-supporting device)?

It's worth keeping in mind that users intending to use build_input/output_stream_raw currently must use a SupportedStreamConfig, so it would be especially important that Device::supported_input/output_formats is accurate and thorough to ensure we aren't restricting users from opening streams that are in fact supported by the device and host. Alternatively, to avoid this issue we could change the build_input/output_stream_raw API to accept a StreamConfig and SampleFormat as separate arguments, rather than expecting a SupportedStreamConfig.

Copy link
Contributor

Choose a reason for hiding this comment

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

The proposed change to the raw stream APIs seems natural, but bear in mind that this is a type with public fields, which can therefore be constructed by hand regardless.

This should give the user a higher confidence that, if they have a
`SupportedStreamConfig` format type that it is actually supported.

Also updates the `raw` stream builder methods to take a `StreamConfig`
and `SampleFormat` as separate arguments for flexibility.

**Backends Updated**

- [x] null
- [x] alsa
- [ ] emscripten
- [ ] coreaudio
- [ ] wasapi
- [ ] asio
Restrict the ways in which `SupportedStreamConfig/Range`s can be constructed
@mitchmindtree mitchmindtree merged commit e4df8b2 into RustAudio:master Feb 4, 2020
@mitchmindtree mitchmindtree deleted the stream_config branch February 4, 2020 16:08
mitchmindtree added a commit to mitchmindtree/cpal that referenced this pull request May 21, 2020
This rebases RustAudio#372, addressing the recent changes introduced by RustAudio#397, RustAudio#395, and RustAudio#371 in the process.

TODO:

- [ ] Complete implementation of `callback` and `playback` timestamps in the output stream callback.
mitchmindtree added a commit to mitchmindtree/cpal that referenced this pull request May 21, 2020
This rebases RustAudio#372, addressing the recent changes introduced by RustAudio#397, RustAudio#395, and RustAudio#371 in the process.

TODO:

- [ ] Complete implementation of `callback` and `playback` timestamps in the output stream callback.
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.

Change Format to something more suitable/flexible

3 participants