Пример #1
0
        private void BuildGraph(string sFileName, out IFilterGraph2 graphBuilder, out IBaseFilter audioFilter)
        {
            int         hr           = 0;
            IBaseFilter sourceFilter = null;
            IPin        pinOut       = null;

            graphBuilder = new FilterGraph() as IFilterGraph2;
            audioFilter  = null;

            try
            {
                hr = graphBuilder.AddSourceFilter(sFileName, sFileName, out sourceFilter);
                Marshal.ThrowExceptionForHR(hr);

                audioFilter = (IBaseFilter) new DSoundRender();
                hr          = graphBuilder.AddFilter(audioFilter, "DirectSound Renderer");

                pinOut = DsFindPin.ByDirection(sourceFilter, PinDirection.Output, 0);

                hr = graphBuilder.RenderEx(pinOut, AMRenderExFlags.RenderToExistingRenderers, IntPtr.Zero);
                Marshal.ThrowExceptionForHR(hr);
            }
            catch
            {
                Marshal.ReleaseComObject(graphBuilder);
                throw;
            }
            finally
            {
                Marshal.ReleaseComObject(sourceFilter);
                Marshal.ReleaseComObject(pinOut);
            }
        }
        private void ConnectGraph(ref IFilterGraph2 graphBuilder, ref IBaseFilter sourceFilter, ref IBaseFilter vmr9Filter)
        {
            int  hr     = 0;
            IPin pinOut = null;

            try
            {
                pinOut = DsFindPin.ByDirection(sourceFilter, PinDirection.Output, 0);

                hr = graphBuilder.RenderEx(pinOut, AMRenderExFlags.RenderToExistingRenderers, IntPtr.Zero);
                Marshal.ThrowExceptionForHR(hr);
            }
            finally
            {
                Marshal.ReleaseComObject(pinOut);
            }
        }