Пример #1
0
        /// <summary> create the used COM components and get the interfaces. </summary>
        bool GetInterfaces()
        {
            Type   comType = null;
            object comObj  = null;

            try
            {
                graphBuilder = (IGraphBuilder)DsDev.CreateFromCLSID(Clsid.FilterGraph);
                mediaEvt     = (IMediaEvent)graphBuilder;
                AssignTaskToWaitForCompletion(mediaEvt);

                Guid clsid = Clsid.CaptureGraphBuilder2;
                Guid riid  = typeof(ICaptureGraphBuilder2).GUID;
                capGraph = (ICaptureGraphBuilder2)DsBugWO.CreateDsInstance(ref clsid, ref riid);

                if (atiTVCardFound)
                {
                    wmVideoDecoder = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.AVI_Decompressor);
                }

                stretchVideo   = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.Stretch_Video);
                colorConverter = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.ColorSpaceConverter);
                modFrameRate   = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.ModifyFrameRate);

                motionVector = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.MotionVector);
                // Vector Grabber
                vectorGrabber = (IVectorGrabber)DsDev.CreateFromCLSID(Clsid.FlowVectorGrabber);

                sampleGrabber = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.SampleGrabber);
                grabberConfig = sampleGrabber as ISampleGrabber;

                mediaCtrl = (IMediaControl)graphBuilder;

                if (videoPreview)
                {
                    teeSplitter   = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.SmartTee);      //.CreateFromMoniker(TeeSplitter);
                    videoRenderer = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.VideoRenderer); // (Clsid.VMR9);
                }

                // Attemp to use VMR9 abandoned for now
                //vmrAllocator = (IVMRSurfaceAllocator9)DsDev.CreateFromCLSID(Clsid.VMR9Allocator);
                baseGrabFlt = (IBaseFilter)vectorGrabber;
                return(true);
            }
            catch (Exception ee)
            {
                LogInfo(LogGroups.Console, "Could not get interfaces\r\n" + ee.Message);
                return(false);
            }
            finally
            {
                if (comObj != null)
                {
                    Marshal.ReleaseComObject(comObj);
                }
                comObj = null;
            }
        }
Пример #2
0
        /// <summary>
        /// create the used COM components and get the interfaces.
        /// </summary>
        private void GetInterfaces()
        {
            Type   comType = null;
            object comObj  = null;
            String errMsg  = "";

            try
            {
                comType = Type.GetTypeFromCLSID(Clsid.FilterGraph);
                if (comType == null)
                {
                    throw new NotImplementedException(@"DirectShow FilterGraph not installed/registered!");
                }
                comObj       = Activator.CreateInstance(comType);
                graphBuilder = (IGraphBuilder)comObj; comObj = null;

                Guid clsid = Clsid.CaptureGraphBuilder2;
                Guid riid  = typeof(ICaptureGraphBuilder2).GUID;
                comObj   = DsBugWO.CreateDsInstance(ref clsid, ref riid);
                capGraph = (ICaptureGraphBuilder2)comObj; comObj = null;

                comType = Type.GetTypeFromCLSID(Clsid.SampleGrabber);
                if (comType == null)
                {
                    throw new NotImplementedException(@"DirectShow SampleGrabber not installed/registered!");
                }
                comObj      = Activator.CreateInstance(comType);
                sampGrabber = (ISampleGrabber)comObj; comObj = null;

                mediaCtrl   = (IMediaControl)graphBuilder;
                mediaEvt    = (IMediaEventEx)graphBuilder;
                baseGrabFlt = (IBaseFilter)sampGrabber;
            }
            catch (Exception ee)
            {
                errMsg = "Could not get interfaces\r\n" + ee.Message;
            }
            finally
            {
                if (comObj != null)
                {
                    Marshal.ReleaseComObject(comObj);
                }
                comObj = null;
            }

            if (errMsg.Length > 0)
            {
                throw new GoblinException(errMsg);
            }
        }
