Skip to content

Define how an in-place stream/start treats buffered visualizer data - #307

Merged
maximmaxim345 merged 1 commit into
mainfrom
fix/visualizer-in-place-stream-start
Oct 20, 2026
Merged

maximmaxim345 merged 1 commit into
mainfrom
fix/visualizer-in-place-stream-start

Conversation

@kahrendt

@kahrendt kahrendt commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

The visualizer role didn't define how an in-place stream/start treats data received under the previous configuration, which messaging.md leaves 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-place stream/start doesn't reset the buffer_capacity count, 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/start and decodes at delivery time with the current n_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.

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 maximmaxim345 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice catch, thanks @kahrendt !

@maximmaxim345
maximmaxim345 merged commit 974e1bf into main Oct 20, 2026
1 check passed
@maximmaxim345
maximmaxim345 deleted the fix/visualizer-in-place-stream-start branch October 20, 2026 08:10
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Define how an in-place stream/start treats buffered visualizer data

2 participants