From dbc4722f14aa6d4b3322405c9251c5cee2e165d8 Mon Sep 17 00:00:00 2001
From: Stanislaw Halik <sthalik@misaki.pl>
Date: Sun, 6 Dec 2015 02:14:23 +0100
Subject: api/camera: move from header

There's no need to have a copy in each module.
---
 opentrack/camera-names.hpp | 113 +--------------------------------------------
 1 file changed, 2 insertions(+), 111 deletions(-)

(limited to 'opentrack/camera-names.hpp')

diff --git a/opentrack/camera-names.hpp b/opentrack/camera-names.hpp
index f6ab736e..ef914458 100644
--- a/opentrack/camera-names.hpp
+++ b/opentrack/camera-names.hpp
@@ -10,116 +10,7 @@
 
 #include <QList>
 #include <QString>
-#include <QDebug>
 
-#if defined(OPENTRACK_API) && defined(_WIN32)
-#   define NO_DSHOW_STRSAFE
-#   include <windows.h>
-#   include <dshow.h>
-#endif
+QList<QString> get_camera_names();
+int camera_name_to_index(const QString &name);
 
-#if defined(OPENTRACK_API) && (defined(__unix) || defined(__linux) || defined(__APPLE__))
-#   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;
-#if defined(_WIN32)
-    // Create the System Device Enumerator.
-    HRESULT hr;
-    hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
-    if (FAILED(hr))
-        qDebug() << "failed CoInitializeEx" << hr;
-    ICreateDevEnum *pSysDevEnum = NULL;
-    hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysDevEnum);
-    if (FAILED(hr))
-    {
-        qDebug() << "failed CLSID_SystemDeviceEnum" << hr;
-        return ret;
-    }
-    // Obtain a class enumerator for the video compressor category.
-    IEnumMoniker *pEnumCat = NULL;
-    hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0);
-
-    if (hr == S_OK) {
-        // Enumerate the monikers.
-        IMoniker *pMoniker = NULL;
-        ULONG cFetched;
-        while (pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK) {
-            IPropertyBag *pPropBag;
-            hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag);
-            if (SUCCEEDED(hr))	{
-                // To retrieve the filter's friendly name, do the following:
-                VARIANT varName;
-                VariantInit(&varName);
-                hr = pPropBag->Read(L"FriendlyName", &varName, 0);
-                if (SUCCEEDED(hr))
-                {
-                    // Display the name in your UI somehow.
-                    QString str((QChar*)varName.bstrVal, wcslen(varName.bstrVal));
-                    ret.append(str);
-                }
-                VariantClear(&varName);
-
-                ////// To create an instance of the filter, do the following:
-                ////IBaseFilter *pFilter;
-                ////hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter,
-                ////	(void**)&pFilter);
-                // Now add the filter to the graph.
-                //Remember to release pFilter later.
-                pPropBag->Release();
-            }
-            pMoniker->Release();
-        }
-        pEnumCat->Release();
-    }
-    else
-        qDebug() << "failed CLSID_VideoInputDeviceCategory" << hr;
-    
-    pSysDevEnum->Release();
-#endif
-#ifdef __linux
-    for (int i = 0; i < 16; i++) {
-        char buf[128];
-        sprintf(buf, "/dev/video%d", i);
-        if (access(buf, F_OK) == 0)
-            ret.append(buf);
-        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
-    return ret;
-}
-
-template<typename = void>
-int camera_name_to_index(const QString &name)
-{
-    auto list = get_camera_names();
-    int ret = list.indexOf(name);
-    if (ret < 0)
-        ret = 0;
-    return ret;
-}
-- 
cgit v1.2.3


From 211a17996e3ffc0d84c985c43c612da32923b42d Mon Sep 17 00:00:00 2001
From: Stanislaw Halik <sthalik@misaki.pl>
Date: Sun, 6 Dec 2015 02:24:44 +0100
Subject: api/camera-names: move to compat/

