Пример #1
0
        /// <summary>
        /// Build the graph and connect filters
        /// </summary>
        /// <param name="outputPath">Path of stego video file</param>
        private void BuildGraph(string outputPath)
        {
            ///Create a graph builder.
            this._graphBuilder = (IGraphBuilder) new FilterGraph();

            ///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
            this.ConfigureSampleGrabber(this._sampleGrabber, MediaSubType.RGB24);


            ///Create the file reader filter.
            this._fileReaderFilter = ComGuids.GetFilterFromGuid(ComGuids.FileReaderFilterGuid);
            ///Add the filter to graph. This function only adds filter to graph but
            ///do not connect it
            this._graphBuilder.AddFilter(this._fileReaderFilter, "File Source");

            ///Get source filter, this will let you load an AVI file
            IFileSourceFilter sourceFilter = this._fileReaderFilter as IFileSourceFilter;

            ///Load the file
            sourceFilter.Load(this._sourcePath, null);


            ///Create AVI splitter. This filter splits the AVI file into video and audio or other
            ///components that form the video (e.g text)
            this._aviSplitter = ComGuids.GetFilterFromGuid(ComGuids.AviSplitterGuid);
            ///Add the filter to graph
            this._graphBuilder.AddFilter(this._aviSplitter, "AVI Splitter");


            ///Add the sample grabber filter to graph
            this._graphBuilder.AddFilter((IBaseFilter)this._sampleGrabber, "SampleGrabber");


            ///Create AVI mux filter. This filter will combine the audio and video in one stream.
            ///We will use this filter to combine audio and video streams after hiding
            ///data in ISampleGrabber's BufferCB callback.
            this._aviMultiplexer = ComGuids.GetFilterFromGuid(ComGuids.AviMultiplexerGuid);
            ///Add filter to graph
            this._graphBuilder.AddFilter(this._aviMultiplexer, "AVI multiplexer");

            ///We will add file writer, only then we will add file writer
            if (this._processing == ProcessingType.Hide)
            {
                ///Create a file writer filter. This filter will be used to write the AVI stream
                ///to a file
                this._rendererFilter = ComGuids.GetFilterFromGuid(ComGuids.FileWriterFilterGuid);

                ///Add renderer filter to graph
                this._graphBuilder.AddFilter(this._rendererFilter, "File writer");

                ///Get the file sink filter
                IFileSinkFilter sinkFilter = this._rendererFilter as IFileSinkFilter;
                ///Set the output file name
                sinkFilter.SetFileName(outputPath, null);
            }
            else
            {
                ///Create a null renderer
                this._rendererFilter = ComGuids.GetFilterFromGuid(ComGuids.NullRendererGuid);

                ///Add renderer filter to graph
                this._graphBuilder.AddFilter(this._rendererFilter, "Null renderer");
            }

            DirectShowUtil.ConnectFilters(this._graphBuilder, this._fileReaderFilter, this._aviSplitter);
            DirectShowUtil.ConnectFilters(this._graphBuilder, this._aviSplitter, (IBaseFilter)this._sampleGrabber);
            DirectShowUtil.ConnectFilters(this._graphBuilder, (IBaseFilter)this._sampleGrabber, this._aviMultiplexer);
            DirectShowUtil.ConnectFilters(this._graphBuilder, this._aviMultiplexer, this._rendererFilter);
        }