VedioCaptureHelper
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;
}
VedioCaptureHelper的更多相关文章
随机推荐
- pt-online-schema-change 实例
pt-pmp (http://www.cnblogs.com/ivictor/p/6012183.html) pt-online-schema-change (http://blog.csdn.net ...
- [Linux] CentOS 加入开机启动
1.在/etc/init.d/目录下新建一个文件:autostart.sh #!/bin/sh #chkconfig: 2345 80 80 #description: auto start web ...
- SSIS 项目部署模型
微软 BI 系列随笔 - SSIS 2012 基础 - SSIS 项目部署模型 关于部署 SSIS 2012 支持两种部署模型:项目部署模型和包部署模型. 使用项目部署模型可以将项目部署到 Integ ...
- MYSQL EXPLAIN 很慢的原因
今天同事在查看一个SQL的执行计划的时候,EXPLAIN语句跑了2分钟.SQL命令类似: SELECT * FROM (SELECT USERID,COUNT(*) FROM TBNAME GROUP ...
- (C++) CreateThread
先理解一下函数原型: HANDLE WINAPI CreateThread( _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, // 指向SECUR ...
- I18N、L10N、G11N
I18N --是“Internationalization” 的缩写,由于 “Internationalization” 单词较长,所以为了书写简便,通常缩写为“I18N” .中间的 18 代表在首字 ...
- [CF442B] Andrey and Problem (概率dp)
题目链接:http://codeforces.com/problemset/problem/442/B 题目大意:有n个人,第i个人出一道题的概率是pi,现在选出一个子集,使得这些人恰好出一个题的概率 ...
- The listener supports no services解决一例
The listener supports no services解决一例 Listener动态监听静态监听注册实例 今天做Advacned Replication实验的时候碰到一个问题,启动目标 ...
- Android test---monkey
一.在使用monkey之前,需要用到模拟器,那么怎么启动模拟器呢,先看一下电脑有什么模拟器,通过命令行查看一下 android list avd 二.看到了模拟器列表了,下来就是启动模拟器了.在命令行 ...
- NHibernate系列文章九:NHibernate对象二级缓存上
摘要 NHibernate的二级缓存由SessionFactory管理,由所有Session共享. NHibernate缓存读取顺序: 首先从一级缓存中读取,如果一级缓存对象存在,则读取一级缓存对象并 ...