---
 opentrack-compat/CMakeLists.txt         |   1 +
 opentrack-compat/camera-names.cpp       | 113 ++++++++++++++++++++++++++++++++
 opentrack-compat/camera-names.hpp       |  22 +++++++
 opentrack/CMakeLists.txt                |   1 -
 opentrack/camera-names.cpp              | 113 --------------------------------
 opentrack/camera-names.hpp              |  16 -----
 opentrack/opencv-camera-dialog.hpp      |   2 +-
 tracker-aruco/ftnoir_tracker_aruco.cpp  |   2 +-
 tracker-pt/ftnoir_tracker_pt.cpp        |   2 +-
 tracker-pt/ftnoir_tracker_pt_dialog.cpp |   2 +-
 10 files changed, 140 insertions(+), 134 deletions(-)
 create mode 100644 opentrack-compat/camera-names.cpp
 create mode 100644 opentrack-compat/camera-names.hpp
 delete mode 100644 opentrack/camera-names.cpp
 delete mode 100644 opentrack/camera-names.hpp

(limited to 'opentrack/camera-names.hpp')

diff --git a/opentrack-compat/CMakeLists.txt b/opentrack-compat/CMakeLists.txt
index 37d53e6c..8dba67e2 100644
--- a/opentrack-compat/CMakeLists.txt
+++ b/opentrack-compat/CMakeLists.txt
@@ -2,3 +2,4 @@ opentrack_boilerplate(opentrack-compat NO-COMPAT NO-LINKER-SCRIPT LINKAGE)
 if(NOT WIN32 AND NOT APPLE)
     target_link_libraries(opentrack-compat rt)
 endif()
+link_with_dinput8(opentrack-compat)
diff --git a/opentrack-compat/camera-names.cpp b/opentrack-compat/camera-names.cpp
new file mode 100644
index 00000000..72bcf41a
--- /dev/null
+++ b/opentrack-compat/camera-names.cpp
@@ -0,0 +1,113 @@
+#include "camera-names.hpp"
+
+#if defined(OPENTRACK_API) && defined(_WIN32)
+#   define NO_DSHOW_STRSAFE
+#   include <windows.h>
+#   include <dshow.h>
+#endif
+
+#if defined(OPENTRACK_API) && (defined(__unix) || defined(__linux) || defined(__APPLE__))
+#   include <unistd.h>
+#endif
+
+#ifdef __linux
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <linux/videodev2.h>
+#include <cerrno>
+#endif
+
+#include <QDebug>
+
+OPENTRACK_COMPAT_EXPORT int camera_name_to_index(const QString &name)
+{
+    auto list = get_camera_names();
+    int ret = list.indexOf(name);
+    if (ret < 0)
+        ret = 0;
+    return ret;
+}
+
+OPENTRACK_COMPAT_EXPORT QList<QString> get_camera_names() {
+    QList<QString> ret;
+#if defined(_WIN32)
+    // Create the System Device Enumerator.
+    HRESULT hr;
+    hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
+    if (FAILED(hr))
+        qDebug() << "failed CoInitializeEx" << hr;
+    ICreateDevEnum *pSysDevEnum = NULL;
+    hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysDevEnum);
+    if (FAILED(hr))
+    {
+        qDebug() << "failed CLSID_SystemDeviceEnum" << hr;
+        return ret;
+    }
+    // Obtain a class enumerator for the video compressor category.
+    IEnumMoniker *pEnumCat = NULL;
+    hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0);
+
+    if (hr == S_OK) {
+        // Enumerate the monikers.
+        IMoniker *pMoniker = NULL;
+        ULONG cFetched;
+        while (pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK) {
+            IPropertyBag *pPropBag;
+            hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag);
+            if (SUCCEEDED(hr))	{
+                // To retrieve the filter's friendly name, do the following:
+                VARIANT varName;
+                VariantInit(&varName);
+                hr = pPropBag->Read(L"FriendlyName", &varName, 0);
+                if (SUCCEEDED(hr))
+                {
+                    // Display the name in your UI somehow.
+                    QString str((QChar*)varName.bstrVal, wcslen(varName.bstrVal));
+                    ret.append(str);
+                }
+                VariantClear(&varName);
+
+                ////// To create an instance of the filter, do the following:
+                ////IBaseFilter *pFilter;
+                ////hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter,
+                ////	(void**)&pFilter);
+                // Now add the filter to the graph.
+                //Remember to release pFilter later.
+                pPropBag->Release();
+            }
+            pMoniker->Release();
+        }
+        pEnumCat->Release();
+    }
+    else
+        qDebug() << "failed CLSID_VideoInputDeviceCategory" << hr;
+    
+    pSysDevEnum->Release();
+#endif
+#ifdef __linux
+    for (int i = 0; i < 16; i++) {
+        char buf[128];
+        sprintf(buf, "/dev/video%d", i);
+        if (access(buf, F_OK) == 0)
+            ret.append(buf);
+        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
+    return ret;
+}
\ No newline at end of file
diff --git a/opentrack-compat/camera-names.hpp b/opentrack-compat/camera-names.hpp
new file mode 100644
index 00000000..c2879000
--- /dev/null
+++ b/opentrack-compat/camera-names.hpp
@@ -0,0 +1,22 @@
+/* Copyright (c) 2014-2015, Stanislaw Halik <sthalik@misaki.pl>
+
+ * Permission to use, copy, modify, and/or distribute this
+ * software for any purpose with or without fee is hereby granted,
+ * provided that the above copyright notice and this permission
+ * notice appear in all copies.
+ */
+
+#pragma once
+
+#include <QList>
+#include <QString>
+
+#ifdef BUILD_compat
+#   include "compat-export.hpp"
+#else
+#   include "compat-import.hpp"
+#endif
+
+OPENTRACK_COMPAT_EXPORT QList<QString> get_camera_names();
+OPENTRACK_COMPAT_EXPORT int camera_name_to_index(const QString &name);
+
diff --git a/opentrack/CMakeLists.txt b/opentrack/CMakeLists.txt
index de5975e2..08003a5c 100644
--- a/opentrack/CMakeLists.txt
+++ b/opentrack/CMakeLists.txt
@@ -4,5 +4,4 @@ if(NOT WIN32)
 else()
     target_link_libraries(opentrack-api winmm)
 endif()
