Skip to content

video: Drop video endpoint id in video APIs #87070

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

Merged

Conversation

ngphibang
Copy link
Collaborator

@ngphibang ngphibang commented Mar 13, 2025

In the video framework, the video_endpoint_id parameter put in each API function has nothing to do with its meaning and has no usage. They should be removed.

Currently, video drivers in Zephyr upstream are all "typical" video devices e.g., camera sensor, receiver, encoders, etc. which have only one buffer queue and does not need to distinguish which buffer queue it operates on. However, devices like ISP, PxP fall into another catergory which (Linux) calls m2m devices. For this kind of devices, the driver needs two separate buffer queues and hence needs to distinguish between input (which Linux calls "output") and output (which Linux calls "capture") side.

To support this kind of devices, such as this PR and the NXP PxP, add a video_buf_type to distinguish the buffer queue:

  • get_caps(), set/get_format(), enqueue()/dequeue() : the buffer type is embeded in the video_caps, video_format and video_buffer structs itself.
  • video_stream_start/stop() : buffer type is sent as a parameter
  • set/get_ctrl() : no need as control IDs are already different for input and output (and also, we rarely has to set controls on both input and output)
  • set/get/enum_frmival() : N/A.

@zephyrbot zephyrbot added platform: ESP32 Espressif ESP32 area: Samples Samples platform: NXP Drivers NXP Semiconductors, drivers area: Video Video subsystem platform: STM32 ST Micro STM32 labels Mar 13, 2025
@ngphibang ngphibang changed the title video : Remove video endpoint id in video APIs video: Drop video endpoint id in video APIs Mar 13, 2025
Copy link
Collaborator

@josuah josuah left a comment

Choose a reason for hiding this comment

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

It would simplify the application development. I wait CI and answers but am in favor of it!

@josuah josuah added area: API Changes to public APIs Release Notes Required Release notes required for this change labels Mar 13, 2025
@josuah
Copy link
Collaborator

josuah commented Mar 19, 2025

Something I notice now that I read #82158 again...

zephyr_video_device_control_flattened_out

@avolmat-st
Copy link
Collaborator

Hi,

I am currently writing the driver for the DCMIPP camera block of the STM32N6 which has actually 3 outputs. In a sense there is a single device but can have up to 3 streams of data going out.
While most of driver have been using the endpoint with simply VIDEO_EP_OUT, it seemed possible to use this in order to distinguish which pipe to control using this endpoint mechanism. set_stream didn't mentioned any endpoint so this a missing point for a device such as this one since it would be necessary to mention which pipe to start / stop.

Proposed video_buf_type is great thing in order to distinguish between capture and output buffers in case of M2M devices, however this remove the way to select between multiple output (or inputs) of the same type.

In the Linux world, such device is exposed using a multiple video devices (as well as multiple subdevices as well), however in Zephyr I am not aware of a way to have multiple devices which would thus be adressed via the usual set of function (fmt/stream etc etc).

What would you propose to handle such case ?

Screenshot from 2025-04-15 08-54-57

@ngphibang ngphibang force-pushed the remove_video_endpoint_id branch 2 times, most recently from b76d869 to f305207 Compare May 12, 2025 08:53
Copy link
Collaborator

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

Within commit log of

drivers: video: Add video_buf_type

incomming -> incoming
outcomming -> outcoming

zexpect_not_null(vbuf);
zexpect_equal(vbuf->bytesused, vbuf->size);

/* Nothing left in the queue, possible to stop */
zexpect_ok(video_stream_stop(rx_dev));
zexpect_ok(video_stream_stop(rx_dev, VIDEO_BUF_TYPE_OUTPUT));
Copy link
Collaborator

Choose a reason for hiding this comment

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

VIDEO_BUF_TYPE_OUTPUT is introduced in the following commit hence this commit won't probably build (?). This line should probably be added within the next commit introducing the buf type enum.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I mistook the commit id when rebasing to fix CI.

