doc: describe when the partial block after a seek is written - #924
Open
Alb3e3 wants to merge 1 commit into
Open
Conversation
FLAC__stream_decoder_seek_absolute() decodes the block containing the target sample during the seek and hands the samples from the target onwards to the write callback before it returns. The documentation only said that the next write callback may contain a partial block, which reads as if that callback comes from a later FLAC__stream_decoder_process_single() call. Seeking into the last block of a stream then looks like lost audio: the samples have already been written, and the following process_single() call reports end of stream without a write callback (issue xiph#906). Assisted-by: Claude Code (Claude Opus 5)
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.
Documentation only, no behaviour change. It comes out of #906, where seeking into the last block of a stream looks like the write callback stops being called.
Chasing that down, the decoder is doing what it was built to do:
write_audio_frame_to_client_()recognises the frame that contains the target sample whileis_seekingis set, trims the samples before the target, calls the write callback with that partial block, and only then kicks out of seek mode. So the partial block is delivered from insideFLAC__stream_decoder_seek_absolute(), and decoding resumes with the block after it.For a seek into any block but the last that is invisible: the next
FLAC__stream_decoder_process_single()delivers the following frame, so the client keeps getting audio. For a seek into the last block there is no following frame, soprocess_single()returnstrue, calls nothing, and leaves the decoder inFLAC__STREAM_DECODER_END_OF_STREAM— which reads as lost audio even though those samples were already handed over during the seek.Measured on a 258048-sample, 4096-blocksize file (write callbacks counted separately during the seek and during the following
process_single()):No samples are lost in any of these cases —
blocksizeis exactly the number of samples from the target to the end of the stream.The existing wording is what misleads:
"the next write callback" reads as a callback from a later
process_single()call. This patch says when that callback actually happens and what to expect when the target is in the last block.If the preference is to change the behaviour instead — hold the partial block back and deliver it from the next
process_single()— I'm happy to look at that, but it would change what every existing client sees during a seek, so documenting the current contract seemed like the right first step.AI tool disclosure
Prepared with AI assistance; I verified the code path and ran the measurements above myself, and can answer questions during review. The commit carries an
Assisted-by:trailer.