Esempio n. 1
0
        private IBaseFilter ConfigAsf(ICaptureGraphBuilder2 capGraph,
                                      string szOutputFileName,
                                      CaptureOptions.VideoCompression quality)
        {
            IFileSinkFilter pTmpSink  = null;
            IBaseFilter     asfWriter = null;

            int hr = capGraph.SetOutputFileName(MediaSubType.Asf, szOutputFileName, out asfWriter, out pTmpSink);

            Marshal.ThrowExceptionForHR(hr);

            try
            {
                IConfigAsfWriter lConfig = (IConfigAsfWriter)asfWriter;

                string profileData;
                int    bitRate;
                switch (quality)
                {
                case CaptureOptions.VideoCompression.MinimalSize:
                    bitRate = (int)(1000000.0 * (_inFrameWidth * _inFrameHeight * _FPS) / (720 * 1280 * 25));
                    break;

                case CaptureOptions.VideoCompression.Optimal:
                    bitRate = (int)(2000000.0 * (_inFrameWidth * _inFrameHeight * _FPS) / (720 * 1280 * 25));
                    break;

                case CaptureOptions.VideoCompression.BestQuality:
                    bitRate = (int)(4000000.0 * (_inFrameWidth * _inFrameHeight * _FPS) / (720 * 1280 * 25));
                    break;

                default:
                    throw new ApplicationException("Internal error: unknown type of the required video codec");
                }

                //Getting XML with profile.
                using (var reader = new StreamReader(Path.Combine(Directories.GetConfigDirectory(), "Encoder.prx")))
                {
                    profileData = reader.ReadToEnd();
                }
                profileData = profileData.Replace("__FRAME_WIDTH__", _inFrameWidth.ToString());
                profileData = profileData.Replace("__FRAME_HEIGHT__", _inFrameHeight.ToString());
                profileData = profileData.Replace("__BIT_RATE__", bitRate.ToString());

                // Get manager
                IWMProfileManager profileManager;
                WMUtils.WMCreateProfileManager(out profileManager);

                // Create profile
                IWMProfile profile;
                profileManager.LoadProfileByData(profileData, out profile);
                lConfig.ConfigureFilterUsingProfile(profile);
            }
            finally
            {
                Marshal.ReleaseComObject(pTmpSink);
            }

            return(asfWriter);
        }
Esempio n. 2
0
        /// <summary>
        /// This method must be called to initialize the network sink. Make sure the SinkURL is properly populated before calling this method.
        /// </summary>
        protected void InitializeSink()
        {
            _sinkControl.StartChangingAttributes();
            IFileSinkFilter fileSink = (IFileSinkFilter)_sink;

            if (fileSink == null)
            {
                throw new Exception("IFileSourceFilter not found on DVR Sink");
            }
            AMMediaType mediaType = new AMMediaType();

            mediaType.majorType = DirectShowLib.MediaType.Stream;
            mediaType.subType   = MediaSubType.Null;
            String sinkFolderPath = null;

            sinkFolderPath = Settings.RootFolder + SourceConfig.SourceName + @"/";
            if (Directory.Exists(sinkFolderPath) == false)
            {
                Directory.CreateDirectory(sinkFolderPath);
            }
            int hr = fileSink.SetFileName(sinkFolderPath + "Stream.LBL", mediaType);

            DsError.ThrowExceptionForHR(hr);
            _sinkControl.SetBufferSize(0, Settings.NumberOfFiles, Settings.FileSize);
            Debug.WriteLine(String.Format("DVR for {0} is writing to {1}--{2} files with {3} bytes per file", SourceConfig.SourceName,
                                          sinkFolderPath, Settings.NumberOfFiles, Settings.FileSize));
            _sinkControl.StopChangingAttributes(false);
        }
Esempio n. 3
0
        protected override HRESULT OnInitInterfaces()
        {
            HRESULT hr;
            // Create Capture Graph Builder
            ICaptureGraphBuilder2 _capture = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            // Set Filter Graph
            _capture.SetFiltergraph(m_GraphBuilder);
            // Insert Capture Device into the Graph
            m_pCaptureDevice.FilterGraph = m_GraphBuilder;
            IBaseFilter     _muxer = null;
            IFileSinkFilter _sync  = null;

            // if we output into a file too
            if (!string.IsNullOrEmpty(m_sOutputFileName))
            {
                // Setup output for an avi file
                hr = (HRESULT)_capture.SetOutputFileName(MediaSubType.Avi, m_sOutputFileName, out _muxer, out _sync);
                hr.Assert();
                if (SUCCEEDED(hr))
                {
                    // Connect capture
                    hr = (HRESULT)_capture.RenderStream(PinCategory.Capture, MediaType.Video, m_pCaptureDevice.Value, null, _muxer);
                    hr.Assert();
                }
            }
            // Make preview
            hr = (HRESULT)_capture.RenderStream(PinCategory.Preview, MediaType.Video, m_pCaptureDevice.Value, null, null);
            Marshal.FinalReleaseComObject(_capture);
            return(hr);
        }
Esempio n. 4
0
        public override void RenderCapture(string fileName)
        {
            int hr;



            if (_encoderDevice == null)
            {
                throw new Exception("Encoder device \"" + GraphConfig[FilterType.VideoEncoder].Name + "\" could not be loaded!");
            }
            if (_writerDevice == null)
            {
                throw new Exception("Writer device \"" + GraphConfig[FilterType.Writer].Name + "\" could not be loaded!");
            }

            _videoEncoder = AddFilterByDevicePath(_encoderDevice.DevicePath, _encoderDevice.Name);
            _fileWriter   = AddFilterByDevicePath(_writerDevice.DevicePath, _writerDevice.Name);

            SetVideoBitRate(GraphConfig.VideoBitrate.MinBitRate, GraphConfig.VideoBitrate.MaxBitRate, GraphConfig.VideoIsVBR);
            ConnectFilters(_captureFilter, "656", _videoEncoder, "656", true);
            ConnectFilters(_videoEncoder, "MPEG", _fileWriter, "Input", true);

            IFileSinkFilter fileSinkControl = (IFileSinkFilter)_fileWriter;

            hr = fileSinkControl.SetFileName(fileName + ".mpg", _emptyAMMediaType);
            DsError.ThrowExceptionForHR(hr);

            StartDVRWriter(_fileWriter);
        }
Esempio n. 5
0
        /// <summary>
        /// Builds a recording graph that saves the incoming H264 stream to an Ogg container to add
        /// support for seeking.
        /// </summary>
        /// <param name="filename">file to record to</param>
        /// <remarks>
        /// Since this recording graph does not recompress or decompress any data, it performs its job
        /// with little overhead.
        /// </remarks>
        protected void CreateRecordingGraph(string filename)
        {
            lock (instanceMutex)
            {
                //create file recording graph
                _fileSinkGraphBuilder        = (IGraphBuilder) new FilterGraph();
                _fileSinkCaptureGraphBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();
                _fileSinkMediaControl        = (IMediaControl)_fileSinkGraphBuilder;

                //attach filter graph to capture graph, for recording
                int hr = _fileSinkCaptureGraphBuilder.SetFiltergraph(_fileSinkGraphBuilder);
                DsError.ThrowExceptionForHR(hr);

                //add bridge source to the recording graph, linked to the bridge sink
                _bridgeSource = (IBaseFilter)_bridgeController.InsertSourceFilter(_bridgeSink, _fileSinkGraphBuilder);

                _muxer = AddFilterByName(_fileSinkGraphBuilder, FilterCategory.LegacyAmFilterCategory, "LEAD MPEG2 Multiplexer (2.0)");
                //add the File Writer
                _fileSink       = AddFilterByName(_fileSinkGraphBuilder, FilterCategory.LegacyAmFilterCategory, "File writer");
                _fileSinkFilter = (IFileSinkFilter)_fileSink;
                hr = _fileSinkFilter.SetFileName(filename, null);
                DsError.ThrowExceptionForHR(hr);
                ConnectFilters(_fileSinkGraphBuilder, _bridgeSource, "Output 1", _muxer, "Input 01", true);
                ConnectFilters(_fileSinkGraphBuilder, _muxer, "Output 01", _fileSink, "in", false);
            }
        }
Esempio n. 6
0
        private IBaseFilter ConfigAsf(ICaptureGraphBuilder2 capGraph, string szOutputFileName)
        {
            IFileSinkFilter pTmpSink  = null;
            IBaseFilter     asfWriter = null;

            int hr = capGraph.SetOutputFileName(MediaSubType.Asf, szOutputFileName, out asfWriter, out pTmpSink);

            Marshal.ThrowExceptionForHR(hr);

            try
            {
                IConfigAsfWriter lConfig = asfWriter as IConfigAsfWriter;

                // Windows Media Video 8 for Dial-up Modem (No audio, 56 Kbps)
                // READ THE README for info about using guids
                Guid cat = new Guid(0x6E2A6955, 0x81DF, 0x4943, 0xBA, 0x50, 0x68, 0xA9, 0x86, 0xA7, 0x08, 0xF6);

                hr = lConfig.ConfigureFilterUsingProfileGuid(cat);
                Marshal.ThrowExceptionForHR(hr);
            }
            finally
            {
                Marshal.ReleaseComObject(pTmpSink);
            }

            return(asfWriter);
        }
