From 13b76c2363e3fd11df30869f48f9b9ee517129cc Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 19 Jul 2015 12:53:11 +0200 Subject: grab Linux camera names --- opentrack/camera-names.hpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'opentrack/camera-names.hpp') diff --git a/opentrack/camera-names.hpp b/opentrack/camera-names.hpp index 6f82ba34..77945171 100644 --- a/opentrack/camera-names.hpp +++ b/opentrack/camera-names.hpp @@ -13,6 +13,12 @@ # include #endif +#ifdef __linux +#include +#include +#include +#endif + template QList get_camera_names() { QList ret; @@ -69,12 +75,23 @@ QList 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) { - ret.append(buf); + int fd = open(buf, O_RDONLY); + if (fd == -1) + continue; + struct video_capability video_cap; + if(ioctl(fd, VIDIOCGCAP, &video_cap) == -1) + { + close(fd); + continue; + } + ret.append(video_cap.name); + close(fd); } else { continue; } -- cgit v1.2.3 From 9457c8c2c7e7bc6bf057cbb2e17b2e0f207db572 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 19 Jul 2015 12:58:15 +0200 Subject: ensure camera name indices match We can't make spaces in indices or else wrong camera gets opened. --- opentrack/camera-names.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'opentrack/camera-names.hpp') diff --git a/opentrack/camera-names.hpp b/opentrack/camera-names.hpp index 77945171..d769a24f 100644 --- a/opentrack/camera-names.hpp +++ b/opentrack/camera-names.hpp @@ -80,6 +80,11 @@ QList get_camera_names() { for (int i = 0; i < 16; i++) { char buf[128]; sprintf(buf, "/dev/video%d", i); + if (access(buf, F_OK) == 0) + ret.append(""); + else + continue; + if (access(buf, R_OK | W_OK) == 0) { int fd = open(buf, O_RDONLY); if (fd == -1) @@ -90,7 +95,7 @@ QList get_camera_names() { close(fd); continue; } - ret.append(video_cap.name); + ret[ret.size()-1] = video_cap.name; close(fd); } else { continue; -- cgit v1.2.3 From 82b32622408090dd1c3716b58e292ec706e4fc57 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 19 Jul 2015 13:11:31 +0200 Subject: append more useful name than empty string --- opentrack/camera-names.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'opentrack/camera-names.hpp') diff --git a/opentrack/camera-names.hpp b/opentrack/camera-names.hpp index d769a24f..6e5bc8e7 100644 --- a/opentrack/camera-names.hpp +++ b/opentrack/camera-names.hpp @@ -81,7 +81,7 @@ QList get_camera_names() { char buf[128]; sprintf(buf, "/dev/video%d", i); if (access(buf, F_OK) == 0) - ret.append(""); + ret.append(buf); else continue; -- cgit v1.2.3 From 8339eb029f68840de30dfc6772848784781ff2f5 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 19 Jul 2015 13:11:51 +0200 Subject: cleanup flow --- opentrack/camera-names.hpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'opentrack/camera-names.hpp') diff --git a/opentrack/camera-names.hpp b/opentrack/camera-names.hpp index 6e5bc8e7..ee6d8ceb 100644 --- a/opentrack/camera-names.hpp +++ b/opentrack/camera-names.hpp @@ -97,8 +97,6 @@ QList get_camera_names() { } ret[ret.size()-1] = video_cap.name; close(fd); - } else { - continue; } } #endif -- cgit v1.2.3 From 04a72110203d70338849e47a24b12d6b13fdfed6 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 19 Jul 2015 13:31:22 +0200 Subject: camera names on linux work, finally --- opentrack/camera-names.hpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'opentrack/camera-names.hpp') diff --git a/opentrack/camera-names.hpp b/opentrack/camera-names.hpp index ee6d8ceb..fd869e6b 100644 --- a/opentrack/camera-names.hpp +++ b/opentrack/camera-names.hpp @@ -16,7 +16,8 @@ #ifdef __linux #include #include -#include +#include +#include #endif template @@ -89,13 +90,14 @@ QList get_camera_names() { int fd = open(buf, O_RDONLY); if (fd == -1) continue; - struct video_capability video_cap; - if(ioctl(fd, VIDIOCGCAP, &video_cap) == -1) + struct v4l2_capability video_cap; + if(ioctl(fd, VIDIOC_QUERYCAP, &video_cap) == -1) { + qDebug() << "VIDIOC_QUERYCAP" << errno; close(fd); continue; } - ret[ret.size()-1] = video_cap.name; + ret[ret.size()-1] = reinterpret_cast(video_cap.card); close(fd); } } -- cgit v1.2.3