Exemplo n.º 1
0
        public static IBaseFilter CreateAudioCompressor(DisposalCleanup dc, IGraphBuilder graph, IPin outPin,
                                                        AudioFormat settings)
        {
            if (dc == null) throw new ArgumentNullException("dc");
            if (graph == null) throw new ArgumentNullException("graph");
            if (outPin == null) throw new ArgumentNullException("outPin");
            if (settings == null) throw new ArgumentNullException("settings");

            int hr = 0;

            using (AudioCompressor compressor = AudioCompressorFactory.Create(settings))
            {
                IBaseFilter compressorFilter = compressor.Filter;
                dc.Add(compressorFilter);

                hr = graph.AddFilter(compressorFilter, settings.AudioCompressor);
                DsError.ThrowExceptionForHR(hr);

                FilterGraphTools.ConnectFilters(graph, outPin, compressorFilter, true);

                // set the media type on the output pin of the compressor
                if (compressor.MediaType != null)
                {
                    FilterGraphTools.SetFilterFormat(compressor.MediaType, compressorFilter);
                }

                return compressorFilter;
            }
        }
Exemplo n.º 2
0
        public static IBaseFilter RenderAsfWriterWithProfile(DisposalCleanup dc, IGraphBuilder graph, string profileData,
                                                             string outputFile)
        {
            if (dc == null) throw new ArgumentNullException("dc");
            if (graph == null) throw new ArgumentNullException("graph");
            if (string.IsNullOrEmpty(profileData)) throw new ArgumentNullException("profileData");
            if (string.IsNullOrEmpty(outputFile)) throw new ArgumentNullException("outputFile");

            int hr = 0;

            var asfWriterFilter = (IBaseFilter) new WMAsfWriter();
            dc.Add(asfWriterFilter);
            hr = graph.AddFilter(asfWriterFilter, Resources.DefaultAsfWriterName);
            DsError.ThrowExceptionForHR(hr);

            // Create an appropriate IWMProfile from the data
            IWMProfileManager profileManager = ProfileManager.CreateInstance();
            dc.Add(profileManager);

            IntPtr wmProfile = profileManager.LoadProfileByData(profileData);
            dc.Add(wmProfile);

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

            hr = ((IFileSinkFilter) asfWriterFilter).SetFileName(outputFile, null);
            DsError.ThrowExceptionForHR(hr);

            return asfWriterFilter;
        }
Exemplo n.º 3
0
        public static IBaseFilter RenderWavDestination(DisposalCleanup dc, IGraphBuilder graph)
        {
            if (dc == null) throw new ArgumentNullException("dc");
            if (graph == null) throw new ArgumentNullException("graph");

            IBaseFilter wavDest =
                FilterGraphTools.AddFilterFromClsid(graph, WavDestinationFilterId, Resources.DefaultWavDestinationName);
            dc.Add(wavDest);

            return wavDest;
        }
Exemplo n.º 4
0
        public static IBaseFilter RenderFileDestination(DisposalCleanup dc, IGraphBuilder graph, string outputFile)
        {
            if (dc == null) throw new ArgumentNullException("dc");
            if (graph == null) throw new ArgumentNullException("graph");
            if (string.IsNullOrEmpty(outputFile)) throw new ArgumentNullException("outputFile");

            int hr = 0;

            var fileFilter = (IBaseFilter) new FileWriter();

            hr = ((IFileSinkFilter) fileFilter).SetFileName(outputFile, null);
            DsError.ThrowExceptionForHR(hr);

            hr = graph.AddFilter(fileFilter, Resources.DefaultFileDestinationName);
            DsError.ThrowExceptionForHR(hr);

            dc.Add(fileFilter);

            return fileFilter;
        }
Exemplo n.º 5
0
        public static IBaseFilter RenderNull(DisposalCleanup dc, IGraphBuilder graph)
        {
            if (dc == null) throw new ArgumentNullException("dc");
            if (graph == null) throw new ArgumentNullException("graph");

            var filter = (IBaseFilter) new NullRenderer();
            dc.Add(filter);

            graph.AddFilter(filter, Resources.DefaultNullRendererName);

            return filter;
        }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
0
        protected virtual void DisposeRenderer(bool disposing)
        {
            if (disposing)
            {
                if (_cleanup != null)
                {
                    (_cleanup).Dispose();
                    _cleanup = null;
                }

                if (_timeline != null)
                {
                    _timeline.Dispose();
                    _timeline = null;
                }
            }

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

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

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