Send and receive structured data streams with other participants.
More...
Send and receive structured data streams with other participants.
A data stream delivers content as a sequence of events: open, recv/write (one or more), and close. Data is automatically chunked into LIVEKIT_DATA_STREAM_CHUNK_SIZE byte pieces.
The maximum number of concurrent streams is controlled by CONFIG_LK_MAX_DATA_STREAM_READERS and CONFIG_LK_MAX_DATA_STREAM_WRITERS in Kconfig (default 4 each).
Receiving
Register a handler for a topic using livekit_room_data_stream_topic_register. The handler's livekit_data_stream_handler_t::on_recv callback is invoked for each received chunk.
{
}
const uint8_t * content
Definition livekit_data_stream.h:52
size_t content_size
Definition livekit_data_stream.h:53
livekit_err_t livekit_room_data_stream_topic_register(livekit_room_handle_t handle, const char *topic, const livekit_data_stream_handler_t *handler)
Registers a handler for incoming data streams on a given topic.
A received chunk of data stream content.
Definition livekit_data_stream.h:49
Handler for incoming data streams on a topic.
Definition livekit_data_stream.h:94
Sending a Text Stream
livekit_err_t livekit_room_data_stream_write(livekit_room_handle_t handle, livekit_data_stream_handle_t stream, const uint8_t *data, size_t size)
Writes data to an open outgoing data stream.
livekit_err_t livekit_room_data_stream_close(livekit_room_handle_t handle, livekit_data_stream_handle_t stream)
Closes an open outgoing data stream.
void * livekit_data_stream_handle_t
Opaque handle to an open outgoing data stream.
Definition livekit_data_stream.h:32
livekit_err_t livekit_room_data_stream_open(livekit_room_handle_t handle, const livekit_data_stream_options_t *options, livekit_data_stream_handle_t *stream)
Opens an outgoing data stream.
Options for opening an outgoing data stream.
Definition livekit_data_stream.h:81
Sending a Byte Stream
uint8_t image_data[4096];
size_t image_size = read_image(image_data, sizeof(image_data));
.topic = "image",
.is_text = false,
.total_length = image_size,
.has_total_length = true,
};
◆ livekit_data_stream_header_t
| struct livekit_data_stream_header_t |
Header information about a data stream.
| Data Fields |
|
bool |
has_total_length |
|
|
bool |
is_text |
True if this is a text stream (UTF-8 chunks), false if byte stream (raw binary). |
|
const char * |
sender_identity |
|
|
const char * |
stream_id |
|
|
int64_t |
timestamp |
|
|
const char * |
topic |
|
|
uint64_t |
total_length |
|
◆ livekit_data_stream_chunk_t
| struct livekit_data_stream_chunk_t |
A received chunk of data stream content.
| Data Fields |
|
uint64_t |
chunk_index |
|
|
const uint8_t * |
content |
|
|
size_t |
content_size |
|
|
const char * |
stream_id |
|
◆ livekit_data_stream_trailer_t
| struct livekit_data_stream_trailer_t |
Trailer information when a data stream closes.
| Data Fields |
|
const char * |
reason |
Empty string for normal closure, non-empty for abnormal end. |
|
const char * |
stream_id |
|
◆ livekit_data_stream_options_t
| struct livekit_data_stream_options_t |
Options for opening an outgoing data stream.
| Data Fields |
|
bool |
has_total_length |
Whether total_length is set. |
|
bool |
is_text |
True for a text stream (UTF-8 chunks), false for a byte stream (raw binary). |
|
const char * |
topic |
Topic to publish the stream under. Required. |
|
uint64_t |
total_length |
Total size of the stream in bytes, if known upfront. |
◆ livekit_data_stream_handler_t
| struct livekit_data_stream_handler_t |
Handler for incoming data streams on a topic.
◆ livekit_data_stream_close_cb_t
Called when a data stream is closed.
◆ livekit_data_stream_handle_t
Opaque handle to an open outgoing data stream.
◆ livekit_data_stream_open_cb_t
Called when a new data stream is opened.
◆ livekit_data_stream_recv_cb_t
Called for each received chunk of a data stream.
◆ livekit_room_data_stream_close()
Closes an open outgoing data stream.
Sends the stream trailer and releases the stream slot.
- Parameters
-
- Returns
- LIVEKIT_ERR_NONE if successful, otherwise an error code.
◆ livekit_room_data_stream_open()
Opens an outgoing data stream.
Sends the stream header and returns a stream handle for writing.
- Parameters
-
| handle[in] | Room handle. |
| options[in] | Stream options (topic, type, optional total length). |
| stream[out] | Stream handle for subsequent write/close calls. |
- Returns
- LIVEKIT_ERR_NONE if successful, otherwise an error code.
◆ livekit_room_data_stream_topic_register()
Registers a handler for incoming data streams on a given topic.
- Parameters
-
| handle[in] | Room handle. |
| topic[in] | Topic to handle. |
| handler[in] | Handler callbacks. The on_recv field is required; on_open and on_close are optional and may be NULL. The struct is copied internally. |
- Returns
- LIVEKIT_ERR_NONE if successful, otherwise an error code.
◆ livekit_room_data_stream_topic_unregister()
| livekit_err_t livekit_room_data_stream_topic_unregister |
( |
livekit_room_handle_t | handle, |
|
|
const char * | topic ) |
Unregisters a handler for incoming data streams on a given topic.
- Parameters
-
| handle[in] | Room handle. |
| topic[in] | Topic to unregister. |
- Returns
- LIVEKIT_ERR_NONE if successful, otherwise an error code.
◆ livekit_room_data_stream_write()
Writes data to an open outgoing data stream.
Data is automatically chunked into LIVEKIT_DATA_STREAM_CHUNK_SIZE byte pieces. Can be called multiple times.
- Parameters
-
- Returns
- LIVEKIT_ERR_NONE if successful, otherwise an error code.