예제 #1
0
        protected override void Initialize(IGraphBuilder pGraphBuilder, IntPtr hMediaWindow)
        {
            object factoryObject   = null;
            object presenterObject = null;

            try
            {
                int hr = ClassFactory.GetEvrPresenterClassFactory(ref CLSID_CustomEVRPresenter, ref ClassFactory.IID_ClassFactory, out factoryObject);
                Marshal.ThrowExceptionForHR(hr);

                IClassFactory factory = (IClassFactory)factoryObject;

                var iidPresenter = typeof(IMFVideoPresenter).GUID;
                hr = factory.CreateInstance(null, ref iidPresenter, out presenterObject);
                Marshal.ThrowExceptionForHR(hr);

                IMFVideoPresenter presenter = (IMFVideoPresenter)presenterObject;

                IMFVideoRenderer renderer = (IMFVideoRenderer)BaseFilter; // will be released when IBaseFilter is released
                renderer.InitializeRenderer(null, presenter);

                IMFGetService pMFGetService = (IMFGetService)BaseFilter; // will be released when IBaseFilter is released
                object        o;
                var           serviceId = ServiceID.EnhancedVideoRenderer;
                var           iidImfVideoDisplayControl = typeof(IMFVideoDisplayControl).GUID;
                Marshal.ThrowExceptionForHR(pMFGetService.GetService(ref serviceId, ref iidImfVideoDisplayControl, out o));
                _pMFVideoDisplayControl = (IMFVideoDisplayControl)o;

                _pMFVideoDisplayControl.SetVideoWindow(hMediaWindow);
                _pMFVideoDisplayControl.SetAspectRatioMode(MFVideoAspectRatioMode.MFVideoARMode_None);

                _pvpPresenterConfig = (IPvpPresenterConfig)presenterObject;
                _pvpPresenterConfig.SetBufferCount(PRESENTER_BUFFER_COUNT);

                _pvpPresenterHook.HookUp(presenterObject);

                // as EVR requests IMFVideoDisplayControl from the presenter and our custom presenter implements IPvpPresenter and IPvpPresenterConfig
                // presenterObject and _pMFVideoDisplayControl point to the same RCW

                presenterObject = null; // we will release the presenter when releasing _pMFVideoDisplayControl
            }
            catch
            {
                _pMFVideoDisplayControl = null;
                _pvpPresenterConfig     = null;
            }
            finally
            {
                if (factoryObject != null)
                {
                    Marshal.FinalReleaseComObject(factoryObject);
                }

                if (presenterObject != null)
                {
                    Marshal.FinalReleaseComObject(presenterObject);
                }
            }
        }
예제 #2
0
 protected void Dispose(bool disp)
 {
     if (VideoPresenter != null)
     {
         Marshal.FinalReleaseComObject(VideoPresenter);
         VideoPresenter = null;
     }
 }
예제 #3
0
 public void Dispose()
 {
     if (VideoPresenter != null)
     {
         ((IEVRPresenterRegisterCallback)VideoPresenter).RegisterCallback(null);
     }
     VideoPresenter = null;
 }
예제 #4
0
        /// <summary>
        /// Create a new EVR video presenter
        /// </summary>
        /// <returns></returns>
        public static EvrPresenter CreateNew()
        {
            //            object comObject;
            //            int hr;



            /* Our exception var we use to hold the exception
             * until we need to throw it (after clean up) */
            //           Exception exception = null;

            /* A COM object we query form our native library */
            //          IClassFactory factory = null;

            /* Create our 'helper' class */
            var evrPresenter            = new EvrPresenter();
            IMFVideoPresenter presenter = null;

            try
            {
                var path      = System.IO.Path.GetDirectoryName(new Uri(typeof(EvrPresenter).Assembly.CodeBase).LocalPath);
                var dlltoload = System.IO.Path.Combine(path, IntPtr.Size == 8 ? @"EvrPresenter64.dll" : @"EvrPresenter32.dll");
                presenter = COMUtil.CreateFromDll <IMFVideoPresenter>(dlltoload, EVR_PRESENTER_CLSID);

                int count;
                var settings = presenter as IEVRPresenterSettings;
                DsError.ThrowExceptionForHR(settings.RegisterCallback(evrPresenter));
                DsError.ThrowExceptionForHR(settings.GetBufferCount(out count));
                DsError.ThrowExceptionForHR(settings.SetBufferCount(PRESENTER_BUFFER_COUNT));

                /* Populate the IMFVideoPresenter */
                evrPresenter.VideoPresenter = presenter;
            }
            catch (Exception ex)
            {
                COMUtil.TryFinalRelease(ref presenter);
                throw new WPFMediaKitException("Could not create EnhancedVideoRenderer", ex);
            }

            return(evrPresenter);

            //         /* Call the DLL export to create the class factory */

            /*       if(ProcessBits == 32)
             *             hr = DllGetClassObject32(EVR_PRESENTER_CLSID, IUNKNOWN_GUID, out comObject);
             *         else if(ProcessBits == 64)
             *             hr = DllGetClassObject64(EVR_PRESENTER_CLSID, IUNKNOWN_GUID, out comObject);
             *         else
             *         {
             *             exception = new Exception(string.Format("{0} bit processes are unsupported", ProcessBits));
             *             goto bottom;
             *         }
             */
            /* Check if our call to our DLL failed */

            /*          if(hr != 0 || comObject == null)
             *          {
             *              exception = new COMException("Could not create a new class factory.", hr);
             *              goto bottom;
             *          }
             */
            /* Cast the COM object that was returned to a COM interface type */

            /*          factory = comObject as IClassFactory;
             *
             *          if(factory == null)
             *          {
             *              exception = new Exception("Could not QueryInterface for the IClassFactory interface");
             *              goto bottom;
             *          }
             *
             *          /* Get the GUID of the IMFVideoPresenter */
            //          Guid guidVideoPresenter = typeof(IMFVideoPresenter).GUID;

            /* Creates a new instance of the IMFVideoPresenter */
            //          factory.CreateInstance(null, ref guidVideoPresenter, out comObject);

            /* QueryInterface for the IMFVideoPresenter */
            //           var presenter = comObject as IMFVideoPresenter;

            /* QueryInterface for our callback registration interface */

            /*            var registerCb = comObject as IEVRPresenterRegisterCallback;
             *          if(registerCb == null)
             *          {
             *              exception = new Exception("Could not QueryInterface for IEVRPresenterRegisterCallback");
             *              goto bottom;
             *          }
             */
            /* Register the callback to the 'helper' class we created */
            //            registerCb.RegisterCallback(evrPresenter);

            /* Populate the IMFVideoPresenter */
            //            evrPresenter.VideoPresenter = presenter;

            //            bottom:

            //          if(factory != null)
            //              Marshal.FinalReleaseComObject(factory);

            /*            if(exception != null)
             *              throw exception;
             *
             *          return evrPresenter;*/
        }
예제 #5
0
 public void Dispose()
 {
     if (VideoPresenter != null)
     {
         ((IEVRPresenterRegisterCallback)VideoPresenter).RegisterCallback(null);
     }
     VideoPresenter = null;
 }
예제 #6
0
 protected void Dispose(bool disp)
 {
     if (VideoPresenter != null)
     {
         Marshal.FinalReleaseComObject(VideoPresenter);
         VideoPresenter = null;
     }
 }