Esempio n. 7
0
        IBaseFilter ConfigAsf(ICaptureGraphBuilder2 capGraph, string szFileName)
        {
            int hr;

            IBaseFilter     asfWriter = null;
            IFileSinkFilter pTmpSink  = null;

            // You *must* set an output file name.  Even though it never gets used
            hr = capGraph.SetOutputFileName(MediaSubType.Asf, szFileName, out asfWriter, out pTmpSink);
            DsError.ThrowExceptionForHR(hr);

            try
            {
                WindowsMediaLib.IConfigAsfWriter lConfig = asfWriter as WindowsMediaLib.IConfigAsfWriter;

                // Use one of the pre-defined system profiles.  I picked one with mucho
                // compression and no audio streams

                // Windows Media Video 8 for Dial-up Modem (No audio, 56 Kbps)
                Guid cat = new Guid(0x6E2A6955, 0x81DF, 0x4943, 0xBA, 0x50, 0x68, 0xA9, 0x86, 0xA7, 0x08, 0xF6);

                lConfig.ConfigureFilterUsingProfileGuid(cat);
            }
            finally
            {
                if (pTmpSink != null)
                {
                    Marshal.ReleaseComObject(pTmpSink);
                    pTmpSink = null;
                }
            }

            return(asfWriter);
        }
Esempio n. 8
0
        /// <summary>
        /// Constructs a new OggWriter
        /// </summary>
        public OggWriter() : base()
        {
            oggMux = FilterGraphTools.AddFilterByName(this.graph, FilterCategory.LegacyAmFilterCategory, "LEAD Ogg Multiplexer");
            if (oggMux == null)
            {
                throw new Exception("Could not instantiate OGG Mux!");
            }

            fileWriter = FilterGraphTools.AddFilterByName(this.graph, FilterCategory.LegacyAmFilterCategory, "File writer");
            if (fileWriter == null)
            {
                throw new Exception("File writer could not be instantiated");
            }

            IFileSinkFilter fs = fileWriter as IFileSinkFilter;

            if (fs == null)
            {
                throw new Exception(@"Can't get IFileSinkFilter interface!");
            }

            string datetime = DateTime.Now.ToString("yyMMdd HHmmss");

            int hr = fs.SetFileName(@"C:\temp\" + datetime + " oggwriter.ogm", null);

            DsError.ThrowExceptionForHR(hr);
        }
Esempio n. 9
0
 protected void derenderGraph()
 {
     if (this.mediaControl != null)
     {
         this.mediaControl.Stop();
     }
     if (this.videoWindow != null)
     {
         this.videoWindow.put_Visible(0);
         this.videoWindow.put_Owner(IntPtr.Zero);
         this.videoWindow = null;
     }
     if (this.PreviewWindow != null)
     {
         this.previewWindow.Resize -= new EventHandler(this.onPreviewWindowResize);
     }
     if (this.graphState >= GraphState.Rendered)
     {
         this.graphState        = GraphState.Created;
         this.isCaptureRendered = false;
         this.isPreviewRendered = false;
         if (this.videoDeviceFilter != null)
         {
             this.removeDownstream(this.videoDeviceFilter, this.videoCompressor == null);
         }
         if (this.audioDeviceFilter != null)
         {
             this.removeDownstream(this.audioDeviceFilter, this.audioCompressor == null);
         }
         this.muxFilter        = null;
         this.fileWriterFilter = null;
         this.baseGrabFlt      = null;
     }
 }
Esempio n. 10
0
        /// <summary>
        /// Configs the asf.
        /// </summary>
        /// <param name="capGraph">The cap graph.</param>
        /// <param name="szOutputFileName">Name of the sz output file.</param>
        /// <returns></returns>
        private IBaseFilter ConfigAsf(ICaptureGraphBuilder2 capGraph, string szOutputFileName)
        {
            IBaseFilter       asfWriter        = null;
            IFileSinkFilter   pTmpSink         = null;
            IWMProfileManager ppProfileManager = null;
            IWMProfile        ppProfile        = null;

            try
            {
                WindowsMediaLib.WMUtils.WMCreateProfileManager(out ppProfileManager);
                string prx = File.ReadAllText(Path.Combine(Path.GetDirectoryName(
                                                               Assembly.GetEntryAssembly().Location), "profile.prx"));
                ppProfileManager.LoadProfileByData(prx, out ppProfile);

                int hr = capGraph.SetOutputFileName(MediaSubType.Asf, szOutputFileName, out asfWriter, out pTmpSink);
                Marshal.ThrowExceptionForHR(hr);

                WindowsMediaLib.IConfigAsfWriter lConfig = asfWriter as WindowsMediaLib.IConfigAsfWriter;
                lConfig.ConfigureFilterUsingProfile(ppProfile);
            }
            finally
            {
                Marshal.ReleaseComObject(pTmpSink);
                Marshal.ReleaseComObject(ppProfile);
                Marshal.ReleaseComObject(ppProfileManager);
            }

            return(asfWriter);
        }
Esempio n. 11
0
        /// <summary>
        /// 解放
        /// </summary>
        public virtual void Dispose()
        {
            try
            {
                Stop();
            }
            catch (Exception)
            {
            }

            DeviceName = "";
            SampleGrabberCB.FrameSize = new Size(0, 0);
            SampleGrabberCB.Notify   -= SampleGrabberCB_Notify;

            CaptureFilter = null;
            CaptureOutPin = null;
            SampleGrabber = null;
            Renderer      = null;

            Mux  = null;
            Sync = null;

            if (CaptureBuilder != null)
            {
                Marshal.ReleaseComObject(CaptureBuilder);
            }
            CaptureBuilder = null;

            if (GraphBuilder != null)
            {
                Marshal.ReleaseComObject(GraphBuilder);
            }
            GraphBuilder = null;
        }
        void TestOutputFileName()
        {
            int             hr;
            IFileSinkFilter ppsink = null;

            hr = m_icgb2.SetOutputFileName(MediaSubType.Avi, g_DestTestFile, out m_Multiplexer, out ppsink);
            DsError.ThrowExceptionForHR(hr);
        }
Esempio n. 13
0
 /// <summary>
 /// 释放资源
 /// </summary>
 public void Dispose()
 {
     if (mediaControl != null)
     {
         mediaControl.Stop();
         mediaControl = null;
     }
     if (graphBuilder != null)
     {
         Marshal.ReleaseComObject(graphBuilder);
         graphBuilder = null;
     }
     if (captureGraphBuilder != null)
     {
         Marshal.ReleaseComObject(captureGraphBuilder);
         captureGraphBuilder = null;
     }
     if (sampleGrabber != null)
     {
         Marshal.ReleaseComObject(sampleGrabber);
         sampleGrabber = null;
     }
     if (theDevice != null)
     {
         Marshal.ReleaseComObject(theDevice);
         theDevice = null;
     }
     if (theDeviceCompressor != null)
     {
         Marshal.ReleaseComObject(theDeviceCompressor);
         theDeviceCompressor = null;
     }
     if (theAudio != null)
     {
         Marshal.ReleaseComObject(theAudio);
         theAudio = null;
     }
     if (theAudioCompressor != null)
     {
         Marshal.ReleaseComObject(theAudioCompressor);
         theAudioCompressor = null;
     }
     if (mux != null)
     {
         Marshal.ReleaseComObject(mux);
         mux = null;
     }
     if (sink != null)
     {
         Marshal.ReleaseComObject(sink);
         sink = null;
     }
     DisposeDevice(dsVideoDevice);             //释放视频设备
     DisposeDevice(dsVideoCompressorCategory); //释放视频解码器设备
     DisposeDevice(dsAudioInputDevice);        //释放语音设备
     DisposeDevice(dsAudioCompressorCategory); //释放语音解码器设备
 }
Esempio n. 14
0
        public string ChooseDstFileName()
        {
            string          ret  = null;
            IFileSinkFilter fdst = basefilter as IFileSinkFilter;

            if (fdst != null)
            {
                using (var fd = new SaveFileDialog())
                {
                    if (fd.ShowDialog() == DialogResult.OK)
                    {
                        try
                        {
                            int hr = fdst.SetFileName(fd.FileName, null);
                            DsError.ThrowExceptionForHR(hr);
                            ret = fd.FileName;
                        }
                        catch (COMException e)
                        {
                            Graph.ShowCOMException(e, "Can't create file " + fd.FileName);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message, "Exception caught while setting output file name " + fd.FileName);
                        }
                    }
                    else
                    if (Program.mainform.suggestURLs)
                    {
                        using (var rf = new RenderURLForm("Open URL"))
                        {
                            rf.ShowDialog();
                            if (rf.selectedURL != null)
                            {
                                try
                                {
                                    int hr = fdst.SetFileName(rf.selectedURL, null);
                                    DsError.ThrowExceptionForHR(hr);
                                    ret = rf.selectedURL;
                                }
                                catch (COMException e)
                                {
                                    Graph.ShowCOMException(e, "Can't set " + rf.selectedURL);
                                }
                                catch (Exception e)
                                {
                                    MessageBox.Show(e.Message, "Exception caught while setting URL " + rf.selectedURL);
                                }
                            }
                        }    //using rf
                    }
                }//using fd
            }
            return(ret);
        }
