Skip to content

Keep the audio before from_timestamp of a stream/clear - #249

Merged
maximmaxim345 merged 2 commits into
mainfrom
feat/stream-clear-from-timestamp
Nov 25, 2026
Merged

maximmaxim345 merged 2 commits into
mainfrom
feat/stream-clear-from-timestamp

Conversation

@maximmaxim345

Copy link
Copy Markdown
Member

What does this implement/fix?

A stream/clear with from_timestamp now 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 on SendspinCore. Chunks the clear keeps keep their generation, so a SendspinCore app 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):

Types of changes

  • Bugfix (non-breaking change which fixes an issue): bugfix
  • New feature (non-breaking change which adds functionality): new-feature
  • Enhancement to an existing feature: enhancement
  • Breaking change (changes the public API or the protocol in a way that is not backwards compatible): breaking-change
  • Refactor (no behavior change): refactor
  • Documentation only: documentation
  • Maintenance / chore: maintenance
  • CI / workflow change: ci
  • Dependencies bump: dependencies

@maximmaxim345
maximmaxim345 requested an adaptive review from Copilot November 25, 2026 08:46
@github-actions github-actions Bot added the new-feature Adds new functionality label Nov 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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_timestamp through 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)

Comment thread src/audio/scheduler.ts Resolved
Comment thread src/core/core.ts Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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)

Comment thread src/core/state-manager.ts Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block approval of the timestamp-based partial audio clearing change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced (adaptive)

@maximmaxim345
maximmaxim345 merged commit a377d83 into main Nov 25, 2026
4 checks passed
@maximmaxim345
maximmaxim345 deleted the feat/stream-clear-from-timestamp branch November 25, 2026 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-feature Adds new functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants