Repository navigation
Keep the audio before from_timestamp of a stream/clear - #249
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Late-decoding retained audio can play after its replacement, and delayed native Opus outputs lack regression coverage for cutoff filtering and rejection after a full clear.
2 open issues
What changed in this PR
This PR adds timestamped partial clearing to the Sendspin SDK so replacing buffered upcoming audio preserves the remainder of the current track.
Changes:
- Forward
from_timestampthrough protocol handling and public callbacks. - Preserve eligible decoded and scheduled audio across partial clears.
- Add regression tests for cutoff filtering, callback forwarding, and playback continuity.
| File | Description |
|---|---|
| tests/unit/state-manager.test.ts | Tests chunk validity across repeated partial clears. |
| tests/unit/scheduler.test.ts | Tests selective clearing and replacement continuity. |
| tests/unit/protocol-handler.test.ts | Tests forwarding the clear timestamp. |
| tests/unit/core.test.ts | Tests retaining and dropping pending decoded chunks. |
| tests/unit/application-roles.test.ts | Tests timestamp delivery to application roles. |
| src/types.ts | Adds timestamp types and documents retained generations. |
| src/internal-types.ts | Extends the stream-clear handler signature. |
| src/index.ts | Routes timestamped clears to selective scheduler clearing. |
| src/core/state-manager.ts | Tracks partial-clear cutoffs and chunk validity. |
| src/core/protocol-handler.ts | Forwards and logs timestamped clears. |
| src/core/core.ts | Applies partial clears and filters decoded output. |
| src/core/application-roles.ts | Passes clear timestamps to role callbacks. |
| src/audio/scheduler.ts | Preserves earlier audio and adjusts the scheduling timeline. |
| src/audio/decoder.ts | Allows output from retained older generations. |
Review effort: Balanced (adaptive)
There was a problem hiding this comment.
🟡 Changes recommended
Repeated partial clears grow the retained history, causing per-chunk filtering costs to increase during continuous playback because current-generation chunks unnecessarily scan that history.
1 open issue
2 resolved since last review
Review effort: Balanced (adaptive)
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.

What does this implement/fix?
A
stream/clearwithfrom_timestampnow drops only the audio from that time on, and the player keeps playing what it buffered before it. Until now the player cleared everything, so when a server replaced a buffered next track, the rest of the current track went silent.Apps get the timestamp as a new argument of
onStreamClear, on application roles and onSendspinCore. Chunks the clear keeps keep theirgeneration, so aSendspinCoreapp can receive them after chunks of a newer one.Tested by hand in the Music Assistant web player against a server that replaces the next track. With 6.0.0, changing the next track near the end of a track left the rest of the track silent. With this change, the track played to its end and the new next track followed without a gap.
Related issue or spec PR (if applicable):
stream/cleardrop only audio from a timestamp on spec#336Types of changes
bugfixnew-featureenhancementbreaking-changerefactordocumentationmaintenancecidependencies