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 }
// Configure the video window private void ConfigureVideoWindow(DirectShowLib.IVideoWindow videoWindow, Control hWin) { int hr; // Set the output window hr = videoWindow.put_Owner(hWin.Handle); DsError.ThrowExceptionForHR(hr); // Set the window style hr = videoWindow.put_WindowStyle((WindowStyle.Child | WindowStyle.ClipChildren | WindowStyle.ClipSiblings)); DsError.ThrowExceptionForHR(hr); // Make the window visible hr = videoWindow.put_Visible(OABool.True); DsError.ThrowExceptionForHR(hr); // Make the window visible //hr = videoWindow.put_Visible( OABool.False ); //DsError.ThrowExceptionForHR( hr ); // Position the playing location Rectangle rc = hWin.ClientRectangle; hr = videoWindow.SetWindowPosition(0, 0, rc.Right, rc.Bottom); DsError.ThrowExceptionForHR(hr); //Rectangle rc = hWin.ClientRectangle; //hr = videoWindow.SetWindowPosition( 0, 0, 0, 0 ); //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(); }