You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2022/12/08 11:39:01 UTC

[nuttx-apps] branch master updated (776136a11 -> 3e2c8fdb4)

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

pkarashchenko pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git


    from 776136a11 Fix various error in Windows native build
     new ca855f3f2 examples/camera: Fix the style issue
     new 02f608b64 examples/camera: Call VIDIOC_S_FMT before VIDIOC_REQBUFS
     new 519c4ccb1 examples/camera: Add FAR for all pointer
     new 3e2c8fdb4 examples/camera: Cast the last argument of ioctl to uintptr_t

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 examples/camera/camera_bkgd.c     |  15 +++---
 examples/camera/camera_fileutil.c |  36 ++++++-------
 examples/camera/camera_fileutil.h |   4 +-
 examples/camera/camera_main.c     | 104 ++++++++++++++++++--------------------
 4 files changed, 74 insertions(+), 85 deletions(-)


[nuttx-apps] 03/04: examples/camera: Add FAR for all pointer

Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 519c4ccb1b987e1be5b28384c6cdb91c666699ea
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Dec 7 10:36:41 2022 +0800

    examples/camera: Add FAR for all pointer
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 examples/camera/camera_fileutil.c |  8 ++++----
 examples/camera/camera_fileutil.h |  4 ++--
 examples/camera/camera_main.c     | 36 +++++++++++++++++++-----------------
 3 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/examples/camera/camera_fileutil.c b/examples/camera/camera_fileutil.c
index 0e8cdd0bf..463567704 100644
--- a/examples/camera/camera_fileutil.c
+++ b/examples/camera/camera_fileutil.c
@@ -40,7 +40,7 @@
  * Private Data
  ****************************************************************************/
 
-static const char *g_save_dir;
+static FAR const char *g_save_dir;
 static int g_framecount;
 
 /****************************************************************************
@@ -54,7 +54,7 @@ static int g_framecount;
  *   Choose strage to write a file.
  ****************************************************************************/
 
