summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-05-31 18:58:14 +0200
committerStanislaw Halik <sthalik@misaki.pl>2015-05-31 18:58:14 +0200
commitfc0e8afb25c6fa32f299e8c7318c3bd2411673c9 (patch)
tree7e6f11dd71ca3eaa0fd71e3c4249420b31da1d2f
parentce1608610e2173b453364ce297ed16427478532e (diff)
put camera name list in header, don't copy-paste
-rw-r--r--ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp73
-rw-r--r--ftnoir_tracker_ht/ftnoir_tracker_ht.cpp70
-rw-r--r--ftnoir_tracker_pt/camera.cpp66
-rw-r--r--ftnoir_tracker_pt/camera.h3
-rw-r--r--ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp5
-rw-r--r--opentrack/camera-names.hpp76
6 files changed, 85 insertions, 208 deletions
diff --git a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp
index d7ceb8a6..a6394b71 100644
--- a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp
+++ b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp
@@ -15,78 +15,7 @@
#include "opentrack/plugin-api.hpp"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
-
-#if defined(_WIN32)
-# undef NOMINMAX
-# define NOMINMAX
-# define NO_DSHOW_STRSAFE
-# include <dshow.h>
-#else
-# include <unistd.h>
-#endif
-
-// delicious copypasta
-static QList<QString> get_camera_names(void) {
- QList<QString> ret;
-#if defined(_WIN32)
- // Create the System Device Enumerator.
- HRESULT hr;
- ICreateDevEnum *pSysDevEnum = NULL;
- hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysDevEnum);
- if (FAILED(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();
- }
- pSysDevEnum->Release();
-#else
- 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);
- } else {
- continue;
- }
- }
-#endif
- return ret;
-}
+#include "opentrack/camera-names.hpp"
typedef struct {
int width;
diff --git a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp
index 41ecbc9b..bd5595e1 100644
--- a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp
+++ b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp
@@ -5,75 +5,7 @@
#include "ui_ht-trackercontrols.h"
#include "opentrack/plugin-api.hpp"
#include <cmath>
-
-#if defined(_WIN32)
-#include <dshow.h>
-#else
-#include <unistd.h>
-#endif
-
-// delicious copypasta
-static QList<QString> get_camera_names(void) {
- QList<QString> ret;
-#if defined(_WIN32)
- // Create the System Device Enumerator.
- HRESULT hr;
- ICreateDevEnum *pSysDevEnum = NULL;
- hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysDevEnum);
- if (FAILED(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();
- }
- pSysDevEnum->Release();
-#elif !defined(__APPLE__)
- 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);
- } else {
- continue;
- }
- }
-#endif
- return ret;
-}
+#include "opentrack/camera-names.hpp"
typedef struct {
int width;
diff --git a/ftnoir_tracker_pt/camera.cpp b/ftnoir_tracker_pt/camera.cpp
index 432e0158..eaf51e17 100644
--- a/ftnoir_tracker_pt/camera.cpp
+++ b/ftnoir_tracker_pt/camera.cpp
@@ -5,79 +5,13 @@
* copyright notice and this permission notice appear in all copies.
*/
- #if defined(OPENTRACK_API) && defined(_WIN32)
-#include <windows.h>
-#include <dshow.h>
-#endif
-
#include "camera.h"
#include <string>
#include <QDebug>
using namespace cv;
-#if defined(OPENTRACK_API) && (defined(__unix) || defined(__linux) || defined(__APPLE__))
-#include <unistd.h>
-#endif
-
#ifdef OPENTRACK_API
-void get_camera_device_names(std::vector<std::string>& device_names) {
-# if defined(_WIN32)
- // Create the System Device Enumerator.
- HRESULT hr;
- ICreateDevEnum *pSysDevEnum = NULL;
- hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysDevEnum);
- if (FAILED(hr))
- {
- return;
- }
- // 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))
- {
- auto wstr = std::wstring(varName.bstrVal);
- auto str = std::string(wstr.begin(), wstr.end());
- device_names.push_back(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();
- }
- pSysDevEnum->Release();
-# else
- for (int i = 0; i < 16; i++) {
- char buf[128];
- sprintf(buf, "/dev/video%d", i);
- if (access(buf, R_OK | W_OK) == 0) {
- device_names.push_back(std::string(buf));
- }
- }
-# endif
-}
#else
// ----------------------------------------------------------------------------
void get_camera_device_names(std::vector<std::string>& device_names)
diff --git a/ftnoir_tracker_pt/camera.h b/ftnoir_tracker_pt/camera.h
index 2bce6f35..bffd19ee 100644
--- a/ftnoir_tracker_pt/camera.h
+++ b/ftnoir_tracker_pt/camera.h
@@ -17,9 +17,10 @@
#endif
#include <string>
+#ifndef OPENTRACK_API
// ----------------------------------------------------------------------------
void get_camera_device_names(std::vector<std::string>& device_names);
-
+#endif
// ----------------------------------------------------------------------------
struct CamInfo
diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp b/ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp
index 7be05bb7..3486f234 100644
--- a/ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp
+++ b/ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp
@@ -14,6 +14,7 @@
# include <boost/shared_ptr.hpp>
#else
# include <memory>
+# include "opentrack/camera-names.hpp"
#endif
#include <vector>
@@ -27,12 +28,16 @@ TrackerDialog::TrackerDialog()
{
ui.setupUi( this );
+#ifdef OPENTRACK_API
+ ui.camdevice_combo->addItems(get_camera_names());
+#else
vector<string> device_names;
get_camera_device_names(device_names);
for (vector<string>::iterator iter = device_names.begin(); iter != device_names.end(); ++iter)
{
ui.camdevice_combo->addItem(iter->c_str());
}
+#endif
tie_setting(s.cam_index, ui.camdevice_combo);
tie_setting(s.cam_res_x, ui.res_x_spin);
diff --git a/opentrack/camera-names.hpp b/opentrack/camera-names.hpp
new file mode 100644
index 00000000..975fe28b
--- /dev/null
+++ b/opentrack/camera-names.hpp
@@ -0,0 +1,76 @@
+#pragma once
+
+#include <QList>
+#include <QString>
+
+#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
+
+QList<QString> get_camera_names() {
+ QList<QString> ret;
+#if defined(_WIN32)
+ // Create the System Device Enumerator.
+ HRESULT hr;
+ ICreateDevEnum *pSysDevEnum = NULL;
+ hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysDevEnum);
+ if (FAILED(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();
+ }
+ pSysDevEnum->Release();
+#else
+ 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);
+ } else {
+ continue;
+ }
+ }
+#endif
+ return ret;
+}