void testFun()

{

chStringA strDevName;

chStringA strDevID;

chStringA useDevName = "WIN2 USB2.0 PC Camera";
chStringA useDevId = "\\\\?\\usb#vid_0ac8&pid_3420&mi_00#7&24c43346&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\\global";
chListStringA listName;
listName = wVideoHelper::GetVideoCaptureNameList();
chStringA listFirstName = listName.front();
chListStringA listIDs;
listIDs = wVideoHelper::GetVideoCaptureIDList();
chStringA listFirstID = listIDs.front();
strDevName = wVideoHelper::GetVideoCaptureNameByID(useDevId);
strDevID = wVideoHelper::GetVideoCaptureIDByName(useDevName);
int nCounts = wVideoHelper::GetVideoCaptureDevicesCounts();
chStringA strWinTitle = "yecy hello world";

DisplayCaptureSettingsDialogBox(useDevId, strWinTitle, NULL, 500, 1000);
return -1;

}

#ifndef __wVedioHelper_h__
#define __wVedioHelper_h__

#include "uiHelper.h"
#include <Dshow.h>
#pragma comment(lib, "Strmiids.lib")
//typedef chObjList_stack<chStringA> VideoCaptureDevNameList;

class UIHELPER_EXPORT wVideoHelper
{
public:
/************************vedio input***************/
static int GetVideoCaptureDevicesCounts();
static chStringA GetVideoCaptureIDByName(const chConstString& strDevName);
static chStringA GetVideoCaptureNameByID(const chConstString& strDevID);
static chListStringA GetVideoCaptureNameList();
static chListStringA GetVideoCaptureIDList();
public:
wVideoHelper(){};
~wVideoHelper(){};
};

int UIHELPER_EXPORT DisplayCaptureSettingsDialogBox(const chConstString& deviceUniqueIdUTF8,
const chConstString& dialogTitleUTF8,
void* parentWindow,
int positionX,
int positionY);
#endif

/////////////.h///////////

#include "ETLLib/ETLLib.hpp"
#include "wVedioHelper.h"
#define THIS_MODULE "wVedioHelper"

//#define RELEASE_AND_CLEAR(p) if (p) { (p) -> Release () ; (p) = NULL ; }
//int deviceUniqueIdUTF8Length = 256;

int wVideoHelper::GetVideoCaptureDevicesCounts()
{
int nResultDevCounts = 0;

CoInitializeEx(NULL, COINIT_MULTITHREADED);

ICreateDevEnum* _dsDevEnum = NULL;
CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC, IID_ICreateDevEnum, (void **) &_dsDevEnum);

IEnumMoniker* _dsMonikerDevEnum = NULL;
HRESULT hr = _dsDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &_dsMonikerDevEnum, 0);

if (SUCCEEDED(hr) || _dsMonikerDevEnum != NULL)
{
_dsMonikerDevEnum->Reset();
ULONG cFetched = 0; IMoniker *pM = NULL;
while (S_OK == _dsMonikerDevEnum->Next(1, &pM, &cFetched))
{
++nResultDevCounts;
}
if (pM != NULL)
{
pM->Release();
}
_dsMonikerDevEnum->Release();
}

CoUninitialize();
return nResultDevCounts;
}
chStringA wVideoHelper::GetVideoCaptureIDByName(const chConstString& strDevName)
{// enumerate all video capture devices
chStringA strResultDeviceID;

CoInitializeEx(NULL, COINIT_MULTITHREADED);

ICreateDevEnum* _dsDevEnum = NULL;
CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC, IID_ICreateDevEnum, (void **) &_dsDevEnum);

IEnumMoniker* _dsMonikerDevEnum = NULL;
HRESULT hr = _dsDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &_dsMonikerDevEnum, 0);
if (SUCCEEDED(hr) && _dsMonikerDevEnum != NULL)
{
_dsMonikerDevEnum->Reset();

ULONG cFetched = 0; IMoniker *pM = NULL;bool deviceFound = false;
while (S_OK == _dsMonikerDevEnum->Next(1, &pM, &cFetched) && !deviceFound)
{
IPropertyBag *pBag = NULL;
if (S_OK == pM->BindToStorage(0, 0, IID_IPropertyBag, (void **) &pBag))
{
VARIANT varName; VariantInit(&varName);
hr = pBag->Read(L"FriendlyName", &varName, 0);
if (SUCCEEDED(hr))
{
chStringA strDeviceName = chW2UTF8(varName.bstrVal);
if (strDevName == strDeviceName)
{
// We have found the requested device
VARIANT varID;
VariantInit(&varID);
pBag->Read(L"DevicePath", &varID, 0);
strResultDeviceID = chW2UTF8(varID.bstrVal);
VariantClear(&varID);
deviceFound = true;
}
}
pBag->Release();
VariantClear(&varName);
pM->Release();
}
}
_dsMonikerDevEnum->Release();
}
CoUninitialize();
return strResultDeviceID;
}

