Skip to content

Commit ae3c77e

Browse files
ladvocstephen-derosa
authored andcommitted
LiveKit Capture integrated through FFI
1 parent e17e2d9 commit ae3c77e

14 files changed

Lines changed: 1507 additions & 16 deletions

‎.github/workflows/tests.yml‎

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ env:
132132
VCPKG_DEFAULT_TRIPLET: x64-windows-static-md
133133
VCPKG_DEFAULT_HOST_TRIPLET: x64-windows-static-md
134134
VCPKG_TARGET_TRIPLET: x64-windows-static-md
135+
# Windows uses an explicit, checksum-pinned GStreamer SDK. Linux and macOS
136+
# intentionally use their supported platform-package versions; `1.0` in
137+
# Ubuntu package names denotes the GStreamer ABI, not the installed release.
138+
GSTREAMER_WINDOWS_VERSION: "1.28.5"
139+
GSTREAMER_WINDOWS_SHA256: "51ee5eaec33008e8409d8cf6f6884457f22aa3bd515f8856f993a3eaab903530"
135140

136141
jobs:
137142
test:
@@ -209,6 +214,34 @@ jobs:
209214
with:
210215
vcpkgGitCommitId: ${{ env.VCPKG_GIT_COMMIT }}
211216

217+
- name: Install GStreamer (Windows)
218+
if: runner.os == 'Windows'
219+
shell: pwsh
220+
run: |
221+
$installer = Join-Path $env:RUNNER_TEMP "gstreamer-installer.exe"
222+
$installDir = Join-Path $env:RUNNER_TEMP "gstreamer"
223+
$uri = "https://gstreamer.freedesktop.org/data/pkg/windows/$env:GSTREAMER_WINDOWS_VERSION/msvc/gstreamer-1.0-msvc-x86_64-$env:GSTREAMER_WINDOWS_VERSION.exe"
224+
225+
Invoke-WebRequest -Uri $uri -OutFile $installer
226+
$actualHash = (Get-FileHash -Algorithm SHA256 $installer).Hash.ToLowerInvariant()
227+
if ($actualHash -ne $env:GSTREAMER_WINDOWS_SHA256) {
228+
throw "GStreamer installer SHA-256 mismatch: expected $env:GSTREAMER_WINDOWS_SHA256, got $actualHash"
229+
}
230+
231+
$process = Start-Process -FilePath $installer -ArgumentList @(
232+
"/TYPE=devel",
233+
"/DIR=$installDir",
234+
"/CURRENTUSER",
235+
"/VERYSILENT",
236+
"/NORESTART"
237+
) -Wait -PassThru
238+
if ($process.ExitCode -ne 0) {
239+
throw "GStreamer installer failed with exit code $($process.ExitCode)"
240+
}
241+
242+
"$installDir\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
243+
"PKG_CONFIG_PATH=$installDir\lib\pkgconfig" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
244+
212245
# ---------- OS-specific deps ----------
213246
- name: Install deps (Ubuntu)
214247
if: runner.os == 'Linux'
@@ -227,6 +260,11 @@ jobs:
227260
libabsl-dev \
228261
libcurl4-openssl-dev \
229262
libwayland-dev libdecor-0-dev \
263+
libunwind-dev \
264+
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
265+
gstreamer1.0-plugins-base gstreamer1.0-plugins-good \
266+
gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly \
267+
gstreamer1.0-libav \
230268
gdb jq
231269
232270
# The libwebrtc artifact ships a hermetic libc++ built from LLVM trunk.
@@ -242,7 +280,7 @@ jobs:
242280
run: |
243281
set -eux
244282
brew update
245-
brew install cmake ninja protobuf abseil
283+
brew install cmake ninja protobuf abseil gstreamer
246284
247285
# ---------- Rust toolchain ----------
248286
- name: Install Rust (stable)
@@ -517,7 +555,12 @@ jobs:
517555
libprotobuf-dev protobuf-compiler \
518556
libabsl-dev \
519557
libcurl4-openssl-dev \
520-
libwayland-dev libdecor-0-dev
558+
libwayland-dev libdecor-0-dev \
559+
libunwind-dev \
560+
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
561+
gstreamer1.0-plugins-base gstreamer1.0-plugins-good \
562+
gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly \
563+
gstreamer1.0-libav
521564
pip install --break-system-packages gcovr
522565
523566
# The coverage build compiles the Rust FFI too, so it needs the same

‎CMakeLists.txt‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ include(warnings)
1818

1919
option(LIVEKIT_BUILD_EXAMPLES "Build LiveKit examples" OFF)
2020
option(LIVEKIT_BUILD_TESTS "Build LiveKit tests" OFF)
21+
option(LIVEKIT_ENABLE_CAPTURE "Build the Rust FFI with the capture feature (livekit-capture sources; links system GStreamer)" OFF)
2122

