Skip to content
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
4 changes: 2 additions & 2 deletions boards/st/stm32n6570_dk/stm32n6570_dk_common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,10 @@ csi_interface: &dcmipp {
};
};

&venc {
zephyr_h264enc: &venc {
status = "okay";
};

&jpeg {
zephyr_jpegenc: &jpeg {
status = "okay";
};
1 change: 1 addition & 0 deletions doc/releases/release-notes-4.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ New APIs and options

* :c:member:`video_format.size` field
* :c:func:`video_estimate_fmt_size`
* :c:func:`video_transfer_buffer`

.. zephyr-keep-sorted-stop

Expand Down
18 changes: 18 additions & 0 deletions drivers/video/video_common.c
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like nothing but it saves a lot of variable definition in the samples 👍

Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ int video_estimate_fmt_size(struct video_format *fmt)

switch (fmt->pixelformat) {
case VIDEO_PIX_FMT_JPEG:
case VIDEO_PIX_FMT_H264:
/* Rough estimate for the worst case (quality = 100) */
fmt->pitch = 0;
fmt->size = fmt->width * fmt->height * 2;
Expand Down Expand Up @@ -489,3 +490,20 @@ int video_set_compose_format(const struct device *dev, struct video_format *fmt)

return video_set_format(dev, fmt);
}

int video_transfer_buffer(const struct device *src, const struct device *sink,
enum video_buf_type src_type, enum video_buf_type sink_type,
k_timeout_t timeout)
{
struct video_buffer *buf = &(struct video_buffer){.type = src_type};
int ret;

ret = video_dequeue(src, &buf, timeout);
if (ret < 0) {
return ret;
}

buf->type = sink_type;

return video_enqueue(sink, buf);
}
18 changes: 18 additions & 0 deletions include/zephyr/drivers/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,24 @@ int video_estimate_fmt_size(struct video_format *fmt);
*/
int video_set_compose_format(const struct device *dev, struct video_format *fmt);

/**
* @brief Transfer a buffer between 2 video device
*
* Helper function which dequeues a buffer from a source device and enqueues it into a
* sink device, changing its buffer type between the two.
*
* @param src Video device from where buffer is dequeued (source)
* @param sink Video device into which the buffer is queued (sink)
* @param src_type Video buffer type on the source device
* @param sink_type Video buffer type on the sink device
* @param timeout Timeout to be applied on dequeue
*
* @return 0 on success, otherwise a negative errno code
*/
int video_transfer_buffer(const struct device *src, const struct device *sink,
enum video_buf_type src_type, enum video_buf_type sink_type,
k_timeout_t timeout);

/**
* @defgroup video_pixel_formats Video pixel formats
* The '|' characters separate the pixels or logical blocks, and spaces separate the bytes.
Expand Down
32 changes: 26 additions & 6 deletions samples/drivers/video/tcpserversink/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ int configure_encoder(void)
}

buffer->type = VIDEO_BUF_TYPE_OUTPUT;
video_enqueue(encoder_dev, buffer);
if (video_enqueue(encoder_dev, buffer)) {
LOG_ERR("Unable to enqueue encoder output buf");
return -1;
}
Comment on lines +134 to +137
Copy link
Contributor

Choose a reason for hiding this comment

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

How about contributing to samples transition to Zephyr-like coding style for new code, so that the original error code can be returned?

	ret = (video_enqueue(encoder_dev, buffer);
	if (ret < 0) {
		LOG_ERR("Unable to enqueue encoder output buf");
		return ret;
	}


/* Set input format */
if (strcmp(CONFIG_VIDEO_PIXEL_FORMAT, "")) {
Expand Down Expand Up @@ -165,12 +168,16 @@ int encode_frame(struct video_buffer *in, struct video_buffer **out)
int ret;

in->type = VIDEO_BUF_TYPE_INPUT;
video_enqueue(encoder_dev, in);
ret = video_enqueue(encoder_dev, in);
if (ret) {
LOG_ERR("Unable to enqueue encoder input buf");
return ret;
}

(*out)->type = VIDEO_BUF_TYPE_OUTPUT;
ret = video_dequeue(encoder_dev, out, K_FOREVER);
if (ret) {
LOG_ERR("Unable to dequeue encoder buf");
LOG_ERR("Unable to dequeue encoder output buf");
return ret;
}

Expand Down Expand Up @@ -422,7 +429,11 @@ int main(void)

/* Enqueue Buffers */
for (i = 0; i < ARRAY_SIZE(buffers); i++) {
video_enqueue(video_dev, buffers[i]);
ret = video_enqueue(video_dev, buffers[i]);
if (ret) {
LOG_ERR("Unable to enqueue video buf");
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Intentionally returning 0?
Ditto for a few other occurrences below.

Copy link
Author

Choose a reason for hiding this comment

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

Overall in this sample the error code are either return 0 or -1 or ret depending on the function. I think this would be fixed by the rework of video related sample app ongoing in PR #96072 so here I return the same kind of error code as return by other calls "around". That's not good, but overall correction as to be done, which is not in the scope of this PR.

}
}

/* Start video capture */
Expand Down Expand Up @@ -452,7 +463,12 @@ int main(void)
ret = sendall(client, vbuf_out->buffer, vbuf_out->bytesused);

vbuf_out->type = VIDEO_BUF_TYPE_OUTPUT;
video_enqueue(encoder_dev, vbuf_out);
ret = video_enqueue(encoder_dev, vbuf_out);
if (ret) {
LOG_ERR("Unable to enqueue encoder output buf");
return 0;
}

#else
LOG_INF("Sending frame %d", i++);
/* Send video buffer to TCP client */
Expand All @@ -465,7 +481,11 @@ int main(void)
}

vbuf->type = VIDEO_BUF_TYPE_INPUT;
(void)video_enqueue(video_dev, vbuf);
ret = video_enqueue(video_dev, vbuf);
if (ret) {
LOG_ERR("Unable to enqueue video buf");
return 0;
}
} while (!ret);

/* stop capture */
Expand Down
13 changes: 13 additions & 0 deletions samples/subsys/usb/uvc/app_h264enc.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2025 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "app.overlay"

/ {
chosen {
zephyr,videoenc = &zephyr_h264enc;
};
};
13 changes: 13 additions & 0 deletions samples/subsys/usb/uvc/app_jpegenc.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2025 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "app.overlay"

/ {
chosen {
zephyr,videoenc = &zephyr_jpegenc;
};
};
24 changes: 24 additions & 0 deletions samples/subsys/usb/uvc/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,27 @@ tests:
filter: dt_chosen_enabled("zephyr,camera")
integration_platforms:
- arduino_nicla_vision/stm32h747xx/m7
sample.subsys.usb.uvc.encoder.h264:
depends_on:
- usbd
tags: usb video
extra_configs:
- CONFIG_VIDEO_ENCODER_H264=y
extra_args:
- EXTRA_DTC_OVERLAY_FILE="app_h264enc.overlay"
- SHIELD=st_b_cams_imx_mb1854
filter: dt_chosen_enabled("zephyr,camera")
integration_platforms:
- stm32n6570_dk/stm32n657xx/sb
sample.subsys.usb.uvc.encoder.jpeg:
depends_on:
- usbd
tags: usb video
extra_configs:
- CONFIG_VIDEO_ENCODER_JPEG=y
extra_args:
- EXTRA_DTC_OVERLAY_FILE="app_jpegenc.overlay"
- SHIELD=st_b_cams_imx_mb1854
filter: dt_chosen_enabled("zephyr,camera")
integration_platforms:
- stm32n6570_dk/stm32n657xx/sb
Loading