summaryrefslogtreecommitdiffhomepage
path: root/opentrack/camera-names.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-07-19 16:50:41 +0200
committerStanislaw Halik <sthalik@misaki.pl>2015-07-19 16:50:41 +0200
commit4da0c0619cbf052eb87a618aba4c8de79f0d4325 (patch)
treee075b2a2601d6d2f26a8a70fb83cb682cdfb23df /opentrack/camera-names.hpp
parentf9b5b72cbcf9f121e0184f9a907bbffd7e1e16a9 (diff)
parenta8165591d993a23ae71ea4e5bb7df7596688ef7b (diff)
Merge branch 'unstable' into trackhat-ui
Diffstat (limited to 'opentrack/camera-names.hpp')
-rw-r--r--opentrack/camera-names.hpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/opentrack/camera-names.hpp b/opentrack/camera-names.hpp
index 6f82ba34..fd869e6b 100644
--- a/opentrack/camera-names.hpp
+++ b/opentrack/camera-names.hpp
@@ -13,6 +13,13 @@
# include <unistd.h>
#endif
+#ifdef __linux
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <linux/videodev2.h>
+#include <cerrno>
+#endif
+
template<typename = void>
QList<QString> get_camera_names() {
QList<QString> ret;
@@ -69,14 +76,29 @@ QList<QString> get_camera_names() {
qDebug() << "failed CLSID_VideoInputDeviceCategory" << hr;
pSysDevEnum->Release();
-#else
+#endif
+#ifdef __linux
for (int i = 0; i < 16; i++) {
char buf[128];
sprintf(buf, "/dev/video%d", i);
- if (access(buf, R_OK | W_OK) == 0) {
+ if (access(buf, F_OK) == 0)
ret.append(buf);
- } else {
+ else
continue;
+
+ if (access(buf, R_OK | W_OK) == 0) {
+ int fd = open(buf, O_RDONLY);
+ if (fd == -1)
+ continue;
+ struct v4l2_capability video_cap;
+ if(ioctl(fd, VIDIOC_QUERYCAP, &video_cap) == -1)
+ {
+ qDebug() << "VIDIOC_QUERYCAP" << errno;
+ close(fd);
+ continue;
+ }
+ ret[ret.size()-1] = reinterpret_cast<const char*>(video_cap.card);
+ close(fd);
}
}
#endif