Exemplo n.º 1
0
        private void CloseInterface()
        {
            //그래프와 콘트롤 해제
            if (pMediaControl != null)
            {
                pMediaControl.StopWhenReady();
            }
            if (pVideoWindow != null)
            {
                pVideoWindow.put_Visible(OABool.False);
                pVideoWindow.put_Owner(IntPtr.Zero);
            }

            Marshal.ReleaseComObject(pSampleGrabber);
            pSampleGrabber = null;
            Marshal.ReleaseComObject(pSampleGrabberFilter);
            pSampleGrabberFilter = null;
            Marshal.ReleaseComObject(pGraphBuilder);
            pGraphBuilder = null;
            Marshal.ReleaseComObject(pMediaControl);
            pMediaControl = null;
            Marshal.ReleaseComObject(pVideoWindow);
            pVideoWindow = null;
            Marshal.ReleaseComObject(pMediaPosition);
            pMediaPosition = null;
            //this.Close(); //close this program
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load a video to setup DirectShow. This also initally creates an instance of the DirectX3D Device
        /// </summary>
        public static void StartGraph()
        {
            int hr = 0;

            //CloseGraph();

            string path = @"opensebj.wmv";

            try
            {
                graph  = (DirectShowLib.IGraphBuilder) new DirectShowLib.FilterGraph();
                filter = (DirectShowLib.IBaseFilter) new DirectShowLib.VideoMixingRenderer9();

                DirectShowLib.IVMRFilterConfig9 filterConfig = (DirectShowLib.IVMRFilterConfig9)filter;

                hr = filterConfig.SetRenderingMode(VMR9Mode.Renderless);
                DsError.ThrowExceptionForHR(hr);

                hr = filterConfig.SetNumberOfStreams(2);
                DsError.ThrowExceptionForHR(hr);

                SetAllocatorPresenter();

                hr = graph.AddFilter(filter, "Video Mixing Renderer 9");
                DsError.ThrowExceptionForHR(hr);

                hr = graph.RenderFile(path, null);
                DsError.ThrowExceptionForHR(hr);

                mediaControl = (DirectShowLib.IMediaControl)graph;
            }
            catch
            {
            }
        }
Exemplo n.º 3
0
        public static void startSecond()
        {
            initDSArrays();



            filter1 = (DirectShowLib.IBaseFilter) new DirectShowLib.VideoMixingRenderer9();
            DirectShowLib.IVMRFilterConfig9 filterConfig = (DirectShowLib.IVMRFilterConfig9)filter1;
            filterConfig.SetRenderingMode(VMR9Mode.Renderless);
            filterConfig.SetNumberOfStreams(2);


            DirectShowLib.IVMRSurfaceAllocatorNotify9 vmrSurfAllocNotify = (DirectShowLib.IVMRSurfaceAllocatorNotify9)filter1;

            try
            {
                int hr = vmrSurfAllocNotify.AdviseSurfaceAllocator(userId1, allocator);
                DsError.ThrowExceptionForHR(hr);

                hr = allocator.AdviseNotify(vmrSurfAllocNotify);
                DsError.ThrowExceptionForHR(hr);
            }
            catch { }



            graph1 = (DirectShowLib.IGraphBuilder) new DirectShowLib.FilterGraph();
            graph1.AddFilter(filter1, "Video Mixing Renderer 9");

            graph1.RenderFile(@"C:\Download\workmates.wmv", null);
            mediaControl1 = (DirectShowLib.IMediaControl)graph1;
            mediaControl1.Run();
        }
Exemplo n.º 4
0
        public void Init(Transcoder transcoder, int transcoderInputIndex, IMediaControl mediaControl)
        {
            Reset();

            this.transcoder           = transcoder;
            this.transcoderInputIndex = transcoderInputIndex;
            this.mediaControl         = mediaControl;
        }
Exemplo n.º 5
0
 public virtual void Dispose()
 {
     m_MediaControl  = null;
     m_MediaPosition = null;
     Marshal.ReleaseComObject(m_GraphBuilder);
     m_GraphBuilder = null;
     //GC.Collect();
 }
Exemplo n.º 6
0
 void Reset()
 {
     transcoder           = null;
     transcoderInputIndex = 0;
     mediaControl         = null;
     transcoderError      = null;
     samplesProcessed     = 0;
     sampleBuffer         = null;
 }
Exemplo n.º 7
0
        public AudioVideoBase(String path, Boolean isDemo)
            : base(isDemo, path)
        {
            m_GraphBuilder = (DirectShowLib.IGraphBuilder) new FilterGraph();
            m_hr           = m_GraphBuilder.RenderFile(path, null);
            DsError.ThrowExceptionForHR(m_hr);

            m_MediaControl  = (DirectShowLib.IMediaControl)m_GraphBuilder;
            m_MediaPosition = (DirectShowLib.IMediaPosition)m_GraphBuilder;
            m_BasicAudio    = (DirectShowLib.IBasicAudio)m_GraphBuilder;
        }
Exemplo n.º 8
0
        private void Videotest1()
        {
            pGraphBuilder = (DirectShowLib.IGraphBuilder) new FilterGraph();
            pMediaControl = (DirectShowLib.IMediaControl)pGraphBuilder; //controler
            pMediaEvent   = (DirectShowLib.IMediaEvent)pGraphBuilder;   //envent

            pMediaControl.RenderFile(@"C:\Users\trevor\Desktop\Videos\cctv2.wmv");
            pVideoWindow = (DirectShowLib.IVideoWindow)pGraphBuilder; // renderFile을 실행 한 후 연결해줘야한다. 출력처를 알기위해서.
            //pVideoWindow.put_Caption("test"); // setTitle
            //pVideoWindow.put_FullScreenMode(OABool.True); //Video full Screen
            pVideoWindow.put_Owner(tabPage2.Handle); // tabPage2에 그리기.
            pVideoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipSiblings);
            Rectangle rect = tabPage2.ClientRectangle;

            pVideoWindow.SetWindowPosition(0, 0, rect.Right, rect.Bottom);
            pMediaControl.Run();                              // Video play

            pMediaEvent.WaitForCompletion(-1, out eventCode); //블로킹을 실시하는 메소드

            switch (eventCode)
            {
            case 0:
                textBox1.Text = "TimeOut";
                break;

            case EventCode.UserAbort:     //ex) alt+f4
                textBox1.Text = "User Abort";
                break;

            case EventCode.Complete:
                textBox1.Text = "complete";
                break;

            case EventCode.ErrorAbort:
                textBox1.Text = "Error Abort";

                break;
            }

            //pVideoWindow.put_FullScreenMode(OABool.False); // !full Screen

            //free
            Marshal.ReleaseComObject(pGraphBuilder);
            pGraphBuilder = null;
            Marshal.ReleaseComObject(pMediaControl);
            pMediaControl = null;
            Marshal.ReleaseComObject(pMediaEvent);
            pMediaEvent = null;
        }
