Пример #1
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;
            }
        }
Пример #2
0
 /// <summary>Runs the conversion synchronously.</summary>
 /// <returns>The result of the conversion.</returns>
 public object Convert()
 {
     _cancellationPending = false;
     try
     {
         object result;
         using (_dc = new DisposalCleanup())
         {
             // Do the actual work
             result = DoWork();
         }
         OnConversionComplete(null, result);
         return(result);
     }
     catch (DirectShowException exc)
     {
         OnConversionComplete(exc, null);
         throw;
     }
     catch (Exception exc)
     {
         exc = new DirectShowException(exc);
         OnConversionComplete(exc, null);
         throw exc;
     }
 }
Пример #3
0
        public static IBaseFilter RenderAsfWriterWithProfile(DisposalCleanup dc, IGraphBuilder graph, string profileData,
                                                             string outputFile)
        {
            int hr = 0;

            IBaseFilter asfWriterFilter = (IBaseFilter) new WMAsfWriter();

            dc.Add(asfWriterFilter);
            hr = graph.AddFilter(asfWriterFilter, "ASF Writer");
            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
            IConfigAsfWriter2 configWriter = (IConfigAsfWriter2)asfWriterFilter;

            configWriter.ConfigureFilterUsingProfile(wmProfile);

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

            return(asfWriterFilter);
        }
Пример #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);
        }
Пример #5
0
        public void Dispose()
        {
            if (_dc != null)
            {
                ((IDisposable)_dc).Dispose();
                _dc = 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;
            }
        }
Пример #6
0
        public static IBaseFilter RenderWavDest(DisposalCleanup dc, IGraphBuilder graph)
        {
            IBaseFilter wavDest = FilterGraphTools.AddFilterFromClsid(graph, WavDestFilterId, "Wav DEST");

            dc.Add(wavDest);

            return(wavDest);
        }
Пример #7
0
        public static IBaseFilter RenderNull(DisposalCleanup dc, IGraphBuilder graph)
        {
            IBaseFilter filter = (IBaseFilter) new NullRenderer();

            dc.Add(filter);

            graph.AddFilter(filter, "Null Renderer");

            return(filter);
        }
Пример #8
0
        /// <summary>Connects together to graph filters.</summary>
        /// <param name="graph">The graph on which the filters exist.</param>
        /// <param name="source">The source filter.</param>
        /// <param name="outPinName">The name of the output pin on the source filter.</param>
        /// <param name="destination">The destination filter.</param>
        /// <param name="inPinName">The name of the input pin on the destination filter.</param>
        protected void Connect(IGraphBuilder graph, IBaseFilter source, string outPinName,
                               IBaseFilter destination, string inPinName)
        {
            IPin outPin = source.FindPin(outPinName);

            DisposalCleanup.Add(outPin);

            IPin inPin = destination.FindPin(inPinName);

            DisposalCleanup.Add(inPin);

            graph.Connect(outPin, inPin);
        }
Пример #9
0
        public static IBaseFilter RenderFileDestination(DisposalCleanup dc, IGraphBuilder graph, string outputFile)
        {
            int hr = 0;

            IBaseFilter fileFilter = (IBaseFilter) new FileWriter();

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

            hr = graph.AddFilter(fileFilter, "Output File");
            DsError.ThrowExceptionForHR(hr);

            dc.Add(fileFilter);

            return(fileFilter);
        }
Пример #10
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);
        }