-link_with_dinput8(opentrack-api)
 target_link_libraries(opentrack-api opentrack-spline-widget)
diff --git a/opentrack/camera-names.cpp b/opentrack/camera-names.cpp
deleted file mode 100644
index 74e998ca..00000000
--- a/opentrack/camera-names.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-#include "camera-names.hpp"
-
-#if defined(OPENTRACK_API) && defined(_WIN32)
-#   define NO_DSHOW_STRSAFE
-#   include <windows.h>
-#   include <dshow.h>
-#endif
-
-#if defined(OPENTRACK_API) && (defined(__unix) || defined(__linux) || defined(__APPLE__))
-#   include <unistd.h>
-#endif
-
-#ifdef __linux
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <linux/videodev2.h>
-#include <cerrno>
-#endif
-
-#include <QDebug>
-
-int camera_name_to_index(const QString &name)
-{
-    auto list = get_camera_names();
-    int ret = list.indexOf(name);
-    if (ret < 0)
-        ret = 0;
-    return ret;
-}
-
-QList<QString> get_camera_names() {
-    QList<QString> ret;
-#if defined(_WIN32)
-    // Create the System Device Enumerator.
-    HRESULT hr;
-    hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
-    if (FAILED(hr))
-        qDebug() << "failed CoInitializeEx" << hr;
-    ICreateDevEnum *pSysDevEnum = NULL;
-    hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysDevEnum);
-    if (FAILED(hr))
-    {
-        qDebug() << "failed CLSID_SystemDeviceEnum" << hr;
-        return ret;
-    }
-    // Obtain a class enumerator for the video compressor category.
-    IEnumMoniker *pEnumCat = NULL;
-    hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0);
-
-    if (hr == S_OK) {
-        // Enumerate the monikers.
-        IMoniker *pMoniker = NULL;
-        ULONG cFetched;
-        while (pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK) {
-            IPropertyBag *pPropBag;
-            hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag);
-            if (SUCCEEDED(hr))	{
-                // To retrieve the filter's friendly name, do the following:
-                VARIANT varName;
-                VariantInit(&varName);
-                hr = pPropBag->Read(L"FriendlyName", &varName, 0);
-                if (SUCCEEDED(hr))
-                {
-                    // Display the name in your UI somehow.
-                    QString str((QChar*)varName.bstrVal, wcslen(varName.bstrVal));
-                    ret.append(str);
-                }
-                VariantClear(&varName);
-
-                ////// To create an instance of the filter, do the following:
-                ////IBaseFilter *pFilter;
-                ////hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter,
-                ////	(void**)&pFilter);
-                // Now add the filter to the graph.
-                //Remember to release pFilter later.
-                pPropBag->Release();
-            }
-            pMoniker->Release();
-        }
-        pEnumCat->Release();
-    }
-    else
-        qDebug() << "failed CLSID_VideoInputDeviceCategory" << hr;
-    
-    pSysDevEnum->Release();
-#endif
-#ifdef __linux
-    for (int i = 0; i < 16; i++) {
-        char buf[128];
-        sprintf(buf, "/dev/video%d", i);
-        if (access(buf, F_OK) == 0)
-            ret.append(buf);
-        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
-    return ret;
-}
\ No newline at end of file
diff --git a/opentrack/camera-names.hpp b/opentrack/camera-names.hpp
deleted file mode 100644
index ef914458..00000000
--- a/opentrack/camera-names.hpp
+++ /dev/null
@@ -1,16 +0,0 @@
-/* Copyright (c) 2014-2015, Stanislaw Halik <sthalik@misaki.pl>
-
- * Permission to use, copy, modify, and/or distribute this
- * software for any purpose with or without fee is hereby granted,
- * provided that the above copyright notice and this permission
- * notice appear in all copies.
- */
-
-#pragma once
-
-#include <QList>
-#include <QString>
-
-QList<QString> get_camera_names();
-int camera_name_to_index(const QString &name);
-
diff --git a/opentrack/opencv-camera-dialog.hpp b/opentrack/opencv-camera-dialog.hpp
index 0d4a51af..96c7a643 100644
--- a/opentrack/opencv-camera-dialog.hpp
+++ b/opentrack/opencv-camera-dialog.hpp
@@ -12,7 +12,7 @@
 #include <QMutex>
 #include <QMutexLocker>
 #include <opencv2/videoio.hpp>
