/// <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;*/
        }
Beispiel #2
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();

            /* 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;
        }
Beispiel #3
0
        protected void CreateOutputNode(
            IMFStreamDescriptor pSourceSD,
            out IMFTopologyNode ppNode
            )
        {
            IMFTopologyNode     pNode             = null;
            IMFMediaTypeHandler pHandler          = null;
            IMFActivate         pRendererActivate = null;

            Guid guidMajorType = Guid.Empty;
            int  hr            = S_Ok;

            // Get the stream ID.
            int streamID = 0;

            try
            {
                try
                {
                    pSourceSD.GetStreamIdentifier(out streamID); // Just for debugging, ignore any failures.
                }
                catch
                {
                    TRACE("IMFStreamDescriptor::GetStreamIdentifier" + hr.ToString());
                }

                // Get the media type handler for the stream.
                pSourceSD.GetMediaTypeHandler(out pHandler);

                // Get the major media type.
                pHandler.GetMajorType(out guidMajorType);

                // Create a downstream node.
                MFExtern.MFCreateTopologyNode(MFTopologyType.OutputNode, out pNode);

                // Create an IMFActivate object for the renderer, based on the media type.
                if (MFMediaType.Audio == guidMajorType)
                {
                    // Create the audio renderer.
                    TRACE(string.Format("Stream {0}: audio stream", streamID));
                    MFExtern.MFCreateAudioRendererActivate(out pRendererActivate);
                }
                else if (MFMediaType.Video == guidMajorType)
                {
                    // Create the video renderer.
                    TRACE(string.Format("Stream {0}: video stream", streamID));
                    MFExtern.MFCreateVideoRendererActivate(m_hwndVideo, out pRendererActivate);

                    object ppv;
                    pRendererActivate.ActivateObject(typeof(IMFVideoRenderer).GUID, out ppv);

                    var renderer = ppv as IMFVideoRenderer;
                    m_customPresenter = EvrPresenter.CreateNew();
                    m_customPresenter.NewAllocatorFrame   += m_customPresenter_NewAllocatorFrame;
                    m_customPresenter.NewAllocatorSurface += m_customPresenter_NewAllocatorSurface;
                    var presenter = m_customPresenter.VideoPresenter as IMFVideoDisplayControl;
                    hr = presenter.SetVideoWindow(m_hwndVideo);
                    hr = renderer.InitializeRenderer(null, m_customPresenter.VideoPresenter);
                    var settings = presenter as IEVRPresenterSettings;
                    settings.SetBufferCount(5);
                }
                else
                {
                    TRACE(string.Format("Stream {0}: Unknown format", streamID));
                    throw new COMException("Unknown format", E_Fail);
                }

                // Set the IActivate object on the output node.
                pNode.SetObject(pRendererActivate);

                // Return the IMFTopologyNode pointer to the caller.
                ppNode = pNode;
            }
            catch
            {
                // If we failed, release the pNode
                SafeRelease(pNode);
                throw;
            }
            finally
            {
                // Clean up.
                SafeRelease(pHandler);
                SafeRelease(pRendererActivate);
            }
        }
        /// <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();

            /* 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);
        }
Beispiel #5
0
        protected void CreateOutputNode(
            IMFStreamDescriptor pSourceSD,
            out IMFTopologyNode ppNode
            )
        {
            IMFTopologyNode pNode = null;
            IMFMediaTypeHandler pHandler = null;
            IMFActivate pRendererActivate = null;

            Guid guidMajorType = Guid.Empty;
            int hr = S_Ok;

            // Get the stream ID.
            int streamID = 0;

            try
            {
                try
                {
                    pSourceSD.GetStreamIdentifier(out streamID); // Just for debugging, ignore any failures.
                }
                catch
                {
                    TRACE("IMFStreamDescriptor::GetStreamIdentifier" + hr.ToString());
                }

                // Get the media type handler for the stream.
                pSourceSD.GetMediaTypeHandler(out pHandler);

                // Get the major media type.
                pHandler.GetMajorType(out guidMajorType);

                // Create a downstream node.
                MFExtern.MFCreateTopologyNode(MFTopologyType.OutputNode, out pNode);

                // Create an IMFActivate object for the renderer, based on the media type.
                if (MFMediaType.Audio == guidMajorType)
                {
                    // Create the audio renderer.
                    TRACE(string.Format("Stream {0}: audio stream", streamID));
                    MFExtern.MFCreateAudioRendererActivate(out pRendererActivate);
                }
                else if (MFMediaType.Video == guidMajorType)
                {
                    // Create the video renderer.
                    TRACE(string.Format("Stream {0}: video stream", streamID));
                    MFExtern.MFCreateVideoRendererActivate(m_hwndVideo, out pRendererActivate);

                    object ppv;
                    pRendererActivate.ActivateObject(typeof(IMFVideoRenderer).GUID, out ppv);

                    var renderer = ppv as IMFVideoRenderer;
                    m_customPresenter = EvrPresenter.CreateNew();
                    m_customPresenter.NewAllocatorFrame += m_customPresenter_NewAllocatorFrame;
                    m_customPresenter.NewAllocatorSurface += m_customPresenter_NewAllocatorSurface;
                    var presenter = m_customPresenter.VideoPresenter as IMFVideoDisplayControl;
                    hr = presenter.SetVideoWindow(m_hwndVideo);
                    hr = renderer.InitializeRenderer(null, m_customPresenter.VideoPresenter);
                    var settings = presenter as IEVRPresenterSettings;
                    settings.SetBufferCount(5);
                }
                else
                {
                    TRACE(string.Format("Stream {0}: Unknown format", streamID));
                    throw new COMException("Unknown format", E_Fail);
                }

                // Set the IActivate object on the output node.
                pNode.SetObject(pRendererActivate);

                // Return the IMFTopologyNode pointer to the caller.
                ppNode = pNode;
            }
            catch
            {
                // If we failed, release the pNode
                SafeRelease(pNode);
                throw;
            }
            finally
            {
                // Clean up.
                SafeRelease(pHandler);
                SafeRelease(pRendererActivate);
            }
        }
        /// <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 e)
            {
                COMUtil.TryFinalRelease(ref presenter);
                throw new Exception("Could not create IMFVideoPresenter", e);
            }

            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;*/
        }