Esempio n. 15
0
        public DumpCom(IBaseFilter baseFilter)
        {
            Type comType = null;

            comType = Type.GetTypeFromCLSID(Clsid.CLSID_CLiveSource);
            if (comType == null)
            {
                throw new NotImplementedException(@"DirectShow FilterGraph not installed/registered!");
            }

            dumpIface = (IFileSinkFilter)baseFilter;
        }
Esempio n. 16
0
    /// <summary> build the capture graph for grabber. </summary>
    private void SetupGraph(string destFilename, string encoderName)
    {
        int hr;

        // Get the graphbuilder object
        captureGraphBuilder = new DirectShowLib.CaptureGraphBuilder2() as DirectShowLib.ICaptureGraphBuilder2;
        IFilterGraph2 filterGraph = new DirectShowLib.FilterGraph() as DirectShowLib.IFilterGraph2;

        mediaCtrl = filterGraph as DirectShowLib.IMediaControl;
        IMediaFilter mediaFilt = filterGraph as IMediaFilter;

        mediaEvent = filterGraph as IMediaEvent;
        captureGraphBuilder.SetFiltergraph(filterGraph);
        IBaseFilter     aviMux;
        IFileSinkFilter fileSink = null;

        hr = captureGraphBuilder.SetOutputFileName(MediaSubType.Avi, destFilename, out aviMux, out fileSink);
        DsError.ThrowExceptionForHR(hr);
        DirectShowLib.IBaseFilter compressor = DirectShowUtils.GetVideoCompressor(encoderName);
        if (compressor == null)
        {
            throw new InvalidCodecException(encoderName);
        }
        hr = filterGraph.AddFilter(compressor, "compressor");
        DsError.ThrowExceptionForHR(hr);
        // Our data source
        IBaseFilter source = (IBaseFilter) new GenericSampleSourceFilter();
        // Get the pin from the filter so we can configure it
        IPin ipin = DsFindPin.ByDirection(source, PinDirection.Output, 0);

        try
        {
            // Configure the pin using the provided BitmapInfo
            ConfigurePusher((IGenericSampleConfig)ipin);
        }
        finally
        {
            Marshal.ReleaseComObject(ipin);
        }
        // Add the filter to the graph
        hr = filterGraph.AddFilter(source, "GenericSampleSourceFilter");
        Marshal.ThrowExceptionForHR(hr);
        hr = filterGraph.AddFilter(source, "source");
        DsError.ThrowExceptionForHR(hr);
        hr = captureGraphBuilder.RenderStream(null, null, source, compressor, aviMux);
        DsError.ThrowExceptionForHR(hr);
        IMediaPosition mediaPos = filterGraph as IMediaPosition;

        hr = mediaCtrl.Run();
        DsError.ThrowExceptionForHR(hr);
    }
Esempio n. 17
0
        public StreamingAndRecording(StreamSourceInfo sourceConfig, OpenGraphRequest openGraphRequest) : base(sourceConfig, openGraphRequest)
        {
            InitializeNetworkSink();

            int hr;

            _tee = (IBaseFilter) new InfTee();
            hr   = _graphBuilder.AddFilter(_tee, "Inf Tee");
            DsError.ThrowExceptionForHR(hr);

            _recordSink       = AddFilterByName(FilterCategory.LegacyAmFilterCategory, "DVR Writer");
            _recordSinkFilter = (IFileSinkFilter)_recordSink;
            _recordSinkFilter.SetFileName(@"c:\test.lts", new AMMediaType());
            _dvrWriter = (IDVRWriterApi)_recordSink;
        }
