Skip to content
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

samples: drivers: video: capture: Add format config #77879

Merged
merged 4 commits into from
Oct 1, 2024
Merged
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
1 change: 1 addition & 0 deletions boards/espressif/esp32s3_eye/esp32s3_eye_procpu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ supported:
- pwm
- dma
- input
- video
testing:
ignore_tags:
- net
Expand Down
2 changes: 0 additions & 2 deletions drivers/video/video_esp32_dvp.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ void video_esp32_dma_rx_done(const struct device *dev, void *user_data, uint32_t
int status)
{
struct video_esp32_data *data = user_data;
int ret = 0;

if (status == DMA_STATUS_BLOCK) {
LOG_DBG("received block");
Expand Down Expand Up @@ -278,7 +277,6 @@ static int video_esp32_set_fmt(const struct device *dev, enum video_endpoint_id
static int video_esp32_enqueue(const struct device *dev, enum video_endpoint_id ep,
struct video_buffer *vbuf)
{
const struct video_esp32_config *cfg = dev->config;
struct video_esp32_data *data = dev->data;

if (ep != VIDEO_EP_OUT) {
Expand Down
27 changes: 27 additions & 0 deletions samples/drivers/video/capture/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
# SPDX-License-Identifier: Apache-2.0

mainmenu "Video capture sample application"

menu "Video capture configuration"

config VIDEO_FRAME_HEIGHT
int "Height of the video frame"
default 0
josuah marked this conversation as resolved.
Show resolved Hide resolved
help
Height of the video frame. If set to 0, the default height is used.

config VIDEO_FRAME_WIDTH
int "Width of the video frame"
default 0
help
Width of the video frame. If set to 0, the default width is used.

config VIDEO_PIXEL_FORMAT
string "Pixel format of the video frame"
help
Pixel format of the video frame. If not set, the default pixel format is used.

endmenu

source "Kconfig.zephyr"
11 changes: 11 additions & 0 deletions samples/drivers/video/capture/boards/esp32s3_eye_procpu.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CONFIG_VIDEO_BUFFER_POOL_SZ_MAX=40000
CONFIG_VIDEO_BUFFER_POOL_NUM_MAX=3
CONFIG_ESP_SPIRAM=y
CONFIG_SPIRAM_MODE_OCT=y
CONFIG_VIDEO_BUFFER_POOL_ALIGN=32
CONFIG_DMA_ESP32_MAX_DESCRIPTOR_NUM=64
CONFIG_VIDEO_BUFFER_USE_SHARED_MULTI_HEAP=y
CONFIG_VIDEO_BUFFER_SMH_ATTRIBUTE=2
CONFIG_VIDEO_FRAME_HEIGHT=240
CONFIG_VIDEO_FRAME_WIDTH=240
CONFIG_VIDEO_PIXEL_FORMAT="RGBP"
1 change: 1 addition & 0 deletions samples/drivers/video/capture/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ tests:
- mimxrt1064_evk
- mimxrt1170_evk/mimxrt1176/cm7
- mm_swiftio
- esp32s3_eye/esp32s3/procpu
depends_on: video
integration_platforms:
- mimxrt1064_evk
Expand Down
55 changes: 35 additions & 20 deletions samples/drivers/video/capture/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,21 @@
struct display_capabilities capabilities;
int ret = 0;

if (!device_is_ready(display_dev)) {
LOG_ERR("Device %s not found", display_dev->name);
return -ENODEV;
}

josuah marked this conversation as resolved.
Show resolved Hide resolved
printk("\nDisplay device: %s\n", display_dev->name);
LOG_INF("Display device: %s", display_dev->name);

display_get_capabilities(display_dev, &capabilities);

printk("- Capabilities:\n");
printk(" x_resolution = %u, y_resolution = %u, supported_pixel_formats = %u\n"
" current_pixel_format = %u, current_orientation = %u\n\n",
LOG_INF("- Capabilities:");
LOG_INF(" x_resolution = %u, y_resolution = %u, supported_pixel_formats = %u"
" current_pixel_format = %u, current_orientation = %u",
capabilities.x_resolution, capabilities.y_resolution,
capabilities.supported_pixel_formats, capabilities.current_pixel_format,
capabilities.current_orientation);

Check notice on line 35 in samples/drivers/video/capture/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

samples/drivers/video/capture/src/main.c:35 - " current_pixel_format = %u, current_orientation = %u", - capabilities.x_resolution, capabilities.y_resolution, - capabilities.supported_pixel_formats, capabilities.current_pixel_format, - capabilities.current_orientation); + " current_pixel_format = %u, current_orientation = %u", + capabilities.x_resolution, capabilities.y_resolution, + capabilities.supported_pixel_formats, capabilities.current_pixel_format, + capabilities.current_orientation);
/* Set display pixel format to match the one in use by the camera */
switch (pixfmt) {
case VIDEO_PIX_FMT_RGB565:
ret = display_set_pixel_format(display_dev, PIXEL_FORMAT_BGR_565);
ret = display_set_pixel_format(display_dev, PIXEL_FORMAT_RGB_565);
josuah marked this conversation as resolved.
Show resolved Hide resolved
break;
case VIDEO_PIX_FMT_XRGB32:
ret = display_set_pixel_format(display_dev, PIXEL_FORMAT_ARGB_8888);
Expand Down Expand Up @@ -101,24 +96,24 @@
}
#endif

printk("Video device: %s\n", video_dev->name);
LOG_INF("Video device: %s", video_dev->name);

/* Get capabilities */
if (video_get_caps(video_dev, VIDEO_EP_OUT, &caps)) {
LOG_ERR("Unable to retrieve video capabilities");
return 0;
}

printk("- Capabilities:\n");
LOG_INF("- Capabilities:");
while (caps.format_caps[i].pixelformat) {
const struct video_format_cap *fcap = &caps.format_caps[i];
/* fourcc to string */
printk(" %c%c%c%c width [%u; %u; %u] height [%u; %u; %u]\n",
LOG_INF(" %c%c%c%c width [%u; %u; %u] height [%u; %u; %u]",
(char)fcap->pixelformat, (char)(fcap->pixelformat >> 8),
(char)(fcap->pixelformat >> 16), (char)(fcap->pixelformat >> 24),
fcap->width_min, fcap->width_max, fcap->width_step, fcap->height_min,
fcap->height_max, fcap->height_step);
i++;

Check notice on line 116 in samples/drivers/video/capture/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

samples/drivers/video/capture/src/main.c:116 - (char)fcap->pixelformat, (char)(fcap->pixelformat >> 8), - (char)(fcap->pixelformat >> 16), (char)(fcap->pixelformat >> 24), - fcap->width_min, fcap->width_max, fcap->width_step, fcap->height_min, - fcap->height_max, fcap->height_step); + (char)fcap->pixelformat, (char)(fcap->pixelformat >> 8), + (char)(fcap->pixelformat >> 16), (char)(fcap->pixelformat >> 24), + fcap->width_min, fcap->width_max, fcap->width_step, fcap->height_min, + fcap->height_max, fcap->height_step);
}

/* Get default/native format */
Expand All @@ -127,27 +122,47 @@
return 0;
}

printk("- Default format: %c%c%c%c %ux%u\n", (char)fmt.pixelformat,
#if CONFIG_VIDEO_FRAME_HEIGHT
fmt.height = CONFIG_VIDEO_FRAME_HEIGHT;
#endif

#if CONFIG_VIDEO_FRAME_WIDTH
fmt.width = CONFIG_VIDEO_FRAME_WIDTH;
fmt.pitch = fmt.width * 2;
#endif

if (strcmp(CONFIG_VIDEO_PIXEL_FORMAT, "")) {
josuah marked this conversation as resolved.
Show resolved Hide resolved
fmt.pixelformat =
video_fourcc(CONFIG_VIDEO_PIXEL_FORMAT[0], CONFIG_VIDEO_PIXEL_FORMAT[1],
CONFIG_VIDEO_PIXEL_FORMAT[2], CONFIG_VIDEO_PIXEL_FORMAT[3]);
}

LOG_INF("- Video format: %c%c%c%c %ux%u", (char)fmt.pixelformat,
(char)(fmt.pixelformat >> 8), (char)(fmt.pixelformat >> 16),
(char)(fmt.pixelformat >> 24), fmt.width, fmt.height);

Check notice on line 143 in samples/drivers/video/capture/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

samples/drivers/video/capture/src/main.c:143 - (char)(fmt.pixelformat >> 8), (char)(fmt.pixelformat >> 16), - (char)(fmt.pixelformat >> 24), fmt.width, fmt.height); + (char)(fmt.pixelformat >> 8), (char)(fmt.pixelformat >> 16), + (char)(fmt.pixelformat >> 24), fmt.width, fmt.height);
if (video_set_format(video_dev, VIDEO_EP_OUT, &fmt)) {
LOG_ERR("Unable to set format");
return 0;
}

if (!video_get_frmival(video_dev, VIDEO_EP_OUT, &frmival)) {
printk("- Default frame rate : %f fps\n",
LOG_INF("- Default frame rate : %f fps",
1.0 * frmival.denominator / frmival.numerator);
}

Check notice on line 152 in samples/drivers/video/capture/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

samples/drivers/video/capture/src/main.c:152 - 1.0 * frmival.denominator / frmival.numerator); + 1.0 * frmival.denominator / frmival.numerator);

