Skip to content

Add new virtio-media V4l2 stream virtual device - #2935

Open
bridadan wants to merge 2 commits into
google:mainfrom
bridadan:v4l2_stream
Open

Add new virtio-media V4l2 stream virtual device#2935
bridadan wants to merge 2 commits into
google:mainfrom
bridadan:v4l2_stream

Conversation

@bridadan

Copy link
Copy Markdown
Collaborator

This PR introduces the v4l2_stream device, a vhost-user-media backend that enables streaming video from a host-side source (via a FIFO/named pipe) into a guest VM using the virtio-media protocol.

It allows video data generated on the host (e.g., from a video file, synthetic test source, or any other producer of raw video frames) to be streamed directly into the guest VM's V4L2 framework.

The first commit copies over the emulated_camera_mplane crate into the new v4l2_stream crate, and includes minimal changes to get it building and launchable. The second commit modifies the new crate with the new functionality.

b/472497998

Brian Daniels added 2 commits July 29, 2026 12:29
This copies the emulated_camera_mplane crate to v4l2_stream,
adds the necessary config and flags to launch it with the same
config as emulated_camera_mplane, and packages it.

Bug: 472497998

TAG=agy
CONV=a47b5cbd-8c0b-492e-b23f-f2482c9367b3
This adds the actual implementation of the v4l2_stream device,
which reads from a FIFO and behaves as a virtio-media device.
It also adds the necessary configuration and flags to support
custom stream parameters (width, height, fps, format, source),
and a test script.

worker_thread_loop in v4l2_stream to uses nix::poll and
nix::sys::eventfd to wait for both FIFO data and control signals
(Stop/BufferQueued) without busy looping or sleeping.

Bug: 472497998
Test: source & lunch a target
      ./base/cvd/cuttlefish/host/commands/vhost_user_media/v4l2_stream/test_stream.sh

TAG=agy
CONV=a47b5cbd-8c0b-492e-b23f-f2482c9367b3
@bridadan
bridadan requested a review from ser-io July 30, 2026 20:39

@ser-io ser-io left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid forking emulated_camera_mplane as the first commit, it makes the second commit very hard to review. Feel free to introduce the new device in the first commit.

/// Lens facing configuration: FRONT, BACK, or EXTERNAL.
#[clap(long, value_name = "LENS_FACING", default_value = "EXTERNAL")]
lens_facing: String,
lens_facing: Option<String>,

@ser-io ser-io Jul 30, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't implement lens_facing for this device now as it's not needed. This would allow us to rmove the relevant ctrl handling methods making the PR easier to review

" 'v4l2_proxy': proxy a host V4L2 device into the guest\n"
" 'v4l2_stream': v4l2 stream device\n"
" 'lens_facing': optional, supported values: 'FRONT', 'BACK', 'EXTERNAL'\n"
" 'v4l2_stream': stream video from a host named pipe into the guest\n"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in the design doc, I think "v4l2_stream_proxy" better describe this device as the device does not generate/create the stream itself; it acts as a passive proxy, reading a pre-existing stream from the host and passing it to the guest VM implementing the v4l2 protocol.

Having said that. I'd also like to suggest new parameter names for this device. The would be:

input_path
input_width
input_height
input_fps
input_format

The most important concern is Forward Compatibility, if decide to support scaling or format translation in the future (e.g., taking a 1080p MJPEG input and outputting 720p YUV to the guest), we can easily introduce output_width and output_format parameters without any naming conflicts or ambiguity.

I also like that these new names are specific to proxy-like devices and they won't be misused by other devices.

@@ -0,0 +1,164 @@
#!/bin/bash

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's implement a proper cvd e2e tests under https://github.com/google/android-cuttlefish/tree/main/e2etests/cvd/media_tests rather than having this bash script.

Also, add the new test in its own commit as the last commit of the PR.

"NV12" => Some(Self::Nv12),
"NV12M" => Some(Self::Nv12M),
_ => None,
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your test generates format YUV420M. Can you support this format for now and add new formats when needed.

If you need to support all this formats now. In this specific commit can you just support format: YUV420M and add support for other formats in other follow-up commits. I'd like to review this PR as minimal as possible.

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.

2 participants