bool set_property_pages_infos(const wchar_t* camera, const VideoProcAmpPropertyInfo videoProcAmpPropertyInfo, const CameraControlPropertyInfo cameraControlPropertyInfo)
{
CoInitialize(NULL);
bool ret = true;
HRESULT hr = S_OK;
if (camera == NULL || camera[0] == 0)
return false;
ATL::CComPtr<ICreateDevEnum> pSysDevEnum;
hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysDevEnum);
if (hr != S_OK) {
XLOG_ERROR("CoCreateInstance CLSID_SystemDeviceEnum.error = %d", hr);
return false;
}
ATL::CComPtr<IEnumMoniker> pEnumCat;
hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0);
if (hr != S_OK) {
XLOG_ERROR("CreateClassEnumerator CLSID_VideoInputDeviceCategory.error = %d", hr);
return false;
}
ATL::CComPtr<IBaseFilter> flter;
while (1)
{
ATL::CComPtr<IMoniker> pMoniker;
ULONG cFetched = 0;
hr = pEnumCat->Next(1, &pMoniker, &cFetched);
if (hr != S_OK || cFetched == 0)
break;
ATL::CComPtr<IPropertyBag> pPropBag;
hr = pMoniker->BindToStorage(NULL, 0, IID_IPropertyBag, (void **)&pPropBag);
if (hr == S_OK)
{
_variant_t varName;
hr = pPropBag->Read(L"FriendlyName", &varName, NULL);
if (hr == S_OK)
{
std::wstring str = varName.bstrVal;
if (str.compare(camera) == 0)
{
hr = pMoniker->BindToObject(NULL, 0, IID_IBaseFilter, (void**)&flter);
break;
}
}
}
}
if (flter == NULL)
return false;
CComPtr<IAMCameraControl> pSpec2;
CComPtr<IAMVideoProcAmp> pSpec;
CAUUID cauuid;
CComPtr<IAMCameraControl> pCameraControl;
hr = flter->QueryInterface(IID_IAMVideoProcAmp, (void **)&pSpec);
if (pSpec) {
//视频
hr = pSpec->Set(VideoProcAmp_Brightness, videoProcAmpPropertyInfo.VideoProcAmp_Brightness_Value, videoProcAmpPropertyInfo.VideoProcAmp_Brightness_Flag);
hr = pSpec->Set(VideoProcAmp_Contrast, videoProcAmpPropertyInfo.VideoProcAmp_Contrast_Value, videoProcAmpPropertyInfo.VideoProcAmp_Contrast_Flag);
hr = pSpec->Set(VideoProcAmp_Hue, videoProcAmpPropertyInfo.VideoProcAmp_Hue_Value, videoProcAmpPropertyInfo.VideoProcAmp_Hue_Flag);
hr = pSpec->Set(VideoProcAmp_Saturation, videoProcAmpPropertyInfo.VideoProcAmp_Saturation_Value, videoProcAmpPropertyInfo.VideoProcAmp_Saturation_Flag);
hr = pSpec->Set(VideoProcAmp_Sharpness, videoProcAmpPropertyInfo.VideoProcAmp_Sharpness_Value, videoProcAmpPropertyInfo.VideoProcAmp_Sharpness_Flag);
hr = pSpec->Set(VideoProcAmp_Gamma, videoProcAmpPropertyInfo.VideoProcAmp_Gamma_Value, videoProcAmpPropertyInfo.VideoProcAmp_Gamma_Flag);
hr = pSpec->Set(VideoProcAmp_ColorEnable, videoProcAmpPropertyInfo.VideoProcAmp_ColorEnable_Value, videoProcAmpPropertyInfo.VideoProcAmp_ColorEnable_Flag);
hr = pSpec->Set(VideoProcAmp_WhiteBalance, videoProcAmpPropertyInfo.VideoProcAmp_WhiteBalance_Value, videoProcAmpPropertyInfo.VideoProcAmp_WhiteBalance_Flag);
hr = pSpec->Set(VideoProcAmp_BacklightCompensation, videoProcAmpPropertyInfo.VideoProcAmp_BacklightCompensation_Value, videoProcAmpPropertyInfo.VideoProcAmp_BacklightCompensation_Flag);
hr = pSpec->Set(VideoProcAmp_Gain, videoProcAmpPropertyInfo.VideoProcAmp_Gain_Value, videoProcAmpPropertyInfo.VideoProcAmp_Gain_Flag);
}
hr = flter->QueryInterface(IID_IAMCameraControl, (void **)&pSpec2);
if (pSpec2) {
//相机
hr = pSpec2->Set(CameraControl_Pan, cameraControlPropertyInfo.CameraControl_Pan_Value, cameraControlPropertyInfo.CameraControl_Pan_Flag);
hr = pSpec2->Set(CameraControl_Tilt, cameraControlPropertyInfo.CameraControl_Tilt_Value, cameraControlPropertyInfo.CameraControl_Tilt_Flag);
hr = pSpec2->Set(CameraControl_Roll, cameraControlPropertyInfo.CameraControl_Roll_Value, cameraControlPropertyInfo.CameraControl_Roll_Flag);
hr = pSpec2->Set(CameraControl_Zoom, cameraControlPropertyInfo.CameraControl_Zoom_Value, cameraControlPropertyInfo.CameraControl_Zoom_Flag);
hr = pSpec2->Set(CameraControl_Exposure, cameraControlPropertyInfo.CameraControl_Exposure_Value, cameraControlPropertyInfo.CameraControl_Exposure_Flag);
hr = pSpec2->Set(CameraControl_Iris, cameraControlPropertyInfo.CameraControl_Iris_Value, cameraControlPropertyInfo.CameraControl_Iris_Flag);
hr = pSpec2->Set(CameraControl_Focus, cameraControlPropertyInfo.CameraControl_Focus_Value, cameraControlPropertyInfo.CameraControl_Focus_Flag);
}
CoUninitialize();
return ret;
}