diff options
author | Sakari Ailus <sakari.ailus@maxwell.research.nokia.com> | 2011-05-04 12:18:51 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2011-05-04 13:06:20 +0200 |
commit | 44b4f2484ebb3014868883273a4dd6f6555c401d (patch) | |
tree | 27ac20a6527e87d6198b3c2c0ad36ec17d10bec2 | |
parent | 5cd3115fdae5989c5765d7fa53454488a17287c2 (diff) |
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 <sakari.ailus@maxwell.research.nokia.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-rw-r--r-- | yavta.c | 52 |
1 files changed, 29 insertions, 23 deletions
@@ -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) |