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

Use builder to init output stream #641

Merged
merged 36 commits into from
Nov 24, 2024
Merged

Conversation

PetrGlad
Copy link
Contributor

@PetrGlad PetrGlad commented Nov 15, 2024

This is a breaking change.

Resolves PR#512 and #613
This pull request may be related #547

  • Use a builder pattern to configure output stream.
  • Make root mixer available to users.
  • Rename some of the creation methods.
  • Try alternative configurations when opening default stream.
  • ....

Still missing:

  • Examples that demonstrate custom stream configuration.
  • Update rustdocs in lib.rs

src/stream.rs Show resolved Hide resolved
src/stream.rs Show resolved Hide resolved
pub sample_rate: SampleRate,
pub buffer_size: BufferSize,
pub sample_format: SampleFormat,
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can be a part of the builder, but I wanted to give users an option co copy/store/modify it if they prefer, so the builder becomes only an optional convenience.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would not make it pub. If we make it pub we can never change the fields or add one without it being a breaking change. By using the builder we are free to add more in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The motivation of making this a separate struct, was to let users to pass it around or keep it in configs somewhere, for example. Yes, there is no problem to not publish it just yet.

Copy link
Collaborator

@dvdsk dvdsk Nov 20, 2024

Choose a reason for hiding this comment

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

If I understand correctly OutputStreamConfig is public to allow users to skip using the builder a second time.

One of the big advantages to builders is that we can expand them over time without that being a breaking change.

My advice is to remove OutputStreamBuilder completely from the public API. Users wanting to abstract away the builder can still do that in their own project.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Usually I prefer plain data if possible. But in this case I have allowed this option (to use the config directly) just to cover all the cases. But since no one actually requested this, I do not object hiding the struct.

Updated.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OutputStreamBuilder fields no longer need to be public (it compiles with pub removed).

Sorry I would apply the change to the PR myself but its such a chore to set that up. Ill see if I can automate that better on my side so its no longer a problem in the future.

Copy link
Collaborator

Choose a reason for hiding this comment

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

you know what ill fix it post merge, cause this is all ready to go! 🥳

src/stream.rs Show resolved Hide resolved
src/stream.rs Show resolved Hide resolved
src/stream.rs Show resolved Hide resolved
src/dynamic_mixer.rs Show resolved Hide resolved
src/stream.rs Show resolved Hide resolved
@PetrGlad
Copy link
Contributor Author

PetrGlad commented Nov 15, 2024

It looks like those "missing documentation" errors do not show up when building with stable toolchain :

rustup default stable
cargo test --all-targets

Using beta or nightly does show them.

@dvdsk dvdsk added the breaking Proposed change that would break the public API label Nov 18, 2024
src/stream.rs Outdated Show resolved Hide resolved
examples/music_mp3.rs Outdated Show resolved Hide resolved
@dvdsk
Copy link
Collaborator

dvdsk commented Nov 18, 2024

I have not done a full review (given its still a draft) but looked through it quickly and tried to address all the comments you made. What I see looks great though 🥳 ! It is clear you carefully considered your choices. Thank you very much for all the work.

Ill be careful not to create any merge conflicts. Given how big this PR is ill stay away from making larger changes till this has landed.

@PetrGlad
Copy link
Contributor Author

PetrGlad commented Nov 18, 2024

@dvdsk I have added dome docs, so in this form I'd say it is complete. The biggest reason I titled it as a draft was that more API changes would be considered necessary.

@PetrGlad PetrGlad changed the title Draft: Use builder to init output stream Use builder to init output stream Nov 18, 2024
@dvdsk
Copy link
Collaborator

dvdsk commented Nov 20, 2024

Only thing I still have a problem with is the OutputStreamConfig being public. I would still prefer another name for that one open function (see discussion) but we can merge that as is.

We do still need a changelog entry (see CHANGELOG.md) and ideally we should add a porting_guide.md given this is a breaking change. Could you make those or shall I get on that post merge?

@PetrGlad
Copy link
Contributor Author

I have added a custom config example (doubles as a test for the builder).

@PetrGlad
Copy link
Contributor Author

PetrGlad commented Nov 21, 2024

@dvdsk Updated, please have a look.

@dvdsk
Copy link
Collaborator

dvdsk commented Nov 24, 2024

This now also resolves: #643

@dvdsk dvdsk merged commit c1d2230 into RustAudio:master Nov 24, 2024
11 checks passed
@dvdsk
Copy link
Collaborator

dvdsk commented Nov 24, 2024

Thanks a lot for all the hard work Petr. This has really improved the API 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Proposed change that would break the public API enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants