Skip to content

Commit 553047a

Browse files
authored
chore: Optional flags for video hw codec. (#701)
* chore: Optional flags for video hw codec. * Update Cargo.toml * enable hw codec for examples/wgpu_room.
1 parent ac1952f commit 553047a

File tree

7 files changed

+31
-9
lines changed

7 files changed

+31
-9
lines changed

examples/wgpu_room/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ tracing = ["console-subscriber", "tokio/tracing"]
1010
[dependencies]
1111
tokio = { version = "1", features = ["full", "parking_lot"] }
1212
livekit = { path = "../../livekit", features = ["native-tls"] }
13+
webrtc-sys = { path = "../../webrtc-sys", features = [ "use_vaapi", "use_nvidia" ] }
1314
futures = "0.3"
1415
winit = "0.30.11"
1516
parking_lot = { version = "0.12.1", features = ["deadlock_detection"] }

livekit-ffi/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ tracing = ["tokio/tracing", "console-subscriber"]
1919

2020
[dependencies]
2121
livekit = { workspace = true }
22+
webrtc-sys = { workspace = true , features = [ "use_vaapi", "use_nvidia" ]}
2223
soxr-sys = { workspace = true }
2324
imgproc = { workspace = true }
2425
livekit-protocol = { workspace = true }

webrtc-sys/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ license = "Apache-2.0"
77
description = "Unsafe bindings to libwebrtc"
88
repository = "https://github.com/livekit/client-sdk-rust"
99

10+
[features]
11+
default = []
12+
use_vaapi = []
13+
use_nvidia = []
14+
1015
[dependencies]
1116
cxx = "1.0"
1217
log = "0.4"

webrtc-sys/build.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ fn main() {
155155

156156
match target_arch.as_str() {
157157
"x86_64" => {
158+
#[cfg(feature = "use_vaapi")]
158159
builder
159160
.file("src/vaapi/vaapi_display_drm.cpp")
160161
.file("src/vaapi/vaapi_h264_encoder_wrapper.cpp")
@@ -163,8 +164,10 @@ fn main() {
163164
.file("src/vaapi/implib/libva-drm.so.init.c")
164165
.file("src/vaapi/implib/libva-drm.so.tramp.S")
165166
.file("src/vaapi/implib/libva.so.init.c")
166-
.file("src/vaapi/implib/libva.so.tramp.S");
167+
.file("src/vaapi/implib/libva.so.tramp.S")
168+
.flag("-DUSE_VAAPI_VIDEO_CODEC=1");
167169

170+
#[cfg(feature = "use_nvidia")]
168171
builder
169172
.flag("-I/usr/local/cuda/include")
170173
.flag("-Isrc/nvidia/NvCodec/include")
@@ -181,7 +184,8 @@ fn main() {
181184
.file("src/nvidia/implib/libcuda.so.tramp.S")
182185
.file("src/nvidia/implib/libnvcuvid.so.init.c")
183186
.file("src/nvidia/implib/libnvcuvid.so.tramp.S")
184-
.flag("-Wno-deprecated-declarations");
187+
.flag("-Wno-deprecated-declarations")
188+
.flag("-DUSE_NVIDIA_VIDEO_CODEC=1");
185189
}
186190
_ => {}
187191
}

webrtc-sys/src/video_decoder_factory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include "livekit/android.h"
3636
#endif
3737

38-
#if defined(__linux__) && defined(__x86_64__) && !defined(WEBRTC_ANDROID)
38+
#if defined(USE_NVIDIA_VIDEO_CODEC)
3939
#include "nvidia/nvidia_decoder_factory.h"
4040
#endif
4141

@@ -50,7 +50,7 @@ VideoDecoderFactory::VideoDecoderFactory() {
5050
factories_.push_back(CreateAndroidVideoDecoderFactory());
5151
#endif
5252

53-
#if defined(__linux__) && defined(__x86_64__) && !defined(WEBRTC_ANDROID)
53+
#if defined(USE_NVIDIA_VIDEO_CODEC)
5454
if (webrtc::NvidiaVideoDecoderFactory::IsSupported()) {
5555
factories_.push_back(std::make_unique<webrtc::NvidiaVideoDecoderFactory>());
5656
}

webrtc-sys/src/video_encoder_factory.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@
3737
#include "livekit/android.h"
3838
#endif
3939

40-
#if defined(__linux__) && defined(__x86_64__) && !defined(WEBRTC_ANDROID)
40+
#if defined(USE_NVIDIA_VIDEO_CODEC)
4141
#include "nvidia/nvidia_encoder_factory.h"
42+
#endif
43+
44+
#if defined(USE_VAAPI_VIDEO_CODEC)
4245
#include "vaapi/vaapi_encoder_factory.h"
4346
#endif
4447

@@ -63,11 +66,19 @@ VideoEncoderFactory::InternalFactory::InternalFactory() {
6366
factories_.push_back(CreateAndroidVideoEncoderFactory());
6467
#endif
6568

66-
#if defined(__linux__) && defined(__x86_64__) && !defined(WEBRTC_ANDROID)
69+
#if defined(USE_NVIDIA_VIDEO_CODEC)
6770
if (webrtc::NvidiaVideoEncoderFactory::IsSupported()) {
6871
factories_.push_back(std::make_unique<webrtc::NvidiaVideoEncoderFactory>());
69-
} else if (webrtc::VAAPIVideoEncoderFactory::IsSupported()) {
70-
factories_.push_back(std::make_unique<webrtc::VAAPIVideoEncoderFactory>());
72+
} else {
73+
#endif
74+
75+
#if defined(USE_VAAPI_VIDEO_CODEC)
76+
if (webrtc::VAAPIVideoEncoderFactory::IsSupported()) {
77+
factories_.push_back(std::make_unique<webrtc::VAAPIVideoEncoderFactory>());
78+
}
79+
#endif
80+
81+
#if defined(USE_NVIDIA_VIDEO_CODEC)
7182
}
7283
#endif
7384
}

yuv-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
77
description = "libyuv bindings"
88

99
[build-dependencies]
10-
bindgen = "0.69"
10+
bindgen = "0.72.1"
1111
cc = "1.0"
1212
regex = "1"
1313
rayon = "1.8"

0 commit comments

Comments
 (0)