Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The SDK has three categories of threads:
1. Completes any pending async `std::promise` matched by `async_id`.
2. Invokes all registered `FfiClient` listeners (including `Room::onEvent`).

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.
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.

**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.

Expand All @@ -76,7 +76,9 @@ All `RoomDelegate` callbacks and stream handler callbacks (e.g., `registerTextSt
| `VideoSource::captureFrame` | No | Not safe to call concurrently from multiple threads. |
| `LocalAudioTrack` / `LocalVideoTrack` | No | Thin `sendRequest` wrappers with no internal synchronization. |
| `LocalDataTrack::tryPush` | No | Thin `sendRequest` wrapper with no internal synchronization. |
| `TextStreamWriter` / `ByteStreamWriter` | Serialized | `write()` is serialized by an internal `write_mutex_`. |
| `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()`. A byte stream is consumed once: the first `readNext()` / `readAll()` starts reading, or `writeToFile()` (never on the FFI callback thread) hands it to the SDK core; `Room` holds byte readers weakly, so an unconsumed reader that is dropped releases its stream. |
| `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. |
| `TextStreamWriter` / `ByteStreamWriter` | Serialized | `write()` and `close()` are serialized by an internal mutex and each waits for its FFI callback, so `close()` never overtakes a write. `LocalParticipant` closes its writers on disconnect (via a shared registry, so writers may outlive the participant); later calls throw `DataStreamError`. Create writers with `LocalParticipant::streamText` / `streamBytes`; the constructors are deprecated. |

### Directory Layout
Be sure to update the directory layout in this file if the directory layout changes.
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,9 @@ add_library(livekit SHARED
src/audio_stream.cpp
src/data_track_frame.cpp
src/data_stream.cpp
src/data_stream_proto_converter.cpp
src/data_stream_proto_converter.h
src/data_stream_writer_registry.h
src/data_track_error.cpp
src/data_track_schema.cpp
src/data_track_stream.cpp
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@ token source helpers for endpoint, development token server, and custom backends
- Dynamic token sourcing (literal, custom, endpoint, development token server, caching)
- Receive remote audio/video tracks
- Publish local audio/video tracks
- Data tracks (low-level) and data streams (high-level)
- Data tracks (low-level) and data streams (high-level): one-shot `sendText` /
`sendBytes` / `sendFile` with compression, incremental writers, per-topic
stream handlers, and writing received byte streams straight to a file
(`ByteStreamReader::writeToFile`)
- RPC between participants
- End-to-end encryption (E2EE)
- Hardware-accelerated codecs (via the underlying Rust SDK)
Expand Down
13 changes: 11 additions & 2 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,21 @@ export LIVEKIT_URL="ws://localhost:7880" # or wss://your-server.livek
export LIVEKIT_TOKEN_A="<first participant token>"
export LIVEKIT_TOKEN_B="<second participant token>"

# Optional: a third participant (same room) for data stream tests that need a
# bystander, e.g. targeted streams. Tests that need it skip when it is unset.
export LIVEKIT_TOKEN_C="<third participant token>"

# Optional (for stress tests)
export RPC_STRESS_DURATION_SECONDS=3600 # Test duration (default: 1 hour)
export RPC_STRESS_CALLER_THREADS=4 # Concurrent caller threads (default: 4)
```

### Generating tokens for the test suites

The easiest path is to source the helper script, which mints both
The easiest path is to source the helper script, which mints the
participant tokens against a local `livekit-server --dev` and exports
`LIVEKIT_TOKEN_A`, `LIVEKIT_TOKEN_B`, and `LIVEKIT_URL` for the current shell:
`LIVEKIT_TOKEN_A`, `LIVEKIT_TOKEN_B`, `LIVEKIT_TOKEN_C`, and `LIVEKIT_URL` for
the current shell:

```bash
source scripts/set-test-tokens.sh
Expand All @@ -103,6 +108,10 @@ export LIVEKIT_TOKEN_B="$(lk token create --api-key devkey --api-secret secret -
--join --valid-for 99999h --room cpp_data_track_test \
--grant '{"canPublish":true,"canSubscribe":true,"canPublishData":true}' \
--token-only)"
export LIVEKIT_TOKEN_C="$(lk token create --api-key devkey --api-secret secret -i cpp-test-c \
--join --valid-for 99999h --room cpp_data_track_test \
--grant '{"canPublish":true,"canSubscribe":true,"canPublishData":true}' \
--token-only)"
```

## Installed SDK packaging tests
Expand Down
Loading
Loading