Skip to content

Add vhost-device-media backend for virtio-media#944

Open
aesteve-rh wants to merge 8 commits intorust-vmm:mainfrom
aesteve-rh:virtio-media
Open

Add vhost-device-media backend for virtio-media#944
aesteve-rh wants to merge 8 commits intorust-vmm:mainfrom
aesteve-rh:virtio-media

Conversation

@aesteve-rh
Copy link
Copy Markdown
Contributor

@aesteve-rh aesteve-rh commented Mar 10, 2026

Summary of the PR

This PR introduces vhost-user-media device.

The virtio-media device first appeared in virtio-spec v1.4 specification[1].
It standardizes how guest applications communicate with media devices on
the host, such as encoders, decoders, and cameras.

The protocol relies on the V4L2 (Video4Linux2) specification to
format the communication between the guest and host, exposing the
host's media devices to the virtualized environment.

The low-level implementation of this backend for the virtio-media
protocol is provided by the device crate from the virtio-media
repository[2].

Implementation is still WiP as it is waiting for vhost release and SHMEM_MAP/UNMAP patch to be merged in Qemu (so that the specs align with current implementation).
Done!

[1] https://docs.oasis-open.org/virtio/virtio/v1.4/virtio-v1.4.html#x1-82200022
[2] https://github.com/chromeos/virtio-media

Requirements

Before submitting your PR, please make sure you addressed the following
requirements:

  • All commits in this PR have Signed-Off-By trailers (with
    git commit -s), and the commit message has max 60 characters for the
    summary and max 75 characters for each description line.
  • All added/changed functionality has a corresponding unit/integration
    test.
  • All added/changed public-facing functionality has entries in the "Upcoming
    Release" section of CHANGELOG.md (if no such section exists, please create one).
  • Any newly added unsafe code is properly documented.

Comment thread vhost-device-media/Cargo.toml
@dorindabassey
Copy link
Copy Markdown
Collaborator

Thank you for this PR @aesteve-rh
IIUC, this vhost-device-media supersedes vhost-device-video, so will vhost-device-video be deprecated once virtio-media is fully supported?

@epilys
Copy link
Copy Markdown
Member

epilys commented Mar 12, 2026

@dorindabassey virtio-video is still under development (see virtio-comment list for v10). It's not replaced by virtio-media.

This commit introduces vhost-user-media device.

The virtio-media device first appeared in virtio-spec v1.4 specification[1].
It standardizes how guest applications communicate with media devices on
the host, such as encoders, decoders, and cameras.

The protocol relies on the V4L2 (Video4Linux2) specification to
format the communication between the guest and host, exposing the
host's media devices to the virtualized environment.

The low-level implementation of this backend for the virtio-media
protocol is provided by the device crate from the virtio-media
repository[2].

[1] https://docs.oasis-open.org/virtio/virtio/v1.4/virtio-v1.4.html#x1-82200022
[2] https://github.com/chromeos/virtio-media

Signed-off-by: Albert Esteve <aesteve@redhat.com>
This commit introduces a memory allocator for managing the shared
memory regions used by the virtio-media device. The allocator is
responsible for finding and managing free regions within the
shared memory, ensuring that buffers are allocated without conflicts.

The new `MediaAllocator` tracks available memory pools and provides a
mechanism for allocating and releasing memory blocks of a requested
size, while also handling alignment requirements. This replaces the
previous, more error-prone approach of managing address ranges in a
simple Vec.

Signed-off-by: Albert Esteve <aesteve@redhat.com>
This commit introduces a new backend that uses FFmpeg for
software-based video decoding. This provides a hardware-independent
way to test and use the virtio-media device for video decoding tasks.

The new `FfmpegDecoder` backend leverages the `virtio-media-ffmpeg-decoder`
crate from the virtio-media repository [1]. It is exposed as a new backend
option and can decode common video formats such as H.264, VP8, and VP9
without requiring any specific host hardware.

This addition is useful for development and testing and also serves as a
reference implementation for a virtio-media decoder device.

[1] https://github.com/chromeos/virtio-media/tree/main/extras/ffmpeg-decoder

Signed-off-by: Albert Esteve <aesteve@redhat.com>
This commit refactors the vhost-device-media crate to make
each backend an optional feature. This allows users to compile
only the backends they need, reducing the final binary size and
dependency footprint.

The following features have been introduced:
- `simple-capture`: Enables the simple V4L2 capture device.
- `v4l2-proxy`: Enables the V4L2 proxy device.
- `ffmpeg`: Enables the FFmpeg software decoder.

The `v4l2-proxy` feature is enabled by default. The `v4l2r` and
`virtio-media-ffmpeg-decoder` dependencies are now optional and are only
included when their corresponding features are enabled. The source code
has been updated with `#[cfg]` attributes to support conditional
compilation of the backends.

Signed-off-by: Albert Esteve <aesteve@redhat.com>
@aesteve-rh aesteve-rh marked this pull request as ready for review April 15, 2026 09:33
aesteve-rh and others added 4 commits April 15, 2026 13:18
Add unit tests to existing code for
vhost-device-media backend.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Albert Esteve <aesteve@redhat.com>
This change reorganizes the vhost-device-media crate to
follow a similar pattern used by other vhost-device crates,
including the template, splitting the codebase into a library
component (lib.rs) and a minimal binary entry point (main.rs).

A new src/lib.rs was added containing the core backend logic,
including backend creation functions (create_*_device_config),
and serve functions for each backend type. The main.rs file
was simplified to focus solely on CLI argument parsing and
delegating to the library.

Signed-off-by: Albert Esteve <aesteve@redhat.com>
Add V4l2DeviceType enum class that reads the device
path received in the command line and resolves the
device type according to the VFL_TYPE_* kernel constants.

Added tests to verify path resolution is correct.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Albert Esteve <aesteve@redhat.com>
Various rust-vmm dependencies support Xen platforms
under a feature `xen`. Add the same here for the
new vhost-device-media crate.

Signed-off-by: Albert Esteve <aesteve@redhat.com>
@aesteve-rh
Copy link
Copy Markdown
Contributor Author

Some rust-vmm-container dependencies may be missing for the builds in CI for the media crate. I will investigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants