mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 15:58:59 +08:00
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:
@@ -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
@@ -30,6 +30,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/videoio.h>
|
||||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
@@ -55,31 +56,100 @@ extern "C"
|
||||
#define VIDEO_HSIZE_3M (2048) /* 3M horizontal 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
|
||||
****************************************************************************/
|
||||
|
||||
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.
|
||||
*
|
||||
* 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,
|
||||
FAR struct imgdata_s *data,
|
||||
FAR struct imgsensor_s **sensors,
|
||||
size_t sensor_num);
|
||||
FAR struct v4l2_s *ctx);
|
||||
|
||||
/* New API to Unregister video driver.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user