private IBaseFilter GetRendererFilter(EVideoRendererType videoRendererType)
        {
            switch (videoRendererType)
            {
            case EVideoRendererType.EnhancedVideoRenderer:
                var evr       = new EnhancedVideoRenderer();
                var evrFilter = (IBaseFilter)evr;

                // Initialize the EVR renderer with our custom video presenter
                var evrPresenter = EVRPresenter.Create();
                ((IMFVideoRenderer)evr).InitializeRenderer(null, evrPresenter.VideoPresenter);

                // Configure the presenter with our hWnd
                var displayControl = (IMFVideoDisplayControl)evrPresenter.VideoPresenter;
                displayControl.SetVideoWindow(_hwnd);

                _customPresenter = evrPresenter;
                _customPresenter.NewSurfaceEvent += _player.NewSurface;
                _customPresenter.NewFrameEvent   += _player.NewFrame;

                return(evrFilter);

            case EVideoRendererType.VideoMixingRenderer:
                var vmr       = new VideoMixingRenderer9();
                var vmrFilter = (IBaseFilter)vmr;

                var vmrPresenter = VMR9Presenter.Create();

                // Initialize the VMR renderer with out custom video presenter
                var filterConfig = (IVMRFilterConfig9)vmr;
                filterConfig.SetRenderingMode(VMR9Mode.Renderless);
                filterConfig.SetNumberOfStreams(1);

                var surfaceAllocatorNotify = (IVMRSurfaceAllocatorNotify9)vmr;

                surfaceAllocatorNotify.AdviseSurfaceAllocator(IntPtr.Zero, vmrPresenter.SurfaceAllocator);
                vmrPresenter.SurfaceAllocator.AdviseNotify(surfaceAllocatorNotify);

                _customPresenter = vmrPresenter;
                _customPresenter.NewSurfaceEvent += _player.NewSurface;
                _customPresenter.NewFrameEvent   += _player.NewFrame;

                return(vmrFilter);
            }

            return(null);
        }
Example #2
0
        /// <summary>
        /// Creates an instance of the EVR
        /// </summary>
        private IBaseFilter CreateEnhancedVideoRenderer(IGraphBuilder graph)
        {
            var evr = new EnhancedVideoRenderer();
            var filter = evr as IBaseFilter;

            int hr = graph.AddFilter(filter, string.Format("Renderer: {0}", VideoRendererType.EnhancedVideoRenderer));
            DsError.ThrowExceptionForHR(hr);

            /* QueryInterface for the IMFVideoRenderer */
            var videoRenderer = filter as IMFVideoRenderer;

            if (videoRenderer == null)
                throw new Exception("Could not QueryInterface for the IMFVideoRenderer");

            /* Create a new EVR presenter */
            var presenter = EvrPresenter.CreateNew();

            /* Initialize the EVR renderer with the custom video presenter */
            hr = videoRenderer.InitializeRenderer(null, presenter.VideoPresenter);
            DsError.ThrowExceptionForHR(hr);

            var presenterSettings = presenter.VideoPresenter as IEVRPresenterSettings;
            if (presenterSettings == null)
                throw new Exception("Could not QueryInterface for the IEVRPresenterSettings");

            presenterSettings.SetBufferCount(4);

            /* Use our interop hWnd */
            IntPtr handle = HwndHelper.Handle;

            /* QueryInterface the IMFVideoDisplayControl */
            var displayControl = presenter.VideoPresenter as IMFVideoDisplayControl;

            if (displayControl == null)
                throw new Exception("Could not QueryInterface the IMFVideoDisplayControl");

            /* Configure the presenter with our hWnd */
            hr = displayControl.SetVideoWindow(handle);
            DsError.ThrowExceptionForHR(hr);

            var filterConfig = filter as IEVRFilterConfig;

            if(filterConfig != null)
                filterConfig.SetNumberOfStreams(4);

            RegisterCustomAllocator(presenter);

            return filter;
        }