Exemplo n.º 9
0
    // Shut down capture
    private void CloseInterfaces()
    {
        int hr;

        lock (this)
        {
            if (m_State != GraphState.Exiting)
            {
                m_State = GraphState.Exiting;

                // Release the thread (if the thread was started)
                if (m_mre != null)
                {
                    m_mre.Set();
                }
            }

            if (m_mediaCtrl != null)
            {
                // Stop the graph
                hr          = m_mediaCtrl.Stop();
                m_mediaCtrl = null;
            }

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

#if DEBUG
            if (m_DsRot != null)
            {
                m_DsRot.Dispose();
            }
#endif

            if (m_graphBuilder != null)
            {
                Marshal.ReleaseComObject(m_graphBuilder);
                m_graphBuilder = null;
            }
        }
        GC.Collect();
    }
Exemplo n.º 10
0
        private void InitializeGraph()
        {
            m_graph = (DirectShowLib.IGraphBuilder) new FilterGraphNoThread();

            // QueryInterface for DirectShow interfaces
            _mediaControl  = (DirectShowLib.IMediaControl)m_graph;
            _mediaEventEx  = (DirectShowLib.IMediaEventEx)m_graph;
            _mediaSeeking  = (DirectShowLib.IMediaSeeking)m_graph;
            _mediaPosition = (DirectShowLib.IMediaPosition)m_graph;

            // Query for video interfaces, which may not be relevant for audio files
            _videoWindow = m_graph as DirectShowLib.IVideoWindow;
            _basicVideo  = m_graph as DirectShowLib.IBasicVideo;

            // Query for audio interfaces, which may not be relevant for video-only files
            _basicAudio = m_graph as DirectShowLib.IBasicAudio;

            // Set up event notification.
            var hr = _mediaEventEx.SetNotifyWindow(VideoWindowHandle, WM_GRAPHNOTIFY, IntPtr.Zero);

            DsError.ThrowExceptionForHR(hr);
        }
Exemplo n.º 11
0
        private void InitializeGraph(bool isDvd)
        {
            int hr = 0;
            _isDvd = isDvd;
            if (isDvd)
            {
                _dvdGraphBuilder = new DvdGraphBuilder() as IDvdGraphBuilder;
                hr = _dvdGraphBuilder.GetFiltergraph(out _graph);
                DsError.ThrowExceptionForHR(hr);
                _filterGraph = _graph as IFilterGraph2;
            }
            else
            {
                _filterGraphNT = new FilterGraphNoThread();
                _graph = (_filterGraphNT as DirectShowLib.IGraphBuilder);
            }
            // QueryInterface for DirectShow interfaces
            _mediaControl = (DirectShowLib.IMediaControl)_graph;
            _mediaEventEx = (DirectShowLib.IMediaEventEx)_graph;
            _mediaSeeking = (DirectShowLib.IMediaSeeking)_graph;
            _mediaPosition = (DirectShowLib.IMediaPosition)_graph;

            // Query for video interfaces, which may not be relevant for audio files
            _videoWindow = _graph as DirectShowLib.IVideoWindow;
            _basicVideo = _graph as DirectShowLib.IBasicVideo;

            // Query for audio interfaces, which may not be relevant for video-only files
            _basicAudio = _graph as DirectShowLib.IBasicAudio;

            // Set up event notification.
            if (isDvd)
                hr = _mediaEventEx.SetNotifyWindow(VideoWindowHandle, WM_DVD_EVENT, IntPtr.Zero);
            else
                hr = _mediaEventEx.SetNotifyWindow(VideoWindowHandle, WM_GRAPHNOTIFY, IntPtr.Zero);
            DsError.ThrowExceptionForHR(hr);

            if (_mbtConfig.Configuration.InternalPlayerConfiguration.PublishGraph)
                m_dsRot = new DsROTEntry(_graph as IFilterGraph);
        }
