Skip to content

Commit 2a98849

Browse files
build flag LIVEKIT_BUILD_CAPTURE sets LIVEKIT_CAPTURE_ENABLED macro
1 parent ebfe4a5 commit 2a98849

11 files changed

Lines changed: 47 additions & 40 deletions

File tree

‎AGENTS.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ To create an installable SDK bundle, use the same build command with
128128
`./build.sh release --bundle --prefix sdk-out/livekit-sdk`). On Windows, use
129129
`build.cmd release --bundle --prefix C:\path\to\livekit-sdk`.
130130

131+
The build scripts set `LIVEKIT_BUILD_CAPTURE`. The generated
132+
`LIVEKIT_CAPTURE_ENABLED` macro is 0 or 1 and supports `#if` checks in consumers.
133+
131134
Both build scripts accept `--capture` to enable GStreamer, pattern, and clock
132135
sources, and `--no-capture` to disable them. Test/all presets enable capture by
133136
default; normal and example presets disable it. Capture-enabled builds need

‎CMakeLists.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +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)
21+
option(LIVEKIT_BUILD_CAPTURE "Build the Rust FFI with the capture feature (livekit-capture sources; links system GStreamer)" OFF)
2222

2323
# vcpkg is only used on Windows; Linux/macOS use system package managers
2424
if(WIN32)
@@ -172,7 +172,7 @@ set(RUST_ROOT ${LIVEKIT_ROOT_DIR}/client-sdk-rust)
172172
# Cargo features for the Rust FFI build.
173173
set(LIVEKIT_CARGO_FEATURES "")
174174
set(LIVEKIT_CAPTURE_ENABLED 0)
175-
if(LIVEKIT_ENABLE_CAPTURE)
175+
if(LIVEKIT_BUILD_CAPTURE)
176176
set(LIVEKIT_CARGO_FEATURES "capture-gstreamer,capture-pattern,capture-clock")
177177
set(LIVEKIT_CAPTURE_ENABLED 1)
178178
endif()