Esempio n. 18
0
        /// <summary>
        /// This method must be called to initialize the network sink. Make sure the SinkURL is properly populated before calling this method.
        /// </summary>
        protected void InitializeSink()
        {
            IFileSinkFilter fileSink = (IFileSinkFilter)_sink;

            if (fileSink == null)
            {
                throw new Exception("IFileSourceFilter not found on DVR Sink");
            }
            AMMediaType mediaType = new AMMediaType();

            mediaType.majorType = DirectShowLib.MediaType.Stream;
            mediaType.subType   = MediaSubType.Null;
            int hr = fileSink.SetFileName(SourceConfig.SinkAddress, mediaType);

            DsError.ThrowExceptionForHR(hr);
        }
        //
        // This method convert the input file to an wmv file
        //
        void Convert2Wmv(string fileName)
        {
            try
            {
                progressText.Text = "Dönüstürme islemi devam ediyor";
                start.Enabled     = false;
                convert.Enabled   = false;
                SaveFileDialog saveFile = new SaveFileDialog();
                if (saveFile.ShowDialog() == DialogResult.OK)
                {
                    hr = me.SetNotifyWindow(this.Handle, WM_GRAPHNOTIFY, IntPtr.Zero);
                    DsError.ThrowExceptionForHR(hr);

                    // here we use the asf writer to create wmv files
                    WMAsfWriter     asf_filter = new WMAsfWriter();
                    IFileSinkFilter fs         = (IFileSinkFilter)asf_filter;
                    hr = fs.SetFileName(saveFile.FileName + ".wmv", null);
                    string[] fileNewName = saveFile.FileName.Split('\\');
                    outPutText.Text = fileNewName[fileNewName.Length - 1].ToString() + ".wmv";
                    DsError.ThrowExceptionForHR(hr);

                    hr = gb.AddFilter((IBaseFilter)asf_filter, "WM Asf Writer");
                    DsError.ThrowExceptionForHR(hr);

                    hr = gb.RenderFile(fileName + fExt, null);
                    DsError.ThrowExceptionForHR(hr);

                    hr = mc.Run();
                    DsError.ThrowExceptionForHR(hr);
                }
                else
                {
                    convert.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Wmv ye çevirilirken hata olustu " + ex.Message);
                timerThread.Stop();
                topProgressBar.Value = 0;
                fileName.Text        = "";
                outPutText.Text      = "";
                start.Enabled        = true;
                convert.Enabled      = true;
                progressText.Text    = "Hata oluþtu, dönüþtürme iþlemi devam ettirilemiyor";
            }
        }
Esempio n. 20
0
        protected void derenderGraph()
        {
            // Stop the graph if it is running (ignore errors)
            if (mediaControl != null)
            {
                mediaControl.Stop();
            }

            // Free the preview window (ignore errors)
            if (videoWindow != null)
            {
                videoWindow.put_Visible(DsHlp.OAFALSE);
                videoWindow.put_Owner(IntPtr.Zero);
                videoWindow = null;
            }

            // Remove the Resize event handler
            if (PreviewWindow != null)
            {
                previewWindow.Resize -= new EventHandler(onPreviewWindowResize);
            }

            if ((int)graphState >= (int)GraphState.Rendered)
            {
                // Update the state
                graphState        = GraphState.Created;
                isCaptureRendered = false;
                isPreviewRendered = false;

                // Disconnect all filters downstream of the
                // video and audio devices. If we have a compressor
                // then disconnect it, but don't remove it
                if (videoDeviceFilter != null)
                {
                    removeDownstream(videoDeviceFilter, (videoCompressor == null));
                }
                if (audioDeviceFilter != null)
                {
                    removeDownstream(audioDeviceFilter, (audioCompressor == null));
                }

                // These filters should have been removed by the
                // calls above. (Is there anyway to check?)
                muxFilter        = null;
                fileWriterFilter = null;
            }
        }
Esempio n. 21
0
        /// <summary>
        /// This method must be called to initialize the network sink. Make sure the SinkURL is properly populated before calling this method.
        /// </summary>
        protected void InitializeNetworkSink()
        {
            IFileSinkFilter fileSink = (IFileSinkFilter)_netSnk;

            if (fileSink == null)
            {
                throw new Exception("IFileSourceFilter not found on LMNetSink");
            }
            _lmNetSnk = (ILMNetSnk)_netSnk;
            AMMediaType mediaType = new AMMediaType();

            mediaType.majorType = DirectShowLib.MediaType.Stream;
            mediaType.subType   = MediaSubType.Null;
            int hr = fileSink.SetFileName(ClientURL, mediaType);

            DsError.ThrowExceptionForHR(hr);
        }
Esempio n. 22
0
        /// <summary>
        /// initializes the sink
        /// </summary>
        protected virtual void InitializeNetworkSink()
        {
            IFileSinkFilter fileSink = (IFileSinkFilter)netSnk;

            if (fileSink == null)
            {
                throw new Exception("IFileSourceFilter not found on LMNetSink");
            }
            lmNetSnk = (LMNetSnk)netSnk;
            AMMediaType mediaType = new AMMediaType();

            mediaType.majorType = MediaType.Stream;
            mediaType.subType   = MediaSubType.Null;
            int hr = fileSink.SetFileName(this.SinkURL, mediaType);

            DsError.ThrowExceptionForHR(hr);
        }
Esempio n. 23
0
        /// <summary>Do the conversion from DVR-MS to WAV.</summary>
        /// <returns>Null; ignored.</returns>
        protected override object DoWork()
        {
            // Get the filter graph
            object filterGraph = ClassId.CoCreateInstance(ClassId.FilterGraph);

            DisposalCleanup.Add(filterGraph);
            IGraphBuilder graph = (IGraphBuilder)filterGraph;

            // Add the ASF writer and set the output name
            IBaseFilter asfWriterFilter = (IBaseFilter)ClassId.CoCreateInstance(ClassId.WMAsfWriter);

            DisposalCleanup.Add(asfWriterFilter);
            graph.AddFilter(asfWriterFilter, null);
            IFileSinkFilter sinkFilter = (IFileSinkFilter)asfWriterFilter;

            sinkFilter.SetFileName(OutputFilePath, null);

            // Set the profile to be used for conversion
            if (_profilePath != null && _profilePath.Trim().Length > 0)
            {
                // Load the profile XML contents
                string profileData;
                using (StreamReader reader = new StreamReader(File.OpenRead(_profilePath)))
                {
                    profileData = reader.ReadToEnd();
                }

                // Create an appropriate IWMProfile from the data
                IWMProfileManager profileManager = ProfileManager.CreateInstance();
                DisposalCleanup.Add(profileManager);
                IntPtr wmProfile = profileManager.LoadProfileByData(profileData);
                DisposalCleanup.Add(wmProfile);

                // Set the profile on the writer
                IConfigAsfWriter2 configWriter = (IConfigAsfWriter2)asfWriterFilter;
                configWriter.ConfigureFilterUsingProfile(wmProfile);
            }

            // Add the source filter; should connect automatically through the appropriate transform filters
            graph.RenderFile(InputFilePath, null);

            // Run the graph to completion
            RunGraph(graph, asfWriterFilter);

            return(null);
        }
Esempio n. 24
0
        /// <summary>Do the conversion from DVR-MS to WAV.</summary>
        /// <returns>Null; ignored.</returns>
        protected override object DoWork()
        {
            // Get the filter graph
            object filterGraph = ClassId.CoCreateInstance(ClassId.FilterGraph);

            DisposalCleanup.Add(filterGraph);
            IGraphBuilder graph = (IGraphBuilder)filterGraph;

            // Add the source filter for the dvr-ms file
            IBaseFilter DvrmsSourceFilter = graph.AddSourceFilter(InputFilePath, null);

            DisposalCleanup.Add(DvrmsSourceFilter);

            // Add the file writer to the graph
            IBaseFilter wavFilter = (IBaseFilter)ClassId.CoCreateInstance(ClassId.FileWriter);

            DisposalCleanup.Add(wavFilter);
            graph.AddFilter(wavFilter, null);
            IFileSinkFilter sinkFilter = (IFileSinkFilter)wavFilter;

            sinkFilter.SetFileName(OutputFilePath, null);

            // Add the Wav Dest filter to the graph
            IBaseFilter wavDest = (IBaseFilter)ClassId.CoCreateInstance(ClassId.WavDest);

            DisposalCleanup.Add(wavDest);
            graph.AddFilter(wavDest, null);

            // Add the decrypter node to the graph
            IBaseFilter decrypter = (IBaseFilter)ClassId.CoCreateInstance(ClassId.DecryptTag);

            DisposalCleanup.Add(decrypter);
            graph.AddFilter(decrypter, null);

            // Connect the dvr-ms source to the decrypter, the decrypter to the wav dest,
            // and the wav dest to the file writer
            Connect(graph, DvrmsSourceFilter, "DVR Out - 1", decrypter, "In(Enc/Tag)");
            Connect(graph, decrypter, "Out", wavDest, "In");
            Connect(graph, wavDest, "Out", wavFilter, "in");

            // Run the graph to convert the audio to wav
            RunGraph(graph);

            return(null);
        }
        private void Cleanup()
        {
            Log.Info("DVR2MPG: cleanup");
            if (_rotEntry != null)
            {
                _rotEntry.SafeDispose();
            }
            _rotEntry = null;

            if (mediaControl != null)
            {
                mediaControl.Stop();
                mediaControl = null;
            }
            mediaSeeking = null;
            mediaEvt     = null;
            mediaControl = null;

            if (powerDvdMuxer != null)
            {
                DirectShowUtil.ReleaseComObject(powerDvdMuxer);
            }
            powerDvdMuxer = null;

            if (fileWriterFilter != null)
            {
                DirectShowUtil.ReleaseComObject(fileWriterFilter);
            }
            fileWriterFilter = null;

            if (bufferSource != null)
            {
                DirectShowUtil.ReleaseComObject(bufferSource);
            }
            bufferSource = null;

            DirectShowUtil.RemoveFilters(graphBuilder);

            if (graphBuilder != null)
            {
                DirectShowUtil.ReleaseComObject(graphBuilder);
            }
            graphBuilder = null;
        }
Esempio n. 26
0
        public override void RenderCapture(string fileName)
        {
            //AVerMedia Encoder
            //ITU Video--|
            //           |--MPEG2 Program
            //I2S Audio--|

            _encoderDevice = FindDevice(FilterCategory.WDMStreamingEncoderDevices, Config.FilterType.VideoEncoder);

            if (_encoderDevice == null)
            {
                throw new Exception("Encoder device \"" + GraphConfig[FilterType.VideoEncoder].Name + "\" could not be loaded!");
            }
            if (_writerDevice == null)
            {
                throw new Exception("Writer device \"" + GraphConfig[FilterType.Writer].Name + "\" could not be loaded!");
            }

            //get filters from devices
            _videoEncoder = AddFilterByDevicePath(_encoderDevice.DevicePath, _encoderDevice.Name);
            _fileWriter   = AddFilterByDevicePath(_writerDevice.DevicePath, _writerDevice.Name);

            ConnectFilters(_captureFilter, "ITU Video", _videoEncoder, "ITU Video", false);
            ConnectFilters(_captureFilter, "I2S Audio", _videoEncoder, "I2S Audio", false);

            ConnectFilters(_videoEncoder, "MPEG2 Program", _fileWriter, "Input", false);

            //configure File Sink / File Writer
            IFileSinkFilter fileSink = (IFileSinkFilter)_fileWriter;
            int             hr       = fileSink.SetFileName(fileName + ".mpg", _emptyAMMediaType);

            if (hr != 0)
            {
                this.CaptureRequiresNewGraph = true;
            }

            DsError.ThrowExceptionForHR(hr);

            StartDVRWriter(_fileWriter);

            this.SaveGraphFile();
        }
Esempio n. 27
0
        public override void RenderCapture(string fileName)
        {
            //add new filters
            r_oggMux = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, "LEAD Ogg Multiplexer");
            if (r_oggMux == null)
            {
                throw new Exception("Could not instantiate OGG Multiplexer!");
            }
            _fileWriter = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, GraphConfig[FilterType.Writer].Name);
            if (_fileWriter == null)
            {
                throw new Exception("Could not instatiate \"" + GraphConfig[FilterType.Writer].Name + "\"!");
            }

            //and path to OGG mux
            ConnectFilters(r_videoTee, VideoTeeOutputName, r_oggMux, "Stream 0", false);

            //path to OGG mux
            ConnectFilters(r_audioTee, AudioTeeOutputName, r_oggMux, "Stream 1", false);

            //configure File Sink / File Writer
            IFileSinkFilter fileSink = (IFileSinkFilter)_fileWriter;
            int             hr       = fileSink.SetFileName(fileName + ".ogm", _emptyAMMediaType);

            if (hr != 0)
            {
                this.CaptureRequiresNewGraph = true;
            }

            DsError.ThrowExceptionForHR(hr);

            StartDVRWriter(_fileWriter);


            ConnectFilters(r_oggMux, "Ogg Stream", _fileWriter, GraphConfig[FilterType.Writer].InPin[0], false);

            CaptureRequiresNewGraph = false;

            this.SaveGraphFile();
        }
Esempio n. 28
0
        /// <summary>
        /// Build a graph for capturing video
        /// </summary>
        /// <param name="sinkPath">Save path for the captured video</param>
        private void BuildGraph(string sinkPath)
        {
            ///Add the capture filter in graph
            this._graphBuilder.AddFilter(this._captureFilter, "Video Capture");

            IFileSinkFilter sink = null;
            int             hr   = this._captureBuilder.SetOutputFileName(MediaSubType.Avi, sinkPath, out this._mux, out sink);

            ///Create a sample grabber filter. Sample grabber filter provides callback
            ///for application to grab video frames on the fly.
            this._sampleGrabber = (ISampleGrabber) new SampleGrabber();
            ///Configure the sample grabber
            base.ConfigureSampleGrabber(this._sampleGrabber, MediaSubType.RGB24);

            this._graphBuilder.AddFilter((IBaseFilter)this._sampleGrabber, "SampleGrabber");

            ///Stream to file
            hr = this._captureBuilder.RenderStream(PinCategory.Capture, MediaType.Video, this._captureFilter, (IBaseFilter)this._sampleGrabber, this._mux);

            ///preview window
            hr = this._captureBuilder.RenderStream(PinCategory.Preview, MediaType.Video, this._captureFilter, null, null);
        }
