-
Notifications
You must be signed in to change notification settings - Fork 8k
drivers: video: Add format size #97197
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
base: main
Are you sure you want to change the base?
Conversation
ngphibang
commented
Oct 8, 2025
- Add a size field into video_format struct.
- Video receiver drivers now need to set the format's size to expose to application. Application should base on the format size to allocate buffers. The caps' min/max_line_count fields (which are needed only for HWs that cannot support the whole image frame) can hence be dropped.
It seems to me that currently there is a hole if a sensor provides a compressed format (ex: OV5640 which is capable, from a HW point of view, to provide JPEG data). So, if the video_bits_per_pixel reports a non zero value, a receiver can estimate the pitch and size (as done in this PR), however if the video_bits_per_pixel is zero (as it would be in case of JPEG), then we cannot apply this calculation and need to get this from another way. (either from the sensor itself, since it could estimate it itself, knowing the quality settings etc etc, or by a rather simple estimation in each receiver, but not based on the video_bits_per_pixel). |
Yes, we should distinguish uncompressed vs compressed formats (can be based on fmt->pitch or video_bits_per_pixel). Will update. |
Yes. Cannot be done on the pitch value I think since pitch is related to the way it is organized into memory, which is not applicable for sensors (which do not write themselves into memory). Hence my proposal to look at video_bits_per_pixel. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/video/video_shell.c
This has a print statement for logging the max count
https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/video/video_emul_rx.c
This will be needing some conversion too, useful for testing this change on CI.
This sounds like a better solution than what I proposed here IMHO #92884 (comment)
include/zephyr/drivers/video.h
Outdated
/** | ||
* @brief size of the buffer in bytes. | ||
* | ||
* For uncompressed formats, this is the size of the raw data buffer in bytes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any word about fractioned frames?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, reworded.
Comments addressed. Note that, I didn't add the format size for compressed format because actually there is no in-tree supported for this case, so difficult to make an estimate. Such an estimate should be done in the future when jpeg format support is added. |
5614ef4
to
8c52f1e
Compare
Sorry, I made some mistake with squashing commits somehow the change in video.h (dropping caps min/max_line_count) and in tcpserversink sample has gone. Just recovered it. |
I should have put a DNM flag on this PR #95862 as I did not find anything more to change so did +1 it, and it got merged before its dependencies (the current "add format size" PR). Maybe this is why. |
doc/releases/release-notes-4.3.rst
Outdated
* The legacy pipe object API was removed. Use the new pipe API instead. | ||
* ``bt_le_set_auto_conn`` | ||
* ``CONFIG_BT_BUF_ACL_RX_COUNT`` | ||
* Removed the ``min_line_count`` and ``max_line_count`` fields from :c:struct:`video_caps`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add this in the migration guide ? If an out of tree app has been using those two fields, it won't compile anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know. The release note is more visible than the migration note ? There is a section for removed stuffs in release note so I added it here. Or should add it in both docs ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Migration guide should I think be here to deal with information users have to read in order to migrate from a previous version to the new one. Basically, without having to read the release-note is should be ok to use straight a new version after taking care of what is described in the migration-guide.
If a user is currently using those 2 fields, it won't build anymore so migration-guide should tell him things about that and optionaly indicates how it should be replaced (if necessary).
Can be added in both docs then I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Indeed API breakages should be documented in Migration Guide. See https://docs.zephyrproject.org/latest/develop/api/api_lifecycle.html.
Note also that release note redirects to Migratin Guide, so I'm not sure you need to duplicate the information unless the api breakage also introduce new feature and hence could be documented in release note as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! Something like this?
* Buffer size information obtained from :c:member:`video_caps.min_line_count` and
:c:member:`video_caps.max_line_count` is now given by :c:member:`video_format.size`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, done. Indeed, I didn't notice that the changes in these fields affects also application, not only driver and for those changes, should go to migration guide:
This document describes the changes required when migrating your application from Zephyr v4.2.0 to
Zephyr v4.3.0.Any other changes (not directly related to migrating applications) can be found in
the :ref:release notes<zephyr_4.3>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small point regarding the migration-guide
My bad, I just saw this now... Nevermind the review request. |
8c52f1e
to
c4b4648
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ngphibang. All good to me.
c4b4648
to
bb65040
Compare
drivers/video/video_esp32_dvp.c
Outdated
return video_get_caps(config->source_dev, caps); | ||
} | ||
|
||
static void video_esp32_compute_fmt(struct video_format *fmt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about making this a common function / helper instead of having this in each driver, and also do the estimation based on the pixelformat ?
So, the proposal is to have a helper that process the size / pitch and basically all drivers call the helper to set their pitch / size.
That should work for most of the drivers and if a driver has a specific pitch, then it won't use the helper and do it within the driver.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, done. A helper would be better.
bb65040
to
4d72b3b
Compare
Add a helper to estimate format size and pitch. Signed-off-by: Phi Bang Nguyen <[email protected]>
Receiver drivers now need to set the format's size to expose it to the application. Application should base on the format size to allocate buffers. The caps' min/max_line_count (which are needed only for HWs that cannot support the whole image frame) can hence be dropped. Signed-off-by: Phi Bang Nguyen <[email protected]>
The mipid02 is just a bridge driver which does not deal with memory so should not expose caps' min_vbuf_count. Signed-off-by: Phi Bang Nguyen <[email protected]>
Mention some dropped fields in the video_caps structure and the buffer allocation size for application. Signed-off-by: Phi Bang Nguyen <[email protected]>
4d72b3b
to
3299582
Compare
Mention a new video_estimate_fmt_size helper. Signed-off-by: Phi Bang Nguyen <[email protected]>
Please retry analysis of this Pull-Request directly on SonarQube Cloud |