Example #3
0
        /// <summary>
        /// Creates an instance of the EVR
        /// </summary>
        private IBaseFilter CreateEnhancedVideoRenderer(IGraphBuilder graph, int streamCount)
        {
            EvrPresenter presenter;
            IBaseFilter  filter;

            lock (m_videoRendererInitLock)
            {
                var evr = new EnhancedVideoRenderer();
                filter = evr as IBaseFilter;

                int hr = graph.AddFilter(filter, string.Format("Renderer: {0}", VideoRendererType.EnhancedVideoRenderer));
                DsError.ThrowExceptionForHR(hr);

                /* QueryInterface for the IMFVideoRenderer */
                var videoRenderer = filter as IMFVideoRenderer;

                if (videoRenderer == null)
                {
                    throw new Exception("Could not QueryInterface for the IMFVideoRenderer");
                }

                /* Create a new EVR presenter */
                presenter = EvrPresenter.CreateNew();

                /* Initialize the EVR renderer with the custom video presenter */
                hr = videoRenderer.InitializeRenderer(null, presenter.VideoPresenter);
                DsError.ThrowExceptionForHR(hr);

                var presenterSettings = presenter.VideoPresenter as IEVRPresenterSettings;
                if (presenterSettings == null)
                {
                    throw new Exception("Could not QueryInterface for the IEVRPresenterSettings");
                }

                presenterSettings.SetBufferCount(3);

                /* Use our interop hWnd */
                IntPtr handle = GetDesktopWindow();//HwndHelper.Handle;

                /* QueryInterface the IMFVideoDisplayControl */
                var displayControl = presenter.VideoPresenter as IMFVideoDisplayControl;

                if (displayControl == null)
                {
                    throw new Exception("Could not QueryInterface the IMFVideoDisplayControl");
                }

                /* Configure the presenter with our hWnd */
                hr = displayControl.SetVideoWindow(handle);
                DsError.ThrowExceptionForHR(hr);

                var filterConfig = filter as IEVRFilterConfig;

                if (filterConfig != null)
                {
                    filterConfig.SetNumberOfStreams(streamCount);
                }
            }


            RegisterCustomAllocator(presenter);

            return(filter);
        }
        private IBaseFilter GetRendererFilter(EVideoRendererType videoRendererType)
        {
            switch (videoRendererType)
            {
                case EVideoRendererType.EnhancedVideoRenderer:
                    var evr = new EnhancedVideoRenderer();
                    var evrFilter = (IBaseFilter)evr;

                    // Initialize the EVR renderer with our custom video presenter
                    var evrPresenter = EVRPresenter.Create();
                    ((IMFVideoRenderer)evr).InitializeRenderer(null, evrPresenter.VideoPresenter);

                    // Configure the presenter with our hWnd
                    var displayControl = (IMFVideoDisplayControl)evrPresenter.VideoPresenter;
                    displayControl.SetVideoWindow(_hwnd);

                    _customPresenter = evrPresenter;
                    _customPresenter.NewSurfaceEvent += _player.NewSurface;
                    _customPresenter.NewFrameEvent += _player.NewFrame;

                    return evrFilter;

                case EVideoRendererType.VideoMixingRenderer:
                    var vmr = new VideoMixingRenderer9();
                    var vmrFilter = (IBaseFilter)vmr;

                    var vmrPresenter = VMR9Presenter.Create();

                    // Initialize the VMR renderer with out custom video presenter
                    var filterConfig = (IVMRFilterConfig9)vmr;
                    filterConfig.SetRenderingMode(VMR9Mode.Renderless);
                    filterConfig.SetNumberOfStreams(1);

                    var surfaceAllocatorNotify = (IVMRSurfaceAllocatorNotify9)vmr;

                    surfaceAllocatorNotify.AdviseSurfaceAllocator(IntPtr.Zero, vmrPresenter.SurfaceAllocator);
                    vmrPresenter.SurfaceAllocator.AdviseNotify(surfaceAllocatorNotify);

                    _customPresenter = vmrPresenter;
                    _customPresenter.NewSurfaceEvent += _player.NewSurface;
                    _customPresenter.NewFrameEvent += _player.NewFrame;

                    return vmrFilter;
            }

            return null;
        }