From 31bab22b5ee7bc18ad4bdb2fb74ed4948a900cc0 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 6 May 2019 03:52:45 +0200 Subject: compat/camera-names: move to original location Issue: #946 --- compat/CMakeLists.txt | 6 +- compat/camera-names.cpp | 106 +++++++++++++++++++++++++++++++ compat/camera-names.hpp | 18 ++++++ tracker-kinect-face/CMakeLists.txt | 5 -- tracker-kinect-face/camera_kinect_ir.cpp | 2 +- video-opencv/camera-names.cpp | 106 ------------------------------- video-opencv/camera-names.hpp | 18 ------ video-opencv/impl-metadata.cpp | 2 +- video-opencv/video-property-page.cpp | 4 +- 9 files changed, 133 insertions(+), 134 deletions(-) create mode 100644 compat/camera-names.cpp create mode 100644 compat/camera-names.hpp delete mode 100644 video-opencv/camera-names.cpp delete mode 100644 video-opencv/camera-names.hpp diff --git a/compat/CMakeLists.txt b/compat/CMakeLists.txt index 3fddefb4..5ef9ab67 100644 --- a/compat/CMakeLists.txt +++ b/compat/CMakeLists.txt @@ -1,7 +1,11 @@ otr_module(compat NO-COMPAT BIN) if(NOT WIN32 AND NOT APPLE) - target_link_libraries(opentrack-compat rt) + target_link_libraries(${self} rt) +endif() + +if(WIN32) + target_link_libraries(${self} strmiids) endif() if(CMAKE_COMPILER_IS_GNUCXX) diff --git a/compat/camera-names.cpp b/compat/camera-names.cpp new file mode 100644 index 00000000..69926e5a --- /dev/null +++ b/compat/camera-names.cpp @@ -0,0 +1,106 @@ +#include "camera-names.hpp" + +#include +#include + +#ifdef _WIN32 +# include +# define NO_DSHOW_STRSAFE +# include +#elif defined(__unix) || defined(__linux) || defined(__APPLE__) +# include +#endif + +#ifdef __linux +# include +# include +# include +# include +# include +#endif + +#include + +int camera_name_to_index(const QString &name) +{ + auto list = get_camera_names(); + auto it = std::find(list.cbegin(), list.cend(), name); + if (it != list.cend()) + return std::distance(list.cbegin(), it); + + return -1; +} + +std::vector get_camera_names() +{ + std::vector ret; +#ifdef _WIN32 + // Create the System Device Enumerator. + HRESULT hr; + CoInitialize(nullptr); + ICreateDevEnum *pSysDevEnum = nullptr; + hr = CoCreateInstance(CLSID_SystemDeviceEnum, nullptr, 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 = nullptr; + hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0); + + if (hr == S_OK) { + // Enumerate the monikers. + IMoniker *pMoniker = nullptr; + ULONG cFetched; + while (pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK) + { + IPropertyBag *pPropBag; + hr = pMoniker->BindToStorage(nullptr, nullptr, IID_IPropertyBag, (void **)&pPropBag); + if (SUCCEEDED(hr)) { + // To retrieve the filter's friendly name, do the following: + VARIANT var; + VariantInit(&var); + hr = pPropBag->Read(L"FriendlyName", &var, nullptr); + if (SUCCEEDED(hr)) + { + // Display the name in your UI somehow. + QString str((QChar*)var.bstrVal, int(std::wcslen(var.bstrVal))); + ret.push_back(str); + } + VariantClear(&var); + 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[32]; + snprintf(buf, sizeof(buf), "/dev/video%d", i); + + 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.push_back(QString((const char*)video_cap.card)); + close(fd); + } + } +#endif + return ret; +} diff --git a/compat/camera-names.hpp b/compat/camera-names.hpp new file mode 100644 index 00000000..bda15e81 --- /dev/null +++ b/compat/camera-names.hpp @@ -0,0 +1,18 @@ +/* Copyright (c) 2014-2015, Stanislaw Halik + + * 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 +#include + +#include "export.hpp" + +OTR_COMPAT_EXPORT std::vector get_camera_names(); +OTR_COMPAT_EXPORT int camera_name_to_index(const QString &name); + diff --git a/tracker-kinect-face/CMakeLists.txt b/tracker-kinect-face/CMakeLists.txt index 31b52ff7..7ab62df2 100644 --- a/tracker-kinect-face/CMakeLists.txt +++ b/tracker-kinect-face/CMakeLists.txt @@ -7,9 +7,6 @@ if (WIN32 AND opentrack-intel) # Register our module otr_module(tracker-kinect-face) - target_sources(${self} PUBLIC "../video-opencv/camera-names.cpp") - target_link_libraries(${self} strmiids) - if(MSVC) # workaround warning in SDK target_compile_options(${self} PRIVATE "-wd4471") @@ -54,7 +51,5 @@ if (WIN32 AND opentrack-intel) target_include_directories(${self} SYSTEM PUBLIC ${OpenCV_INCLUDE_DIRS}) target_link_libraries(${self} opencv_imgproc opentrack-cv opencv_core opentrack-video) endif() - - endif() endif() diff --git a/tracker-kinect-face/camera_kinect_ir.cpp b/tracker-kinect-face/camera_kinect_ir.cpp index 75945d49..81357a6d 100644 --- a/tracker-kinect-face/camera_kinect_ir.cpp +++ b/tracker-kinect-face/camera_kinect_ir.cpp @@ -14,7 +14,7 @@ #include "compat/sleep.hpp" #include "compat/math-imports.hpp" -#include "video-opencv/camera-names.hpp" +#include "compat/camera-names.hpp" #include #include diff --git a/video-opencv/camera-names.cpp b/video-opencv/camera-names.cpp deleted file mode 100644 index 69926e5a..00000000 --- a/video-opencv/camera-names.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#include "camera-names.hpp" - -#include -#include - -#ifdef _WIN32 -# include -# define NO_DSHOW_STRSAFE -# include -#elif defined(__unix) || defined(__linux) || defined(__APPLE__) -# include -#endif - -#ifdef __linux -# include -# include -# include -# include -# include -#endif - -#include - -int camera_name_to_index(const QString &name) -{ - auto list = get_camera_names(); - auto it = std::find(list.cbegin(), list.cend(), name); - if (it != list.cend()) - return std::distance(list.cbegin(), it); - - return -1; -} - -std::vector get_camera_names() -{ - std::vector ret; -#ifdef _WIN32 - // Create the System Device Enumerator. - HRESULT hr; - CoInitialize(nullptr); - ICreateDevEnum *pSysDevEnum = nullptr; - hr = CoCreateInstance(CLSID_SystemDeviceEnum, nullptr, 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 = nullptr; - hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0); - - if (hr == S_OK) { - // Enumerate the monikers. - IMoniker *pMoniker = nullptr; - ULONG cFetched; - while (pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK) - { - IPropertyBag *pPropBag; - hr = pMoniker->BindToStorage(nullptr, nullptr, IID_IPropertyBag, (void **)&pPropBag); - if (SUCCEEDED(hr)) { - // To retrieve the filter's friendly name, do the following: - VARIANT var; - VariantInit(&var); - hr = pPropBag->Read(L"FriendlyName", &var, nullptr); - if (SUCCEEDED(hr)) - { - // Display the name in your UI somehow. - QString str((QChar*)var.bstrVal, int(std::wcslen(var.bstrVal))); - ret.push_back(str); - } - VariantClear(&var); - 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[32]; - snprintf(buf, sizeof(buf), "/dev/video%d", i); - - 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.push_back(QString((const char*)video_cap.card)); - close(fd); - } - } -#endif - return ret; -} diff --git a/video-opencv/camera-names.hpp b/video-opencv/camera-names.hpp deleted file mode 100644 index 9f0883f5..00000000 --- a/video-opencv/camera-names.hpp +++ /dev/null @@ -1,18 +0,0 @@ -/* Copyright (c) 2014-2015, Stanislaw Halik - - * 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 -#include - -#include "export.hpp" - -std::vector get_camera_names(); -int camera_name_to_index(const QString &name); - diff --git a/video-opencv/impl-metadata.cpp b/video-opencv/impl-metadata.cpp index 84b11822..48a2e693 100644 --- a/video-opencv/impl-metadata.cpp +++ b/video-opencv/impl-metadata.cpp @@ -1,5 +1,5 @@ #include "impl.hpp" -#include "camera-names.hpp" +#include "compat/camera-names.hpp" #include "video-property-page.hpp" namespace opencv_camera_impl { diff --git a/video-opencv/video-property-page.cpp b/video-opencv/video-property-page.cpp index 078898a5..8057bf9e 100644 --- a/video-opencv/video-property-page.cpp +++ b/video-opencv/video-property-page.cpp @@ -9,7 +9,7 @@ #ifdef _WIN32 -#include "camera-names.hpp" +#include "compat/camera-names.hpp" #include "compat/sleep.hpp" #include "compat/run-in-thread.hpp" #include "compat/library-path.hpp" @@ -149,7 +149,7 @@ bool video_property_page::show(int idx) #elif defined(__linux) # include -# include "camera-names.hpp" +# include "compat/camera-names.hpp" bool video_property_page::show(int idx) { -- cgit v1.2.3