Refactor nuttx v4l2

Adjust the v4l2 framework to support both capture and v4l2m2m,
and can easily add other v4l2 features.

Signed-off-by: shizhenghui <shizhenghui@xiaomi.com>
This commit is contained in:
shizhenghui
2023-12-07 16:28:02 +08:00
committed by Xiang Xiao
parent c3a3f79741
commit 255090d594
8 changed files with 3098 additions and 2342 deletions
+3 -3
View File
@@ -47,7 +47,7 @@
#include <nuttx/serial/uart_rpmsg.h> #include <nuttx/serial/uart_rpmsg.h>
#include <nuttx/timers/oneshot.h> #include <nuttx/timers/oneshot.h>
#include <nuttx/video/fb.h> #include <nuttx/video/fb.h>
#include <nuttx/video/video.h> #include <nuttx/video/v4l2_cap.h>
#include <nuttx/timers/oneshot.h> #include <nuttx/timers/oneshot.h>
#include <nuttx/wireless/pktradio.h> #include <nuttx/wireless/pktradio.h>
#include <nuttx/wireless/bluetooth/bt_null.h> #include <nuttx/wireless/bluetooth/bt_null.h>
@@ -300,10 +300,10 @@ int sim_bringup(void)
sim_camera_initialize(); sim_camera_initialize();
ret = video_initialize(CONFIG_SIM_CAMERA_DEV_PATH); ret = capture_initialize(CONFIG_SIM_CAMERA_DEV_PATH);
if (ret < 0) if (ret < 0)
{ {
syslog(LOG_ERR, "ERROR: video_initialize() failed: %d\n", ret); syslog(LOG_ERR, "ERROR: capture_initialize() failed: %d\n", ret);
} }
#endif #endif
+1 -1
View File
@@ -29,7 +29,7 @@ if(CONFIG_DRIVERS_VIDEO)
endif() endif()
if(CONFIG_VIDEO_STREAM) if(CONFIG_VIDEO_STREAM)
list(APPEND SRCS video.c video_framebuff.c) list(APPEND SRCS v4l2_core.c video_framebuff.c v4l2_cap.c)
endif() endif()
# These video drivers depend on I2C support # These video drivers depend on I2C support
+1 -1
View File
@@ -27,7 +27,7 @@ ifeq ($(CONFIG_VIDEO_FB),y)
endif endif
ifeq ($(CONFIG_VIDEO_STREAM),y) ifeq ($(CONFIG_VIDEO_STREAM),y)
CSRCS += video.c video_framebuff.c CSRCS += v4l2_core.c video_framebuff.c v4l2_cap.c
endif endif
# These video drivers depend on I2C support # These video drivers depend on I2C support
+2 -4
View File
@@ -34,6 +34,7 @@
#include <nuttx/video/imgsensor.h> #include <nuttx/video/imgsensor.h>
#include <nuttx/video/imgdata.h> #include <nuttx/video/imgdata.h>
#include <nuttx/video/video.h> #include <nuttx/video/video.h>
#include <nuttx/video/v4l2_cap.h>
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
@@ -779,10 +780,7 @@ int goldfish_camera_initialize(void)
snprintf(devpath, sizeof(devpath), "/dev/video%zd", i); snprintf(devpath, sizeof(devpath), "/dev/video%zd", i);
} }
video_register(devpath, capture_register(devpath, &priv[i]->data, &sensor, 1);
&priv[i]->data,
&sensor,
1);
} }
return 0; return 0;
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+87
View File
@@ -0,0 +1,87 @@
/****************************************************************************
* include/nuttx/video/v4l2_cap.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
****************************************************************************/
#ifndef __NUTTX_VIDEO_V4L2_CAP_H
#define __NUTTX_VIDEO_V4L2_CAP_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/video/imgdata.h>
#include <nuttx/video/imgsensor.h>
#ifdef __cplusplus
extern "C"
{
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/* Initialize capture driver.
*
* param [in] devpath: path to capture device
*
* Return on success, 0 is returned. On failure,
* negative value is returned.
*/
int capture_initialize(FAR const char *devpath);
/* Uninitialize capture driver.
*
* Return on success, 0 is returned. On failure,
* negative value is returned.
*/
int capture_uninitialize(FAR const char *devpath);
/* New API to register capture driver.
*
* param [in] devpath: path to capture device
* param [in] data: provide imgdata ops
* param [in] sensor: provide imgsensor ops array
* param [in] sensor_num: the number of imgsensor ops array
*
* Return on success, 0 is returned. On failure,
* negative value is returned.
*/
int capture_register(FAR const char *devpath,
FAR struct imgdata_s *data,
FAR struct imgsensor_s **sensors,
size_t sensor_num);
/* New API to Unregister capture driver.
*
* param [in] devpath: path to capture device
*
* Return on success, 0 is returned. On failure,
* negative value is returned.
*/
int capture_unregister(FAR const char *devpath);
#ifdef __cplusplus
}
#endif
#endif /* __NUTTX_VIDEO_V4L2_CAP_H */
+92 -24
View File
@@ -30,6 +30,7 @@
****************************************************************************/ ****************************************************************************/
#include <sys/videoio.h> #include <sys/videoio.h>
#include <nuttx/fs/fs.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
@@ -55,31 +56,100 @@ extern "C"
#define VIDEO_HSIZE_3M (2048) /* 3M horizontal size */ #define VIDEO_HSIZE_3M (2048) /* 3M horizontal size */
#define VIDEO_VSIZE_3M (1536) /* 3M vertical size */ #define VIDEO_VSIZE_3M (1536) /* 3M vertical size */
/****************************************************************************
* Public Types
*****************************************************************************/
struct video_format_s
{
uint16_t width;
uint16_t height;
uint32_t pixelformat;
};
typedef struct video_format_s video_format_t;
struct v4l2_s
{
FAR const struct v4l2_ops_s *vops;
FAR const struct file_operations *fops;
};
struct v4l2_ops_s
{
CODE int (*querycap)(FAR struct v4l2_s *ctx,
FAR struct v4l2_capability *cap);
CODE int (*g_input)(FAR int *num);
CODE int (*enum_input)(FAR struct v4l2_s *ctx,
FAR struct v4l2_input *input);
CODE int (*reqbufs)(FAR struct v4l2_s *ctx,
FAR struct v4l2_requestbuffers *reqbufs);
CODE int (*querybuf)(FAR struct v4l2_s *ctx,
FAR struct v4l2_buffer *buf);
CODE int (*qbuf)(FAR struct v4l2_s *ctx,
FAR struct v4l2_buffer *buf);
CODE int (*dqbuf)(FAR struct v4l2_s *ctx,
FAR struct v4l2_buffer *buf, int oflags);
CODE int (*cancel_dqbuf)(FAR struct v4l2_s *ctx,
enum v4l2_buf_type type);
CODE int (*g_fmt)(FAR struct v4l2_s *ctx,
FAR struct v4l2_format *fmt);
CODE int (*s_fmt)(FAR struct v4l2_s *ctx,
FAR struct v4l2_format *fmt);
CODE int (*try_fmt)(FAR struct v4l2_s *ctx,
FAR struct v4l2_format *v4l2);
CODE int (*g_parm)(FAR struct v4l2_s *ctx,
FAR struct v4l2_streamparm *parm);
CODE int (*s_parm)(FAR struct v4l2_s *ctx,
FAR struct v4l2_streamparm *parm);
CODE int (*streamon)(FAR struct v4l2_s *ctx,
FAR enum v4l2_buf_type *type);
CODE int (*streamoff)(FAR struct v4l2_s *ctx,
FAR enum v4l2_buf_type *type);
CODE int (*do_halfpush)(FAR struct v4l2_s *ctx,
bool enable);
CODE int (*takepict_start)(FAR struct v4l2_s *ctx,
int32_t capture_num);
CODE int (*takepict_stop)(FAR struct v4l2_s *ctx,
bool halfpush);
CODE int (*s_selection)(FAR struct v4l2_s *ctx,
FAR struct v4l2_selection *clip);
CODE int (*g_selection)(FAR struct v4l2_s *ctx,
FAR struct v4l2_selection *clip);
CODE int (*queryctrl)(FAR struct v4l2_s *ctx,
FAR struct v4l2_queryctrl *ctrl);
CODE int (*query_ext_ctrl)(FAR struct v4l2_s *ctx,
FAR struct v4l2_query_ext_ctrl *ctrl);
CODE int (*querymenu)(FAR struct v4l2_s *ctx,
FAR struct v4l2_querymenu *menu);
CODE int (*g_ctrl)(FAR struct v4l2_s *ctx,
FAR struct v4l2_control *ctrl);
CODE int (*s_ctrl)(FAR struct v4l2_s *ctx,
FAR struct v4l2_control *ctrl);
CODE int (*g_ext_ctrls)(FAR struct v4l2_s *ctx,
FAR struct v4l2_ext_controls *ctrls);
CODE int (*s_ext_ctrls)(FAR struct v4l2_s *ctx,
FAR struct v4l2_ext_controls *ctrls);
CODE int (*query_ext_ctrl_scene)(FAR struct v4l2_s *ctx,
FAR struct v4s_query_ext_ctrl_scene *ctrl);
CODE int (*querymenu_scene)(FAR struct v4l2_s *ctx,
FAR struct v4s_querymenu_scene *menu);
CODE int (*g_ext_ctrls_scene)(FAR struct v4l2_s *ctx,
FAR struct v4s_ext_controls_scene *ctrls);
CODE int (*s_ext_ctrls_scene)(FAR struct v4l2_s *ctx,
FAR struct v4s_ext_controls_scene *ctrls);
CODE int (*enum_fmt)(FAR struct v4l2_s *ctx,
FAR struct v4l2_fmtdesc *f);
CODE int (*enum_frminterval)(FAR struct v4l2_s *ctx,
FAR struct v4l2_frmivalenum *f);
CODE int (*enum_frmsize)(FAR struct v4l2_s *ctx,
FAR struct v4l2_frmsizeenum *f);
};
/**************************************************************************** /****************************************************************************
* Public Function Prototypes * Public Function Prototypes
****************************************************************************/ ****************************************************************************/
struct imgdata_s;
struct imgsensor_s;
/* Initialize video driver.
*
* param [in] devpath: path to video device
*
* Return on success, 0 is returned. On failure,
* negative value is returned.
*/
int video_initialize(FAR const char *devpath);
/* Uninitialize video driver.
*
* Return on success, 0 is returned. On failure,
* negative value is returned.
*/
int video_uninitialize(FAR const char *devpath);
/* New API to register video driver. /* New API to register video driver.
* *
* param [in] devpath: path to video device * param [in] devpath: path to video device
@@ -92,9 +162,7 @@ int video_uninitialize(FAR const char *devpath);
*/ */
int video_register(FAR const char *devpath, int video_register(FAR const char *devpath,
FAR struct imgdata_s *data, FAR struct v4l2_s *ctx);
FAR struct imgsensor_s **sensors,
size_t sensor_num);
/* New API to Unregister video driver. /* New API to Unregister video driver.
* *