From 95624a290d9894966e3dab9ffc7064bbb2b51f18 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 1 Jun 2015 17:09:53 +0200 Subject: camera-names: allow camera selection by name, not index --- opentrack/camera-names.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'opentrack') 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 #endif +// template to allow compiler coalesce function at linking with multiple definitions +template QList get_camera_names() { QList 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 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 get_camera_names() { #endif return ret; } + +template +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