Пример #1
0
        private void RenderToWavDest(
            string outputFile,
            IBaseFilter audioCompressor,
            AMMediaType mediaType,
            ICallbackParticipant[] audioParticipants)
        {
            if (audioCompressor != null)
            {
                Cleanup.Add(audioCompressor);
            }

            int hr;

            if (FirstAudioGroup == null)
            {
                throw new SplicerException(Resources.ErrorNoAudioStreamToRender);
            }

            if (outputFile == null)
            {
                throw new SplicerException(Resources.ErrorInvalidOutputFileName);
            }

            // Contains useful routines for creating the graph
            var graphBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            Cleanup.Add(graphBuilder);

            try
            {
                hr = graphBuilder.SetFiltergraph(Graph);
                DESError.ThrowExceptionForHR(hr);

                IBaseFilter wavDestFilter = StandardFilters.RenderWavDestination(Cleanup, Graph);
                IBaseFilter fileSink      = StandardFilters.RenderFileDestination(Cleanup, Graph, outputFile);

                try
                {
                    RenderGroups(graphBuilder, audioCompressor, null, wavDestFilter, audioParticipants, null);

                    FilterGraphTools.ConnectFilters(Graph, wavDestFilter, fileSink, true);

                    // if supplied, apply the media type to the filter
                    if (mediaType != null)
                    {
                        FilterGraphTools.SetFilterFormat(mediaType, audioCompressor);
                    }

                    DisableClock();
                }
                finally
                {
                    if (wavDestFilter != null)
                    {
                        Marshal.ReleaseComObject(wavDestFilter);
                    }
                    if (fileSink != null)
                    {
                        Marshal.ReleaseComObject(fileSink);
                    }
                }
            }
            finally
            {
                Marshal.ReleaseComObject(graphBuilder);
            }
        }