コード例 #1
0
ファイル: DShowPlayer.cs プロジェクト: gmorkvenas/pimaker
        public void OpenOverlay(Guid gPresenter)
        {
            object o;

            if (m_ImageHandlers != null)
            {
                foreach (ImageHandler ih in m_ImageHandlers)
                {
                    ih.Dispose();
                }
                m_ImageHandlers = null;
            }

            m_ImageHandlers = new ImageHandler[2];

            m_ImageHandlers[0] = new ImageFromPixels(30, new FourCC("YUY2"), 320, 240, 16);
            //m_ImageHandlers[0] = new ImageFromPixels(30, new FourCC(3), 320, 240, 32, 255);
            //m_ImageHandlers[0] = new ImageFromPixels(30, new FourCC("AYUV"), 320, 240, 32, 255);
            //m_ImageHandlers[0] = new ImageFromPixels(30, new FourCC("NV12"), 320, 240, 12, 255);
            //m_ImageHandlers[1] = new ImageFromText(30, new FourCC(3), 320, 240, 32);
            m_ImageHandlers[1] = new ImageFromText(30, new FourCC("AYUV"), 320, 240, 32);

            InitializeGraph();
            SetupGraph(gPresenter);

            IMFGetService pGetService = (IMFGetService)m_pEVR;

            pGetService.GetService(MFServices.MR_VIDEO_MIXER_SERVICE, typeof(IMFVideoMixerControl).GUID, out o);
            m_pMixer = (IMFVideoMixerControl)o;

            pGetService.GetService(MFServices.MR_VIDEO_RENDER_SERVICE, typeof(IMFVideoPositionMapper).GUID, out o);
            m_pMapper = (IMFVideoPositionMapper)o;
        }
コード例 #2
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);
                }
            }
        }
コード例 #3
0
ファイル: EVR.cs プロジェクト: jeason0813/power-video-player
        protected override void Initialize(IGraphBuilder pGraphBuilder, IntPtr hMediaWindow)
        {
            // QUERY the EVR interfaces
            try
            {
                IMFGetService pMFGetService = (IMFGetService)BaseFilter; // will be released when IBaseFilter is released
                object        o;
                Guid          serviceId = ServiceID.EnhancedVideoRenderer;
                Guid          IID_IMFVideoDisplayControl = typeof(IMFVideoDisplayControl).GUID;
                Marshal.ThrowExceptionForHR(pMFGetService.GetService(ref serviceId, ref IID_IMFVideoDisplayControl, out o));
                _pMfVideoDisplayControl = (IMFVideoDisplayControl)o;

                _pMfVideoDisplayControl.SetVideoWindow(hMediaWindow);
                _pMfVideoDisplayControl.SetAspectRatioMode(MFVideoAspectRatioMode.MFVideoARMode_None);
            }
            catch (Exception e)
            {
                throw new FilterGraphBuilderException(GraphBuilderError.ConfigureEVR, e);
            }
        }
コード例 #4
0
        /// <summary>
        /// Retrieves a service interface.
        /// </summary>
        /// <typeparam name="T">The COM interface being requested.</typeparam>
        /// <param name="getService">A valid IMFGetService instance.</param>
        /// <param name="guidService">The service identifier (SID) of the service.</param>
        /// <param name="service">Receives the interface instance.</param>
        /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns>
        public static HResult GetService <T>(this IMFGetService getService, Guid guidService, out T service) where T : class
        {
            if (getService == null)
            {
                throw new ArgumentNullException("getService");
            }

            Type typeOfT = typeof(T);

            if (!typeOfT.IsInterface)
            {
                throw new ArgumentOutOfRangeException("T", "T must be a COM visible interface.");
            }

            object tmp;

            HResult hr = getService.GetService(guidService, typeOfT.GUID, out tmp);

            service = hr.Succeeded() ? tmp as T : default(T);

            return(hr);
        }
