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的更多相关文章

随机推荐

  1. HTML5 history新特性pushState、replaceState,popstate

    http://blog.csdn.net/tianyitianyi1/article/details/7426606 https://developer.mozilla.org/zh-CN/docs/ ...

  2. putty连接ubuntu虚拟机缓慢问题的解决

    vmware安装系统使用了ubuntu,安装后每次用PUTTY登录发现都到等很久,经过上网搜索,发现是Ubuntu安全机制导致的连接缓慢问题,   解决方法如下;   1. sudo vim /etc ...

  3. OAF_文件系列2_实现OAF导出CSV格式文件ExportButton(案例)

    20150727 Created By BaoXinjian

  4. DBMS_JOBS

    http://blog.itpub.net/23055736/viewspace-1115938/

  5. NeHe OpenGL教程 第四十八课:轨迹球

    转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...

  6. ubuntu 下载额外数据不成功”的恼人提示通知

    最近用Ubunt也遇到这个问题,搜到这个答案 参考原文链接: http://forum.ubuntu.org.cn/viewtopic.php?t=387865 2.移除“下载额外数据不成功”的恼人提 ...

  7. 让background-color 无效

    { background-color: transparent; // 让背景透明,相当于背景颜色无效 }

  8. Etag,Expires与Cache-control

    来介绍一下http中的这几个概念 先来介绍一下Etag: 看看百度来的简介:HTTP协议规格说明定义ETag为“被请求变量的实体值”.另一种说法是,ETag是一个可以与Web资源关联的记号(token ...

  9. rpm包形式安装MySQL

    1.下载Mysql安装所需的rpm包 http://cdn.mysql.com/Downloads/MySQL-5.6/MySQL-server-5.6.21-1.linux_glibc2.5.x86 ...

  10. 【原】搭建Samba的简要过程

    1.安装samba yum install samba –y 2.创建用户 useradd admin #先创建系统用户 smbpasswd -a admin #第一次加入需要-a参数,把admin用 ...