Skip to content

feat(ffi): prepare and publish audio sources during async connect - #1732

Draft
xianshijing-lk wants to merge 3 commits into
sxian/fast-track-publicationfrom
sxian/CLT-3610/agent-prepared-publication
Draft

xianshijing-lk wants to merge 3 commits into
sxian/fast-track-publicationfrom
sxian/CLT-3610/agent-prepared-publication

Conversation

@xianshijing-lk

@xianshijing-lk xianshijing-lk commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Foreign SDKs can now supply an audio source, name and complete publication options during async connect. Rust creates the native track on its blocking pool, then passes it through the existing publish-on-join flow. Python/Agents no longer needs to invoke the synchronous native track constructor before scheduling connection and activity startup.

Existing prepared-track handles remain supported. Successful connect returns owned tracks/publications before room events begin, allowing callers to adopt them without duplicate publication. Preparation creates no foreign track handles before success. Failed callback delivery or an unclaimed result releases callback-owned handles; the caller retains source/existing-track ownership.

Stacked on #1704. Rust's existing initial-publication, encryption exclusion and unsupported-server/dual-PC fallback remain in control. This is an additive protobuf FFI change, with no UniFFI API change. Companions: livekit/python-sdks#963 and livekit/agents#8746.

Validation: native FFI build and cargo fmt passed; 39 FFI unit tests passed, one existing live-server test ignored. Python: 23 focused tests and 15 staging integration tests passed, including ordinary/existing-track/source-based and mixed-input publication in single and dual PC, repeated audio/unpublish/destruction, rejection, cancellation and partial invalid input. Agents: 160 focused tests passed.

Paired staging benchmark: 24 measured browser sessions plus six excluded warmups; median ICE RTT 62 ms; all received non-silent audio and message acknowledgements. Compared with the previous synchronous-preparation PR implementation, activity-start delay fell from 102.1 to 3.8 ms. First rendered audio improved by 121 ms with delayed activity and 101 ms with delayed PCM; immediate startup remained effectively unchanged (1,302 to 1,302 ms). Both arms already publish on JOIN, so this isolates preparation placement, not the separate two-RTT signaling optimization. Synthetic PCM and asynchronous delays are used; real-provider timing remains unverified.

Evidence and reproduction: https://github.com/livekit/agents/tree/sxian/CLT-3610/fast-track-publication-session-api/examples/startup_tracing/native-preparation-reports

Refactored the FFI adapter: normalize both input kinds into PreparedConnectTrack with an explicit TrackOrigin enum, pass them directly to RoomOptions.publish_tracks/Room::connect, and build the complete initial callback state together. Ordinary creation/publication and connect now share handle-registration helpers. This removes 41 implementation lines while retaining ownership cleanup and event ordering; no additional public/protobuf API changes. Native build/format, 39 Rust tests, 23 Python tests, 160 Agents tests and 15 staging integration tests passed after the refactor. The latency benchmark above predates this behavior-preserving refactor.

@xianshijing-lk xianshijing-lk changed the title feat(ffi): publish prepared tracks during room connection feat(ffi): prepare and publish audio sources during async connect Nov 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant