I’ve adapted the code in the “PlayCap with frame grabber event” MBS example program to capture data from multiple cameras, basically by changing all of the various DirectShow properties to arrays and iterating through the setup for each camera. It works fine with one camera or with two different cameras, i.e. the built-in webcam and one of my external USB cams, but when I try to use two identical external webcams (same VID/PID), the second one unmounts (I hear the Windows descending tone sound) at the moment the call to DirectShowMonikerMBS.BindBaseFilter occurs after one of them has already been added to the system. It re-mounts a couple of seconds later, but that obviously doesn’t help me. I know that it’s this call that causes the un-mounting because it happens exactly when I single-step over it.
This is my “FindCaptureDevices” method where the problem occurs:
// Create an enumerator for the video capture devices dim devenum as new DirectShowEnumMonikerMBS(DirectShowEnumMonikerMBS.CLSID_VideoInputDeviceCategory) if devenum.Handle = 0 then MsgBox "No video capture device found." end if dim dev as DirectShowMonikerMBS = devenum.NextObject // Loop through devices, adding a DirectShowBaseFilterMBS for each device to our srcfilters array While dev <> nil // Bind Moniker to a filter object dim f as DirectShowBaseFilterMBS = dev.BindBaseFilter // ******* This is where the device unmounts srcfilters.AddRow f dev = devenum.NextObject Wend
and here’s the setup loop that calls it:
FindCaptureDevices // This loads the srcfilters array For CamNum as Integer = 0 to srcfilters.LastRowIndex // Create the filter graph graphs.AddRow new DirectShowGraphBuilderMBS // Create the capture graph builder Captures.AddRow new DirectShowCaptureGraphBuilderMBS // Obtain interfaces for media control and Video Window MC.AddRow Graphs(CamNum).MediaControl VideoWindows.AddRow Graphs(CamNum).VideoWindow 'MEE = Graph.MediaEventEx // Doesn't seem necessary? // Attach the filter graph to the capture graph Captures(CamNum).SetFiltergraph(Graphs(CamNum)) grabbers.AddRow new MyDirectShowSampleGrabberMBS grabberFilter = grabbers(CamNum).BaseFilter // Add Capture filter to our graph. Graphs(CamNum).AddFilter srcfilters(CamNum), "Video Capture" Graphs(CamNum).AddFilter grabberFilter, "Grabber" // Render the preview pin on the video capture filter Captures(CamNum).RenderStream(DirectShowPinMBS.PIN_CATEGORY_PREVIEW, Captures(CamNum).MEDIATYPE_Video, srcfilters(CamNum), grabberFilter) // Set video window style and position SetupVideoWindow(CamNum) // Start previewing video data MC(CamNum).Run if MC(CamNum).Lasterror = 1 then // not yet ready, try again MC(CamNum).Run end if // Visibility gets overridden by mc.Run, have to set it afterwards VideoWindows(CamNum).Visible = TabPanel1.SelectedPanelIndex = 1 Next
Any suggestions, @Christian_Schmitz ?