Esempio n. 1
0
HRESULT VideoCapture::FindCaptureDevice(const wchar_t* deviceName, IBaseFilter** ppSrcFilter)
{
        ICreateDevEnum *pSysDevEnum = NULL;
        hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
                              IID_ICreateDevEnum, (void **)&pSysDevEnum);
        if (FAILED(hr)) 
                return hr;        

        // Obtain a class enumerator for the video input devices category.
        IEnumMoniker *pEnumCat = NULL;
        hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0);
        if (hr == S_OK) {
                // Enumerate the monikers.
                IMoniker *pMoniker = NULL;
                ULONG cFetched;
                while (pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK) {
                        IPropertyBag *pPropBag;
                        hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
                                                     (void **)&pPropBag);
                        if (SUCCEEDED(hr)) {
                                // To retrieve the filter's friendly name
                                VARIANT varName;
                                VariantInit(&varName);
                                hr = pPropBag->Read(L"FriendlyName", &varName, 0);
                                if (SUCCEEDED(hr)) {
                                        if (wcscmp(deviceName, varName.bstrVal) == 0) {
                                                m_DeviceName = varName.bstrVal;
                                                VariantClear(&varName);    

                                                IBaseFilter* pFilter;
                                                hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter,
                                                                            (void**)&pFilter);
                                                if (SUCCEEDED(hr)) {
                                                        *ppSrcFilter = pFilter;
                                                        (*ppSrcFilter)->AddRef();
                                                        pFilter->Release();
                                                }
                                                
                                                pPropBag->Release();        
                                                pMoniker->Release();
                                                pEnumCat->Release();
                                                pSysDevEnum->Release();
                                                return hr;
                                        }                                        
                                }
                                VariantClear(&varName);                                
                                pPropBag->Release();
                        }
                        pMoniker->Release();
                }
                pEnumCat->Release();
        }
        else {
                pSysDevEnum->Release(); 
                return hr;
        }

        pSysDevEnum->Release();
        return -1;        
}
Esempio n. 2
0
HRESULT CaptureDevices::GetAudioDevices(vector<wstring> *audioDevices)
{
	if (!enumMonikerAudio)
		return E_FAIL;

	IMoniker *pMoniker = NULL;
	wstring name;

	while (enumMonikerAudio->Next(1, &pMoniker, NULL) == S_OK)
	{
		IPropertyBag *pPropBag;
		HRESULT hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
		if (FAILED(hr))
		{
			pMoniker->Release();
			continue;  
		} 

		VARIANT var;
		VariantInit(&var);

		hr = pPropBag->Read(L"FriendlyName", &var, 0);
		if (SUCCEEDED(hr))
		{
			name = var.bstrVal;
			VariantClear(&var); 
		}

		pPropBag->Release();
		pMoniker->Release();

		if (!name.empty())
			audioDevices->push_back(name);
	}
}
Esempio n. 3
0
bool CDirectShowFilterFinder::FindFilter(const GUID *pInTypes,int InTypeCount,
	const GUID *pOutTypes,int OutTypeCount,DWORD Merit)
{
	// フィルタを検索する
	bool bRet = false;
	IFilterMapper2 *pMapper=NULL;
	HRESULT hr=::CoCreateInstance(CLSID_FilterMapper2, NULL, CLSCTX_INPROC, IID_IFilterMapper2, (void **)&pMapper);

	if (SUCCEEDED(hr)) {
		IEnumMoniker *pEnum=NULL;

		hr = pMapper->EnumMatchingFilters(
			&pEnum,
			0,					// 予約済み
			TRUE,				// 完全一致を使用するか
			Merit,				// 最小のメリット
			TRUE,				// 1 つ以上の入力ピンか?
			InTypeCount,		// 入力のメジャータイプ/サブタイプの対の数
			pInTypes,			// 入力のメジャータイプ/サブタイプの対の配列
			NULL,				// 入力メディア
			NULL,				// 入力ピンのカテゴリ
			FALSE,				// レンダラでなければならないか
			TRUE,				// 1 つ以上の出力ピンか
			OutTypeCount,		// 出力のメジャータイプ/サブタイプの対の数
			pOutTypes,			// 出力のメジャータイプ/サブタイプの対の配列
			NULL,				// 出力メディア
			NULL);				// 出力ピンのカテゴリ
		if (SUCCEEDED(hr)) {
			IMoniker *pMoniker;
			ULONG cFetched;
			while (pEnum->Next(1, &pMoniker, &cFetched) == S_OK) {
				IPropertyBag *pPropBag;
				hr=pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag);
				if (SUCCEEDED(hr)) {
					VARIANT varName,varID;
					::VariantInit(&varName);
					::VariantInit(&varID);
					hr=pPropBag->Read(L"FriendlyName", &varName, 0);
					if (SUCCEEDED(hr)) {
						hr=pPropBag->Read(L"CLSID", &varID, 0);
						if (SUCCEEDED(hr)) {
							bRet = true;
							CFilterInfo FilterInfo;
							FilterInfo.SetFriendlyName(varName.bstrVal);
							::CLSIDFromString(varID.bstrVal,&FilterInfo.m_clsid);
							m_FilterList.push_back(FilterInfo);
							::SysFreeString(varID.bstrVal);
						}
						SysFreeString(varName.bstrVal);
					}
					pPropBag->Release();
				}
				pMoniker->Release();
			}
			pEnum->Release();
		}
		pMapper->Release();
	}
	return bRet;
}
Esempio n. 4
0
int CCaptureVideo::EnumDevices(CArray<CString, CString>& arList)
{
	int nCount = 0;
	//枚举视频扑捉设备
	ICreateDevEnum *pCreateDevEnum;

	HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,IID_ICreateDevEnum, (void**)&pCreateDevEnum);
	
	if (hr != NOERROR)return -1;
	
	CComPtr<IEnumMoniker> pEm;
	
	hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,&pEm, 0);
	
	if (hr != NOERROR)return -1;
	
	pEm->Reset();
	
	ULONG cFetched;
	
	IMoniker *pM;
	
	while(hr = pEm->Next(1, &pM, &cFetched), hr==S_OK)
	{
		IPropertyBag *pBag;

		hr = pM->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);

		if(SUCCEEDED(hr)) 
		{
			VARIANT var;

			var.vt = VT_BSTR;

			hr = pBag->Read(L"FriendlyName", &var, NULL);

			if (hr == NOERROR) 
			{
				char szStr[2048];

				nCount++;

				WideCharToMultiByte(CP_ACP,0,var.bstrVal, -1, szStr, 2048, NULL, NULL);
				
				arList.Add( CString(szStr) );
				
				SysFreeString(var.bstrVal);
				
				pM->AddRef();

			}

			pBag->Release();
		}

		pM->Release();
	}

	return nCount;
}
Esempio n. 5
0
bool VideoCapture::BindFilter(int deviceId, IBaseFilter **pFilter)
{
	if (deviceId < 0)
		return false;
	
    // enumerate all video capture devices
	CComPtr<ICreateDevEnum> pCreateDevEnum;
    HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
			  IID_ICreateDevEnum, (void**)&pCreateDevEnum);
    if (hr != NOERROR)
		return false;

    CComPtr<IEnumMoniker> pEm;
    hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
								&pEm, 0);
    if (hr != NOERROR) 
		return false;

    pEm->Reset();
    IMoniker *pM;

	for (int i=0; i<=deviceId; i++)
		pEm->Next(1, &pM, NULL);

	IPropertyBag *pBag;
	hr = pM->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);
	pM->BindToObject(0, 0, IID_IBaseFilter, (void**)pFilter);
	pM->Release();

	return true;
}
Esempio n. 6
0
/* Wireshark example (with proxy enabled)
    GET /Resources.zip HTTP/1.0
    Accept: *//*
    Request-Range: bytes=2-5
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)
    Host: www.myurl.com
    Pragma: no-cache
    Via: 1.1 myproxy.com:3128 (squid/2.7.STABLE7)
    X-Forwarded-For: 192.168.0.2
    Cache-Control: max-age=259200
    Connection: keep-alive

   Wireshark example (no proxy, direct connection):
    GET /Resources.zip HTTP/1.1
    Accept: *//*
    Request-Range: bytes=2-5
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)
    Host: www.myurl.com
    Connection: Keep-Alive
    Cache-Control: no-cache
*/
void UseWinInet(const WCHAR* URL)
{
    HRESULT hr;

    IBindStatusCallback* ibscb(0);
    ::CBindStatusCallback::Create( &ibscb );
    /*HRESULT uoshr = URLOpenStream( 0, L"http://www.myurl.com/Resources.zip", 0, ibscb );
    ShowMessage( hwnd, "URLOpenStream: " + toString(uoshr) );*/
    IMoniker* FMoniker;
    CreateURLMoniker(0, URL, &FMoniker);

    IBindCtx* FBindCtx;
    CreateAsyncBindCtx(0, ibscb, 0, &FBindCtx);

    hr = IsValidURL(FBindCtx, URL, 0);
    if ( hr != S_OK )
    {
        ShowMessage( 0, "Invalid url" );
    }
   
    IStream* fstream;
    hr = FMoniker->BindToStorage(FBindCtx, 0, IID_IStream, (void**)&fstream);

    if ( (hr != S_OK) && (hr != MK_S_ASYNCHRONOUS) )
    {
        ShowMessage( 0, "error" );
    }
}
Esempio n. 7
0
QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode)
{
    Q_UNUSED(mode)

    QList<QByteArray> devices;
    //enumerate device fullnames through directshow api
    CoInitialize(NULL);
    ICreateDevEnum *pDevEnum = NULL;
    IEnumMoniker *pEnum = NULL;
    // Create the System device enumerator
    HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
                 CLSCTX_INPROC_SERVER, IID_ICreateDevEnum,
                 reinterpret_cast<void **>(&pDevEnum));

    unsigned long iNumDevs = mode == QAudio::AudioOutput ? waveOutGetNumDevs() : waveInGetNumDevs();
    if (SUCCEEDED(hr)) {
        // Create the enumerator for the audio input/output category
        if (pDevEnum->CreateClassEnumerator(
             mode == QAudio::AudioOutput ? CLSID_AudioRendererCategory : CLSID_AudioInputDeviceCategory,
             &pEnum, 0) == S_OK) {
            pEnum->Reset();
            // go through and find all audio devices
            IMoniker *pMoniker = NULL;
            while (pEnum->Next(1, &pMoniker, NULL) == S_OK) {
                IPropertyBag *pPropBag;
                hr = pMoniker->BindToStorage(0,0,IID_IPropertyBag,
                     reinterpret_cast<void **>(&pPropBag));
                if (FAILED(hr)) {
                    pMoniker->Release();
                    continue; // skip this one
                }
                // Find if it is a wave device
                VARIANT var;
                VariantInit(&var);
                hr = pPropBag->Read(mode == QAudio::AudioOutput ? L"WaveOutID" : L"WaveInID", &var, 0);
                if (SUCCEEDED(hr)) {
                    LONG waveID = var.lVal;
                    if (waveID >= 0 && waveID < LONG(iNumDevs)) {
                        VariantClear(&var);
                        // Find the description
                        hr = pPropBag->Read(L"FriendlyName", &var, 0);
                        if (SUCCEEDED(hr)) {
                            QByteArray  device;
                            QDataStream ds(&device, QIODevice::WriteOnly);
                            ds << quint32(waveID) << QString::fromWCharArray(var.bstrVal);
                            devices.append(device);
                        }
                    }
                }

                pPropBag->Release();
                pMoniker->Release();
            }
        }
    }
    CoUninitialize();

    return devices;
}
Esempio n. 8
0
bool CCaptureVideo::BindFilter(int deviceId, IBaseFilter **pFilter)
{
	if (deviceId < 0) return false;

	// enumerate all video capture devices
	CComPtr<ICreateDevEnum> pCreateDevEnum;

	HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
	IID_ICreateDevEnum, (void**)&pCreateDevEnum);

	if (hr != NOERROR) return false;

	CComPtr<IEnumMoniker> pEm;

	hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,&pEm, 0);

	if (hr != NOERROR) return false;

	pEm->Reset();

	ULONG cFetched;

	IMoniker* pM;

	int index = 0;

	while(hr = pEm->Next(1, &pM, &cFetched), hr==S_OK, index <= deviceId)
	{
		IPropertyBag* pBag;

		hr = pM->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);

		if(SUCCEEDED(hr)) 
		{
			VARIANT var;

			var.vt = VT_BSTR;

			hr = pBag->Read(L"FriendlyName", &var, NULL);

			if (hr == NOERROR) 
			{
				if (index == deviceId)
				{
					pM->BindToObject(0, 0, IID_IBaseFilter, (void**)pFilter);
				}
				SysFreeString(var.bstrVal);
			}

			pBag->Release();

		}

		pM->Release();

		index++;
	}
	return true;
}
Esempio n. 9
0
int Camera::EnumDevices(PENUMDEVICE pCallback, void* pItem)
{
	int nDevice = 0;
	HRESULT			hr				= S_OK;

	// System device enumerators
	ICreateDevEnum	*pDevEnum		= NULL;
	IEnumMoniker	*pEnum			= NULL;
	IMoniker		*pMoniker		= NULL;

	CoInitialize(NULL);

	// Create system device enumerator
	hr = CoCreateInstance( CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, reinterpret_cast<void**>(&pDevEnum) );
	if (FAILED(hr)) {
		return 0;
	}

	// create enumerator for video capture devices
	hr = pDevEnum->CreateClassEnumerator( CLSID_VideoInputDeviceCategory, &pEnum, 0 );
	if (SUCCEEDED(hr)) 
	{
		IBindCtx* pbcfull = NULL;

		// Enumerate through the devices and print friendly name
		while ( (pEnum->Next( 1, &pMoniker, NULL ) == S_OK))
		{	
			VARIANT var;
			IPropertyBag *pPropertyBag;
			char szCameraName[200];

			// FrienlyName : The name of the device
			var.vt = VT_BSTR;

			// Bind to IPropertyBag
			pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropertyBag);
			
			// Reference: https://msdn.microsoft.com/en-us/library/windows/desktop/dd377566(v=vs.85).aspx
			hr = pPropertyBag->Read(L"Description", &var, 0);	// "FriendlyName", "DevicePath", "Description"
			if (FAILED(hr))
			{
				pPropertyBag->Read(L"FriendlyName", &var, 0);
			}
			WideCharToMultiByte(CP_ACP, 0, var.bstrVal, -1,szCameraName, sizeof(szCameraName), 0, 0);
			if (pCallback != NULL) {
				(*pCallback)(pItem, szCameraName);
			}
			VariantClear(&var);

			// Release resource
			pPropertyBag->Release();

			nDevice++;

			SAFE_RELEASE( pMoniker );
		}
	}
	return nDevice; // returns count of camera
}
Esempio n. 10
0
void Audio::LogDeviceInformation(IEnumMoniker *pEnum)
{
	logger.addline("Starting to record audio or video input devices.", info);
	IMoniker *pMoniker = NULL;

	while (pEnum->Next(1, &pMoniker, NULL) == S_OK)
	{
		logger.addline("Have found a new device", success);
		IPropertyBag *pPropBag;
		HRESULT hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
		if (FAILED(hr))
		{
			pMoniker->Release();
			continue;
		}

		VARIANT var;
		VariantInit(&var);

		// Get description or friendly name.
		hr = pPropBag->Read(L"Description", &var, 0);
		if (FAILED(hr))
		{
			hr = pPropBag->Read(L"FriendlyName", &var, 0);
		}
		if (SUCCEEDED(hr))
		{
			//printf("%S\n", var.bstrVal);
			logger.addline("Below is the device name.", debug);
			logger.addline(ConvertBSTRToMBS(var.bstrVal), debug);
			VariantClear(&var);
		}

		hr = pPropBag->Write(L"FriendlyName", &var);

		// WaveInID applies only to audio capture devices.
		hr = pPropBag->Read(L"WaveInID", &var, 0);
		if (SUCCEEDED(hr))
		{
			//printf("WaveIn ID: %d\n", var.lVal);
			logger.addline("Below is the WaveIn ID.", debug);
			logger.addline("BLANK FOR NOW! FIX ME LATER", debug);
			VariantClear(&var);
		}

		hr = pPropBag->Read(L"DevicePath", &var, 0);
		if (SUCCEEDED(hr))
		{
			// The device path is not intended for display.
			printf("Device path: %S\n", var.bstrVal);
			logger.addline("Below is the device path.", debug);
			//logger.addline(ConvertBSTRToMBS(var.bstrVal), success);
			VariantClear(&var);
		}

		pPropBag->Release();
		pMoniker->Release();
	}
}
QT_BEGIN_NAMESPACE

