Skip to content

drivers: video: Add the video shell #88566

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

josuah
Copy link
Collaborator

@josuah josuah commented Apr 14, 2025

Dependencies:

Replaces:

Now that we have a nice shell control querying API, it is possible to tab-complete in-depth every control value.

video - Video driver commands
Subcommands:
  start    : Start a video device and its sources
             Usage: video start <device>
  stop     : Stop a video device and its sources
             Usage: video stop <device>
  capture  : Capture a given number of frames from a device
             Usage: video capture <device> <num-frames>
  format   : Query or set the video format of a device
             Usage: video format <device> <ep> [<fourcc> <width>x<height>]
  frmival  : Query or set the video frame rate/interval of a device
             Usage: video frmival <device> <ep> [<n>fps|<n>ms|<n>us]
  ctrl     : Query or set video controls of a device
             Usage: video ctrl <device> [<ctrl> <value>]

To test on native_sim with VIDEO_SW_GENERATOR:

west build -t run -b native_sim/native/64 samples/drivers/video/capture -- -DCONFIG_VIDEO_SHELL=y

On another terminal, using your favorite serial console client, and likely COM# on Windows instead of /dev/pts/3:

picocom -b 115200 /dev/pts/3

@josuah
Copy link
Collaborator Author

josuah commented Apr 14, 2025

Because of the limitation of the shell API, a hack was used using LISTIFY() to generate completion functions that have an extra argument (i.e. the device number), so that the tab completion results are aware of the beginning of the line.

This is not expected to take more RAM, only more ROM/Flash.

@josuah josuah force-pushed the pr-video-shell branch 3 times, most recently from 11760ae to d34be47 Compare April 14, 2025 01:28
@josuah
Copy link
Collaborator Author

josuah commented Apr 14, 2025

Force-push:

  • Add the capture command mimicking the behavior of yavta -c<num-frames> <device> with video capture <device> <num-frames>.

@decsny decsny removed their request for review April 14, 2025 17:05
@josuah josuah force-pushed the pr-video-shell branch from 7b26cc7 to b7be037 Compare May 6, 2025 18:29
@josuah
Copy link
Collaborator Author

josuah commented May 6, 2025

Tested again with native_sim (64-bit for SDL support) and Arduino Nicla Vision:

west build --board native_sim/native/64 samples/drivers/video/capture/ -- -DCONFIG_VIDEO_SHELL=y
west build -b arduino_nicla_vision/stm32h747xx/m7 samples/drivers/video/capture -- -DCONFIG_VIDEO_SHELL=y

scrot_20250506_202936_569x186

@josuah josuah marked this pull request as ready for review May 6, 2025 18:42
@josuah
Copy link
Collaborator Author

josuah commented May 6, 2025

The controls were just tested again with HFLIP/VFLIP and we observe the image being mirrored left/right.

@kartben kartben requested a review from Copilot May 6, 2025 19:04
Copy link

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

This PR adds support for a video shell in the video driver by introducing a new API function, video_convert_ctrl_name, which converts human-friendly video control names into canonical identifiers for software use. Additionally, necessary header updates and modifications in the video_ctrls.c file ensure the new function is integrated into the control printing process.

  • Added function video_convert_ctrl_name with corresponding documentation in video.h.
  • Updated video_ctrls.c to include ctype.h, implement video_convert_ctrl_name, and integrate it into video_print_ctrl.
  • Enhanced logging to use converted control names for improved usability.

Reviewed Changes

Copilot reviewed 3 out of 7 changed files in this pull request and generated 1 comment.

File Description
include/zephyr/drivers/video.h Adds function declaration and documentation for video_convert_ctrl_name.
drivers/video/video_ctrls.c Implements video_convert_ctrl_name and updates printing of control names.
Files not reviewed (4)
  • drivers/video/CMakeLists.txt: Language not supported
  • drivers/video/Kconfig: Language not supported
  • drivers/video/Kconfig.shell: Language not supported
  • tests/drivers/build_all/video/prj.conf: Language not supported