Esempio n. 29
0
        public static IBaseFilter RenderAviDestination(DisposalCleanup dc, ICaptureGraphBuilder2 graphBuilder,
                                                       string outputFile)
        {
            if (dc == null)
            {
                throw new ArgumentNullException("dc");
            }
            if (graphBuilder == null)
            {
                throw new ArgumentNullException("graphBuilder");
            }
            if (string.IsNullOrEmpty(outputFile))
            {
                throw new ArgumentNullException("outputFile");
            }

            int hr = 0;

            // Create the file writer
            IBaseFilter     multiplexer;
            IFileSinkFilter filter = null;

            try
            {
                hr = graphBuilder.SetOutputFileName(MediaSubType.Avi, outputFile, out multiplexer, out filter);
                dc.Add(multiplexer);
                DESError.ThrowExceptionForHR(hr);
            }
            finally
            {
                if (filter != null)
                {
                    Marshal.ReleaseComObject(filter);
                }
            }

            return(multiplexer);
        }
Esempio n. 30
0
        public static IBaseFilter RenderAviDest(DisposalCleanup dc, ICaptureGraphBuilder2 icgb, string outputFile)
        {
            int hr = 0;

            // Create the file writer
            IBaseFilter     pMux;
            IFileSinkFilter pFilter = null;

            try
            {
                hr = icgb.SetOutputFileName(MediaSubType.Avi, outputFile, out pMux, out pFilter);
                dc.Add(pMux);
                DESError.ThrowExceptionForHR(hr);
            }
            finally
            {
                if (pFilter != null)
                {
                    Marshal.ReleaseComObject(pFilter);
                }
            }

            return(pMux);
        }
Esempio n. 31
0
    public bool Transcode(TranscodeInfo info, MediaPortal.Core.Transcoding.VideoFormat format,
                          MediaPortal.Core.Transcoding.Quality quality, Standard standard)
    {
      if (!Supports(format)) return false;
      string ext = System.IO.Path.GetExtension(info.file);
      if (ext.ToLower() != ".dvr-ms" && ext.ToLower() != ".sbe") return false;

      //Type comtype = null;
      //object comobj = null;
      try
      {
        Log.Info("DVR2MPG: create graph");
        graphBuilder = (IGraphBuilder)new FilterGraph();

        _rotEntry = new DsROTEntry((IFilterGraph)graphBuilder);

        Log.Info("DVR2MPG: add streambuffersource");
        bufferSource = (IStreamBufferSource)new StreamBufferSource();


        IBaseFilter filter = (IBaseFilter)bufferSource;
        graphBuilder.AddFilter(filter, "SBE SOURCE");

        Log.Info("DVR2MPG: load file:{0}", info.file);
        IFileSourceFilter fileSource = (IFileSourceFilter)bufferSource;
        int hr = fileSource.Load(info.file, null);


        Log.Info("DVR2MPG: Add Cyberlink MPEG2 multiplexer to graph");
        string monikerPowerDvdMuxer =
          @"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{7F2BBEAF-E11C-4D39-90E8-938FB5A86045}";
        powerDvdMuxer = Marshal.BindToMoniker(monikerPowerDvdMuxer) as IBaseFilter;
        if (powerDvdMuxer == null)
        {
          Log.Warn("DVR2MPG: FAILED:Unable to create Cyberlink MPEG Muxer (PowerDVD)");
          Cleanup();
          return false;
        }

        hr = graphBuilder.AddFilter(powerDvdMuxer, "PDR MPEG Muxer");
        if (hr != 0)
        {
          Log.Warn("DVR2MPG: FAILED:Add Cyberlink MPEG Muxer to filtergraph :0x{0:X}", hr);
          Cleanup();
          return false;
        }

        //add filewriter 
        Log.Info("DVR2MPG: Add FileWriter to graph");
        string monikerFileWrite =
          @"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{3E8868CB-5FE8-402C-AA90-CB1AC6AE3240}";
        IBaseFilter fileWriterbase = Marshal.BindToMoniker(monikerFileWrite) as IBaseFilter;
        if (fileWriterbase == null)
        {
          Log.Warn("DVR2MPG: FAILED:Unable to create FileWriter");
          Cleanup();
          return false;
        }


        fileWriterFilter = fileWriterbase as IFileSinkFilter;
        if (fileWriterFilter == null)
        {
          Log.Warn("DVR2MPG: FAILED:Add unable to get IFileSinkFilter for filewriter");
          Cleanup();
          return false;
        }

        hr = graphBuilder.AddFilter(fileWriterbase, "FileWriter");
        if (hr != 0)
        {
          Log.Warn("DVR2MPG: FAILED:Add FileWriter to filtergraph :0x{0:X}", hr);
          Cleanup();
          return false;
        }


        //connect output #0 of streambuffer source->powerdvd audio in
        //connect output #1 of streambuffer source->powerdvd video in
        Log.Info("DVR2MPG: connect streambuffer->multiplexer");
        IPin pinOut0, pinOut1;
        IPin pinIn0, pinIn1;
        pinOut0 = DsFindPin.ByDirection((IBaseFilter)bufferSource, PinDirection.Output, 0);
        pinOut1 = DsFindPin.ByDirection((IBaseFilter)bufferSource, PinDirection.Output, 1);

        pinIn0 = DsFindPin.ByDirection(powerDvdMuxer, PinDirection.Input, 0);
        pinIn1 = DsFindPin.ByDirection(powerDvdMuxer, PinDirection.Input, 1);
        if (pinOut0 == null || pinOut1 == null || pinIn0 == null || pinIn1 == null)
        {
          Log.Warn("DVR2MPG: FAILED:unable to get pins of muxer&source");
          Cleanup();
          return false;
        }

        bool usingAc3 = false;
        AMMediaType amAudio = new AMMediaType();
        amAudio.majorType = MediaType.Audio;
        amAudio.subType = MediaSubType.Mpeg2Audio;
        hr = pinOut0.Connect(pinIn1, amAudio);
        if (hr != 0)
        {
          amAudio.subType = MediaSubType.DolbyAC3;
          hr = pinOut0.Connect(pinIn1, amAudio);
          usingAc3 = true;
        }
        if (hr != 0)
        {
          Log.Warn("DVR2MPG: FAILED: unable to connect audio pins: 0x{0:X}", hr);
          Cleanup();
          return false;
        }

        if (usingAc3)
          Log.Info("DVR2MPG: using AC3 audio");
        else
          Log.Info("DVR2MPG: using MPEG audio");

        AMMediaType amVideo = new AMMediaType();
        amVideo.majorType = MediaType.Video;
        amVideo.subType = MediaSubType.Mpeg2Video;
        hr = pinOut1.Connect(pinIn0, amVideo);
        if (hr != 0)
        {
          Log.Warn("DVR2MPG: FAILED: unable to connect video pins: 0x{0:X}", hr);
          Cleanup();
          return false;
        }


        //connect output of powerdvd muxer->input of filewriter
        Log.Info("DVR2MPG: connect multiplexer->filewriter");
        IPin pinOut, pinIn;
        pinOut = DsFindPin.ByDirection(powerDvdMuxer, PinDirection.Output, 0);
        if (pinOut == null)
        {
          Log.Warn("DVR2MPG: FAILED:cannot get output pin of Cyberlink MPEG muxer :0x{0:X}", hr);
          Cleanup();
          return false;
        }
        pinIn = DsFindPin.ByDirection(fileWriterbase, PinDirection.Input, 0);
        if (pinIn == null)
        {
          Log.Warn("DVR2MPG: FAILED:cannot get input pin of Filewriter :0x{0:X}", hr);
          Cleanup();
          return false;
        }
        AMMediaType mt = new AMMediaType();
        hr = pinOut.Connect(pinIn, mt);
        if (hr != 0)
        {
          Log.Warn("DVR2MPG: FAILED:connect muxer->filewriter :0x{0:X}", hr);
          Cleanup();
          return false;
        }

        //set output filename
        string outputFileName = System.IO.Path.ChangeExtension(info.file, ".mpg");
        Log.Info("DVR2MPG: set output file to :{0}", outputFileName);
        mt.majorType = MediaType.Stream;
        mt.subType = MediaSubTypeEx.MPEG2;

        hr = fileWriterFilter.SetFileName(outputFileName, mt);
        if (hr != 0)
        {
          Log.Warn("DVR2MPG: FAILED:unable to set filename for filewriter :0x{0:X}", hr);
          Cleanup();
          return false;
        }
        mediaControl = graphBuilder as IMediaControl;
        mediaSeeking = graphBuilder as IMediaSeeking;
        mediaEvt = graphBuilder as IMediaEventEx;
        Log.Info("DVR2MPG: start transcoding");
        hr = mediaControl.Run();
        if (hr != 0)
        {
          Log.Warn("DVR2MPG: FAILED:unable to start graph :0x{0:X}", hr);
          Cleanup();
          return false;
        }
      }
      catch (Exception ex)
      {
        Log.Error("DVR2MPG: Unable create graph: {0}", ex.Message);
        Cleanup();
        return false;
      }
      return true;
    }
