1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
graphBuilder[i] = (IGraphBuilder)new FilterGraph();
//Add the Video input device to the graph
hr = graphBuilder[i].AddFilter(theDevice[0], "source filter");
smartTee = new SmartTee() as IBaseFilter;
hr = graphBuilder[i].AddFilter(smartTee, "SmartTee");
DsError.ThrowExceptionForHR(hr);
teeIn = DsFindPin.ByDirection(smartTee, PinDirection.Input, 0);
devCapture = DsFindPin.ByCategory(theDevice[0], PinCategory.Capture, 0);
hr = graphBuilder[i].Connect(devCapture, teeIn);
DsError.ThrowExceptionForHR(hr);
IBaseFilter renderer = new VideoRendererDefault() as IBaseFilter;
hr = graphBuilder[i].AddFilter(renderer, "Renderer");
DsError.ThrowExceptionForHR(hr);
teeOut = DsFindPin.ByDirection(smartTee, PinDirection.Output, 0);
rendererIn = DsFindPin.ByDirection(renderer, PinDirection.Input, 0);
hr = graphBuilder[i].Connect(teeOut, rendererIn);
DsError.ThrowExceptionForHR(hr);
IVideoWindow videoWindow = null;
videoWindow = (IVideoWindow)graphBuilder[i];
Panel pan = null;
if (i == 0)
{
pan = this.panel1;
}
else
{
pan = this.panel2;
}
//Set the owener of the videoWindow to an IntPtr of some sort (the Handle of any control - could be a form / button etc.)
hr = videoWindow.put_Owner(pan.Handle);
DsError.ThrowExceptionForHR(hr);
//Set the style of the video window
hr = videoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren);
DsError.ThrowExceptionForHR(hr);
// Position video window in client rect of main application window
hr = videoWindow.SetWindowPosition(0, 0,pan.Width, pan.Height);
DsError.ThrowExceptionForHR(hr);
// Make the video window visible
hr = videoWindow.put_Visible(OABool.True);
DsError.ThrowExceptionForHR(hr); |