Add dynamic V4L2 test pattern controls to emulated_camera_mplane#2845
Add dynamic V4L2 test pattern controls to emulated_camera_mplane#2845changyeon-jo wants to merge 6 commits into
Conversation
8515fd4 to
09bda08
Compare
5591022 to
2e26171
Compare
d6069c2 to
78b00e3
Compare
ser-io
left a comment
There was a problem hiding this comment.
Please move commit: "Implement real-time FFmpeg host video streaming for emulated_camera_mplane" into its own PR.
Also, create a brand new virtio-media device for video streaming. Don't extend emulated_camera_mplane for this.
|
Re:
I can separate FFmpeg commit from PR. Re:
May I ask why you prefer having this in separate device? IMHO, it's also "emulating" a camera data stream from a media source and therefore does not sound out of this device's scope. If you intend to make this as the one strictly generating test patterns, shouldn't we need to rename this like "test_pattern_generator_mplane" or something similar? :) |
Cuttlefish attaches virtio-media devices using vhost-user protocol, which allows the flexibility to have device emulation per host process. Having said that, the case for streaming emulated frames and using FFmpeg for host video streaming are quite different in terms of how the frames are populated which present a case for different binaries. Given we already have the vhost-user protocol in place, it's cleaner to have two different binaries with their own specific flags. The current name emulated_camera_mplane is based on existing EmulatedCamera which this device aims to replace. |
e5be4b9 to
5f9e6e7
Compare
Format pre-existing files inside `emulated_camera_mplane` to comply with the standard Rust formatting style. This eliminates formatting noise in subsequent functional commits. Bug: b/490699808 Bug: b/502639876
5f9e6e7 to
5325a81
Compare
|
Thanks for explanation, @ser-io. Since this replaces the camera framework team's EmulateCamera, it sounds like you're aiming to emulate the Android camera device's attributes and characteristics, rather than just the data stream. Do you plan to support FULL or LEVEL_3? :) Also, will this device's characteristics be configurable similar to hardware/google/camera/devices/EmulatedCamera/hwl/configs/emu_camera_back.json? |
ser-io
left a comment
There was a problem hiding this comment.
Thanks for changing the commits to self-contained smaller commits. Highly appreciated.
| } | ||
| } | ||
|
|
||
| const V4L2_CID_IMAGE_PROC_CLASS: u32 = 0x009f0000; |
There was a problem hiding this comment.
I can see these are standard const https://docs.kernel.org/userspace-api/media/v4l/ext-ctrls-image-process.html. Are not they already defined in the in the Rust v4l2r::bindings port?
There was a problem hiding this comment.
Yes, they are currently missing in v4l2r crate at the moment. We should add them to v4l2r crate eventually.
There was a problem hiding this comment.
I can build using bindings::V4L2_CID_TEST_PATTERN and bindings::V4L2_CID_IMAGE_PROC_CLASS, I have linux headers version: 6.18. cat /usr/include/linux/version.h. which version do you have?
Correct! It should be FULL however this is still in the very early stages, priority is to migrate existing workflow (mostly from auto targets) that can now use the data streams and the existing external camera hal. |
Declare the trait-based `FramePattern` interface inside `src/pattern/mod.rs`. This trait defines the interface for dynamically writing multi-planar YUV video frames into queued virtio-media buffers. This first commit adds the trait definitions and registers the pattern module in the build system as a standalone declaration. Bug: b/490699808 Bug: b/502639876
Implement the color-cycling `Pulse` pattern inside `src/pattern/pulse.rs`. Refactor the internal `write_pattern` helper inside `device.rs` to call the `CameraPattern::Pulse` abstraction instead of hardcoding YUV loop math. Bug: b/490699808 Bug: b/502639876
442de97 to
5acc779
Compare
Introduce the V4L2 controls to allow runtime switching of emulated camera test patterns. Wires up: - V4L2_CID_IMAGE_PROC_CLASS - V4L2_CID_TEST_PATTERN Exposes these controls via standard query and control ioctl handlers, including querymenu and control change event subscriptions. Only Pattern 0 (Pulse) is selectable in this commit. We can use the standard `v4l2-ctl` command-line tool inside the guest OS to list, query, and change the test patterns at runtime: # List all available camera controls (shows "Test Pattern" menu) v4l2-ctl -d /dev/video1 --list-ctrls # Get the currently selected pattern index v4l2-ctl -d /dev/video1 -C test_pattern # Switch the selected pattern to Pulse (index 0) v4l2-ctl -d /dev/video1 -c test_pattern=0 Bug: b/490699808 Bug: b/502639876
Implement the color-bar SMPTE Bars test pattern with an animated inverse-color bouncing box overlay inside `src/pattern/smpte.rs`. Register it in the `pattern` module and expand `device.rs` V4L2 control ranges and query menus to support selecting index 1. Bug: b/490699808 Bug: b/502639876
Implement the CPU-intensive animated Julia Set fractal pattern inside `src/pattern/julia_set.rs`. Register it in the `pattern` module and expand `device.rs` V4L2 control ranges and query menus to support selecting index 2. Bug: b/490699808 Bug: b/502639876
5acc779 to
b23512b
Compare
There was a problem hiding this comment.
When introducing new files this repo we need to add the LICENSE at the top.
// Copyright 2026, The Android Open Source Project
...
Add the license to all the new files introduced in this PR.
| use std::os::fd::AsFd; | ||
| use std::os::fd::BorrowedFd; | ||
|
|
||
| use std::io::Write; |
There was a problem hiding this comment.
nit: why this was moved here? it should be with other "std::io" declarations.
| flags: u32, | ||
| } | ||
|
|
||
| const CONTROLS: [ControlDef; 3] = [ |
There was a problem hiding this comment.
Let's remove "CID_LENS_FACING" from this list, CID_LENS_FACING struct is managed by lens_facing_query_ext_ctrl method, the new ControlDef instance is not aligned with that method.
| const V4L2_CID_IMAGE_PROC_CLASS: u32 = 0x009f0000; | ||
| const V4L2_CID_TEST_PATTERN: u32 = 0x009f0903; | ||
|
|
||
| struct ControlDef { |
There was a problem hiding this comment.
why not use bindings::v4l2_query_ext_ctrl directly?
| maximum: 0, | ||
| step: 1, | ||
| default_value: 0, | ||
| flags: 0, |
There was a problem hiding this comment.
this control is write and read, why not declaring those flags?
| maximum: 0, | ||
| step: 0, | ||
| default_value: 0, | ||
| flags: bindings::V4L2_CTRL_FLAG_READ_ONLY | bindings::V4L2_CTRL_FLAG_WRITE_ONLY, |
| /// Lens facing configuration. | ||
| lens_facing: LensFacing, | ||
| /// Currently selected test pattern. | ||
| current_pattern: u32, |
There was a problem hiding this comment.
Use an enum rather than "u32". Have the first value (0) named undefined as this struct needs to be proto compatible, and defined Pulse as 1.
| } else if id == CID_LENS_FACING { | ||
| return Ok(self.lens_facing_query_ext_ctrl()); | ||
|
|
||
| let mut name = [0 as ::std::os::raw::c_char; 32]; |
There was a problem hiding this comment.
define a method in ControlDef for this.
| dims: [0; 4], | ||
| ..Default::default() | ||
| }) | ||
| } else { |
There was a problem hiding this comment.
Avoid these else clauses as they are not helpful in this context. Return return Err(libc::EINVAL); directly.
Implement support for dynamic video test patterns and their associated
V4L2 control handlers. Supported patterns include:
inverse-color bouncing box overlay, adapted for the 3-sink layout and
640x480 resolution.
for high-load host load scenarios.
Supports V4L2_CID_TEST_PATTERN and V4L2_CID_IMAGE_PROC_CLASS via the
VirtioMediaIoctlHandler implementation.
Bug: b/490699808