Exemplo n.º 1
0
        private bool IsVideoHaveAudio(Control hWin, string FileName)
        {
            int hr = 0;

            // Get the graphbuilder object
            IFilterGraph2 m_FilterGraph = new FilterGraph() as IFilterGraph2;

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

            try
            {
                // Link the ICaptureGraphBuilder2 to the IFilterGraph2
                hr = icgb2.SetFiltergraph(m_FilterGraph);
                DsError.ThrowExceptionForHR(hr);

//#if DEBUG
//                // Allows you to view the graph with GraphEdit File/Connect
//                m_DsRot = new DsROTEntry(m_FilterGraph);
//#endif
                // Add the filters necessary to render the file.  This function will
                // work with a number of different file types.
                IBaseFilter sourceFilter = null;
                hr = m_FilterGraph.AddSourceFilter(FileName, FileName, out sourceFilter);
                DsError.ThrowExceptionForHR(hr);

                // Get the SampleGrabber interface
                ISampleGrabber m_sampGrabber = (ISampleGrabber) new SampleGrabber();
                IBaseFilter    baseGrabFlt   = (IBaseFilter)m_sampGrabber;



                // Configure the Sample Grabber
                ConfigureSampleGrabber(m_sampGrabber);

                // Add it to the filter
                hr = m_FilterGraph.AddFilter(baseGrabFlt, "Ds.NET Grabber");
                DsError.ThrowExceptionForHR(hr);



                // Connect the pieces together, use the default renderer
                hr = icgb2.RenderStream(null, null, sourceFilter, baseGrabFlt, null);

                DsError.ThrowExceptionForHR(hr);

                // Now that the graph is built, read the dimensions of the bitmaps we'll be getting
                SaveSizeInfo(m_sampGrabber);

                // Configure the Video Window
                IVideoWindow m_videoWindow = m_FilterGraph as IVideoWindow;
                ConfigureVideoWindow(m_videoWindow, hWin);

                // Grab some other interfaces
                IMediaEvent   m_mediaEvent   = m_FilterGraph as IMediaEvent;
                IMediaControl m_mediaCtrl    = m_FilterGraph as IMediaControl;
                IMediaSeeking m_mediaSeeking = m_FilterGraph as IMediaSeeking;

                try
                {
                    IBaseFilter pAudioRenderer = (IBaseFilter) new DSoundRender();
                    hr = m_FilterGraph.AddFilter(pAudioRenderer, "Audio Renderer");
                    DsError.ThrowExceptionForHR(hr);

                    hr = icgb2.RenderStream(null, MediaType.Audio, sourceFilter, null, pAudioRenderer);
                    //     DsError.ThrowExceptionForHR(hr);
                    // hr = m_mediaSeeking.SetRate(0.5);
                }
                catch
                {
                }
            }
            finally
            {
                if (icgb2 != null)
                {
                    Marshal.ReleaseComObject(icgb2);
                    icgb2 = null;
                }
            }
#if DEBUG
            // Double check to make sure we aren't releasing something
            // important.
            GC.Collect();
            GC.WaitForPendingFinalizers();
#endif

            CloseInterfaces();
            return(hr == 0);
        }