Repository navigation
decode: probe_file reads a song's length without decoding it - #303
Merged
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
Adds
decode::probe_file, which reads a song's length from its container without decoding it.decode_fileholds the whole song in memory at 8 bytes per frame, and until now a caller could only learn the length after paying for it. A two-hour 128 kbps MP3 is 115 MB on disk and about 1.4 GB decoded. The XR build plays the wearer's own files and caps a track at 15 minutes, so it needs to refuse a long file before the decode, not after.probe_file(path) -> Result<AudioProbe>returns the track's frame count and sample rate from the headers.Option. A stream with no length in its headers says nothing, and the caller falls back to the file size.decode_filebehaves as before.No CHANGELOG entry: nothing a desktop user will notice.
How to test / reproduce
Four tests, three new: a WAV's probed length matches its decode, a headerless MP3 gets an estimate, and a file that is not audio is an error.
On a Quest 3, with the XR branch using the probe, a 25 minute 24 kbps MP3 (4.5 MB) was refused in 36 ms and the next track played.
Checklist
cargo clippyis clean (default,analyze, and--no-default-features --features decode)CHANGELOG.mdhas an entry under## Unreleased(not needed, see above).wgslshader and.pfxdefinition (not applicable)