Esempio n. 32
0
    private void Cleanup()
    {
      Log.Info("DVR2MPG: cleanup");
      if (_rotEntry != null)
      {
        _rotEntry.SafeDispose();
      }
      _rotEntry = null;

      if (mediaControl != null)
      {
        mediaControl.Stop();
        mediaControl = null;
      }
      mediaSeeking = null;
      mediaEvt = null;
      mediaControl = null;

      if (powerDvdMuxer != null)
        DirectShowUtil.ReleaseComObject(powerDvdMuxer);
      powerDvdMuxer = null;

      if (fileWriterFilter != null)
        DirectShowUtil.ReleaseComObject(fileWriterFilter);
      fileWriterFilter = null;

      if (bufferSource != null)
        DirectShowUtil.ReleaseComObject(bufferSource);
      bufferSource = null;

      DirectShowUtil.RemoveFilters(graphBuilder);

      if (graphBuilder != null)
        DirectShowUtil.ReleaseComObject(graphBuilder);
      graphBuilder = null;
    }
Esempio n. 33
0
        /// <summary>
        /// グラフの生成
        /// </summary>
        /// <param name="output_file">出力ファイル</param>
        public virtual void Setup(string output_file)
        {
            this.Dispose();

            try
            {
                CxDSCameraParam param = this.Param;

                // グラフビルダー.
                // CoCreateInstance
                GraphBuilder = (IGraphBuilder)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(GUID.CLSID_FilterGraph)));

                #region フィルタ追加.
                // 画像入力フィルタ.
                IBaseFilter capture = CreateVideoCapture(param);
                if (capture == null)
                    throw new System.IO.IOException();
                this.GraphBuilder.AddFilter(capture, "CaptureFilter");
                IPin capture_out = DSLab.Axi.FindPin(capture, 0, PIN_DIRECTION.PINDIR_OUTPUT);
                this.CaptureFilter = capture;
                this.CaptureOutPin = capture_out;

                // サンプルグラバー.
                IBaseFilter grabber = (IBaseFilter)CreateSampleGrabber();
                if (grabber == null)
                    throw new System.IO.IOException();
                this.GraphBuilder.AddFilter(grabber, "SampleGrabber");
                this.SampleGrabber = (ISampleGrabber)grabber;
                #endregion

                #region キャプチャビルダー:
                {
                    int hr = 0;
                    CaptureBuilder = (ICaptureGraphBuilder2)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(GUID.CLSID_CaptureGraphBuilder2)));
                    hr = CaptureBuilder.SetFiltergraph(GraphBuilder);

                    if (string.IsNullOrEmpty(output_file))
                    {
                        // レンダラー.
                        IBaseFilter renderer = null;
                        renderer = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(GUID.CLSID_NullRenderer)));
                        if (renderer == null)
                            throw new System.IO.IOException();
                        this.GraphBuilder.AddFilter(renderer, "Renderer");
                        this.Renderer = renderer;

            #if true
                        // IGraphBuilder.Connect の代わりに ICaptureGraphBuilder2.RenderStream を使用する.
                        // fig) [capture]-out->-in-[sample grabber]-out->-in-[null render]
                        hr = CaptureBuilder.RenderStream(new Guid(GUID.PIN_CATEGORY_CAPTURE), new Guid(GUID.MEDIATYPE_Video), capture, grabber, renderer);

            #else
                        // ピンの取得.
                        IPin grabber_in = DSLab.Axi.FindPin(grabber, 0, PIN_DIRECTION.PINDIR_INPUT);
                        IPin grabber_out = DSLab.Axi.FindPin(grabber, 0, PIN_DIRECTION.PINDIR_OUTPUT);
                        IPin renderer_in = DSLab.Axi.FindPin(renderer, 0, PIN_DIRECTION.PINDIR_INPUT);

                        // ピンの接続.
                        GraphBuilder.Connect(capture_out, grabber_in);
                        GraphBuilder.Connect(grabber_out, renderer_in);

                        // ピンの保管.
                        //SampleGrabberInPin = grabber_in;
                        //SampleGrabberOutPin = grabber_out;
                        //RendererInPin = renderer_in;
            #endif
                    }
                    else
                    {
                        IBaseFilter mux = null;
                        IFileSinkFilter sync = null;
                        hr = CaptureBuilder.SetOutputFileName(new Guid(GUID.MEDIASUBTYPE_Avi), output_file, ref mux, ref sync);
                        hr = CaptureBuilder.RenderStream(new Guid(GUID.PIN_CATEGORY_CAPTURE), new Guid(GUID.MEDIATYPE_Video), capture, grabber, mux);
                        this.Mux = mux;
                        this.Sync = sync;
                    }
                }
                #endregion

                #region 保管: フレームサイズ.
                VIDEOINFOHEADER vinfo = DSLab.Axi.GetVideoInfo(SampleGrabber);
                this.SampleGrabberCB.BitmapInfo = vinfo.bmiHeader;
                this.SampleGrabberCB.FrameSize = new Size(
                    System.Math.Abs(this.SampleGrabberCB.BitmapInfo.biWidth),
                    System.Math.Abs(this.SampleGrabberCB.BitmapInfo.biHeight)
                    );
                #endregion

                #region 保管: デバイス名称.
                try
                {
                    if (string.IsNullOrEmpty(param.FilterInfo.Name) == false)
                    {
                        this.DeviceName = param.FilterInfo.Name;
                    }
                    else
                    {
                        int filter_index = param.FilterInfo.Index;
                        List<DSLab.CxDSFilterInfo> filters = DSLab.Axi.GetFilterList(DSLab.GUID.CLSID_VideoInputDeviceCategory);
                        if (0 <= filter_index && filter_index < filters.Count)
                        {
                            this.DeviceName = filters[filter_index].Name;
                        }
                    }
                }
                catch (System.Exception)
                {
                    this.DeviceName = "";
                }
                #endregion

                // DEBUG
            #if DEBUG
                DebugPrint(this.GraphBuilder);
            #endif
            }
            catch (Exception ex)
            {
                this.Dispose();
                throw new DSLab.CxDSException(ex);
            }
        }
Esempio n. 34
0
        /// <summary>
        /// 解放
        /// </summary>
        public virtual void Dispose()
        {
            try
            {
                Stop();
            }
            catch (Exception)
            {
            }

            DeviceName = "";
            SampleGrabberCB.FrameSize = new Size(0, 0);
            SampleGrabberCB.Notify -= SampleGrabberCB_Notify;

            CaptureFilter = null;
            CaptureOutPin = null;
            SampleGrabber = null;
            Renderer = null;

            Mux = null;
            Sync = null;

            if (CaptureBuilder != null)
                Marshal.ReleaseComObject(CaptureBuilder);
            CaptureBuilder = null;

            if (GraphBuilder != null)
                Marshal.ReleaseComObject(GraphBuilder);
            GraphBuilder = null;
        }
Esempio n. 35
0
		/// <summary>
		///  Disconnect and remove all filters except the device
		///  and compressor filters. This is the opposite of
		///  renderGraph(). Soem properties such as FrameRate
		///  can only be set when the device output pins are not
		///  connected. 
		/// </summary>
		protected void derenderGraph()
		{
			// Stop the graph if it is running (ignore errors)
			if ( mediaControl != null )
				mediaControl.Stop();

			// Free the preview window (ignore errors)
			if ( videoWindow != null )
			{
				videoWindow.put_Visible( DsHlp.OAFALSE );
				videoWindow.put_Owner( IntPtr.Zero );
				videoWindow = null;
			}

			
			//ELIMINAR RECURSOS CAPTURA <<<<<<<<<================================================
			/*if ( mediaEvt != null ) 
			{
				int hr = mediaEvt.SetNotifyWindow( IntPtr.Zero, WM_GRAPHNOTIFY, IntPtr.Zero );
				mediaEvt = null;
			}*/

			// Remove the Resize event handler
			if ( PreviewWindow != null )
				previewWindow.Resize -= new EventHandler( onPreviewWindowResize );

			if ( (int)graphState >= (int)GraphState.Rendered )
			{
				// Update the state
				graphState = GraphState.Created;
				isCaptureRendered = false;
				isPreviewRendered = false;

				// Disconnect all filters downstream of the 
				// video and audio devices. If we have a compressor
				// then disconnect it, but don't remove it
				if ( videoDeviceFilter != null )
					removeDownstream( videoDeviceFilter, (videoCompressor==null) );
				if ( audioDeviceFilter != null )
					removeDownstream( audioDeviceFilter, (audioCompressor==null) );

				// These filters should have been removed by the
				// calls above. (Is there anyway to check?)
				muxFilter = null;
				fileWriterFilter = null;
				
				//ELIMINAR RECURSOS CAPTURA <<<<<<<<<================================================
				baseGrabFlt = null;
			}
		}