chStringA wVideoHelper::GetVideoCaptureNameByID(const chConstString& strDevID)
{// enumerate all video capture devices

chStringA strResultDevName;

CoInitializeEx(NULL, COINIT_MULTITHREADED);

ICreateDevEnum* _dsDevEnum = NULL;
CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC, IID_ICreateDevEnum, (void **) &_dsDevEnum);

IEnumMoniker* _dsMonikerDevEnum = NULL;
HRESULT hr = _dsDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &_dsMonikerDevEnum, 0);

if (SUCCEEDED(hr) || _dsMonikerDevEnum != NULL)
{
_dsMonikerDevEnum->Reset();
ULONG cFetched = 0; IMoniker *pM = NULL; bool deviceFound = false;
while (S_OK == _dsMonikerDevEnum->Next(1, &pM, &cFetched) && !deviceFound)
{
IPropertyBag *pBag = NULL;
if (pM->BindToStorage(0, 0, IID_IPropertyBag, (void **) &pBag) == S_OK)
{
VARIANT varID; VariantInit(&varID);
hr = pBag->Read(L"DevicePath", &varID, 0);
if (SUCCEEDED(hr))
{
chStringA strDeviceID = chW2UTF8(varID.bstrVal);
if (strDevID == strDeviceID)
{
VARIANT varName;
VariantInit(&varName);
pBag->Read(L"FriendlyName", &varName, 0);
strResultDevName = chW2UTF8(varName.bstrVal);
VariantClear(&varName);
deviceFound = true;
}
}
VariantClear(&varID);
pBag->Release();
pM->Release();
}
}
_dsMonikerDevEnum->Release();
}

CoUninitialize();
return strResultDevName;
}

chListStringA wVideoHelper::GetVideoCaptureNameList()
{
chListStringA listResultDevName;

CoInitializeEx(NULL, COINIT_MULTITHREADED);

ICreateDevEnum* _dsDevEnum = NULL;
CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC, IID_ICreateDevEnum, (void **) &_dsDevEnum);

IEnumMoniker* _dsMonikerDevEnum = NULL;
HRESULT hr = _dsDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &_dsMonikerDevEnum, 0);

if (SUCCEEDED(hr) || _dsMonikerDevEnum != NULL)
{
_dsMonikerDevEnum->Reset();
ULONG cFetched = 0; IMoniker *pM = NULL; bool deviceFound = false;
while (S_OK == _dsMonikerDevEnum->Next(1, &pM, &cFetched) && !deviceFound)
{
IPropertyBag *pBag = NULL;
if (pM->BindToStorage(0, 0, IID_IPropertyBag, (void **) &pBag) == S_OK)
{
VARIANT varName; VariantInit(&varName);
hr = pBag->Read(L"FriendlyName", &varName, 0);
if (SUCCEEDED(hr))
{
chStringA strDevName = chW2UTF8(varName.bstrVal);
listResultDevName.push_back(strDevName);
}
VariantClear(&varName);
pBag->Release();
pM->Release();
}
}
_dsMonikerDevEnum->Release();
}
CoUninitialize();
return listResultDevName;
}

chListStringA wVideoHelper::GetVideoCaptureIDList()
{
chListStringA listResultDevID;

CoInitializeEx(NULL, COINIT_MULTITHREADED);

ICreateDevEnum* _dsDevEnum = NULL;
CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC, IID_ICreateDevEnum, (void **) &_dsDevEnum);

IEnumMoniker* _dsMonikerDevEnum = NULL;
HRESULT hr = _dsDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &_dsMonikerDevEnum, 0);

if (SUCCEEDED(hr) || _dsMonikerDevEnum != NULL)
{
_dsMonikerDevEnum->Reset();
ULONG cFetched = 0; IMoniker *pM = NULL; bool deviceFound = false;
while (S_OK == _dsMonikerDevEnum->Next(1, &pM, &cFetched) && !deviceFound)
{
IPropertyBag *pBag = NULL;
if (pM->BindToStorage(0, 0, IID_IPropertyBag, (void **) &pBag) == S_OK)
{
VARIANT varID; VariantInit(&varID);
hr = pBag->Read(L"DevicePath", &varID, 0);
if (SUCCEEDED(hr))
{
chStringA strDevName = chW2UTF8(varID.bstrVal);
listResultDevID.push_back(strDevName);
}
VariantClear(&varID);
pBag->Release();
pM->Release();
}
}
_dsMonikerDevEnum->Release();
}
CoUninitialize();
return listResultDevID;
}