-#include "opentrack/camera-names.hpp"
+#include "opentrack-compat/camera-names.hpp"
 
 #ifdef __linux
 #include <QProcess>
diff --git a/tracker-aruco/ftnoir_tracker_aruco.cpp b/tracker-aruco/ftnoir_tracker_aruco.cpp
index 1da5b8df..316c7e13 100644
--- a/tracker-aruco/ftnoir_tracker_aruco.cpp
+++ b/tracker-aruco/ftnoir_tracker_aruco.cpp
@@ -16,7 +16,7 @@
 #include <opencv2/core/core.hpp>
 #include <opencv2/highgui/highgui.hpp>
 #include <opencv2/videoio.hpp>
-#include "opentrack/camera-names.hpp"
+#include "opentrack-compat/camera-names.hpp"
 #include "opentrack-compat/sleep.hpp"
 
 typedef struct {
diff --git a/tracker-pt/ftnoir_tracker_pt.cpp b/tracker-pt/ftnoir_tracker_pt.cpp
index 2dbf9068..3dd91a45 100644
--- a/tracker-pt/ftnoir_tracker_pt.cpp
+++ b/tracker-pt/ftnoir_tracker_pt.cpp
@@ -12,7 +12,7 @@
 #include <QDebug>
 #include <QFile>
 #include <QCoreApplication>
-#include "opentrack/camera-names.hpp"
+#include "opentrack-compat/camera-names.hpp"
 #include "opentrack-compat/sleep.hpp"
 
 //#define PT_PERF_LOG	//log performance
diff --git a/tracker-pt/ftnoir_tracker_pt_dialog.cpp b/tracker-pt/ftnoir_tracker_pt_dialog.cpp
index b1ae2238..551910f7 100644
--- a/tracker-pt/ftnoir_tracker_pt_dialog.cpp
+++ b/tracker-pt/ftnoir_tracker_pt_dialog.cpp
@@ -12,7 +12,7 @@
 #include <QDebug>
 #include <opencv2/core/core.hpp>
 #include <memory>
-#include "opentrack/camera-names.hpp"
+#include "opentrack-compat/camera-names.hpp"
 #include <vector>
 
 //-----------------------------------------------------------------------------
-- 
cgit v1.2.3