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

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

commit 8f2b15f454a1c9b1c938e928093c6e86b99d9f66
Author: niyinghao <[email protected]>
AuthorDate: Thu Sep 25 21:07:20 2025 +0800

    v4l2-m2m: add driver's support memory mode check
    
    Validate memory mode support before enabling it.
    
    Signed-off-by: niyinghao <[email protected]>
---
 drivers/video/v4l2_m2m.c       | 14 ++++++++++++++
 include/nuttx/video/v4l2_m2m.h | 20 ++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/drivers/video/v4l2_m2m.c b/drivers/video/v4l2_m2m.c
index bde348b3bda..109e69c6f73 100644
--- a/drivers/video/v4l2_m2m.c
+++ b/drivers/video/v4l2_m2m.c
@@ -288,12 +288,26 @@ static int codec_reqbufs(FAR struct file *filep,
   reqbufs->mode = V4L2_BUF_MODE_FIFO;
   if (V4L2_TYPE_IS_OUTPUT(reqbufs->type))
     {
+      ret = CODEC_OUTPUT_TRY_MEMORY(cmng->codec, cfile->priv,
+                                    reqbufs->memory);
+      if (ret < 0)
+        {
+          return ret;
+        }
+
       buf_size = CODEC_OUTPUT_G_BUFSIZE(cmng->codec, cfile->priv);
       buf_cnt = CODEC_OUTPUT_G_BUFCNT(cmng->codec, cfile->priv);
       reqbufs->count = MIN(buf_cnt, reqbufs->count);
     }
   else
     {
+      ret = CODEC_CAPTURE_TRY_MEMORY(cmng->codec, cfile->priv,
+                                     reqbufs->memory);
+      if (ret < 0)
+        {
+          return ret;
+        }
+
       buf_size = CODEC_CAPTURE_G_BUFSIZE(cmng->codec, cfile->priv);
       buf_cnt = CODEC_CAPTURE_G_BUFCNT(cmng->codec, cfile->priv);
       reqbufs->count = MIN(buf_cnt, reqbufs->count);
diff --git a/include/nuttx/video/v4l2_m2m.h b/include/nuttx/video/v4l2_m2m.h
index 90b61e611ed..4110c6fea0c 100644
--- a/include/nuttx/video/v4l2_m2m.h
+++ b/include/nuttx/video/v4l2_m2m.h
@@ -182,6 +182,18 @@
   ((codec)->ops->output_g_bufcnt ? \
    (codec)->ops->output_g_bufcnt(priv) : V4L2_REQBUFS_COUNT_MAX)
 
+#define CODEC_CAPTURE_TRY_MEMORY(codec, priv, mem) \
+  ((codec)->ops->capture_try_memory ? \
+   (codec)->ops->capture_try_memory(priv, mem) : \
+   ((mem == V4L2_MEMORY_MMAP || mem == V4L2_MEMORY_USERPTR) ? \
+    0 : -ENOTTY))
+
+#define CODEC_OUTPUT_TRY_MEMORY(codec, priv, mem) \
+  ((codec)->ops->output_try_memory ? \
+   (codec)->ops->output_try_memory(priv, mem) : \
+   ((mem == V4L2_MEMORY_MMAP || mem == V4L2_MEMORY_USERPTR) ? \
+    0 : -ENOTTY))
+
 /****************************************************************************
  * Public Types
  ****************************************************************************/
@@ -250,6 +262,14 @@ struct codec_ops_s
   CODE void *(*alloc_buf)(FAR void *priv, size_t size);
   CODE void (*free_buf)(FAR void *priv, FAR void *addr);
 
+  /* Memory mode query interface.
+  *  If the driver does not implement this interface, the v4l2-m2m
+  *  default driver only supports V4L2_MEMORY_MMAP and V4L2_MEMORY_USERPTR.
+  */
+
+  CODE int (*capture_try_memory)(FAR void *priv, enum v4l2_memory mem);
+  CODE int (*output_try_memory)(FAR void *priv, enum v4l2_memory mem);
+
   /* Stream type-dependent parameter ioctls */
 
   CODE int (*capture_g_parm)(FAR void *priv,

Reply via email to