- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在尝试控制相机参数时遇到问题。这是设置亮度参数的函数(我正在扩展 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 都会被填充。有谁知道如何在不插入任意延迟的情况下让它工作?
最佳答案
您描述了众所周知的问题。事实上,在执行激活系统后,需要时间来初始化相机驱动程序。这需要时间。如果你真的想删除 Sleep
功能,那么你应该通过 DeviceIoControl
调用相机属性在 MSDN 上 USB Video Class Properties您会发现下一个文本“调用 KsSynchronousDeviceControl 或 DeviceIoControl 以从用户模式组件发出属性请求。DeviceIoControl 记录在 Microsoft Windows SDK 文档中。”顺便说一下,对于 DeviceIoControl
的使用,它不需要激活 MediaSource。 DeviceIoControl
函数只需要相机的符号链接(symbolic link)。然而,编写直接使用驱动程序的代码可能非常困难(我在一个 C++ 类中编写了它)。
关于c++ - IAMVideoProcAmp GetRange 仅在延迟后有效(C++)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38190107/
我正在使用 DirectShow api 从网络摄像头捕获视频,我正在使用 IAMVideoProcAmp 接口(interface)(例如 VideoProcAmp_WhiteBalance)设置各
我在尝试控制相机参数时遇到问题。这是设置亮度参数的函数(我正在扩展 Windows Media Foundation recording audio 的代码): HRESULT deviceInput
我是一名优秀的程序员,十分优秀!