Exemplo n.º 12
0
    // Shut down capture
    private void CloseInterfaces()
    {
        int hr;

        lock (this)
        {
            if (m_State != GraphState.Exiting)
            {
                m_State = GraphState.Exiting;

                // Release the thread (if the thread was started)
                if (m_mre != null)
                {
                    m_mre.Set();
                }
            }

            if( m_mediaCtrl != null )
            {
                // Stop the graph
                hr = m_mediaCtrl.Stop();
                m_mediaCtrl = null;
            }

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

#if DEBUG
            if (m_DsRot != null)
            {
                m_DsRot.Dispose();
            }
#endif

            if (m_graphBuilder != null)
            {
                Marshal.ReleaseComObject(m_graphBuilder);
                m_graphBuilder = null;
            }
        }
        GC.Collect();
    }
Exemplo n.º 13
0
	// Build the capture graph for grabber and renderer.</summary>
	// (Control to show video in, Filename to play)
	private void SetupGraph(string FileName)
	{
		int hr;

		// Get the graphbuilder object
		m_graphBuilder = new DirectShowLib.FilterGraph() as DirectShowLib.IFilterGraph2;

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

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

#if DEBUG
			// Allows you to view the graph with GraphEdit File/Connect
			m_DsRot = new DsROTEntry(m_graphBuilder);
#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_graphBuilder.AddSourceFilter(FileName, FileName, out sourceFilter);
			DsError.ThrowExceptionForHR( hr );

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

			// Configure the Sample Grabber
			ConfigureSampleGrabber(m_sampGrabber);

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

			// System.Windows.Forms.MessageBox.Show(Width.ToString(), Height.ToString(), System.Windows.Forms.MessageBoxButtons.OK);

			// A Null Renderer does not display the video
			// But it allows the Sample Grabber to run
			// And it will keep proper playback timing
			// Unless specified otherwise.
			DirectShowLib.NullRenderer nullRenderer = new DirectShowLib.NullRenderer();

			m_graphBuilder.AddFilter((DirectShowLib.IBaseFilter) nullRenderer, "Null Renderer");

			// Connect the pieces together, use the default renderer
			hr = icgb2.RenderStream(null, null, sourceFilter, baseGrabFlt, (DirectShowLib.IBaseFilter) nullRenderer);
			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
			//DirectShowLib.IVideoWindow videoWindow = m_graphBuilder as DirectShowLib.IVideoWindow;
			//ConfigureVideoWindow(videoWindow, hWin);

			// Grab some other interfaces
			m_mediaEvent = m_graphBuilder as DirectShowLib.IMediaEvent;
			m_mediaCtrl = m_graphBuilder as DirectShowLib.IMediaControl;
		}
		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
	}
