fix: prevent buffer overruns from destroying stream start position#17
Merged
fix: prevent buffer overruns from destroying stream start position#17
Conversation
The server's initial audio burst can far exceed the client's PCM buffer capacity, especially for compact codecs like OPUS (~43s of audio in seconds on LAN). The old "drop oldest" overrun behavior destroyed the beginning of the stream, causing the player to start from the wrong position — up to 22+ seconds into the song while other players started from the beginning. Three-layer fix: 1. Pre-playback overrun safety net: discard incoming audio instead of dropping oldest when the buffer fills before playback starts. This preserves the stream's starting position. 2. SkipStaleAudio: when playback starts and the first segment's timestamp is in the past (late pipeline init), skip forward to near-current audio so all players start at the same position. 3. Buffer capacity: increase default from 30s to 120s (~44MB) with 60s minimum enforcement to prevent stale user configs from causing undersized buffers. Also derives BufferCapacity (compressed bytes advertised to server in client/hello) from the actual PCM buffer duration and worst-case codec bitrate, instead of hardcoding 32MB. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
chrisuthe
added a commit
that referenced
this pull request
Mar 6, 2026
fix: prevent buffer overruns from destroying stream start position
This file contains hidden or 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
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.
Summary
buffer_capacityinclient/hellofrom actual PCM buffer duration × worst-case codec bitrate, instead of hardcoding 32MB.Root cause
OPUS frames are tiny (~640 bytes/20ms) so the server blasts 40+ seconds of audio in seconds on LAN. With an 8s buffer (stale user config), 1746 overruns destroyed the beginning of the song. The player's scheduled start anchored to audio from 12.8s into the song, waited 12 seconds of silence, then started from ~35s — while the FLAC player started from 0s. The 22-second gap matched the buffer depth difference.
Test plan
Buffer: Xms PCM → Y.ZMB advertised to serveron startup🤖 Generated with Claude Code