aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrenton Schulz <trenton@norwegianrockcat.com>2021-04-06 19:38:00 +0200
committerHans Verkuil <hverkuil-cisco@xs4all.nl>2021-04-20 14:23:29 +0200
commita9555cea63c9e4c4ac57a375f96a4583a6864df0 (patch)
tree7d816b2b8f5fa21ae886a7215eaac85154536ae2
parentfc95aea735185cf78766a8402f0df73a221ff2ce (diff)
downloadv4l-utils-a9555cea63c9e4c4ac57a375f96a4583a6864df0.tar.gz
Rudimentary support for mi_media_detect_type on FreeBSD.
FreeBSD doesn't have the same uevent and sys filesystem that Linux does. So, use the VIDIOC_QUERYCAP ioctl to find out basic capabilities for a device. The ioctl doesn't give us as much information, but it gets things like webcams, VBIs, and radios. This is better than what was there previously, which was returning unknown. This makes some v4l-utils like v4l2-ctl a little more useful. Signed-off-by: Trenton Schulz <trenton@norwegianrockcat.com> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
-rw-r--r--utils/common/media-info.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/utils/common/media-info.cpp b/utils/common/media-info.cpp
index 29a43fb3..6138eda4 100644
--- a/utils/common/media-info.cpp
+++ b/utils/common/media-info.cpp
@@ -17,6 +17,10 @@
#include <linux/media.h>
#include <media-info.h>
+#ifndef __linux__
+#include <linux/videodev2.h>
+#include <fcntl.h>
+#endif
static std::string num2s(unsigned num, bool is_hex = true)
{
@@ -54,7 +58,7 @@ media_type mi_media_detect_type(const char *device)
if (stat(device, &sb) == -1)
return MEDIA_TYPE_CANT_STAT;
-
+#ifdef __linux__
std::string uevent_path("/sys/dev/char/");
uevent_path += num2s(major(sb.st_rdev), false) + ":" +
@@ -90,6 +94,23 @@ media_type mi_media_detect_type(const char *device)
}
uevent_file.close();
+#else // Not Linux
+ int fd = open(device, O_RDONLY);
+ if (fd >= 0) {
+ struct v4l2_capability caps;
+ int error = ioctl(fd, VIDIOC_QUERYCAP, &caps);
+ close(fd);
+ if (error == 0) {
+ if (caps.device_caps & V4L2_CAP_VIDEO_CAPTURE) {
+ return MEDIA_TYPE_VIDEO;
+ } else if (caps.device_caps & V4L2_CAP_VBI_CAPTURE) {
+ return MEDIA_TYPE_VBI;
+ } else if (caps.device_caps & V4L2_CAP_RADIO) {
+ return MEDIA_TYPE_RADIO;
+ }
+ }
+ }
+#endif
return MEDIA_TYPE_UNKNOWN;
}