Skip to content

Add dynamic V4L2 test pattern controls to emulated_camera_mplane#2845

Open
changyeon-jo wants to merge 7 commits into
google:mainfrom
changyeon-jo:migrate_tpg
Open

Add dynamic V4L2 test pattern controls to emulated_camera_mplane#2845
changyeon-jo wants to merge 7 commits into
google:mainfrom
changyeon-jo:migrate_tpg

Conversation

@changyeon-jo

Copy link
Copy Markdown

Implement support for dynamic video test patterns and their associated
V4L2 control handlers. Supported patterns include:

  • Pattern 0 (Legacy Pulse): Uniform color-cycling.
  • Pattern 1 (SMPTE + Bouncing Box): Full color SMPTE bars with an animated
    inverse-color bouncing box overlay, adapted for the 3-sink layout and
    640x480 resolution.
  • Pattern 2 (Animated Julia Set): CPU-intensive fractal pattern simulation
    for high-load host load scenarios.

Supports V4L2_CID_TEST_PATTERN and V4L2_CID_IMAGE_PROC_CLASS via the
VirtioMediaIoctlHandler implementation.

Bug: b/490699808

@changyeon-jo changyeon-jo force-pushed the migrate_tpg branch 3 times, most recently from 8515fd4 to 09bda08 Compare July 10, 2026 23:51
@changyeon-jo changyeon-jo marked this pull request as draft July 10, 2026 23:59
@changyeon-jo changyeon-jo marked this pull request as ready for review July 11, 2026 00:49

@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.

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.

@changyeon-jo changyeon-jo requested a review from ser-io July 14, 2026 19:10
@changyeon-jo

Copy link
Copy Markdown
Author

@ser-io

Re:

Please move commit: "Implement real-time FFmpeg host video streaming for emulated_camera_mplane" into its own PR.

I can separate FFmpeg commit from PR.

Re:

Also, create a brand new virtio-media device for video streaming. Don't extend emulated_camera_mplane for this.

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? :)

@ser-io

ser-io commented Jul 14, 2026

Copy link
Copy Markdown
Member

@ser-io

Re:

Please move commit: "Implement real-time FFmpeg host video streaming for emulated_camera_mplane" into its own PR.

I can separate FFmpeg commit from PR.

Re:

Also, create a brand new virtio-media device for video streaming. Don't extend emulated_camera_mplane for this.

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.

@changyeon-jo changyeon-jo force-pushed the migrate_tpg branch 6 times, most recently from e5be4b9 to 5f9e6e7 Compare July 15, 2026 04:58
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
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
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.

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
Introduce a static startup baseline timestamp initialized on backend boot,
and align all buffer presentation timestamps to be offsets from this
baseline. This aligns with host-side video clock models and prevents clock
drift issues inside the Android guest.

Bug: b/490699808
Bug: b/502639876
@changyeon-jo

Copy link
Copy Markdown
Author

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?

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