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; }
//Возвращает массив имен зарегистрированных в системе фильтров DirectShow (определенной категории) //Что бы узнать требуемую размерность массива, достаточно вызвать функцию //с lpwDSFilArr равным NULL - значение вернется в pArrSize. //В случае ошибки функция вернет значение меньше нуля int CDirectShow::GetDSFiltersNames(LPWSTR *lpwDSFilArr, LPDWORD pArrSize, DWORD dwBuffSize) { if (!m_lDSFilCount) return -1; if (lpwDSFilArr) { IPropertyBag *pPropBag = NULL; VARIANT varDSFName = { 0 }; varDSFName.vt = VT_BSTR; for (m_lCounter = 0; m_lCounter < m_lDSFilCount; m_lCounter++) { if (m_pDSFMoniker[m_lCounter] == NULL) return -1; m_pDSFMoniker[m_lCounter]->BindToStorage(NULL, NULL, IID_IPropertyBag, (LPVOID *)&pPropBag); if (SUCCEEDED(pPropBag->Read(L"FriendlyName", &varDSFName, NULL))) { wcscpy(lpwDSFilArr[m_lCounter], varDSFName.bstrVal); SysFreeString(varDSFName.bstrVal); } else { wcscpy(lpwDSFilArr[m_lCounter], L"<untitled>"); } pPropBag->Release(); } return 0; } else { *pArrSize = m_lDSFilCount; return 0; } }
HRESULT CDSFilterEnum::getFriendlyName(wstring* pName) { if (m_pIMoniker == NULL) { return E_POINTER; } IPropertyBag *pBag; HRESULT hr =m_pIMoniker->BindToStorage(NULL, NULL, IID_IPropertyBag, reinterpret_cast<void**>(&pBag)); if(FAILED(hr)) { OutputDebug(L"Cannot BindToStorage for.\n"); return hr; } VARIANT varName; ::VariantInit(&varName); hr = pBag->Read(L"FriendlyName", &varName, NULL); if(FAILED(hr)){ OutputDebug(L"IPropertyBag->Read method failed for.\n"); SAFE_RELEASE(pBag); ::VariantClear(&varName); return hr; } *pName = varName.bstrVal; SAFE_RELEASE(pBag); ::VariantClear(&varName); return S_OK; }
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); } }
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; }
// @pymethod |PyIPersistPropertyBag|Save|Called by the container to save the object's properties. PyObject *PyIPersistPropertyBag::Save(PyObject *self, PyObject *args) { PyObject *obBag; // @pyparm <o PyIPropertyBag>|bag||the caller's property bag. int clearDirty; // @pyparm int|clearDirty||Specifies whether to clear the dirty flag. int saveAllProperties; // @pyparm int|saveProperties||Specifies whether to save all properties or just those that have changed if ( !PyArg_ParseTuple(args, "Oii:Save", &obBag, &clearDirty, &saveAllProperties) ) return NULL; IPersistPropertyBag *pIPPB = GetI(self); if ( pIPPB == NULL ) return NULL; IPropertyBag *pIPB; if ( !PyCom_InterfaceFromPyObject(obBag, IID_IPropertyBag, (LPVOID*)&pIPB, FALSE) ) return NULL; PY_INTERFACE_PRECALL; HRESULT hr = pIPPB->Save(pIPB, clearDirty, saveAllProperties); pIPB->Release(); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIPPB, IID_IPersistPropertyBag); Py_INCREF(Py_None); return Py_None; }
// @pymethod |PyIPersistPropertyBag|Load|Called by the container to load the control's properties. PyObject *PyIPersistPropertyBag::Load(PyObject *self, PyObject *args) { PyObject *obBag; // @pyparm <o PyIPropertyBag>|bag||the caller's property bag. PyObject *obLog = NULL; // @pyparm <o PyIErrorLog>|log|None|the caller's error log, or None if ( !PyArg_ParseTuple(args, "O|O:Load", &obBag, &obLog) ) return NULL; IPersistPropertyBag *pIPPB = GetI(self); if ( pIPPB == NULL ) return NULL; IPropertyBag *pIPB; if ( !PyCom_InterfaceFromPyObject(obBag, IID_IPropertyBag, (LPVOID*)&pIPB, FALSE) ) return NULL; IErrorLog *pIEL = NULL; if ( obLog != NULL && obLog != Py_None && !PyCom_InterfaceFromPyObject(obLog, IID_IErrorLog, (LPVOID*)&pIEL, FALSE) ) { pIPB->Release(); return NULL; } PY_INTERFACE_PRECALL; HRESULT hr = pIPPB->Load(pIPB, pIEL); pIPB->Release(); pIEL->Release(); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIPPB, IID_IPersistPropertyBag); Py_INCREF(Py_None); return Py_None; }
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; }
// @pymethod |PyIPropertyBag|Write|Called by the control to write each property in turn to the storage provided by the container. PyObject *PyIPropertyBag::Write(PyObject *self, PyObject *args) { PyObject *obName; PyObject *obValue; // @pyparm str|propName||Name of the property to read. // @pyparm object|value||The value for the property. The value must be able to be converted to a COM VARIANT. if ( !PyArg_ParseTuple(args, "OO:Write", &obName, &obValue) ) return NULL; IPropertyBag *pIPB = GetI(self); if ( pIPB == NULL ) return NULL; TmpWCHAR Name; if ( !PyWinObject_AsWCHAR(obName, &Name)) return NULL; VARIANT var; if ( !PyCom_VariantFromPyObject(obValue, &var) ) return NULL; PY_INTERFACE_PRECALL; HRESULT hr = pIPB->Write(Name, &var); VariantClear(&var); PY_INTERFACE_POSTCALL; if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIPB, IID_IPropertyBag); Py_INCREF(Py_None); return Py_None; }
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; }
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; }
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 }
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 }
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; }
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"; } }
HRESULT STDMETHODCALLTYPE UIDelegate::exceededDatabaseQuota( /* [in] */ IWebView *sender, /* [in] */ IWebFrame *frame, /* [in] */ IWebSecurityOrigin *origin, /* [in] */ BSTR databaseIdentifier) { BSTR protocol; BSTR host; unsigned short port; origin->protocol(&protocol); origin->host(&host); origin->port(&port); if (!done && gTestRunner->dumpDatabaseCallbacks()) printf("UI DELEGATE DATABASE CALLBACK: exceededDatabaseQuotaForSecurityOrigin:{%S, %S, %i} database:%S\n", protocol, host, port, databaseIdentifier); SysFreeString(protocol); SysFreeString(host); unsigned long long defaultQuota = 5 * 1024 * 1024; double testDefaultQuota = gTestRunner->databaseDefaultQuota(); if (testDefaultQuota >= 0) defaultQuota = testDefaultQuota; COMPtr<IWebDatabaseManager> databaseManager; COMPtr<IWebDatabaseManager> tmpDatabaseManager; if (FAILED(WebKitCreateInstance(CLSID_WebDatabaseManager, 0, IID_IWebDatabaseManager, (void**)&tmpDatabaseManager))) { origin->setQuota(defaultQuota); return S_OK; } if (FAILED(tmpDatabaseManager->sharedWebDatabaseManager(&databaseManager))) { origin->setQuota(defaultQuota); return S_OK; } IPropertyBag* detailsBag; if (FAILED(databaseManager->detailsForDatabase(databaseIdentifier, origin, &detailsBag))) { origin->setQuota(defaultQuota); return S_OK; } VARIANT var; detailsBag->Read(WebDatabaseUsageKey, &var, 0); unsigned long long expectedSize = V_UI8(&var); unsigned long long newQuota = defaultQuota; double maxQuota = gTestRunner->databaseMaxQuota(); if (maxQuota >= 0) { if (defaultQuota < expectedSize && expectedSize <= maxQuota) { newQuota = expectedSize; printf("UI DELEGATE DATABASE CALLBACK: increased quota to %llu\n", newQuota); } } origin->setQuota(newQuota); return S_OK; }
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; }
//枚举设备 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; }
//连接音频设备,并将音频设备加入到 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; }
HRESULT CKTVDlg::EnumFiltersAndMonikersToList( IEnumMoniker *pEnumCat ) { HRESULT r=S_OK; IMoniker* pMoniker=0; ULONG cFetched=0; VARIANT varName={0}; int nFilters=0; // If there are no filters of a requested type, show default string if (!pEnumCat) { return S_FALSE; } // Enumerate all items associated with the moniker while(pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK) { IPropertyBag *pPropBag; ASSERT(pMoniker); // Associate moniker with a file r = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag); ASSERT(SUCCEEDED(r)); ASSERT(pPropBag); if (FAILED(r)) continue; // Read filter name from property bag varName.vt = VT_BSTR; r = pPropBag->Read(L"FriendlyName", &varName, 0); if (FAILED(r)) continue; // Get filter name (converting BSTR name to a CString) CString str(varName.bstrVal); SysFreeString(varName.bstrVal); nFilters++; TCaptureFilter filter = {str, pMoniker}; m_captureFilterVec.push_back(filter); // Cleanup interfaces SAFE_RELEASE(pPropBag); // Intentionally DO NOT release the pMoniker, since it is // stored in a listbox for later use } return r; }
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(); }
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; }
HRESULT UIDelegate::exceededDatabaseQuota(IWebView* sender, IWebFrame* frame, IWebSecurityOrigin* origin, BSTR databaseIdentifier) { _bstr_t protocol; _bstr_t host; unsigned short port; origin->protocol(&protocol.GetBSTR()); origin->host(&host.GetBSTR()); origin->port(&port); if (!done && gTestRunner->dumpDatabaseCallbacks()) printf("UI DELEGATE DATABASE CALLBACK: exceededDatabaseQuotaForSecurityOrigin:{%s, %s, %i} database:%S\n", static_cast<const char*>(protocol), static_cast<const char*>(host), port, databaseIdentifier); unsigned long long defaultQuota = 5 * 1024 * 1024; double testDefaultQuota = gTestRunner->databaseDefaultQuota(); if (testDefaultQuota >= 0) defaultQuota = testDefaultQuota; COMPtr<IWebDatabaseManager> databaseManager; COMPtr<IWebDatabaseManager> tmpDatabaseManager; if (FAILED(WebKitCreateInstance(CLSID_WebDatabaseManager, 0, IID_IWebDatabaseManager, (void**)&tmpDatabaseManager))) { origin->setQuota(defaultQuota); return S_OK; } if (FAILED(tmpDatabaseManager->sharedWebDatabaseManager(&databaseManager))) { origin->setQuota(defaultQuota); return S_OK; } IPropertyBag* detailsBag; if (FAILED(databaseManager->detailsForDatabase(databaseIdentifier, origin, &detailsBag))) { origin->setQuota(defaultQuota); return S_OK; } _variant_t var; detailsBag->Read(WebDatabaseUsageKey, &var.GetVARIANT(), nullptr); unsigned long long expectedSize = V_UI8(&var); unsigned long long newQuota = defaultQuota; double maxQuota = gTestRunner->databaseMaxQuota(); if (maxQuota >= 0) { if (defaultQuota < expectedSize && expectedSize <= maxQuota) { newQuota = expectedSize; printf("UI DELEGATE DATABASE CALLBACK: increased quota to %llu\n", newQuota); } } origin->setQuota(newQuota); return S_OK; }
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; }
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); }
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; }
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; }
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(); } }
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; }
HRESULT CSystemDeviceEnumerator::Enumerate(std::vector<CString>& vectorDevices, const IID clsidDeviceClass) { if(NULL == m_pSysDevEnum) return E_POINTER; m_Hr = m_pSysDevEnum->CreateClassEnumerator(clsidDeviceClass, &m_pEnumCat, 0); if(NULL == m_pEnumCat) return E_POINTER; if(S_OK == m_Hr) { ULONG cFetched; while(m_pEnumCat->Next(1, &m_pMoniker, &cFetched) == S_OK) { IPropertyBag *pPropBag; m_Hr = m_pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag); if (SUCCEEDED(m_Hr)) { // To retrieve the filter's friendly name, do the following VARIANT varName; VariantInit(&varName); m_Hr = pPropBag->Read(L"FriendlyName", &varName, 0); if (SUCCEEDED(m_Hr)) { char szName[128]; wcstombs(szName, varName.bstrVal, sizeof(szName)); if(std::find(vectorDevices.begin(), vectorDevices.end(), szName) == vectorDevices.end()) { //if(std::find(m_listDMOs.begin(), m_listDMOs.end(), szName) == m_listDMOs.end()) { vectorDevices.push_back(szName); } } } VariantClear(&varName); pPropBag->Release(); } m_pMoniker->Release(); } } return S_OK; }