Skip to content

Commit d0a00fb

Browse files
kixelatedclaude
andauthored
feat(moq-video): reintroduce VAAPI via discord/cros-codecs + NV12 surface upload (#1720)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent e13be2c commit d0a00fb

10 files changed

Lines changed: 460 additions & 38 deletions

File tree

Cargo.lock

Lines changed: 139 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,9 @@ strip = true
109109
# doesn't have that feature yet, so consume a fork branch until it's merged.
110110
[patch.crates-io]
111111
nvidia-video-codec-sdk = { git = "https://github.com/kixelated/nvidia-video-codec-sdk.git", branch = "dynamic-loading" }
112+
# moq-video's `vaapi` feature uses discord/cros-codecs (`vaapi_dlopen`), which
113+
# pulls cros-libva 0.0.13. The `dlopen` feature it needs (load libva at runtime
114+
# so a vaapi-enabled binary still links without libva-dev and still loads on a
115+
# libva-less machine, falling back to software) lives only on discord's fork, so
116+
# point the published 0.0.13 at it. Drop once `dlopen` is upstreamed.
117+
cros-libva = { git = "https://github.com/discord/cros-libva.git", branch = "discord-0.0.13" }

deny.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,12 @@ allow-registry = ["https://github.com/rust-lang/crates.io-index"]
7070
# moq-video patches nvidia-video-codec-sdk to a fork that adds dlopen
7171
# (`dynamic-loading`); see the root Cargo.toml [patch.crates-io]. Drop this once
7272
# the feature is upstreamed and the patch is removed.
73-
allow-git = ["https://github.com/kixelated/nvidia-video-codec-sdk"]
73+
#
74+
# The `vaapi` feature pulls discord/cros-codecs (the maintained fork: cros-libva
75+
# 0.0.13 + a hardened H.264 VAAPI encoder) and patches cros-libva to discord's
76+
# fork for the `dlopen` feature. Drop these once `dlopen` is upstreamed.
77+
allow-git = [
78+
"https://github.com/kixelated/nvidia-video-codec-sdk",
79+
"https://github.com/discord/cros-codecs",
80+
"https://github.com/discord/cros-libva",
81+
]

doc/bin/cli.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ moq-cli publish --url https://relay.example.com --broadcast cam.hang capture --n
9090

9191
Video capture uses a native per-platform backend (AVFoundation on macOS, V4L2 on
9292
Linux, Media Foundation on Windows) and picks a hardware H.264 encoder
93-
(VideoToolbox on macOS, NVENC on Linux NVIDIA) when one is present, falling back
94-
to the built-in software encoder (openh264); force either with `--hardware` /
95-
`--software`. `--camera` takes a bare integer as a device index, otherwise a
93+
(VideoToolbox on macOS, NVENC on Linux NVIDIA, VAAPI on Linux Intel/AMD) when one
94+
is present, falling back to the built-in software encoder (openh264); force either
95+
with `--hardware` / `--software`. `--camera` takes a bare integer as a device index, otherwise a
9696
device path (Linux) or name (a friendly-name substring on Windows, the
9797
AVFoundation `uniqueID` on macOS). Audio capture uses cpal (CoreAudio / WASAPI /
9898
ALSA) and encodes Opus.

flake.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@
104104
# cpal's `alsa-sys` (moq-audio `capture` feature) links libasound on
105105
# Linux via pkg-config; macOS uses CoreAudio, so no dep there.
106106
pkgs.alsa-lib
107+
# moq-video `vaapi` feature: cros-libva runs bindgen against the libva
108+
# headers at build time (found via pkg-config), even though libva is
109+
# dlopen'd at runtime (`vaapi_dlopen`). macOS has no VAAPI.
110+
pkgs.libva
107111
];
108112

109113
# JavaScript dependencies

rs/moq-video/Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,24 @@ doctest = false
2424
# driver, falling back to software (see backend::open). `cuda-12020` pins the CUDA
2525
# API version so the build needs no CUDA toolkit.
2626
nvenc = ["dep:nvidia-video-codec-sdk", "nvidia-video-codec-sdk/dynamic-loading", "cudarc/fallback-dynamic-loading", "cudarc/cuda-12020"]
27+
# Intel/AMD VAAPI hardware encoder (Linux). Off by default; enable for a build
28+
# that should use VAAPI where present. Everything is dlopen'd at runtime:
29+
# discord/cros-codecs's `vaapi_dlopen` resolves libva through the cros-libva
30+
# `dlopen` feature (a fork feature, see the root [patch.crates-io]). So a
31+
# vaapi-enabled binary still links on a libva-less builder and still loads on
32+
# machines without libva, falling back to software (see backend::open). The
33+
# build still needs libva *headers* for bindgen (provided by the nix devShell).
34+
vaapi = ["dep:cros-codecs"]
2735

2836
[dependencies]
2937
anyhow = "1"
3038
bytes = "1"
39+
# VAAPI H.264 encoder + zero-copy dmabuf import, gated behind `vaapi` + a linux
40+
# cfg. discord's fork is the maintained one: cros-libva 0.0.13 so it builds
41+
# against libva >= 2.23 (published cros-codecs pins the broken 0.0.12), plus a
42+
# hardened H.264 encoder (packed SPS/PPS + slice headers, frame_num, rate
43+
# control). `vaapi_dlopen` loads libva at runtime.
44+
cros-codecs = { git = "https://github.com/discord/cros-codecs.git", branch = "discord-0.0.5", optional = true, default-features = false, features = ["vaapi_dlopen"] }
3145
cudarc = { version = "0.19", optional = true, default-features = false, features = ["driver"] }
3246
moq-mux = { workspace = true }
3347
moq-net = { workspace = true }

0 commit comments

Comments
 (0)