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>
diff --git a/yavta.c b/yavta.c
index 821e526..b1a17de 100644
--- a/yavta.c
+++ b/yavta.c
@@ -109,6 +109,7 @@
 	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 @@
 		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;
-		}
-
-		printf("Device %s opened: %s (%s).\n", devname, cap.card, cap.bus_info);
-	} else {
+	if (no_query) {
+		/* Assume capture device. */
 		dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-		printf("Device %s opened.\n", devname);
+		return 0;
 	}
 
+	memset(&cap, 0, sizeof cap);
+	ret = ioctl(dev->fd, VIDIOC_QUERYCAP, &cap);
+	if (ret < 0)
+		return 0;
+
+	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;
+	}
+
+	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 @@
 	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)