]>
Commit | Line | Data |
---|---|---|
f13467ec | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
c5a9680e | 2 | /* |
c5a9680e KS |
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 | ||
c5a9680e | 16 | #include <ctype.h> |
cf0fbc49 | 17 | #include <errno.h> |
c5a9680e KS |
18 | #include <fcntl.h> |
19 | #include <getopt.h> | |
cf0fbc49 TA |
20 | #include <stdio.h> |
21 | #include <stdlib.h> | |
22 | #include <string.h> | |
c5a9680e | 23 | #include <sys/ioctl.h> |
cf0fbc49 TA |
24 | #include <sys/time.h> |
25 | #include <sys/types.h> | |
26 | #include <unistd.h> | |
c5a9680e KS |
27 | #include <linux/videodev2.h> |
28 | ||
3ffd4af2 | 29 | #include "fd-util.h" |
5ac0162c LP |
30 | |
31 | int main(int argc, char *argv[]) { | |
912541b0 KS |
32 | static const struct option options[] = { |
33 | { "help", no_argument, NULL, 'h' }, | |
34 | {} | |
35 | }; | |
254d1313 | 36 | _cleanup_close_ int fd = -EBADF; |
912541b0 KS |
37 | char *device; |
38 | struct v4l2_capability v2cap; | |
fadce6ca | 39 | int c; |
c5a9680e | 40 | |
fadce6ca | 41 | while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) |
c5a9680e | 42 | |
fadce6ca | 43 | switch (c) { |
912541b0 | 44 | case 'h': |
5ac0162c LP |
45 | printf("%s [-h,--help] <device file>\n\n" |
46 | "Video4Linux device identification.\n\n" | |
bc556335 DDM |
47 | " -h Print this message\n", |
48 | program_invocation_short_name); | |
912541b0 | 49 | return 0; |
fadce6ca ZJS |
50 | case '?': |
51 | return -EINVAL; | |
52 | ||
912541b0 | 53 | default: |
04499a70 | 54 | assert_not_reached(); |
912541b0 | 55 | } |
c5a9680e | 56 | |
fadce6ca | 57 | device = argv[optind]; |
4e361acc | 58 | if (!device) |
912541b0 | 59 | return 2; |
fadce6ca | 60 | |
5ac0162c | 61 | fd = open(device, O_RDONLY); |
912541b0 KS |
62 | if (fd < 0) |
63 | return 3; | |
c5a9680e | 64 | |
5ac0162c | 65 | if (ioctl(fd, VIDIOC_QUERYCAP, &v2cap) == 0) { |
64687610 | 66 | int capabilities; |
912541b0 KS |
67 | printf("ID_V4L_VERSION=2\n"); |
68 | printf("ID_V4L_PRODUCT=%s\n", v2cap.card); | |
69 | printf("ID_V4L_CAPABILITIES=:"); | |
64687610 MO |
70 | if (v2cap.capabilities & V4L2_CAP_DEVICE_CAPS) |
71 | capabilities = v2cap.device_caps; | |
72 | else | |
73 | capabilities = v2cap.capabilities; | |
74 | if ((capabilities & V4L2_CAP_VIDEO_CAPTURE) > 0 || | |
75 | (capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE) > 0) | |
912541b0 | 76 | printf("capture:"); |
64687610 MO |
77 | if ((capabilities & V4L2_CAP_VIDEO_OUTPUT) > 0 || |
78 | (capabilities & V4L2_CAP_VIDEO_OUTPUT_MPLANE) > 0) | |
912541b0 | 79 | printf("video_output:"); |
64687610 | 80 | if ((capabilities & V4L2_CAP_VIDEO_OVERLAY) > 0) |
912541b0 | 81 | printf("video_overlay:"); |
64687610 | 82 | if ((capabilities & V4L2_CAP_AUDIO) > 0) |
912541b0 | 83 | printf("audio:"); |
64687610 | 84 | if ((capabilities & V4L2_CAP_TUNER) > 0) |
912541b0 | 85 | printf("tuner:"); |
64687610 | 86 | if ((capabilities & V4L2_CAP_RADIO) > 0) |
912541b0 KS |
87 | printf("radio:"); |
88 | printf("\n"); | |
89 | } | |
c5a9680e | 90 | |
912541b0 | 91 | return 0; |
c5a9680e | 92 | } |