Skip to content

Commit aa1ded7

Browse files
committed
drivers: video: emul_rx: add basic support for video_set_stats()
Add support for the new API video_set_stats() to the emulated video RX driver, and use it to implement simple API tests. The data returned is arbitrary for the sake of testing the API itself. Signed-off-by: Josuah Demangeon <me@josuah.net>
1 parent b247d7a commit aa1ded7

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

drivers/video/video_emul_rx.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,25 @@ static int emul_rx_get_caps(const struct device *dev, enum video_endpoint_id ep,
131131
return video_get_caps(cfg->source_dev, VIDEO_EP_OUT, caps);
132132
}
133133

134+
static int emul_rx_get_stats(const struct device *dev, enum video_endpoint_id ep,
135+
struct video_stats *stats)
136+
{
137+
struct video_stats_channels *chan = (void *)stats;
138+
139+
if ((stats->flags & VIDEO_STATS_CHANNELS_Y) == 0) {
140+
return -ENOTSUP;
141+
}
142+
143+
/* Fake data for the sake of demonstrating and testing the APIs */
144+
chan->y = 0x7f;
145+
stats->frame_counter = k_cycle_get_32() / 1024;
146+
147+
/* Let the caller know what type of statistics is collected */
148+
stats->flags = VIDEO_STATS_CHANNELS_Y;
149+
150+
return 0;
151+
}
152+
134153
static int emul_rx_set_stream(const struct device *dev, bool enable)
135154
{
136155
const struct emul_rx_config *cfg = dev->config;
@@ -251,6 +270,7 @@ static DEVICE_API(video, emul_rx_driver_api) = {
251270
.set_format = emul_rx_set_fmt,
252271
.get_format = emul_rx_get_fmt,
253272
.get_caps = emul_rx_get_caps,
273+
.get_stats = emul_rx_get_stats,
254274
.set_stream = emul_rx_set_stream,
255275
.enqueue = emul_rx_enqueue,
256276
.dequeue = emul_rx_dequeue,

tests/drivers/video/api/src/video_emul.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,33 @@ ZTEST(video_emul, test_video_vbuf)
186186
zexpect_ok(video_stream_stop(rx_dev));
187187
}
188188

189+
ZTEST(video_emul, test_video_stats)
190+
{
191+
struct video_stats_channels chan = {
192+
.base.flags = VIDEO_STATS_CHANNELS,
193+
};
194+
195+
zexpect_ok(video_get_stats(rx_dev, VIDEO_EP_OUT, &chan.base),
196+
"statistics collection should succeed for the emulated device");
197+
198+
zexpect_equal(chan.base.flags & VIDEO_STATS_HISTOGRAM, 0, "histogram was not requested");
199+
200+
zexpect_not_equal(chan.base.flags & VIDEO_STATS_CHANNELS, 0,
201+
"this emulated device is known to support channel averages.");
202+
203+
if (chan.base.flags & VIDEO_STATS_CHANNELS_Y) {
204+
zexpect_not_equal(chan.y, 0x00, "Test data likely not completely black.");
205+
zexpect_not_equal(chan.y, 0xff, "Test data likely not completely white.");
206+
}
207+
208+
if (chan.base.flags & VIDEO_STATS_CHANNELS_RGB) {
209+
zexpect_not_equal(chan.rgb[0], 0x00, "Red channel likely not completely 0x00.");
210+
zexpect_not_equal(chan.rgb[0], 0xff, "Red channel likely not completely 0xff.");
211+
zexpect_not_equal(chan.rgb[1], 0x00, "Green channel likely not completely 0x00.");
212+
zexpect_not_equal(chan.rgb[1], 0xff, "Green channel likely not completely 0xff.");
213+
zexpect_not_equal(chan.rgb[2], 0x00, "Blue channel likely not completely 0x00.");
214+
zexpect_not_equal(chan.rgb[2], 0xff, "Blue channel likely not completely 0xff.");
215+
}
216+
}
217+
189218
ZTEST_SUITE(video_emul, NULL, NULL, NULL, NULL, NULL);

0 commit comments

Comments
 (0)