drivers/video: Support ioctl(VIDIOC_QUERYCAP)

Support ioctl(VIDIOC_QUERYCAP) to get driver's name.
This commit is contained in:
SPRESENSE
2022-05-30 20:38:47 +03:00
committed by Petro Karashchenko
parent eb02528a39
commit 229c7d30b6
4 changed files with 61 additions and 1 deletions
+7
View File
@@ -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)
{
+33
View File
@@ -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);
+1 -1
View File
@@ -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,
+20
View File
@@ -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.