【发布时间】:2016-11-06 12:05:54
【问题描述】:
我在尝试控制相机参数时遇到问题。这是设置亮度参数的函数(我从Windows Media Foundation recording audio扩展代码):
HRESULT deviceInput::SetupCamera(UINT32 deviceID) {
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
IMFActivate* device = this->getDevice(deviceID);
if (device == NULL)
return E_FAIL;
IMFMediaSource* pCameraSource = NULL;
HRESULT hr = (m_devices[deviceID])->ActivateObject(IID_PPV_ARGS(&pCameraSource));
if (FAILED(hr)) {
wcout << "Could not activate object" << endl;
return hr;
}
IAMVideoProcAmp* spVideo = NULL;
hr = CoCreateInstance(__uuidof(IMFMediaSource) , NULL, CLSCTX_INPROC_SERVER, __uuidof(IAMVideoProcAmp),
reinterpret_cast<void**>(&spVideo));
hr = pCameraSource->QueryInterface(IID_PPV_ARGS(&spVideo));
if(FAILED(hr)) {
wcout << "Could not get interface" << endl;
return hr;
}
if(spVideo) {
wcout << "Getting brightness" << endl;
long Min, Max, step, def, control;
Sleep(100); // if I remove this - will get "Element not found error"
hr = spVideo->GetRange(VideoProcAmp_Brightness, &Min, &Max, &step, &def, &control);
if (SUCCEEDED(hr))
wcout << "Brightness. Min = " << Min <<", max = " << Max << endl;
else {
_com_error err(hr);
LPCTSTR errMsg = err.ErrorMessage();
wcout << "Failed: " << errMsg << endl;
}
}
CoUninitialize();
return hr;
}
似乎我需要在调用 GetRange() 方法之前插入一个暂停,否则我会收到“找不到元素”错误。 QueryInterface 工作正常,因为我正在检查 HRESULT 值,并且无论延迟如何,都会填充 spVideo。有谁知道如何在不插入任意延迟的情况下让它工作?
【问题讨论】:
-
我想您需要从此源开始视频捕获并更改活动设备上的参数。这应该确保后台的东西被正确初始化。
标签: c++ windows video-capture ms-media-foundation