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

Implements Seek #513

Merged
merged 67 commits into from
Apr 6, 2024
Merged

Implements Seek #513

merged 67 commits into from
Apr 6, 2024

Conversation

dvdsk
Copy link
Collaborator

@dvdsk dvdsk commented Oct 4, 2023

Adresses #176, see #176 (comment) for the motivations behind the design.

Adds a fail-able method fn try_seek(&mut self, pos: Duration) -> Result<(), SeekNotSupported> to all sources and decoders. The error struct SeekNotSupported contains the type name of the source that did not support seek. This is particularly useful when you have a chain of sources.

I commented out some working functionality that could not be merged yet:

  • Mixing sources are not seek-able, they need to know the current position in a source to be able to roll back when one of the sources fails to seek.
  • I added seeking to Minimp3 however the minimp3_fixed maintainer has engaged with my PR yet. I want to give them some more time to do so before looking at other options.

@dvdsk dvdsk marked this pull request as draft October 4, 2023 10:47
@dvdsk
Copy link
Collaborator Author

dvdsk commented Oct 4, 2023

Note: this is currently still a draft, early reviews are welcome though :)

@dvdsk dvdsk mentioned this pull request Oct 4, 2023
src/source/mix.rs Outdated Show resolved Hide resolved
src/decoder/vorbis.rs Outdated Show resolved Hide resolved
tests/seek.rs Show resolved Hide resolved
Copy link
Collaborator Author

@dvdsk dvdsk left a comment

Choose a reason for hiding this comment

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

Yet another thought, now we've got them implemented everywhere can_seek and try_seek should get default implementations. That way this wont break the build for everyone implementing Source on their own type.

@dvdsk
Copy link
Collaborator Author

dvdsk commented Oct 7, 2023

So the motivation behind can_seek was to use it in mixing sources. That way we can prevent scenarios where we seek in one source (A) and cant in the other (B). The problem is that the seek can still fail if can_seek returns true.

A better approach is to use #510 to seek back in A if B returns a (non critical) error while seeking. Such an error could be our SeekError::NotSupported or something like symphonia's SeekErrorKind::Unseekable.

examples/seek_mp3.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@naglis naglis left a comment

Choose a reason for hiding this comment

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

Thank you for your work!

I lack the expertise to give a thorough review of the actual implementation, so these are mostly typos I've noticed.

src/conversions/sample.rs Show resolved Hide resolved
src/conversions/sample_rate.rs Show resolved Hide resolved
src/decoder/mp3.rs Outdated Show resolved Hide resolved
src/decoder/mp3.rs Outdated Show resolved Hide resolved
src/decoder/symphonia.rs Outdated Show resolved Hide resolved
src/source/mod.rs Outdated Show resolved Hide resolved
src/source/sine.rs Show resolved Hide resolved
src/spatial_sink.rs Outdated Show resolved Hide resolved
src/spatial_sink.rs Outdated Show resolved Hide resolved
tests/seek.rs Outdated Show resolved Hide resolved
@dvdsk
Copy link
Collaborator Author

dvdsk commented Oct 12, 2023

Thank you for your work!

I lack the expertise to give a thorough review of the actual implementation, so these are mostly typos I've noticed.

I applied all the spelling/grammar suggestions directly, thanks a lot for them! The others are great too they just require a little more attention. I will apply them tomorrow!

seek is broken, RustAudio/lewton#73.
We could work around it by:
 - using unsafe to create an instance of Self
 - use mem::swap to turn the &mut self into a mut self
 - take out the underlying Read+Seek
 - make a new self and seek

If this issue is fixed use the implementation in
commit: 3bafe32
This adds two dependencies, they are only needed for the test suite.
Compile time will not increase for users. The extra overhead when
running the test suite is worth it imho. The test file is significantly
shorter and there is less code duplication. A run time solution would
decrease the test interface (you would have to manually find out which
params caused the test).
More readable, prep for using the same lines in new refine_position fn.
Since that is already pretty complex this needed to be made simpler.

This code retries on all errors not only decode errors. Retries will not
work on anything else then a decode error however they also wont cause
any problems. Not checking the result does however make the code
simpler.
@Houndie
Copy link

Houndie commented Apr 5, 2024

Just wanted to drop props for @dvdsk and everyone else who has reviewed this, this is great work and I'll be excited to see this land!

@dvdsk
Copy link
Collaborator Author

dvdsk commented Apr 6, 2024

Thanks to @Rintse for his extensive review! We caught a few cases where seek could be extended. The review also inspired me to extend the test suite with as result a ton of bugs discovered 😄.

Those have now all been fixed! Time to merge this PR 🎉 🥳 🎈.

Whats next?

In a few days I plan to cut a new release and push that to crates.io and maybe an announcement on users.rust-lang.org and the reddit.

In the long term I am planning a few other features to make rodio more suitable as a backend for music players. They will land over the next year probably (no promises). Meanwhile I'll be spending a little time every week to work through the PR backlog. So if you see anything you would like in rodio, do not hesitate to open an issue. If it fits for rodio we can work on it together.

@dvdsk dvdsk merged commit d103517 into RustAudio:master Apr 6, 2024
10 checks passed
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.

None yet

8 participants