xref: /third_party/eudev/src/v4l_id/v4l_id.c (revision 99ca880a)
1/*
2 * Copyright (C) 2009 Kay Sievers <kay@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#ifndef _GNU_SOURCE
17#define _GNU_SOURCE 1
18#endif
19
20#include <stdio.h>
21#include <errno.h>
22#include <string.h>
23#include <ctype.h>
24#include <stdlib.h>
25#include <unistd.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#include "util.h"
34
35int main(int argc, char *argv[]) {
36        static const struct option options[] = {
37                { "help", no_argument, NULL, 'h' },
38                {}
39        };
40        _cleanup_close_ int fd = -1;
41        char *device;
42        struct v4l2_capability v2cap;
43        int c;
44
45        while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
46
47                switch (c) {
48                case 'h':
49                        printf("%s [-h,--help] <device file>\n\n"
50                               "Video4Linux device identification.\n\n"
51                               "  -h  Print this message\n"
52                               , program_invocation_short_name);
53                        return 0;
54                case '?':
55                        return -EINVAL;
56
57                default:
58                        assert_not_reached("Unhandled option");
59                }
60
61        device = argv[optind];
62        if (device == NULL)
63                return 2;
64
65        fd = open(device, O_RDONLY);
66        if (fd < 0)
67                return 3;
68
69        if (ioctl(fd, VIDIOC_QUERYCAP, &v2cap) == 0) {
70                printf("ID_V4L_VERSION=2\n");
71                printf("ID_V4L_PRODUCT=%s\n", v2cap.card);
72                printf("ID_V4L_CAPABILITIES=:");
73                if ((v2cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) > 0)
74                        printf("capture:");
75                if ((v2cap.capabilities & V4L2_CAP_VIDEO_OUTPUT) > 0)
76                        printf("video_output:");
77                if ((v2cap.capabilities & V4L2_CAP_VIDEO_OVERLAY) > 0)
78                        printf("video_overlay:");
79                if ((v2cap.capabilities & V4L2_CAP_AUDIO) > 0)
80                        printf("audio:");
81                if ((v2cap.capabilities & V4L2_CAP_TUNER) > 0)
82                        printf("tuner:");
83                if ((v2cap.capabilities & V4L2_CAP_RADIO) > 0)
84                        printf("radio:");
85                printf("\n");
86        }
87
88        return 0;
89}
90