-
Notifications
You must be signed in to change notification settings - Fork 235
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
Calculate duration for mp3s #481
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a third time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the source: https://github.com/rust-lang/rust/blob/master/library/std/src/io/mod.rs#L1841
Third time is needed to go back to initial position
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, i guess its only 2 seeks, so its second, not third, bug in a comment in std I guess :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, stream_position() is also calling a seek, so it is indeed a third
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Three seeks are a lot, and it seems that's also the reason why the function isn't stable yet. Isn't there some API that symphonia provides to optionally return the length of a stream?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you asking about
MediaSource::byte_len
method? Yes, it is provided by symphonia, and this PR changes the implementation to returnSome
calculated length now instead of returningNone
as before. This is then used to estimate the duration of the trackThe method says that "This may be an expensive operation"
Although in my implementation here, I cache it when creating the source instead of calculating when the method is called.
I did it because of the method requiring shared reference to self instead of a
&mut
reference.This could instead be done with a
RefCell
so this "expensive" operation is performed only when actually neededWould that be better?
Other ways I see is changing the API bringing a trait like
MediaSource
into rodio itself. so that implementation of this is defined by the user, but I don't think thats a good ideaThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the RefCell idea tbh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would also make total_duration() work for all symphonia-decoded audio, which would be really helpful for my projects. @kuviman if you want me to try make the refcell changes, I'd be happy to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the PR to use lazy calculation. This is done not using
RefCell
, but with aMutex
/RwLock
since we need the source to bySync
.This should not have any performance issues tho since
get_mut
is enough and works without locking for normal usage, and locking will only happen once when we need to calculate the stream length