-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
video: emul: virtual driver for an imager and RX engine #79482
Merged
nashif
merged 2 commits into
zephyrproject-rtos:main
from
josuah:pr-video-sensor-skeleton
Dec 6, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(integration) | ||
|
||
target_sources(app PRIVATE src/video_common.c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CONFIG_ZTEST=y | ||
CONFIG_VIDEO=y | ||
CONFIG_VIDEO_BUFFER_POOL_SZ_MAX=16384 | ||
CONFIG_VIDEO_BUFFER_POOL_NUM_MAX=1 | ||
CONFIG_VIDEO_LOG_LEVEL_DBG=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/* | ||
* Copyright (c) 2024 tinyVision.ai Inc. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/ztest.h> | ||
#include <zephyr/drivers/video.h> | ||
|
||
enum { | ||
RGB565, | ||
YUYV_A, | ||
YUYV_B, | ||
}; | ||
|
||
static const struct video_format_cap fmts[] = { | ||
[RGB565] = {.pixelformat = VIDEO_PIX_FMT_RGB565, | ||
.width_min = 1280, .width_max = 1280, .width_step = 50, | ||
.height_min = 720, .height_max = 720, .height_step = 50}, | ||
[YUYV_A] = {.pixelformat = VIDEO_PIX_FMT_YUYV, | ||
.width_min = 100, .width_max = 1000, .width_step = 50, | ||
.height_min = 100, .height_max = 1000, .height_step = 50}, | ||
[YUYV_B] = {.pixelformat = VIDEO_PIX_FMT_YUYV, | ||
.width_min = 1920, .width_max = 1920, .width_step = 0, | ||
.height_min = 1080, .height_max = 1080, .height_step = 0}, | ||
{0}, | ||
}; | ||
|
||
ZTEST(video_common, test_video_format_caps_index) | ||
{ | ||
struct video_format fmt = {0}; | ||
size_t idx; | ||
int ret; | ||
|
||
fmt.pixelformat = VIDEO_PIX_FMT_YUYV; | ||
|
||
fmt.width = 100; | ||
fmt.height = 100; | ||
fmt.pitch = 100 * 2; | ||
ret = video_format_caps_index(fmts, &fmt, &idx); | ||
zassert_ok(ret, "expecting minimum value to match"); | ||
zassert_equal(idx, YUYV_A); | ||
|
||
fmt.width = 1000; | ||
fmt.height = 1000; | ||
fmt.pitch = 1000 * 2; | ||
ret = video_format_caps_index(fmts, &fmt, &idx); | ||
zassert_ok(ret, "expecting maximum value to match"); | ||
zassert_equal(idx, YUYV_A); | ||
|
||
fmt.width = 1920; | ||
fmt.height = 1080; | ||
fmt.pitch = 1920 * 2; | ||
ret = video_format_caps_index(fmts, &fmt, &idx); | ||
zassert_ok(ret, "expecting exact match to work"); | ||
zassert_equal(idx, YUYV_B); | ||
|
||
fmt.width = 1001; | ||
fmt.height = 1000; | ||
fmt.pitch = 1001 * 2; | ||
ret = video_format_caps_index(fmts, &fmt, &idx); | ||
zassert_not_ok(ret, "expecting 1 above maximum width to mismatch"); | ||
|
||
fmt.width = 1000; | ||
fmt.height = 1001; | ||
fmt.pitch = 1000 * 2; | ||
ret = video_format_caps_index(fmts, &fmt, &idx); | ||
zassert_not_ok(ret, "expecting 1 above maximum height to mismatch"); | ||
|
||
fmt.width = 1280; | ||
fmt.height = 720; | ||
fmt.pitch = 1280 * 2; | ||
ret = video_format_caps_index(fmts, &fmt, &idx); | ||
zassert_not_ok(ret); | ||
zassert_not_ok(ret, "expecting wrong format to mismatch"); | ||
|
||
fmt.pixelformat = VIDEO_PIX_FMT_RGB565; | ||
|
||
fmt.width = 1000; | ||
fmt.height = 1000; | ||
fmt.pitch = 1000 * 2; | ||
ret = video_format_caps_index(fmts, &fmt, &idx); | ||
zassert_not_ok(ret, "expecting wrong format to mismatch"); | ||
|
||
fmt.width = 1280; | ||
fmt.height = 720; | ||
fmt.pitch = 1280 * 2; | ||
ret = video_format_caps_index(fmts, &fmt, &idx); | ||
zassert_ok(ret, "expecting exact match to work"); | ||
zassert_equal(idx, RGB565); | ||
} | ||
|
||
ZTEST(video_common, test_video_frmival_nsec) | ||
{ | ||
zassert_equal( | ||
video_frmival_nsec(&(struct video_frmival){.numerator = 1, .denominator = 15}), | ||
66666666); | ||
|
||
zassert_equal( | ||
video_frmival_nsec(&(struct video_frmival){.numerator = 1, .denominator = 30}), | ||
33333333); | ||
|
||
zassert_equal( | ||
video_frmival_nsec(&(struct video_frmival){.numerator = 5, .denominator = 1}), | ||
5000000000); | ||
|
||
zassert_equal( | ||
video_frmival_nsec(&(struct video_frmival){.numerator = 1, .denominator = 1750000}), | ||
571); | ||
} | ||
|
||
ZTEST(video_common, test_video_closest_frmival_stepwise) | ||
{ | ||
struct video_frmival_stepwise stepwise; | ||
struct video_frmival desired; | ||
struct video_frmival expected; | ||
struct video_frmival match; | ||
|
||
stepwise.min.numerator = 1; | ||
stepwise.min.denominator = 30; | ||
stepwise.max.numerator = 30; | ||
stepwise.max.denominator = 30; | ||
stepwise.step.numerator = 1; | ||
stepwise.step.denominator = 30; | ||
|
||
desired.numerator = 1; | ||
desired.denominator = 1; | ||
video_closest_frmival_stepwise(&stepwise, &desired, &match); | ||
zassert_equal(video_frmival_nsec(&match), video_frmival_nsec(&desired), "1 / 1"); | ||
|
||
desired.numerator = 3; | ||
desired.denominator = 30; | ||
video_closest_frmival_stepwise(&stepwise, &desired, &match); | ||
zassert_equal(video_frmival_nsec(&match), video_frmival_nsec(&desired), "3 / 30"); | ||
|
||
desired.numerator = 7; | ||
desired.denominator = 80; | ||
expected.numerator = 3; | ||
expected.denominator = 30; | ||
video_closest_frmival_stepwise(&stepwise, &desired, &match); | ||
zassert_equal(video_frmival_nsec(&match), video_frmival_nsec(&expected), "7 / 80"); | ||
|
||
desired.numerator = 1; | ||
desired.denominator = 120; | ||
video_closest_frmival_stepwise(&stepwise, &desired, &match); | ||
zassert_equal(video_frmival_nsec(&match), video_frmival_nsec(&stepwise.min), "1 / 120"); | ||
|
||
desired.numerator = 100; | ||
desired.denominator = 1; | ||
video_closest_frmival_stepwise(&stepwise, &desired, &match); | ||
zassert_equal(video_frmival_nsec(&match), video_frmival_nsec(&stepwise.max), "100 / 1"); | ||
} | ||
|
||
ZTEST_SUITE(video_common, NULL, NULL, NULL, NULL, NULL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright (c) 2024 tinyVision.ai Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
tests: | ||
drivers.video.api: | ||
tags: | ||
- drivers | ||
- video | ||
platform_allow: native_sim |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the introduced functions here are supposed for drivers uses only ?. I think it should be put in an internal header rather in the public header
video.h
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The users can access the format cap structure, so they could be interested in verifying: "for this particular width/height/pixelformat, what is the min/max/step?
Not sure this would ever get used that way though! Glad with putting it on a
drivers/video/video_common.h
header like often done for driver helper functions.