printk("- Supported frame intervals for the default format:\n");
LOG_INF("- Supported frame intervals for the default format:");
memset(&fie, 0, sizeof(fie));
fie.format = &fmt;
while (video_enum_frmival(video_dev, VIDEO_EP_OUT, &fie) == 0) {
if (fie.type == VIDEO_FRMIVAL_TYPE_DISCRETE) {
printk(" %u/%u ", fie.discrete.numerator, fie.discrete.denominator);
LOG_INF(" %u/%u ", fie.discrete.numerator, fie.discrete.denominator);
} else {
printk(" [min = %u/%u; max = %u/%u; step = %u/%u]\n",
LOG_INF(" [min = %u/%u; max = %u/%u; step = %u/%u]",
fie.stepwise.min.numerator, fie.stepwise.min.denominator,
fie.stepwise.max.numerator, fie.stepwise.max.denominator,
fie.stepwise.step.numerator, fie.stepwise.step.denominator);
}

Check notice on line 165 in samples/drivers/video/capture/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

samples/drivers/video/capture/src/main.c:165 - fie.stepwise.min.numerator, fie.stepwise.min.denominator, - fie.stepwise.max.numerator, fie.stepwise.max.denominator, - fie.stepwise.step.numerator, fie.stepwise.step.denominator); + fie.stepwise.min.numerator, fie.stepwise.min.denominator, + fie.stepwise.max.numerator, fie.stepwise.max.denominator, + fie.stepwise.step.numerator, fie.stepwise.step.denominator);
fie.index++;
}

Expand Down Expand Up @@ -190,7 +205,7 @@
return 0;
}

printk("Capture started\n");
LOG_INF("Capture started");

/* Grab video frames */
while (1) {
Expand All @@ -200,9 +215,9 @@
return 0;
}

printk("Got frame %u! size: %u; timestamp %u ms\n", frame++, vbuf->bytesused,
LOG_DBG("Got frame %u! size: %u; timestamp %u ms", frame++, vbuf->bytesused,
vbuf->timestamp);

Check notice on line 220 in samples/drivers/video/capture/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

samples/drivers/video/capture/src/main.c:220 - vbuf->timestamp); + vbuf->timestamp);
#if DT_HAS_CHOSEN(zephyr_display)
video_display_frame(display_dev, vbuf, fmt);
#endif
Expand Down
Loading