Esempio n. 36
0
    /// <summary>
    /// Dispose the resources used by this capture class.
    /// Stops the graph first.
    /// </summary>
    public void Dispose()
    {
      // Stop the graph if it is running (ignore errors)
      this.Stop();

      // Free the preview window (ignore errors)
      if (videoWindow != null)
      {
        videoWindow.put_Visible(OABool.False);
        videoWindow.put_Owner(IntPtr.Zero);
        videoWindow = null;
      }

      // Remove the Resize event handler
      if (this.captureDeviceProperties.PreviewWindow != null)
      {
        this.captureDeviceProperties.PreviewWindow.Resize -= new EventHandler(onPreviewWindowResize);
      }

#if DEBUG
      // Remove graph from the ROT 
      if (rotCookie != null)
      {
        rotCookie.Dispose();
        rotCookie = null;
      }
#endif

      // Cleanup
      if (graphBuilder != null)
      {
        Marshal.ReleaseComObject(graphBuilder);
        graphBuilder = null;
      }

      if (captureGraphBuilder != null)
      {
        Marshal.ReleaseComObject(captureGraphBuilder);
        captureGraphBuilder = null;
      }

      if (muxFilter != null)
      {
        Marshal.ReleaseComObject(muxFilter);
        muxFilter = null;
      }

      if (fileWriterFilter != null)
      {
        Marshal.ReleaseComObject(fileWriterFilter);
        fileWriterFilter = null;
      }

      if (this.videoStreamConfig != null)
      {
        Marshal.ReleaseComObject(videoStreamConfig);
        videoStreamConfig = null;
      }

      if (this.referenceClock != null)
      {
        Marshal.ReleaseComObject(referenceClock);
        referenceClock = null;
      }

      if (this.VideoDeviceFilter != null)
      {
        Marshal.ReleaseComObject(VideoDeviceFilter);
        VideoDeviceFilter = null;
      }

      if (this.AudioDeviceFilter != null)
      {
        Marshal.ReleaseComObject(AudioDeviceFilter);
        AudioDeviceFilter = null;
      }

      if (this.VideoCompressorFilter != null)
      {
        Marshal.ReleaseComObject(VideoCompressorFilter);
        VideoCompressorFilter = null;
      }

      if (this.AudioCompressorFilter != null)
      {
        Marshal.ReleaseComObject(AudioCompressorFilter);
        AudioCompressorFilter = null;
      }

      // These are copies of graphBuilder
      mediaControl = null;
      videoWindow = null;

      this.HasValidGraph = false;

      // For unmanaged objects we haven't released explicitly
      GC.Collect();
    }
Esempio n. 37
0
		/// <summary>
		///  Completely tear down a filter graph and 
		///  release all associated resources.
		/// </summary>
		protected void destroyGraph()
		{
			// Derender the graph (This will stop the graph
			// and release preview window. It also destroys
			// half of the graph which is unnecessary but
			// harmless here.) (ignore errors)
			try{ derenderGraph(); } catch {}

			// Update the state after derender because it
			// depends on correct status. But we also want to
			// update the state as early as possible in case
			// of error.
			graphState = GraphState.Null;
			isCaptureRendered = false;
			isPreviewRendered = false;

            // Remove graph from the ROT
#if DSHOWNET
			if ( rotCookie != 0 )
			{
				DsROT.RemoveGraphFromRot( ref rotCookie );
				rotCookie = 0;
			}
#else
            if (rotCookie != null)
            {
                rotCookie.Dispose();
                rotCookie = null;
            }
#endif

            // Remove filters from the graph
			// This should be unnecessary but the Nvidia WDM
			// video driver cannot be used by this application 
			// again unless we remove it. Ideally, we should
			// simply enumerate all the filters in the graph
			// and remove them. (ignore errors)
			if ( muxFilter != null )
				graphBuilder.RemoveFilter( muxFilter );
			if ( videoCompressorFilter != null )
				graphBuilder.RemoveFilter( videoCompressorFilter  );
			if ( audioCompressorFilter != null )
				graphBuilder.RemoveFilter( audioCompressorFilter  );
			if ( videoDeviceFilter != null )
				graphBuilder.RemoveFilter( videoDeviceFilter );
			if ( audioDeviceFilter != null )
				graphBuilder.RemoveFilter( audioDeviceFilter );

			if(this.videoRendererFilter != null)
			{
				this.graphBuilder.RemoveFilter(this.videoRendererFilter);
			}

            // Clean up properties
			if ( videoSources != null )
				videoSources.Dispose(); videoSources = null;
			if ( audioSources != null )
				audioSources.Dispose(); audioSources = null;
            this.PropertyPages = null; // Disposal done within PropertyPages
			if ( tuner != null )
				tuner.Dispose(); tuner = null;

// #if NEWCODE
			if(this.tvAudio != null)
			{
				Marshal.ReleaseComObject(this.tvAudio); tvAudio = null;
			}

			if(this.dxUtils != null)
			{
				this.dxUtils.Dispose();
				this.dxUtils = null;
			}
// #endif

			// Cleanup
			if ( graphBuilder != null )
				Marshal.ReleaseComObject( graphBuilder );  graphBuilder = null;
			if ( captureGraphBuilder != null )
				Marshal.ReleaseComObject( captureGraphBuilder ); captureGraphBuilder = null;
			if ( muxFilter != null )
				Marshal.ReleaseComObject( muxFilter ); muxFilter = null;
			if ( fileWriterFilter != null )
				Marshal.ReleaseComObject( fileWriterFilter ); fileWriterFilter = null;
			if ( videoDeviceFilter != null )
				Marshal.ReleaseComObject( videoDeviceFilter ); videoDeviceFilter = null;
			if ( audioDeviceFilter != null )
				Marshal.ReleaseComObject( audioDeviceFilter ); audioDeviceFilter = null;
			if ( videoCompressorFilter != null )
				Marshal.ReleaseComObject( videoCompressorFilter ); videoCompressorFilter = null;
			if ( audioCompressorFilter != null )
				Marshal.ReleaseComObject( audioCompressorFilter ); audioCompressorFilter = null;
// #if NEWCODE
			this.DisposeSampleGrabber();
// #endif

			if(this.videoRendererFilter != null)
			{
				Marshal.ReleaseComObject(this.videoRendererFilter); this.videoRendererFilter = null;
			}

            // These are copies of graphBuilder
			mediaControl = null;
			videoWindow = null;

			// For unmanaged objects we haven't released explicitly
			GC.Collect();
		}
Esempio n. 38
0
		/// <summary>
		///  Disconnect and remove all filters except the device
		///  and compressor filters. This is the opposite of
		///  renderGraph(). Soem properties such as FrameRate
		///  can only be set when the device output pins are not
		///  connected. 
		/// </summary>
		protected void derenderGraph()
		{
			// Stop the graph if it is running (ignore errors)
			if ( mediaControl != null )
				mediaControl.Stop();

			// Free the preview window (ignore errors)
			if ( videoWindow != null )
			{
#if DSHOWNET
                videoWindow.put_Visible(DsHlp.OAFALSE);
#else
                videoWindow.put_Visible(OABool.False);
#endif
				videoWindow.put_Owner( IntPtr.Zero );
				videoWindow = null;
			}

			// Remove the Resize event handler
			if ( PreviewWindow != null )
				previewWindow.Resize -= new EventHandler( onPreviewWindowResize );

			if ( (int)graphState >= (int)GraphState.Rendered )
			{
				// Update the state
				graphState = GraphState.Created;
				isCaptureRendered = false;
				isPreviewRendered = false;

				// Disconnect all filters downstream of the 
				// video and audio devices. If we have a compressor
				// then disconnect it, but don't remove it
				if (videoDeviceFilter != null)
				{
					try
					{
						removeDownstream(videoDeviceFilter, (videoCompressor == null));
					}
					catch
					{
						Debug.WriteLine("Error removeDownstream videoDeviceFilter");
					}
				}
				if (audioDeviceFilter != null)
				{
					try
					{
						removeDownstream(audioDeviceFilter, (audioCompressor == null));
					}
					catch
					{
						Debug.WriteLine("Error removeDownstream audioDeviceFilter");
					}
				}

				// These filters should have been removed by the
				// calls above. (Is there anyway to check?)
				muxFilter = null;
				fileWriterFilter = null;
				this.videoRendererFilter = null;
				this.deInterlaceFilter = null;
            }
		}
Esempio n. 39
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.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();
 }
Esempio n. 40
0
		/// <summary>
		///  Disconnect and remove all filters except the device
		///  and compressor filters. This is the opposite of
		///  renderGraph(). Soem properties such as FrameRate
		///  can only be set when the device output pins are not
		///  connected. 
		/// </summary>
		private void derenderGraph()
		{
			// Stop the graph if it is running (ignore errors)
			if (_mediaControl != null)
				_mediaControl.Stop();

			// Free the preview window (ignore errors)
			if (_videoWindow != null)
			{
				_videoWindow.put_Visible(OABool.False);
				_videoWindow.put_Owner(IntPtr.Zero);
				_videoWindow = null;
			}

			// Remove the Resize event handler
			if (PreviewWindow != null)
				_previewWindow.Resize -= new EventHandler(onPreviewWindowResize);

			if ((int)_graphState >= (int)GraphState.Rendered)
			{
				// Update the state
				_graphState = GraphState.Created;
				_isCaptureRendered = false;
				_isPreviewRendered = false;

				// Disconnect all filters downstream of the 
				// video and audio devices. If we have a compressor
				// then disconnect it, but don't remove it
				if (_videoDeviceFilter != null)
					removeDownstream(_videoDeviceFilter, (_videoCompressor == null));
				if (_audioDeviceFilter != null)
					removeDownstream(_audioDeviceFilter, (_audioCompressor == null));

				// These filters should have been removed by the
				// calls above. (Is there anyway to check?)
				_muxFilter = null;
				_fileWriterFilter = null;
			}
		}
