gpt4 book ai didi

c++ - IAMVideoProcAmp GetRange 仅在延迟后有效(C++)?

转载 作者:可可西里 更新时间:2023-11-01 10:33:54 25 4
gpt4 key购买 nike

我在尝试控制相机参数时遇到问题。这是设置亮度参数的函数(我正在扩展 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com