/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// A centralized place to close down all media devices. /// </summary> /// <history> /// 01 Nov 18 Cynic - Started /// </history> private void CloseAllMediaDevices() { HResult hr; LogMessage("CloseAllMediaDevices"); // close and release our call back handler if (mediaSessionAsyncCallbackHandler != null) { // stop any messaging or events in the call back handler mediaSessionAsyncCallbackHandler.ShutDown(); mediaSessionAsyncCallbackHandler = null; } // close the session (this is NOT the same as shutting it down) if (mediaSession != null) { hr = mediaSession.Close(); if (hr != HResult.S_OK) { // just log it LogMessage("CloseAllMediaDevices call to mediaSession.Close failed. Err=" + hr.ToString()); } } // Shut down the media source if (mediaSource != null) { hr = mediaSource.Shutdown(); if (hr != HResult.S_OK) { // just log it LogMessage("CloseAllMediaDevices call to mediaSource.Shutdown failed. Err=" + hr.ToString()); } Marshal.ReleaseComObject(mediaSource); mediaSource = null; } // Shut down the media session (note we only closed it before). if (mediaSession != null) { hr = mediaSession.Shutdown(); if (hr != HResult.S_OK) { // just log it LogMessage("CloseAllMediaDevices call to mediaSession.Shutdown failed. Err=" + hr.ToString()); } Marshal.ReleaseComObject(mediaSession); mediaSession = null; } // close the media sink if (mediaSink != null) { Marshal.ReleaseComObject(mediaSink); mediaSink = null; } }
private void CloseAllMediaDevices() { HResult hr; Console.WriteLine("CloseAllMediaDevices"); // close and release our call back handler if (mediaSessionAsyncCallbackHandler != null) { // stop any messaging or events in the call back handler mediaSessionAsyncCallbackHandler.ShutDown(); mediaSessionAsyncCallbackHandler = null; } // Shut down the source reader if (StreamReader != null) { Marshal.ReleaseComObject(StreamReader); StreamReader = null; } // close the session (this is NOT the same as shutting it down) if (mediaSession != null) { hr = mediaSession.Close(); if (hr != HResult.S_OK) { // just log it Console.WriteLine("CloseAllMediaDevices call to mediaSession.Close failed. Err=" + hr.ToString()); } } // Shut down the media source if (MediaSource != null) { hr = MediaSource.Shutdown(); if (hr != HResult.S_OK) { // just log it Console.WriteLine("CloseAllMediaDevices call to mediaSource.Shutdown failed. Err=" + hr.ToString()); } Marshal.ReleaseComObject(MediaSource); MediaSource = null; } // Shut down the media session (note we only closed it before). if (mediaSession != null) { hr = mediaSession.Shutdown(); if (hr != HResult.S_OK) { // just log it Console.WriteLine("CloseAllMediaDevices call to mediaSession.Shutdown failed. Err=" + hr.ToString()); } Marshal.ReleaseComObject(mediaSession); mediaSession = null; } if (currentVideoMediaType != null) { Marshal.ReleaseComObject(currentVideoMediaType); currentVideoMediaType = null; } }
//////////////////////////////////////////////////////////////////////////////////////// // Name: CPlayer::ShutDown (Public) // Description: // Releases all resources and shuts down Media Foundation /////////////////////////////////////////////////////////////////////////////////////////// HResult ShutDown() { Debug.WriteLine("\nCPlayer::ShutDown"); HResult hr = 0; IMFMediaSource pMediaSource; try { //Call shutdown on the sequencer source pMediaSource = (IMFMediaSource)m_pSequencerSource; hr = pMediaSource.Shutdown(); MFError.ThrowExceptionForHR(hr); //Close media session if (m_pMediaSession != null) { hr = m_pMediaSession.Close(); MFError.ThrowExceptionForHR(hr); // Wait for the close operation to complete bool res = m_hCloseEvent.WaitOne(5000, false); if (!res) { Debug.WriteLine("WaitForSingleObject timed out!"); } m_hCloseEvent.Close(); m_hCloseEvent = null; } //Shutdown media session hr = m_pMediaSession.Shutdown(); MFError.ThrowExceptionForHR(hr); // Shut down Media Foundation. hr = MFExtern.MFShutdown(); MFError.ThrowExceptionForHR(hr); } catch (Exception e) { hr = (HResult)Marshal.GetHRForException(e); } SafeRelease(m_pMediaSession); SafeRelease(m_pSequencerSource); SafeRelease(m_pPresentationClock); SafeRelease(m_pAudioRendererActivate); return(hr); }
protected void CloseSession() { int hr; /*if (m_pVideoDisplay != null) * { * Marshal.ReleaseComObject(m_pVideoDisplay); * m_pVideoDisplay = null; * } */ if (m_pSession != null) { hr = m_pSession.Close(); MFError.ThrowExceptionForHR(hr); // Wait for the close operation to complete /*bool res = m_hCloseEvent.WaitOne(5000, true); * if (!res) * { * TRACE(("WaitForSingleObject timed out!")); * }*/ } // Complete shutdown operations // 1. Shut down the media source if (m_pSource != null) { hr = m_pSource.Shutdown(); MFError.ThrowExceptionForHR(hr); COMBase.SafeRelease(m_pSource); m_pSource = null; } // 2. Shut down the media session. (Synchronous operation, no events.) if (m_pSession != null) { hr = m_pSession.Shutdown(); Marshal.ReleaseComObject(m_pSession); m_pSession = null; } }
/// <summary> /// Close a Media Session /// </summary> protected void CloseSession() { if (m_pVideoDisplay != null) { Marshal.ReleaseComObject(m_pVideoDisplay); m_pVideoDisplay = null; } if (m_pSession != null) { m_pSession.Close(); // Wait for the close operation to complete bool res = m_hCloseEvent.WaitOne(WAIT_TIMEOUT, true); if (!res) { TRACE("WaitForSingleObject Timed Out !"); } } // Complete shutdown operations // 1. Shut down the media source if (m_pSource != null) { m_pSource.Shutdown(); SafeRelease(m_pSource); m_pSource = null; } // 2. Shut down the media session. (Synchronous operation, no events.) if (m_pSession != null) { m_pSession.Shutdown(); Marshal.ReleaseComObject(m_pSession); m_pSession = null; } }