DSVideoDeviceControl::DSVideoDeviceControl(QObject *parent)
    : QVideoDeviceControl(parent)
{
    m_session = qobject_cast<DSCameraSession*>(parent);

    devices.clear();
    descriptions.clear();

    CoInitialize(NULL);
    ICreateDevEnum* pDevEnum = NULL;
    IEnumMoniker* pEnum = NULL;
    // Create the System device enumerator
    HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
            CLSCTX_INPROC_SERVER, IID_ICreateDevEnum,
            reinterpret_cast<void**>(&pDevEnum));
    if(SUCCEEDED(hr)) {
        // Create the enumerator for the video capture category
        hr = pDevEnum->CreateClassEnumerator(
                CLSID_VideoInputDeviceCategory, &pEnum, 0);
        if (S_OK == hr) {
            pEnum->Reset();
            // go through and find all video capture devices
            IMoniker* pMoniker = NULL;
            while(pEnum->Next(1, &pMoniker, NULL) == S_OK) {
                IPropertyBag *pPropBag;
                hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
                        (void**)(&pPropBag));
                if(FAILED(hr)) {
                    pMoniker->Release();
                    continue; // skip this one
                }
                // Find the description
                WCHAR str[120];
                VARIANT varName;
                varName.vt = VT_BSTR;
                hr = pPropBag->Read(L"FriendlyName", &varName, 0);
                if(SUCCEEDED(hr)) {
                    wcsncpy(str, varName.bstrVal, sizeof(str)/sizeof(str[0]));
                    QString temp(QString::fromUtf16((unsigned short*)str));
                    devices.append(QString("ds:%1").arg(temp).toLocal8Bit().constData());
                    hr = pPropBag->Read(L"Description", &varName, 0);
                    wcsncpy(str, varName.bstrVal, sizeof(str)/sizeof(str[0]));
                    QString temp2(QString::fromUtf16((unsigned short*)str));
                    descriptions.append(temp2.toLocal8Bit().constData());
                }
                pPropBag->Release();
                pMoniker->Release();
            }
            pEnum->Release();
        }
        pDevEnum->Release();
    }
    CoUninitialize();

    selected = 0;
}
Esempio n. 12
0
void FaceTrackNoIR::GetCameraNameDX() {
#if defined(_WIN32)
	ui.cameraName->setText("No video-capturing device was found in your system: check if it's connected!");

	// Create the System Device Enumerator.
	HRESULT hr;
	ICreateDevEnum *pSysDevEnum = NULL;
	hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysDevEnum);
	if (FAILED(hr))
	{
		qDebug() << "GetWDM says: CoCreateInstance Failed!";
		return;
	}

	qDebug() << "GetWDM says: CoCreateInstance succeeded!";
	
	// Obtain a class enumerator for the video compressor category.
	IEnumMoniker *pEnumCat = NULL;
	hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0);

	if (hr == S_OK) {
		qDebug() << "GetWDM says: CreateClassEnumerator succeeded!";

		IMoniker *pMoniker = NULL;
		ULONG cFetched;
		if (pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK) {
			IPropertyBag *pPropBag;
			hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag);
			if (SUCCEEDED(hr))	{
				VARIANT varName;
				VariantInit(&varName);
				hr = pPropBag->Read(L"FriendlyName", &varName, 0);
				if (SUCCEEDED(hr))
				{
					QString str((QChar*)varName.bstrVal, wcslen(varName.bstrVal));
					qDebug() << "GetWDM says: Moniker found:" << str;
					ui.cameraName->setText(str);
				}
				VariantClear(&varName);

				pPropBag->Release();
			}
			pMoniker->Release();
		}
		pEnumCat->Release();
	}
	pSysDevEnum->Release();