Exemplo n.º 14
0
    /// <summary> build the capture graph for grabber. </summary>
    private void SetupGraph(DsDevice dev, int iFrameRate, int iWidth, int iHeight, Control hControl)
    {
        int hr;

        DirectShowLib.ISampleGrabber sampGrabber = null;
        DirectShowLib.IBaseFilter capFilter = null;
        DirectShowLib.ICaptureGraphBuilder2 capGraph = null;

        // Get the graphbuilder object
        m_graphBuilder = (DirectShowLib.IFilterGraph2) new FilterGraph();
        m_mediaCtrl = m_graphBuilder as DirectShowLib.IMediaControl;
        try
        {
            // Get the ICaptureGraphBuilder2
            capGraph = (DirectShowLib.ICaptureGraphBuilder2) new DirectShowLib.CaptureGraphBuilder2();

            // Get the SampleGrabber interface
            sampGrabber = (DirectShowLib.ISampleGrabber) new DirectShowLib.SampleGrabber();

            // Start building the graph
            hr = capGraph.SetFiltergraph( m_graphBuilder );
            DsError.ThrowExceptionForHR( hr );

            // Add the video device
            hr = m_graphBuilder.AddSourceFilterForMoniker(dev.Mon, null, "Video input", out capFilter);
            DsError.ThrowExceptionForHR( hr );

            DirectShowLib.IBaseFilter baseGrabFlt = (DirectShowLib.IBaseFilter)	sampGrabber;
            ConfigureSampleGrabber(sampGrabber);

            // Add the frame grabber to the graph
            hr = m_graphBuilder.AddFilter( baseGrabFlt, "Ds.NET Grabber" );
            DsError.ThrowExceptionForHR( hr );

            // If any of the default config items are set
            if (iFrameRate + iHeight + iWidth > 0)
            {
                SetConfigParms(capGraph, capFilter, iFrameRate, iWidth, iHeight);
            }

			// ------------------------------------

			if (false) 
			{
				if (false)
				{
					hr = capGraph.RenderStream(DirectShowLib.PinCategory.Preview, DirectShowLib.MediaType.Video, capFilter, null, baseGrabFlt);
					DsError.ThrowExceptionForHR(hr);
				}
				theCompressor = CreateFilter(FilterCategory.VideoCompressorCategory, "Microsoft MPEG-4 Video Codec V2");

				// Add the Video compressor filter to the graph
				if (theCompressor != null)
				{
					hr = m_graphBuilder.AddFilter(theCompressor, "Compressor Filter");
					DsError.ThrowExceptionForHR(hr);
				}

				// Create the file writer part of the graph. SetOutputFileName does this for us, and returns the mux and sink
				DirectShowLib.IBaseFilter mux;
				DirectShowLib.IFileSinkFilter sink;
				hr = capGraph.SetOutputFileName(DirectShowLib.MediaSubType.Avi, "C:\\Test.avi", out mux, out sink);
				DsError.ThrowExceptionForHR(hr);

				hr = capGraph.RenderStream(DirectShowLib.PinCategory.Capture, DirectShowLib.MediaType.Video, capFilter, theCompressor, mux);
				DsError.ThrowExceptionForHR(hr);

				Marshal.ReleaseComObject(mux);
				Marshal.ReleaseComObject(sink);

				hr = capGraph.RenderStream(DirectShowLib.PinCategory.Preview, DirectShowLib.MediaType.Video, capFilter, null, null);
				DsError.ThrowExceptionForHR(hr);

				//ShowVideoWindow(hControl);
			}
			else
			{
				hr = capGraph.RenderStream(DirectShowLib.PinCategory.Capture, DirectShowLib.MediaType.Video, capFilter, null, baseGrabFlt);
				DsError.ThrowExceptionForHR(hr);

				//hr = capGraph.RenderStream(DirectShowLib.PinCategory.Preview, DirectShowLib.MediaType.Video, capFilter, null, null);
				//DsError.ThrowExceptionForHR(hr);

				//ShowVideoWindow(hControl);
			}

            // --------------------------------------

            //hr = capGraph.RenderStream( DirectShowLib.PinCategory.Capture, DirectShowLib.MediaType.Video, capFilter, null, baseGrabFlt );
            //DsError.ThrowExceptionForHR( hr );

            SaveSizeInfo(sampGrabber);
        }
        finally
        {
            if (capFilter != null)
            {
                Marshal.ReleaseComObject(capFilter);
                capFilter = null;
            }
            if (sampGrabber != null)
            {
                Marshal.ReleaseComObject(sampGrabber);
                sampGrabber = null;
            }
            if (capGraph != null)
            {
                Marshal.ReleaseComObject(capGraph);
                capGraph = null;
            }
        }
    }
