This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 112c87e2adfe8815fa1a311d90755f7c11071051
Author: raiden00pl <[email protected]>
AuthorDate: Wed Nov 4 10:48:29 2026 +0100

    video/v4l2_cap: Enumerate frame intervals per frame size.
    
    VIDIOC_ENUM_FRAMEINTERVALS returned every sensor entry whatever the
    requested size and format.  Entries that set a width, height or pixel
    format now only match a request for it.  This also filters the per-size
    entries of the UVC host driver; tables without them work as before.
    
    Assisted-by: Claude:claude-fable-5-1
    Signed-off-by: raiden00pl <[email protected]>
---
 Documentation/os/drivers/special/video.rst |  3 ++-
 drivers/video/v4l2_cap.c                   | 40 ++++++++++++++++++++++--------
 2 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/Documentation/os/drivers/special/video.rst 
b/Documentation/os/drivers/special/video.rst
index 4f8f8f4ea65..e5fd16057f7 100644
--- a/Documentation/os/drivers/special/video.rst
+++ b/Documentation/os/drivers/special/video.rst
@@ -80,4 +80,5 @@ capture devices; single-zone sensors report one distance 
through the
 sensor framework (``SENSOR_TYPE_PROXIMITY``).  The frame is
 ``V4L2_PIX_FMT_Z16``: one little-endian 16-bit distance in millimetres
 per pixel, 0 when the pixel has no valid target.  The resolutions and
-the frame rates are V4L2 frame sizes and frame intervals.
+the frame rates are V4L2 frame sizes and frame intervals; an interval
+entry that sets a size or a format only applies to it.
diff --git a/drivers/video/v4l2_cap.c b/drivers/video/v4l2_cap.c
index abf07725928..879e832caa0 100644
--- a/drivers/video/v4l2_cap.c
+++ b/drivers/video/v4l2_cap.c
@@ -4049,6 +4049,9 @@ static int capture_enum_frminterval(FAR struct file 
*filep,
 {
   FAR struct inode *inode = filep->f_inode;
   FAR capture_mng_t *cmng = inode->i_private;
+  FAR const struct v4l2_frmivalenum *ival = NULL;
+  uint32_t n = 0;
+  size_t i;
 
   if (cmng == NULL || f == NULL)
     {
@@ -4057,22 +4060,39 @@ static int capture_enum_frminterval(FAR struct file 
*filep,
 
   if (cmng->imgsensor && cmng->imgsensor->frmintervals)
     {
-      if (f->index >= cmng->imgsensor->frmintervals_num)
-        {
-          return -EINVAL;
-        }
-      else
+      /* Entries with a frame size or a format only apply to it */
+
+      for (i = 0; i < cmng->imgsensor->frmintervals_num; i++)
         {
-          f->type = cmng->imgsensor->frmintervals[f->index].type;
-          if (f->type == V4L2_FRMIVAL_TYPE_DISCRETE)
+          ival = &cmng->imgsensor->frmintervals[i];
+          if ((ival->width != 0 && ival->width != f->width) ||
+              (ival->height != 0 && ival->height != f->height) ||
+              (ival->pixel_format != 0 &&
+               ival->pixel_format != f->pixel_format))
             {
-              f->discrete = cmng->imgsensor->frmintervals[f->index].discrete;
+              continue;
             }
-          else
+
+          if (n++ == f->index)
             {
-              f->stepwise = cmng->imgsensor->frmintervals[f->index].stepwise;
+              break;
             }
         }
+
+      if (i >= cmng->imgsensor->frmintervals_num)
+        {
+          return -EINVAL;
+        }
+
+      f->type = ival->type;
+      if (f->type == V4L2_FRMIVAL_TYPE_DISCRETE)
+        {
+          f->discrete = ival->discrete;
+        }
+      else
+        {
+          f->stepwise = ival->stepwise;
+        }
     }
   else
     {

Reply via email to