2223
# vcpkg is only used on Windows; Linux/macOS use system package managers
2324
if(WIN32)
@@ -86,6 +87,7 @@ set(FFI_PROTO_FILES
8687
${FFI_PROTO_DIR}/data_track.proto
8788
${FFI_PROTO_DIR}/rpc.proto
8889
${FFI_PROTO_DIR}/track_publication.proto
90+
${FFI_PROTO_DIR}/capture.proto
8991
)
9092
set(PROTO_BINARY_DIR ${LIVEKIT_BINARY_DIR}/generated)
9193
file(MAKE_DIRECTORY ${PROTO_BINARY_DIR})
@@ -167,6 +169,14 @@ set(GENERATED_BUILD_H "${LIVEKIT_ROOT_DIR}/include/livekit/build.h")
167169
set(GENERATED_BUILD_INFO_JSON "${LIVEKIT_BINARY_DIR}/build-info.json")
168170
set(RUST_ROOT ${LIVEKIT_ROOT_DIR}/client-sdk-rust)
169171

172+
# Cargo features for the Rust FFI build.
173+
set(LIVEKIT_CARGO_FEATURES "")
174+
set(LIVEKIT_CAPTURE_ENABLED 0)
175+
if(LIVEKIT_ENABLE_CAPTURE)
176+
set(LIVEKIT_CARGO_FEATURES "capture")
177+
set(LIVEKIT_CAPTURE_ENABLED 1)
178+
endif()
179+
170180
set(GIT_COMMIT "unknown")
171181
set(RUST_GIT_COMMIT "unknown")
172182
find_package(Git QUIET)
@@ -262,6 +272,11 @@ if(NOT CFG STREQUAL \"Debug\")
262272
list(APPEND ARGS --release)
263273
endif()
264274
275+
if(DEFINED CARGO_FEATURES AND NOT CARGO_FEATURES STREQUAL \"\")
276+
list(APPEND ARGS --features \"\${CARGO_FEATURES}\")
277+
message(STATUS \"[run_cargo.cmake] Cargo features: \${CARGO_FEATURES}\")
278+
endif()
279+
265280
if(DEFINED RUST_TARGET AND NOT RUST_TARGET STREQUAL \"\")
266281
list(APPEND ARGS --target \"\${RUST_TARGET}\")
267282
message(STATUS \"[run_cargo.cmake] Cross-compiling for target: \${RUST_TARGET}\")
@@ -378,6 +393,7 @@ add_custom_command(
378393
-DPROTOC_PATH=${Protobuf_PROTOC_EXECUTABLE}
379394
-DRUST_TARGET=${RUST_TARGET_TRIPLE}
380395
-DGCC_LIB_DIR=${GCC_LIB_DIR}
396+
-DCARGO_FEATURES=${LIVEKIT_CARGO_FEATURES}
381397
-P "${RUN_CARGO_SCRIPT}"
382398
WORKING_DIRECTORY "${RUST_ROOT}"
383399
DEPENDS ${RUST_SOURCES}
@@ -396,6 +412,8 @@ include(uniffi_cpp)
396412
add_library(livekit SHARED
397413
src/audio_frame.cpp
398414
src/audio_processing_module.cpp
415+
src/capture_source.cpp
416+
src/capture_source_internal.h
399417
src/audio_source.cpp
400418
src/audio_stream.cpp
401419
src/data_track_frame.cpp

‎CMakePresets.json‎

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@
214214
"cacheVariables": {
215215
"CMAKE_BUILD_TYPE": "Release",
216216
"LIVEKIT_BUILD_EXAMPLES": "ON",
217-
"LIVEKIT_BUILD_TESTS": "ON"
217+
"LIVEKIT_BUILD_TESTS": "ON",
218+
"LIVEKIT_ENABLE_CAPTURE": "ON"
218219
}
219220
},
220221
{
@@ -226,7 +227,8 @@
226227
"cacheVariables": {
227228
"CMAKE_BUILD_TYPE": "Debug",
228229
"LIVEKIT_BUILD_EXAMPLES": "ON",
229-
"LIVEKIT_BUILD_TESTS": "ON"
230+
"LIVEKIT_BUILD_TESTS": "ON",
231+
"LIVEKIT_ENABLE_CAPTURE": "ON"
230232
}
231233
},
232234
{
@@ -238,7 +240,8 @@
238240
"cacheVariables": {
239241
"CMAKE_BUILD_TYPE": "Release",
240242
"LIVEKIT_BUILD_EXAMPLES": "OFF",
241-
"LIVEKIT_BUILD_TESTS": "ON"
243+
"LIVEKIT_BUILD_TESTS": "ON",
244+
"LIVEKIT_ENABLE_CAPTURE": "ON"
242245
}
243246
},
244247
{
@@ -250,7 +253,8 @@
250253
"cacheVariables": {
251254
"CMAKE_BUILD_TYPE": "Debug",
252255
"LIVEKIT_BUILD_EXAMPLES": "OFF",
253-
"LIVEKIT_BUILD_TESTS": "ON"
256+
"LIVEKIT_BUILD_TESTS": "ON",
257+
"LIVEKIT_ENABLE_CAPTURE": "ON"
254258
}
255259
},
256260
{
@@ -262,7 +266,8 @@
262266
"cacheVariables": {
263267
"CMAKE_BUILD_TYPE": "Release",
264268
"LIVEKIT_BUILD_EXAMPLES": "ON",
265-
"LIVEKIT_BUILD_TESTS": "ON"
269+
"LIVEKIT_BUILD_TESTS": "ON",
270+
"LIVEKIT_ENABLE_CAPTURE": "ON"
266271
}
267272
},
268273
{
@@ -274,7 +279,8 @@
274279
"cacheVariables": {
275280
"CMAKE_BUILD_TYPE": "Debug",
276281
"LIVEKIT_BUILD_EXAMPLES": "ON",
277-
"LIVEKIT_BUILD_TESTS": "ON"
282+
"LIVEKIT_BUILD_TESTS": "ON",
283+
"LIVEKIT_ENABLE_CAPTURE": "ON"
278284
}
279285
},
280286
{
@@ -286,7 +292,8 @@
286292
"cacheVariables": {
287293
"CMAKE_BUILD_TYPE": "Release",
288294
"LIVEKIT_BUILD_EXAMPLES": "OFF",
289-
"LIVEKIT_BUILD_TESTS": "ON"
295+
"LIVEKIT_BUILD_TESTS": "ON",
296+
"LIVEKIT_ENABLE_CAPTURE": "ON"
290297
}
291298
},
292299
{
@@ -298,7 +305,8 @@
298305
"cacheVariables": {
299306
"CMAKE_BUILD_TYPE": "Debug",
300307
"LIVEKIT_BUILD_EXAMPLES": "OFF",
301-
"LIVEKIT_BUILD_TESTS": "ON"
308+
"LIVEKIT_BUILD_TESTS": "ON",
309+
"LIVEKIT_ENABLE_CAPTURE": "ON"
302310
}
303311
},
304312
{
@@ -310,7 +318,8 @@
310318
"cacheVariables": {
311319
"CMAKE_BUILD_TYPE": "Release",
312320
"LIVEKIT_BUILD_EXAMPLES": "ON",
313-
"LIVEKIT_BUILD_TESTS": "ON"
321+
"LIVEKIT_BUILD_TESTS": "ON",
322+
"LIVEKIT_ENABLE_CAPTURE": "ON"
314323
}
315324
},
316325
{
@@ -322,7 +331,8 @@
322331
"cacheVariables": {
323332
"CMAKE_BUILD_TYPE": "Debug",
324333
"LIVEKIT_BUILD_EXAMPLES": "ON",
325-
"LIVEKIT_BUILD_TESTS": "ON"
334+
"LIVEKIT_BUILD_TESTS": "ON",
335+
"LIVEKIT_ENABLE_CAPTURE": "ON"
326336
}
327337
},
328338
{
@@ -334,7 +344,8 @@
334344
"cacheVariables": {
335345
"CMAKE_BUILD_TYPE": "Release",
336346
"LIVEKIT_BUILD_EXAMPLES": "OFF",
337-
"LIVEKIT_BUILD_TESTS": "ON"
347+
"LIVEKIT_BUILD_TESTS": "ON",
348+
"LIVEKIT_ENABLE_CAPTURE": "ON"
338349
}
339350
},
340351
{
@@ -346,7 +357,8 @@
346357
"cacheVariables": {
347358
"CMAKE_BUILD_TYPE": "Debug",
348359
"LIVEKIT_BUILD_EXAMPLES": "OFF",
349-
"LIVEKIT_BUILD_TESTS": "ON"
360+
"LIVEKIT_BUILD_TESTS": "ON",
361+
"LIVEKIT_ENABLE_CAPTURE": "ON"
350362
}
351363
}
352364
],

‎build.h.in‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// Version injected by CMake (CI should set it). Defaults to 0.0.0 for dev builds.
88
#define LIVEKIT_BUILD_VERSION "@LIVEKIT_VERSION@"
99
#define LIVEKIT_BUILD_FLAVOR "cpp"
10+
#define LIVEKIT_CAPTURE_ENABLED @LIVEKIT_CAPTURE_ENABLED@
1011

1112
#ifdef DEBUG
1213
#define LIVEKIT_BUILD_SUFFIX "-debug"
@@ -18,4 +19,4 @@
1819
#define LIVEKIT_BUILD_DATE "@BUILD_DATE@"
1920
#define LIVEKIT_BUILD_COMMIT "@GIT_COMMIT@"
2021

21-
#define LIVEKIT_BUILD_VERSION_FULL LIVEKIT_BUILD_VERSION LIVEKIT_BUILD_SUFFIX
22+
#define LIVEKIT_BUILD_VERSION_FULL LIVEKIT_BUILD_VERSION LIVEKIT_BUILD_SUFFIX

‎client-sdk-rust‎

0 commit comments

Comments
 (0)