Exemplo n.º 15
0
    /// <summary> build the capture graph for grabber. </summary>
    private void SetupGraph(DsDevice dev, int iFrameRate, int iWidth, int iHeight, Control hControl)
    {
        int hr;

        DirectShowLib.ISampleGrabber        sampGrabber = null;
        DirectShowLib.IBaseFilter           capFilter   = null;
        DirectShowLib.ICaptureGraphBuilder2 capGraph    = null;

        // Get the graphbuilder object
        m_graphBuilder = (DirectShowLib.IFilterGraph2) new FilterGraph();
        m_mediaCtrl    = m_graphBuilder as DirectShowLib.IMediaControl;
        try
        {
            // Get the ICaptureGraphBuilder2
            capGraph = (DirectShowLib.ICaptureGraphBuilder2) new DirectShowLib.CaptureGraphBuilder2();

            // Get the SampleGrabber interface
            sampGrabber = (DirectShowLib.ISampleGrabber) new DirectShowLib.SampleGrabber();

            // Start building the graph
            hr = capGraph.SetFiltergraph(m_graphBuilder);
            DsError.ThrowExceptionForHR(hr);

            // Add the video device
            hr = m_graphBuilder.AddSourceFilterForMoniker(dev.Mon, null, "Video input", out capFilter);
            DsError.ThrowExceptionForHR(hr);

            DirectShowLib.IBaseFilter baseGrabFlt = (DirectShowLib.IBaseFilter)sampGrabber;
            ConfigureSampleGrabber(sampGrabber);

            // Add the frame grabber to the graph
            hr = m_graphBuilder.AddFilter(baseGrabFlt, "Ds.NET Grabber");
            DsError.ThrowExceptionForHR(hr);

            // If any of the default config items are set
            if (iFrameRate + iHeight + iWidth > 0)
            {
                SetConfigParms(capGraph, capFilter, iFrameRate, iWidth, iHeight);
            }

            // ------------------------------------

            if (false)
            {
                if (false)
                {
                    hr = capGraph.RenderStream(DirectShowLib.PinCategory.Preview, DirectShowLib.MediaType.Video, capFilter, null, baseGrabFlt);
                    DsError.ThrowExceptionForHR(hr);
                }
                theCompressor = CreateFilter(FilterCategory.VideoCompressorCategory, "Microsoft MPEG-4 Video Codec V2");

                // Add the Video compressor filter to the graph
                if (theCompressor != null)
                {
                    hr = m_graphBuilder.AddFilter(theCompressor, "Compressor Filter");
                    DsError.ThrowExceptionForHR(hr);
                }

                // Create the file writer part of the graph. SetOutputFileName does this for us, and returns the mux and sink
                DirectShowLib.IBaseFilter     mux;
                DirectShowLib.IFileSinkFilter sink;
                hr = capGraph.SetOutputFileName(DirectShowLib.MediaSubType.Avi, "C:\\Test.avi", out mux, out sink);
                DsError.ThrowExceptionForHR(hr);

                hr = capGraph.RenderStream(DirectShowLib.PinCategory.Capture, DirectShowLib.MediaType.Video, capFilter, theCompressor, mux);
                DsError.ThrowExceptionForHR(hr);

                Marshal.ReleaseComObject(mux);
                Marshal.ReleaseComObject(sink);

                hr = capGraph.RenderStream(DirectShowLib.PinCategory.Preview, DirectShowLib.MediaType.Video, capFilter, null, null);
                DsError.ThrowExceptionForHR(hr);

                //ShowVideoWindow(hControl);
            }
            else
            {
                hr = capGraph.RenderStream(DirectShowLib.PinCategory.Capture, DirectShowLib.MediaType.Video, capFilter, null, baseGrabFlt);
                DsError.ThrowExceptionForHR(hr);

                //hr = capGraph.RenderStream(DirectShowLib.PinCategory.Preview, DirectShowLib.MediaType.Video, capFilter, null, null);
                //DsError.ThrowExceptionForHR(hr);

                //ShowVideoWindow(hControl);
            }

            // --------------------------------------

            //hr = capGraph.RenderStream( DirectShowLib.PinCategory.Capture, DirectShowLib.MediaType.Video, capFilter, null, baseGrabFlt );
            //DsError.ThrowExceptionForHR( hr );

            SaveSizeInfo(sampGrabber);
        }
        finally
        {
            if (capFilter != null)
            {
                Marshal.ReleaseComObject(capFilter);
                capFilter = null;
            }
            if (sampGrabber != null)
            {
                Marshal.ReleaseComObject(sampGrabber);
                sampGrabber = null;
            }
            if (capGraph != null)
            {
                Marshal.ReleaseComObject(capGraph);
                capGraph = null;
            }
        }
    }
        private void CloseInterfaces()
        {
            int hr;

            if (m_adecOut != null)
            {
                CleanUpInterface(m_adecOut);
                m_adecOut = null;
            }

            if (_defaultAudioRenderer != null)
            {
                m_graph.RemoveFilter(_defaultAudioRenderer as DirectShowLib.IBaseFilter);

                CleanUpInterface(_defaultAudioRenderer);
                _defaultAudioRenderer = null;
            }

            if (_reclockAudioRenderer != null)
            {
                m_graph.RemoveFilter(_reclockAudioRenderer as DirectShowLib.IBaseFilter);

                CleanUpInterface(_reclockAudioRenderer);
                _reclockAudioRenderer = null;
            }

            if (_wasapiAR != null)
            {
                m_graph.RemoveFilter(_wasapiAR as DirectShowLib.IBaseFilter);

                CleanUpInterface(_wasapiAR);
                _wasapiAR = null;
            }

            if (_lavaudio != null)
            {
                m_graph.RemoveFilter(_lavaudio as DirectShowLib.IBaseFilter);

                CleanUpInterface(_lavaudio);
                _lavaudio = null;
            }

            if (_xyVsFilter != null)
            {
                m_graph.RemoveFilter(_xyVsFilter as DirectShowLib.IBaseFilter);

                CleanUpInterface(_xyVsFilter);
                _xyVsFilter = null;
            }

            if (_xySubFilter != null)
            {
                m_graph.RemoveFilter(_xySubFilter as DirectShowLib.IBaseFilter);

                CleanUpInterface(_xySubFilter);
                _xySubFilter = null;
            }

            if (_lavvideo != null)
            {
                m_graph.RemoveFilter(_lavvideo as DirectShowLib.IBaseFilter);

                CleanUpInterface(_lavvideo);
                _lavvideo = null;
            }

            if (_madvr != null)
            {
                m_graph.RemoveFilter(_madvr as DirectShowLib.IBaseFilter);

                CleanUpInterface(_madvr);
                _madvr = null;
            }

            if (_videoWindow != null)
            {
                // Relinquish ownership (IMPORTANT!) after hiding video window
                hr = _videoWindow.put_Visible(OABool.False);

                hr = _videoWindow.put_Owner(IntPtr.Zero);
            }

            if (_mediaEventEx != null)
            {
                hr = _mediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);
                //Marshal.ReleaseComObject(_mediaEventEx);
                //_mediaEventEx = null;
            }

            //if (_dvdNav != null)
            //{
            //    Marshal.ReleaseComObject(_dvdNav);
            //    _dvdNav = null;
            //}
            /* //this will double release the source filter
            if (dvdInfo != null)
            {
                Marshal.ReleaseComObject(dvdInfo);
                dvdInfo = null;
            }

            if (_mDvdControl != null)
            {
                Marshal.ReleaseComObject(_mDvdControl);                
            }
            */
            _mDvdControl = null;

            CleanUpInterface(_mPDisplay);
            _mPDisplay = null;
            CleanUpInterface(_sourceFilter);
            _sourceFilter = null;
            CleanUpInterface(_mPEvr);
            _mPEvr = null;
            CleanUpInterface(m_filterGraph);
            m_filterGraph = null;

            m_filterGraph = null;
            _mediaEventEx = null;
            _mediaSeeking = null;
            _mediaPosition = null;
            _mediaControl = null;
            _basicAudio = null;
            _basicVideo = null;
            m_graph = null;
            _videoWindow = null;
            _filterGraph = null;

            if (m_dsRot != null)
                m_dsRot.Dispose();
            m_dsRot = null;

            _mSeekCaps = 0;

            _streams = null;

            GC.Collect();
        }
