generated from rust-vmm/crate-template
-
Notifications
You must be signed in to change notification settings - Fork 81
Add vhost-device-media backend for virtio-media #944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
aesteve-rh
wants to merge
7
commits into
rust-vmm:main
Choose a base branch
from
aesteve-rh:virtio-media
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
82a9d4f
vhost-device-media: add virtio-media device
aesteve-rh 50b75b2
vhost-device-media: add shared memory allocator
aesteve-rh d199cc6
vhost-device-media: add FFmpeg decoder backend
aesteve-rh 036aeb1
vhost-device-media: split backends into cargo features
aesteve-rh ab17b10
vhost-device-media: add unit tests
aesteve-rh 0444a4d
vhost-device-media: refactor structure to lib
aesteve-rh 4a6c56d
vhost-device-media: device type resolve helper
aesteve-rh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Changelog | ||
| ## Unreleased | ||
|
|
||
| ### Added | ||
|
|
||
| ### Changed | ||
|
|
||
| ### Fixed | ||
|
|
||
| ### Deprecated | ||
|
|
||
| ## v0.1.0 | ||
|
|
||
| First release |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| [package] | ||
| name = "vhost-device-media" | ||
| version = "0.1.0" | ||
| authors = ["Albert Esteve <aesteve@redhat.com>"] | ||
| description = "A virtio-media device using the vhost-user protocol." | ||
| repository = "https://github.com/rust-vmm/vhost-device" | ||
| keywords = ["vhost", "media", "virt", "backend"] | ||
| license = "Apache-2.0 OR BSD-3-Clause" | ||
| edition = "2021" | ||
|
|
||
| # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
|
||
| [features] | ||
| default = ["v4l2-proxy"] | ||
| v4l2-proxy = ["v4l2r"] | ||
| ffmpeg = ["v4l2r", "virtio-media-ffmpeg-decoder"] | ||
| simple-capture = ["v4l2r"] | ||
|
|
||
| [dependencies] | ||
| bitflags = "2.6.0" | ||
| clap = { version = "4.5.20", features = ["derive"] } | ||
| env_logger = "0.11.5" | ||
| epoll = "4.3.3" | ||
| num_enum = "0.7.3" | ||
| log = "0.4.22" | ||
| libc = "0.2.162" | ||
| thiserror = "2.0.3" | ||
| anyhow = "1.0.93" | ||
| futures-executor = { version = "0.3.31", features = ["thread-pool"] } | ||
| vhost = { git = "https://github.com/rust-vmm/vhost", branch = "main", features = ["vhost-user-backend"] } | ||
| vhost-user-backend = { git = "https://github.com/rust-vmm/vhost", branch = "main"} | ||
| virtio-bindings = "0.2.5" | ||
| virtio-queue = "0.17.0" | ||
| vm-memory = { version = "0.17.1", features = ["backend-mmap", "backend-atomic"] } | ||
| vmm-sys-util = "0.15.0" | ||
| ref-cast = "1.0.23" | ||
| virtio-media = { git = "https://github.com/chromeos/virtio-media", rev = "c6cc93a"} | ||
| virtio-media-ffmpeg-decoder = { git = "https://github.com/chromeos/virtio-media/", package = "virtio-media-ffmpeg-decoder", rev = "c6cc93a", optional = true} | ||
| v4l2r = { git = "https://github.com/Gnurou/v4l2r", rev = "7b44138", optional = true } | ||
| zerocopy = { version = "0.8.27", features = ["derive"] } | ||
|
|
||
| [dev-dependencies] | ||
| assert_matches = "1.5.0" | ||
| rstest = "0.26.1" | ||
| tempfile = "3.14.0" | ||
| virtio-queue = { version = "0.17.0", features = ["test-utils"] } | ||
| vm-memory = { version = "0.17.1", features = ["backend-mmap", "backend-atomic"] } | ||
| zerocopy = { version = "0.8.27", features = ["derive"] } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../LICENSE-APACHE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../LICENSE-BSD-3-Clause |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # vhost-device-media | ||
|
|
||
| A virtio-media device using the vhost-user protocol. | ||
|
|
||
| This crate provides a vhost-user backend for virtio-media devices. It is an implementation of the VIRTIO Media Device specification, which can be found on [virtio-spec v1.4](https://docs.oasis-open.org/virtio/virtio/v1.4/virtio-v1.4.html). The purpose of this device is to provide a standardized way for virtual machines to access media devices on the host. | ||
|
|
||
| The low-level implementation of the virtio-media protocol is provided by the device crate from the [virtio-media](https://github.com/chromeos/virtio-media) repository. | ||
|
|
||
| ## Synopsis | ||
|
|
||
| ```console | ||
| vhost-device-media --socket-path <SOCKET> --v4l2-device <V4L2_DEVICE> --backend <BACKEND> | ||
| ``` | ||
|
|
||
| ## Description | ||
|
|
||
|
|
||
| ## Options | ||
|
|
||
| ```text | ||
| --socket-path <SOCKET> | ||
| vhost-user Unix domain socket path | ||
|
|
||
| --v4l2-device <V4L2_DEVICE> | ||
| Path to the V4L2 media device file. Defaults to /dev/video0. | ||
|
|
||
| --backend <BACKEND> | ||
| Media backend to be used. [possible values: simple-capture, v4l2-proxy, ffmpeg-decoder] | ||
|
|
||
| -h, --help | ||
| Print help | ||
|
|
||
| -V, --version | ||
| Print version | ||
| ``` | ||
|
|
||
| ## Examples | ||
|
|
||
| Launch the backend on the host machine: | ||
|
|
||
| ```shell | ||
| host# vhost-device-media --socket-path /tmp/media.sock --v4l2-device /dev/video0 --backend v4l2-proxy | ||
| ``` | ||
|
|
||
| With QEMU, you can add a `virtio` device that uses the backend's socket with the following flags: | ||
|
|
||
| ```text | ||
| -chardev socket,id=vmedia,path=/tmp/media.sock \ | ||
| -device vhost-user-media-pci,chardev=vmedia,id=media | ||
| ``` | ||
|
|
||
| ## Features | ||
|
|
||
| The following backends are available: | ||
|
|
||
| - **simple-capture**: A simple video capture device generating a pattern, purely software-based and thus not requiring any kind of hardware. Can be used for testing purposes. | ||
| - **v4l2-proxy**: A proxy device for host V4L2 devices, i.e. a device allowing to expose a host V4L2 device to the guest almost as-is. | ||
| - **ffmpeg-decoder**: A software-based video decoder backend using FFmpeg. | ||
|
|
||
| ## Limitations | ||
|
|
||
| This crate is currently under active development. | ||
|
|
||
| - **dmabuf memory sharing**: DMA buffer (dmabuf) support for zero-copy memory sharing between guest and host and through multiple virtio devices using VirtIO shared objects is not yet implemented. Currently, all memory operations use regular memory mappings. | ||
| - **Kernel driver availability**: The virtio-media kernel driver is still being upstreamed to the Linux kernel and may not be available in all kernel versions. Check [virtio-media](https://github.com/chromeos/virtio-media) for instructions on how to build the OOT module. | ||
|
|
||
| ## License | ||
|
|
||
| This project is licensed under either of | ||
|
|
||
| - [Apache License](http://www.apache.org/licenses/LICENSE-2.0), Version 2.0 | ||
| - [BSD-3-Clause License](https://opensource.org/licenses/BSD-3-Clause) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v4l2randvirtio-mediaare on crates.io, are they behind this revision? Maybe we can request new releases (and also publishing ofvirtio-media-ffmpeg-decoder)Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with
virtio-mediafrom crates.io is thatffmpeg-decoderhas the dependency set with a relative path (https://github.com/chromeos/virtio-media/blob/main/extras/ffmpeg-decoder/Cargo.toml#L13).Cargo treats these as different crates, so
VideoDecoderexpectsVideoDecoderBackendfrom crates.io 0.0.7, butFfmpegDecoderimplementsVideoDecoderBackendfrom the git version. Rust sees these as different traits, causingE0277: the trait bound FfmpegDecoder: VideoDecoderBackend is not satisfied.I did send this PR some time ago: chromeos/virtio-media#19
But I must confess I did not follow up. And maybe I did not explain the issue good enough.
Maybe I can use the crates.io version and patch it in the root Cargo.toml, as a workaround.
Asking them to publish
virtio-media-ffmpeg-decodersounds reasonable.For
v4l2rI tested and it works now with the latest released version, so that much is good. I will change it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could try to do that after this PR is merged then :) It's not that we need crates.io publishing anyway.