1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (c) 2009 Filippo Argiolas <filippo.argiolas@gmail.com>
8 #include <linux/videodev2.h>
10 #include <sys/ioctl.h>
13 #include "errno-util.h"
16 #include "main-func.h"
18 static const char *arg_device
= NULL
;
20 static int parse_argv(int argc
, char *argv
[]) {
21 static const struct option options
[] = {
22 { "help", no_argument
, NULL
, 'h' },
23 { "version", no_argument
, NULL
, 'v' },
28 while ((c
= getopt_long(argc
, argv
, "h", options
, NULL
)) >= 0)
31 printf("%s [OPTIONS...] DEVICE\n\n"
32 "Video4Linux device identification.\n\n"
33 " -h --help Show this help text\n"
34 " --version Show package version\n",
35 program_invocation_short_name
);
46 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
47 "DEVICE argument missing.");
49 arg_device
= argv
[optind
];
53 static int run(int argc
, char *argv
[]) {
54 _cleanup_close_
int fd
= -EBADF
;
55 struct v4l2_capability v2cap
;
58 r
= parse_argv(argc
, argv
);
62 fd
= open(arg_device
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
);
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
;
71 if (ioctl(fd
, VIDIOC_QUERYCAP
, &v2cap
) == 0) {
74 printf("ID_V4L_VERSION=2\n");
75 printf("ID_V4L_PRODUCT=%s\n", v2cap
.card
);
76 printf("ID_V4L_CAPABILITIES=:");
78 if (v2cap
.capabilities
& V4L2_CAP_DEVICE_CAPS
)
79 capabilities
= v2cap
.device_caps
;
81 capabilities
= v2cap
.capabilities
;
83 if ((capabilities
& V4L2_CAP_VIDEO_CAPTURE
) > 0 ||
84 (capabilities
& V4L2_CAP_VIDEO_CAPTURE_MPLANE
) > 0)
86 if ((capabilities
& V4L2_CAP_VIDEO_OUTPUT
) > 0 ||
87 (capabilities
& V4L2_CAP_VIDEO_OUTPUT_MPLANE
) > 0)
88 printf("video_output:");
89 if ((capabilities
& V4L2_CAP_VIDEO_OVERLAY
) > 0)
90 printf("video_overlay:");
91 if ((capabilities
& V4L2_CAP_AUDIO
) > 0)
93 if ((capabilities
& V4L2_CAP_TUNER
) > 0)
95 if ((capabilities
& V4L2_CAP_RADIO
) > 0)
103 DEFINE_MAIN_FUNCTION(run
);