From ceeb6d790fa071637a6f24ce0df6b9e220690793 Mon Sep 17 00:00:00 2001 From: Anton Date: Fri, 2 Jul 2021 13:41:55 +0400 Subject: pica-client/videodevice: filter out metadata /dev/video devices --- pica-client/videodevice.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'pica-client/videodevice.cpp') diff --git a/pica-client/videodevice.cpp b/pica-client/videodevice.cpp index 24b5b98..781c8a2 100644 --- a/pica-client/videodevice.cpp +++ b/pica-client/videodevice.cpp @@ -1,6 +1,15 @@ #include "videodevice.h" #include +#ifdef Q_OS_LINUX +#include +#include +#include +#include +#include +#include +#endif + VideoDevice::VideoDevice() { @@ -42,6 +51,23 @@ QList VideoDevice::Enumerate() d.humanReadable = QString(v4l2_name.readLine()).trimmed(); v4l2_name.close(); } + /* Skip metadata device nodes introduced in latest kernels + * See: + * https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=088ead25524583e2200aa99111bea2f66a86545a + * https://bugzilla.kernel.org/show_bug.cgi?id=199575 + * Add only devices having V4L2_CAP_VIDEO_CAPTURE capability. + */ + int fd = ::open(d.device.toLatin1().constData(), O_RDWR | O_NONBLOCK); + if (fd < 0) + continue; + struct v4l2_capability cap; + memset(&cap, 0, sizeof cap); + int ret = ::ioctl(fd, VIDIOC_QUERYCAP, &cap); + ::close(fd); + if (ret == -1) + continue; + if (!(cap.device_caps & V4L2_CAP_VIDEO_CAPTURE)) + continue; d.index = index++; result << d; -- cgit v1.2.1