#else
    for (int i = 0; i < 16; i++) {
        char buf[128];
        sprintf(buf, "/dev/video%d", i);
        if (access(buf, R_OK | W_OK) == 0) {
            ui.cameraName->setText(QString(buf));
            break;
        }
    }
#endif
}
Esempio n. 13
0
void DSServicePlugin::updateDevices() const
{
    m_cameraDevices.clear();
    m_cameraDescriptions.clear();
    BOOL bFound = TRUE;
    CoInitialize(NULL);
    ICreateDevEnum* pDevEnum = NULL;
    IEnumMoniker* pEnum = NULL;
    // Create the System device enumerator
    HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
                 CLSCTX_INPROC_SERVER, IID_ICreateDevEnum,
		 reinterpret_cast<void**>(&pDevEnum));
    if(SUCCEEDED(hr)) {
        // Create the enumerator for the video capture category
	hr = pDevEnum->CreateClassEnumerator(
	     CLSID_VideoInputDeviceCategory, &pEnum, 0);
        if (S_OK == hr) {
            pEnum->Reset();
            // go through and find all video capture devices
            IMoniker* pMoniker = NULL;
            while(pEnum->Next(1, &pMoniker, NULL) == S_OK) {
                IPropertyBag *pPropBag;
                hr = pMoniker->BindToStorage(0,0,IID_IPropertyBag,
                     (void**)(&pPropBag));
                if(FAILED(hr)) {
                    pMoniker->Release();
                    continue; // skip this one
                }
                bFound = TRUE;
                // Find the description
                WCHAR str[120];
                VARIANT varName;
                varName.vt = VT_BSTR;
                hr = pPropBag->Read(L"FriendlyName", &varName, 0);
                if(SUCCEEDED(hr)) {
                    wcsncpy(str, varName.bstrVal, sizeof(str)/sizeof(str[0]));
                    QString temp(QString::fromUtf16((unsigned short*)str));
                    m_cameraDevices.append(QString("ds:%1").arg(temp).toLocal8Bit().constData());
                    hr = pPropBag->Read(L"Description", &varName, 0);
                    wcsncpy(str, varName.bstrVal, sizeof(str)/sizeof(str[0]));
                    QString temp2(QString::fromUtf16((unsigned short*)str));
                    m_cameraDescriptions.append(temp2);
                } else {
                    qWarning() << "No friendly name";
                }
                pPropBag->Release();
                pMoniker->Release();
            }
            pEnum->Release();
        }
        pDevEnum->Release();
    }
    CoUninitialize();
    if (!bFound) {
        qWarning() << "No camera devices found";
    }
}
Esempio n. 14
0
int VideoCapture::EnumDevices()
{
	int id = 0;
	
    // enumerate all video capture devices
	CComPtr<ICreateDevEnum> pCreateDevEnum;

	HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
								  IID_ICreateDevEnum, (void**)&pCreateDevEnum);
    if (hr != NOERROR)  return -1;
	
    CComPtr<IEnumMoniker> pEm;
    hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
								&pEm, 0);
    if (hr != NOERROR) 	return -1 ;
    
    pEm->Reset();

    IMoniker *pM;
	nDevices = 0;
    while(hr = pEm->Next(1, &pM, NULL), hr==S_OK)
		nDevices++;
	
	if (nDevices==0) return -1;

	pEm->Reset();

	devices_names = new string[nDevices];
		
	while(hr = pEm->Next(1, &pM, NULL), hr==S_OK)
    {
		IPropertyBag *pBag;
		hr = pM->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);
		if(SUCCEEDED(hr)) 
		{
			VARIANT var;
			var.vt = VT_BSTR;
			hr = pBag->Read(L"FriendlyName", &var, NULL);
			if (hr == NOERROR) 
			{
				TCHAR str[2048];		

				WideCharToMultiByte(CP_ACP,0,var.bstrVal, -1, str, 2048, NULL, NULL);
				devices_names[id] = str;

				id++;

				SysFreeString(var.bstrVal);
			}
			pBag->Release();
		}
		pM->Release();
    }
	return id;
}
Esempio n. 15
0
//枚举设备
HRESULT CCaptureDevice::EnumDevices( REFCLSID clsidDeviceClass, ENUMCALLBACK pEnumCallBack, LPVOID lp )
{
	//创建枚举组件
    ICreateDevEnum *pCreateDevEnum;
	HRESULT hr;
	VARIANT var;
	hr = CoCreateInstance( CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,IID_ICreateDevEnum, (void**)&pCreateDevEnum );
	if( hr==S_OK )
	{
		//创建枚举器
		IEnumMoniker* pEm;
		hr = pCreateDevEnum->CreateClassEnumerator( clsidDeviceClass, &pEm, 0 );
		if( hr==S_OK )
		{
			if( pEm )
			{
				//复位
				pEm->Reset();

				//准备顺序找设备
				ULONG cFetched;
				IMoniker *pM;
				BOOL bCancel = false;
				int index = 0;
				while( !bCancel && (hr = pEm->Next(1, &pM, &cFetched), hr==S_OK) )
				{
					IPropertyBag *pBag;
					hr = pM->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);
					if(hr==S_OK)
					{
						ZeroMemory( &var, sizeof(var) );
						var.vt = VT_BSTR;
						hr = pBag->Read(L"FriendlyName", &var, NULL);
						if(hr==S_OK && var.bstrVal!=0 )
						{
							if(pEnumCallBack)
								hr = pEnumCallBack( index, &var, pM, lp, bCancel );
							SysFreeString(var.bstrVal);
						}
						pBag->Release();
					}
					pM->Release();
					index++;
				}

				//释放
				pEm->Release();
			}
		}
		pCreateDevEnum->Release();
	}
	return hr;
}
	void DisplayDeviceInformation(IEnumMoniker *pEnum)
	{
		IMoniker *pMoniker = NULL;

		while (pEnum->Next(1, &pMoniker, NULL) == S_OK)
		{
			IPropertyBag *pPropBag;
			HRESULT hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
			if (FAILED(hr))
			{
				pMoniker->Release();
				continue;  
			} 

			VARIANT var;
			VariantInit(&var);

			// Get description or friendly name.
			hr = pPropBag->Read(L"Description", &var, 0);
			if (FAILED(hr))
			{
				hr = pPropBag->Read(L"FriendlyName", &var, 0);
			}
			if (SUCCEEDED(hr))
			{
				out_message() << "Capture device: " << var.bstrVal << std::endl;
				VariantClear(&var); 
			}

			hr = pPropBag->Write(L"FriendlyName", &var);

			// WaveInID applies only to audio capture devices.
			hr = pPropBag->Read(L"WaveInID", &var, 0);
			if (SUCCEEDED(hr))
			{
				out_message() << "Audio device: " << var.lVal << std::endl;
				VariantClear(&var); 
			}

			hr = pPropBag->Read(L"DevicePath", &var, 0);
			if (SUCCEEDED(hr))
			{
				// The device path is not intended for display.
				out_message() << "Video device: " << var.bstrVal << std::endl;
				VariantClear(&var); 
			}

			pPropBag->Release();
			pMoniker->Release();
		}
	}