Exemplo n.º 17
0
        private void SetupGraph(Control hWin, string filename)
        {
            pGraphBuilder   = (DirectShowLib.IGraphBuilder) new FilterGraph();
            pMediaControl   = (DirectShowLib.IMediaControl)pGraphBuilder;
            pVideoWindow    = (DirectShowLib.IVideoWindow)pGraphBuilder;
            pVideoFrameStep = (DirectShowLib.IVideoFrameStep)pGraphBuilder; // video frame...
            pMediaPosition  = (DirectShowLib.IMediaPosition)pGraphBuilder;
            //DirectShowLib.IBaseFilter pBaseFilter = (DirectShowLib.IBaseFilter)pGraphBuilder;

            //pMediaSeeking = (DirectShowLib.IMediaSeeking)pGraphBuilder;
            //pMediaSeeking.SetPositions(5000, AMSeekingSeekingFlags.AbsolutePositioning, 6000, AMSeekingSeekingFlags.AbsolutePositioning);

            //test
            DirectShowLib.ICaptureGraphBuilder2  pCaptureGraphBuilder2;
            DirectShowLib.IBaseFilter            pRenderer;
            DirectShowLib.IVMRFilterConfig9      pIVMRFilterConfig9;
            DirectShowLib.IVMRWindowlessControl9 pVMRWC9;

            pCaptureGraphBuilder2 = (DirectShowLib.ICaptureGraphBuilder2) new CaptureGraphBuilder2();
            pCaptureGraphBuilder2.SetFiltergraph(pGraphBuilder);     // CaptureGraph를  GraphBuilder에 붙인다.

            //pGraphBuilder.AddFilter(pMediaControl "SDZ 375 Source");  // GraphBuilder에 영상장치필터를 추가한다.
            pRenderer          = (DirectShowLib.IBaseFilter) new DirectShowLib.VideoMixingRenderer9(); // 믹서 필터를 생성 한다.
            pIVMRFilterConfig9 = (DirectShowLib.IVMRFilterConfig9)pRenderer;                           // 믹서 필터의 속성을 설정한다.
            pIVMRFilterConfig9.SetRenderingMode(VMR9Mode.Windowless);
            pIVMRFilterConfig9.SetNumberOfStreams(2);

            pVMRWC9 = (DirectShowLib.IVMRWindowlessControl9)pRenderer;              // 오버레이 평면의 속성을 설정한다.
            pVMRWC9.SetVideoClippingWindow(hWin.Handle);
            pVMRWC9.SetBorderColor(0);
            pVMRWC9.SetVideoPosition(null, hWin.ClientRectangle);
            pGraphBuilder.AddFilter(pRenderer, "Video Mixing Renderer");                               // GraphBuilder에 믹스 필터를 추가한다.
            pCaptureGraphBuilder2.RenderStream(null, MediaType.Video, pGraphBuilder, null, pRenderer); // 영상표시를 위한 필터를 설정한다.
            ///test

            //sampleGrabber
            AMMediaType am_media_type = new AMMediaType();

            pSampleGrabber           = (DirectShowLib.ISampleGrabber) new SampleGrabber();
            pSampleGrabberFilter     = (DirectShowLib.IBaseFilter)pSampleGrabber;
            am_media_type.majorType  = MediaType.Video;
            am_media_type.subType    = MediaSubType.RGB24;
            am_media_type.formatType = FormatType.VideoInfo;
            pSampleGrabber.SetMediaType(am_media_type);
            //Graph에 sampleGrabber filter를 추가
            pGraphBuilder.AddFilter(pSampleGrabberFilter, "Sample Grabber");

            pMediaControl.RenderFile(filename);

            pVideoWindow.put_Owner(hWin.Handle);
            pVideoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipSiblings);
            Rectangle rect = hWin.ClientRectangle;

            pVideoWindow.SetWindowPosition(0, 0, rect.Right, rect.Bottom);

            //sampleGrabber2
            pSampleGrabber.GetConnectedMediaType(am_media_type);
            DirectShowLib.VideoInfoHeader pVideoInfoHeader = (DirectShowLib.VideoInfoHeader)Marshal.PtrToStructure(am_media_type.formatPtr, typeof(VideoInfoHeader));
            String str = string.Format("size = {0} x {1}", pVideoInfoHeader.BmiHeader.Width, pVideoInfoHeader.BmiHeader.Height);

            Video_Width   = pVideoInfoHeader.BmiHeader.Width;
            Video_Height  = pVideoInfoHeader.BmiHeader.Height;
            str          += string.Format("sample size = {0}", am_media_type.sampleSize);
            textBox1.Text = str;
            DsUtils.FreeAMMediaType(am_media_type);
            //SetBufferSamples를 실행하지 않으면 버퍼로부터 데이터를 얻을 수 없다.
            //불필요하게 부하를 주고싶지 않은경우 false, 데이터를 얻고싶으면 true
            pSampleGrabber.SetBufferSamples(true);

            //play time
            pMediaPosition = (DirectShowLib.IMediaPosition)pGraphBuilder;
            double Length;

            pMediaPosition.get_Duration(out Length);
            String str2 = string.Format("play time: {0}", Length);

            textBox1.Text = str2;
            pMediaPosition.put_CurrentPosition(5.0); //set current Position



            //2017.05.08
            DirectShowLib.IVMRWindowlessControl9 windowlessCtrl = (DirectShowLib.IVMRWindowlessControl9)pRenderer;
            windowlessCtrl.SetVideoClippingWindow(hWin.Handle);
            IntPtr lpDib;

            windowlessCtrl.GetCurrentImage(out lpDib);
            BitmapInfoHeader head;

            head = (BitmapInfoHeader)Marshal.PtrToStructure(lpDib, typeof(BitmapInfoHeader));
            int         width       = head.Width;
            int         height      = head.Height;
            int         stride      = width * (head.BitCount / 8);
            PixelFormat pixelFormat = PixelFormat.Format24bppRgb;

            switch (head.BitCount)
            {
            case 24: pixelFormat = PixelFormat.Format24bppRgb; break;

            case 32: pixelFormat = PixelFormat.Format32bppRgb; break;

            case 48: pixelFormat = PixelFormat.Format48bppRgb; break;

            default: throw new Exception("Unknown BitCount");
            }

            Bitmap Cap = new Bitmap(width, height, stride, pixelFormat, lpDib);

            Cap.RotateFlip(RotateFlipType.RotateNoneFlipY);
            pictureBox1.Image = Cap;
        }
