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