All of lore.kernel.org
 help / color / mirror / Atom feed
From: Trenton Schulz <trenton@norwegianrockcat.com>
To: linux-media@vger.kernel.org
Subject: [PATCH] Rudimentary support for mi_media_detect_type on FreeBSD.
Date: Sun,  4 Apr 2021 15:44:30 +0200	[thread overview]
Message-ID: <20210404134430.4537-1-trenton@norwegianrockcat.com> (raw)

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>
---
 utils/common/media-info.cpp | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/utils/common/media-info.cpp b/utils/common/media-info.cpp
index 29a43fb3..3fed5a46 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,22 @@ 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;
+		if (ioctl(fd, VIDIOC_QUERYCAP, &caps) == 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;
+			}
+		}
+		close(fd);
+	}
+#endif
 	return MEDIA_TYPE_UNKNOWN;
 }
 
-- 
2.31.0


             reply	other threads:[~2021-04-04 14:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-04 13:44 Trenton Schulz [this message]
2021-04-06 13:12 ` [PATCH] Rudimentary support for mi_media_detect_type on FreeBSD Hans Petter Selasky
2021-04-06 17:13   ` Trenton Schulz
2021-04-06 17:38     ` Trenton Schulz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210404134430.4537-1-trenton@norwegianrockcat.com \
    --to=trenton@norwegianrockcat.com \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.