chiark / gitweb /
d530a6d391748b678862bc8a18a9b40d25c386a5
[elogind.git] / 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/videodev.h>
32 #include <linux/videodev2.h>
33
34 int main (int argc, char *argv[])
35 {
36         static const struct option options[] = {
37                 { "help", no_argument, NULL, 'h' },
38                 {}
39         };
40         int fd;
41         char *device;
42         struct video_capability v1cap;
43         struct v4l2_capability v2cap;
44
45         while (1) {
46                 int option;
47
48                 option = getopt_long(argc, argv, "h", options, NULL);
49                 if (option == -1)
50                         break;
51
52                 switch (option) {
53                 case 'h':
54                         printf("Usage: v4l_id [--help] <device file>\n\n");
55                         return 0;
56                 default:
57                         return 1;
58                 }
59         }
60         device = argv[optind];
61
62         if (device == NULL)
63                 return 2;
64         fd = open (device, O_RDONLY);
65         if (fd < 0)
66                 return 3;
67
68         if (ioctl (fd, VIDIOC_QUERYCAP, &v2cap) == 0) {
69                 printf("ID_V4L_VERSION=2\n");
70                 printf("ID_V4L_PRODUCT=%s\n", v2cap.card);
71                 printf("ID_V4L_CAPABILITIES=:");
72                 if ((v2cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) > 0)
73                         printf("capture:");
74                 if ((v2cap.capabilities & V4L2_CAP_VIDEO_OUTPUT) > 0)
75                         printf("video_output:");
76                 if ((v2cap.capabilities & V4L2_CAP_VIDEO_OVERLAY) > 0)
77                         printf("video_overlay:");
78                 if ((v2cap.capabilities & V4L2_CAP_AUDIO) > 0)
79                         printf("audio:");
80                 if ((v2cap.capabilities & V4L2_CAP_TUNER) > 0)
81                         printf("tuner:");
82                 if ((v2cap.capabilities & V4L2_CAP_RADIO) > 0)
83                         printf("radio:");
84                 printf("\n");
85         } else if (ioctl (fd, VIDIOCGCAP, &v1cap) == 0) {
86                 printf("ID_V4L_VERSION=1\n");
87                 printf("ID_V4L_PRODUCT=%s\n", v1cap.name);
88                 printf("ID_V4L_CAPABILITIES=:");
89                 if ((v1cap.type & VID_TYPE_CAPTURE) > 0)
90                         printf("capture:");
91                 if ((v1cap.type & VID_TYPE_OVERLAY) > 0)
92                         printf("video_overlay:");
93                 if (v1cap.audios > 0)
94                         printf("audio:");
95                 if ((v1cap.type & VID_TYPE_TUNER) > 0)
96                         printf("tuner:");
97                 printf("\n");
98         }
99
100         close (fd);
101         return 0;
102 }