Skip to content

Commit 4a9cf68

Browse files
committed
video: add v4l2-decoder backend
Add new v4l2-decoder backend, that uses v4l2r [1] for interactions with the video device in the host. Specialized for Linux systems. [1] - https://github.com/Gnurou/v4l2r Signed-off-by: Albert Esteve <[email protected]>
1 parent aa77647 commit 4a9cf68

File tree

5 files changed

+928
-5
lines changed

5 files changed

+928
-5
lines changed

Cargo.lock

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

crates/video/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ edition = "2021"
1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1212

1313
[features]
14-
default = []
14+
default = ["v4l2-decoder"]
15+
v4l2-decoder = ["v4l2r", "nix"]
1516

1617
[dependencies]
1718
bitflags = "2.3.3"
@@ -29,7 +30,12 @@ virtio-bindings = "0.2.1"
2930
virtio-queue = "0.9"
3031
vm-memory = "0.12"
3132
vmm-sys-util = "0.11"
33+
nix = { version = "0.27.1", optional = true }
34+
v4l2r = { git = "https://github.com/Gnurou/v4l2r", rev = "532c316", optional = true }
3235

3336
[dev-dependencies]
37+
assert_matches = "1.5"
38+
rstest = "0.18.2"
39+
tempfile = "3.8.0"
3440
virtio-queue = { version = "0.9", features = ["test-utils"] }
3541
vm-memory = { version = "0.12", features = ["backend-mmap", "backend-atomic"] }

crates/video/src/vhu_video.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ impl convert::From<VuVideoError> for io::Error {
103103
pub(crate) enum BackendType {
104104
#[default]
105105
Null,
106+
#[cfg(feature = "v4l2-decoder")]
107+
V4L2Decoder,
106108
}
107109

108110
/// Virtio Video Configuration

crates/video/src/video_backends.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
mod null;
44

5+
#[cfg(feature = "v4l2-decoder")]
6+
mod v4l2_decoder;
7+
58
use self::null::NullBackend;
9+
#[cfg(feature = "v4l2-decoder")]
10+
use self::v4l2_decoder::V4L2Decoder;
611

712
use crate::stream::{ResourcePlane, Stream};
813
use crate::vhu_video::{BackendType, Result, VuVideoError};
@@ -78,9 +83,14 @@ pub(crate) fn alloc_video_backend(
7883
backend: BackendType,
7984
video_path: &Path,
8085
) -> Result<Box<dyn VideoBackend + Sync + Send>> {
81-
match backend {
82-
BackendType::Null => Ok(Box::new(
83-
NullBackend::new(video_path).map_err(|_| VuVideoError::AccessVideoDeviceFile)?,
84-
)),
86+
macro_rules! build_backend {
87+
($type:ident) => {
88+
Box::new($type::new(video_path).map_err(|_| VuVideoError::AccessVideoDeviceFile)?)
89+
};
8590
}
91+
Ok(match backend {
92+
BackendType::Null => build_backend!(NullBackend),
93+
#[cfg(feature = "v4l2-decoder")]
94+
BackendType::V4L2Decoder => build_backend!(V4L2Decoder),
95+
})
8696
}

0 commit comments

Comments
 (0)