From 2fb259833ffc95bf826bcdb0a068f05a180661f5 Mon Sep 17 00:00:00 2001 From: Daniel DeGrasse Date: Fri, 4 Oct 2024 12:03:30 -0500 Subject: [PATCH] samples: drivers: video: update video samples for min/max line count Update video samples to use min/max line count capabilities when allocating video buffers. Signed-off-by: Daniel DeGrasse --- samples/drivers/video/capture/src/main.c | 6 +++++- samples/drivers/video/capture_to_lvgl/src/main.c | 4 ++++ samples/drivers/video/tcpserversink/src/main.c | 12 ++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/samples/drivers/video/capture/src/main.c b/samples/drivers/video/capture/src/main.c index d2d64b84dd4..979727af282 100644 --- a/samples/drivers/video/capture/src/main.c +++ b/samples/drivers/video/capture/src/main.c @@ -182,7 +182,11 @@ int main(void) #endif /* Size to allocate for each buffer */ - bsize = fmt.pitch * fmt.height; + if (caps.min_line_count == LINE_COUNT_HEIGHT) { + bsize = fmt.pitch * fmt.height; + } else { + bsize = fmt.pitch * caps.min_line_count; + } /* Alloc video buffers and enqueue for capture */ for (i = 0; i < ARRAY_SIZE(buffers); i++) { diff --git a/samples/drivers/video/capture_to_lvgl/src/main.c b/samples/drivers/video/capture_to_lvgl/src/main.c index 1c50163d1af..0d0a07e0d55 100644 --- a/samples/drivers/video/capture_to_lvgl/src/main.c +++ b/samples/drivers/video/capture_to_lvgl/src/main.c @@ -88,6 +88,10 @@ int main(void) (char)(fmt.pixelformat >> 16), (char)(fmt.pixelformat >> 24), fmt.width, fmt.height, fmt.pitch); + if (caps.min_line_count != LINE_COUNT_HEIGHT) { + LOG_ERR("Partial framebuffers not supported by this sample"); + return 0; + } /* Size to allocate for each buffer */ bsize = fmt.pitch * fmt.height; diff --git a/samples/drivers/video/tcpserversink/src/main.c b/samples/drivers/video/tcpserversink/src/main.c index 90946be44bd..99186545198 100644 --- a/samples/drivers/video/tcpserversink/src/main.c +++ b/samples/drivers/video/tcpserversink/src/main.c @@ -41,6 +41,7 @@ int main(void) struct video_buffer *buffers[2], *vbuf; int i, ret, sock, client; struct video_format fmt; + struct video_caps caps; #if DT_HAS_CHOSEN(zephyr_camera) const struct device *const video = DEVICE_DT_GET(DT_CHOSEN(zephyr_camera)); @@ -81,6 +82,12 @@ int main(void) return 0; } + /* Get capabilities */ + if (video_get_caps(video, VIDEO_EP_OUT, &caps)) { + LOG_ERR("Unable to retrieve video capabilities"); + return 0; + } + /* Get default/native format */ if (video_get_format(video, VIDEO_EP_OUT, &fmt)) { LOG_ERR("Unable to retrieve video format"); @@ -91,6 +98,11 @@ int main(void) (char)(fmt.pixelformat >> 8), (char)(fmt.pixelformat >> 16), (char)(fmt.pixelformat >> 24), fmt.width, fmt.height); + if (caps.min_line_count != LINE_COUNT_HEIGHT) { + LOG_ERR("Partial framebuffers not supported by this sample"); + return 0; + } + /* Alloc Buffers */ for (i = 0; i < ARRAY_SIZE(buffers); i++) { buffers[i] = video_buffer_alloc(fmt.pitch * fmt.height);