Пример #3
0
        /// <summary> create the used COM components and get the interfaces. </summary>
        bool GetInterfaces()
        {
            Type   comType = null;
            object comObj  = null;

            try
            {
                comType = Type.GetTypeFromCLSID(Clsid.FilterGraph);
                if (comType == null)
                {
                    throw new NotImplementedException(@"DirectShow FilterGraph not installed/registered!");
                }
                comObj       = Activator.CreateInstance(comType);
                graphBuilder = (IGraphBuilder)comObj; comObj = null;

                Guid clsid = Clsid.CaptureGraphBuilder2;
                Guid riid  = typeof(ICaptureGraphBuilder2).GUID;
                comObj   = DsBugWO.CreateDsInstance(ref clsid, ref riid);
                capGraph = (ICaptureGraphBuilder2)comObj; comObj = null;

                comType = Type.GetTypeFromCLSID(Clsid.SampleGrabber);
                if (comType == null)
                {
                    throw new NotImplementedException(@"DirectShow SampleGrabber not installed/registered!");
                }
                comObj      = Activator.CreateInstance(comType);
                sampGrabber = (ISampleGrabber)comObj; comObj = null;

                baseGrabFlt = (IBaseFilter)sampGrabber;

                mediaCtrl = (IMediaControl)graphBuilder;
                videoWin  = (IVideoWindow)graphBuilder;
                mediaEvt  = (IMediaEventEx)graphBuilder;

                return(true);
            }
            catch (Exception ee)
            {
                MessageBox.Show("Could not get interfaces\r\n" + ee.Message, "DirectShow.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }
            finally
            {
                if (comObj != null)
                {
                    Marshal.ReleaseComObject(comObj);
                }
                comObj = null;
            }
        }
Пример #4
0
        /// <summary> create the used COM components and get the interfaces. </summary>
        private bool GetInterfaces()
        {
            Type   comType = null;
            object comObj  = null;

            try
            {
                comType = Type.GetTypeFromCLSID(Clsid.FilterGraph);
                if (comType == null)
                {
                    throw new NotImplementedException(@"DirectShow FilterGraph not installed or registered!");
                }
                comObj        = Activator.CreateInstance(comType);
                _graphBuilder = (IGraphBuilder)comObj; comObj = null;

                Guid clsid = Clsid.CaptureGraphBuilder2;
                Guid riid  = typeof(ICaptureGraphBuilder2).GUID;
                comObj            = DsBugWO.CreateDsInstance(ref clsid, ref riid);
                _capGraphBuilder2 = (ICaptureGraphBuilder2)comObj; comObj = null;

                comType = Type.GetTypeFromCLSID(Clsid.SampleGrabber);
                if (comType == null)
                {
                    throw new NotImplementedException(@"DirectShow SampleGrabber not installed or registered!");
                }
                comObj       = Activator.CreateInstance(comType);
                _sampGrabber = (ISampleGrabber)comObj; comObj = null;

                _mediaCtrl      = (IMediaControl)_graphBuilder;
                _baseGrabFilter = (IBaseFilter)_sampGrabber;
                return(true);
            }
            catch (Exception ee)
            {
                if (comObj != null)
                {
                    Marshal.ReleaseComObject(comObj);
                }
                comObj = null;

                throw ee;
            }
        }
Пример #5
0
        public void Init(Hashtable config = null)
        {
            //m_FilterGraph = (IFilterGraph2)new FilterGraph();
            m_FilterGraph = (IGraphBuilder)Activator.CreateInstance(Type.GetTypeFromCLSID(Clsid.FilterGraph, true));

            // Get the ICaptureGraphBuilder2
            Guid clsid = Clsid.CaptureGraphBuilder2;
            Guid riid  = typeof(ICaptureGraphBuilder2).GUID;
            ICaptureGraphBuilder2 capGraph        = (ICaptureGraphBuilder2)DsBugWO.CreateDsInstance(ref clsid, ref riid);
            IBaseFilter           capVideoFilter  = null;
            IBaseFilter           capAudioFilter  = null;
            IBaseFilter           asfWriter       = null;
            IServiceProvider      serviceProvider = null;
            int    hr;
            object iwmWriter2;

            try
            {
                // Start building the graph
                hr = capGraph.SetFiltergraph(m_FilterGraph);
                Marshal.ThrowExceptionForHR(hr);

                // Add the video device to the graph
                if (videoDevChosen != null)
                {
                    capVideoFilter = GetCapFilter(ref videoDevChosen);
                    hr             = m_FilterGraph.AddFilter(capVideoFilter, "Video Capture Device");
                    Marshal.ThrowExceptionForHR(hr);
                }

                // Add the audio device to the graph
                if (audioDevChosen != null)
                {
                    capAudioFilter = GetCapFilter(ref audioDevChosen);
                    hr             = m_FilterGraph.AddFilter(capAudioFilter, "Audio Capture Device");
                    Marshal.ThrowExceptionForHR(hr);
                }
                // if we need some shitty quality
                if (config.Contains("shitty"))
                {
                    InitAsfWriter(out asfWriter, true);
                }
                else
                {
                    InitAsfWriter(out asfWriter);
                }


                //GEtting IWMAdvancedWriter2;
                serviceProvider = (IServiceProvider)asfWriter;
                Guid IID_IWMWriterAdvanced2 = new Guid("{962dc1ec-c046-4db8-9cc7-26ceae500817}");
                hr = serviceProvider.QueryService(IID_IWMWriterAdvanced2, IID_IWMWriterAdvanced2, out iwmWriter2);
                Marshal.ThrowExceptionForHR(hr);

                m_writerAdvanced2 = (IWMWriterAdvanced2)iwmWriter2;
                m_writerAdvanced2.SetLiveSource(true);

                if (config.ContainsKey("cap"))
                {
                    outputFilename = config["cap"] as string;
                    Console.WriteLine("[MODE] Capturing to a local file: {0}", outputFilename);
                }
                IFileSinkFilter cap = (IFileSinkFilter)asfWriter;
                cap.SetFileName(outputFilename, null);

                if (!config.ContainsKey("cap"))
                {
                    //deleting useless sink (writer to a file on a disk).
                    IWMWriterSink uselessSink = null;
                    m_writerAdvanced2.GetSink(0, out uselessSink);
                    m_writerAdvanced2.RemoveSink(uselessSink);
                    if (uselessSink != null)
                    {
                        Marshal.ReleaseComObject(uselessSink);
                        uselessSink = null;
                    }
                }

                if (config.Contains("send"))
                {
                    string url = config["send"] as string;
                    Console.WriteLine("[MODE] Streaming to a remote server: {0}", url);
                    WriterNetworkSink sender = new WriterNetworkSink(url);
                    m_writerAdvanced2.AddSink(sender);
                }
                if (config.Contains("share"))
                {
                    int port = (int)config["share"];
                    WriterNetworkSink listener = new WriterNetworkSink(port);
                    Console.WriteLine("[MODE] Started listening on port {0}", port);
                    m_writerAdvanced2.AddSink(listener);
                }
                //Connecting VideoDev to asfWriter
                if (videoDevChosen != null)
                {
                    hr = capGraph.RenderStream(PinCategory.Capture, MediaType.Video, capVideoFilter, null, asfWriter);
                    //hr = capGraph.RenderStream(null, null, capVideoFilter, null, asfWriter);
                    Marshal.ThrowExceptionForHR(hr);
                }
                //Connecting AudioDev to asfWriter
                if (audioDevChosen != null)
                {
                    hr = capGraph.RenderStream(PinCategory.Capture, MediaType.Audio, capAudioFilter, null, asfWriter);
                    //hr = capGraph.RenderStream(null, null, capAudioFilter, null, asfWriter);
                    Marshal.ThrowExceptionForHR(hr);
                }
                m_mediaCtrl = m_FilterGraph as IMediaControl;
                //debug, dumps graph
                //DirectShowLib.Utils.FilterGraphTools.SaveGraphFile(m_FilterGraph, ".\\mygraph.grf");
            }
            finally
            {
                if (capVideoFilter != null)
                {
                    Marshal.ReleaseComObject(capVideoFilter);
                    capVideoFilter = null;
                }
                if (capAudioFilter != null)
                {
                    Marshal.ReleaseComObject(capAudioFilter);
                    capAudioFilter = null;
                }
                if (asfWriter != null)
                {
                    Marshal.ReleaseComObject(asfWriter);
                    asfWriter = null;
                }
                if (capGraph != null)
                {
                    Marshal.ReleaseComObject(capGraph);
                    capGraph = null;
                }
                if (serviceProvider != null)
                {
                    Marshal.ReleaseComObject(serviceProvider);
                    serviceProvider = null;
                }
            }
            Console.WriteLine("INIT done");
        }
Пример #6
0
        protected void CreateGraph()
        {
            // Ensure required properties are set
            if (videoDevice == null && 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");
            }

            // Skip if we are already created
            if ((int)graphState >= (int)GraphState.Created)
            {
                return;
            }

            // Make a new filter graph
            graphBuilder = (IGraphBuilder)Activator.CreateInstance(Type.GetTypeFromCLSID(Clsid.FilterGraph, true));

            // Get the Capture Graph Builder
            Guid clsid = Clsid.CaptureGraphBuilder2;
            Guid riid  = typeof(ICaptureGraphBuilder2).GUID;

            captureGraphBuilder = (ICaptureGraphBuilder2)DsBugWO.CreateDsInstance(ref clsid, ref riid);

            // Link the CaptureGraphBuilder to the filter graph
            var hr = captureGraphBuilder.SetFiltergraph(graphBuilder);

            if (hr < 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            // Add the graph to the Running Object Table so it can be
            // viewed with GraphEdit
#if DEBUG
            DsROT.AddGraphToRot(graphBuilder, out rotCookie);
#endif
            // Get the video device and add it to the filter graph
            if (VideoDevice != null)
            {
                videoDeviceFilter = (IBaseFilter)Marshal.BindToMoniker(VideoDevice.MonikerString);
                hr = graphBuilder.AddFilter(videoDeviceFilter, "Video Capture Device");
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
            }

            // Get the audio device and add it to the filter graph
            if (AudioDevice != null)
            {
                audioDeviceFilter = (IBaseFilter)Marshal.BindToMoniker(AudioDevice.MonikerString);
                hr = graphBuilder.AddFilter(audioDeviceFilter, "Audio Capture Device");
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
            }

            // Get the video compressor and add it to the filter graph
            if (VideoCompressor != null)
            {
                videoCompressorFilter = (IBaseFilter)Marshal.BindToMoniker(VideoCompressor.MonikerString);
                hr = graphBuilder.AddFilter(videoCompressorFilter, "Video Compressor");
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
            }

            // Get the audio compressor and add it to the filter graph
            if (AudioCompressor != null)
            {
                audioCompressorFilter = (IBaseFilter)Marshal.BindToMoniker(AudioCompressor.MonikerString);
                hr = graphBuilder.AddFilter(audioCompressorFilter, "Audio Compressor");
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
            }

            // Retrieve the stream control interface for the video device
            // FindInterface will also add any required filters
            // (WDM devices in particular may need additional
            // upstream filters to function).

            // Try looking for an interleaved media type
            object o;
            var    cat = PinCategory.Capture;
            var    med = MediaType.Interleaved;
            Guid   iid = typeof(IAMStreamConfig).GUID;
            hr = captureGraphBuilder.FindInterface(
                ref cat, ref med, videoDeviceFilter, ref iid, out o);
            if (hr != 0)
            {
                // If not found, try looking for a video media type
                med = MediaType.Video;
                hr  = captureGraphBuilder.FindInterface(
                    ref cat, ref med, videoDeviceFilter, ref iid, out o);
                if (hr != 0)
                {
                    o = null;
                }
            }
            videoStreamConfig = o as IAMStreamConfig;

            cat = PinCategory.Preview;
            med = MediaType.Interleaved;
            iid = typeof(IAMStreamConfig).GUID;
            hr  = captureGraphBuilder.FindInterface(
                ref cat, ref med, videoDeviceFilter, ref iid, out o);

            if (hr != 0)
            {
                // If not found, try looking for a video media type
                med = MediaType.Video;
                hr  = captureGraphBuilder.FindInterface(
                    ref cat, ref med, videoDeviceFilter, ref iid, out o);
                if (hr != 0)
                {
                    o = null;
                }
            }
            previewStreamConfig = o as IAMStreamConfig;
            cat = PinCategory.Capture;
            med = MediaType.Audio;
            iid = typeof(IAMStreamConfig).GUID;
            if ((_audioViaPci) &&
                (audioDeviceFilter == null) && (videoDeviceFilter != null))
            {
                hr = captureGraphBuilder.FindInterface(ref cat, ref med, videoDeviceFilter, ref iid, out o);
            }
            else
            {
                hr = captureGraphBuilder.FindInterface(ref cat, ref med, audioDeviceFilter, ref iid, out o);
            }

            if (hr != 0)
            {
                o = null;
            }
            audioStreamConfig = o as IAMStreamConfig;

            // Retreive the media control interface (for starting/stopping graph)
            mediaControl = graphBuilder as IMediaControl;

            // Reload any video crossbars
            videoSources?.Dispose();
            videoSources = null;

            // Reload any audio crossbars
            audioSources?.Dispose();
            audioSources = null;

            // Reload any property pages exposed by filters
            //PropertyPages = null;

            // Reload capabilities of video device
            videoCaps   = null;
            previewCaps = null;

            // Reload capabilities of video device
            audioCaps = null;


            graphState = GraphState.Created;
        }
Пример #7
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;
            }
        }
Пример #8
0
 // Token: 0x0600018F RID: 399 RVA: 0x00011350 File Offset: 0x0000F550
 protected void createGraph()
 {
     if (this.zgraphState < Capture.GraphState.Created)
     {
         GC.Collect();
         this.graphBuilder = (IGraphBuilder)Activator.CreateInstance(Type.GetTypeFromCLSID(Clsid.FilterGraph, true));
         Guid captureGraphBuilder = Clsid.CaptureGraphBuilder2;
         Guid guid = typeof(ICaptureGraphBuilder2).GUID;
         this.captureGraphBuilder = (ICaptureGraphBuilder2)DsBugWO.CreateDsInstance(ref captureGraphBuilder, ref guid);
         int    num           = this.captureGraphBuilder.SetFiltergraph(this.graphBuilder);
         Type   typeFromCLSID = Type.GetTypeFromCLSID(Clsid.SampleGrabber);
         object objectValue   = RuntimeHelpers.GetObjectValue(Activator.CreateInstance(typeFromCLSID));
         this.sampGrabber = (ISampleGrabber)objectValue;
         this.baseGrabFlt = (IBaseFilter)this.sampGrabber;
         AMMediaType ammediaType = new AMMediaType();
         if (this.VideoDevice != null)
         {
             this.videoDeviceFilter = (IBaseFilter)Marshal.BindToMoniker(this.VideoDevice.MonikerString);
             num = this.graphBuilder.AddFilter(this.videoDeviceFilter, "Video Capture Device");
             ammediaType.majorType  = MediaType.Video;
             ammediaType.subType    = MediaSubType.RGB24;
             ammediaType.formatType = FormatType.VideoInfo;
             num = this.sampGrabber.SetMediaType(ammediaType);
             num = this.graphBuilder.AddFilter(this.baseGrabFlt, "Ds.NET Grabber");
         }
         if (this.AudioDevice != null)
         {
             this.audioDeviceFilter = (IBaseFilter)Marshal.BindToMoniker(this.AudioDevice.MonikerString);
             num = this.graphBuilder.AddFilter(this.audioDeviceFilter, "Audio Capture Device");
         }
         if (this.VideoCompressor != null)
         {
             this.videoCompressorFilter = (IBaseFilter)Marshal.BindToMoniker(this.VideoCompressor.MonikerString);
             num = this.graphBuilder.AddFilter(this.videoCompressorFilter, "Video Compressor");
         }
         if (this.AudioCompressor != null)
         {
             this.audioCompressorFilter = (IBaseFilter)Marshal.BindToMoniker(this.AudioCompressor.MonikerString);
             num = this.graphBuilder.AddFilter(this.audioCompressorFilter, "Audio Compressor");
         }
         Guid   capture = PinCategory.Capture;
         Guid   guid2   = MediaType.Interleaved;
         Guid   guid3   = typeof(IAMStreamConfig).GUID;
         object obj;
         num = this.captureGraphBuilder.FindInterface(ref capture, ref guid2, this.videoDeviceFilter, ref guid3, out obj);
         if (num != 0)
         {
             guid2 = MediaType.Video;
             num   = this.captureGraphBuilder.FindInterface(ref capture, ref guid2, this.videoDeviceFilter, ref guid3, out obj);
             if (num != 0)
             {
                 obj = null;
             }
         }
         this.videoStreamConfig = (obj as IAMStreamConfig);
         obj     = null;
         capture = PinCategory.Capture;
         guid2   = MediaType.Audio;
         guid3   = typeof(IAMStreamConfig).GUID;
         num     = this.captureGraphBuilder.FindInterface(ref capture, ref guid2, this.audioDeviceFilter, ref guid3, out obj);
         if (num != 0)
         {
             obj = null;
         }
         this.audioStreamConfig = (obj as IAMStreamConfig);
         this.mediaControl      = (IMediaControl)this.graphBuilder;
         if (this.m_videoSources != null)
         {
             this.m_videoSources.Dispose();
         }
         this.m_videoSources = null;
         if (this.m_audioSources != null)
         {
             this.m_audioSources.Dispose();
         }
         this.m_audioSources = null;
         if (this.m_propertyPages != null)
         {
             this.m_propertyPages.Dispose();
         }
         this.m_propertyPages = null;
         this.m_videoCaps     = null;
         obj     = null;
         capture = PinCategory.Capture;
         guid2   = MediaType.Interleaved;
         guid3   = typeof(IAMTVTuner).GUID;
         num     = this.captureGraphBuilder.FindInterface(ref capture, ref guid2, this.videoDeviceFilter, ref guid3, out obj);
         if (num != 0)
         {
             guid2 = MediaType.Video;
             num   = this.captureGraphBuilder.FindInterface(ref capture, ref guid2, this.videoDeviceFilter, ref guid3, out obj);
             if (num != 0)
             {
                 obj = null;
             }
         }
         IAMTVTuner iamtvtuner = obj as IAMTVTuner;
         if (iamtvtuner != null)
         {
             this.m_tuner = new Tuner(iamtvtuner);
         }
         this.videoInfoHeader = (VideoInfoHeader)Marshal.PtrToStructure(ammediaType.formatPtr, typeof(VideoInfoHeader));
         Marshal.FreeCoTaskMem(ammediaType.formatPtr);
         ammediaType.formatPtr = IntPtr.Zero;
         num = this.sampGrabber.SetBufferSamples(false);
         if (num == 0)
         {
             num = this.sampGrabber.SetOneShot(false);
         }
         if (num == 0)
         {
             num = this.sampGrabber.SetCallback(null, 0);
         }
         this.zgraphState = Capture.GraphState.Created;
     }
 }