fix: prevent channel shift when appending to an empty keep-alive queue#872
Merged
roderickvd merged 1 commit intomasterfrom Mar 29, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a race where wrapping an empty keep-alive queue in UniformSourceIterator could cache incorrect initial metadata (mono) and apply the wrong channel conversion to the first samples appended shortly after, causing a permanent 1-sample channel shift.
Changes:
- Make
UniformSourceIteratorlazily bootstrap its converters on the firstnext()call (instead of duringnew()), so it observes up-to-date source metadata. - Adjust queue span-length reporting to use
self.channels()(which can reflect the next queued source) rather than the current exhausted source’s channel count. - Add a regression test ensuring the first appended stereo samples are emitted with correct L/R ordering when added to a mixer after connecting an initially-empty keep-alive queue.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/source/uniform.rs |
Defers converter initialization until first sample pull using a pending source, preventing early metadata capture from placeholder sources. |
src/queue.rs |
Ensures span-length fallback aligns with the queue’s effective channel count and adds a regression test for correct first-append channel behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
When
Player::connect_newcallsmixer.add(queue)with an empty queue,UniformSourceIterator::bootstrap()captureschannels=1from theEmptyplaceholder and creates aTake(1)with aChannelCountConverter(from=1). If a stereo source is then appended before the audio thread callsnext(), that first sample passes through the wrong converter: L is treated as mono and duplicated, permanently shifting the stream by one sample and shifting channels.Supersedes #870
Fixes #871