Repository navigation
Define how an in-place stream/start treats buffered visualizer data - #307
Merged
Merged
Conversation
Keep buffered frames and interpret each under the configuration in effect when it was received, matching the player role. An in-place `stream/start` does not reset the `buffer_capacity` count.
maximmaxim345
approved these changes
Oct 20, 2026
maximmaxim345
left a comment
Member
There was a problem hiding this comment.
Nice catch, thanks @kahrendt !
kahrendt
added a commit
to Sendspin/sendspin-cpp
that referenced
this pull request
Nov 17, 2026
…ns as a span (#266) ## Summary Third step of moving the public API to standard view types (after #260, #261), and the visualizer half of Sendspin/spec#307. `on_spectrum()` handed a `std::vector`, and `on_visualizer_stream_start()` a struct holding one; an in-place `stream/start` recalled the buffered frames, which #307 says the client keeps; and the main-loop stream callbacks were unordered against the drain thread's frame callbacks, so a frame could arrive after `on_visualizer_stream_end()`. Part of Sendspin/backlog#92. **Migration:** | Deprecated | Replacement | |---|---| | `on_spectrum(int64_t, const std::vector<uint16_t>&)` | `on_spectrum_bins(int64_t, std::span<const uint16_t>, const VisualizerSpectrumConfig&)` | | `on_visualizer_stream_start(const ServerVisualizerStreamObject&)` | `on_visualizer_stream_started(const VisualizerStream&)` | `config` is the configuration the frame was received under; size the display from `bins.size()`. `VisualizerStream` (4 bytes) is the admitted stream: served types, `tracks_downbeats`, `rate_max`. A start whose notice a later start overwrote before it fired is folded into that later one. Overriding a deprecated callback draws no warning, so search for the old names and mark overrides `override`. ## Change - **In-place start:** updates the negotiated types and bin count without recalling buffered or held frames. Spectrum length and the downbeat bit are fitted on the protocol task at arrival, so the drain thread decodes with no configuration and the decode atomics go. - **Ordering,** modeled on the player's `on_stream_start()`/`on_stream_end()` against `on_audio_write()`: every start, end, clear and teardown takes a lifecycle ordinal stamped into each frame's item header. The drain thread holds a frame until the main loop has acknowledged its ordinal (dropped as late at its lag bound), and the main loop holds an end or clear until the drain thread reports it is past it. All stream callbacks stay on the main loop. A long run of in-place starts pulls the boundary and the drain thread's reported position along, so the 16-bit ordinals stay in range; a late frame's 20 ms bound counts from its display time. - **Start notice:** a latest-wins Inbox slot replaces the config slot and its topic. A start or clear the full event ring drops is acknowledged where it is lost, costing ordering, not delivery. - The tui example and the integration guide (visualizer section, threading table, the Deprecated String API section now "Deprecated API") use the new API; internals.md gains "Visualizer Stream Events". - The visualizer tests in `test_client_lifecycle.cpp` name the private members they reach in their own comments; `tests/CMakeLists.txt` points there (a follow-up applies this to the other tests and the conventions). ## Tests - Handshake table: frames wait for the events queued before them, across folded starts, a clear behind a superseded start, dropped starts and clears, a full held-event queue, ordinal wraparound, and a run of updates past half the ordinal range (with the drain thread reporting and stuck in a callback); late frames waiting for their notice are dropped past the bound. - Lifecycle: no frame callback after its stream's end or clear (stream/end, clear, deactivation, connection loss, with a callback in flight); a frame after a fresh start, update or clear waits for its notice; `stop()` ends a wait; an in-place start keeps held and listed frames, each frame decoding with its own bin count; both spectrum forms (new first, identical bins and config). - The first-spectrum-frame alloc window stays at 0 with both forms overridden. Mutants caught include the acknowledgement wait removed, an end or clear fired without waiting, a superseded start firing, no lost-event fallback, a plain `<=` in place of the wrap-safe compare, and a skipped or reordered deprecated call. - TSan runs of the visualizer tests (20 repeats) were clean; builds checked: `-DENABLE_WERROR=ON` with examples, and an ESP-IDF esp32s3 build with no deprecation warnings. Not run on hardware.
48 of 58 tasks
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.
The visualizer role didn't define how an in-place
stream/starttreats data received under the previous configuration, whichmessaging.mdleaves to each role. Match the player: frames sent before the update keep the previous configuration, and clients keep buffered frames and interpret each under the configuration in effect when it was received. Also state that an in-placestream/startdoesn't reset thebuffer_capacitycount, as the player role does.This matches what the existing timestamp-ordering (#229) and buffer-accounting (#232) rules already assume, and what sendspin-server and the aiosendspin server do.
Closes #306
Breaking changes
sendspin-cpp: drops all buffered visualizer frames on any
stream/startand decodes at delivery time with the currentn_disp_bins. It must keep frames across an in-place start and decode each under its own configuration.I accept the Contributor License Agreement for this contribution.