-const char *futil_initialize(void)
+FAR const char *futil_initialize(void)
 {
   int ret;
   struct stat stat_buf;
@@ -83,10 +83,10 @@ const char *futil_initialize(void)
  *   Write a image file to selected storage.
  ****************************************************************************/
 
-int futil_writeimage(uint8_t *data, size_t len, const char *fsuffix)
+int futil_writeimage(FAR uint8_t *data, size_t len, FAR const char *fsuffix)
 {
   char fname[IMAGE_FILENAME_LEN];
-  FILE *fp;
+  FAR FILE *fp;
 
   g_framecount++;
   if (g_framecount >= 1000)
diff --git a/examples/camera/camera_fileutil.h b/examples/camera/camera_fileutil.h
index 5e366d9b5..08d2513d7 100644
--- a/examples/camera/camera_fileutil.h
+++ b/examples/camera/camera_fileutil.h
@@ -34,11 +34,11 @@
 
 /* Initialize file util of camera example */
 
-const char *futil_initialize(void);
+FAR const char *futil_initialize(void);
 
 /* Write an image file */
 
-int futil_writeimage(uint8_t *data, size_t len, const char *fsuffix);
+int futil_writeimage(FAR uint8_t *data, size_t len, FAR const char *fsuffix);
 
 #endif  /* __APPS_EXAMPLES_CAMERA_CAMERA_FILEUTIL_H */
 
diff --git a/examples/camera/camera_main.c b/examples/camera/camera_main.c
index e9c9f0bab..0eac422f7 100644
--- a/examples/camera/camera_main.c
+++ b/examples/camera/camera_main.c
@@ -64,7 +64,7 @@
 
 struct v_buffer
 {
-  uint32_t *start;
+  FAR uint32_t *start;
   uint32_t length;
 };
 
@@ -77,14 +77,15 @@ typedef struct v_buffer v_buffer_t;
 static int camera_prepare(int fd, enum v4l2_buf_type type,
                           uint32_t buf_mode, uint32_t pixformat,
                           uint16_t hsize, uint16_t vsize,
-                          struct v_buffer **vbuf,
+                          FAR struct v_buffer **vbuf,
                           uint8_t buffernum, int buffersize);
-static void free_buffer(struct v_buffer *buffers, uint8_t bufnum);
-static int parse_arguments(int argc, char *argv[],
-                           int *capture_num, enum v4l2_buf_type *type);
-static int get_camimage(int fd, struct v4l2_buffer *v4l2_buf,
+static void free_buffer(FAR struct v_buffer *buffers, uint8_t bufnum);
+static int parse_arguments(int argc, FAR char *argv[],
+                           FAR int *capture_num,
+                           FAR enum v4l2_buf_type *type);
+static int get_camimage(int fd, FAR struct v4l2_buffer *v4l2_buf,
                         enum v4l2_buf_type buf_type);
-static int release_camimage(int fd, struct v4l2_buffer *v4l2_buf);
+static int release_camimage(int fd, FAR struct v4l2_buffer *v4l2_buf);
 static int start_stillcapture(int v_fd, enum v4l2_buf_type capture_type);
 static int stop_stillcapture(int v_fd, enum v4l2_buf_type capture_type);
 
@@ -111,7 +112,7 @@ static int stop_stillcapture(int v_fd, enum v4l2_buf_type capture_type);
 static int camera_prepare(int fd, enum v4l2_buf_type type,
                           uint32_t buf_mode, uint32_t pixformat,
                           uint16_t hsize, uint16_t vsize,
-                          struct v_buffer **vbuf,
+                          FAR struct v_buffer **vbuf,
                           uint8_t buffernum, int buffersize)
 {
   int ret;
@@ -239,7 +240,7 @@ static int camera_prepare(int fd, enum v4l2_buf_type type,
  *   All free allocated memory of v_buffer.
  ****************************************************************************/
 
-static void free_buffer(struct v_buffer *buffers, uint8_t bufnum)
+static void free_buffer(FAR struct v_buffer *buffers, uint8_t bufnum)
 {
   uint8_t cnt;
   if (buffers)
@@ -263,8 +264,9 @@ static void free_buffer(struct v_buffer *buffers, uint8_t bufnum)
  *   Parse and decode commandline arguments.
  ****************************************************************************/
 
-static int parse_arguments(int argc, char *argv[],
-                           int *capture_num, enum v4l2_buf_type *type)
+static int parse_arguments(int argc, FAR char *argv[],
+                           FAR int *capture_num,
+                           FAR enum v4l2_buf_type *type)
 {
   if (argc == 1)
     {
@@ -327,7 +329,7 @@ static int parse_arguments(int argc, char *argv[],
  *   DQBUF camera frame buffer from video driver with taken picture data.
  ****************************************************************************/
 
-static int get_camimage(int fd, struct v4l2_buffer *v4l2_buf,
+static int get_camimage(int fd, FAR struct v4l2_buffer *v4l2_buf,
                         enum v4l2_buf_type buf_type)
 {
   int ret;
@@ -355,7 +357,7 @@ static int get_camimage(int fd, struct v4l2_buffer *v4l2_buf,
  *   Re-QBUF to set used frame buffer into video driver.
  ****************************************************************************/
 
-static int release_camimage(int fd, struct v4l2_buffer *v4l2_buf)
+static int release_camimage(int fd, FAR struct v4l2_buffer *v4l2_buf)
 {
   int ret;
 
@@ -466,8 +468,8 @@ int main(int argc, FAR char *argv[])
   struct timeval delta;
   struct timeval wait;
 
-  struct v_buffer *buffers_video = NULL;
-  struct v_buffer *buffers_still = NULL;
+  FAR struct v_buffer *buffers_video = NULL;
+  FAR struct v_buffer *buffers_still = NULL;
 
   /* =====  Parse and Check arguments  ===== */
 
@@ -658,7 +660,7 @@ int main(int argc, FAR char *argv[])
               }
 
 #ifdef CONFIG_EXAMPLES_CAMERA_OUTPUT_LCD
-            nximage_draw((void *)v4l2_buf.m.userptr,
+            nximage_draw((FAR void *)v4l2_buf.m.userptr,
                          VIDEO_HSIZE_QVGA, VIDEO_VSIZE_QVGA);
 #endif
 
@@ -711,7 +713,7 @@ int main(int argc, FAR char *argv[])
                   }
 
                 futil_writeimage(
-                  (uint8_t *)v4l2_buf.m.userptr,
+                  (FAR uint8_t *)v4l2_buf.m.userptr,
                   (size_t)v4l2_buf.bytesused,
                   capture_type == V4L2_BUF_TYPE_VIDEO_CAPTURE ?
                   "RGB" : "JPG");


[nuttx-apps] 04/04: examples/camera: Cast the last argument of ioctl to uintptr_t

Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 3e2c8fdb4162ee190f49e9dcfaad6f754590c814
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Dec 7 10:44:39 2022 +0800

    examples/camera: Cast the last argument of ioctl to uintptr_t
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 examples/camera/camera_main.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/examples/camera/camera_main.c b/examples/camera/camera_main.c
index 0eac422f7..d41f124e5 100644
--- a/examples/camera/camera_main.c
+++ b/examples/camera/camera_main.c
@@ -140,7 +140,7 @@ static int camera_prepare(int fd, enum v4l2_buf_type type,
   fmt.fmt.pix.field       = V4L2_FIELD_ANY;
   fmt.fmt.pix.pixelformat = pixformat;
 
-  ret = ioctl(fd, VIDIOC_S_FMT, (unsigned long)&fmt);
+  ret = ioctl(fd, VIDIOC_S_FMT, (uintptr_t)&fmt);
   if (ret < 0)
     {
       printf("Failed to VIDIOC_S_FMT: errno = %d\n", errno);
@@ -154,7 +154,7 @@ static int camera_prepare(int fd, enum v4l2_buf_type type,
   req.count  = buffernum;
   req.mode   = buf_mode;
 
-  ret = ioctl(fd, VIDIOC_REQBUFS, (unsigned long)&req);
+  ret = ioctl(fd, VIDIOC_REQBUFS, (uintptr_t)&req);
   if (ret < 0)
     {
       printf("Failed to VIDIOC_REQBUFS: errno = %d\n", errno);
@@ -206,10 +206,10 @@ static int camera_prepare(int fd, enum v4l2_buf_type type,
       buf.type = type;
       buf.memory = V4L2_MEMORY_USERPTR;
       buf.index = cnt;
-      buf.m.userptr = (unsigned long)(*vbuf)[cnt].start;
+      buf.m.userptr = (uintptr_t)(*vbuf)[cnt].start;
       buf.length = (*vbuf)[cnt].length;
 
-      ret = ioctl(fd, VIDIOC_QBUF, (unsigned long)&buf);
+      ret = ioctl(fd, VIDIOC_QBUF, (uintptr_t)&buf);
       if (ret)
         {
           printf("Fail QBUF %d\n", errno);
@@ -221,7 +221,7 @@ static int camera_prepare(int fd, enum v4l2_buf_type type,
 
   /* VIDIOC_STREAMON start stream */
 
-  ret = ioctl(fd, VIDIOC_STREAMON, (unsigned long)&type);
+  ret = ioctl(fd, VIDIOC_STREAMON, (uintptr_t)&type);
   if (ret < 0)
     {
       printf("Failed to VIDIOC_STREAMON: errno = %d\n", errno);
@@ -340,7 +340,7 @@ static int get_camimage(int fd, FAR struct v4l2_buffer *v4l2_buf,
   v4l2_buf->type = buf_type;
   v4l2_buf->memory = V4L2_MEMORY_USERPTR;
 
-  ret = ioctl(fd, VIDIOC_DQBUF, (unsigned long)v4l2_buf);
+  ret = ioctl(fd, VIDIOC_DQBUF, (uintptr_t)v4l2_buf);
   if (ret)
     {
       printf("Fail DQBUF %d\n", errno);
@@ -363,7 +363,7 @@ static int release_camimage(int fd, FAR struct v4l2_buffer *v4l2_buf)
 
   /* VIDIOC_QBUF sets buffer pointer into video driver again. */
 
-  ret = ioctl(fd, VIDIOC_QBUF, (unsigned long)v4l2_buf);
+  ret = ioctl(fd, VIDIOC_QBUF, (uintptr_t)v4l2_buf);
   if (ret)
     {
       printf("Fail QBUF %d\n", errno);
@@ -433,7 +433,7 @@ static FAR const char *get_imgsensor_name(int fd)
 {
   static struct v4l2_capability cap;
 
-  ioctl(fd, VIDIOC_QUERYCAP, (unsigned long)&cap);
+  ioctl(fd, VIDIOC_QUERYCAP, (uintptr_t)&cap);
 
   return (FAR const char *)cap.driver;
 }


[nuttx-apps] 01/04: examples/camera: Fix the style issue

Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit ca855f3f230a6e005d9aa5d14a17aedd5dd0ccb1
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Tue Dec 6 19:20:55 2022 +0800

    examples/camera: Fix the style issue
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 examples/camera/camera_bkgd.c     | 15 +++++++--------
 examples/camera/camera_fileutil.c | 30 +++++++++++++-----------------
 examples/camera/camera_main.c     | 26 +++++++++-----------------
 3 files changed, 29 insertions(+), 42 deletions(-)

diff --git a/examples/camera/camera_bkgd.c b/examples/camera/camera_bkgd.c
index 436b02f83..32e07e746 100644
--- a/examples/camera/camera_bkgd.c
+++ b/examples/camera/camera_bkgd.c
@@ -47,7 +47,7 @@ struct nximage_data_s
   /* The NX handles */
 
   NXHANDLE hnx;
-  NXHANDLE hbkgd;
+  NXWINDOW hbkgd;
   bool     connected;
 
   /* The screen resolution */
@@ -115,7 +115,7 @@ static struct nximage_data_s g_nximage =
  *   NX event listener for an event from NX server.
  ****************************************************************************/
 
-FAR void *nximage_listener(FAR void *arg)
+static FAR void *nximage_listener(FAR void *arg)
 {
   int ret;
 
@@ -162,7 +162,7 @@ FAR void *nximage_listener(FAR void *arg)
  ****************************************************************************/
 
 static void nximage_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
-                        bool more, FAR void *arg)
+                           bool more, FAR void *arg)
 {
   ginfo("hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n",
          hwnd, rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y,
@@ -281,7 +281,7 @@ int nximage_initialize(void)
 
   while (!g_nximage.havepos)
     {
-      (void) sem_wait(&g_nximage.sem);
+      sem_wait(&g_nximage.sem);
     }
 
   printf("nximage_initialize: Screen resolution (%d,%d)\n",
@@ -291,7 +291,7 @@ int nximage_initialize(void)
 }
 
 /****************************************************************************
- * Name: nximage_image
+ * Name: nximage_draw
  *
  * Description:
  *   Put the NuttX logo in the center of the display.
@@ -317,11 +317,11 @@ void nximage_draw(FAR void *image, int w, int h)
 
   src[0] = image;
 
-  ret = nx_bitmap((NXWINDOW)g_nximage.hbkgd, &dest, src, &origin,
+  ret = nx_bitmap(g_nximage.hbkgd, &dest, src, &origin,
                   g_nximage.xres * sizeof(nxgl_mxpixel_t));
   if (ret < 0)
     {
-      printf("nximage_image: nx_bitmapwindow failed: %d\n", errno);
+      printf("nximage_image: nx_bitmap failed: %d\n", errno);
     }
 }
 
@@ -336,4 +336,3 @@ void nximage_finalize(void)
 {
   nx_disconnect(g_nximage.hnx);
 }
-
diff --git a/examples/camera/camera_fileutil.c b/examples/camera/camera_fileutil.c
index 743b0c7b3..0e8cdd0bf 100644
--- a/examples/camera/camera_fileutil.c
+++ b/examples/camera/camera_fileutil.c
@@ -40,7 +40,8 @@
  * Private Data
  ****************************************************************************/
 
-static const char *save_dir;
+static const char *g_save_dir;
+static int g_framecount;
 
 /****************************************************************************
  * Public Functions
@@ -65,14 +66,14 @@ const char *futil_initialize(void)
   ret = stat("/mnt/sd0", &stat_buf);
   if (ret < 0)
     {
-      save_dir = "/mnt/spif";
+      g_save_dir = "/mnt/spif";
     }
   else
     {
-      save_dir = "/mnt/sd0";
+      g_save_dir = "/mnt/sd0";
     }
 
-  return save_dir;
+  return g_save_dir;
 }
 
 /****************************************************************************
@@ -84,27 +85,23 @@ const char *futil_initialize(void)
 
 int futil_writeimage(uint8_t *data, size_t len, const char *fsuffix)
 {
-  static char s_fname[IMAGE_FILENAME_LEN];
-  static int s_framecount = 0;
-
+  char fname[IMAGE_FILENAME_LEN];
   FILE *fp;
 
-  s_framecount++;
-  if (s_framecount >= 1000)
+  g_framecount++;
+  if (g_framecount >= 1000)
     {
-      s_framecount = 1;
+      g_framecount = 1;
     }
 
-  memset(s_fname, 0, sizeof(s_fname));
-
-  snprintf(s_fname,
+  snprintf(fname,
            IMAGE_FILENAME_LEN,
            "%s/VIDEO%03d.%s",
-           save_dir, s_framecount, fsuffix);
+           g_save_dir, g_framecount, fsuffix);
 
-  printf("FILENAME:%s\n", s_fname);
+  printf("FILENAME:%s\n", fname);
 
-  fp = fopen(s_fname, "wb");
+  fp = fopen(fname, "wb");
   if (NULL == fp)
     {
       printf("fopen error : %d\n", errno);
@@ -119,4 +116,3 @@ int futil_writeimage(uint8_t *data, size_t len, const char *fsuffix)
   fclose(fp);
   return 0;
 }
-
diff --git a/examples/camera/camera_main.c b/examples/camera/camera_main.c
index 1fe7485e4..024d68f13 100644
--- a/examples/camera/camera_main.c
+++ b/examples/camera/camera_main.c
@@ -36,12 +36,7 @@
 #include <nuttx/video/video.h>
 
 #include "camera_fileutil.h"
-
-#ifdef CONFIG_EXAMPLES_CAMERA_OUTPUT_LCD
-#include <nuttx/nx/nx.h>
-#include <nuttx/nx/nxglib.h>
 #include "camera_bkgd.h"
-#endif
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -88,7 +83,7 @@ static void free_buffer(struct v_buffer *buffers, uint8_t bufnum);
 static int parse_arguments(int argc, char *argv[],
                            int *capture_num, enum v4l2_buf_type *type);
 static int get_camimage(int fd, struct v4l2_buffer *v4l2_buf,
-    enum v4l2_buf_type buf_type);
+                        enum v4l2_buf_type buf_type);
 static int release_camimage(int fd, struct v4l2_buffer *v4l2_buf);
 static int start_stillcapture(int v_fd, enum v4l2_buf_type capture_type);
 static int stop_stillcapture(int v_fd, enum v4l2_buf_type capture_type);
@@ -109,7 +104,7 @@ static int stop_stillcapture(int v_fd, enum v4l2_buf_type capture_type);
  * Name: camera_prepare()
  *
  * Description:
- *   Allocate frame buffer for camera and Queue the allocated buffer
+ *   Allocate frame buffer for camera and queue the allocated buffer
  *   into video driver.
  ****************************************************************************/
 
@@ -168,7 +163,6 @@ static int camera_prepare(int fd, enum v4l2_buf_type type,
   /* Prepare video memory to store images */
 
   *vbuf = malloc(sizeof(v_buffer_t) * buffernum);
-
   if (!(*vbuf))
     {
       printf("Out of memory for array of v_buffer_t[%d]\n", buffernum);
@@ -184,7 +178,7 @@ static int camera_prepare(int fd, enum v4l2_buf_type type,
        * Buffer pointer must be 32bytes aligned.
        */
 
-      (*vbuf)[cnt].start  = memalign(32, buffersize);
+      (*vbuf)[cnt].start = memalign(32, buffersize);
       if (!(*vbuf)[cnt].start)
         {
           printf("Out of memory for image buffer of %d/%d\n",
@@ -192,9 +186,8 @@ static int camera_prepare(int fd, enum v4l2_buf_type type,
 
           /* Release allocated memory. */
 
-          while (cnt)
+          while (cnt--)
             {
-              cnt--;
               free((*vbuf)[cnt].start);
             }
 
@@ -288,7 +281,7 @@ static int parse_arguments(int argc, char *argv[],
       else
         {
           *capture_num = atoi(argv[1]);
-          if ((*capture_num < 0) || (*capture_num > MAX_CAPTURE_NUM))
+          if (*capture_num < 0 || *capture_num > MAX_CAPTURE_NUM)
             {
               printf("Invalid capture num(%d). must be >=0 and <=%d\n",
                     *capture_num, MAX_CAPTURE_NUM);
@@ -303,7 +296,7 @@ static int parse_arguments(int argc, char *argv[],
       if (strncmp(argv[1], "-jpg", 5) == 0)
         {
           *capture_num = atoi(argv[2]);
-          if ((*capture_num < 0) || (*capture_num > MAX_CAPTURE_NUM))
+          if (*capture_num < 0 || *capture_num > MAX_CAPTURE_NUM)
             {
               printf("Invalid capture num(%d). must be >=0 and <=%d\n",
                     *capture_num, MAX_CAPTURE_NUM);
@@ -335,7 +328,7 @@ static int parse_arguments(int argc, char *argv[],
  ****************************************************************************/
 
 static int get_camimage(int fd, struct v4l2_buffer *v4l2_buf,
-    enum v4l2_buf_type buf_type)
+                        enum v4l2_buf_type buf_type)
 {
   int ret;
 
@@ -636,7 +629,7 @@ int main(int argc, FAR char *argv[])
       wait.tv_usec = 0;
       printf("Take %d pictures as %s file in %s after %d seconds.\n",
              capture_num,
-              (capture_type == V4L2_BUF_TYPE_STILL_CAPTURE) ? "JPEG" : "RGB",
+             capture_type == V4L2_BUF_TYPE_STILL_CAPTURE ? "JPEG" : "RGB",
              save_dir, START_CAPTURE_TIME);
       printf(" After finishing taking pictures,"
              " this app will be finished after %d seconds.\n",
@@ -720,7 +713,7 @@ int main(int argc, FAR char *argv[])
                 futil_writeimage(
                   (uint8_t *)v4l2_buf.m.userptr,
                   (size_t)v4l2_buf.bytesused,
-                  (capture_type == V4L2_BUF_TYPE_VIDEO_CAPTURE) ?
+                  capture_type == V4L2_BUF_TYPE_VIDEO_CAPTURE ?
                   "RGB" : "JPG");
 
                 ret = release_camimage(v_fd, &v4l2_buf);
@@ -770,4 +763,3 @@ exit_without_cleaning_videodriver:
 #endif
   return ret;
 }
-


[nuttx-apps] 02/04: examples/camera: Call VIDIOC_S_FMT before VIDIOC_REQBUFS

Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 02f608b64d27761a2c953bcfc398dc93f30f4ac8
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Tue Dec 6 19:21:37 2022 +0800

    examples/camera: Call VIDIOC_S_FMT before VIDIOC_REQBUFS
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 examples/camera/camera_main.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/examples/camera/camera_main.c b/examples/camera/camera_main.c
index 024d68f13..e9c9f0bab 100644
--- a/examples/camera/camera_main.c
+++ b/examples/camera/camera_main.c
@@ -131,20 +131,6 @@ static int camera_prepare(int fd, enum v4l2_buf_type type,
     0
   };
 
-  /* VIDIOC_REQBUFS initiate user pointer I/O */
-
-  req.type   = type;
-  req.memory = V4L2_MEMORY_USERPTR;
-  req.count  = buffernum;
-  req.mode   = buf_mode;
-
-  ret = ioctl(fd, VIDIOC_REQBUFS, (unsigned long)&req);
-  if (ret < 0)
-    {
-      printf("Failed to VIDIOC_REQBUFS: errno = %d\n", errno);
-      return ret;
-    }
-
   /* VIDIOC_S_FMT set format */
 
   fmt.type                = type;
@@ -160,6 +146,20 @@ static int camera_prepare(int fd, enum v4l2_buf_type type,
       return ret;
     }
 
+  /* VIDIOC_REQBUFS initiate user pointer I/O */
+
+  req.type   = type;
+  req.memory = V4L2_MEMORY_USERPTR;
+  req.count  = buffernum;
+  req.mode   = buf_mode;
+
+  ret = ioctl(fd, VIDIOC_REQBUFS, (unsigned long)&req);
+  if (ret < 0)
+    {
+      printf("Failed to VIDIOC_REQBUFS: errno = %d\n", errno);
+      return ret;
+    }
+
   /* Prepare video memory to store images */
 
   *vbuf = malloc(sizeof(v_buffer_t) * buffernum);