コード例 #1
0
ファイル: Capture.cs プロジェクト: alienwow/CSharpProjects
 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.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.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();
 }
コード例 #2
0
ファイル: Capture.cs プロジェクト: alienwow/CSharpProjects
 protected void createGraph()
 {
     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 obj2;
         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);
         int errorCode = this.captureGraphBuilder.SetFiltergraph(this.graphBuilder);
         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);
             }
         }
         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 obj2) != 0)
         {
             interleaved = MediaType.Video;
             if (this.captureGraphBuilder.FindInterface(ref capture, ref interleaved, this.videoDeviceFilter, ref riid, out obj2) != 0)
             {
                 obj2 = null;
             }
         }
         this.videoStreamConfig = obj2 as IAMStreamConfig;
         obj2 = null;
         capture = PinCategory.Capture;
         interleaved = MediaType.Audio;
         riid = typeof(IAMStreamConfig).GUID;
         if (this.captureGraphBuilder.FindInterface(ref capture, ref interleaved, this.audioDeviceFilter, ref riid, out obj2) != 0)
         {
             obj2 = null;
         }
         this.audioStreamConfig = obj2 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;
         obj2 = null;
         capture = PinCategory.Capture;
         interleaved = MediaType.Interleaved;
         riid = typeof(IAMTVTuner).GUID;
         if (this.captureGraphBuilder.FindInterface(ref capture, ref interleaved, this.videoDeviceFilter, ref riid, out obj2) != 0)
         {
             interleaved = MediaType.Video;
             if (this.captureGraphBuilder.FindInterface(ref capture, ref interleaved, this.videoDeviceFilter, ref riid, out obj2) != 0)
             {
                 obj2 = null;
             }
         }
         IAMTVTuner tuner = obj2 as IAMTVTuner;
         if (tuner != null)
         {
             this.tuner = new DirectX.Capture.Tuner(tuner);
         }
         this.graphState = GraphState.Created;
     }
 }