Add new virtio-media V4l2 stream virtual device - #2935
Conversation
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
ser-io
left a comment
There was a problem hiding this comment.
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>, |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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, | ||
| } |
There was a problem hiding this comment.
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.
This PR introduces the
v4l2_streamdevice, avhost-user-mediabackend that enables streaming video from a host-side source (via a FIFO/named pipe) into a guest VM using thevirtio-mediaprotocol.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_mplanecrate into the newv4l2_streamcrate, and includes minimal changes to get it building and launchable. The second commit modifies the new crate with the new functionality.b/472497998