]>
Commit | Line | Data |
---|---|---|
f13467ec | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
c5a9680e | 2 | /* |
c5a9680e | 3 | * Copyright (c) 2009 Filippo Argiolas <filippo.argiolas@gmail.com> |
c5a9680e KS |
4 | */ |
5 | ||
c5a9680e KS |
6 | #include <fcntl.h> |
7 | #include <getopt.h> | |
1cf40697 | 8 | #include <linux/videodev2.h> |
cf0fbc49 | 9 | #include <stdio.h> |
c5a9680e | 10 | #include <sys/ioctl.h> |
c5a9680e | 11 | |
5356761d | 12 | #include "build.h" |
3ffd4af2 | 13 | #include "fd-util.h" |
93a1f792 | 14 | #include "log.h" |
6fecd78c | 15 | #include "main-func.h" |
5ac0162c | 16 | |
6fecd78c ZJS |
17 | static const char *arg_device = NULL; |
18 | ||
19 | static int parse_argv(int argc, char *argv[]) { | |
912541b0 | 20 | static const struct option options[] = { |
5356761d ZJS |
21 | { "help", no_argument, NULL, 'h' }, |
22 | { "version", no_argument, NULL, 'v' }, | |
912541b0 KS |
23 | {} |
24 | }; | |
fadce6ca | 25 | int c; |
c5a9680e | 26 | |
fadce6ca | 27 | while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) |
fadce6ca | 28 | switch (c) { |
912541b0 | 29 | case 'h': |
6fecd78c | 30 | printf("%s [OPTIONS...] DEVICE\n\n" |
5ac0162c | 31 | "Video4Linux device identification.\n\n" |
5356761d ZJS |
32 | " -h --help Show this help text\n" |
33 | " --version Show package version\n", | |
bc556335 | 34 | program_invocation_short_name); |
912541b0 | 35 | return 0; |
5356761d ZJS |
36 | case 'v': |
37 | return version(); | |
fadce6ca ZJS |
38 | case '?': |
39 | return -EINVAL; | |
912541b0 | 40 | default: |
04499a70 | 41 | assert_not_reached(); |
912541b0 | 42 | } |
c5a9680e | 43 | |
6fecd78c ZJS |
44 | if (!argv[optind]) |
45 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), | |
46 | "DEVICE argument missing."); | |
47 | ||
48 | arg_device = argv[optind]; | |
49 | return 1; | |
50 | } | |
fadce6ca | 51 | |
6fecd78c ZJS |
52 | static int run(int argc, char *argv[]) { |
53 | _cleanup_close_ int fd = -EBADF; | |
54 | struct v4l2_capability v2cap; | |
55 | int r; | |
56 | ||
57 | r = parse_argv(argc, argv); | |
58 | if (r <= 0) | |
59 | return r; | |
60 | ||
42fff80c | 61 | fd = open(arg_device, O_RDONLY|O_CLOEXEC|O_NOCTTY); |
912541b0 | 62 | if (fd < 0) |
6fecd78c | 63 | return log_error_errno(errno, "Failed to open %s: %m", arg_device); |
c5a9680e | 64 | |
5ac0162c | 65 | if (ioctl(fd, VIDIOC_QUERYCAP, &v2cap) == 0) { |
64687610 | 66 | int capabilities; |
6fecd78c | 67 | |
912541b0 KS |
68 | printf("ID_V4L_VERSION=2\n"); |
69 | printf("ID_V4L_PRODUCT=%s\n", v2cap.card); | |
70 | printf("ID_V4L_CAPABILITIES=:"); | |
6fecd78c | 71 | |
64687610 MO |
72 | if (v2cap.capabilities & V4L2_CAP_DEVICE_CAPS) |
73 | capabilities = v2cap.device_caps; | |
74 | else | |
75 | capabilities = v2cap.capabilities; | |
6fecd78c | 76 | |
64687610 MO |
77 | if ((capabilities & V4L2_CAP_VIDEO_CAPTURE) > 0 || |
78 | (capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE) > 0) | |
912541b0 | 79 | printf("capture:"); |
64687610 MO |
80 | if ((capabilities & V4L2_CAP_VIDEO_OUTPUT) > 0 || |
81 | (capabilities & V4L2_CAP_VIDEO_OUTPUT_MPLANE) > 0) | |
912541b0 | 82 | printf("video_output:"); |
64687610 | 83 | if ((capabilities & V4L2_CAP_VIDEO_OVERLAY) > 0) |
912541b0 | 84 | printf("video_overlay:"); |
64687610 | 85 | if ((capabilities & V4L2_CAP_AUDIO) > 0) |
912541b0 | 86 | printf("audio:"); |
64687610 | 87 | if ((capabilities & V4L2_CAP_TUNER) > 0) |
912541b0 | 88 | printf("tuner:"); |
64687610 | 89 | if ((capabilities & V4L2_CAP_RADIO) > 0) |
912541b0 KS |
90 | printf("radio:"); |
91 | printf("\n"); | |
92 | } | |
c5a9680e | 93 | |
912541b0 | 94 | return 0; |
c5a9680e | 95 | } |
6fecd78c ZJS |
96 | |
97 | DEFINE_MAIN_FUNCTION(run); |