public void Cleanup() { if (Device != null) { Device.Dispose(); Device = null; } if (stillSampleGrabber != null) { Marshal.ReleaseComObject(stillSampleGrabber); stillSampleGrabber = null; } if (captureSG != null) { Marshal.ReleaseComObject(captureSG); stillSampleGrabber = null; } if (pRenderIn != null) { Marshal.ReleaseComObject(pRenderIn); pRenderIn = null; } if (pStillSampleIn != null) { Marshal.ReleaseComObject(pStillSampleIn); pStillSampleIn = null; } if (pCaptureSampleIn != null) { Marshal.ReleaseComObject(pCaptureSampleIn); pCaptureSampleIn = null; } }
private void Form1_FormClosed(object sender, FormClosedEventArgs e) { // Release pointers if (m_dev != null) { m_dev.Dispose(); m_dev = null; } if (m_Previewer != null) { m_Previewer.Dispose(); m_Previewer = null; } }
public static BaseFilterEx GetFilter_Capture(int index) { var devices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice); if (devices.Count() > index) { DsDevice device = devices[index]; Guid guidBaseFilter = typeof(IBaseFilter).GUID; object resultObj = null; device.Mon.BindToObject(null, null, ref guidBaseFilter, out resultObj); device.Dispose(); var baseFilter = resultObj as IBaseFilter; if (baseFilter != null) { return(new BaseFilterEx((IBaseFilter)resultObj, "Capture:" + (index + 1).ToString())); } else { return(null); } } return(null); }
/// <summary> do cleanup and release DirectShow. </summary> void CloseInterfaces() { int hr; #if DEBUG if (rotCookie != 0) { DsROT.RemoveGraphFromRot(ref rotCookie); } #endif if (mediaCtrl != null) { hr = mediaCtrl.Stop(); Marshal.ReleaseComObject(mediaCtrl); mediaCtrl = null; } if (mediaEvt != null) { Marshal.ReleaseComObject(mediaEvt); mediaEvt = null; } if (baseGrabFlt != null) { Marshal.ReleaseComObject(baseGrabFlt); baseGrabFlt = null; } if (sampleGrabber != null) { Marshal.ReleaseComObject(sampleGrabber); sampleGrabber = null; } if (grabberConfig != null) { Marshal.ReleaseComObject(grabberConfig); grabberConfig = null; } if (capGraph != null) { Marshal.ReleaseComObject(capGraph); capGraph = null; } if (graphBuilder != null) { Marshal.ReleaseComObject(graphBuilder); graphBuilder = null; } if (dev != null) { dev.Dispose(); dev = null; } if (wmVideoDecoder != null) { Marshal.ReleaseComObject(wmVideoDecoder); wmVideoDecoder = null; } if (capFilter != null) { Marshal.ReleaseComObject(capFilter); capFilter = null; } if (capDevices != null) { foreach (DsDevice d in capDevices) { d.Dispose(); } capDevices = null; } if (atiCrossbar != null) { Marshal.ReleaseComObject(atiCrossbar); atiCrossbar = null; } if (motionVector != null) { Marshal.ReleaseComObject(motionVector); motionVector = null; } if (teeSplitter != null) { Marshal.ReleaseComObject(teeSplitter); teeSplitter = null; } if (videoRenderer != null) { Marshal.ReleaseComObject(videoRenderer); videoRenderer = null; } if (vectorGrabber != null) { //vectorGrabber.SetCallback(null); // FIXME: sometimes, this causes an exception Marshal.ReleaseComObject(vectorGrabber); vectorGrabber = null; } if (crossBar != null) { Marshal.ReleaseComObject(crossBar); crossBar = null; } }