Click here to Skip to main content
15,861,168 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi,

I have below code to capture and preview using GMFPreview bridge. Its working fine. Now i need to add sample Grabber filter so that i can capture image parallel without any glitch using SetMode function. Please let me know how to add sample grabber filter in this block.

I tried a lot but not able to achieve. Please help as i am new to this.

C#
// Specify a device, and a window to draw the preview in
   public void
   SelectDevice(DsDevice dev, IntPtr hwnd)
   {
       int hr;
       IBaseFilter pfDevice = null;
       ICaptureGraphBuilder2 pBuilder = null;

       try
       {
           // create source graph and add sink filter
           m_pSourceGraph = (IGraphBuilder)new FilterGraph();
           m_rot1 = new DsROTEntry(m_pSourceGraph);

           m_pBridge = (IGMFBridgeController)new GMFBridgeController();

           // init to video-only, in discard mode (ie when source graph
           // is running but not connected, buffers are discarded at the bridge)
           hr = m_pBridge.AddStream(true, eFormatType.MuxInputs, true);
           DsError.ThrowExceptionForHR(hr);

           // Add the requested device
           hr = ((IFilterGraph2)m_pSourceGraph).AddSourceFilterForMoniker(dev.Mon, null, dev.Name, out pfDevice);
           DsError.ThrowExceptionForHR(hr);


           // Add the sink filter to the source graph
           hr = m_pBridge.InsertSinkFilter(m_pSourceGraph, out m_pSourceGraphSinkFilter);
           DsError.ThrowExceptionForHR(hr);

           // use capture graph builder to render preview
           pBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();

           // Init the CaptureGraphBuilder2
           hr = pBuilder.SetFiltergraph(m_pSourceGraph);
           DsError.ThrowExceptionForHR(hr);

           // Connect the filters together to allow preview
           hr = pBuilder.RenderStream(PinCategory.Preview, MediaType.Video, pfDevice, null, null);
           DsError.ThrowExceptionForHR(hr);

           // connect capture output to the pseudo-sink filter,
           // where it will be discarded until required
           hr = pBuilder.RenderStream(PinCategory.Capture, MediaType.Video, pfDevice, null, m_pSourceGraphSinkFilter);
           DsError.ThrowExceptionForHR(hr);


           // turn off capture stream if possible except when capturing
           hr = pBuilder.FindPin(pfDevice, PinDirection.Output, PinCategory.Capture, MediaType.Video, false, 0, out m_pCapOutput);
           if (hr >= 0)
           {
               IAMStreamControl pSC = (IAMStreamControl)m_pCapOutput;
               pSC.StartAt(NEVER, 0);  // Ignore any error
           }


           ConfigureVideo(hwnd);

           IMediaControl pMC = (IMediaControl)m_pSourceGraph;

           hr = pMC.Run();
           DsError.ThrowExceptionForHR(hr);

           // If we made it here, the device is selected
           m_DeviceSelected = true;
       }
       catch
       {
           ReleaseSelectMembers();
           throw;
       }
       finally
       {
           if (pBuilder != null)
           {
               Marshal.ReleaseComObject(pBuilder);
           }

           if (pfDevice != null)
           {
               Marshal.ReleaseComObject(pfDevice);
           }

           Saved_m_pSourceGraph = m_pSourceGraph;
       }
   }
Posted

1 solution

C#
m_sampleGrabber = (ISampleGrabber)new SampleGrabber();                   
SetupSampleGrabber(m_sampleGrabber);
hr = m_pSourceGraph.AddFilter(m_sampleGrabber as IBaseFilter, "SampleGrabber");
DsError.ThrowExceptionForHR(hr);


Something like that
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900