diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2015-06-01 17:09:53 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2015-06-01 17:09:53 +0200 |
commit | 95624a290d9894966e3dab9ffc7064bbb2b51f18 (patch) | |
tree | 03cd9f722640660898db9eb3ac2adcadeaa6a0b4 /opentrack | |
parent | a47185a112e9abc4509c4a80a96f8343fb7443b7 (diff) |
camera-names: allow camera selection by name, not index
Diffstat (limited to 'opentrack')
-rw-r--r-- | opentrack/camera-names.hpp | 19 |
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; +} |