‎CMakePresets.json‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
"cacheVariables": {
3333
"VCPKG_TARGET_TRIPLET": "x64-windows-static-md",
34-
"LIVEKIT_ENABLE_CAPTURE": "OFF"
34+
"LIVEKIT_BUILD_CAPTURE": "OFF"
3535
}
3636
},
3737
{
@@ -41,7 +41,7 @@
4141
"cacheVariables": {
4242
"LIVEKIT_USE_VCPKG": "OFF",
4343
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
44-
"LIVEKIT_ENABLE_CAPTURE": "OFF"
44+
"LIVEKIT_BUILD_CAPTURE": "OFF"
4545
},
4646
"condition": {
4747
"type": "equals",
@@ -56,7 +56,7 @@
5656
"cacheVariables": {
5757
"LIVEKIT_USE_VCPKG": "OFF",
5858
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
59-
"LIVEKIT_ENABLE_CAPTURE": "OFF"
59+
"LIVEKIT_BUILD_CAPTURE": "OFF"
6060
},
6161
"condition": {
6262
"type": "equals",
@@ -218,7 +218,7 @@
218218
"CMAKE_BUILD_TYPE": "Release",
219219
"LIVEKIT_BUILD_EXAMPLES": "ON",
220220
"LIVEKIT_BUILD_TESTS": "ON",
221-
"LIVEKIT_ENABLE_CAPTURE": "ON"
221+
"LIVEKIT_BUILD_CAPTURE": "ON"
222222
}
223223
},
224224
{
@@ -231,7 +231,7 @@
231231
"CMAKE_BUILD_TYPE": "Debug",
232232
"LIVEKIT_BUILD_EXAMPLES": "ON",
233233
"LIVEKIT_BUILD_TESTS": "ON",
234-
"LIVEKIT_ENABLE_CAPTURE": "ON"
234+
"LIVEKIT_BUILD_CAPTURE": "ON"
235235
}
236236
},
237237
{
@@ -244,7 +244,7 @@
244244
"CMAKE_BUILD_TYPE": "Release",
245245
"LIVEKIT_BUILD_EXAMPLES": "OFF",
246246
"LIVEKIT_BUILD_TESTS": "ON",
247-
"LIVEKIT_ENABLE_CAPTURE": "ON"
247+
"LIVEKIT_BUILD_CAPTURE": "ON"
248248
}
249249
},
250250
{
@@ -257,7 +257,7 @@
257257
"CMAKE_BUILD_TYPE": "Debug",
258258
"LIVEKIT_BUILD_EXAMPLES": "OFF",
259259
"LIVEKIT_BUILD_TESTS": "ON",
260-
"LIVEKIT_ENABLE_CAPTURE": "ON"
260+
"LIVEKIT_BUILD_CAPTURE": "ON"
261261
}
262262
},
263263
{
@@ -270,7 +270,7 @@
270270
"CMAKE_BUILD_TYPE": "Release",
271271
"LIVEKIT_BUILD_EXAMPLES": "ON",
272272
"LIVEKIT_BUILD_TESTS": "ON",
273-
"LIVEKIT_ENABLE_CAPTURE": "ON"
273+
"LIVEKIT_BUILD_CAPTURE": "ON"
274274
}
275275
},
276276
{
@@ -283,7 +283,7 @@
283283
"CMAKE_BUILD_TYPE": "Debug",
284284
"LIVEKIT_BUILD_EXAMPLES": "ON",
285285
"LIVEKIT_BUILD_TESTS": "ON",
286-
"LIVEKIT_ENABLE_CAPTURE": "ON"
286+
"LIVEKIT_BUILD_CAPTURE": "ON"
287287
}
288288
},
289289
{
@@ -296,7 +296,7 @@
296296
"CMAKE_BUILD_TYPE": "Release",
297297
"LIVEKIT_BUILD_EXAMPLES": "OFF",
298298
"LIVEKIT_BUILD_TESTS": "ON",
299-
"LIVEKIT_ENABLE_CAPTURE": "ON"
299+
"LIVEKIT_BUILD_CAPTURE": "ON"
300300
}
301301
},
302302
{
@@ -309,7 +309,7 @@
309309
"CMAKE_BUILD_TYPE": "Debug",
310310
"LIVEKIT_BUILD_EXAMPLES": "OFF",
311311
"LIVEKIT_BUILD_TESTS": "ON",
312-
"LIVEKIT_ENABLE_CAPTURE": "ON"
312+
"LIVEKIT_BUILD_CAPTURE": "ON"
313313
}
314314
},
315315
{
@@ -322,7 +322,7 @@
322322
"CMAKE_BUILD_TYPE": "Release",
323323
"LIVEKIT_BUILD_EXAMPLES": "ON",
324324
"LIVEKIT_BUILD_TESTS": "ON",
325-
"LIVEKIT_ENABLE_CAPTURE": "ON"
325+
"LIVEKIT_BUILD_CAPTURE": "ON"
326326
}
327327
},
328328
{
@@ -335,7 +335,7 @@
335335
"CMAKE_BUILD_TYPE": "Debug",
336336
"LIVEKIT_BUILD_EXAMPLES": "ON",
337337
"LIVEKIT_BUILD_TESTS": "ON",
338-
"LIVEKIT_ENABLE_CAPTURE": "ON"
338+
"LIVEKIT_BUILD_CAPTURE": "ON"
339339
}
340340
},
341341
{
@@ -348,7 +348,7 @@
348348
"CMAKE_BUILD_TYPE": "Release",
349349
"LIVEKIT_BUILD_EXAMPLES": "OFF",
350350
"LIVEKIT_BUILD_TESTS": "ON",
351-
"LIVEKIT_ENABLE_CAPTURE": "ON"
351+
"LIVEKIT_BUILD_CAPTURE": "ON"
352352
}
353353
},
354354
{
@@ -361,7 +361,7 @@
361361
"CMAKE_BUILD_TYPE": "Debug",
362362
"LIVEKIT_BUILD_EXAMPLES": "OFF",
363363
"LIVEKIT_BUILD_TESTS": "ON",
364-
"LIVEKIT_ENABLE_CAPTURE": "ON"
364+
"LIVEKIT_BUILD_CAPTURE": "ON"
365365
}
366366
}
367367
],

