Skip to content

Commit

Permalink
video: add v4l2-decoder backend
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
aesteve-rh committed Sep 18, 2023
1 parent c335a1a commit dbdd2de
Show file tree
Hide file tree
Showing 5 changed files with 934 additions and 5 deletions.
59 changes: 59 additions & 0 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion crates/video/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = []
default = ["v4l2-decoder"]
v4l2-decoder = ["v4l2r", "nix"]

[dependencies]
bitflags = "2.3.3"
Expand All @@ -33,5 +34,8 @@ nix = { version = "0.24.0", optional = true }
v4l2r = { git = "https://github.com/Gnurou/v4l2r", rev = "f3353c9", optional = true }

[dev-dependencies]
assert_matches = "1.5"
rstest = "0.18.2"
tempfile = "3.8.0"
virtio-queue = { version = "0.9", features = ["test-utils"] }
vm-memory = { version = "0.12", features = ["backend-mmap", "backend-atomic"] }
2 changes: 2 additions & 0 deletions crates/video/src/vhu_video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ impl convert::From<VuVideoError> for io::Error {
pub(crate) enum BackendType {
#[default]
Null,
#[cfg(feature = "v4l2-decoder")]
V4L2Decoder,
}

/// Virtio Video Configuration
Expand Down
18 changes: 14 additions & 4 deletions crates/video/src/video_backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

mod null;

#[cfg(feature = "v4l2-decoder")]
mod v4l2_decoder;

use self::null::NullBackend;
#[cfg(feature = "v4l2-decoder")]
use self::v4l2_decoder::V4L2Decoder;

use crate::stream::{ResourcePlane, Stream};
use crate::vhu_video::{BackendType, Result, VuVideoError};
Expand Down Expand Up @@ -78,9 +83,14 @@ pub(crate) fn alloc_video_backend(
backend: BackendType,
video_path: &Path,
) -> Result<Box<dyn VideoBackend + Sync + Send>> {
match backend {
BackendType::Null => Ok(Box::new(
NullBackend::new(video_path).map_err(|_| VuVideoError::AccessVideoDeviceFile)?,
)),
macro_rules! build_backend {
($type:ident) => {
Box::new($type::new(video_path).map_err(|_| VuVideoError::AccessVideoDeviceFile)?)
};
}
Ok(match backend {
BackendType::Null => build_backend!(NullBackend),
#[cfg(feature = "v4l2-decoder")]
BackendType::V4L2Decoder => build_backend!(V4L2Decoder),
})
}
Loading

0 comments on commit dbdd2de

Please sign in to comment.