summaryrefslogtreecommitdiffhomepage
path: root/opentrack/camera-names.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'opentrack/camera-names.hpp')
-rw-r--r--opentrack/camera-names.hpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/opentrack/camera-names.hpp b/opentrack/camera-names.hpp
index 975fe28b..d6b26493 100644
--- a/opentrack/camera-names.hpp
+++ b/opentrack/camera-names.hpp
@@ -13,15 +13,21 @@
# include <unistd.h>
#endif
+// template to allow compiler coalesce function at linking with multiple definitions
+template<typename = int>
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.
@@ -60,6 +66,9 @@ QList<QString> get_camera_names() {
}
pEnumCat->Release();
}
+ else
+ qDebug() << "failed CLSID_VideoInputDeviceCategory" << hr;
+
pSysDevEnum->Release();
#else
for (int i = 0; i < 16; i++) {
@@ -74,3 +83,13 @@ QList<QString> get_camera_names() {
#endif
return ret;
}
+
+template<typename = int>
+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;
+}