‎build.cmd‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ if defined LIVEKIT_VERSION (
144144
set "CMAKE_EXTRA_ARGS=-DLIVEKIT_VERSION=%LIVEKIT_VERSION%"
145145
echo ==^> Injecting LIVEKIT_VERSION=%LIVEKIT_VERSION%
146146
)
147-
if defined CAPTURE_OVERRIDE set "CMAKE_EXTRA_ARGS=%CMAKE_EXTRA_ARGS% -DLIVEKIT_ENABLE_CAPTURE=%CAPTURE_OVERRIDE%"
147+
if defined CAPTURE_OVERRIDE set "CMAKE_EXTRA_ARGS=%CMAKE_EXTRA_ARGS% -DLIVEKIT_BUILD_CAPTURE=%CAPTURE_OVERRIDE%"
148148
goto dispatch
149149

150150
:dispatch

‎build.h.in‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@
88
#define LIVEKIT_BUILD_VERSION "@LIVEKIT_VERSION@"
99
#define LIVEKIT_BUILD_FLAVOR "cpp"
1010

11-
namespace livekit {
12-
13-
/// @brief Whether the Rust FFI was built with capture-source support.
14-
inline constexpr bool kCaptureEnabled = "@LIVEKIT_CAPTURE_ENABLED@"[0] == '1';
15-
16-
} // namespace livekit
11+
/// @brief Whether the Rust FFI was built with capture-source support (0 or 1).
12+
#define LIVEKIT_CAPTURE_ENABLED @LIVEKIT_CAPTURE_ENABLED@
1713

1814
#ifdef DEBUG
1915
#define LIVEKIT_BUILD_SUFFIX "-debug"

