【问题标题】:IAMVideoProcAmp GetRange only works after delay (C++)?IAMVideoProcAmp GetRange 仅在延迟后有效(C++)?
【发布时间】: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


【解决方案1】:

您描述了众所周知的问题。事实上,执行激活系统后需要时间来初始化相机驱动程序。它需要时间。如果您真的想删除Sleep 功能,那么您应该通过DeviceIoControl 调用相机属性 在 MSDN USB Video Class Properties 上,您可以找到下一个文本“调用 KsSynchronousDeviceControl 或 DeviceIoControl 以从用户模式组件发出属性请求。Microsoft Windows SDK 文档中记录了 DeviceIoControl。” 顺便说一句,对于DeviceIoControl 的使用,它不需要激活 MediaSource。 DeviceIoControl 函数只需要相机的符号链接。但是,为直接使用驱动程序编写代码可能非常困难(我在一个 C++ 类中编写了它)。

【讨论】:

  • Evgeny,感谢您的回答。因此,无法从 MediaFoundation 类中检查驱动程序是否准备就绪(可能是某种阻塞调用?)。
  • 没有。无法通过MediaFoundation 处理相机属性。仅通过IAMVideoProcAmp DirectShow 或DeviceIoControl。相机是一种硬件设备 - 这意味着要使用它,您需要使用与在 Windows 上使用任何设备(例如硬盘)相同的代码 - DeviceIoControl
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多