Skip to content

Prioritize audio cache filling after seeks - #785

Open
rcombs wants to merge 26 commits into
TypesettingTools:masterfrom
rcombs:codex/seek-prioritized-audio-cache
Open

rcombs wants to merge 26 commits into
TypesettingTools:masterfrom
rcombs:codex/seek-prioritized-audio-cache

Conversation

@rcombs

@rcombs rcombs commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

With audio caching enabled, jumping late in a large video can leave the waveform or spectrum blank while the cache decodes from the beginning. Turning off the cache can make disk reads block the UI.

The RAM and disk cache workers now jump to the first undecoded chunk at or after the requested position. They continue forward until they reach cached audio or the end of the file, then return to earlier gaps. Sources that cannot seek keep decoding sequentially. If a cache read fails, the worker retries sequentially and preserves samples it already published.

The spectrum and waveform draw tiles once their input samples are available. Spectrum requests include the full FFT window around the requested tile. The scrollbar shades uncached regions and shows the active decoder position with a gradient that stops at cache gaps.

The macOS build and all 389 tests passed. Regression coverage exercises seek order, readiness, and decode failures for both cache types. Also checked the live spectrum view with a synthetic file and a slowed cache worker.

🤖 Codex

Query availability for a sample range and request background filling at the first gap from a starting sample. Let providers opt out of out-of-order cache filling.
Playback and rendering can read the same cache concurrently. Protect lazy mapping creation and remapping, and keep the mapping stable until the copy finishes. The decoder uses a separate write mapping.
Store whole samples in each fixed-size block so the read and write indexes agree when the sample width does not divide the block size.
Decode and publish 65,536 samples at a time in the RAM cache as well. Keep 4 MiB storage blocks and limit reads to samples already decoded within a block.
Move the sequential worker, decoded-prefix counter, and startup and shutdown code into CacheAudioProvider. Keep the cache read and allocation paths in each backend.
Use the interleaved frame width for cache allocation, indexing, and copies. Use format-aware silence to pad uncached frames. The app factory currently downmixes before caching, while the cache providers can also wrap multichannel sources directly.
Keep storage access in the RAM and disk providers and use one loop to copy decoded samples and pad the unavailable tail.
Give callers an explicit way to request the existing silence fallback on decode errors.
Playback, clip export, waveform and spectrum rendering, and the linear cache retain the silence fallback.
Catch, log, and fill with silence in the tagged overload. Converters and locks let errors reach the outer caller.
Retain the source index and accepted output format so a fresh decoder can reproduce the original sequential read state.
Publish availability per chunk and use it to answer range queries and copy ready samples. Continue filling sequentially.
Expose the worker state separately from the number of samples it published.
Request decode error propagation and leave a failed chunk unpublished. Reset once and replay from the start, discarding samples for ready chunks. Stop the worker if the retry fails.
Follow the latest request to the next gap, continue forward to EOF or a filled region, then fill the earliest gap. Keep linear fill for FFMS2 streams without advancing timestamps.
Compute the audio support of a pixel range, including the full window on each side of the first and last FFT centers in the spectrum.
Check the samples needed for each bitmap, including FFT input, before caching its derived data.
Size the last bitmap to the remaining audio and paint silence beyond the stream end.
Refresh as the total number of ready samples grows and stop polling when the worker finishes.
Use the first visible tile’s required start sample to request a background fill. Repaints at the same position leave the decoder’s current run in progress.
Gate source reads in both cache modes to cover the latest seek, skipping filled chunks, gap backfilling, partially available reads, and sequential-only sources.
Verify that plain reads throw and tagged reads silence partial results. Exercise failed seeks through a converter, linear retry with immutable ready chunks, and a permanent failure in both cache backends.

This branch has not been deployed

No deployments
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