]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/extras/v4l_id/v4l_id.c
tabs are as useful as a hole in the head
[thirdparty/systemd.git] / src / extras / v4l_id / v4l_id.c
1 /*
2 * Copyright (C) 2009 Kay Sievers <kay.sievers@vrfy.org>
3 * Copyright (c) 2009 Filippo Argiolas <filippo.argiolas@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details:
14 */
15
16 #include <stdio.h>
17 #include <errno.h>
18 #include <string.h>
19 #include <ctype.h>
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
25 #include <errno.h>
26 #include <fcntl.h>
27 #include <getopt.h>
28 #include <sys/types.h>
29 #include <sys/time.h>
30 #include <sys/ioctl.h>
31 #include <linux/videodev2.h>
32
33 int main (int argc, char *argv[])
34 {
35 static const struct option options[] = {
36 { "help", no_argument, NULL, 'h' },
37 {}
38 };
39 int fd;
40 char *device;
41 struct v4l2_capability v2cap;
42
43 while (1) {
44 int option;
45
46 option = getopt_long(argc, argv, "h", options, NULL);
47 if (option == -1)
48 break;
49
50 switch (option) {
51 case 'h':
52 printf("Usage: v4l_id [--help] <device file>\n\n");
53 return 0;
54 default:
55 return 1;
56 }
57 }
58 device = argv[optind];
59
60 if (device == NULL)
61 return 2;
62 fd = open (device, O_RDONLY);
63 if (fd < 0)
64 return 3;
65
66 if (ioctl (fd, VIDIOC_QUERYCAP, &v2cap) == 0) {
67 printf("ID_V4L_VERSION=2\n");
68 printf("ID_V4L_PRODUCT=%s\n", v2cap.card);
69 printf("ID_V4L_CAPABILITIES=:");
70 if ((v2cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) > 0)
71 printf("capture:");
72 if ((v2cap.capabilities & V4L2_CAP_VIDEO_OUTPUT) > 0)
73 printf("video_output:");
74 if ((v2cap.capabilities & V4L2_CAP_VIDEO_OVERLAY) > 0)
75 printf("video_overlay:");
76 if ((v2cap.capabilities & V4L2_CAP_AUDIO) > 0)
77 printf("audio:");
78 if ((v2cap.capabilities & V4L2_CAP_TUNER) > 0)
79 printf("tuner:");
80 if ((v2cap.capabilities & V4L2_CAP_RADIO) > 0)
81 printf("radio:");
82 printf("\n");
83 }
84
85 close (fd);
86 return 0;
87 }