Skip to content
Draft
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
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ 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. |
| `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()`. |
| `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()` is serialized by an internal `write_mutex_`. |

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,9 @@ token source helpers for endpoint, development token server, and custom backends
- Receive remote audio/video tracks
- Publish local audio/video tracks
- Data tracks (low-level) and data streams (high-level): one-shot `sendText` /
`sendBytes` / `sendFile` with compression, incremental writers, and
per-topic stream handlers
`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
37 changes: 36 additions & 1 deletion include/livekit/data_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ constexpr std::size_t kStreamChunkSize = 15'000; // 15 KB
/// LocalParticipant::sendText()) when the send fails or the participant is no
/// longer connected, and by TextStreamReader / ByteStreamReader when an
/// incoming stream ends abnormally (for example the sender closed it with a
/// reason, the stream exceeded the receive size limit, or the room
/// reason, the stream exceeded RoomOptions::data_stream limits, or the room
/// disconnected mid-stream). The message carries the SDK's error description.
///
/// Derives from std::runtime_error, so existing
Expand Down Expand Up @@ -282,6 +282,11 @@ class LIVEKIT_API TextStreamReader {
/// with a handler registered via Room::registerByteStreamHandler(). The SDK
/// decompresses and reassembles the stream.
///
/// A stream is consumed once, either by reading it (readNext() / readAll())
/// or by having the SDK write it to disk (writeToFile()). The SDK holds the
/// incoming data until one of them is called; dropping every reference to an
/// unconsumed reader discards the stream.
///
/// Reading blocks the calling thread. Stream handlers run on the SDK's event
/// thread, which also delivers the chunks, so never read from inside the
/// handler: move the reader to another thread first.
Expand Down Expand Up @@ -312,6 +317,28 @@ class LIVEKIT_API ByteStreamReader {
/// before the error are returned first.
bool readNext(std::vector<std::uint8_t>& out);

/// @brief Write the whole stream to a file instead of reading it.
///
/// Blocks until the stream has been written, so call it from your own
/// thread, not from the stream handler. Call it instead of readNext() /
/// readAll(): a stream can only be consumed once. Afterwards readNext()
/// reports the end of the stream.
///
/// The file is named after the stream (info().name) unless
/// @p name_override is given. Either must be a plain file name: names with
/// path separators, "..", or an absolute path are rejected, so a sender
/// can't choose where the file goes. An existing file is overwritten.
///
/// @param directory Directory to write into; the system temporary
/// directory when unset.
/// @param name_override File name to use instead of the stream's name.
/// @return Path of the written file.
/// @throws DataStreamError if the stream was already read or closed, the
/// file name is not a plain file name, the file can't be written,
/// or the stream ended abnormally.
std::string writeToFile(const std::optional<std::string>& directory = std::nullopt,
const std::optional<std::string>& name_override = std::nullopt);

/// @brief Read the entire stream into a single buffer.
///
/// Blocks until the stream ends.
Expand Down Expand Up @@ -348,6 +375,14 @@ class LIVEKIT_API ByteStreamReader {
/// ended abnormally.
void onStreamEnded(const std::map<std::string, std::string>& attributes, std::optional<std::string> error);

/// Called by the Room with the stream's owned FFI reader handle. The reader
/// consumes it on the first readNext() / readAll() / writeToFile(), and
/// drops it if it is closed or destroyed first.
void attachUnreadHandle(std::uint64_t handle);

/// Starts incremental reading if the stream has not been consumed yet.
void startReading();

ByteStreamInfo info_;
std::unique_ptr<Impl> impl_;
};
Expand Down
17 changes: 16 additions & 1 deletion include/livekit/room.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ struct RtcConfig {
std::vector<IceServer> ice_servers;
};

/// @brief Data stream settings applied when connecting.
struct DataStreamOptions {
/// Maximum number of (decompressed) bytes accepted per incoming data stream.
/// A stream that exceeds it ends with a DataStreamError on the reader.
///
/// If unset, the SDK default (5 GB) is used.
std::optional<std::uint64_t> max_payload_byte_length;
};

/// Top-level room connection options.
struct RoomOptions {
/// If true (default), automatically subscribe to all remote tracks.
Expand Down Expand Up @@ -127,6 +136,9 @@ struct RoomOptions {
/// If unset, the Rust SDK default is used.
std::optional<std::chrono::milliseconds> connect_timeout;

/// Data stream settings, such as the incoming stream size limit.
DataStreamOptions data_stream;

/// @cond
/// Additional LiveKit SDKs layered on top of this one, reported to the server
/// as part of the client info.
Expand Down Expand Up @@ -369,7 +381,10 @@ class LIVEKIT_API Room {
// Active incoming stream readers, keyed by FFI reader handle id. A reader is
// removed when its end-of-stream event arrives or the room shuts down.
using TextStreamReaderMap = std::unordered_map<std::uint64_t, std::shared_ptr<TextStreamReader>>;
using ByteStreamReaderMap = std::unordered_map<std::uint64_t, std::shared_ptr<ByteStreamReader>>;
// Byte readers are held weakly: a byte stream is consumed lazily (read or
// written to a file), so a reader nobody keeps must be free to go away and
// release its stream.
using ByteStreamReaderMap = std::unordered_map<std::uint64_t, std::weak_ptr<ByteStreamReader>>;
TextStreamReaderMap text_stream_readers_;
ByteStreamReaderMap byte_stream_readers_;
// The E2EE manager is owned by the room and is not shared with other objects.
Expand Down
97 changes: 93 additions & 4 deletions src/data_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
#include <chrono>
#include <condition_variable>
#include <deque>
#include <future>
#include <mutex>
#include <optional>
#include <random>
#include <stdexcept>
#include <utility>

#include "ffi_client.h"
#include "livekit/local_participant.h"
Expand Down Expand Up @@ -203,7 +206,26 @@ class ReaderState {
} // namespace

struct TextStreamReader::Impl : ReaderState<std::string> {};
struct ByteStreamReader::Impl : ReaderState<std::vector<std::uint8_t>> {};
struct ByteStreamReader::Impl : ReaderState<std::vector<std::uint8_t>> {
enum class Consumer { kNone, kReader, kFile, kDiscarded };

/// Guards the one-time choice of how the stream is consumed.
std::mutex consume_mutex;
/// Owned FFI reader handle, until something consumes or drops it.
std::uint64_t unread_handle = 0;
Consumer consumer = Consumer::kNone;

/// Claims the stream for @p who. Returns the unread handle (0 if there is
/// none) when the stream was unclaimed; std::nullopt if already claimed.
std::optional<std::uint64_t> claim(Consumer who) {
const std::scoped_lock<std::mutex> lock(consume_mutex);
if (consumer != Consumer::kNone) {
return std::nullopt;
}
consumer = who;
return std::exchange(unread_handle, 0);
}
};

TextStreamReader::TextStreamReader(TextStreamInfo info) : info_(std::move(info)), impl_(std::make_unique<Impl>()) {}

Expand Down Expand Up @@ -231,7 +253,31 @@ void TextStreamReader::close() { impl_->close(); }

ByteStreamReader::ByteStreamReader(ByteStreamInfo info) : info_(std::move(info)), impl_(std::make_unique<Impl>()) {}

ByteStreamReader::~ByteStreamReader() = default;
ByteStreamReader::~ByteStreamReader() {
// Nobody consumed the stream: release it so the SDK core stops buffering.
if (const auto handle = impl_->claim(Impl::Consumer::kDiscarded); handle && *handle != 0) {
(void)dropFfiHandle(*handle);
}
}

void ByteStreamReader::attachUnreadHandle(std::uint64_t handle) {
const std::scoped_lock<std::mutex> lock(impl_->consume_mutex);
impl_->unread_handle = handle;
}

void ByteStreamReader::startReading() {
const auto handle = impl_->claim(Impl::Consumer::kReader);
if (!handle || *handle == 0) {
return;
}
try {
// Consumes the handle; chunks then arrive through the Room.
FfiClient::instance().byteStreamReadIncremental(*handle);
} catch (const std::exception& e) {
(void)dropFfiHandle(*handle);
impl_->end({}, std::string(e.what()));
}
}

void ByteStreamReader::onChunkReceived(std::vector<std::uint8_t> bytes) { impl_->push(std::move(bytes)); }

Expand All @@ -240,7 +286,10 @@ void ByteStreamReader::onStreamEnded(const std::map<std::string, std::string>& a
impl_->end(attributes, std::move(error));
}

bool ByteStreamReader::readNext(std::vector<std::uint8_t>& out) { return impl_->next(out, info_, "ByteStreamReader"); }
bool ByteStreamReader::readNext(std::vector<std::uint8_t>& out) {
startReading();
return impl_->next(out, info_, "ByteStreamReader");
}

std::vector<std::uint8_t> ByteStreamReader::readAll() {
std::vector<std::uint8_t> result;
Expand All @@ -251,7 +300,47 @@ std::vector<std::uint8_t> ByteStreamReader::readAll() {
return result;
}

void ByteStreamReader::close() { impl_->close(); }
std::string ByteStreamReader::writeToFile(const std::optional<std::string>& directory,
const std::optional<std::string>& name_override) {
if (isOnFfiCallbackThread()) {
// The result arrives on this same thread, so waiting here would deadlock.
throw DataStreamError("ByteStreamReader::writeToFile cannot be called on the SDK event thread");
}
const auto handle = impl_->claim(Impl::Consumer::kFile);
if (!handle) {
throw DataStreamError("ByteStreamReader::writeToFile: the stream was already read or closed");
}
if (*handle == 0) {
throw DataStreamError("ByteStreamReader::writeToFile: the stream is not available");
}

try {
std::future<std::string> written;
try {
written = FfiClient::instance().byteStreamWriteToFileAsync(*handle, directory, name_override);
} catch (...) {
// The request never reached the SDK core, so the handle is still ours.
(void)dropFfiHandle(*handle);
throw;
}
std::string path = written.get();
impl_->end({}, std::nullopt);
return path;
} catch (const DataStreamError& e) {
impl_->end({}, std::string(e.what()));
throw;
} catch (const std::exception& e) {
impl_->end({}, std::string(e.what()));
throw DataStreamError(e.what());
}
}

void ByteStreamReader::close() {
if (const auto handle = impl_->claim(Impl::Consumer::kDiscarded); handle && *handle != 0) {
(void)dropFfiHandle(*handle);
}
impl_->close();
}

// =====================================================================
// Writer implementation (uses your future-based FfiClient)
Expand Down
47 changes: 47 additions & 0 deletions src/ffi_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,53 @@ void FfiClient::byteStreamReadIncremental(std::uint64_t reader_handle) {
}
}

std::future<std::string> FfiClient::byteStreamWriteToFileAsync(std::uint64_t reader_handle,
const std::optional<std::string>& directory,
const std::optional<std::string>& name_override) {
const AsyncId async_id = generateAsyncId();

auto fut = registerAsync<std::string>(
async_id,
[async_id](const proto::FfiEvent& e) {
return e.has_byte_stream_reader_write_to_file() && e.byte_stream_reader_write_to_file().async_id() == async_id;
},
[](const proto::FfiEvent& e, std::promise<std::string>& pr) {
const auto& cb = e.byte_stream_reader_write_to_file();
if (cb.has_error()) {
pr.set_exception(std::make_exception_ptr(DataStreamError(cb.error().description())));
return;
}
if (!cb.has_file_path()) {
pr.set_exception(std::make_exception_ptr(DataStreamError("write_to_file callback missing file_path")));
return;
}
pr.set_value(cb.file_path());
});

proto::FfiRequest req;
auto* msg = req.mutable_byte_write_to_file();
msg->set_reader_handle(reader_handle);
msg->set_request_async_id(async_id);
if (directory) {
msg->set_directory(*directory);
}
if (name_override) {
msg->set_name_override(*name_override);
}

try {
const proto::FfiResponse resp = sendRequest(req);
if (!resp.has_byte_write_to_file()) {
logAndThrow("FfiResponse missing byte_write_to_file");
}
} catch (...) {
cancelPendingByAsyncId(async_id);
throw;
}

return fut;
}

std::future<void> FfiClient::sendStreamHeaderAsync(std::uint64_t local_participant_handle,
const proto::DataStream::Header& header,
const std::vector<std::string>& destination_identities,
Expand Down
7 changes: 7 additions & 0 deletions src/ffi_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@
void textStreamReadIncremental(std::uint64_t reader_handle);
void byteStreamReadIncremental(std::uint64_t reader_handle);

// Write an owned byte reader handle's stream to a file (the SDK core
// validates the file name). Consumes the handle. Resolves to the written
// file's path.
std::future<std::string> byteStreamWriteToFileAsync(std::uint64_t reader_handle,
const std::optional<std::string>& directory,
const std::optional<std::string>& name_override);

// Low-level data stream functionalities (legacy v1 framing)
std::future<void> sendStreamHeaderAsync(std::uint64_t local_participant_handle,
const proto::DataStream::Header& header,
Expand Down Expand Up @@ -287,17 +294,17 @@
bool cancelPendingByAsyncId(AsyncId async_id);

/// Map of listener IDs to listener slots
std::unordered_map<ListenerId, std::shared_ptr<ListenerSlot>> listeners_;

Check warning on line 297 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Builds / Build (windows-x64)

'livekit::FfiClient::listeners_': 'std::unordered_map<livekit::FfiClient::ListenerId,std::shared_ptr<livekit::FfiClient::ListenerSlot>,std::hash<int>,std::equal_to<livekit::FfiClient::ListenerId>,std::allocator<std::pair<const livekit::FfiClient::ListenerId,std::shared_ptr<livekit::FfiClient::ListenerSlot>>>>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 297 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Builds / Build (windows-x64)

'livekit::FfiClient::listeners_': 'std::unordered_map<livekit::FfiClient::ListenerId,std::shared_ptr<livekit::FfiClient::ListenerSlot>,std::hash<int>,std::equal_to<livekit::FfiClient::ListenerId>,std::allocator<std::pair<const livekit::FfiClient::ListenerId,std::shared_ptr<livekit::FfiClient::ListenerSlot>>>>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 297 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Builds / Build (windows-x64)

'livekit::FfiClient::listeners_': 'std::unordered_map<livekit::FfiClient::ListenerId,std::shared_ptr<livekit::FfiClient::ListenerSlot>,std::hash<int>,std::equal_to<livekit::FfiClient::ListenerId>,std::allocator<std::pair<const livekit::FfiClient::ListenerId,std::shared_ptr<livekit::FfiClient::ListenerSlot>>>>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 297 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Builds / Build (windows-x64)

'livekit::FfiClient::listeners_': 'std::unordered_map<livekit::FfiClient::ListenerId,std::shared_ptr<livekit::FfiClient::ListenerSlot>,std::hash<int>,std::equal_to<livekit::FfiClient::ListenerId>,std::allocator<std::pair<const livekit::FfiClient::ListenerId,std::shared_ptr<livekit::FfiClient::ListenerSlot>>>>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 297 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Tests / Test (windows-x64)

'livekit::FfiClient::listeners_': 'std::unordered_map<livekit::FfiClient::ListenerId,std::shared_ptr<livekit::FfiClient::ListenerSlot>,std::hash<int>,std::equal_to<livekit::FfiClient::ListenerId>,std::allocator<std::pair<const livekit::FfiClient::ListenerId,std::shared_ptr<livekit::FfiClient::ListenerSlot>>>>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 297 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Tests / Test (windows-x64)

'livekit::FfiClient::listeners_': 'std::unordered_map<livekit::FfiClient::ListenerId,std::shared_ptr<livekit::FfiClient::ListenerSlot>,std::hash<int>,std::equal_to<livekit::FfiClient::ListenerId>,std::allocator<std::pair<const livekit::FfiClient::ListenerId,std::shared_ptr<livekit::FfiClient::ListenerSlot>>>>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 297 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Tests / Test (windows-x64)

'livekit::FfiClient::listeners_': 'std::unordered_map<livekit::FfiClient::ListenerId,std::shared_ptr<livekit::FfiClient::ListenerSlot>,std::hash<int>,std::equal_to<livekit::FfiClient::ListenerId>,std::allocator<std::pair<const livekit::FfiClient::ListenerId,std::shared_ptr<livekit::FfiClient::ListenerSlot>>>>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 297 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Tests / Test (windows-x64)

'livekit::FfiClient::listeners_': 'std::unordered_map<livekit::FfiClient::ListenerId,std::shared_ptr<livekit::FfiClient::ListenerSlot>,std::hash<int>,std::equal_to<livekit::FfiClient::ListenerId>,std::allocator<std::pair<const livekit::FfiClient::ListenerId,std::shared_ptr<livekit::FfiClient::ListenerSlot>>>>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]
/// Next listener ID to generate
std::atomic<ListenerId> next_listener_id{1};

Check warning on line 299 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Builds / Build (windows-x64)

'livekit::FfiClient::next_listener_id': 'std::atomic<int>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 299 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Builds / Build (windows-x64)

'livekit::FfiClient::next_listener_id': 'std::atomic<int>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 299 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Builds / Build (windows-x64)

'livekit::FfiClient::next_listener_id': 'std::atomic<int>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 299 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Tests / Test (windows-x64)

'livekit::FfiClient::next_listener_id': 'std::atomic<int>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 299 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Tests / Test (windows-x64)

'livekit::FfiClient::next_listener_id': 'std::atomic<int>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 299 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Tests / Test (windows-x64)

'livekit::FfiClient::next_listener_id': 'std::atomic<int>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]
mutable std::mutex lock_;
/// Map of async IDs to pending operations
mutable std::unordered_map<AsyncId, std::unique_ptr<PendingBase>> pending_by_id_;

Check warning on line 302 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Builds / Build (windows-x64)

'livekit::FfiClient::pending_by_id_': 'std::unordered_map<livekit::FfiClient::AsyncId,std::unique_ptr<livekit::FfiClient::PendingBase,std::default_delete<livekit::FfiClient::PendingBase>>,std::hash<livekit::FfiClient::AsyncId>,std::equal_to<livekit::FfiClient::AsyncId>,std::allocator<std::pair<const livekit::FfiClient::AsyncId,std::unique_ptr<livekit::FfiClient::PendingBase,std::default_delete<livekit::FfiClient::PendingBase>>>>>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 302 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Builds / Build (windows-x64)

'livekit::FfiClient::pending_by_id_': 'std::unordered_map<livekit::FfiClient::AsyncId,std::unique_ptr<livekit::FfiClient::PendingBase,std::default_delete<livekit::FfiClient::PendingBase>>,std::hash<livekit::FfiClient::AsyncId>,std::equal_to<livekit::FfiClient::AsyncId>,std::allocator<std::pair<const livekit::FfiClient::AsyncId,std::unique_ptr<livekit::FfiClient::PendingBase,std::default_delete<livekit::FfiClient::PendingBase>>>>>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 302 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Tests / Test (windows-x64)

'livekit::FfiClient::pending_by_id_': 'std::unordered_map<livekit::FfiClient::AsyncId,std::unique_ptr<livekit::FfiClient::PendingBase,std::default_delete<livekit::FfiClient::PendingBase>>,std::hash<livekit::FfiClient::AsyncId>,std::equal_to<livekit::FfiClient::AsyncId>,std::allocator<std::pair<const livekit::FfiClient::AsyncId,std::unique_ptr<livekit::FfiClient::PendingBase,std::default_delete<livekit::FfiClient::PendingBase>>>>>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 302 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Tests / Test (windows-x64)

'livekit::FfiClient::pending_by_id_': 'std::unordered_map<livekit::FfiClient::AsyncId,std::unique_ptr<livekit::FfiClient::PendingBase,std::default_delete<livekit::FfiClient::PendingBase>>,std::hash<livekit::FfiClient::AsyncId>,std::equal_to<livekit::FfiClient::AsyncId>,std::allocator<std::pair<const livekit::FfiClient::AsyncId,std::unique_ptr<livekit::FfiClient::PendingBase,std::default_delete<livekit::FfiClient::PendingBase>>>>>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]
/// Next async ID to generate
std::atomic<AsyncId> next_async_id_{1};

Check warning on line 304 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Builds / Build (windows-x64)

'livekit::FfiClient::next_async_id_': 'std::atomic<unsigned __int64>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 304 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Builds / Build (windows-x64)

'livekit::FfiClient::next_async_id_': 'std::atomic<unsigned __int64>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 304 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Tests / Test (windows-x64)

'livekit::FfiClient::next_async_id_': 'std::atomic<unsigned __int64>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 304 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Tests / Test (windows-x64)

'livekit::FfiClient::next_async_id_': 'std::atomic<unsigned __int64>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

void pushEvent(const proto::FfiEvent& event) const;
friend void ffiEventCallback(const uint8_t* buf, size_t len);
std::atomic<LifecycleState> lifecycle_state_{LifecycleState::Uninitialized};

Check warning on line 308 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Builds / Build (windows-x64)

'livekit::FfiClient::lifecycle_state_': 'std::atomic<livekit::FfiClient::LifecycleState>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 308 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Builds / Build (windows-x64)

'livekit::FfiClient::lifecycle_state_': 'std::atomic<livekit::FfiClient::LifecycleState>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 308 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Tests / Test (windows-x64)

'livekit::FfiClient::lifecycle_state_': 'std::atomic<livekit::FfiClient::LifecycleState>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]

Check warning on line 308 in src/ffi_client.h

View workflow job for this annotation

GitHub Actions / Tests / Test (windows-x64)

'livekit::FfiClient::lifecycle_state_': 'std::atomic<livekit::FfiClient::LifecycleState>' needs to have dll-interface to be used by clients of 'livekit::FfiClient' [D:\a\client-sdk-cpp\client-sdk-cpp\build-release\livekit.vcxproj]
};
} // namespace livekit
30 changes: 15 additions & 15 deletions src/room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,9 @@ void Room::endStreamReaders(const TextStreamReaderMap& text_readers, const ByteS
kv.second->onStreamEnded({}, std::string(kDisconnectedWhileReceiving));
}
for (const auto& kv : byte_readers) {
kv.second->onStreamEnded({}, std::string(kDisconnectedWhileReceiving));
if (const auto reader = kv.second.lock()) {
reader->onStreamEnded({}, std::string(kDisconnectedWhileReceiving));
}
}
}

Expand Down Expand Up @@ -1464,11 +1466,14 @@ bool Room::dispatchStreamReaderEvent(const FfiEvent& event) {
if (it == byte_stream_readers_.end()) {
return true;
}
reader = it->second;
reader = it->second.lock();
if (ev.has_eos()) {
byte_stream_readers_.erase(it);
}
}
if (!reader) {
return true; // The application dropped the reader; discard its data.
}
if (ev.has_chunk_received()) {
const std::string& content = ev.chunk_received().content();
reader->onChunkReceived(std::vector<std::uint8_t>(content.begin(), content.end()));
Expand Down Expand Up @@ -1545,7 +1550,14 @@ void Room::onByteStreamOpened(const proto::ByteStreamOpened& opened, RoomDelegat
if (room_handle_ && it != byte_stream_handlers_.end()) {
handler = it->second;
reader = std::make_shared<ByteStreamReader>(fromProto(owned.info()));
// Register before read_incremental so no chunk can arrive unrouted.
// Reading starts lazily: the reader consumes the handle on its first
// readNext() / readAll() / writeToFile(), or drops it if discarded.
reader->attachUnreadHandle(reader_handle);
// Forget readers the application dropped without consuming; no events
// will ever arrive for them.
for (auto r = byte_stream_readers_.begin(); r != byte_stream_readers_.end();) {
r = r->second.expired() ? byte_stream_readers_.erase(r) : std::next(r);
}
byte_stream_readers_[reader_handle] = reader;
}
}
Expand All @@ -1555,18 +1567,6 @@ void Room::onByteStreamOpened(const proto::ByteStreamOpened& opened, RoomDelegat
const FfiHandle unread(static_cast<uintptr_t>(reader_handle));
LK_LOG_DEBUG("No byte stream handler for topic '{}'; ignoring stream {}", owned.info().topic(),
owned.info().stream_id());
} else {
try {
FfiClient::instance().byteStreamReadIncremental(reader_handle);
} catch (const std::exception& e) {
LK_LOG_ERROR("Failed to start reading byte stream {}: {}", owned.info().stream_id(), e.what());
{
const std::scoped_lock<std::mutex> guard(lock_);
byte_stream_readers_.erase(reader_handle);
}
const FfiHandle unread(static_cast<uintptr_t>(reader_handle));
reader->onStreamEnded({}, std::string(e.what()));
}
}

if (reader) {
Expand Down
3 changes: 3 additions & 0 deletions src/room_proto_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@ proto::RoomOptions toProto(const RoomOptions& in) {
if (in.other_sdks) {
out.set_other_sdks(*in.other_sdks);
}
if (in.data_stream.max_payload_byte_length) {
out.mutable_data_stream()->set_max_payload_byte_length(*in.data_stream.max_payload_byte_length);
}
return out;
}

Expand Down
Loading
Loading