diff options
| author | Anton <anton@picapica> | 2021-07-02 13:41:55 +0400 |
|---|---|---|
| committer | Anton <anton@picapica> | 2021-07-02 13:41:55 +0400 |
| commit | ceeb6d790fa071637a6f24ce0df6b9e220690793 (patch) | |
| tree | 9b400a010049918a638ec5593bae7c61b6571597 /pica-client | |
| parent | 85ce6b8d675ac8ce03ff590e30004c9d3dd16852 (diff) | |
| download | pica-pica-ceeb6d790fa071637a6f24ce0df6b9e220690793.tar.gz pica-pica-ceeb6d790fa071637a6f24ce0df6b9e220690793.zip | |
pica-client/videodevice: filter out metadata /dev/video devices
Diffstat (limited to 'pica-client')
| -rw-r--r-- | pica-client/videodevice.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
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 <QFile> +#ifdef Q_OS_LINUX +#include <linux/videodev2.h> +#include <sys/ioctl.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#endif + VideoDevice::VideoDevice() { @@ -42,6 +51,23 @@ QList<MediaDeviceInfo> 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; |
