Example #1
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <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;
            }
        }
Example #2
0
        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;
            }
        }
 /// <summary>
 /// Closes the player
 /// </summary>
 public void Close()
 {
     Marshal.FinalReleaseComObject(m_Clock);
     Marshal.FinalReleaseComObject(m_pDescriptor);
     Marshal.FinalReleaseComObject(m_Rate);
     Marshal.FinalReleaseComObject(m_Volume);
     m_Session.Shutdown();
     m_Session = null;
     m_Eventthread.Join();
     GC.SuppressFinalize(this);
 }
Example #4
0
        ////////////////////////////////////////////////////////////////////////////////////////
        //  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);
        }
Example #5
0
 public void Dispose()
 {
     if (m_Session != null)
     {
         Marshal.FinalReleaseComObject(m_clock);
         Marshal.FinalReleaseComObject(m_rate);
         Marshal.FinalReleaseComObject(m_volume);
         m_Session.Shutdown();
         m_Session = null;
         m_eventthread?.Join();
     }
     GC.SuppressFinalize(this);
 }
Example #6
0
        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;
            }
        }
Example #7
0
        /// <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;
            }
        }