Repository navigation
feat(ffi): prepare and publish audio sources during async connect - #1732
Draft
xianshijing-lk wants to merge 3 commits into
Draft
xianshijing-lk wants to merge 3 commits into
xianshijing-lk wants to merge 3 commits into
Conversation
This was referenced Nov 23, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.