Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/capture-source-device-v4l2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
livekit-capture: minor
---

Add Linux camera capture through V4L2.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions livekit-capture/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ source-device = [
"objc2-foundation/NSValue",
"objc2-foundation/NSString",
"objc2-foundation/objc2-core-foundation",
# Linux backend
"dep:image",
"dep:libc",
"dep:v4l",
]
source-pattern = ["dep:pollster", "dep:wgpu", "dep:yuv-sys"]

Expand Down Expand Up @@ -115,3 +119,8 @@ objc2-av-foundation = { version = "0.3.2", default-features = false, optional =
objc2-core-media = { version = "0.3.2", default-features = false, optional = true }
objc2-core-video = { version = "0.3.2", default-features = false, optional = true }
objc2-foundation = { version = "0.3.2", default-features = false, features = ["std"], optional = true }

[target.'cfg(target_os = "linux")'.dependencies]
image = { workspace = true, optional = true }
libc = { version = "0.2", optional = true }
v4l = { version = "0.14", default-features = false, features = ["v4l2"], optional = true }
14 changes: 9 additions & 5 deletions livekit-capture/src/sources/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@

#[cfg(target_os = "macos")]
mod avfoundation;
#[cfg(target_os = "macos")]
#[cfg(any(target_os = "macos", target_os = "linux"))]
mod timestamp;
#[cfg(target_os = "linux")]
mod v4l2;

#[cfg(target_os = "macos")]
use avfoundation as backend;
#[cfg(not(target_os = "macos"))]
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
use unsupported as backend;
#[cfg(target_os = "linux")]
use v4l2 as backend;

use std::fmt;

Expand Down Expand Up @@ -404,7 +408,7 @@ pub enum DeviceVideoSourceError {

/// Builds the packet-trailer metadata that device frames are pre-filled
/// with. A metadata callback set on the pump takes precedence.
#[cfg(target_os = "macos")]
#[cfg(any(target_os = "macos", target_os = "linux"))]
fn capture_frame_metadata(
capture_wall_time_us: u64,
) -> livekit::webrtc::video_frame::FrameMetadata {
Expand All @@ -417,7 +421,7 @@ fn capture_frame_metadata(

/// Validates the platform-neutral parts of a configuration; `supported`
/// reports whether the backend can deliver a frame format.
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
#[cfg_attr(not(any(target_os = "macos", target_os = "linux")), allow(dead_code))]
fn validate_config(
config: &DeviceVideoSourceConfig,
supported: fn(DeviceFrameFormat) -> bool,
Expand Down Expand Up @@ -479,7 +483,7 @@ fn validate_config(
}

/// Stub backend for platforms without device capture.
#[cfg(not(target_os = "macos"))]
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
mod unsupported {
use livekit::webrtc::video_frame::BoxVideoFrame;

Expand Down
Loading
Loading