Пример #1
0
        //public void InitServicePointers(IMFTopologyServiceLookup pLookup)
        public int InitServicePointers(IntPtr p1Lookup)
        {
            // Make sure we *never* leave this entry point with an exception
            try
            {
                TRACE(("InitServicePointers"));

                int hr;
                int dwObjectCount = 0;
                IMFTopologyServiceLookup pLookup = null;
                IHack h1 = (IHack)new Hack();

                try
                {
                    h1.Set(p1Lookup, typeof(IMFTopologyServiceLookup).GUID, true);

                    pLookup = (IMFTopologyServiceLookup)h1;

                    lock (this)
                    {
                        // Do not allow initializing when playing or paused.
                        if (IsActive())
                        {
                            throw new COMException("EVRCustomPresenter::InitServicePointers", MFError.MF_E_INVALIDREQUEST);
                        }

                        SafeRelease(m_pClock); m_pClock = null;
                        SafeRelease(m_pMixer); m_pMixer = null;
                        SafeRelease(m_h2); m_h2 = null;
                        m_pMediaEventSink = null; // SafeRelease(m_pMediaEventSink);

                        dwObjectCount = 1;
                        object[] o = new object[1];

                        try
                        {
                            // Ask for the clock. Optional, because the EVR might not have a clock.
                            hr = pLookup.LookupService(
                                MFServiceLookupType.Global,   // Not used.
                                0,                          // Reserved.
                                MFServices.MR_VIDEO_RENDER_SERVICE,    // Service to look up.
                                typeof(IMFClock).GUID,         // Interface to look up.
                                o,
                                ref dwObjectCount              // Number of elements in the previous parameter.
                                );
                            MFError.ThrowExceptionForHR(hr);
                            m_pClock = (IMFClock)o[0];
                        }
                        catch { }

                        // Ask for the mixer. (Required.)
                        dwObjectCount = 1;

                        hr = pLookup.LookupService(
                            MFServiceLookupType.Global,
                            0,
                            MFServices.MR_VIDEO_MIXER_SERVICE,
                            typeof(IMFTransform).GUID,
                            o,
                            ref dwObjectCount
                            );
                        MFError.ThrowExceptionForHR(hr);
                        m_pMixer = (IMFTransform)o[0];

                        // Make sure that we can work with this mixer.
                        ConfigureMixer(m_pMixer);

                        // Ask for the EVR's event-sink interface. (Required.)
                        dwObjectCount = 1;

                        IMFTopologyServiceLookupAlt pLookup2 = (IMFTopologyServiceLookupAlt)pLookup;
                        IntPtr[] p2 = new IntPtr[1];

                        hr = pLookup2.LookupService(
                            MFServiceLookupType.Global,
                            0,
                            MFServices.MR_VIDEO_RENDER_SERVICE,
                            typeof(IMediaEventSink).GUID,
                            p2,
                            ref dwObjectCount
                            );
                        MFError.ThrowExceptionForHR(hr);

                        m_h2 = (IHack)new Hack();

                        m_h2.Set(p2[0], typeof(IMediaEventSink).GUID, false);

                        m_pMediaEventSink = (IMediaEventSink)m_h2;

                        // Successfully initialized. Set the state to "stopped."
                        m_RenderState = RenderState.Stopped;
                    }
                }
                finally
                {
                    SafeRelease(h1);
                }
                return S_Ok;
            }
            catch (Exception e)
            {
                return Marshal.GetHRForException(e);
            }
        }