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. idea maven mvn archetype:generate 速度缓慢问题(转)

    From:https://my.oschina.net/u/225373/blog/468035   maven 骨架生成项目速度慢的令人发指,都在Generating project in Batc ...

  2. 请求rest web服务client

    RestClient using System; using System.Globalization; using System.IO; using System.Net; using System ...

  3. HTTP POST GET详解

    get /shang/a1.php http/1.1 host: localhost                           POST /shang/a1.php HTTP/1.1 Hos ...

  4. javascript中的对象之间继承关系

    相信每个学习过其他语言的同学再去学习JavaScript时就会感觉到诸多的不适应,这真是一个颠覆我们以前的编程思想的一门语言,先不要说它的各种数据类型以及表达式的不同了,最让我们头疼,恐怕就是面向对象 ...

  5. SpringMVC学习系列(6) 之 数据验证

    在系列(4).(5)中我们展示了如何绑定数据,绑定完数据之后如何确保我们得到的数据的正确性?这就是我们本篇要说的内容 —> 数据验证. 这里我们采用Hibernate-validator来进行验 ...

  6. bzoj3745: [Coci2015]Norma

    Description Input 第1行,一个整数N: 第2~n+1行,每行一个整数表示序列a. Output 输出答案对10^9取模后的结果. 预处理每个位置的数作为最小/大值向左延伸的最大距离, ...

  7. ERROR 1130 (HY000):Host'localhost'解决方法

    http://www.2cto.com/database/201211/169504.html ERROR 1130 (HY000):Host'localhost'解决方法   ERROR 1130 ...

  8. iOS8通讯录之联系人增删查,多号码增删操作

    #import <AddressBook/AddressBook.h> #pragma mark 删除一个号码 - (void)deleteLocalMarkSuccess:(void(^ ...

  9. 36. Construct Binary Tree from Inorder and Postorder Traversal && Construct Binary Tree from Preorder and Inorder Traversal

    Construct Binary Tree from Inorder and Postorder Traversal OJ: https://oj.leetcode.com/problems/cons ...

  10. [zhang] ViewController的生命周期分析和使用

    iOS的SDK中提供很多原生ViewController,大大提高了我们的开发效率,下面是我的一些经验. 一.结构 按结构可以对iOS的所有ViewController分成两类:1.主要用于展示内容的 ...