コード例 #5
0
ファイル: DSFilterNodeUI.cs プロジェクト: manuag/DSGraphEdit
        /// <summary>
        /// Event that is raised after a DaggerNode has been created and associated to the UI element
        /// </summary>
        /// <param name="node"></param>
        void DSFilterNodeUI_DaggerNodeAttached(DaggerLib.Core.DaggerNode node)
        {
            _dsfilternode = (DSFilterNode)node;
            CaptionText   = node.ToString();

            // hook the AfterNodeRemoved event to dispose of any directshow interfaces
            node.AfterNodeRemoved += new DaggerLib.Core.AfterNodeRemoveHandler(node_AfterNodeRemoved);

            // get the IBaseFilter from the DSFilterNode
            IBaseFilter filter = _dsfilternode._filter;

            // only grab the video window or EVR if it was manually added to the graph via the UI
            if (_dsfilternode._manualAdded || (_dsfilternode.ParentGraph.ParentUIGraph as DSDaggerUIGraph)._filterGraphCreated)
            {
                // if it supports IVideoWindow create a VideoInternalWindow for it
                IVideoWindow vw = filter as IVideoWindow;
                if (vw != null)
                {
                    try
                    {
                        _videoWindow         = new VideoInternalWindow(CaptionText, filter);
                        _videoWindow.Dock    = DockStyle.Fill;
                        _videoWindow.Visible = true;
                        InternalControl.Controls.Add(_videoWindow);

                        // only nodes with video windows are resizeable
                        Resizable = true;

                        // hook the connection events to init/deinit the video window
                        node.ParentGraph.AfterPinsConnected += new DaggerLib.Core.PinAfterConnectedHandler(ParentGraph_AfterPinsConnected);
                    }
                    catch (Exception ex)
                    {
#if DEBUG
                        MessageBox.Show(ex.Message);
#endif
                        _videoWindow = null;
                    }
                }

                // if it's an Enhaced Video Renderer create a VideoInternalWindow for it
                // (see docs for Windows Media Foundation)
                IMFGetService mfgs = filter as IMFGetService;
                if (mfgs != null)
                {
                    // this is a video horse of a different color
                    // create a video clipping window for the Media Foundation Enhanced Video Renderer
                    try
                    {
                        // get the IMFVideoDisplayControl for the EVR filter
                        object o = null;
                        mfgs.GetService(MediaFoundation.MFServices.MR_VIDEO_RENDER_SERVICE,
                                        typeof(IMFVideoDisplayControl).GUID,
                                        out o
                                        );
                        m_pVideoDisplay = o as IMFVideoDisplayControl;

                        // if the Video Size is 0,0 the EVR hasn't been initialized/connected yet
                        MediaFoundation.Misc.SIZE videoSize = new MediaFoundation.Misc.SIZE();
                        MediaFoundation.Misc.SIZE ar        = new MediaFoundation.Misc.SIZE();
                        m_pVideoDisplay.GetNativeVideoSize(videoSize, ar);

                        if (videoSize.cx == 0 && videoSize.cy == 0)
                        {
                            // You only get one chance to set the number of pins in an EVR filter.
                            PinsComboBoxForm pcf = new PinsComboBoxForm();
                            if (pcf.ShowDialog() == DialogResult.OK)
                            {
                                (filter as IEVRFilterConfig).SetNumberOfStreams(pcf.Value);
                            }
                            pcf.Dispose();
                        }

                        _videoWindow         = new VideoInternalWindow(CaptionText, m_pVideoDisplay);
                        _videoWindow.Dock    = DockStyle.Fill;
                        _videoWindow.Visible = true;
                        InternalControl.Controls.Add(_videoWindow);

                        // only nodes with video windows are resizeable
                        Resizable = true;

                        // hook the connection events to init/deinit the video window
                        node.ParentGraph.AfterPinsConnected += new DaggerLib.Core.PinAfterConnectedHandler(ParentGraph_AfterPinsConnected);
                    }
                    catch (InvalidCastException)
                    {
                        m_pVideoDisplay = null;
                    }
                }
            }

            // if it's a DMO, create the DMO properties page for it
            if ((filter as IDMOWrapperFilter) != null)
            {
                // set the caption to show it's a DMO
                CaptionText           = "DMO - " + CaptionText;
                CaptionColor          = Color.Green;
                CaptionColorUnfocused = Color.LightGreen;
            }

            // remove clock button if it doesn't support IReferenceClock
            _referenceClock = filter as IReferenceClock;
            if (_referenceClock == null)
            {
                CaptionButtons.RemoveAt(CaptionButtons.AllButtons.IndexOf(_clockButton));
            }
            else
            {
                // see if this filter is the reference clock for the graph
                IReferenceClock graphClock = null;
                filter.GetSyncSource(out graphClock);
                _clockButton.Tag = false;
                _clockButton.MouseOutsideTint = Color.DarkGray;
                if (graphClock != null)
                {
                    if (graphClock == _referenceClock)
                    {
                        _clockButton.MouseOutsideTint = Color.Yellow;
                        _clockButton.Tag = true;
                    }
                    Marshal.ReleaseComObject(graphClock);
                }
            }

            // remove video window button if it's not a video window
            if (_videoWindow == null)
            {
                CaptionButtons.RemoveAt(CaptionButtons.AllButtons.IndexOf(_detachVideoWindowButton));
            }

            // Sync the pins to the Pin Property Pages
            SyncPinPropertyPages(null);

            // set it to the smallest possible size.  DaggerLib uses InternalControlMinimumSize
            // to prevent the UI node from being smaller than designated
            this.Size = new Size(1, 1);
        }