Esempio n. 17
0
//连接音频设备,并将音频设备加入到
BOOL CCaptureAudio::BindToAudioDev(int deviceId, IBaseFilter **pFilter)
{
	if (deviceId < 0)
	{
		return FALSE;
	}
	CComPtr<ICreateDevEnum> pCreateDevEnum;
	HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
		IID_ICreateDevEnum, (void**)&pCreateDevEnum);
	if (hr != NOERROR)
	{
		return FALSE;
	}
	CComPtr<IEnumMoniker> pEm;
	//此处与视频不同的地方
	hr = pCreateDevEnum->CreateClassEnumerator(CLSID_AudioInputDeviceCategory,&pEm, 0);
	if (hr != NOERROR)
	{
		return FALSE;
	}
	pEm->Reset();
	ULONG cFetched;
	IMoniker *pM;
	
	int index = 0;
	while(hr = pEm->Next(1, &pM, &cFetched), hr==S_OK, index <= deviceId)
	{
		IPropertyBag *pBag;
		hr = pM->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);
		if(SUCCEEDED(hr)) 
		{
			VARIANT var;
			var.vt = VT_BSTR;
			hr = pBag->Read(L"FriendlyName", &var, NULL);
			if (hr == NOERROR) 
			{
				if (index == deviceId)
				{
					//将视频设备绑定到基础过滤器上
					pM->BindToObject(0, 0, IID_IBaseFilter, (void**)pFilter);
					//m_iDeviceId = deviceId;
				}
				SysFreeString(var.bstrVal);
			}
			pBag->Release();
		}
		pM->Release();
		index++;
	}
	return TRUE;
}
Esempio n. 18
0
int CCameraDS::CameraName(int nCamID, char* sName, int nBufferSize)
{
	int count = 0;
 	CoInitialize(NULL);

   // enumerate all video capture devices
	CComPtr<ICreateDevEnum> pCreateDevEnum;
    HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
									IID_ICreateDevEnum, (void**)&pCreateDevEnum);

    CComPtr<IEnumMoniker> pEm;
    hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
        &pEm, 0);
    if (hr != NOERROR) return 0;


    pEm->Reset();
    ULONG cFetched;
    IMoniker *pM;
    while(hr = pEm->Next(1, &pM, &cFetched), hr==S_OK)
    {
		if (count == nCamID)
		{
			IPropertyBag *pBag=0;
			hr = pM->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);
			if(SUCCEEDED(hr))
			{
				VARIANT var;
				var.vt = VT_BSTR;
				hr = pBag->Read(L"FriendlyName", &var, NULL); //还有其他属性,像描述信息等等...
	            if(hr == NOERROR)
		        {
			        //获取设备名称			
					WideCharToMultiByte(CP_ACP,0,var.bstrVal,-1,sName, nBufferSize ,"",NULL);

	                SysFreeString(var.bstrVal);				
		        }
			    pBag->Release();
			}
			pM->Release();

			break;
		}
		count++;
    }

	pCreateDevEnum = NULL;
	pEm = NULL;

	return 1;
}
Esempio n. 19
0
HRESULT CaptureGraph::GetCaptureFilters(int *filterCount, CListBox *captureFilterList)
{
	HRESULT hr;
	int maxFilterCount = *filterCount;
	ICreateDevEnum *pSysVideoCaptureEnum = NULL;
	hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysVideoCaptureEnum);
	if (FAILED(hr))
	{
		return hr;
	}
	IBaseFilter *pVideoCapture = NULL;
	IEnumMoniker *pEnumMoniker = NULL;
	hr = pSysVideoCaptureEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumMoniker, 0);
	if (hr == S_OK)
	{
		IMoniker *pMoniker = NULL;
		ULONG fetched;
		int filterIndex = 0;
		while(pEnumMoniker->Next(1, &pMoniker, &fetched) == S_OK)
		{
			IPropertyBag *pPropBag;
			hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag);
			if(SUCCEEDED(hr))
			{
				VARIANT varName;
				VariantInit(&varName);
				hr = pPropBag->Read(L"FriendlyName", &varName, 0);
				if(SUCCEEDED(hr))
				{
					ASSERT(varName.vt == VT_BSTR);
					CString friendlyName(varName.bstrVal);
					
					VariantClear(&varName);
					pPropBag->Release();

					filterIndex ++;
					captureFilterList->AddString(friendlyName);
					int currentFilterIndex = captureFilterList->FindStringExact(-1, friendlyName);
					captureFilterList->SetItemDataPtr(currentFilterIndex, pMoniker);
					if(filterIndex > maxFilterCount)
					{
						*filterCount = filterIndex;
						break;
					}
				}
			}
		}
		pEnumMoniker->Release();
	}
	pSysVideoCaptureEnum->Release();
}
Esempio n. 20
0
// @pymethod <o PyIUnknown>|PyIMoniker|BindToStorage|Retrieves an interface object to the storage that contains the object identified by the moniker.
PyObject *PyIMoniker::BindToStorage(PyObject *self, PyObject *args)
{
	// @pyparm <o PyIBindCtx>|bindCtx||bind context object to be used.
	// @pyparm <o PyIMoniker>|moniker||If the moniker is part of a composite moniker, otherwise None
	// @pyparm <o IID>|iidResult||IID of the result object.
	PyObject *obBindCtx;
	PyObject *obMoniker;
	PyObject *obIID;

	if (!PyArg_ParseTuple(args, "OOO:BindToStorage", &obBindCtx, &obMoniker, &obIID))
		return NULL;

	IMoniker *pMy = GetI(self);
	if (pMy==NULL) return NULL;

	IBindCtx *pBindCtx;
	if (!PyCom_InterfaceFromPyInstanceOrObject(obBindCtx, IID_IBindCtx, (void **)&pBindCtx, FALSE))
		return NULL;
	
	IMoniker *pMonLeft = NULL;
	if (obMoniker!=Py_None) {
		if (!PyCom_InterfaceFromPyInstanceOrObject(obMoniker, IID_IMoniker, (void **)&pMonLeft, FALSE)) {
			PY_INTERFACE_PRECALL;
			pBindCtx->Release();
			PY_INTERFACE_POSTCALL;

			return NULL;
		}
	}
	IID iid;
	if (!PyWinObject_AsIID(obIID, &iid)) {
		PY_INTERFACE_PRECALL;
		pBindCtx->Release();
		if (pMonLeft) pMonLeft->Release();
		PY_INTERFACE_POSTCALL;

		return NULL;
	}

	void *pResult = NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pMy->BindToStorage(pBindCtx, pMonLeft, iid, &pResult );
	pBindCtx->Release();
	if (pMonLeft) pMonLeft->Release();
	PY_INTERFACE_POSTCALL;

	if (S_OK!=hr) // S_OK only acceptable
		return PyCom_BuildPyException(hr, pMy, IID_IMoniker);
	return PyCom_PyObjectFromIUnknown((IUnknown *)pResult, iid, FALSE );
}
Esempio n. 21
0
	HRESULT GetCaptureFilter(REFCLSID CLSID_DeviceCategory, LPCTSTR lpFriendlyName, void** ppCapture)
	{
		ICreateDevEnum *pCreateDevEnum = 0;
		HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum
			, NULL
			, CLSCTX_INPROC_SERVER
			, IID_ICreateDevEnum
			, (void**)&pCreateDevEnum);
		if (FAILED(hr)) return hr;

		IEnumMoniker* pEnumMoniker = 0;
		hr = pCreateDevEnum->CreateClassEnumerator(CLSID_DeviceCategory, &pEnumMoniker, 0);
		if (FAILED(hr))
		{
			pCreateDevEnum->Release();
			return hr;
		}
		pEnumMoniker->Reset();

		BOOL bFound = FALSE;
		IMoniker* pMoniker = NULL;
		while ((pEnumMoniker->Next(1, &pMoniker, NULL) == S_OK )&& (!bFound))
		{
			IPropertyBag *pBag = NULL;
			hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);
			if (SUCCEEDED(hr))
			{
				VARIANT var = { 0 };
				var.vt = VT_BSTR;
				hr = pBag->Read(_T("FriendlyName"), &var, NULL);
				if (SUCCEEDED(hr))
				{
					if (!_tcscmp(var.bstrVal, lpFriendlyName))
					{
						hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**)ppCapture);
						pMoniker->AddRef();
						bFound = TRUE;
					}
					pBag->Release();
				}
			}
			pMoniker->Release();
		}//end while
		pEnumMoniker->Release();
		pCreateDevEnum->Release();

		if (*ppCapture == NULL) return E_FAIL;
		if (FAILED(hr)) return hr;
		return bFound ? S_OK : S_FALSE;
	}
