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

Fix Symphonia seek for a duration with a fractional element of 0 #687

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

will3942
Copy link
Contributor

@will3942 will3942 commented Jan 23, 2025

Fixes: #686

@will3942 will3942 marked this pull request as draft January 23, 2025 13:58
@will3942 will3942 marked this pull request as ready for review January 23, 2025 13:58
@will3942 will3942 marked this pull request as draft January 23, 2025 14:04
@will3942 will3942 marked this pull request as ready for review January 23, 2025 14:16
@will3942 will3942 marked this pull request as draft January 23, 2025 14:17
@will3942 will3942 marked this pull request as ready for review January 23, 2025 14:29
@will3942
Copy link
Contributor Author

@dvdsk Ready for review - it was harder to get a 0ms test file than it should have been...

src/decoder/symphonia.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@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.

Ready to merge as is, could make the unit test an integration test. Let me know what you choose and ill merge.

edit: oh and good find! thanks for fixing my bug (this one is my fault) 🎉

@will3942
Copy link
Contributor Author

Ready to merge as is, could make the unit test an integration test. Let me know what you choose and ill merge.

edit: oh and good find! thanks for fixing my bug (this one is my fault) 🎉

No worries - have moved this to be an integration test :)

@@ -301,10 +301,13 @@ fn skip_back_a_tiny_bit(
}: Time,
) -> Time {
frac -= 0.0001;
Copy link
Collaborator

@PetrGlad PetrGlad Jan 23, 2025

Choose a reason for hiding this comment

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

Maybeif frac < 0.0001 { } else { } instead?

Next to the beginning of the Source saturating_sub will leave seconds unchanged, and the whole effect would be to actually seek forward almost a second.

Copy link
Collaborator

@dvdsk dvdsk Jan 24, 2025

Choose a reason for hiding this comment

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

its never called at the beginning of the source. This handles seeking beyond a source end.

Copy link
Collaborator

Choose a reason for hiding this comment

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

so this is good to merge right?

Copy link
Collaborator

@PetrGlad PetrGlad Jan 24, 2025

Choose a reason for hiding this comment

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

If it fixes the problem - yes, we can merge. Since it is already an improvement.
We can handle other cases later if necessary.
The source itself can be less than a second long. The check compares with < 1ms overlap, but tick-back is 0.1ms. what about overlaps in range 0.1...1.0 ms? I wonder if there are any symphonia functions to work with its timestamps or ways to convert those from/to Duration.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The source itself can be less than a second long

ahh damn, I did not think of that. Thanks for clarifying. No I agree now, lets fix this properly only then merge. This will need a comment in the code explaining this case or a future refactor might throw the code out.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I placed this comment in the code:

        let time = if seek_beyond_end {
            let time = self.total_duration.expect("if guarantees this is Some");
            skip_back_a_tiny_bit(time) // some decoders can only seek to just before the end
        } else {
            pos.as_secs_f64().into()
        };

As I remember symphonia does not seek if the time is beyond the length of the track. In rodio we have defined seek to saturate at the track length. If symphonia now saturates we can remove this.

Copy link
Contributor

Choose a reason for hiding this comment

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

When you seek to or beyond the end, you get an UnexpectedEof which is anyway what you get when the stream ends.

Copy link
Collaborator

@dvdsk dvdsk Feb 4, 2025

Choose a reason for hiding this comment

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

Though that is completely valid behavior for symphonia its not what we want in rodio (seeking beyond source should saturate as that is easiest for the end user) we do this instead. We also still want to return UnexpectedEof in case of other errors.

Though reading it now is still kinda fragile when audio has no total_duration. I'm strongly for leaving it as is for now. Since we have more then enough going on atm :)

edit: and the next release is already going to be gigantic. Do feel free to open an issue and present alternative behavior.

Copy link
Contributor

@roderickvd roderickvd Feb 4, 2025

Choose a reason for hiding this comment

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

What do you mean with saturating? I assume the behavior should be that the iterator returns None. Is that also what you mean?

I would make (and have made) the Symphonia decoder such that it handles this specific end-of-stream UnexpectedEof that way.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you mean with saturating?

see the docs: https://docs.rs/rodio/latest/rodio/source/trait.Source.html#method.try_seek

As long as the duration of the source is known seek is guaranteed to saturate at the end of the source. For example given a source that reports a total duration of 42 seconds calling try_seek() with 60 seconds as argument will seek to 42 seconds.

I would make (and have made) the Symphonia decoder such that it handles this specific end-of-stream UnexpectedEof that way.

Yeah that's way simpler, go ahead and do that 👍 Maybe I was worried about skipping back? but that's not a feature nor can we make it one.

@dvdsk dvdsk mentioned this pull request Feb 7, 2025
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.

Thread panic: Invalid range for Time fractional part.
4 participants