capDlgVideoSource problems with multiple webcams
I have two different webcams connected to my PC, but I have problems choosing them when running the following code. I included all the initialization routine and the last line with capDlgVideoSource call is causing only the one webcam's videosource dialog to appear instead of a list where I can choose between them. OS is WinXP SP3
//Create invisible window to hold the capture window.
hwnd = CreateWindowEx(0, _T("webcampcapwindow"), _T(""), 0, 0, 0, 1, 1, HWND_DESKTOP, NULL, GetModuleHandle(NULL), NULL);
if( !hwnd )
throw FatalException( _T("main Capture window create failed"), _T(__FILE__), __LINE__ );
//Create capture window.
capHwnd = capCreateCaptureWindow(_T("webcampcapwindowchild"), WS_CHILD, 0, 0, 1, 1, hwnd, 1);
if( !capHwnd )
throw FatalException( _T("secondary Capture window create failed"), _T(__FILE__), __LINE__ );
CAPDRIVERCAPS caps;
if(capDriverConnect(capHwnd, 0)) {
connectedtoWc = true;
break;
}
if ( !connectedtoWc )
throw FatalException( _T("Could not connect to capture driver."), _T(__FILE__), __LINE__ );
//Attach our callback to the capture window.
if( !capSetCallbackOnVideoStream(capHwnd, videoCallback))
throw FatalException( _T("Unable to Attach our callback to the capture window."), _T(__FILE__), __LINE__ );
//Make sure we can access this object from the callback.
if(!capSetUserData(capHwnd, this))
throw FatalException( _T("Could not associate user data with capture."), _T(__FILE__), __LINE__ );
//Check everything'开发者_如何学Gos initialised.
caps.fCaptureInitialized = false;
if( !capDriverGetCaps(capHwnd, &caps, sizeof(CAPDRIVERCAPS)))
throw FatalException( _T("Unable to get driver caps"), _T(__FILE__), __LINE__ );
if(!caps.fCaptureInitialized)
throw FatalException( _T("Unable to initialize capture driver"), _T(__FILE__), __LINE__ );
if (caps.fHasDlgVideoSource)
capDlgVideoSource(capHwnd);
What do I change so I can get to select the webcam in video source dialog? Currently it shows the second webcam properties.
It's a bit unclear from your question, and I'm no expert, but it would appear you're using VfW, which many camera drivers don't support anymore.
Support is built in using a WDM backwards compatibility driver, which doesn't seem to work very well. The only solution I've seen to this problem is to perform some registry gymnastics (set DevicePath
in HKLM\SYSTEM\CurrentControlSet\Control\MediaResources\msvideo\MSVideo.VFWWDM
to the desired device), but this is a bit over my head - I'm a hardware guy.
精彩评论