summaryrefslogtreecommitdiff
path: root/yavta.c
diff options
context:
space:
mode:
authorSakari Ailus <sakari.ailus@iki.fi>2014-04-12 16:23:55 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2014-04-16 20:07:43 +0200
commitd029d1d5bba831b96624d46ee075adbc94cf9c6a (patch)
tree0faf3e22e3a1cd2278ed697dae4c6d3d920b3755 /yavta.c
parent9c4c449917f98b6c7d87947fab72028f2946ded2 (diff)
Separate querying capabilities and determining buffer queue type
Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
Diffstat (limited to 'yavta.c')
-rw-r--r--yavta.c74
1 files changed, 42 insertions, 32 deletions
diff --git a/yavta.c b/yavta.c
index d8f0c59..02a7403 100644
--- a/yavta.c
+++ b/yavta.c
@@ -239,12 +239,8 @@ static void video_init(struct device *dev)
dev->type = (enum v4l2_buf_type)-1;
}
-static int video_open(struct device *dev, const char *devname, int no_query)
+static int video_open(struct device *dev, const char *devname)
{
- struct v4l2_capability cap;
- unsigned int capabilities;
- int ret;
-
dev->fd = open(devname, O_RDWR);
if (dev->fd < 0) {
printf("Error opening device %s: %s (%d).\n", devname,
@@ -254,35 +250,22 @@ static int video_open(struct device *dev, const char *devname, int no_query)
printf("Device %s opened.\n", devname);
- if (no_query) {
- /* Assume capture device. */
- dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- return 0;
- }
+ return 0;
+}
+
+static int video_querycap(struct device *dev, unsigned int *capabilities)
+{
+ struct v4l2_capability cap;
+ int ret;
memset(&cap, 0, sizeof cap);
ret = ioctl(dev->fd, VIDIOC_QUERYCAP, &cap);
if (ret < 0)
return 0;
- capabilities = cap.capabilities & V4L2_CAP_DEVICE_CAPS
+ *capabilities = cap.capabilities & V4L2_CAP_DEVICE_CAPS
? cap.device_caps : cap.capabilities;
- if (capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE)
- dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
- else if (capabilities & V4L2_CAP_VIDEO_OUTPUT_MPLANE)
- dev->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
- else if (capabilities & V4L2_CAP_VIDEO_CAPTURE)
- dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- else if (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 (%s mplanes) device.\n",
cap.card, cap.bus_info,
video_is_capture(dev) ? "capture" : "output",
@@ -290,6 +273,24 @@ static int video_open(struct device *dev, const char *devname, int no_query)
return 0;
}
+static int cap_get_buf_type(unsigned int capabilities)
+{
+ if (capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE) {
+ return V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
+ } else if (capabilities & V4L2_CAP_VIDEO_OUTPUT_MPLANE) {
+ return V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
+ } else if (capabilities & V4L2_CAP_VIDEO_CAPTURE) {
+ return V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ } else if (capabilities & V4L2_CAP_VIDEO_OUTPUT) {
+ return V4L2_BUF_TYPE_VIDEO_OUTPUT;
+ } else {
+ printf("Device supports neither capture nor output.\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
static void video_close(struct device *dev)
{
unsigned int i;
@@ -1577,6 +1578,8 @@ int main(int argc, char *argv[])
/* Options parsings */
const struct v4l2_format_info *info;
+ /* Use video capture by default if query isn't done. */
+ unsigned int capabilities = V4L2_CAP_VIDEO_CAPTURE;
int do_file = 0, do_capture = 0, do_pause = 0;
int do_set_time_per_frame = 0;
int do_enum_formats = 0, do_set_format = 0;
@@ -1766,15 +1769,22 @@ int main(int argc, char *argv[])
if (!do_file)
filename = NULL;
- /* 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);
+ ret = video_open(&dev, argv[optind]);
+ if (ret < 0)
+ return 1;
+
+ if (!no_query) {
+ ret = video_querycap(&dev, &capabilities);
+ if (ret < 0)
+ return 1;
+ }
+
+ ret = cap_get_buf_type(capabilities);
if (ret < 0)
return 1;
- if (dev.type == (enum v4l2_buf_type)-1)
- no_query = 1;
+ if (!video_is_buf_type_valid(&dev))
+ video_set_buf_type(&dev, ret);
dev.memtype = memtype;