Skip to content

Commit b69e0d1

Browse files
committed
Linux hardware acceleration build fixes
Remove the use_vaapi and use_nvidia Cargo features. Instead: Always require libva on x86 Linux, checked with pkg-config. If cuda.h exists, build with NVidia hardware acceleration support. If you don't have an NVidia GPU, you probably don't have the CUDA Toolkit installed, so the default build failed before. The only reason to have the CUDA Toolkit installed if you don't have an NVidia GPU is if you're building a binary that might be used on machines with an NVidia GPU, which isn't necessary for development. Also, allow specifying a non-default path for the CUDA Toolkit with the CUDA_HOME environment variable.
1 parent 68b0291 commit b69e0d1

File tree

4 files changed

+36
-20
lines changed

4 files changed

+36
-20
lines changed

examples/wgpu_room/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ tracing = ["console-subscriber", "tokio/tracing"]
1111
[dependencies]
1212
tokio = { version = "1", features = ["full", "parking_lot"] }
1313
livekit = { workspace = true, features = ["rustls-tls-native-roots"]}
14-
webrtc-sys = { workspace = true, features = [ "use_vaapi", "use_nvidia" ] }
14+
webrtc-sys = { workspace = true }
1515
futures = "0.3"
1616
winit = { version = "0.30.11", features = [ "android-native-activity" ] }
1717
parking_lot = { version = "0.12.1", features = ["deadlock_detection"] }

livekit-ffi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ tracing = ["tokio/tracing", "console-subscriber"]
2020

2121
[dependencies]
2222
livekit = { workspace = true }
23-
webrtc-sys = { workspace = true , features = [ "use_vaapi", "use_nvidia" ]}
23+
webrtc-sys = { workspace = true }
2424
soxr-sys = { workspace = true }
2525
imgproc = { workspace = true }
2626
livekit-protocol = { workspace = true }

webrtc-sys/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ repository = "https://github.com/livekit/client-sdk-rust"
99

1010
[features]
1111
default = []
12-
use_vaapi = []
13-
use_nvidia = []
1412

1513
[dependencies]
1614
cxx = "1.0"
@@ -21,6 +19,7 @@ webrtc-sys-build = { workspace = true }
2119
cxx-build = "1.0"
2220
glob = "0.3"
2321
cc = "1.0"
22+
pkg-config = "0.3.22"
2423

2524
[dev-dependencies]
2625
env_logger = "0.10"

webrtc-sys/build.rs

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -153,22 +153,38 @@ fn main() {
153153
println!("cargo:rustc-link-lib=dylib=pthread");
154154
println!("cargo:rustc-link-lib=dylib=m");
155155

156-
match target_arch.as_str() {
157-
"x86_64" => {
158-
#[cfg(feature = "use_vaapi")]
159-
builder
160-
.file("src/vaapi/vaapi_display_drm.cpp")
161-
.file("src/vaapi/vaapi_h264_encoder_wrapper.cpp")
162-
.file("src/vaapi/vaapi_encoder_factory.cpp")
163-
.file("src/vaapi/h264_encoder_impl.cpp")
164-
.file("src/vaapi/implib/libva-drm.so.init.c")
165-
.file("src/vaapi/implib/libva-drm.so.tramp.S")
166-
.file("src/vaapi/implib/libva.so.init.c")
167-
.file("src/vaapi/implib/libva.so.tramp.S")
168-
.flag("-DUSE_VAAPI_VIDEO_CODEC=1");
169-
170-
#[cfg(feature = "use_nvidia")]
156+
let x86 = target_arch == "x86_64" || target_arch == "i686";
157+
let arm = target_arch == "aarch64" || target_arch.contains("arm");
158+
159+
if x86 {
160+
// Do not use pkg_config::probe_library because libva is dlopened
161+
// and pkg_config::probe_library would link it.
162+
let libva_include = pkg_config::get_variable("libva", "includedir")
163+
.expect("libva development headers not found");
164+
builder
165+
.include(libva_include)
166+
.file("src/vaapi/vaapi_display_drm.cpp")
167+
.file("src/vaapi/vaapi_h264_encoder_wrapper.cpp")
168+
.file("src/vaapi/vaapi_encoder_factory.cpp")
169+
.file("src/vaapi/h264_encoder_impl.cpp")
170+
.file("src/vaapi/implib/libva-drm.so.init.c")
171+
.file("src/vaapi/implib/libva-drm.so.tramp.S")
172+
.file("src/vaapi/implib/libva.so.init.c")
173+
.file("src/vaapi/implib/libva.so.tramp.S")
174+
.flag("-DUSE_VAAPI_VIDEO_CODEC=1");
175+
}
176+
177+
if x86 || arm {
178+
let cuda_home = PathBuf::from(match env::var("CUDA_HOME") {
179+
Ok(p) => p,
180+
Err(_) => "/usr/local/cuda".to_owned(),
181+
});
182+
let cuda_include_dir = cuda_home.join("include");
183+
184+
// libcuda and libnvcuvid are dlopened, so do not link them.
185+
if cuda_include_dir.join("cuda.h").exists() {
171186
builder
187+
.include(cuda_include_dir)
172188
.flag("-I/usr/local/cuda/include")
173189
.flag("-Isrc/nvidia/NvCodec/include")
174190
.flag("-Isrc/nvidia/NvCodec/NvCodec")
@@ -186,8 +202,9 @@ fn main() {
186202
.file("src/nvidia/implib/libnvcuvid.so.tramp.S")
187203
.flag("-Wno-deprecated-declarations")
188204
.flag("-DUSE_NVIDIA_VIDEO_CODEC=1");
205+
} else {
206+
println!("cargo:warning=cuda.h not found; building without hardware accelerated video codec support for NVidia GPUs");
189207
}
190-
_ => {}
191208
}
192209

193210
builder.flag("-Wno-changes-meaning").flag("-std=c++20");

0 commit comments

Comments
 (0)