Esempio n. 41
0
 /// <summary>Runs the graph</summary>
 /// <param name="graphBuilder">The graph to be run.</param>
 /// <param name="seekableFilter">The filter to use for computing percent complete. Must implement IMediaSeeking.</param>
 protected void RunGraph(IGraphBuilder graphBuilder, IFileSinkFilter seekableFilter)
 {
     RunGraph(graphBuilder, (IBaseFilter)seekableFilter);
 }
Esempio n. 42
0
        public override void Stop()
        {
            
            if (this.receiveStreams.Count > 0)
            {
                Log.WriteLine("cannot stop since there are other receivers");
                return;
            }
            if (this.working)
            {
                Log.WriteLine("stopping........");
                try
                {
                    if (!object.Equals(graphBuilder, null))
                    {
                        int hr = (this.graphBuilder as IMediaControl).StopWhenReady();
                        hr = (this.graphBuilder as IMediaControl).Stop();
                    }
                    FilterGraphTools.RemoveAllFilters(this.graphBuilder);

                    if (!object.Equals(this.sink, null)) Marshal.ReleaseComObject(sink); this.sink = null;
                    if (!object.Equals(this.fileDump, null)) Marshal.ReleaseComObject(this.fileDump); this.fileDump = null;
                    if (!object.Equals(this.graphBuilder, null)) Marshal.ReleaseComObject(this.graphBuilder); this.graphBuilder = null;
                }
                catch { }
            }
            base.Stop();
            
        }
Esempio n. 43
0
        private void SetSaveFile(string filename)
        {
            fileDump = FilterGraphTools.FindFilterByName(graphBuilder, dumpFilterName);
            if (object.Equals(fileDump, null))
                throw new System.Exception("Couldn't find dump filter in filter graph: " + dumpFilterName);


            sink = fileDump as IFileSinkFilter;

            AMMediaType media = new AMMediaType();
            media.majorType = MediaType.Video;
            media.subType = MediaSubType.Mpeg2Transport;
            media.formatType = FormatType.VideoInfo;


            int hr = sink.SetFileName(filename, media);
            DsError.ThrowExceptionForHR(hr);
        }
Esempio n. 44
0
		/// <summary>
		///  Completely tear down a filter graph and 
		///  release all associated resources.
		/// </summary>
		private void destroyGraph()
		{
			// Derender the graph (This will stop the graph
			// and release preview window. It also destroys
			// half of the graph which is unnecessary but
			// harmless here.) (ignore errors)
			try 
			{ 
				derenderGraph(); 
			}
			catch { }

			// Update the state after derender because it
			// depends on correct status. But we also want to
			// update the state as early as possible in case
			// of error.
			_graphState = GraphState.Null;
			_isCaptureRendered = false;
			_isPreviewRendered = false;

			// Remove graph from the ROT
			//if (_rotCookie != 0)
			//{
			//    DsROT.RemoveGraphFromRot(ref _rotCookie);
			//    _rotCookie = 0;
			//}

			// Remove filters from the graph
			// This should be unnecessary but the Nvidia WDM
			// video driver cannot be used by this application 
			// again unless we remove it. Ideally, we should
			// simply enumerate all the filters in the graph
			// and remove them. (ignore errors)
			if (_muxFilter != null)
				_graphBuilder.RemoveFilter(_muxFilter);
			if (_videoCompressorFilter != null)
				_graphBuilder.RemoveFilter(_videoCompressorFilter);
			if (_audioCompressorFilter != null)
				_graphBuilder.RemoveFilter(_audioCompressorFilter);
			if (_videoDeviceFilter != null)
				_graphBuilder.RemoveFilter(_videoDeviceFilter);
			if (_audioDeviceFilter != null)
				_graphBuilder.RemoveFilter(_audioDeviceFilter);

			// Clean up properties
			if (_videoSources != null)
				_videoSources.Dispose(); 
			_videoSources = null;
			if (_audioSources != null)
				_audioSources.Dispose(); 
			_audioSources = null;
			if (_propertyPages != null)
				_propertyPages.Dispose(); 
			_propertyPages = null;
			if (Tuner != null)
				Tuner.Dispose(); 
			Tuner = null;

			// Cleanup
			if (_graphBuilder != null)
				Marshal.ReleaseComObject(_graphBuilder); 
			_graphBuilder = null;
			if (_captureGraphBuilder != null)
				Marshal.ReleaseComObject(_captureGraphBuilder); 
			_captureGraphBuilder = null;
			if (_muxFilter != null)
				Marshal.ReleaseComObject(_muxFilter); 
			_muxFilter = null;
			if (_fileWriterFilter != null)
				Marshal.ReleaseComObject(_fileWriterFilter); 
			_fileWriterFilter = null;
			if (_videoDeviceFilter != null)
				Marshal.ReleaseComObject(_videoDeviceFilter); 
			_videoDeviceFilter = null;
			if (_audioDeviceFilter != null)
				Marshal.ReleaseComObject(_audioDeviceFilter); 
			_audioDeviceFilter = null;
			if (_videoCompressorFilter != null)
				Marshal.ReleaseComObject(_videoCompressorFilter); 
			_videoCompressorFilter = null;
			if (_audioCompressorFilter != null)
				Marshal.ReleaseComObject(_audioCompressorFilter); 
			_audioCompressorFilter = null;

			// These are copies of graphBuilder
			_mediaControl = null;
			_videoWindow = null;

			// For unmanaged objects we haven't released explicitly
			GC.Collect();
		}
Esempio n. 45
0
 protected void derenderGraph()
 {
     if (this.mediaControl != null)
     {
         this.mediaControl.Stop();
     }
     if (this.videoWindow != null)
     {
         this.videoWindow.put_Visible(0);
         this.videoWindow.put_Owner(IntPtr.Zero);
         this.videoWindow = null;
     }
     if (this.PreviewWindow != null)
     {
         this.previewWindow.Resize -= new EventHandler(this.onPreviewWindowResize);
     }
     if (this.graphState >= GraphState.Rendered)
     {
         this.graphState = GraphState.Created;
         this.isCaptureRendered = false;
         this.isPreviewRendered = false;
         if (this.videoDeviceFilter != null)
         {
             this.removeDownstream(this.videoDeviceFilter, this.videoCompressor == null);
         }
         if (this.audioDeviceFilter != null)
         {
             this.removeDownstream(this.audioDeviceFilter, this.audioCompressor == null);
         }
         this.muxFilter = null;
         this.fileWriterFilter = null;
     }
 }
Esempio n. 46
0
    /// <summary> 
    ///  Calls Stop, releases all references. If a capture is in progress
    ///  it will be stopped, but the CaptureComplete event will NOT fire.
    /// </summary>
    public void Dispose()
    {
      try
      {
#if DEBUG

        // Remove graph from the ROT 
        if (this.rotCookie != null)
        {
          this.rotCookie.Dispose();
          this.rotCookie = null;
        }

#endif

        // Free the preview window (ignore errors)
        if (this.videoWindow != null)
        {
          this.videoWindow.put_Visible(OABool.False);
          this.videoWindow.put_Owner(IntPtr.Zero);
          this.videoWindow = null;
        }

        // Remove the Resize event handler
        if (this.previewWindow != null)
        {
          this.previewWindow.Resize -= new EventHandler(this.onPreviewWindowResize);
        }

        // Cleanup
        if (this.graphBuilder != null)
        {
          Marshal.ReleaseComObject(this.graphBuilder);
          this.graphBuilder = null;

          // These are copies of graphBuilder
          this.mediaControl = null;
          this.videoWindow = 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.screenCaptureFilter != null)
        {
          Marshal.ReleaseComObject(this.screenCaptureFilter);
          this.screenCaptureFilter = null;
        }

        if (this.videoCompressorFilter != null)
        {
          Marshal.ReleaseComObject(this.videoCompressorFilter);
          this.videoCompressorFilter = null;
        }

        if (this.dmoFilter != null)
        {
          Marshal.ReleaseComObject(this.dmoFilter);
          this.dmoFilter = null;
        }

        if (this.smartTeeFilter != null)
        {
          Marshal.ReleaseComObject(this.smartTeeFilter);
          this.smartTeeFilter = null;
        }

        // For unmanaged objects we haven't released explicitly
        GC.Collect();
      }
      catch (Exception ex)
      {
        ExceptionMethods.HandleExceptionSilent(ex);
      }
    }