Exemplo n.º 18
0
        private void CloseInterfaces()
        {
            _hiddenWindow.SizeChanged -= _hiddenWindow_SizeChanged;

            int hr;

            if (_defaultAudioRenderer != null)
            {
                m_graph.RemoveFilter(_defaultAudioRenderer as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_defaultAudioRenderer);
                _defaultAudioRenderer = null;
            }

            if (_reclockAudioRenderer != null)
            {
                m_graph.RemoveFilter(_reclockAudioRenderer as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_reclockAudioRenderer);
                _reclockAudioRenderer = null;
            }

            if (_lavaudio != null)
            {
                m_graph.RemoveFilter(_lavaudio as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_lavaudio);
                _lavaudio = null;
            }

            if (_xyVsFilter != null)
            {
                m_graph.RemoveFilter(_xyVsFilter as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_xyVsFilter);
                _xyVsFilter = null;
            }

            if (_xySubFilter != null)
            {
                m_graph.RemoveFilter(_xySubFilter as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_xySubFilter);
                _xySubFilter = null;
            }

            if (_lavvideo != null)
            {
                m_graph.RemoveFilter(_lavvideo as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_lavvideo);
                _lavvideo = null;
            }

            if (_madvr != null)
            {
                m_graph.RemoveFilter(_madvr as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_madvr);
                _madvr = null;
            }

            if (_videoWindow != null)
            {
                // Relinquish ownership (IMPORTANT!) after hiding video window
                hr = _videoWindow.put_Visible(OABool.False);

                hr = _videoWindow.put_Owner(IntPtr.Zero);
            }

            if (_mediaEventEx != null)
            {
                hr = _mediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);
                Marshal.ReleaseComObject(_mediaEventEx);
                _mediaEventEx = null;
            }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            _mSeekCaps = 0;

            _streams = null;

            GC.Collect();
        }
        private void InitializeGraph()
        {
            m_graph = (DirectShowLib.IGraphBuilder)new FilterGraphNoThread();

            // QueryInterface for DirectShow interfaces
            _mediaControl = (DirectShowLib.IMediaControl)m_graph;
            _mediaEventEx = (DirectShowLib.IMediaEventEx)m_graph;
            _mediaSeeking = (DirectShowLib.IMediaSeeking)m_graph;
            _mediaPosition = (DirectShowLib.IMediaPosition)m_graph;

            // Query for video interfaces, which may not be relevant for audio files
            _videoWindow = m_graph as DirectShowLib.IVideoWindow;
            _basicVideo = m_graph as DirectShowLib.IBasicVideo;

            // Query for audio interfaces, which may not be relevant for video-only files
            _basicAudio = m_graph as DirectShowLib.IBasicAudio;

            // Set up event notification.
            var hr = _mediaEventEx.SetNotifyWindow(VideoWindowHandle, WM_GRAPHNOTIFY, IntPtr.Zero);
            DsError.ThrowExceptionForHR(hr);
        }
        private void CloseInterfaces()
        {
            _hiddenWindow.SizeChanged -= _hiddenWindow_SizeChanged;

            int hr;

            if (_defaultAudioRenderer != null)
            {
                m_graph.RemoveFilter(_defaultAudioRenderer as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_defaultAudioRenderer);
                _defaultAudioRenderer = null;
            }

            if (_reclockAudioRenderer != null)
            {
                m_graph.RemoveFilter(_reclockAudioRenderer as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_reclockAudioRenderer);
                _reclockAudioRenderer = null;
            }

            if (_lavaudio != null)
            {
                m_graph.RemoveFilter(_lavaudio as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_lavaudio);
                _lavaudio = null;
            }

            if (_xyVsFilter != null)
            {
                m_graph.RemoveFilter(_xyVsFilter as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_xyVsFilter);
                _xyVsFilter = null;
            }

            if (_xySubFilter != null)
            {
                m_graph.RemoveFilter(_xySubFilter as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_xySubFilter);
                _xySubFilter = null;
            }

            if (_lavvideo != null)
            {
                m_graph.RemoveFilter(_lavvideo as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_lavvideo);
                _lavvideo = null;
            }

            if (_madvr != null)
            {
                m_graph.RemoveFilter(_madvr as DirectShowLib.IBaseFilter);

                Marshal.ReleaseComObject(_madvr);
                _madvr = null;
            }

            if (_videoWindow != null)
            {
                // Relinquish ownership (IMPORTANT!) after hiding video window
                hr = _videoWindow.put_Visible(OABool.False);

                hr = _videoWindow.put_Owner(IntPtr.Zero);
            }

            if (_mediaEventEx != null)
            {
                hr = _mediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);
                Marshal.ReleaseComObject(_mediaEventEx);
                _mediaEventEx = null;
            }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            _mSeekCaps = 0;

            _streams = null;

            GC.Collect();
        }
        private void InitializeGraph(bool isDvd)
        {
            int hr = 0;
            _isDvd = isDvd;
            m_filterGraph = new FilterGraphNoThread();
            m_graph = (m_filterGraph as DirectShowLib.IGraphBuilder);

            // QueryInterface for DirectShow interfaces
            _mediaControl = (DirectShowLib.IMediaControl)m_graph;
            _mediaEventEx = (DirectShowLib.IMediaEventEx)m_graph;
            _mediaSeeking = (DirectShowLib.IMediaSeeking)m_graph;
            _mediaPosition = (DirectShowLib.IMediaPosition)m_graph;

            // Query for video interfaces, which may not be relevant for audio files
            _videoWindow = m_graph as DirectShowLib.IVideoWindow;
            _basicVideo = m_graph as DirectShowLib.IBasicVideo;

            // Query for audio interfaces, which may not be relevant for video-only files
            _basicAudio = m_graph as DirectShowLib.IBasicAudio;

            // Set up event notification.
            if (isDvd)
                hr = _mediaEventEx.SetNotifyWindow(VideoWindowHandle, DirectShowPlayerConfiguration.WM_DVD_EVENT, IntPtr.Zero);
            else
                hr = _mediaEventEx.SetNotifyWindow(VideoWindowHandle, DirectShowPlayerConfiguration.WM_GRAPH_NOTIFY, IntPtr.Zero);
            DsError.ThrowExceptionForHR(hr);

            if (_config.PublishGraph)
                m_dsRot = new DsROTEntry(m_graph as IFilterGraph);
        }
