Skip to content

drivers: video: sw_stats: software-based statistics #87008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions drivers/video/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ zephyr_library_sources(video_device.c)
zephyr_library_sources_ifdef(CONFIG_VIDEO_MCUX_CSI video_mcux_csi.c)
zephyr_library_sources_ifdef(CONFIG_VIDEO_MCUX_MIPI_CSI2RX video_mcux_mipi_csi2rx.c)
zephyr_library_sources_ifdef(CONFIG_VIDEO_SW_GENERATOR video_sw_generator.c)
zephyr_library_sources_ifdef(CONFIG_VIDEO_SW_ISP video_sw_isp.c)
zephyr_library_sources_ifdef(CONFIG_VIDEO_SW_STATS video_sw_stats.c)
zephyr_library_sources_ifdef(CONFIG_VIDEO_MT9M114 mt9m114.c)
zephyr_library_sources_ifdef(CONFIG_VIDEO_OV7725 ov7725.c)
zephyr_library_sources_ifdef(CONFIG_VIDEO_OV2640 ov2640.c)
Expand Down
4 changes: 4 additions & 0 deletions drivers/video/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ source "drivers/video/Kconfig.mcux_mipi_csi2rx"

source "drivers/video/Kconfig.sw_generator"

source "drivers/video/Kconfig.sw_isp"

source "drivers/video/Kconfig.sw_stats"

source "drivers/video/Kconfig.mt9m114"

source "drivers/video/Kconfig.ov7725"
Expand Down
20 changes: 20 additions & 0 deletions drivers/video/Kconfig.sw_stats
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) 2025 tinyVision.ai Inc.
# SPDX-License-Identifier: Apache-2.0

config VIDEO_SW_STATS
bool "Video Software Statistics"
select PIXEL
help
Enable a software-based frame statistics video device, providing information that can be
by an Image Processing Algorithm (IPA) via the video stats API. This allows applications
to tune the image colors through the video control API.

config VIDEO_SW_STATS_NUM_SAMPLES
int "Number of pixels to sample on every frame"
default 400
range 0 65535
help
The more pixels are sample, the most accurate the statistics may be, but the slowest they
would be collected. The default value is estimated good enough not to slow-down most
systems. Note that the performance of statistics collection does not depend on the frame
size and only the number of samples, but accuracy does.
20 changes: 20 additions & 0 deletions drivers/video/video_emul_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,25 @@ static int emul_rx_get_caps(const struct device *dev, enum video_endpoint_id ep,
return video_get_caps(cfg->source_dev, VIDEO_EP_OUT, caps);
}

static int emul_rx_get_stats(const struct device *dev, enum video_endpoint_id ep,
struct video_stats *stats)
{
struct video_stats_channels *chan = (void *)stats;

if ((stats->flags & VIDEO_STATS_CHANNELS_Y) == 0) {
return -ENOTSUP;
}

/* Fake data for the sake of demonstrating and testing the APIs */
chan->y = 0x7f;
stats->frame_counter = k_cycle_get_32() / 1024;

/* Let the caller know what type of statistics is collected */
stats->flags = VIDEO_STATS_CHANNELS_Y;

return 0;
}

static int emul_rx_set_stream(const struct device *dev, bool enable)
{
const struct emul_rx_config *cfg = dev->config;
Expand Down Expand Up @@ -238,6 +257,7 @@ static DEVICE_API(video, emul_rx_driver_api) = {
.set_format = emul_rx_set_fmt,
.get_format = emul_rx_get_fmt,
.get_caps = emul_rx_get_caps,
.get_stats = emul_rx_get_stats,
.set_stream = emul_rx_set_stream,
.enqueue = emul_rx_enqueue,
.dequeue = emul_rx_dequeue,
Expand Down
Loading
Loading