Handle stream/clear internally#54
Merged
Merged
Conversation
Handles stream/clear entirely in the inner loop. The Sendspin server sends a clear marker as well as a signal. When the task gets the signal, it discards all encoded audio chunks until the clear marker. After that, the regular syncing algorithm takes over and ensures the new encoded chunks are played at the appropriate time.
…_syncing` to true on stream/clear, as there will be some gap to fix
There was a problem hiding this comment.
Pull request overview
This PR changes how stream/clear is handled for the player pipeline: instead of treating it like a stream lifecycle event (and assuming a subsequent stream/start), it is now treated as an in-stream seek handled internally by the sync task using an encoded ring-buffer marker.
Changes:
- Add
CHUNK_TYPE_STREAM_CLEAR_MARKERand update the sync task to discard buffered chunks up to this marker, then resume decoding with hard-sync behavior. - Remove
PlayerRoleListener::on_stream_clear()and the internalSTREAM_CLEARplayer callback type; update examples and docs accordingly. - Update internal documentation to reflect the new seek-style handling of
stream/clear.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/sync_task.h | Documents new seek semantics and adds helper method declarations for seek handling. |
| src/sync_task.cpp | Implements discard-to-marker logic and post-seek state adjustments in the sync loop. |
| src/player_role.cpp | On stream/clear, signals the sync task and enqueues a clear-marker chunk (no listener callback). |
| src/player_role_impl.h | Removes STREAM_CLEAR from the player event enum. |
| src/audio_types.h | Introduces CHUNK_TYPE_STREAM_CLEAR_MARKER. |
| include/sendspin/player_role.h | Removes on_stream_clear() from the public listener API and updates thread-safety docs. |
| examples/tui_client/main.cpp | Removes the on_stream_clear() override usage. |
| examples/basic_client/main.cpp | Removes the on_stream_clear() override usage. |
| docs/internals.md | Updates internal design documentation for seek-style stream/clear. |
| docs/integration-guide.md | Removes guidance/code for implementing on_stream_clear(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced May 13, 2026
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.
Fixes a bug where
stream/clearalways assumed astream/startmessage would follow.stream/clearmessages are now handled internally by the player role. It adds a marker to the ring buffer queue, and then the sync task clears all chunks up to that marker. It does not break out of the inner loop, so the next new chunk will get synchronized using the current sync algorithm (with the hard_sync flag automatically set so it uses a stricter bound for correction).There is one flaw with this design: it does not clear data already written out to the user provided buffer, so any pending audio will still play before starting with the new audio. This requires exposing more details to the library user, as the library itself has no control over that buffer. I have a longer-term plan to introduce this to the library. Note that in ESPHome, this is also the current behavior when stream/clear and stream/end are paired together, as the current
speaker_sourcemedia player always waits until all data is played before, so this is not a regression on that platform. I'm tracking this in #55This is a breaking change, because this PR removes the
on_stream_clearfunction from thePlayerRoleListenerclass.