Skip to content

feat(stream): stream_channel::publish_external — alias caller storage (Phase 2 PR3) - #517

Merged
transfix merged 1 commit into
masterfrom
feat/stream-publish-external
Oct 1, 2026
Merged

transfix merged 1 commit into
masterfrom
feat/stream-publish-external

Conversation

@transfix

@transfix transfix commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Adds a stream_channel producer path that publishes a frame aliasing caller-owned storage via a supplied std::shared_ptr<void> keepalive, with no pool slab. This is the hard prerequisite for the zero-copy pycvc producer (PR4): a numpy ndarray's buffer is borrowed, not copied into a slab.

  • publish_external(data, size, pts, keepalive) builds a frame borrowing data (keepalive co-owns it for the frame's life), stamps the next seq from the same counter as the pool path (seq monotonic across both producer paths), and fans out to every subscriber. The lease-based publish() is unchanged; the snapshot-under-lock + deliver-off-lock fan-out is factored into a private fan_out() shared by both.
  • Thread-safe for a single producer thread (deliver() is atomic/bounded-queue safe; subscribers snapshotted under subs_mu_, delivered off-lock). Caller treats data as immutable after publishing.

Tests: zero-copy alias (frame->data == caller buffer, pool untouched), seq interleaving across pool+external publishes, keepalive released exactly when the last subscriber frame drops. 20/20 pass, valgrind clean. Pure cvc::stream, no GL/Python/hardware.

Independent of PR1/PR2 (disjoint files); unblocks PR4. Addresses the plan's risk #3 (the previously-undesigned external-producer contract): seq stamping shared with the pool, fan-out thread-safety, immutability.

… Phase 2 PR3)

Adds a producer path that publishes a frame ALIASING caller-owned storage via a
supplied std::shared_ptr<void> keepalive, with NO pool slab — the prerequisite
for the zero-copy pycvc producer (PR4), where a numpy ndarray's buffer is
borrowed instead of copied into a slab.

- publish_external(data, size, pts, keepalive): builds a frame borrowing `data`
  (keepalive co-owns it for the frame's life), stamps the next seq from the SAME
  counter as the pool path (seq monotonic across both), and fans out to every
  subscriber. The lease-based publish() is unchanged; the shared snapshot+deliver
  fan-out is factored into a private fan_out() helper used by both.
- Thread-safe for a single producer thread (deliver() is atomic/bounded-queue
  safe; the subscriber snapshot is taken under subs_mu_ then delivered off-lock).
  The caller must treat `data` as immutable after publishing.

Tests (stream_test): zero-copy alias (frame->data == caller buffer, pool
untouched), seq interleaving across pool+external publishes, and keepalive
released exactly when the last subscriber frame drops. 20/20 pass, valgrind clean.
@transfix
transfix merged commit 3ca45b3 into master Oct 1, 2026
13 checks passed
@transfix
transfix deleted the feat/stream-publish-external branch October 29, 2026 20:53
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.

1 participant