private void Configure()
        {
            int hr;
            IDMOWrapperFilter iDMO = (IDMOWrapperFilter) new DMOWrapperFilter();
            Guid g = new Guid("03be3ac4-84b7-4e0e-a78d-d3524e60395a");

            hr    = iDMO.Init(g, Guid.Empty);
            m_voo = (IDMOVideoOutputOptimizations)iDMO;
        }
Exemplo n.º 2
0
        private void BuildGraph(string sFileName, bool bLeft)
        {
            int               hr;
            IBaseFilter       ibfFile          = null;
            IBaseFilter       ibfFilter        = null;
            IBaseFilter       ibfRender        = null;
            IDMOWrapperFilter dmoWrapperFilter = null;

            ICaptureGraphBuilder2 icgb = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            graphBuilder = (IFilterGraph2) new FilterGraph();
#if DEBUG
            m_rot = new DsROTEntry(graphBuilder);
#endif

            hr = icgb.SetFiltergraph(graphBuilder);
            DsError.ThrowExceptionForHR(hr);

            // Add a DMO Wrapper Filter
            ibfFilter        = (IBaseFilter) new DMOWrapperFilter();
            dmoWrapperFilter = (IDMOWrapperFilter)ibfFilter;

            // Since I know the guid of the DMO I am looking for, I can do this.
            hr = dmoWrapperFilter.Init(new Guid("{EAB6CBA9-78DD-4ae4-9A69-1CE1C55369F6}"), DMOCategory.AudioEffect);
            DMOError.ThrowExceptionForHR(hr);

            // Add it to the Graph
            hr = graphBuilder.AddFilter(ibfFilter, "DMO Filter");
            DsError.ThrowExceptionForHR(hr);

            ibfRender = (IBaseFilter) new AudioRender();
            hr        = graphBuilder.AddFilter(ibfRender, "Renderer");
            DsError.ThrowExceptionForHR(hr);

            ibfFile = (IBaseFilter) new AsyncReader();
            hr      = graphBuilder.AddFilter(ibfFile, "Reader");
            DsError.ThrowExceptionForHR(hr);

            IFileSourceFilter ifileSink = (IFileSourceFilter)ibfFile;
            hr = ifileSink.Load(sFileName, null);
            DsError.ThrowExceptionForHR(hr);

            hr = icgb.RenderStream(null, null, ibfFile, null, ibfFilter);
            DsError.ThrowExceptionForHR(hr);

            IPin iPin = DsFindPin.ByDirection(ibfFilter, PinDirection.Output, bLeft ? 0 : 1);

            hr = icgb.RenderStream(null, null, iPin, null, ibfRender);
            DsError.ThrowExceptionForHR(hr);

            Marshal.ReleaseComObject(ibfRender);
            Marshal.ReleaseComObject(dmoWrapperFilter);
            Marshal.ReleaseComObject(iPin);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create and add a filter from a DSFilterTreeViewNode
        /// </summary>
        /// <param name="tn"></param>
        public IBaseFilter AddFilter(DSFilterTreeViewNode tn)
        {
            int         hr     = 0;
            IBaseFilter filter = null;

            if (tn.DSFilterType == FilterType.DMO)
            {
                // create a DMO wrapper and init it with the ClassGuid
                filter = (IBaseFilter) new DMOWrapperFilter();
                IDMOWrapperFilter wrapper = (IDMOWrapperFilter)filter;
                hr = wrapper.Init(tn.ClassGuid, tn.DMOCategory);
                if (hr != 0)
                {
                    MessageBox.Show(DsError.GetErrorText(hr), "Error wrapping DMO");
                    Marshal.ReleaseComObject(filter);
                    return(null);
                }
                hr = _Graph.AddFilter(filter, tn.Text);
                if (hr != 0)
                {
                    MessageBox.Show(DsError.GetErrorText(hr), "Error Adding DMO");
                    Marshal.ReleaseComObject(filter);
                    return(null);
                }
                SyncGraphs(filter);
                return(filter);
            }
            else
            {
                // try adding it as a source filter first (this usually works for non-source filters anyway)
                hr = (_Graph as IFilterGraph2).AddSourceFilterForMoniker(tn.Moniker, null, tn.Text, out filter);

                // that didn't work.  Try AddFilterByDevicePath
                if (filter == null)
                {
                    DirectShowLib.Utils.FilterGraphTools.AddFilterByDevicePath(_Graph as IGraphBuilder, tn.DevicePath, tn.Name);
                }

                // force the DaggerGraph to reflect changes in the DS graph
                List <DSFilterNode> addedNodes = SyncGraphs(filter);

                // get the DSFilterNode that was added and give it the information
                if (addedNodes.Count == 1)
                {
                    addedNodes[0]._devicePath = tn.DevicePath;
                    addedNodes[0]._moniker    = tn.Moniker;
                }

                return(filter);
            }
        }
Exemplo n.º 4
0
        private void Configure()
        {
            int hr;

            DMOWrapperFilter  dmoFilter        = new DMOWrapperFilter();
            IDMOWrapperFilter dmoWrapperFilter = (IDMOWrapperFilter)dmoFilter;

            // Chorus - {efe6629c-81f7-4281-bd91-c9d604a95af6}
            // DmoFlip - {7EF28FD7-E88F-45bb-9CDD-8A62956F2D75}
            //hr = dmoWrapperFilter.Init(new Guid("{7EF28FD7-E88F-45bb-9CDD-8A62956F2D75}"), DMOCategory.AudioEffect);
            hr = dmoWrapperFilter.Init(new Guid("{efe6629c-81f7-4281-bd91-c9d604a95af6}"), DMOCategory.AudioEffect);
            DMOError.ThrowExceptionForHR(hr);

            m_impi = dmoWrapperFilter as IMediaParamInfo;
        }
Exemplo n.º 5
0
        private void junk()
        {
            int      hr;
            IEnumDMO idmo;

            Guid []   g      = new Guid[1];
            string [] sn     = new string[1];
            int       iCount = 0;

            hr = DMOUtils.DMOEnum(Guid.Empty, DMOEnumerator.None, 0, null, 0, null, out idmo);
            DMOError.ThrowExceptionForHR(hr);

            do
            {
                DMOWrapperFilter  dmoFilter        = new DMOWrapperFilter();
                IDMOWrapperFilter dmoWrapperFilter = (IDMOWrapperFilter)dmoFilter;

                hr = idmo.Next(1, g, sn, IntPtr.Zero);
                DMOError.ThrowExceptionForHR(hr);

                if (hr > 0)
                {
                    break;
                }

                hr = dmoWrapperFilter.Init(g[0], Guid.Empty);

                if (hr >= 0)
                {
                    m_impi = dmoWrapperFilter as IMediaParamInfo;
                    if (m_impi != null)
                    {
                        hr = m_impi.GetParamCount(out iCount);
                    }
                    else
                    {
                        iCount = 0;
                    }

                    if (iCount > 0)
                    {
                        Debug.WriteLine(string.Format("{0} {1} {2}", sn[0], iCount, g[0]));
                    }
                }
            } while (iCount >= 0);
        }
Exemplo n.º 6
0
        public Nullable <Pair <Guid, Guid> > ReadDMOGuids()
        {
            IDMOWrapperFilter idmo = BaseFilter as IDMOWrapperFilter;

            if (idmo == null)
            {
                return(null);
            }
            IPersistStream ips = BaseFilter as IPersistStream;

            if (ips == null)
            {
                return(null);
            }
            IntPtr hg = Marshal.AllocHGlobal(10240);

            try
            {
                IStream stream;
                Graph.CheckHR(FilterGraphTools.CreateStreamOnHGlobal(hg, false, out stream), "CreateStreamOnHGlobal");
                Graph.CheckHR(ips.Save(stream, false), "IPersistStream::Save");
                IntPtr ppos = Marshal.AllocHGlobal(8);
                stream.Seek(0, 1, ppos);
                long pos = Marshal.ReadInt64(ppos);
                if (pos >= 32)
                {
                    byte[] data1 = new byte[16];
                    byte[] data2 = new byte[16];
                    Marshal.Copy(hg, data1, 0, 16);
                    IntPtr hg16 = new IntPtr(hg.ToInt64() + 16);
                    Marshal.Copy(hg16, data2, 0, 16);
                    Guid g1 = new Guid(data1);
                    Guid g2 = new Guid(data2);
                    return(new Pair <Guid, Guid>(g1, g2));
                }
            }
            finally
            {
                Marshal.FreeHGlobal(hg);
            }
            return(null);
        }
Exemplo n.º 7
0
        ///////////////////////////////////////////////////////////////////////////////
        // Inherited methods                                                         //
        ///////////////////////////////////////////////////////////////////////////////
        #region OVERRIDES
        #endregion //OVERRIDES

        ///////////////////////////////////////////////////////////////////////////////
        // Eventhandler                                                              //
        ///////////////////////////////////////////////////////////////////////////////
        #region EVENTS

        ///////////////////////////////////////////////////////////////////////////////
        // Eventhandler for UI, Menu, Buttons, Toolbars etc.                         //
        ///////////////////////////////////////////////////////////////////////////////
        #region WINDOWSEVENTHANDLER
        #endregion //WINDOWSEVENTHANDLER

        ///////////////////////////////////////////////////////////////////////////////
        // Eventhandler for Custom Defined Events                                    //
        ///////////////////////////////////////////////////////////////////////////////
        #region CUSTOMEVENTHANDLER
        #endregion //CUSTOMEVENTHANDLER

        #endregion //EVENTS

        ///////////////////////////////////////////////////////////////////////////////
        // Methods and Eventhandling for Background tasks                            //
        ///////////////////////////////////////////////////////////////////////////////
        #region BACKGROUNDWORKER
        #endregion //BACKGROUNDWORKER

        ///////////////////////////////////////////////////////////////////////////////
        // Methods for doing main class job                                          //
        ///////////////////////////////////////////////////////////////////////////////
        #region PRIVATEMETHODS

        /// <summary>
        ///  Create a new filter graph and add filters (devices, compressors,
        ///  misc), but leave the filters unconnected. Call renderGraph()
        ///  to connect the filters.
        /// </summary>
        /// <returns>True if successful created the graph.</returns>
        protected bool createGraph()
        {
            int hr;

            try
            {
                // Garbage collect, ensure that previous filters are released
                GC.Collect();

                // Get the graphbuilder object
                this.graphBuilder = new FilterGraph() as IFilterGraph2;

                // Get a ICaptureGraphBuilder2 to help build the graph
                this.captureGraphBuilder = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;

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

#if DEBUG
                this.rotCookie = new DsROTEntry(this.graphBuilder);
#endif

                // this.screenCaptureFilter = (IBaseFilter)new OgamaScreenCaptureFilter();

                // Get the ogama screen capture device and add it to the filter graph
                this.screenCaptureFilter = DirectShowUtils.CreateFilter(FilterCategory.VideoInputDevice, "OgamaCapture");

                hr = this.graphBuilder.AddFilter(this.screenCaptureFilter, "OgamaCapture");
                DsError.ThrowExceptionForHR(hr);

                // Query the interface for the screen capture Filter
                var ogamaFilter = this.screenCaptureFilter as IOgamaScreenCapture;

                hr = ogamaFilter.set_Monitor(this.monitorIndex);
                DsError.ThrowExceptionForHR(hr);

                hr = ogamaFilter.set_Framerate(this.frameRate);
                DsError.ThrowExceptionForHR(hr);

                //// Get the IAMStreamConfig from the filter so we can configure it
                //var videoStreamConfig = this.screenCaptureFilter as IAMStreamConfig;

                var resolution = PresentationScreen.GetPresentationResolution();
                //hr = videoStreamConfig.SetFormat(this.CreateVideoMediaType(24, resolution.Width, resolution.Height));
                //DsError.ThrowExceptionForHR(hr);

                this.smartTeeFilter = new SmartTee() as IBaseFilter;
                hr = this.graphBuilder.AddFilter(this.smartTeeFilter, "Smart Tee");
                DsError.ThrowExceptionForHR(hr);

                if (SecondaryScreen.SystemHasSecondaryScreen())
                {
                    // Add a DMO Wrapper Filter
                    this.dmoFilter        = (IBaseFilter) new DMOWrapperFilter();
                    this.dmoWrapperFilter = (IDMOWrapperFilter)this.dmoFilter;

                    // But it is more useful to show how to scan for the DMO
                    var g = this.FindGuid("DmoOverlay", DMOCategory.VideoEffect);

                    hr = this.dmoWrapperFilter.Init(g, DMOCategory.VideoEffect);
                    DMOError.ThrowExceptionForHR(hr);

                    this.SetDMOParams(this.dmoFilter);

                    // Add it to the Graph
                    hr = this.graphBuilder.AddFilter(this.dmoFilter, "DMO Filter");
                    DsError.ThrowExceptionForHR(hr);

                    var dmo = (IMediaObject)this.dmoFilter;
                    hr = dmo.SetInputType(0, this.CreateVideoMediaType(24, resolution.Width, resolution.Height), DMOSetType.None);
                    DsError.ThrowExceptionForHR(hr);
                    hr = dmo.SetOutputType(0, this.CreateVideoMediaType(24, resolution.Width, resolution.Height), DMOSetType.None);
                    DsError.ThrowExceptionForHR(hr);
                }

                // Get the video compressor and add it to the filter graph
                // Create the filter for the selected video compressor
                this.videoCompressorFilter = DirectShowUtils.CreateFilter(
                    FilterCategory.VideoCompressorCategory,
                    this.videoCompressorName);
                hr = this.graphBuilder.AddFilter(this.videoCompressorFilter, "Video Compressor");
                DsError.ThrowExceptionForHR(hr);

                // Render the file writer portion of graph (mux -> file)
                hr = this.captureGraphBuilder.SetOutputFileName(
                    MediaSubType.Avi,
                    this.tempFilename,
                    out this.muxFilter,
                    out this.fileWriterFilter);
                DsError.ThrowExceptionForHR(hr);

                //// Disable overwrite
                //// hr = this.fileWriterFilter.SetMode(AMFileSinkFlags.None);
                //// DsError.ThrowExceptionForHR(hr);
                hr = this.captureGraphBuilder.AllocCapFile(this.tempFilename, 10000000);
                DsError.ThrowExceptionForHR(hr);

                if (SecondaryScreen.SystemHasSecondaryScreen())
                {
                    hr = this.captureGraphBuilder.RenderStream(null, null, this.screenCaptureFilter, null, this.smartTeeFilter);
                    DsError.ThrowExceptionForHR(hr);

                    hr = this.captureGraphBuilder.RenderStream(
                        null,
                        null,
                        this.smartTeeFilter,
                        this.videoCompressorFilter,
                        this.muxFilter);
                    DsError.ThrowExceptionForHR(hr);

                    hr = this.captureGraphBuilder.RenderStream(null, null, this.smartTeeFilter, null, this.dmoFilter);
                    DsError.ThrowExceptionForHR(hr);

                    hr = this.captureGraphBuilder.RenderStream(null, null, this.dmoFilter, null, null);
                    DsError.ThrowExceptionForHR(hr);
                }
                else
                {
                    hr = this.captureGraphBuilder.RenderStream(
                        null,
                        null,
                        this.screenCaptureFilter,
                        this.videoCompressorFilter,
                        this.muxFilter);
                    DsError.ThrowExceptionForHR(hr);
                }

                // IMediaFilter filter = this.graphBuilder as IMediaFilter;
                // IReferenceClock clock;
                // filter.GetSyncSource(out clock);
                hr = this.graphBuilder.SetDefaultSyncSource();
                DsError.ThrowExceptionForHR(hr);

                // Retreive the media control interface (for starting/stopping graph)
                this.mediaControl = (IMediaControl)this.graphBuilder;
            }
            catch (Exception ex)
            {
                ExceptionMethods.HandleException(ex);
                return(false);
            }

            return(true);
        }
Exemplo n.º 8
0
        private void BuildGraph()
        {
            int  hr = 0;
            Guid wavesReverbDMO = new Guid("87fc0268-9a55-4360-95aa-004a1d9de26c");
            IPin pinIn, pinOut;

            graphBuilder = (IFilterGraph2) new FilterGraph();

            // Add a source filter
            hr = graphBuilder.AddSourceFilter(@"..\..\..\Resources\foo.avi", "foo.avi", out fileSource);
            DsError.ThrowExceptionForHR(hr);

            // Add an Avi Splitter
            aviSplitter = (IBaseFilter) new AviSplitter();
            hr          = graphBuilder.AddFilter(aviSplitter, "Splitter");
            DsError.ThrowExceptionForHR(hr);

            // Add a DMO Wrapper Filter
            dmoFilter        = (IBaseFilter) new DMOWrapperFilter();
            dmoWrapperFilter = (IDMOWrapperFilter)dmoFilter;

            // IDMOWrapperFilter unique method is tested here
            //
            // Init this filter with WavesReverb DMO Object
            //
            hr = dmoWrapperFilter.Init(wavesReverbDMO, DMOCategory.AudioEffect);
            DsError.ThrowExceptionForHR(hr);

            // Add it to the Graph
            hr = graphBuilder.AddFilter(dmoFilter, "DMO Filter");
            DsError.ThrowExceptionForHR(hr);

            // Add an audio renderer
            directSoundDevice = (IBaseFilter) new DSoundRender();
            hr = graphBuilder.AddFilter(directSoundDevice, "DirectSound Device");
            DsError.ThrowExceptionForHR(hr);

            // Connect Source filter with Avi Splitter
            pinOut = DsFindPin.ByDirection(fileSource, PinDirection.Output, 0);
            pinIn  = DsFindPin.ByDirection(aviSplitter, PinDirection.Input, 0);
            hr     = graphBuilder.Connect(pinOut, pinIn);
            DsError.ThrowExceptionForHR(hr);
            Marshal.ReleaseComObject(pinOut);
            Marshal.ReleaseComObject(pinIn);

            // Connect Avi Splitter audio (2nd) pin with DMO Wrapper
            // Should add an audio codec between the 2 filters
            pinOut = DsFindPin.ByDirection(aviSplitter, PinDirection.Output, 1);
            pinIn  = DsFindPin.ByDirection(dmoFilter, PinDirection.Input, 0);
            hr     = graphBuilder.Connect(pinOut, pinIn);
            DsError.ThrowExceptionForHR(hr);
            Marshal.ReleaseComObject(pinOut);
            Marshal.ReleaseComObject(pinIn);

            // Connect DMO Wrapper with the audio renderer
            pinOut = DsFindPin.ByDirection(dmoFilter, PinDirection.Output, 0);
            pinIn  = DsFindPin.ByDirection(directSoundDevice, PinDirection.Input, 0);
            hr     = graphBuilder.Connect(pinOut, pinIn);
            DsError.ThrowExceptionForHR(hr);
            Marshal.ReleaseComObject(pinOut);
            Marshal.ReleaseComObject(pinIn);


            // Run this graph (just for fun)
            hr = (graphBuilder as IMediaControl).Run();
            DsError.ThrowExceptionForHR(hr);

            System.Threading.Thread.Sleep(4000);
        }
Exemplo n.º 9
0
        ///////////////////////////////////////////////////////////////////////////////
        // Inherited methods                                                         //
        ///////////////////////////////////////////////////////////////////////////////
        #region OVERRIDES
        #endregion //OVERRIDES

        ///////////////////////////////////////////////////////////////////////////////
        // Eventhandler                                                              //
        ///////////////////////////////////////////////////////////////////////////////
        #region EVENTS

        ///////////////////////////////////////////////////////////////////////////////
        // Eventhandler for UI, Menu, Buttons, Toolbars etc.                         //
        ///////////////////////////////////////////////////////////////////////////////
        #region WINDOWSEVENTHANDLER
        #endregion //WINDOWSEVENTHANDLER

        ///////////////////////////////////////////////////////////////////////////////
        // Eventhandler for Custom Defined Events                                    //
        ///////////////////////////////////////////////////////////////////////////////
        #region CUSTOMEVENTHANDLER
        #endregion //CUSTOMEVENTHANDLER

        #endregion //EVENTS

        ///////////////////////////////////////////////////////////////////////////////
        // Methods and Eventhandling for Background tasks                            //
        ///////////////////////////////////////////////////////////////////////////////
        #region BACKGROUNDWORKER
        #endregion //BACKGROUNDWORKER

        ///////////////////////////////////////////////////////////////////////////////
        // Methods for doing main class job                                          //
        ///////////////////////////////////////////////////////////////////////////////
        #region PRIVATEMETHODS

        /// <summary>
        /// Build the filter graph
        /// </summary>
        /// <returns>True if successful, otherwise false.</returns>
        private bool SetupGraph()
        {
            int hr;

            // Get the graphbuilder object
            this.filterGraph = new FilterGraph() as IFilterGraph2;

            // Get a ICaptureGraphBuilder2 to help build the graph
            ICaptureGraphBuilder2 captureGraph = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            try
            {
                // Link the ICaptureGraphBuilder2 to the IFilterGraph2
                hr = captureGraph.SetFiltergraph(this.filterGraph);
                DsError.ThrowExceptionForHR(hr);

#if DEBUG
                // Allows you to view the graph with GraphEdit File/Connect
                this.dsRot = new DsROTEntry(this.filterGraph);
#endif

                // Our data source one
                IBaseFilter bitmapSource = (IBaseFilter) new GenericSampleSourceFilter();

                // Create a DMO Wrapper Filter
                IBaseFilter       dmoFilter        = (IBaseFilter) new DMOWrapperFilter();
                IDMOWrapperFilter dmoWrapperFilter = (IDMOWrapperFilter)dmoFilter;

                Guid g = this.FindGuid("DmoMixer", DMOCategory.VideoEffect);

                hr = dmoWrapperFilter.Init(g, DMOCategory.VideoEffect);
                DMOError.ThrowExceptionForHR(hr);

                try
                {
                    // Get the pin from the filter so we can configure it
                    IPin ipin = DsFindPin.ByDirection(bitmapSource, PinDirection.Output, 0);

                    try
                    {
                        // Configure the pin using the provided BitmapInfo
                        this.ConfigurePusher((IGenericSampleConfig)ipin);
                    }
                    catch (Exception ex)
                    {
                        ExceptionMethods.HandleException(ex);
                        return(false);
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(ipin);
                    }

                    // Add the bitmap source to the graph
                    hr = this.filterGraph.AddFilter(bitmapSource, "BitmapSourceFilter");
                    DsError.ThrowExceptionForHR(hr);

                    IBaseFilter webcamSource = null;
                    if (this.videoExportProperties.UserVideoProperties.IsStreamRendered)
                    {
                        hr = this.filterGraph.AddSourceFilter(
                            this.videoExportProperties.UserVideoTempFile,
                            "WebcamVideoSource",
                            out webcamSource);
                        DsError.ThrowExceptionForHR(hr);
                    }

                    // Add it to the Graph
                    hr = this.filterGraph.AddFilter(dmoFilter, "DMO Filter");
                    DsError.ThrowExceptionForHR(hr);

                    this.SetDMOParams(dmoFilter, this.videoExportProperties);

                    // Add the Video compressor filter to the graph
                    if (this.videoCompressor != null)
                    {
                        hr = this.filterGraph.AddFilter(this.videoCompressor, "video compressor filter");
                        DsError.ThrowExceptionForHR(hr);
                    }

                    // Create the file writer part of the graph.
                    // SetOutputFileName does this for us, and returns the mux and sink
                    IBaseFilter     mux;
                    IFileSinkFilter sink;
                    hr = captureGraph.SetOutputFileName(MediaSubType.Avi, this.videoExportProperties.OutputVideoProperties.Filename, out mux, out sink);
                    DsError.ThrowExceptionForHR(hr);

                    // Connect the bitmap source to the dmo mixer filter
                    hr = captureGraph.RenderStream(
                        null,
                        null,
                        bitmapSource,
                        null,
                        dmoFilter);
                    DsError.ThrowExceptionForHR(hr);

                    // If there is a webcam source connect it to the second input of the dmo mixer
                    if (webcamSource != null)
                    {
                        hr = captureGraph.RenderStream(
                            null,
                            null,
                            webcamSource,
                            null,
                            dmoFilter);
                        DsError.ThrowExceptionForHR(hr);
                    }

                    // Create a smart tee filter to enable preview and capture pins
                    IBaseFilter smartTee = new SmartTee() as IBaseFilter;

                    // Add the filter to the graph
                    hr = this.filterGraph.AddFilter(smartTee, "Smart Tee");
                    DsError.ThrowExceptionForHR(hr);

                    // Connect the dmo mixer output to the smart tee
                    hr = captureGraph.RenderStream(
                        null,
                        null,
                        dmoFilter,
                        null,
                        smartTee);
                    DsError.ThrowExceptionForHR(hr);

                    // Render the smart tee capture pin to the capture part including
                    // compressor to the file muxer.
                    hr = captureGraph.RenderStream(
                        null,
                        null,
                        smartTee,
                        this.videoCompressor,
                        mux);
                    DsError.ThrowExceptionForHR(hr);

                    // Render the smart tee preview pin to the default video renderer
                    hr = captureGraph.RenderStream(
                        null,
                        null,
                        smartTee,
                        null,
                        null);
                    DsError.ThrowExceptionForHR(hr);

                    // Configure the Video Window
                    this.videoWindow = this.filterGraph as IVideoWindow;
                    this.ConfigureVideoWindow(this.videoWindow, this.previewWindow);
                }
                catch (Exception ex)
                {
                    ExceptionMethods.HandleException(ex);
                    return(false);
                }
                finally
                {
                    Marshal.ReleaseComObject(bitmapSource);
                }

                // Grab some other interfaces
                this.mediaControl = this.filterGraph as IMediaControl;
            }
            catch (Exception ex)
            {
                ExceptionMethods.HandleException(ex);
                return(false);
            }
            finally
            {
                Marshal.ReleaseComObject(captureGraph);
            }

            return(true);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Connecte le File Splitter et le renderer vidéo en créant le décodeur vidéo.
        /// </summary>
        /// <param name="graph">Le graphe.</param>
        /// <param name="filtersConfig">La configuration pour ce fichier.</param>
        /// <param name="parserOutputVideoPin">Le pin de sortie vidéo</param>
        /// <param name="videoRendererInputPin">Le pin d'entrée du Renderer.</param>
        internal static void ConnectSplitterAndRendererWithDecoder(IGraphBuilder graph, ExtensionFiltersSource filtersConfig,
                                                                   IPin parserOutputVideoPin, IPin videoRendererInputPin)
        {
            FilterSource videoFilterSource = filtersConfig.VideoDecoder;

            switch (videoFilterSource.SourceType)
            {
            case FilterSourceTypeEnum.Auto:

                int hr = graph.Connect(parserOutputVideoPin, videoRendererInputPin);
                DsError.ThrowExceptionForHR(hr);

                break;

            case FilterSourceTypeEnum.External:
                if (new Guid(videoFilterSource.ExternalCLSID) == new Guid(CLSID_VIDEO_DECODER_DMO))
                {
                    // The DMO filter is handled differently
                    DMOWrapperFilter  dmoFilter = new DMOWrapperFilter();
                    IDMOWrapperFilter wrapper   = (IDMOWrapperFilter)dmoFilter;
                    hr = wrapper.Init(new Guid(CLSID_VIDEO_DECODER_DMO), DirectShowLib.DMO.DMOCategory.VideoDecoder);

                    DsError.ThrowExceptionForHR(hr);

                    if (dmoFilter is IBaseFilter decoderFilter)
                    {
                        hr = graph.AddFilter(decoderFilter, "WMVideo Decoder DMO");
                        DsError.ThrowExceptionForHR(hr);

                        IPin wmvDecoderInputPin = DsFindPin.ByDirection(decoderFilter, PinDirection.Input, 0);
                        hr = graph.ConnectDirect(parserOutputVideoPin, wmvDecoderInputPin, null);
                        DsError.ThrowExceptionForHR(hr);

                        IPin wmvDecoderOutputPin = DsFindPin.ByDirection(decoderFilter, PinDirection.Output, 0);
                        hr = graph.ConnectDirect(wmvDecoderOutputPin, videoRendererInputPin, null);
                        DsError.ThrowExceptionForHR(hr);

                        SafeRelease(wmvDecoderInputPin);
                        SafeRelease(wmvDecoderOutputPin);
                    }
                    else
                    {
                        wrapper = null;
                        SafeRelease(dmoFilter);
                        dmoFilter = null;
                    }
                }
                else
                {
                    Type        filterType     = null;
                    IBaseFilter externalFilter = null;

                    CreateFilter(videoFilterSource.ExternalCLSID, videoFilterSource.Name, ref filterType, ref externalFilter);

                    hr = graph.AddFilter(externalFilter, videoFilterSource.Name);
                    DsError.ThrowExceptionForHR(hr);

                    IPin externalDecoderInputPin = DsFindPin.ByDirection(externalFilter, PinDirection.Input, 0);
                    hr = graph.ConnectDirect(parserOutputVideoPin, externalDecoderInputPin, null);
                    DsError.ThrowExceptionForHR(hr);

                    IPin externalDecoderOutputPin = DsFindPin.ByDirection(externalFilter, PinDirection.Output, 0);
                    hr = graph.ConnectDirect(externalDecoderOutputPin, videoRendererInputPin, null);
                    DsError.ThrowExceptionForHR(hr);

                    SafeRelease(externalDecoderInputPin);
                    SafeRelease(externalDecoderOutputPin);
                }


                break;

            default:
                throw new ArgumentOutOfRangeException($"{nameof(videoFilterSource)}.{nameof(FilterSource.SourceType)}");
            }
        }
Exemplo n.º 11
0
    ///////////////////////////////////////////////////////////////////////////////
    // Inherited methods                                                         //
    ///////////////////////////////////////////////////////////////////////////////
    #region OVERRIDES
    #endregion //OVERRIDES

    ///////////////////////////////////////////////////////////////////////////////
    // Eventhandler                                                              //
    ///////////////////////////////////////////////////////////////////////////////
    #region EVENTS

    ///////////////////////////////////////////////////////////////////////////////
    // Eventhandler for UI, Menu, Buttons, Toolbars etc.                         //
    ///////////////////////////////////////////////////////////////////////////////
    #region WINDOWSEVENTHANDLER
    #endregion //WINDOWSEVENTHANDLER

    ///////////////////////////////////////////////////////////////////////////////
    // Eventhandler for Custom Defined Events                                    //
    ///////////////////////////////////////////////////////////////////////////////
    #region CUSTOMEVENTHANDLER
    #endregion //CUSTOMEVENTHANDLER

    #endregion //EVENTS

    ///////////////////////////////////////////////////////////////////////////////
    // Methods and Eventhandling for Background tasks                            //
    ///////////////////////////////////////////////////////////////////////////////
    #region BACKGROUNDWORKER
    #endregion //BACKGROUNDWORKER

    ///////////////////////////////////////////////////////////////////////////////
    // Methods for doing main class job                                          //
    ///////////////////////////////////////////////////////////////////////////////
    #region PRIVATEMETHODS

    /// <summary> 
    ///  Create a new filter graph and add filters (devices, compressors, 
    ///  misc), but leave the filters unconnected. Call renderGraph()
    ///  to connect the filters.
    /// </summary>
    /// <returns>True if successful created the graph.</returns>
    protected bool createGraph()
    {
      int hr;

      try
      {
        // Garbage collect, ensure that previous filters are released
        GC.Collect();

        // Get the graphbuilder object
        this.graphBuilder = new FilterGraph() as IFilterGraph2;

        // Get a ICaptureGraphBuilder2 to help build the graph
        this.captureGraphBuilder = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;

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

#if DEBUG
        this.rotCookie = new DsROTEntry(this.graphBuilder);
#endif

       // this.screenCaptureFilter = (IBaseFilter)new OgamaScreenCaptureFilter();

        // Get the ogama screen capture device and add it to the filter graph
        this.screenCaptureFilter = DirectShowUtils.CreateFilter(FilterCategory.VideoInputDevice, "OgamaCapture");

        hr = this.graphBuilder.AddFilter(this.screenCaptureFilter, "OgamaCapture");
        DsError.ThrowExceptionForHR(hr);

        // Query the interface for the screen capture Filter
        var ogamaFilter = this.screenCaptureFilter as IOgamaScreenCapture;

        hr = ogamaFilter.set_Monitor(this.monitorIndex);
        DsError.ThrowExceptionForHR(hr);

        hr = ogamaFilter.set_Framerate(this.frameRate);
        DsError.ThrowExceptionForHR(hr);

        //// Get the IAMStreamConfig from the filter so we can configure it 
        //var videoStreamConfig = this.screenCaptureFilter as IAMStreamConfig;

        var resolution = PresentationScreen.GetPresentationResolution();
        //hr = videoStreamConfig.SetFormat(this.CreateVideoMediaType(24, resolution.Width, resolution.Height));
        //DsError.ThrowExceptionForHR(hr);

        this.smartTeeFilter = new SmartTee() as IBaseFilter;
        hr = this.graphBuilder.AddFilter(this.smartTeeFilter, "Smart Tee");
        DsError.ThrowExceptionForHR(hr);

        if (SecondaryScreen.SystemHasSecondaryScreen())
        {
          // Add a DMO Wrapper Filter
          this.dmoFilter = (IBaseFilter)new DMOWrapperFilter();
          this.dmoWrapperFilter = (IDMOWrapperFilter)this.dmoFilter;

          // But it is more useful to show how to scan for the DMO
          var g = this.FindGuid("DmoOverlay", DMOCategory.VideoEffect);

          hr = this.dmoWrapperFilter.Init(g, DMOCategory.VideoEffect);
          DMOError.ThrowExceptionForHR(hr);

          this.SetDMOParams(this.dmoFilter);

          // Add it to the Graph
          hr = this.graphBuilder.AddFilter(this.dmoFilter, "DMO Filter");
          DsError.ThrowExceptionForHR(hr);

          var dmo = (IMediaObject)this.dmoFilter;
          hr = dmo.SetInputType(0, this.CreateVideoMediaType(24, resolution.Width, resolution.Height), DMOSetType.None);
          DsError.ThrowExceptionForHR(hr);
          hr = dmo.SetOutputType(0, this.CreateVideoMediaType(24, resolution.Width, resolution.Height), DMOSetType.None);
          DsError.ThrowExceptionForHR(hr);
        }

        // Get the video compressor and add it to the filter graph
        // Create the filter for the selected video compressor
        this.videoCompressorFilter = DirectShowUtils.CreateFilter(
          FilterCategory.VideoCompressorCategory,
          this.videoCompressorName);
        hr = this.graphBuilder.AddFilter(this.videoCompressorFilter, "Video Compressor");
        DsError.ThrowExceptionForHR(hr);

        // Render the file writer portion of graph (mux -> file)
        hr = this.captureGraphBuilder.SetOutputFileName(
          MediaSubType.Avi,
          this.tempFilename,
          out this.muxFilter,
          out this.fileWriterFilter);
        DsError.ThrowExceptionForHR(hr);

        //// Disable overwrite
        //// hr = this.fileWriterFilter.SetMode(AMFileSinkFlags.None);
        //// DsError.ThrowExceptionForHR(hr);
        hr = this.captureGraphBuilder.AllocCapFile(this.tempFilename, 10000000);
        DsError.ThrowExceptionForHR(hr);

        if (SecondaryScreen.SystemHasSecondaryScreen())
        {
          hr = this.captureGraphBuilder.RenderStream(null, null, this.screenCaptureFilter, null, this.smartTeeFilter);
          DsError.ThrowExceptionForHR(hr);

          hr = this.captureGraphBuilder.RenderStream(
            null,
            null,
            this.smartTeeFilter,
            this.videoCompressorFilter,
            this.muxFilter);
          DsError.ThrowExceptionForHR(hr);

          hr = this.captureGraphBuilder.RenderStream(null, null, this.smartTeeFilter, null, this.dmoFilter);
          DsError.ThrowExceptionForHR(hr);

          hr = this.captureGraphBuilder.RenderStream(null, null, this.dmoFilter, null, null);
          DsError.ThrowExceptionForHR(hr);
        }
        else
        {
          hr = this.captureGraphBuilder.RenderStream(
            null,
            null,
            this.screenCaptureFilter,
            this.videoCompressorFilter,
            this.muxFilter);
          DsError.ThrowExceptionForHR(hr);
        }

        // IMediaFilter filter = this.graphBuilder as IMediaFilter;
        // IReferenceClock clock;
        // filter.GetSyncSource(out clock);
        hr = this.graphBuilder.SetDefaultSyncSource();
        DsError.ThrowExceptionForHR(hr);

        // Retreive the media control interface (for starting/stopping graph)
        this.mediaControl = (IMediaControl)this.graphBuilder;
      }
      catch (Exception ex)
      {
        ExceptionMethods.HandleException(ex);
        return false;
      }

      return true;
    }
Exemplo n.º 12
0
        private void BuildGraph(Control hControl)
        {
            int hr;

            DsDevice []       devs;
            IBaseFilter       ibfSource        = null;
            IBaseFilter       dmoFilter        = null;
            IBaseFilter       ibfRender        = null;
            IDMOWrapperFilter dmoWrapperFilter = null;

            ICaptureGraphBuilder2 icgb = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            graphBuilder = (IFilterGraph2) new FilterGraph();
#if DEBUG
            m_rot = new DsROTEntry(graphBuilder);
#endif

            hr = icgb.SetFiltergraph(graphBuilder);
            DsError.ThrowExceptionForHR(hr);

            devs = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);

            if (devs.Length < 1)
            {
                throw new Exception("This sample requires a capture device.  If you don't " +
                                    "have a capture device, change the BuildGraph routine to use AddSourceFilter " +
                                    "and use a file.");
            }

            // Add a source filter
            hr = graphBuilder.AddSourceFilterForMoniker(devs[0].Mon, null, "Video Input Device", out ibfSource);
            DsError.ThrowExceptionForHR(hr);

            // Add a DMO Wrapper Filter
            dmoFilter        = (IBaseFilter) new DMOWrapperFilter();
            dmoWrapperFilter = (IDMOWrapperFilter)dmoFilter;

            // Since I know the guid of the DMO I am looking for, I *could* do this.
            //hr = dmoWrapperFilter.Init(new Guid("{7EF28FD7-E88F-45bb-9CDD-8A62956F2D75}"), DMOCatergory.VideoEffect);
            //DMOError.ThrowExceptionForHR(hr);

            // But it is more useful to show how to scan for the DMO
            Guid g = FindGuid("DmoFlip", DMOCategory.VideoEffect);

            hr = dmoWrapperFilter.Init(g, DMOCategory.VideoEffect);
            DMOError.ThrowExceptionForHR(hr);

            SetDMOParams(dmoFilter);

            // Add it to the Graph
            hr = graphBuilder.AddFilter(dmoFilter, "DMO Filter");
            DsError.ThrowExceptionForHR(hr);

            ibfRender = (IBaseFilter) new VideoRenderer();
            hr        = graphBuilder.AddFilter(ibfRender, "renderer");
            DsError.ThrowExceptionForHR(hr);

            hr = icgb.RenderStream(null, null, ibfSource, dmoFilter, ibfRender);
            DsError.ThrowExceptionForHR(hr);

            ConfigVideo(graphBuilder as IVideoWindow, hControl);

            Marshal.ReleaseComObject(ibfSource);
            Marshal.ReleaseComObject(ibfRender);
        }
Exemplo n.º 13
0
        public void SetupGraph()
        {
            GraphBuilder = (IGraphBuilder) new FilterGraph();

            // Get ICaptureGraphBuilder2 to build the graph
            CaptureGraphBuilder2 = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;

            try
            {
                ReturnHR = CaptureGraphBuilder2.SetFiltergraph(GraphBuilder);

                IBaseFilter source_filter = null;

                ReturnHR = GraphBuilder.AddSourceFilter(InputFile, "Source Filter", out source_filter);

                IBaseFilter       wmv_video_decoder_dmo = (IBaseFilter) new DMOWrapperFilter();
                IDMOWrapperFilter dmo_wrapper_filter_v  = (IDMOWrapperFilter)wmv_video_decoder_dmo;

                ReturnHR = dmo_wrapper_filter_v.Init(new Guid("{82D353DF-90BD-4382-8BC2-3F6192B76E34}"), DMOCategory.VideoDecoder);
                ReturnHR = GraphBuilder.AddFilter(wmv_video_decoder_dmo, "Wmv Video Decoder DMO");

                IBaseFilter       wmv_audio_decoder_dmo = (IBaseFilter) new DMOWrapperFilter();
                IDMOWrapperFilter dmo_wrapper_filter_a  = (IDMOWrapperFilter)wmv_audio_decoder_dmo;

                ReturnHR = dmo_wrapper_filter_a.Init(new Guid("{2EEB4ADF-4578-4D10-BCA7-BB955F56320A}"), DMOCategory.AudioDecoder);
                ReturnHR = GraphBuilder.AddFilter(wmv_audio_decoder_dmo, "Wmv Audio Decoder DMO");

                IBaseFilter vp8_encoder = (IBaseFilter) new VP8Encoder();
                ReturnHR = GraphBuilder.AddFilter(vp8_encoder, "VP8 Encoder");

                IVP8Encoder vp8_encoder_interface = (IVP8Encoder)vp8_encoder;
                if (target_bitrate != 0)
                {
                    vp8_encoder_interface.SetTargetBitrate(target_bitrate);
                }

                IBaseFilter webm_muxer = (IBaseFilter) new WebMMuxer();
                ReturnHR = GraphBuilder.AddFilter(webm_muxer, "WebM Muxer");

                IBaseFilter vorbis_encoder = (IBaseFilter) new VorbisEncoder();
                ReturnHR = GraphBuilder.AddFilter(vorbis_encoder, "Vorbis Encoder");

                IBaseFilter file_writer = (IBaseFilter) new FileWriter();
                ReturnHR = GraphBuilder.AddFilter(file_writer, "file writer");
                IFileSinkFilter filewriter_sink = file_writer as IFileSinkFilter;
                ReturnHR = filewriter_sink.SetFileName(OutputFile, null);

                ReturnHR = GraphBuilder.ConnectDirect(FindPin("Raw Video 1", source_filter), FindPin("in0", wmv_video_decoder_dmo), null);
                ReturnHR = GraphBuilder.ConnectDirect(FindPin("Raw Audio 0", source_filter), FindPin("in0", wmv_audio_decoder_dmo), null);
                ReturnHR = GraphBuilder.ConnectDirect(FindPin("out0", wmv_audio_decoder_dmo), FindPin("PCM In", vorbis_encoder), null);
                ReturnHR = GraphBuilder.ConnectDirect(FindPin("out0", wmv_video_decoder_dmo), FindPin("YUV", vp8_encoder), null);
                ReturnHR = GraphBuilder.ConnectDirect(FindPin("Vorbis Out", vorbis_encoder), FindPin("audio", webm_muxer), null);
                ReturnHR = GraphBuilder.ConnectDirect(FindPin("VP80", vp8_encoder), FindPin("video", webm_muxer), null);
                ReturnHR = GraphBuilder.ConnectDirect(FindPin("outpin", webm_muxer), FindPin("in", file_writer), null);
            }
            catch (Exception)
            {
                LogError("Failed to initialize FilterGraph.");
            }
            finally
            {
                if (CaptureGraphBuilder2 != null)
                {
                    Marshal.ReleaseComObject(CaptureGraphBuilder2);
                    CaptureGraphBuilder2 = null;
                }
            }
        }