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/incubator-nuttx.git
commit 229c7d30b65ddc953a96b5ebeb0f18e1be111deb Author: SPRESENSE <[email protected]> AuthorDate: Mon Nov 22 10:30:35 2021 +0900 drivers/video: Support ioctl(VIDIOC_QUERYCAP) Support ioctl(VIDIOC_QUERYCAP) to get driver's name. --- drivers/video/isx012.c | 7 +++++++ drivers/video/video.c | 33 +++++++++++++++++++++++++++++++++ include/nuttx/video/imgsensor.h | 2 +- include/nuttx/video/video.h | 20 ++++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/drivers/video/isx012.c b/drivers/video/isx012.c index 050cb28d3e..e644954906 100644 --- a/drivers/video/isx012.c +++ b/drivers/video/isx012.c @@ -217,6 +217,7 @@ static bool is_movie_needed(uint8_t fmt, uint8_t fps); static int isx012_init(void); static int isx012_uninit(void); +static const char *isx012_get_driver_name(void); static int isx012_validate_frame_setting(imgsensor_stream_type_t type, uint8_t nr_datafmt, FAR imgsensor_format_t *datafmts, @@ -616,6 +617,7 @@ static struct imgsensor_ops_s g_isx012_ops = { isx012_init, /* init */ isx012_uninit, /* uninit */ + isx012_get_driver_name, /* get driver name */ isx012_validate_frame_setting, /* validate_frame_setting */ isx012_start_capture, /* start_capture */ isx012_stop_capture, /* stop_capture */ @@ -1284,6 +1286,11 @@ static int isx012_uninit(void) return ret; } +static const char *isx012_get_driver_name(void) +{ + return "ISX012"; +} + static int8_t isx012_get_maximum_fps(uint8_t nr_fmt, FAR imgsensor_format_t *fmt) { diff --git a/drivers/video/video.c b/drivers/video/video.c index 685c7465c2..79b4c6f3ba 100644 --- a/drivers/video/video.c +++ b/drivers/video/video.c @@ -218,6 +218,7 @@ static int video_complete_capture(uint8_t err_code, uint32_t datasize); /* internal function for each cmds of ioctl */ +static int video_querycap(FAR struct v4l2_capability *cap); static int video_reqbufs(FAR struct video_mng_s *vmng, FAR struct v4l2_requestbuffers *reqbufs); static int video_qbuf(FAR struct video_mng_s *vmng, @@ -989,6 +990,33 @@ static int video_close(FAR struct file *filep) return ret; } +static int video_querycap(FAR struct v4l2_capability *cap) +{ + FAR const char *name; + + ASSERT(g_video_sensor_ops); + + if (cap == NULL) + { + return -EINVAL; + } + + if (g_video_sensor_ops->get_driver_name == NULL) + { + return -ENOTTY; + } + + name = g_video_sensor_ops->get_driver_name(); + + memset(cap, 0, sizeof(struct v4l2_capability)); + + /* cap->driver needs to be NULL-terminated. */ + + strlcpy((FAR char *)cap->driver, name, sizeof(cap->driver)); + + return OK; +} + static int video_reqbufs(FAR struct video_mng_s *vmng, FAR struct v4l2_requestbuffers *reqbufs) { @@ -2657,6 +2685,11 @@ static int video_ioctl(FAR struct file *filep, int cmd, unsigned long arg) switch (cmd) { + case VIDIOC_QUERYCAP: + ret = video_querycap((FAR struct v4l2_capability *)arg); + + break; + case VIDIOC_REQBUFS: ret = video_reqbufs(priv, (FAR struct v4l2_requestbuffers *)arg); diff --git a/include/nuttx/video/imgsensor.h b/include/nuttx/video/imgsensor.h index e98759e55c..0254250cf7 100644 --- a/include/nuttx/video/imgsensor.h +++ b/include/nuttx/video/imgsensor.h @@ -305,7 +305,7 @@ struct imgsensor_ops_s { CODE int (*init)(void); CODE int (*uninit)(void); - + CODE const char * (*get_driver_name)(void); CODE int (*validate_frame_setting)(imgsensor_stream_type_t type, uint8_t nr_datafmts, FAR imgsensor_format_t *datafmts, diff --git a/include/nuttx/video/video.h b/include/nuttx/video/video.h index d9c9480ad2..c237125d10 100644 --- a/include/nuttx/video/video.h +++ b/include/nuttx/video/video.h @@ -172,6 +172,12 @@ extern "C" #define V4SIOC_S_EXT_CTRLS_SCENE _VIDIOC(0x001a) +/* Query device capability + * Address pointing to struct v4l2_capability + */ + +#define VIDIOC_QUERYCAP _VIDIOC(0x001b) + #define VIDEO_HSIZE_QVGA (320) /* QVGA horizontal size */ #define VIDEO_VSIZE_QVGA (240) /* QVGA vertical size */ #define VIDEO_HSIZE_VGA (640) /* VGA horizontal size */ @@ -238,6 +244,20 @@ extern "C" * Public Types ****************************************************************************/ +/* V4L2 device capabilities for VIDIOC_QUERYCAP. + * Currently, only member "driver" is supported. + */ + +struct v4l2_capability +{ + uint8_t driver[16]; /* name of driver module(e.g. "bttv" */ + uint8_t card[32]; /* name of the card(e.g. "Yoyodyne TV/FM" */ + uint8_t bus_info[32]; /* name of the bus(e.g. "PCI:0000:05:06.0" */ + uint32_t version; /* version number of the driver */ + uint32_t capabilities; /* Available capabilities of the physical device */ + uint32_t device_caps; /* Device capabilities of the opened device */ +}; + /* Buffer type. * Currently, support only V4L2_BUF_TYPE_VIDEO_CAPTURE and * V4L2_BUF_TYPE_STILL_CAPTURE.
