examples/camera: Fix the style issue

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2022-12-06 19:20:55 +08:00 committed by Petro Karashchenko
parent 776136a113
commit ca855f3f23
3 changed files with 29 additions and 42 deletions

View File

@ -47,7 +47,7 @@ struct nximage_data_s
/* The NX handles */ /* The NX handles */
NXHANDLE hnx; NXHANDLE hnx;
NXHANDLE hbkgd; NXWINDOW hbkgd;
bool connected; bool connected;
/* The screen resolution */ /* The screen resolution */
@ -115,7 +115,7 @@ static struct nximage_data_s g_nximage =
* NX event listener for an event from NX server. * 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; 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, 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", ginfo("hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n",
hwnd, rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y, 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) while (!g_nximage.havepos)
{ {
(void) sem_wait(&g_nximage.sem); sem_wait(&g_nximage.sem);
} }
printf("nximage_initialize: Screen resolution (%d,%d)\n", printf("nximage_initialize: Screen resolution (%d,%d)\n",
@ -291,7 +291,7 @@ int nximage_initialize(void)
} }
/**************************************************************************** /****************************************************************************
* Name: nximage_image * Name: nximage_draw
* *
* Description: * Description:
* Put the NuttX logo in the center of the display. * 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; 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)); g_nximage.xres * sizeof(nxgl_mxpixel_t));
if (ret < 0) 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); nx_disconnect(g_nximage.hnx);
} }

View File

@ -40,7 +40,8 @@
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
static const char *save_dir; static const char *g_save_dir;
static int g_framecount;
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
@ -65,14 +66,14 @@ const char *futil_initialize(void)
ret = stat("/mnt/sd0", &stat_buf); ret = stat("/mnt/sd0", &stat_buf);
if (ret < 0) if (ret < 0)
{ {
save_dir = "/mnt/spif"; g_save_dir = "/mnt/spif";
} }
else 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) int futil_writeimage(uint8_t *data, size_t len, const char *fsuffix)
{ {
static char s_fname[IMAGE_FILENAME_LEN]; char fname[IMAGE_FILENAME_LEN];
static int s_framecount = 0;
FILE *fp; FILE *fp;
s_framecount++; g_framecount++;
if (s_framecount >= 1000) if (g_framecount >= 1000)
{ {
s_framecount = 1; g_framecount = 1;
} }
memset(s_fname, 0, sizeof(s_fname)); snprintf(fname,
snprintf(s_fname,
IMAGE_FILENAME_LEN, IMAGE_FILENAME_LEN,
"%s/VIDEO%03d.%s", "%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) if (NULL == fp)
{ {
printf("fopen error : %d\n", errno); printf("fopen error : %d\n", errno);
@ -119,4 +116,3 @@ int futil_writeimage(uint8_t *data, size_t len, const char *fsuffix)
fclose(fp); fclose(fp);
return 0; return 0;
} }

View File

@ -36,12 +36,7 @@
#include <nuttx/video/video.h> #include <nuttx/video/video.h>
#include "camera_fileutil.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" #include "camera_bkgd.h"
#endif
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * 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[], static int parse_arguments(int argc, char *argv[],
int *capture_num, enum v4l2_buf_type *type); int *capture_num, enum v4l2_buf_type *type);
static int get_camimage(int fd, struct v4l2_buffer *v4l2_buf, 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 release_camimage(int fd, struct v4l2_buffer *v4l2_buf);
static int start_stillcapture(int v_fd, enum v4l2_buf_type capture_type); 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); 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() * Name: camera_prepare()
* *
* Description: * Description:
* Allocate frame buffer for camera and Queue the allocated buffer * Allocate frame buffer for camera and queue the allocated buffer
* into video driver. * into video driver.
****************************************************************************/ ****************************************************************************/
@ -168,7 +163,6 @@ static int camera_prepare(int fd, enum v4l2_buf_type type,
/* Prepare video memory to store images */ /* Prepare video memory to store images */
*vbuf = malloc(sizeof(v_buffer_t) * buffernum); *vbuf = malloc(sizeof(v_buffer_t) * buffernum);
if (!(*vbuf)) if (!(*vbuf))
{ {
printf("Out of memory for array of v_buffer_t[%d]\n", buffernum); 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. * Buffer pointer must be 32bytes aligned.
*/ */
(*vbuf)[cnt].start = memalign(32, buffersize); (*vbuf)[cnt].start = memalign(32, buffersize);
if (!(*vbuf)[cnt].start) if (!(*vbuf)[cnt].start)
{ {
printf("Out of memory for image buffer of %d/%d\n", 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. */ /* Release allocated memory. */
while (cnt) while (cnt--)
{ {
cnt--;
free((*vbuf)[cnt].start); free((*vbuf)[cnt].start);
} }
@ -288,7 +281,7 @@ static int parse_arguments(int argc, char *argv[],
else else
{ {
*capture_num = atoi(argv[1]); *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", printf("Invalid capture num(%d). must be >=0 and <=%d\n",
*capture_num, MAX_CAPTURE_NUM); *capture_num, MAX_CAPTURE_NUM);
@ -303,7 +296,7 @@ static int parse_arguments(int argc, char *argv[],
if (strncmp(argv[1], "-jpg", 5) == 0) if (strncmp(argv[1], "-jpg", 5) == 0)
{ {
*capture_num = atoi(argv[2]); *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", printf("Invalid capture num(%d). must be >=0 and <=%d\n",
*capture_num, MAX_CAPTURE_NUM); *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, 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; int ret;
@ -636,7 +629,7 @@ int main(int argc, FAR char *argv[])
wait.tv_usec = 0; wait.tv_usec = 0;
printf("Take %d pictures as %s file in %s after %d seconds.\n", printf("Take %d pictures as %s file in %s after %d seconds.\n",
capture_num, 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); save_dir, START_CAPTURE_TIME);
printf(" After finishing taking pictures," printf(" After finishing taking pictures,"
" this app will be finished after %d seconds.\n", " this app will be finished after %d seconds.\n",
@ -720,7 +713,7 @@ int main(int argc, FAR char *argv[])
futil_writeimage( futil_writeimage(
(uint8_t *)v4l2_buf.m.userptr, (uint8_t *)v4l2_buf.m.userptr,
(size_t)v4l2_buf.bytesused, (size_t)v4l2_buf.bytesused,
(capture_type == V4L2_BUF_TYPE_VIDEO_CAPTURE) ? capture_type == V4L2_BUF_TYPE_VIDEO_CAPTURE ?
"RGB" : "JPG"); "RGB" : "JPG");
ret = release_camimage(v_fd, &v4l2_buf); ret = release_camimage(v_fd, &v4l2_buf);
@ -770,4 +763,3 @@ exit_without_cleaning_videodriver:
#endif #endif
return ret; return ret;
} }