@josuah josuah force-pushed the pr-video-shell branch from b7be037 to 9630a22 Compare May 6, 2025 19:43
@josuah
Copy link
Collaborator Author

josuah commented May 6, 2025

My bad, here we go again. No complain from:

cmake --build _build --target doxygen
scripts/ci/check_compliance.py -n -c origin/main..HEAD -e ClangFormat

SHELL_DYNAMIC_CMD_CREATE(dsub_##name##n, complete_##name##n)

/* Maximum size for a video control name, be it standard one or custom device-specific one */
#define VIDEO_SHELL_NAME_MAX_SIZE 40
Copy link
Collaborator

Choose a reason for hiding this comment

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

should this be a Kconfig?

Copy link
Collaborator Author

@josuah josuah May 6, 2025

Choose a reason for hiding this comment

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

I opted for a more global CONFIG_VIDEO_CTRL_NAME_MAX_SIZE if that is fit.

@@ -462,6 +480,7 @@ void video_print_ctrl(const struct device *const dev, const struct video_ctrl_qu
uint8_t i = 0;
const char *type = NULL;
char typebuf[8];
char namebuf[40];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
char namebuf[40];
char namebuf[VIDEO_SHELL_NAME_MAX_SIZE];

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Applied, good point.

Comment on lines 430 to 439
for (i = 0; i + 1 < dst_size && src[i] != '\0'; i++) {
if (isalnum(src[i])) {
dst[i] = tolower(src[i]);
add_underscore = true;
} else if (add_underscore && src[i + 1] != '\0') {
dst[i] = '_';
add_underscore = false;
}
}
dst[i] = '\0';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you test corner cases (including your own example "White Balance, Automatic")?
Using the same index for both strings seems like asking for trouble.

char dest[20];
const char *examples[] = {
    "hello   world",
    "  hello",
    "hello!",
    "White Balance, Automatic",
};

for (int i = 0; i < sizeof(examples) / sizeof(examples[0]); i++) {
    video_convert_ctrl_name(examples[i], dest, sizeof(dest));
    printf("Input: '%s' => Output: '%s'\n", examples[i], dest);
}

/*
Input: 'hello   world' => Output: 'hello_'
Input: '  hello' => Output: 'hehello'
Input: 'hello!' => Output: 'hellol'
Input: 'White Balance, Automatic' => Output: 'white_balance_'
*/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good opportunity to add unit tests...

@josuah josuah force-pushed the pr-video-shell branch from 9630a22 to dee26ae Compare May 6, 2025 21:14
Comment on lines 18 to 19
{" _ leading special characters", "leading_special_characters"},
{"trailing special characters!@#$%^", "trailing_special_characters_"},
Copy link
Collaborator

Choose a reason for hiding this comment

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

so trailing special characters are folded into 1 underscore and leading special characters end up being discarded? the lack of symmetry seems odd, maybe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the lack of symmetry seems odd, maybe?

I agree. This was assuming a control would never be named i.e. Misc +.
Latest push also covers this edge case instead of asserting a mis-handling.

josuah added 3 commits May 6, 2025 21:41
This permits to generate control names similar to v4l2-ctl that can be
used as string identifiers for the controls.

Signed-off-by: Josuah Demangeon <me@josuah.net>
Add tests to cover video_ctrls.c functions.
For now only video_convert_ctrl_name().

Signed-off-by: Josuah Demangeon <me@josuah.net>
Introduce the video shell and implement some video shell commands.
Make use of the various querying API to implement tab-completion, and
validiate the data, as well as convert string names into integers.
Commands provided: frmival, format, ctrl, start, stop, capture

Signed-off-by: Josuah Demangeon <me@josuah.net>
@josuah josuah force-pushed the pr-video-shell branch from dee26ae to 21e5ff7 Compare May 6, 2025 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Build System area: Drivers area: Samples Samples area: Shell Shell subsystem area: Video Video subsystem platform: ESP32 Espressif ESP32 platform: NXP Drivers NXP Semiconductors, drivers platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants