You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit beb795d
Browse filesBrowse the repository at this point in the historyBrowse files
Port data stream receive path to FFI readers; add sendText/sendBytes/sendFile
Incoming data streams were rebuilt from the low-level stream_header/chunk/
trailer events. Since livekit-ffi 0.15.0 always advertises data streams v2,
modern senders send C++ participants single-packet and deflate-compressed
streams, which that path can't read: inline streams hang readAll() forever
and compressed chunks arrive as raw deflate bytes. The FFI also handed C++ an
owned reader handle for every incoming stream, which C++ ignored, so every
stream's content stayed buffered in the FFI for the life of the process.
Receive:
- Room consumes text/byte_stream_opened: unhandled topics drop the reader
handle; handled topics start read_incremental and route the resulting
*_stream_reader_events (keyed by reader handle) to the reader. The
low-level stream_*_received events are now ignored.
- Readers surface abnormal ends (sender close reason, size limit, disconnect)
as DataStreamError after draining buffered chunks, merge end-of-stream
attributes into info() on the reading thread, gain close(), and
ByteStreamReader gains readAll(). Room shutdown wakes blocked readers.
- RoomOptions::data_stream.max_payload_byte_length sets the receive limit.
Send:
- LocalParticipant::sendText / sendBytes / sendFile use the FFI one-shot
sends (compression and single-packet delivery when recipients support
them). They throw DataStreamError on failure and refuse to reach the FFI
once the room has disconnected, since the FFI panics there.
TextStreamOpenedEvent / ByteStreamOpenedEvent::reader_handle stays 0 and is
documented as deprecated. Existing writers are unchanged (v1 framing is still
accepted by FFI readers).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: AGENTS.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,7 +56,7 @@ The SDK has three categories of threads:
56
56
1. Completes any pending async `std::promise` matched by `async_id`.
57
57
2. Invokes all registered `FfiClient` listeners (including `Room::onEvent`).
58
58
59
-
All `RoomDelegate` callbacks and stream handler callbacks (e.g., `registerTextStreamHandler`) are invoked on this FFI callback thread. **Handlers must not block**; spawn a background thread if synchronous work is needed.
59
+
All `RoomDelegate` callbacks and stream handler callbacks (e.g., `registerTextStreamHandler`) are invoked on this FFI callback thread. **Handlers must not block**; spawn a background thread if synchronous work is needed. Incoming data stream chunks are also delivered to `TextStreamReader` / `ByteStreamReader` on this thread (routed by `Room` from `*_stream_reader_event`s keyed by reader handle), so a stream handler must never call `readNext()` / `readAll()` inline; readers log a warning if they would block on the FFI callback thread.
60
60
61
61
**Per-subscription reader threads** — `SubscriptionThreadDispatcher` creates a dedicated `std::thread` for each active audio, video, or data track subscription. These threads block on `AudioStream::read()`, `VideoStream::read()`, or `DataTrackStream::read()` and invoke the registered `AudioFrameCallback`, `VideoFrameCallback`, or `DataFrameCallback` on that reader thread — not on the FFI callback thread. A hard limit of 20 concurrent reader threads is enforced.
62
62
@@ -76,6 +76,8 @@ All `RoomDelegate` callbacks and stream handler callbacks (e.g., `registerTextSt
76
76
|`VideoSource::captureFrame`| No | Not safe to call concurrently from multiple threads. |
77
77
|`LocalAudioTrack` / `LocalVideoTrack`| No | Thin `sendRequest` wrappers with no internal synchronization. |
78
78
|`LocalDataTrack::tryPush`| No | Thin `sendRequest` wrapper with no internal synchronization. |
79
+
|`TextStreamReader` / `ByteStreamReader`| Yes | Fed on the FFI callback thread, read on a user thread (internal `std::mutex` + `condition_variable`). End-of-stream attributes are merged into `info()` on the reading thread, so don't call `info()` concurrently with `readNext()`. |
80
+
|`LocalParticipant::sendText` / `sendBytes` / `sendFile`| Yes | Independent async FFI requests; each call blocks its caller until its own callback arrives. They throw `DataStreamError` once the room has disconnected rather than reaching the FFI. |
79
81
|`TextStreamWriter` / `ByteStreamWriter`| Serialized |`write()` is serialized by an internal `write_mutex_`. |
0 commit comments