-
Notifications
You must be signed in to change notification settings - Fork 156
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
base: main
Are you sure you want to change the base?
Data streams v2 #997
Changes from all commits
f865225
975888b
6c4df62
506bd9e
666f773
b72830c
ada8932
d11b57e
e64c274
808c713
c9338e3
80d6a31
fa009f0
b991d5e
b46b23c
ec3ade1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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)) | ||
| } |
| 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, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't we also advertise the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIK, android does not support stripping / processing packet trailers from video frames. If this capability isn't advertised, I believe the SFU will do the trailer stripping instead, but I may be misremembering, cc @chenosaurus for clarification here. Once the android client is updated to support packet trailer processing (ie, stripping them out, and also extracting the metadata and providing apis to consume this metadata downstream) then this capability can be added to the advertisement here. |
||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.