Skip to content

decode: probe_file reads a song's length without decoding it - #303

Merged
kevinraymond merged 1 commit into
mainfrom
decode-probe
Nov 12, 2026
Merged

kevinraymond merged 1 commit into
mainfrom
decode-probe

Conversation

@kevinraymond

Copy link
Copy Markdown
Owner

What does this PR do?

Adds decode::probe_file, which reads a song's length from its container without decoding it.

decode_file holds 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.
  • The frame count is an Option. A stream with no length in its headers says nothing, and the caller falls back to the file size.
  • A constant-bitrate MP3 with no Xing header does get an estimate from the reader. A test pins that, since it is the long-podcast case.
  • Opening and probing the container moved into a helper that both functions share. decode_file behaves as before.

No CHANGELOG entry: nothing a desktop user will notice.

How to test / reproduce

cargo test -p fosfora-app --features analyze --lib decode::tests

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

  • Tested on at least one platform (Linux; the caller on a Quest 3)
  • cargo clippy is clean (default, analyze, and --no-default-features --features decode)
  • CHANGELOG.md has an entry under ## Unreleased (not needed, see above)
  • New effects include both the .wgsl shader and .pfx definition (not applicable)

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog No CHANGELOG entry needed: users won't notice this change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant