Screen sharing was slow mostly because every frame was copied and allocated several times on its way to the encoder: the PipeWire callback copied the mapped buffer into a new Vec, X11 copied the shared-memory segment, Windows copied twice, `to_i420` allocated fresh planes on one thread, and libvpx output was copied into Vec after Vec. Capture backends now hand each frame to a `FrameSink` on their own thread, with the pixels still in the capture buffer (`FrameRef`: borrowed planes with strides). `ScreenCapture::start_sink` is implemented by the test pattern (renders into one reused buffer), X11 (the MIT-SHM segment, cursor blended in place, monitor/window geometry looked up once a second instead of every frame), the portal and Windows Graphics Capture (the mapped staging texture with its row pitch); other backends get a forwarding default. `start` keeps working through a queue adapter. `FramePacer` caps frame rates by timestamps; sinks can change the cap while capturing (X11 and the test pattern follow, the portal renegotiates the frame rate). Portal: LINEAR DMA-BUFs are negotiated in addition to shared memory (mandatory modifier, fixated by us, `dataType` per buffer kind), mapped once per buffer and read between DMA_BUF_IOCTL_SYNC start/end. When reading them is slow (uncached VRAM), the stream renegotiates to shared memory. Tiled modifiers are not offered (needs a GPU import). The streaming path: - `workers::Workers`: a fork-join pool that allocates nothing per job. - `convert::Converter`: any stride, BGRx/BGRA/RGBx/RGBA (yuv's SIMD paths), I420 and NV12 into a caller's I420 frame, in row bands on all cores; handles buffers without padding after the last row. - `scale`: separable area-average downscaling (bilinear up), weights per size pair computed once, a 2x2 box fast path, row bands on the pool; `Pyramid` converts a capture once and derives every requested size from the nearest larger one, sharing equal sizes. - `pool::FramePool`: recycled `Arc<VideoFrame>`s; `handoff::Handoff`: a one-slot latest-wins atomic handoff that counts replaced frames. Codecs: `VideoEncoder::encode_with` hands out encoded frames borrowed from the encoder (libvpx's own buffer; OpenH264 into a reused buffer). libvpx: `cpu-used` adapts to the measured encode time against the frame interval (VP8 levels -10..-4, VP9 starting at 8 within 5..9), threads from all CPUs the frame size can use, VP8 token partitions and VP9 tile columns from the thread count and width, keyframes only on request, frame durations from timestamps (variable frame rate), `set_fps`, and `speed` for stats. A probe on the desktop test pattern showed VP8 speeds beyond -10 are no faster on screen content, only worse (about 3 dB PSNR). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
62 lines
2.5 KiB
TOML
62 lines
2.5 KiB
TOML
[package]
|
|
name = "voelin-media"
|
|
version = "0.1.0"
|
|
description = "Video frames, pixel conversion, video codecs (VP8/VP9, H.264, AV1) and screen / system-audio capture for streams."
|
|
edition.workspace = true
|
|
rust-version.workspace = true
|
|
license.workspace = true
|
|
repository.workspace = true
|
|
publish.workspace = true
|
|
|
|
[features]
|
|
default = ["vpx", "openh264", "openh264-download", "x11", "pipewire"]
|
|
# VP8 and VP9 through the system libvpx (pkg-config `vpx`).
|
|
vpx = ["dep:libvpx-native-sys"]
|
|
# H.264 through Cisco's prebuilt OpenH264 library, loaded at runtime. The
|
|
# OpenH264 source is never compiled in (see docs/media.md).
|
|
openh264 = ["dep:openh264"]
|
|
# Download of Cisco's OpenH264 binary over HTTPS with a SHA-256 check.
|
|
openh264-download = ["openh264", "dep:reqwest", "dep:bzip2", "dep:sha2"]
|
|
# AV1 decoding through the system libdav1d (pkg-config `dav1d` >= 1.3).
|
|
av1 = ["dep:dav1d"]
|
|
# X11 screen capture (Linux).
|
|
x11 = ["dep:x11rb", "dep:memmap2", "dep:rustix"]
|
|
# Wayland screen capture (ScreenCast portal + PipeWire, shared memory or
|
|
# LINEAR DMA-BUFs) and PipeWire system audio (Linux).
|
|
pipewire = ["dep:ashpd", "dep:pipewire", "dep:memmap2", "dep:rustix"]
|
|
# Conversion between `Codec` and `str0m::format::Codec`.
|
|
str0m = ["dep:str0m"]
|
|
|
|
[dependencies]
|
|
bzip2 = { version = "0.6.1", optional = true }
|
|
dav1d = { version = "0.11.1", optional = true }
|
|
libvpx-native-sys = { version = "5.0.17", optional = true }
|
|
openh264 = { version = "0.9.8", default-features = false, features = ["libloading"], optional = true }
|
|
reqwest = { version = "0.13.5", default-features = false, features = ["rustls"], optional = true }
|
|
sha2 = { version = "0.10.9", optional = true }
|
|
str0m = { version = "0.23.1", default-features = false, optional = true }
|
|
thiserror = "2.0.21"
|
|
tokio = { version = "1", features = ["sync"] }
|
|
tracing = "0.1.44"
|
|
yuv = "0.8.19"
|
|
|
|
[target.'cfg(target_os = "linux")'.dependencies]
|
|
ashpd = { version = "0.13.13", default-features = false, features = ["screencast", "tokio"], optional = true }
|
|
memmap2 = { version = "0.9.11", optional = true }
|
|
pipewire = { version = "0.10.1", optional = true }
|
|
rustix = { version = "1.1.5", features = ["fs"], optional = true }
|
|
x11rb = { version = "0.13.2", features = ["randr", "shm", "xfixes"], optional = true }
|
|
|
|
[target.'cfg(target_os = "android")'.dependencies]
|
|
ndk = { version = "0.9.0", default-features = false, features = ["media", "api-level-29"] }
|
|
|
|
[target.'cfg(windows)'.dependencies]
|
|
wasapi = "0.24.0"
|
|
windows-capture = "2.0.1"
|
|
|
|
[dev-dependencies]
|
|
tokio = { version = "1", features = ["macros", "rt", "rt-multi-thread", "time"] }
|
|
|
|
[lints]
|
|
workspace = true
|