Exemplo n.º 22
0
    // Build the capture graph for grabber and renderer.</summary>
    // (Control to show video in, Filename to play)
    private void SetupGraph(string FileName)
    {
        int hr;

        // Get the graphbuilder object
        m_graphBuilder = new DirectShowLib.FilterGraph() as DirectShowLib.IFilterGraph2;

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

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

#if DEBUG
            // Allows you to view the graph with GraphEdit File/Connect
            m_DsRot = new DsROTEntry(m_graphBuilder);
#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_graphBuilder.AddSourceFilter(FileName, FileName, out sourceFilter);
            DsError.ThrowExceptionForHR(hr);

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

            // Configure the Sample Grabber
            ConfigureSampleGrabber(m_sampGrabber);

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

            // System.Windows.Forms.MessageBox.Show(Width.ToString(), Height.ToString(), System.Windows.Forms.MessageBoxButtons.OK);

            // A Null Renderer does not display the video
            // But it allows the Sample Grabber to run
            // And it will keep proper playback timing
            // Unless specified otherwise.
            DirectShowLib.NullRenderer nullRenderer = new DirectShowLib.NullRenderer();

            m_graphBuilder.AddFilter((DirectShowLib.IBaseFilter)nullRenderer, "Null Renderer");

            // Connect the pieces together, use the default renderer
            hr = icgb2.RenderStream(null, null, sourceFilter, baseGrabFlt, (DirectShowLib.IBaseFilter)nullRenderer);
            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
            //DirectShowLib.IVideoWindow videoWindow = m_graphBuilder as DirectShowLib.IVideoWindow;
            //ConfigureVideoWindow(videoWindow, hWin);

            // Grab some other interfaces
            m_mediaEvent = m_graphBuilder as DirectShowLib.IMediaEvent;
            m_mediaCtrl  = m_graphBuilder as DirectShowLib.IMediaControl;
        }
        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
    }