Skip to content

Conversation

@josuah
Copy link
Contributor

@josuah josuah commented Sep 16, 2025

I am proposing a lot of changes, with the goal to let reviewers decide which ones are relevant, essential, and which one are un-necessary or unwanted, and then I can apply the decisions.

For now, only tested with zephyr,video-sw-generator on native_sim:

west build -b native_sim/native/64 -S video-sw-generator samples/drivers/video/capture/
west build -b native_sim/native/64 -S video-sw-generator tests/drivers/video/test_pattern/

Then west flash to see the results.

@josuah josuah marked this pull request as ready for review September 16, 2025 10:25
@zephyrbot zephyrbot added area: Video Video subsystem area: Samples Samples labels Sep 16, 2025
@josuah
Copy link
Contributor Author

josuah commented Sep 16, 2025

Final result: https://github.com/josuah/zephyr/blob/f965294b9f5f58be8665b3c8f17f1b970ed8d619/samples/drivers/video/capture/src/main.c#L334-L426

Once this is reviewed, it should become easy to convert every other sample to the same layout.

Maybe further making some sort of common code used by the samples, which is configuring the video drivers out of Kconfig values using the video API, just for the sake of samples.

@kartben kartben requested a review from Copilot September 16, 2025 10:32
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Refactors the video capture sample and introduces a comprehensive video test pattern validation test. The changes improve code organization, error handling, and provide proper test coverage for video capture functionality.

  • Split monolithic main function into modular setup functions for better maintainability
  • Added comprehensive test for video test pattern validation using CIELAB color analysis
  • Improved error handling and proper return codes throughout video capture sample

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
samples/drivers/video/capture/src/main.c Refactored into modular functions with improved error handling
samples/drivers/video/capture/src/check_test_pattern.h Removed (functionality moved to test)
tests/drivers/video/test_pattern/src/main.c New comprehensive test with CIELAB color validation
tests/drivers/video/test_pattern/testcase.yaml Test configuration for video pattern testing
tests/drivers/video/test_pattern/prj.conf Basic project configuration
tests/drivers/video/test_pattern/boards/native_sim_native_64.conf Platform-specific test configuration
tests/drivers/video/test_pattern/Kconfig Configuration options for video testing
tests/drivers/video/test_pattern/CMakeLists.txt CMake build configuration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@josuah josuah force-pushed the pr_video_sample_improvement branch 3 times, most recently from c23d99b to 0e5bde7 Compare September 16, 2025 10:52
@josuah josuah requested a review from Copilot September 16, 2025 10:53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@josuah
Copy link
Contributor Author

josuah commented Sep 16, 2025

Here is the video test that ran and passed on CI:
https://github.com/zephyrproject-rtos/zephyr/actions/runs/17763404492/job/50481543225?pr=96072#step:13:791

#INFO    - 711/896 native_sim/native/64      drivers.dma.chan_blen_transfer                     FILTERED (runtime filter)
#INFO    - 712/896 native_sim/native/64      drivers.stepper.stepper_api.adi_tmc2209_work_q     PASSED (native 0.011s <host>)
 INFO    - 713/896 native_sim/native/64      drivers.video.test_pattern                         PASSED (native 0.007s <host>)
#INFO    - 714/896 native_sim/native/64      drivers.stepper.stepper_api.adi_tmc2209            PASSED (native 0.012s <host>)
#INFO    - 715/896 native_sim/native/64      drivers.gpio.hogs                                  PASSED (native 0.006s <host>)

@josuah josuah force-pushed the pr_video_sample_improvement branch from 0e5bde7 to 3236b02 Compare September 17, 2025 09:09
@sonarqubecloud
Copy link

#endif