Esempio n. 22
0
HRESULT CDShowControl::CreateFilter(CString filterName, IBaseFilter **pFilter, FILTER_CATEGORY category)
{
	HRESULT hr;
	IMoniker *pMoniker;
	IEnumMoniker *pEnumCat = NULL;
	ICreateDevEnum *pCreateDevEnum = NULL;
	ULONG cFetched;
	VARIANT varName = {0};

	RETURNIF(CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void**)&pCreateDevEnum));
	RETURNIF(pCreateDevEnum->CreateClassEnumerator(*categories[category].pClsid, &pEnumCat, 0));
	if (!pEnumCat)
	{
		return S_FALSE;
	}
	while (pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK)
	{
		IPropertyBag *pPropBag;
		hr = pMoniker->BindToStorage(0,0,IID_IPropertyBag,(void**)&pPropBag);
		if (FAILED(hr))
			continue;
		varName.vt = VT_BSTR;
		hr = pPropBag->Read(L"FriendlyName", &varName, 0);
		if (FAILED(hr))
			continue;

		CString str(varName.bstrVal);
		SysFreeString(varName.bstrVal);

		if (str.Find(filterName) != -1 || filterName.Compare(L"") == 0)
		{
			hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**)pFilter);
			if (SUCCEEDED(hr))
			{
				SAFE_RELEASE(pPropBag);
				SAFE_RELEASE(pMoniker);
				pEnumCat->Release();
				pCreateDevEnum->Release();
				return S_OK;
			}
		}
		SAFE_RELEASE(pPropBag);
		SAFE_RELEASE(pMoniker);
	}
	SAFE_RELEASE(pEnumCat);
	SAFE_RELEASE(pCreateDevEnum);

	return S_FALSE;
}
Esempio n. 23
0
bool CDirectShowDeviceEnumerator::CreateFilter(REFCLSID clsidDeviceClass,LPCWSTR pszFriendlyName,IBaseFilter **ppFilter)
{
	HRESULT hr;
	ICreateDevEnum *pDevEnum;

	hr=::CoCreateInstance(CLSID_SystemDeviceEnum,NULL,CLSCTX_INPROC_SERVER,
						  IID_ICreateDevEnum,reinterpret_cast<void**>(&pDevEnum));
	if (FAILED(hr))
		return false;

	IEnumMoniker *pEnumCategory;
	hr=pDevEnum->CreateClassEnumerator(clsidDeviceClass,&pEnumCategory,0);
	bool bFound=false;
	if (hr==S_OK) {
		IMoniker *pMoniker;
		ULONG cFetched;

		while (pEnumCategory->Next(1,&pMoniker,&cFetched)==S_OK) {
			IPropertyBag *pPropBag;

			hr=pMoniker->BindToStorage(0,0,IID_IPropertyBag,reinterpret_cast<void**>(&pPropBag));
			if (SUCCEEDED(hr)) {
				VARIANT varName;

				::VariantInit(&varName);
				hr=pPropBag->Read(L"FriendlyName",&varName,0);
				if (SUCCEEDED(hr)) {
					if (::lstrcmpiW(varName.bstrVal,pszFriendlyName)==0) {
						hr=pMoniker->BindToObject(NULL,NULL,IID_IBaseFilter,
										reinterpret_cast<void**>(ppFilter));
						bFound=true;
					}
				}
				::VariantClear(&varName);
				pPropBag->Release();
			}
			pMoniker->Release();
			if (bFound)
				break;
		}
		pEnumCategory->Release();
	}
	pDevEnum->Release();

	if (!bFound)
		return false;
	return SUCCEEDED(hr);
}
Esempio n. 24
0
	HRESULT EnumCaptures(REFCLSID CLSID_DeviceCategory, std::vector<TCaptureDevice>& refDeviceList)
	{
		refDeviceList.clear();

		ICreateDevEnum *pCreateDevEnum = 0;
		HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum
			, NULL
			, CLSCTX_INPROC_SERVER
			, IID_ICreateDevEnum
			, (void**)&pCreateDevEnum);
		if (FAILED(hr)) return hr;

		IEnumMoniker* pEnumMoniker = 0;
		hr = pCreateDevEnum->CreateClassEnumerator(CLSID_DeviceCategory, &pEnumMoniker, 0);
		if (FAILED(hr))
		{
			pCreateDevEnum->Release();
			return hr;
		}
		pEnumMoniker->Reset();

		IMoniker* pMoniker = NULL;
		while (pEnumMoniker->Next(1, &pMoniker, NULL) == S_OK)
		{
			IPropertyBag *pBag = NULL;
			hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);
			if (SUCCEEDED(hr))
			{
				VARIANT var = { 0 };
				var.vt = VT_BSTR;
				hr = pBag->Read(_T("FriendlyName"), &var, NULL);
				if (SUCCEEDED(hr))
				{
					TCaptureDevice device;
					_tcscpy_s(device.szDeviceName, var.bstrVal);
					refDeviceList.push_back(device);
					pBag->Release();
				}
			}
			pMoniker->Release();
		}//end while

		pEnumMoniker->Release();
		pCreateDevEnum->Release();
		return hr;
	}