static IBaseFilter * GetDeviceFilter(chConstString deviceUniqueIdUTF8)
{
IBaseFilter *captureFilter = NULL;

CoInitializeEx(NULL, COINIT_MULTITHREADED);

ICreateDevEnum* _dsDevEnum;
CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC, IID_ICreateDevEnum, (void **) &_dsDevEnum);

IEnumMoniker* _dsMonikerDevEnum = NULL;
HRESULT hr = _dsDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &_dsMonikerDevEnum, 0);
if (SUCCEEDED(hr) || _dsMonikerDevEnum != NULL)
{
_dsMonikerDevEnum->Reset();

ULONG cFetched = 0; IMoniker *pM = NULL; bool deviceFound = false;
while (S_OK == _dsMonikerDevEnum->Next(1, &pM, &cFetched) && !deviceFound)
{
IPropertyBag *pBag;
if (pM->BindToStorage(0, 0, IID_IPropertyBag, (void **) &pBag) == S_OK)
{
VARIANT varName; VariantInit(&varName);
hr = pBag->Read(L"DevicePath", &varName, 0);
if (SUCCEEDED(hr))
{
chStringA strDeviceID = chW2UTF8(varName.bstrVal);
if (deviceUniqueIdUTF8 == strDeviceID)
{
deviceFound = true;
hr = pM->BindToObject(0, 0, IID_IBaseFilter, (void**) &captureFilter);

}
}
VariantClear(&varName);
pBag->Release();
pM->Release();
}
}
_dsMonikerDevEnum->Release();
}
CoUninitialize();
return captureFilter;
}

int DisplayCaptureSettingsDialogBox(const chConstString& deviceUniqueIdUTF8,
const chConstString& dialogTitleUTF8,
void* parentWindow,
int positionX,
int positionY)
{
HWND window = (HWND) parentWindow;
CoInitializeEx(NULL, COINIT_MULTITHREADED);
IBaseFilter* filter = GetDeviceFilter(deviceUniqueIdUTF8);
if (filter != NULL)
{
ISpecifyPropertyPages* pPages = NULL; HRESULT hr = S_OK;
hr = filter->QueryInterface(IID_ISpecifyPropertyPages, (LPVOID*) &pPages);
if (SUCCEEDED(hr))
{
CAUUID uuid;
hr = pPages->GetPages(&uuid);
if (SUCCEEDED(hr))
{
chStringW strDialogTitleW = chUTF82W(dialogTitleUTF8);
// Invoke a dialog box to display.
hr = OleCreatePropertyFrame(window, // You must create the parent window.
positionX, // Horizontal position for the dialog box.
positionY, // Vertical position for the dialog box.
strDialogTitleW.c_str(),// String used for the dialog box caption.
1, // Number of pointers passed in pPlugin.
(LPUNKNOWN*) &filter, // Pointer to the filter.
uuid.cElems, // Number of property pages.
uuid.pElems, // Array of property page CLSIDs.
LOCALE_USER_DEFAULT, // Locale ID for the dialog box.
0, NULL); // Reserved
// Release memory.
if (uuid.pElems)
{
CoTaskMemFree(uuid.pElems);
}
}
}
}
filter->Release();
CoUninitialize();
return 0;
}

最新文章

  1. MySQL的简单使用
  2. SUSE zypper failed to work
  3. 【Android】Android Studio 进行代码混淆,打包release APK
  4. Android开发快速入门(环境配置、Android Studio安装)
  5. 原创docker dcos 的安装
  6. java 框架Nutz
  7. PAT1053. Path of Equal Weight
  8. 不容错过的iOS 8的导航交互
  9. 一个好用的hibernate泛型dao
  10. PHP框架原理
  11. iOS 独立开发记录(下)
  12. WampServer Mysql配置
  13. 跨域CORS
  14. WARN [wxpay java sdk] - report fail. reason: report.mch.weixin.qq.com:80 failed to respond
  15. 二十八、layui的日历组件使用
  16. (并发编程)进程池线程池--提交任务2种方式+(异步回调)、协程--yield关键字 greenlet ,gevent模块
  17. CSS-三角形及其原理
  18. RHEL7 CentOS7 的 firewall命令简单介绍
  19. SO\PR\MO\排产回写的数据如下
  20. JAVA-Servlet内容

热门文章

  1. LNMP编译安装教程
  2. 为重负网络优化 Nginx 和 Node.js --引用自https://linux.cn/article-1314-1.html
  3. ASP.NET MVC Web API 学习笔记---第一个Web API程序
  4. SQL 2000/2005/2008 收缩日志方法
  5. S7-1200 与 S7-200 的对比PPT
  6. linux下安装jdk的几种方式
  7. Android 通过按钮弹出系统菜单(通过Button显示菜单)转
  8. OFBIZ:启动之ContainerLoader
  9. Android Studio JNI/NDK 编程简介(一)
  10. 洛谷P3378 【模板】堆