protected void destroyGraph() { try { this.derenderGraph(); } catch { } this.graphState = GraphState.Null; this.isCaptureRendered = false; this.isPreviewRendered = false; if (this.rotCookie != 0) { DsROT.RemoveGraphFromRot(ref this.rotCookie); this.rotCookie = 0; } if (this.muxFilter != null) { this.graphBuilder.RemoveFilter(this.muxFilter); } if (this.baseGrabFlt != null) { this.graphBuilder.RemoveFilter(this.baseGrabFlt); } if (this.videoCompressorFilter != null) { this.graphBuilder.RemoveFilter(this.videoCompressorFilter); } if (this.audioCompressorFilter != null) { this.graphBuilder.RemoveFilter(this.audioCompressorFilter); } if (this.videoDeviceFilter != null) { this.graphBuilder.RemoveFilter(this.videoDeviceFilter); } if (this.audioDeviceFilter != null) { this.graphBuilder.RemoveFilter(this.audioDeviceFilter); } if (this.videoSources != null) { this.videoSources.Dispose(); } this.videoSources = null; if (this.audioSources != null) { this.audioSources.Dispose(); } this.audioSources = null; if (this.propertyPages != null) { this.propertyPages.Dispose(); } this.propertyPages = null; if (this.tuner != null) { this.tuner.Dispose(); } this.tuner = null; if (this.graphBuilder != null) { Marshal.ReleaseComObject(this.graphBuilder); } this.graphBuilder = null; if (this.captureGraphBuilder != null) { Marshal.ReleaseComObject(this.captureGraphBuilder); } this.captureGraphBuilder = null; if (this.muxFilter != null) { Marshal.ReleaseComObject(this.muxFilter); } this.muxFilter = null; if (this.baseGrabFlt != null) { Marshal.ReleaseComObject(this.baseGrabFlt); } this.baseGrabFlt = null; if (this.fileWriterFilter != null) { Marshal.ReleaseComObject(this.fileWriterFilter); } this.fileWriterFilter = null; if (this.videoDeviceFilter != null) { Marshal.ReleaseComObject(this.videoDeviceFilter); } this.videoDeviceFilter = null; if (this.audioDeviceFilter != null) { Marshal.ReleaseComObject(this.audioDeviceFilter); } this.audioDeviceFilter = null; if (this.videoCompressorFilter != null) { Marshal.ReleaseComObject(this.videoCompressorFilter); } this.videoCompressorFilter = null; if (this.audioCompressorFilter != null) { Marshal.ReleaseComObject(this.audioCompressorFilter); } this.audioCompressorFilter = null; this.mediaControl = null; this.videoWindow = null; GC.Collect(); }
protected void createGraph() { System.Type typeFromCLSID = null; object obj2 = null; if ((this.videoDevice == null) && (this.audioDevice == null)) { throw new ArgumentException("The video and/or audio device have not been set. Please set one or both to valid capture devices.\n"); } if (this.graphState < GraphState.Created) { object obj3; GC.Collect(); this.graphBuilder = (IGraphBuilder)Activator.CreateInstance(System.Type.GetTypeFromCLSID(Clsid.FilterGraph, true)); Guid clsid = Clsid.CaptureGraphBuilder2; Guid gUID = typeof(ICaptureGraphBuilder2).GUID; this.captureGraphBuilder = (ICaptureGraphBuilder2)DsBugWO.CreateDsInstance(ref clsid, ref gUID); typeFromCLSID = System.Type.GetTypeFromCLSID(Clsid.SampleGrabber, true); if (typeFromCLSID == null) { throw new NotImplementedException("DirectShow SampleGrabber not installed/registered"); } obj2 = Activator.CreateInstance(typeFromCLSID); this.sampGrabber = (ISampleGrabber)obj2; obj2 = null; int errorCode = this.captureGraphBuilder.SetFiltergraph(this.graphBuilder); if (errorCode < 0) { Marshal.ThrowExceptionForHR(errorCode); } AMMediaType pmt = new AMMediaType(); pmt.majorType = MediaType.Video; pmt.subType = MediaSubType.RGB24; pmt.formatType = FormatType.VideoInfo; errorCode = this.sampGrabber.SetMediaType(pmt); if (errorCode < 0) { Marshal.ThrowExceptionForHR(errorCode); } if (this.VideoDevice != null) { this.videoDeviceFilter = (IBaseFilter)Marshal.BindToMoniker(this.VideoDevice.MonikerString); errorCode = this.graphBuilder.AddFilter(this.videoDeviceFilter, "Video Capture Device"); if (errorCode < 0) { Marshal.ThrowExceptionForHR(errorCode); } this.mediaEvt = (IMediaEventEx)this.graphBuilder; this.baseGrabFlt = (IBaseFilter)this.sampGrabber; errorCode = this.graphBuilder.AddFilter(this.baseGrabFlt, "DS.NET Grabber"); if (errorCode < 0) { Marshal.ThrowExceptionForHR(errorCode); } } if (this.AudioDevice != null) { this.audioDeviceFilter = (IBaseFilter)Marshal.BindToMoniker(this.AudioDevice.MonikerString); errorCode = this.graphBuilder.AddFilter(this.audioDeviceFilter, "Audio Capture Device"); if (errorCode < 0) { Marshal.ThrowExceptionForHR(errorCode); } } if (this.VideoCompressor != null) { this.videoCompressorFilter = (IBaseFilter)Marshal.BindToMoniker(this.VideoCompressor.MonikerString); errorCode = this.graphBuilder.AddFilter(this.videoCompressorFilter, "Video Compressor"); if (errorCode < 0) { Marshal.ThrowExceptionForHR(errorCode); } } if (this.AudioCompressor != null) { this.audioCompressorFilter = (IBaseFilter)Marshal.BindToMoniker(this.AudioCompressor.MonikerString); errorCode = this.graphBuilder.AddFilter(this.audioCompressorFilter, "Audio Compressor"); if (errorCode < 0) { Marshal.ThrowExceptionForHR(errorCode); } } Guid capture = PinCategory.Capture; Guid interleaved = MediaType.Interleaved; Guid riid = typeof(IAMStreamConfig).GUID; if (this.captureGraphBuilder.FindInterface(ref capture, ref interleaved, this.videoDeviceFilter, ref riid, out obj3) != 0) { interleaved = MediaType.Video; if (this.captureGraphBuilder.FindInterface(ref capture, ref interleaved, this.videoDeviceFilter, ref riid, out obj3) != 0) { obj3 = null; } } this.videoStreamConfig = obj3 as IAMStreamConfig; obj3 = null; capture = PinCategory.Capture; interleaved = MediaType.Audio; riid = typeof(IAMStreamConfig).GUID; if (this.captureGraphBuilder.FindInterface(ref capture, ref interleaved, this.audioDeviceFilter, ref riid, out obj3) != 0) { obj3 = null; } this.audioStreamConfig = obj3 as IAMStreamConfig; this.mediaControl = (IMediaControl)this.graphBuilder; if (this.videoSources != null) { this.videoSources.Dispose(); } this.videoSources = null; if (this.audioSources != null) { this.audioSources.Dispose(); } this.audioSources = null; if (this.propertyPages != null) { this.propertyPages.Dispose(); } this.propertyPages = null; this.videoCaps = null; this.audioCaps = null; obj3 = null; capture = PinCategory.Capture; interleaved = MediaType.Interleaved; riid = typeof(IAMTVTuner).GUID; if (this.captureGraphBuilder.FindInterface(ref capture, ref interleaved, this.videoDeviceFilter, ref riid, out obj3) != 0) { interleaved = MediaType.Video; if (this.captureGraphBuilder.FindInterface(ref capture, ref interleaved, this.videoDeviceFilter, ref riid, out obj3) != 0) { obj3 = null; } } IAMTVTuner tuner = obj3 as IAMTVTuner; if (tuner != null) { this.tuner = new Tuner(tuner); } this.graphState = GraphState.Created; } }