if (strcmp(CONFIG_VIDEO_PIXEL_FORMAT, "")) {
if (CONFIG_VIDEO_FRAME_HEIGHT > 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Behavior would change I think like that since fmt.width / fmt.height used at line 183 should be normally updated with request given by CONFIG_VIDEO_FRAME_WIDTH / HEIGHT.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably meant this (185 now)?

if (err == 0 && (sel.rect.width != fmt.width || sel.rect.height != fmt.height)) {

Yes I see they need to be updated before this if() happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved these lines to app_get_video_info() to preserve the order.

        if (CONFIG_VIDEO_FRAME_HEIGHT > 0) {
                fmt->height = CONFIG_VIDEO_FRAME_HEIGHT;
        }
        if (CONFIG_VIDEO_FRAME_WIDTH > 0) {
                fmt->width = CONFIG_VIDEO_FRAME_WIDTH;
        }
        if (strcmp(CONFIG_VIDEO_PIXEL_FORMAT, "") != 0) {
                fmt->pixelformat = VIDEO_FOURCC_FROM_STR(CONFIG_VIDEO_PIXEL_FORMAT);
        }                        

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, I still think that this bunch of code should be done before the set selection since this is the width / height we want to give to the set_selection (compose). Did I missed something, or maybe this is fixed in another commit later on ?

@avolmat-st
Copy link

avolmat-st commented Sep 17, 2025

Thanks @josuah for this work. I haven't commented on the last commit since previous comments regarding crop/compose would make the commit change again, however I think the approach is very good.
I am actually a bit puzzled by the move of the test into a dedicated test appli, since this tends to create duplication of the code between the sample and the test itself, while (currently) losing some parts, such as for example compose.
However maybe creating helper functions for selection / format / display etc as you did could help to have smaller sample and test appli, avoid too much about code duplication.

I was also wondering if you could have a tester such as a transform element. Just an idea but basically, inserting an element between the receiver and the app, and this element would perform the test, avoiding to have test implemented into the test app.
Maybe this puts too much effort for just a test.

Something like:

 <sensor> -> <receiver> -> appli

would become

<sensor> -> <receiver> -> <test transform> -> appli

Test test transform would be checking the buffers given by the receiver, checking them or performing some hash or so on it for example before given them to the appli, which doesn't potentially even have any idea that there is something checking in the middle. Since we will probably tend to have more and more stuff like that, starting to get some encoder for example, why not having some debug / test purpose elements as well.

@CkovMk
Copy link
Contributor

CkovMk commented Sep 18, 2025

Great thanks for @josuah to clean-up this sample. I used this sample for testing recently, and would like to share my experience.

This sample uses a simple <sensor> -> <receiver> video pipeline, which is fine for simple devices. In our case, the pipeline is like <sensor> -> <external ISP> -> <receiver>. The input format (being passed to its upstream device) and output format of both the reciever and external ISP can be set differently. As a result, we modified the code to add 2 more format configs.

As the zephyr video subsystem evolves, we may build more and more complicated pipelines. Do you think it's possible to make this sample more flexible?

@josuah
Copy link
Contributor Author

josuah commented Oct 15, 2025

Sorry @CkovMk I also missed your message.

As the zephyr video subsystem evolves, we may build more and more complicated pipelines. Do you think it's possible to make this sample more flexible?

Yes absolutely, not only the sample, page 27 of this slide, libMP is introduced:
https://static.sched.com/hosted_files/osseu2025/7d/Video4Zephyr_EOSS_2025_Final.pdf#page=27

And here is a video about it:
https://www.youtube.com/watch?v=bjqUerc5jJw

But in the meantime, there is also more complex hardware coming with video encoder and internal ISP.

But for an external ISP, I suspect this would be only devicetree-level interconnection of devices? With a single input stream, arriving onto the video capture chip, the application would not be having more devices involved.

With the current APIs, it is possible to have the application configure the format of the ISP, and the ISP configure the format of the sensor.

Though, if it is arbitrary application/user choice for both, agreed, this needs to have both devices configured from main.c or similar.

#endif

if (strcmp(CONFIG_VIDEO_PIXEL_FORMAT, "")) {
if (CONFIG_VIDEO_FRAME_HEIGHT > 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, I still think that this bunch of code should be done before the set selection since this is the width / height we want to give to the set_selection (compose). Did I missed something, or maybe this is fixed in another commit later on ?

@josuah josuah force-pushed the pr_video_sample_improvement branch 2 times, most recently from 566e08e to ddaabc4 Compare October 24, 2025 12:50
Add an always-on CID for enabling the test pattern, which makes
it possible to use it in tests enabling the test first enabling
the pattern.

Signed-off-by: Josuah Demangeon <me@josuah.net>
When possible, use static initializer instead of memset() and
initialization at runtime. Fixes a bug where uninitialized memory of caps
would be used, in case drivers do not initialize them like they should.

Signed-off-by: Josuah Demangeon <me@josuah.net>
Increase log verbosity to print one line per captured frames and make
it like in the README by default. This avoids giving the impression
that the capture sample does not work. Users desiring to get better
performance can disable logging or reduce verbosity from INF to WRN.

Signed-off-by: Josuah Demangeon <me@josuah.net>
When possible, make use of C if statements instead of preprocessor #ifdef.
This still allow conditional compilation by letting the compiler
garbage-collect unused code.

Signed-off-by: Josuah Demangeon <me@josuah.net>
Use an "app_" prefix for all functions local to the application.
This avoids accidentally using "display_" or "video_" prefix that
are reserved for the respective area.

Signed-off-by: Josuah Demangeon <me@josuah.net>
@josuah josuah force-pushed the pr_video_sample_improvement branch from ddaabc4 to 0564078 Compare October 24, 2025 13:06
Use the same error handling implementation as everywhere else in the
video area and the majority of Zephyr:

  ret = error();
  if (ret < 0) {
      return ret;
  }

Signed-off-by: Josuah Demangeon <me@josuah.net>
@josuah josuah force-pushed the pr_video_sample_improvement branch from 0564078 to ea3fa88 Compare October 24, 2025 13:27
avolmat-st
avolmat-st previously approved these changes Oct 24, 2025
Copy link

@avolmat-st avolmat-st left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @josuah !!!

@josuah
Copy link
Contributor Author

josuah commented Oct 24, 2025

Another force-push for the compliance check (probably cocci rule unable to make sense out of he if / else if / else.

@josuah
Copy link
Contributor Author

josuah commented Oct 24, 2025

@hakehuang

You might be interested in seeing the new tests/drivers/video/test_pattern which is now separated from samples/drivers/video/capture.

I hope this suits you well.

avolmat-st
avolmat-st previously approved these changes Oct 24, 2025
@josuah josuah requested a review from ngphibang October 24, 2025 14:25
int "Value used for the test pattern menu control"
default 1
help
Some hardware support different typtes of test patteren in different order in the menu.
Copy link
Contributor

@ngphibang ngphibang Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo Some drivers support different types of test patterns and/or in a different order

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch >_<
And agreed on better wording.

Turn the test part of the sample code into a dedicated test into the
tests/ directory instead of just samples/.

Signed-off-by: Josuah Demangeon <me@josuah.net>
Move blocks of code into individual functions to make the sample more
modular, component-based.

Signed-off-by: Josuah Demangeon <me@josuah.net>
Centralize exit of all helper functions and display a common message
that indicates clearly that the sample is not blocking on any function
but instead stopped running.

Signed-off-by: Josuah Demangeon <me@josuah.net>
Allow the display to also use if() instead of #if by leveraging the
DEVICE_DT_GET_OR_NULL() that permit display_dev to always be defined.
The compiler will const-fold all the unused variables and functions.

Signed-off-by: Josuah Demangeon <me@josuah.net>
@sonarqubecloud
Copy link

Copy link
Contributor

@ngphibang ngphibang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @josuah !

@josuah josuah requested a review from avolmat-st October 24, 2025 15:16
@dkalowsk dkalowsk merged commit 1ac86c4 into zephyrproject-rtos:main Oct 24, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Samples Samples area: Tests Issues related to a particular existing or missing test area: Video Video subsystem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants