Exemplo n.º 1
0
 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();
 }
Exemplo n.º 2
0
        protected void addFromGraph(ICaptureGraphBuilder2 graphBuilder, IBaseFilter videoDeviceFilter, IBaseFilter audioDeviceFilter, IBaseFilter videoCompressorFilter, IBaseFilter audioCompressorFilter, SourceCollection videoSources, SourceCollection audioSources)
        {
            object ppint = null;

            Trace.Assert(graphBuilder != null);
            this.addIfSupported(videoDeviceFilter, "Video Capture Device");
            Guid capture     = PinCategory.Capture;
            Guid interleaved = MediaType.Interleaved;
            Guid gUID        = typeof(IAMStreamConfig).GUID;

            if (graphBuilder.FindInterface(ref capture, ref interleaved, videoDeviceFilter, ref gUID, out ppint) != 0)
            {
                interleaved = MediaType.Video;
                if (graphBuilder.FindInterface(ref capture, ref interleaved, videoDeviceFilter, ref gUID, out ppint) != 0)
                {
                    ppint = null;
                }
            }
            this.addIfSupported(ppint, "Video Capture Pin");
            capture     = PinCategory.Preview;
            interleaved = MediaType.Interleaved;
            gUID        = typeof(IAMStreamConfig).GUID;
            if (graphBuilder.FindInterface(ref capture, ref interleaved, videoDeviceFilter, ref gUID, out ppint) != 0)
            {
                interleaved = MediaType.Video;
                if (graphBuilder.FindInterface(ref capture, ref interleaved, videoDeviceFilter, ref gUID, out ppint) != 0)
                {
                    ppint = null;
                }
            }
            this.addIfSupported(ppint, "Video Preview Pin");
            ArrayList list = new ArrayList();
            int       num  = 1;

            for (int i = 0; i < videoSources.Count; i++)
            {
                CrossbarSource source = videoSources[i] as CrossbarSource;
                if ((source != null) && (list.IndexOf(source.Crossbar) < 0))
                {
                    list.Add(source.Crossbar);
                    if (this.addIfSupported(source.Crossbar, "Video Crossbar " + ((num == 1) ? "" : num.ToString())))
                    {
                        num++;
                    }
                }
            }
            list.Clear();
            this.addIfSupported(videoCompressorFilter, "Video Compressor");
            capture     = PinCategory.Capture;
            interleaved = MediaType.Interleaved;
            gUID        = typeof(IAMTVTuner).GUID;
            if (graphBuilder.FindInterface(ref capture, ref interleaved, videoDeviceFilter, ref gUID, out ppint) != 0)
            {
                interleaved = MediaType.Video;
                if (graphBuilder.FindInterface(ref capture, ref interleaved, videoDeviceFilter, ref gUID, out ppint) != 0)
                {
                    ppint = null;
                }
            }
            this.addIfSupported(ppint, "TV Tuner");
            IAMVfwCompressDialogs compressDialogs = videoCompressorFilter as IAMVfwCompressDialogs;

            if (compressDialogs != null)
            {
                VfwCompressorPropertyPage page = new VfwCompressorPropertyPage("Video Compressor", compressDialogs);
                base.InnerList.Add(page);
            }
            this.addIfSupported(audioDeviceFilter, "Audio Capture Device");
            capture     = PinCategory.Capture;
            interleaved = MediaType.Audio;
            gUID        = typeof(IAMStreamConfig).GUID;
            if (graphBuilder.FindInterface(ref capture, ref interleaved, audioDeviceFilter, ref gUID, out ppint) != 0)
            {
                ppint = null;
            }
            this.addIfSupported(ppint, "Audio Capture Pin");
            capture     = PinCategory.Preview;
            interleaved = MediaType.Audio;
            gUID        = typeof(IAMStreamConfig).GUID;
            if (graphBuilder.FindInterface(ref capture, ref interleaved, audioDeviceFilter, ref gUID, out ppint) != 0)
            {
                ppint = null;
            }
            this.addIfSupported(ppint, "Audio Preview Pin");
            num = 1;
            for (int j = 0; j < audioSources.Count; j++)
            {
                CrossbarSource source2 = audioSources[j] as CrossbarSource;
                if ((source2 != null) && (list.IndexOf(source2.Crossbar) < 0))
                {
                    list.Add(source2.Crossbar);
                    if (this.addIfSupported(source2.Crossbar, "Audio Crossbar " + ((num == 1) ? "" : num.ToString())))
                    {
                        num++;
                    }
                }
            }
            list.Clear();
            this.addIfSupported(audioCompressorFilter, "Audio Compressor");
        }
Exemplo n.º 3
0
        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;
            }
        }
Exemplo n.º 4
0
 internal PropertyPageCollection(ICaptureGraphBuilder2 graphBuilder, IBaseFilter videoDeviceFilter, IBaseFilter audioDeviceFilter, IBaseFilter videoCompressorFilter, IBaseFilter audioCompressorFilter, SourceCollection videoSources, SourceCollection audioSources)
 {
     this.addFromGraph(graphBuilder, videoDeviceFilter, audioDeviceFilter, videoCompressorFilter, audioCompressorFilter, videoSources, audioSources);
 }