public int ReleaseServicePointersImpl()
        {
            try
            {
                HRESULT hr = S_OK;

                // Enter the shut-down state.
                lock (m_ObjectLock)
                {
                    m_RenderState = RENDER_STATE.RENDER_STATE_SHUTDOWN;
                }

                // Flush any samples that were scheduled.
                Flush();

                // Clear the media type and release related resources (surfaces, etc).
                SetMediaType(null);

                // Release all services that were acquired from InitServicePointers.
                m_pClock = null;

                if (m_pMixer != IntPtr.Zero)
                {
                    Marshal.Release(m_pMixer);
                    m_pMixer = IntPtr.Zero;
                }

                m_pMediaEventSink = null;
                return hr;
            }
            catch (Exception _exception)
            {
                throw _exception;
            }
        }
 public int OnClockStopImpl(long hnsSystemTime)
 {
     HRESULT hr = S_OK;
     lock (m_ObjectLock)
     {
         hr = CheckShutdown();
         if (hr.Failed) return hr;
         if (m_RenderState != RENDER_STATE.RENDER_STATE_STOPPED)
         {
             m_RenderState = RENDER_STATE.RENDER_STATE_STOPPED;
             Flush();
         }
     }
     return hr;
 }
        public int OnClockStartImpl(long hnsSystemTime, long llClockStartOffset)
        {
            HRESULT hr = S_OK;

            lock (m_ObjectLock)
            {
                hr = CheckShutdown();
                if (hr.Failed) return hr;

                m_RenderState = RENDER_STATE.RENDER_STATE_STARTED;

                // Check if the clock is already active (not stopped).
                if (IsActive())
                {
                    // If the clock position changes while the clock is active, it
                    // is a seek request. We need to flush all pending samples.
                    if (llClockStartOffset != PRESENTATION_CURRENT_POSITION)
                    {
                        Flush();
                    }
                }

                ProcessOutputLoop();
            }
            return hr;
        }
        public int OnClockRestartImpl(long hnsSystemTime)
        {
            HRESULT hr = S_OK;
            lock (m_ObjectLock)
            {
                hr = CheckShutdown();
                if (hr.Failed) return hr;

                // The EVR calls OnClockRestart only while paused.
                ASSERT(m_RenderState == RENDER_STATE.RENDER_STATE_PAUSED);

                m_RenderState = RENDER_STATE.RENDER_STATE_STARTED;

                // Now resume the presentation loop.
                ProcessOutputLoop();
            }
            return hr;
        }
        public int OnClockPauseImpl(long hnsSystemTime)
        {
            HRESULT hr = S_OK;

            lock (m_ObjectLock)
            {
                // We cannot pause the clock after shutdown.
                hr = CheckShutdown();
                if (hr.Failed) return hr;

                // Set the state. (No other actions are necessary.)
                m_RenderState = RENDER_STATE.RENDER_STATE_PAUSED;

            }
            return hr;
        }
        public int InitServicePointersImpl(IntPtr pLookup)
        {
            try
            {
                if (pLookup == IntPtr.Zero) return E_POINTER;

                HRESULT hr = S_OK;

                lock (m_ObjectLock)
                {
                    // Do not allow initializing when playing or paused.
                    if (IsActive()) return MFHelper.MF_E_INVALIDREQUEST;

                    if (m_pMixer != IntPtr.Zero)
                    {
                        Marshal.Release(m_pMixer);
                        m_pMixer = IntPtr.Zero;
                    }
                    m_pClock = null;
                    m_pMediaEventSink = null;

                    uint dwObjectCount;

                    MFTopologyServiceLookup _lookUp = new MFTopologyServiceLookup(pLookup);

                    if (hr.Succeeded)
                    {
                        // Ask for the clock. Optional, because the EVR might not have a clock.
                        dwObjectCount = 1;

                        IntPtr[] o = new IntPtr[dwObjectCount];

                        _lookUp.LookupService(
                            MFServiceLookUpType.GLOBAL,
                            0,
                            MFServices.MR_VIDEO_RENDER_SERVICE,
                            typeof(IMFClock).GUID,
                            o,
                            ref dwObjectCount
                            );

                        if (o[0] != IntPtr.Zero && dwObjectCount > 0)
                        {
                            m_pClock = (IMFClock)Marshal.GetObjectForIUnknown(o[0]);
                        }
                        // Ask for the mixer. (Required.)
                        dwObjectCount = 1;

                        hr = (HRESULT)_lookUp.LookupService(
                            MFServiceLookUpType.GLOBAL,
                            0,
                            MFServices.MR_VIDEO_MIXER_SERVICE,
                            typeof(IMFTransform).GUID,
                            o,
                            ref dwObjectCount);

                        hr.Assert();

                        if (o[0] != IntPtr.Zero && dwObjectCount > 0)
                        {
                            m_pMixer = o[0];
                        }

                        hr = ConfigureMixer((IMFTransform)Marshal.GetObjectForIUnknown(m_pMixer));

                        hr.Assert();
                        if (hr.Failed) return hr;

                        o[0] = IntPtr.Zero;
                        // Ask for the EVR's event-sink interface. (Required.)
                        dwObjectCount = 1;
                        hr = (HRESULT)_lookUp.LookupService(
                            MFServiceLookUpType.GLOBAL,
                            0,
                            MFServices.MR_VIDEO_RENDER_SERVICE,
                            typeof(IMediaEventSink).GUID,
                            o,
                            ref dwObjectCount);

                        hr.Assert();
                        if (hr.Failed) return hr;

                        if (o[0] != IntPtr.Zero && dwObjectCount > 0)
                        {
                            m_pMediaEventSink = new MediaEventSink(o[0]);
                        }

                        // Successfully initialized. Set the state to "stopped."
                        m_RenderState = RENDER_STATE.RENDER_STATE_STOPPED;
                    }
                    _lookUp.Dispose();
                }

                return hr;
            }
            catch (Exception _exception)
            {
                throw _exception;
            }
        }