Пример #11
0
        /// <summary>Do the conversion from DVR-MS to WAV.</summary>
        /// <returns>Null; ignored.</returns>
        protected override object DoWork()
        {
            // Get the filter graph
            object filterGraph = ClassId.CoCreateInstance(ClassId.FilterGraph);

            DisposalCleanup.Add(filterGraph);
            IGraphBuilder graph = (IGraphBuilder)filterGraph;

            // Add the ASF writer and set the output name
            IBaseFilter asfWriterFilter = (IBaseFilter)ClassId.CoCreateInstance(ClassId.WMAsfWriter);

            DisposalCleanup.Add(asfWriterFilter);
            graph.AddFilter(asfWriterFilter, null);
            IFileSinkFilter sinkFilter = (IFileSinkFilter)asfWriterFilter;

            sinkFilter.SetFileName(OutputFilePath, null);

            // Set the profile to be used for conversion
            if (_profilePath != null && _profilePath.Trim().Length > 0)
            {
                // Load the profile XML contents
                string profileData;
                using (StreamReader reader = new StreamReader(File.OpenRead(_profilePath)))
                {
                    profileData = reader.ReadToEnd();
                }

                // Create an appropriate IWMProfile from the data
                IWMProfileManager profileManager = ProfileManager.CreateInstance();
                DisposalCleanup.Add(profileManager);
                IntPtr wmProfile = profileManager.LoadProfileByData(profileData);
                DisposalCleanup.Add(wmProfile);

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

            // Add the source filter; should connect automatically through the appropriate transform filters
            graph.RenderFile(InputFilePath, null);

            // Run the graph to completion
            RunGraph(graph, asfWriterFilter);

            return(null);
        }
Пример #12
0
        /// <summary>Do the conversion from DVR-MS to WAV.</summary>
        /// <returns>Null; ignored.</returns>
        protected override object DoWork()
        {
            // Get the filter graph
            object filterGraph = ClassId.CoCreateInstance(ClassId.FilterGraph);

            DisposalCleanup.Add(filterGraph);
            IGraphBuilder graph = (IGraphBuilder)filterGraph;

            // Add the source filter for the dvr-ms file
            IBaseFilter DvrmsSourceFilter = graph.AddSourceFilter(InputFilePath, null);

            DisposalCleanup.Add(DvrmsSourceFilter);

            // Add the file writer to the graph
            IBaseFilter wavFilter = (IBaseFilter)ClassId.CoCreateInstance(ClassId.FileWriter);

            DisposalCleanup.Add(wavFilter);
            graph.AddFilter(wavFilter, null);
            IFileSinkFilter sinkFilter = (IFileSinkFilter)wavFilter;

            sinkFilter.SetFileName(OutputFilePath, null);

            // Add the Wav Dest filter to the graph
            IBaseFilter wavDest = (IBaseFilter)ClassId.CoCreateInstance(ClassId.WavDest);

            DisposalCleanup.Add(wavDest);
            graph.AddFilter(wavDest, null);

            // Add the decrypter node to the graph
            IBaseFilter decrypter = (IBaseFilter)ClassId.CoCreateInstance(ClassId.DecryptTag);

            DisposalCleanup.Add(decrypter);
            graph.AddFilter(decrypter, null);

            // Connect the dvr-ms source to the decrypter, the decrypter to the wav dest,
            // and the wav dest to the file writer
            Connect(graph, DvrmsSourceFilter, "DVR Out - 1", decrypter, "In(Enc/Tag)");
            Connect(graph, decrypter, "Out", wavDest, "In");
            Connect(graph, wavDest, "Out", wavFilter, "in");

            // Run the graph to convert the audio to wav
            RunGraph(graph);

            return(null);
        }
Пример #13
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);
        }
Пример #14
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);
        }
Пример #15
0
        /// <summary>Saves a graph to a GRF file.</summary>
        /// <param name="graph">The graph to be saved.</param>
        /// <param name="path">Path to the target GRF file.</param>
        private static void SaveGraphToFile(IGraphBuilder graph, string path)
        {
            using (DisposalCleanup dc = new DisposalCleanup())
            {
                // Get the graph's persist stream interface
                IPersistStream ps = (IPersistStream)graph;

                // Create the file to which the graph should be stored
                IStorage graphStorage = StgCreateDocfile(path, (int)(STGM_CREATE | STGM_TRANSACTED | STGM_READWRITE | STGM_SHARE_EXCLUSIVE), 0);
                dc.Add(graphStorage);

                // Create the movie graph stream
                IStream stream = graphStorage.CreateStream("ActiveMovieGraph", (int)(STGM_WRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE), 0, 0);
                dc.Add(stream);

                // Save out the graph and commit it
                ps.Save(stream, true);
                graphStorage.Commit(0);
            }
        }
Пример #16
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);
            }
        }
Пример #17
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);
        }
Пример #18
0
        public static IBaseFilter RenderAviDest(DisposalCleanup dc, ICaptureGraphBuilder2 icgb, string outputFile)
        {
            int hr = 0;

            // Create the file writer
            IBaseFilter     pMux;
            IFileSinkFilter pFilter = null;

            try
            {
                hr = icgb.SetOutputFileName(MediaSubType.Avi, outputFile, out pMux, out pFilter);
                dc.Add(pMux);
                DESError.ThrowExceptionForHR(hr);
            }
            finally
            {
                if (pFilter != null)
                {
                    Marshal.ReleaseComObject(pFilter);
                }
            }

            return(pMux);
        }