‎build.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ configure() {
148148
echo "==> Configuring CMake (${BUILD_TYPE}) using preset ${PRESET}..."
149149
local -a extra_args=()
150150
if [[ -n "${CAPTURE_OVERRIDE:-}" ]]; then
151-
extra_args+=("-DLIVEKIT_ENABLE_CAPTURE=${CAPTURE_OVERRIDE}")
151+
extra_args+=("-DLIVEKIT_BUILD_CAPTURE=${CAPTURE_OVERRIDE}")
152152
fi
153153
if [[ -n "${LIVEKIT_VERSION}" ]]; then
154154
echo "==> Injecting LIVEKIT_VERSION=${LIVEKIT_VERSION}"

‎docs/building.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ Standard `debug`, `release`, and `*-examples` builds disable capture. The
358358
./build.sh release --capture --bundle --prefix sdk-out/livekit-sdk-capture
359359
```
360360

361+
The build scripts set `LIVEKIT_BUILD_CAPTURE`. The generated
362+
`LIVEKIT_CAPTURE_ENABLED` macro is 0 or 1 and supports `#if` checks in consumers.
363+
361364
On Windows, use `build.cmd release --capture --bundle --prefix sdk-out\livekit-sdk-capture`.
362365
Capture builds enable GStreamer, GPU test patterns, and the GPU wall clock.
363366
They require GStreamer development libraries at build time and its runtime

‎docs/capture-sources.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ them explicitly:
2525
```
2626

2727
On Windows, use `build.cmd release --capture --bundle --prefix sdk-out\livekit-sdk-capture`.
28-
Custom CMake configurations can set `LIVEKIT_ENABLE_CAPTURE=ON`. The build enables
28+
Custom CMake configurations can set `LIVEKIT_BUILD_CAPTURE=ON`. The build enables
2929
`capture-gstreamer`, `capture-pattern`, and `capture-clock` in the Rust FFI.
3030

3131
Release downloads with `-capture` in their names include these features, for
3232
example `livekit-sdk-macos-arm64-capture-<version>.tar.gz`. Standard release
33-
bundles have capture disabled. The generated `livekit::kCaptureEnabled` constant
33+
bundles have capture disabled. The generated numeric `LIVEKIT_CAPTURE_ENABLED` macro (0 or 1)
3434
and `share/livekit/build-info.json` describe the selected bundle's build features;
3535
they do not test whether a GPU or a requested GStreamer plugin is available.
3636

‎include/livekit/capture_source.h‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ struct CaptureResult {
160160
/// a track from @ref CaptureSource::videoSource(), merge application options
161161
/// through @ref CaptureSource::publishOptions(), then call @ref CaptureSource::start().
162162
///
163-
/// Requires a capture-enabled SDK build (`LIVEKIT_ENABLE_CAPTURE`), with
163+
/// Requires a capture-enabled SDK build (`LIVEKIT_BUILD_CAPTURE`), with
164164
/// `capture-gstreamer`, `capture-pattern`, and `capture-clock` Rust features.
165165
/// Otherwise creation fails.
166166
///
@@ -186,12 +186,19 @@ class LIVEKIT_API CaptureSource {
186186

187187
/// @brief Create the built-in test pattern capture source.
188188
///
189+
/// Completes asynchronously after Rust initializes the GPU renderer.
190+
/// Keep the future to overlap setup with other work, or await it immediately.
191+
///
189192
/// @param config Pattern source configuration.
190193
/// @return A future that resolves to the created capture source.
191194
/// @throws CaptureSourceError When awaiting the future if creation fails.
192195
static std::future<std::shared_ptr<CaptureSource>> create(PatternVideoSourceConfig config);
193196

194197
/// @brief Create the built-in wall clock capture source.
198+
///
199+
/// Completes asynchronously after Rust initializes the GPU renderer.
200+
/// Keep the future to overlap setup with other work, or await it immediately.
201+
///
195202
/// @param config Clock source configuration.
196203
/// @return A future that resolves to the created capture source.
197204
/// @throws CaptureSourceError When awaiting the future if creation fails.

‎src/tests/integration/test_capture_source.cpp‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
/// Publishes the built-in pattern and clock sources and verifies that a second
2020
/// participant receives video through the SFU without per-frame FFI traffic.
2121
///
22-
/// All of them require the Rust FFI built with the `capture` feature
23-
/// (-DLIVEKIT_ENABLE_CAPTURE=ON); otherwise they skip.
22+
/// All of them require the Rust FFI built with capture-source support
23+
/// (-DLIVEKIT_BUILD_CAPTURE=ON); otherwise they skip.
2424

2525
#include <livekit/capture_source.h>
2626

@@ -45,15 +45,13 @@ constexpr int kCaptureWidth = 1280;
4545
constexpr int kCaptureHeight = 720;
4646
constexpr std::uint32_t kCaptureFramerateFps = 30;
4747

48-
/// Skips the calling test when the FFI library was built without the capture
49-
/// feature. A feature-less FFI reports only a generic invalid handle, so this
50-
/// has to be decided at compile time rather than sniffed from an error string.
51-
#define SKIP_WITHOUT_CAPTURE_FEATURE() \
52-
do { \
53-
if constexpr (!kCaptureEnabled) { \
54-
GTEST_SKIP() << "livekit-ffi built without the 'capture' feature; configure with -DLIVEKIT_ENABLE_CAPTURE=ON"; \
55-
} \
56-
} while (false)
48+
// Decide from build metadata rather than interpreting source-creation errors.
49+
#if LIVEKIT_CAPTURE_ENABLED
50+
#define SKIP_WITHOUT_CAPTURE_FEATURE() ((void)0)
51+
#else
52+
#define SKIP_WITHOUT_CAPTURE_FEATURE() \
53+
GTEST_SKIP() << "livekit-ffi built without capture support; configure with -DLIVEKIT_BUILD_CAPTURE=ON"
54+
#endif
5755
5856
std::shared_ptr<CaptureSource> createCapture(bool clock) {
5957
if (clock) {

0 commit comments

Comments
 (0)