コード例 #6
0
ファイル: DShowPlayer.cs プロジェクト: gmorkvenas/pimaker
        private void InitializeEVR(IBaseFilter pEVR, int dwStreams, out IMFVideoDisplayControl ppDisplay)
        {
            IMFVideoRenderer       pRenderer;
            IMFVideoDisplayControl pDisplay;
            IEVRFilterConfig       pConfig;
            IMFVideoPresenter      pPresenter;

            // Before doing anything else, set any custom presenter or mixer.

            // Presenter?
            if (m_clsidPresenter != Guid.Empty)
            {
                Type type = Type.GetTypeFromCLSID(m_clsidPresenter);

                // An error here means that the custom presenter sample from
                // http://mfnet.sourceforge.net hasn't been installed or
                // registered.
                pPresenter = (IMFVideoPresenter)Activator.CreateInstance(type);

                try
                {
                    pRenderer = (IMFVideoRenderer)pEVR;

                    pRenderer.InitializeRenderer(null, pPresenter);
                }
                finally
                {
                    //Marshal.ReleaseComObject(pPresenter);
                }
            }

            // Continue with the rest of the set-up.

            // Set the video window.
            object        o;
            IMFGetService pGetService = null;

            pGetService = (IMFGetService)pEVR;
            pGetService.GetService(MFServices.MR_VIDEO_RENDER_SERVICE, typeof(IMFVideoDisplayControl).GUID, out o);

            try
            {
                pDisplay = (IMFVideoDisplayControl)o;
            }
            catch
            {
                Marshal.ReleaseComObject(o);
                throw;
            }

            try
            {
                // Set the number of streams.
                pDisplay.SetVideoWindow(m_hwndVideo.Handle);

                if (dwStreams > 1)
                {
                    pConfig = (IEVRFilterConfig)pEVR;
                    pConfig.SetNumberOfStreams(dwStreams);
                }

                // Set the display position to the entire window.
                Rectangle r  = m_hwndVideo.ClientRectangle;
                MFRect    rc = new MFRect(r.Left, r.Top, r.Right, r.Bottom);

                pDisplay.SetVideoPosition(null, rc);

                // Return the IMFVideoDisplayControl pointer to the caller.
                ppDisplay = pDisplay;
            }
            finally
            {
                //Marshal.ReleaseComObject(pDisplay);
            }
            m_pMixer = null;
        }