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
25 changes: 25 additions & 0 deletions include/livekit/remote_data_track.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

#pragma once

#include <cstdint>
#include <memory>
#include <optional>
#include <string>

#include "livekit/data_track_error.h"
Expand All @@ -32,6 +34,21 @@ namespace proto {
class OwnedRemoteDataTrack;
}

/// Track-level options that configure how the incoming-frame pipeline
/// reassembles packets for a remote data track.
///
/// Applied via RemoteDataTrack::setPipelineOptions().
struct DataTrackPipelineOptions {
/// Maximum number of partial frames the depacketizer will track
/// concurrently for this track.
///
/// Defaults to 1. Higher values give more out-of-order tolerance for
/// high-frequency senders at the cost of additional buffering. Zero is
/// not a valid value; if a value of zero is provided, it will be
/// clamped to one. Leave unset to keep the current value.
std::optional<std::uint32_t> max_partial_frames{std::nullopt};
};

/// Represents a data track published by a remote participant.
///
/// Discovered via the DataTrackPublishedEvent room event. Unlike
Expand Down Expand Up @@ -65,6 +82,14 @@ class RemoteDataTrack {
/// Whether the track is still published by the remote participant.
LIVEKIT_API bool isPublished() const;

/// Configures options for the pipeline handling incoming packets for this
/// track.
///
/// These options apply to all current and future subscriptions of this
/// track, and may be set at any time. New options take effect with the
/// next received packet.
LIVEKIT_API void setPipelineOptions(const DataTrackPipelineOptions& options);

#ifdef LIVEKIT_TEST_ACCESS
/// Test-only accessor for exercising lower-level FFI subscription paths.
uintptr_t testFfiHandleId() const noexcept { return ffiHandleId(); }
Expand Down
16 changes: 16 additions & 0 deletions src/remote_data_track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ bool RemoteDataTrack::isPublished() const {
return resp.remote_data_track_is_published().is_published();
}

void RemoteDataTrack::setPipelineOptions(const DataTrackPipelineOptions& options) {
if (!handle_.valid()) {
return;
}

proto::FfiRequest req;
auto* msg = req.mutable_remote_data_track_set_pipeline_options();
msg->set_track_handle(static_cast<uint64_t>(handle_.get()));
auto* opts = msg->mutable_options();
if (options.max_partial_frames) {
opts->set_max_partial_frames(*options.max_partial_frames);
}

FfiClient::instance().sendRequest(req);
}

Result<std::shared_ptr<DataTrackStream>, SubscribeDataTrackError> RemoteDataTrack::subscribe(
const DataTrackStream::Options& options) {
if (!handle_.valid()) {
Expand Down
Loading