// Capture control
// --------------------------------------------------------------------------------------
int VideoCaptureDirectShow2::listDevices() {
  // Get enumerator creator 
  int count = 0;

  IEnumMoniker* enum_moniker = NULL;
  if(!createDeviceMoniker(&enum_moniker)) {
    RX_ERROR("Cannot create IEnumMoniker so also not the device");
    goto done;
  }

  // Get information from devices
  HRESULT hr = S_OK;
  IMoniker* moniker = NULL;
  while(enum_moniker->Next(1, &moniker, NULL) == S_OK) {
    
    // Get the properties bag
    IPropertyBag* property_bag = NULL;
    hr = moniker->BindToStorage(0, 0, IID_PPV_ARGS(&property_bag));
    if(FAILED(hr)) {
      RX_ERROR("Cannot bind property bag to storage");
      moniker->Release();
      continue;
    }

    VARIANT var;
    VariantInit(&var);

    // Get the FriendlyName
    hr = property_bag->Read(L"FriendlyName", &var, 0);
    if(SUCCEEDED(hr)) {
      RX_VERBOSE("[%d] %S", count, var.bstrVal);
      VariantClear(&var);
    }
    else {
      RX_ERROR("Cannot retrieve the FriendlyName");
    }
    
    ++count;
    property_bag->Release();
    moniker->Release();
  }

 done:
  safeReleaseDirectShow(&enum_moniker);
  return count;
}
Esempio n. 26
0
BOOL CSystemInfo::GetCameraInfo()
{
	::CoInitialize(NULL);

	ICreateDevEnum *pSysDevEnum = NULL;
	BOOL            bIsGetSuccess = FALSE;
	HRESULT         hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysDevEnum);
	if (hr == S_FALSE)	return FALSE;	

	IEnumMoniker *pEnumCat = NULL;
	hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0);
	if (hr == S_FALSE)	return FALSE;	

	//Enumerate   the   monikers.   
	IMoniker *pMoniker = NULL;
	ULONG   cFetched;
	while(pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK)
	{
		IPropertyBag *pPropBag = NULL;
		hr = pMoniker->BindToStorage(0,   0,   IID_IPropertyBag, (void **)&pPropBag);
		if (SUCCEEDED(hr))
		{
			//To retrieve the filter's  friendly   name,   do   the   following:   
			VARIANT   varName;
			VariantInit(&varName);
			hr = pPropBag->Read(L"FriendlyName", &varName, 0);
			if (SUCCEEDED(hr))
			{
				_bstr_t str(varName);
				tstrcpy(m_stCltHardInfo.szWebcam, MAX_PATH, (TCHAR*)str);
				bIsGetSuccess = TRUE;
			}
			VariantClear(&varName);

			//Remember   to   release   pFilter   later.
			pPropBag->Release();
		}
		pMoniker->Release();
		if (bIsGetSuccess) break;
	}
	pEnumCat->Release();
	pSysDevEnum->Release();
	::CoUninitialize();
	return TRUE;
}
Esempio n. 27
0
MonikersMap CaptureDShow::listMonikers() const
{
    MonikersMap monikers;
    IEnumMoniker *pEnum = NULL;
    HRESULT hr = this->enumerateCameras(&pEnum);

    if (SUCCEEDED(hr)) {
        IMoniker *pMoniker = NULL;

        for (int i = 0; pEnum->Next(1, &pMoniker, NULL) == S_OK; i++) {
            IPropertyBag *pPropBag;
            HRESULT hr = pMoniker->BindToStorage(0,
                                                 0,
                                                 IID_IPropertyBag,
                                                 reinterpret_cast<void **>(&pPropBag));

            if (FAILED(hr)) {
                pMoniker->Release();

                continue;
            }

            VARIANT var;
            VariantInit(&var);
            hr = pPropBag->Read(L"DevicePath", &var, 0);

            QString devicePath;

            if (SUCCEEDED(hr))
                devicePath = QString::fromWCharArray(var.bstrVal);
            else
                devicePath = QString("/dev/video%1").arg(i);

            monikers[devicePath] = MonikerPtr(pMoniker, this->deleteUnknown);

            VariantClear(&var);
            pPropBag->Release();
        }

        pEnum->Release();
    }

    return monikers;
}
Esempio n. 28
0
/* 枚举本地系统的采集设备 */
int  CVMR_Capture::EnumDevices(HWND hList)
{
	if (!hList) return  -1;
	int id = 0;
    
	// enumerate all video capture devices
    ICreateDevEnum *pCreateDevEnum;
    HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, 
						CLSCTX_INPROC_SERVER,
						IID_ICreateDevEnum, (void**)&pCreateDevEnum);
    if (hr != NOERROR) return -1;
	
	IEnumMoniker *pEm;
    hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEm, 0);
    if (hr != NOERROR) return -1;

    pEm->Reset();
    ULONG cFetched;
    IMoniker *pM;
    while(hr = pEm->Next(1, &pM, &cFetched), hr==S_OK)
    {
		IPropertyBag *pBag;
		hr = pM->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);
		if(SUCCEEDED(hr)) 
		{
			VARIANT var;
			var.vt = VT_BSTR;
			hr = pBag->Read(L"FriendlyName", &var, NULL);
			if (hr == NOERROR) 
			{
				id++;
				(long)SendMessage(hList, CB_ADDSTRING, 0,(LPARAM)var.bstrVal);
				SysFreeString(var.bstrVal);
			}
			pBag->Release();
		}
		pM->Release();
    }
	return id;
}
Esempio n. 29
0
int CCaptureVideo::EnumDevices(BYTE* buf)
{
	int id = 0;//枚举视频扑捉设备
	   //ICreateDevEnum接口建立指定类型的列表
	ICreateDevEnum *pCreateDevEnum;
	   //用指定的类标识符创建一个未初始化的对象,这里的参数为CLSID_SystemDeviceEnum即枚举设备的对象
	HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,IID_ICreateDevEnum, (void**)&pCreateDevEnum);if (hr != NOERROR)return -1;
	CComPtr<IEnumMoniker> pEm;
	   //指出要枚举那个类型的设备这里参数CLSID_VideoInputDeviceCategory枚举视频设备
	hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,&pEm, 0);
	   if (hr != NOERROR)return -1;
	   pEm->Reset();
	   ULONG cFetched;
       IMoniker *pM;
	   int count=0;           //记录数组的个数
	   while(hr = pEm->Next(1, &pM, &cFetched), hr==S_OK) {
		   IPropertyBag *pBag;
		   //此绑定到该对象的存储
		   hr = pM->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);
		   if(SUCCEEDED(hr)) {
			   VARIANT var;
			   var.vt = VT_BSTR;
			   hr = pBag->Read(L"FriendlyName", &var, NULL);  //读取设备名
			   if (hr == NOERROR) {
				   TCHAR str[2048]; 
				   id++;
				   WideCharToMultiByte(CP_ACP,0,var.bstrVal, -1, str, 2048, NULL, NULL);
				   //::SendMessage(hList, CB_ADDSTRING, 0,(LPARAM)str);
				   //将得到的设备名存储起来
				   memcpy(buf+(count++)*512,str,strlen(str));
				   SysFreeString(var.bstrVal);
			   }
			   pBag->Release();
		   }
		   pM->Release();
	   }
	   return id;
	   
				   //oninitdialog分析过了,就是获取视频设备名,然后我们点击HaveLook就能显示视频的数据,我们去看一看
}
Esempio n. 30
0
// Code from http://msdn.microsoft.com/en-us/library/windows/desktop/dd377566(v=vs.85).aspx
void	Video::EnumerateDevices( EnumerateDelegate _pDeviceEnumerator, void* _pUserData )
{
	IEnumMoniker*	pEnumerator = NULL;
	ASSERT( SUCCEEDED( EnumerateDevices( CLSID_VideoInputDeviceCategory, &pEnumerator ) ), "Failed enumerating devices!" );

	VARIANT	varFriendlyName, varDevicePath;
	VariantInit( &varFriendlyName );
	VariantInit( &varDevicePath );

	int			DeviceIndex = 0;
	IMoniker*	pMoniker = NULL;
	while ( pEnumerator->Next( 1, &pMoniker, NULL ) == S_OK )
	{
		IPropertyBag*	pPropBag;
		HRESULT hr = pMoniker->BindToStorage( 0, 0, IID_PPV_ARGS( &pPropBag ) );
		if ( FAILED(hr) )
		{
			pMoniker->Release();
			continue;  
		} 

		// Get friendly name.
		hr = pPropBag->Read( L"FriendlyName", &varFriendlyName, 0 );
		if ( !SUCCEEDED(hr) )
			continue;

		hr = pPropBag->Read( L"DevicePath", &varDevicePath, 0 );
		if ( !SUCCEEDED(hr) )
			continue;

		// Notify delegate
		(*_pDeviceEnumerator)( DeviceIndex++, varFriendlyName.bstrVal, varDevicePath.bstrVal, pMoniker, _pUserData );

		pPropBag->Release();
		pMoniker->Release();
	}

	pEnumerator->Release();
}