Esempio n. 1
0
        protected void createGraph()
        {
            System.Type typeFromCLSID = null;
            object      obj2          = null;

            if (this.graphState < GraphState.Created)
            {
                GC.Collect();
                this.graphBuilder = (IGraphBuilder)Activator.CreateInstance(System.Type.GetTypeFromCLSID(Clsid.FilterGraph, true));
                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;
                AMMediaType pmt = new AMMediaType();
                pmt.majorType  = MediaType.Video;
                pmt.subType    = MediaSubType.RGB24;
                pmt.formatType = FormatType.VideoInfo;
                int errorCode = this.sampGrabber.SetMediaType(pmt);
                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);
                }
                Guid capture     = PinCategory.Capture;
                Guid interleaved = MediaType.Interleaved;
                Guid gUID        = typeof(IAMStreamConfig).GUID;
                if (errorCode != 0)
                {
                    Guid video = MediaType.Video;
                }
                object obj3  = null;
                Guid   guid5 = PinCategory.Capture;
                Guid   audio = MediaType.Audio;
                Guid   guid7 = typeof(IAMStreamConfig).GUID;
                this.audioStreamConfig = obj3 as IAMStreamConfig;
                this.mediaControl      = (IMediaControl)this.graphBuilder;
                this.videoCaps         = null;
                this.audioCaps         = null;
                obj3 = null;
                Guid guid8  = PinCategory.Capture;
                Guid guid9  = MediaType.Interleaved;
                Guid guid10 = typeof(IAMTVTuner).GUID;
                this.graphState = GraphState.Created;
            }
        }
Esempio n. 2
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;
            }
        }