@@ -162,7 +163,7 @@ static int nxp_video_sdma_enqueue(const struct device *dev, struct video_buffer
k_fifo_put(&data->fifo_in, vbuf);
if (data->stream_starved) {
/* Kick SmartDMA off */
nxp_video_sdma_set_stream(dev, true);
nxp_video_sdma_set_stream(dev, true, vbuf->type);
Copy link
Collaborator

Choose a reason for hiding this comment

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

is vbuf->type correct here ? Considering that there is a type field (buf_type) within the video buffer structure this can work however I do not see any place where the video buffer type is being set.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it's pointed out in the commit message, for those APIs, the application needs to set the type field but I forgot to do it. Thanks !

@ngphibang ngphibang force-pushed the remove_video_endpoint_id branch 2 times, most recently from f477409 to c722650 Compare May 12, 2025 20:34
@dleach02
Copy link
Member

Coding guidelines complains about the signal variable is a reserved indentifier in some video functions k_poll_signal *signal but it is NOT related to the changes:

Error: drivers/video/video_mcux_csi.c:374:WARNING: Violation to rule 21.2 (Should not used a reserved identifier) - signal
drivers/video/video_sw_generator.c:229:WARNING: Violation to rule 21.2 (Should not used a reserved identifier) - signal
include/zephyr/drivers/video.h:711:WARNING: Violation to rule 21.2 (Should not used a reserved identifier) - signal
Error: Process completed with exit code 1.

@ngphibang it is because you modified the line. The project may have turned on some checking here. I'll note that I see inconsistent naming where we sometimes use "sig" and other times use "signal". My recommendation is to change the "signal" to "sig" to be compliant.

Copy link
Collaborator

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

very minor comment regarding function parameter description, apart from that LGTM.

@ngphibang ngphibang force-pushed the remove_video_endpoint_id branch from c722650 to 9169626 Compare May 13, 2025 07:10
@ngphibang
Copy link
Collaborator Author

@ngphibang it is because you modified the line. The project may have turned on some checking here. I'll note that I see inconsistent naming where we sometimes use "sig" and other times use "signal". My recommendation is to change the "signal" to "sig" to be compliant.

I added a commit to rename the signal variables to avoid code compliance violation for this PR (though this is not related to the PR changes).

avolmat-st
avolmat-st previously approved these changes May 13, 2025
Copy link
Collaborator

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

uLipe
uLipe previously approved these changes May 13, 2025
ngphibang added 4 commits May 14, 2025 09:56
When stopping, the framework calls driver's stop callback then driver's
flush callback. Hence, driver's flush callback does not need to call
stop callback again.

Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
The video endpoints are already described in the devicetree. The
video_endpoint_id parameter in each video API is not necessary and has
no usage. Drop it.

Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
M2M devices like ISPs or PxP have two separate buffer queues, i.e.
incoming and outcoming queues. For each API, the driver needs to
distinguish on which queue it needs to take action.

Add video buffer type to support this kind of devices.

- get_caps(), set/get_format(), enqueue()/dequeue(): the buffer type
is embeded in the video_caps, video_format and video_buffer structs

- video_stream_start/stop() : buffer type needs is sent as a parameter

Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
Rename signal variables to sig to be compliant with code rule 21.2

Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
@ngphibang ngphibang dismissed stale reviews from uLipe and avolmat-st via 1cbc868 May 14, 2025 08:22
@ngphibang ngphibang force-pushed the remove_video_endpoint_id branch from 9169626 to 1cbc868 Compare May 14, 2025 08:22
@ngphibang
Copy link
Collaborator Author

Rebased as #89627 has been merged.

Copy link

Copy link
Collaborator

@josuah josuah left a comment

Choose a reason for hiding this comment

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

I will happily rebase my PRs as soon as I am back. :]

@kartben kartben merged commit 7b42139 into zephyrproject-rtos:main May 16, 2025
26 checks passed
if (ep != VIDEO_EP_OUT) {
return -EINVAL;
}

/* ESP32 produces full frames */
caps->min_line_count = caps->max_line_count = LINE_COUNT_HEIGHT;

/* Forward the message to the source device */
return video_get_caps(config->source_dev, ep, caps);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missed updating this line here. #90090

Copy link
Collaborator Author

@ngphibang ngphibang May 17, 2025

Choose a reason for hiding this comment

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

Yes, I missed it. Thank you ! Searching all "ep" pattern was difficult ... Having esp32 svp driver built-only test would help ...

Copy link
Collaborator

@sylvioalves sylvioalves May 17, 2025

Choose a reason for hiding this comment

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

I am checking PR Twister tests.. sounds there is no video test case at all. Is it? I mean, there is some sample code but none is being triggered in CI.

Copy link
Collaborator Author

@ngphibang ngphibang May 17, 2025

Choose a reason for hiding this comment

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

Yes, test case for esp32 dvp was missing in build_all/video tests. I can add it at the end of the day (unless you do it faster)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I updated the PR. Thanks!

@ngphibang ngphibang deleted the remove_video_endpoint_id branch June 24, 2025 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: API Changes to public APIs area: Samples Samples area: Video Video subsystem platform: ESP32 Espressif ESP32 platform: NXP Drivers NXP Semiconductors, drivers platform: STM32 ST Micro STM32 Release Notes Required Release notes required for this change Release Notes To be mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants