Skip to content

caf: Fix seeking issues by properly binary searching the entire container - #549

Open
baylesj wants to merge 1 commit into
pdeljanov:mainfrom
baylesj:fix/caf-seek-index
Open

baylesj wants to merge 1 commit into
pdeljanov:mainfrom
baylesj:fix/caf-seek-index

Conversation

@baylesj

@baylesj baylesj commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Currently, the seeking logic for the CAF audio container format searches over a sub-slice of the packets relative to the current point in the file, however the result is used to index all packets, causing an offset error that gets worse the deeper into the audio file you get.

This PR updates the logic to search all packets instead, regardless of current position. The implementation uses a binary search so this decision is cheap and also more robust. Test coverage is also added to reduce the risk of a regression.

Progress on #501

The partition point was searched over a sub-slice of the packets, and
so is relative to the start of that sub-slice, but the result was used
to index all packets. When seeking forwards from any packet other than
the first, the seek landed on an earlier packet than the one requested.

The start frame of every packet is monotonically increasing, so
searching the sub-slice yields the same packet as searching all of
them. Search all packets instead. This also permits seeking once the
end of the stream has been reached, which previously failed because the
current packet index was then out-of-bounds.
@baylesj
baylesj force-pushed the fix/caf-seek-index branch from 785e02b to ed3e8f1 Compare August 13, 2026 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant