Skip to content

Fix playback timing after delay changes, clears and reconnects - #209

Merged
maximmaxim345 merged 6 commits into
mainfrom
fix/playback-timing-gaps
Oct 28, 2026
Merged

maximmaxim345 merged 6 commits into
mainfrom
fix/playback-timing-gaps

Conversation

@maximmaxim345

Copy link
Copy Markdown
Member

What does this implement/fix?

Fixes several cases where audio played at the wrong time or mixed in audio it should have dropped:

  • A chunk that was already late once the output delay was subtracted played late, and the chunks after it stayed late until correction caught up. It is now dropped.
  • In the quality and quality-local correction modes, a changed output delay never applied to a running stream. Every mode now resyncs once when the delay changes.
  • With SendspinCore used on its own, audio still decoding when a stream was cleared or ended was emitted afterwards.
  • After a quick reconnect, the first stream/start on the new connection was treated as a format update of the old stream, so old and new audio got mixed. Buffered audio from the old connection now stops when the new connection is activated.

quality-local is now documented as not spec compliant, since it leaves large sync errors uncorrected.

This is a breaking change: CorrectionThresholds.immediateDelayCutover is removed, since every mode now applies delay changes right away.

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 a balanced review from Copilot October 28, 2026 08:10
@github-actions github-actions Bot added the breaking-change Changes the public API or the protocol in a way that is not backwards compatible label Oct 28, 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

Increasing the delay from 0 to 10 ms in quality-local can leave buffered playback at the old delay because an overlapping chunk is shifted forward, propagating an uncorrected 10 ms timing error.

1 open issue
What changed in this PR

This PR improves playback timing and stream lifecycle handling in the Sendspin SDK, addressing late chunks, output-delay changes, pending decodes, and reconnects.

Changes:

  • Drops chunks whose adjusted start time has passed and enables delay-change cutovers in every correction mode.
  • Invalidates pending audio on stream resets and ends stale streams when a new connection activates.
  • Removes CorrectionThresholds.immediateDelayCutover and documents quality-local as non-compliant with the specification.
File Description
tests/​unit/​scheduler.test.ts Adds late-chunk and delay-change regression tests.
tests/​unit/​protocol-handler.test.ts Tests reconnect cleanup and stream preservation during re-handshakes.
tests/​unit/​core.test.ts Tests dropping pending decodes after a stream clear.
src/​types.ts Removes the cutover option and clarifies correction-mode documentation.
src/​core/​protocol-handler.ts Ends stale player streams on new-connection activation.
src/​core/​core.ts Invalidates pending decodes when resetting streams.
src/​audio/​scheduler.ts Updates late-chunk dropping and delay-change cutovers.
README.md Documents the quality-local compliance limitation.
index.html Adds the compliance warning to sample-player help text.

Review effort: Balanced

Comment thread src/audio/scheduler.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 were identified for the playback-timing and stream-lifecycle changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@maximmaxim345
maximmaxim345 merged commit 1ca8862 into main Oct 28, 2026
4 checks passed
@maximmaxim345
maximmaxim345 deleted the fix/playback-timing-gaps branch October 28, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change Changes the public API or the protocol in a way that is not backwards compatible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants