-
Notifications
You must be signed in to change notification settings - Fork 154
Data streams v2 #997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
1egoman
wants to merge
16
commits into
main
Choose a base branch
from
data-streams-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Data streams v2 #997
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f865225
feat: add temporary maven local
1egoman 975888b
chore(protocol): bump submodule to v1.50.4-4 for data streams v2 fields
1egoman 6c4df62
build: consume livekit-uniffi and make it loadable from unit tests
1egoman 506bd9e
feat(datastream): read peer client capabilities
1egoman 666f773
feat(datastream): add the DataStreams FFI coordinator
1egoman b72830c
feat(datastream)!: back data streams with the Rust core
1egoman ada8932
feat(datastream): advertise data streams v2, and cover the FFI glue w…
1egoman d11b57e
style: apply spotless, and drain stragglers before RPC test tear-down
1egoman e64c274
feat(datastream): make the core's errors one to one with StreamException
1egoman 808c713
revert: drop the unrelated RoomAgentDispatch.attributes addition
1egoman c9338e3
test(datastream): verify on a real device, and fix a 16 KB page-size …
1egoman 80d6a31
build: fix the uniffi name collisions upstream, drop the patch script
1egoman fa009f0
fix(sample): stop LeakCanary crashing sample-app on launch
1egoman b991d5e
feat(sample): add a data streams panel to sample-app
1egoman b46b23c
fix(datastream): log every stream on an unhandled topic
1egoman ec3ade1
fix(datastream): hold an incoming stream to the encryption it opened …
1egoman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* | ||
| * Copyright 2026 LiveKit, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| // Points JNA at a *host* build of liblivekit_uniffi for local unit tests. | ||
| // | ||
| // Data streams are implemented in the Rust core, so any test that exercises them has to load | ||
| // the native library. Unit tests here run on the host JVM (Robolectric), but the | ||
| // livekit-uniffi AAR only ships Android .so files -- so the host build has to be supplied | ||
| // separately. This mirrors how client-sdk-swift's tests link the real xcframework rather than | ||
| // faking the core. | ||
| // | ||
| // Resolution order: | ||
| // 1. LIVEKIT_UNIFFI_LIB_DIR environment variable | ||
| // 2. livekitUniffiLibDir Gradle property | ||
| // 3. auto-discovery in a sibling rust-sdks checkout, which is the layout the LiveKit SDKs | ||
| // already assume for local uniffi development | ||
| // | ||
| // To produce the host library: | ||
| // cd ../rust-sdks/livekit-uniffi | ||
| // CARGO_PROFILE_RELEASE_STRIP=false cargo build --release --target <host triple> | ||
|
|
||
| ext.resolveUniffiNativeLibDirs = { | ||
| def libNames = ["liblivekit_uniffi.dylib", "liblivekit_uniffi.so"] | ||
| def hasLib = { File dir -> dir.isDirectory() && libNames.any { new File(dir, it).isFile() } } | ||
|
|
||
| def explicit = System.getenv("LIVEKIT_UNIFFI_LIB_DIR") ?: project.findProperty("livekitUniffiLibDir") | ||
| if (explicit) { | ||
| def dir = file(explicit) | ||
| if (!hasLib(dir)) { | ||
| throw new GradleException( | ||
| "LIVEKIT_UNIFFI_LIB_DIR/livekitUniffiLibDir is set to '${dir}' but no " + | ||
| "liblivekit_uniffi.{dylib,so} was found there.", | ||
| ) | ||
| } | ||
| return [dir] | ||
| } | ||
|
|
||
| // Sibling rust-sdks checkout. `target/<triple>/release` is where a --target build lands | ||
| // (the uniffi Makefile always passes --target); `target/release` covers a plain build. | ||
| def targetRoot = new File(rootDir, "../rust-sdks/target") | ||
| if (!targetRoot.isDirectory()) { | ||
| return [] | ||
| } | ||
| def candidates = [] | ||
| def plain = new File(targetRoot, "release") | ||
| if (hasLib(plain)) { | ||
| candidates << plain | ||
| } | ||
| targetRoot.listFiles({ File f -> f.isDirectory() } as FileFilter)?.sort { it.name }?.each { triple -> | ||
| def dir = new File(triple, "release") | ||
| if (hasLib(dir)) { | ||
| candidates << dir | ||
| } | ||
| } | ||
| return candidates | ||
| } | ||
|
|
||
| ext.configureUniffiForUnitTests = { Test task -> | ||
| // The generated bindings pick their cleaner by API level, and at 34+ use | ||
| // android.system.SystemCleaner. Robolectric's implementation of that delegates to | ||
| // jdk.internal.ref.CleanerFactory, which the module system hides by default -- so merely | ||
| // constructing an FFI object throws IllegalAccessError. Opening the package up lets the | ||
| // Android code path run as written, rather than forcing every test that touches the FFI down | ||
| // to an older Robolectric SDK. | ||
| task.jvmArgs += ["--add-exports", "java.base/jdk.internal.ref=ALL-UNNAMED"] | ||
|
|
||
| def dirs = resolveUniffiNativeLibDirs() | ||
| if (dirs.isEmpty()) { | ||
| task.doFirst { | ||
| logger.warn( | ||
| "[livekit] No host build of liblivekit_uniffi found. Tests that exercise data " + | ||
| "streams will fail to load the native library.\n" + | ||
| " Build it: cd ../rust-sdks/livekit-uniffi && " + | ||
| "CARGO_PROFILE_RELEASE_STRIP=false cargo build --release --target \$(rustc -vV | " + | ||
| "sed -n 's/^host: //p')\n" + | ||
| " Or point at one: -PlivekitUniffiLibDir=/path/to/dir", | ||
| ) | ||
| } | ||
| return | ||
| } | ||
| task.systemProperty("jna.library.path", dirs.collect { it.absolutePath }.join(File.pathSeparator)) | ||
| } |
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
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
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
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
83 changes: 83 additions & 0 deletions
83
livekit-android-sdk/src/main/java/io/livekit/android/room/ClientCapability.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * Copyright 2026 LiveKit, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.livekit.android.room | ||
|
|
||
| import livekit.LivekitModels | ||
|
|
||
| /** | ||
| * An optional feature capability a client advertises at connect time. | ||
| * | ||
| * Capabilities are independent feature flags, in contrast to [ClientProtocolVersion], which is a | ||
| * single monotonic version number. A client may speak a given client protocol yet still lack an | ||
| * individual capability, so the two are negotiated separately. | ||
| * | ||
| * Advertised by this SDK during the join handshake, mirrored by the server onto every | ||
| * `ParticipantInfo`, and readable per-peer via [io.livekit.android.room.participant.Participant.capabilities]. | ||
| */ | ||
| enum class ClientCapability(val value: Int) { | ||
| /** | ||
| * The client can accept RTP packet trailers passed through by the SFU instead of having | ||
| * them stripped. | ||
| */ | ||
| PACKET_TRAILER(1), | ||
|
|
||
| /** | ||
| * The client can decompress a `deflate-raw` compressed data stream payload. | ||
| */ | ||
| COMPRESSION_DEFLATE_RAW(2), | ||
| ; | ||
|
|
||
| fun toProto(): LivekitModels.ClientInfo.Capability { | ||
| return when (this) { | ||
| PACKET_TRAILER -> LivekitModels.ClientInfo.Capability.CAP_PACKET_TRAILER | ||
| COMPRESSION_DEFLATE_RAW -> LivekitModels.ClientInfo.Capability.CAP_COMPRESSION_DEFLATE_RAW | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| /** | ||
| * Converts from the protobuf enum, returning null for values this SDK build does not | ||
| * recognize. | ||
| * | ||
| * Unlike most `fromProto` helpers in this SDK this never throws: capabilities are an | ||
| * open, forward-extensible set, so a peer or server advertising a newer capability must | ||
| * be ignored rather than crash us. | ||
| */ | ||
| fun fromProto(capability: LivekitModels.ClientInfo.Capability): ClientCapability? { | ||
| return when (capability) { | ||
| LivekitModels.ClientInfo.Capability.CAP_PACKET_TRAILER -> PACKET_TRAILER | ||
| LivekitModels.ClientInfo.Capability.CAP_COMPRESSION_DEFLATE_RAW -> COMPRESSION_DEFLATE_RAW | ||
| LivekitModels.ClientInfo.Capability.CAP_UNUSED, | ||
| LivekitModels.ClientInfo.Capability.UNRECOGNIZED, | ||
| -> null | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The capabilities this SDK advertises to the server and, through it, to peers. | ||
| * | ||
| * Declared once so that every place which announces capabilities agrees. Data streams v2 | ||
| * compression is advertised unconditionally: deflate-raw is compressed and decompressed by the | ||
| * Rust data stream core, so support does not vary by device, API level, or room options. | ||
| * | ||
| * @suppress | ||
| */ | ||
| internal val ADVERTISED_CLIENT_CAPABILITIES = listOf( | ||
| ClientCapability.COMPRESSION_DEFLATE_RAW, | ||
| ) |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.