From 44b4f2484ebb3014868883273a4dd6f6555c401d Mon Sep 17 00:00:00 2001 From: Sakari Ailus Date: Wed, 4 May 2011 12:18:51 +0300 Subject: Ignore failed VIDIOC_QUERYCAP. This is not a fatal error, and especially subdevs do not support it. If VIDIOC_QUERY returns an error, assume the device is a V4L2 subdev and set the --no-query option. Signed-off-by: Sakari Ailus Signed-off-by: Laurent Pinchart --- yavta.c | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) (limited to 'yavta.c') diff --git a/yavta.c b/yavta.c index 821e526..b1a17de 100644 --- a/yavta.c +++ b/yavta.c @@ -109,6 +109,7 @@ static int video_open(struct device *dev, const char *devname, int no_query) dev->fd = -1; dev->memtype = V4L2_MEMORY_MMAP; dev->buffers = NULL; + dev->type = (enum v4l2_buf_type)-1; dev->fd = open(devname, O_RDWR); if (dev->fd < 0) { @@ -116,33 +117,33 @@ static int video_open(struct device *dev, const char *devname, int no_query) return dev->fd; } - if (!no_query) { - memset(&cap, 0, sizeof cap); - ret = ioctl(dev->fd, VIDIOC_QUERYCAP, &cap); - if (ret < 0) { - printf("Error opening device %s: unable to query " - "device.\n", devname); - close(dev->fd); - return ret; - } + printf("Device %s opened.\n", devname); - if (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) - dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - else if (cap.capabilities & V4L2_CAP_VIDEO_OUTPUT) - dev->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; - else { - printf("Error opening device %s: neither video capture " - "nor video output supported.\n", devname); - close(dev->fd); - return -EINVAL; - } + if (no_query) { + /* Assume capture device. */ + dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + return 0; + } + + memset(&cap, 0, sizeof cap); + ret = ioctl(dev->fd, VIDIOC_QUERYCAP, &cap); + if (ret < 0) + return 0; - printf("Device %s opened: %s (%s).\n", devname, cap.card, cap.bus_info); - } else { + if (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - printf("Device %s opened.\n", devname); + else if (cap.capabilities & V4L2_CAP_VIDEO_OUTPUT) + dev->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; + else { + printf("Error opening device %s: neither video capture " + "nor video output supported.\n", devname); + close(dev->fd); + return -EINVAL; } + printf("Device `%s' on `%s' is a video %s device.\n", + cap.card, cap.bus_info, + dev->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ? "capture" : "output"); return 0; } @@ -1184,11 +1185,16 @@ int main(int argc, char *argv[]) if (!do_file) filename = NULL; - /* Open the video device. */ + /* Open the video device. If the device type isn't recognized, set the + * --no-query option to avoid querying V4L2 subdevs. + */ ret = video_open(&dev, argv[optind], no_query); if (ret < 0) return 1; + if (dev.type == (enum v4l2_buf_type)-1) + no_query = 1; + dev.memtype = memtype; if (do_get_control) -- cgit v1.2.3