public int PresentImage(System.IntPtr dwUserID, ref VMR9PresentationInfo lpPresInfo)
        {
            Debug.Assert(dwUserID == cookie, "IVMRImagePresenter9.PresentImage");

            PresentImageCount++;
            return(0);
        }
Example #2
0
        public int PresentImage(IntPtr dwUserID, ref VMR9PresentationInfo lpPresInfo)
        {
            lock (this)
            {
                try
                {
                    createdtexture = true;
                    // If YUV mixing is activated, a surface copy is needed
                    if (needCopy)
                    {
                        // Use StretchRectangle to do the Pixel Format conversion
                        device.StretchRectangle(
                            videoSurface,
                            new Rectangle(Point.Empty, videoSize),
                            privateSurface,
                            new Rectangle(Point.Empty, videoSize),
                            TextureFilter.None
                            );
                    }
                }
                catch (SlimDXException e)
                {
                    // A Direct3D error can occure : Notify it to the VMR9 filter
                    return(e.ResultCode.Code);
                }
                catch
                {
                    // Or else, notify a more general error
                    return(E_FAIL);
                }

                // This presentation is a success
                return(0);
            }
        }
Example #3
0
        public int PresentImage(IntPtr dwUserID, ref VMR9PresentationInfo lpPresInfo)
        {
            int hr = 0;

            lock (this)
            {
                try
                {
                    // if we are in the middle of the display change
                    if (NeedToHandleDisplayChange())
                    {
                        // NOTE: this piece of code is left as a user exercise.
                        // The D3DDevice here needs to be switched
                        // to the device that is using another adapter
                    }

                    hr = PresentHelper(lpPresInfo);

                    return(hr);
                }
                catch (DirectXException e)
                {
                    return(e.ErrorCode);
                }
                catch
                {
                    return(E_FAIL);
                }
            }
        }
Example #4
0
        private int PresentHelper(VMR9PresentationInfo lpPresInfo)
        {
            int hr = 0;

            try
            {
                device.SetRenderTarget(0, renderTarget);

                if (privateTexture != null)
                {
                    Marshal.AddRef(lpPresInfo.lpSurf);
                    using (Surface surface = new Surface(lpPresInfo.lpSurf))
                    {
                        device.StretchRectangle(
                            surface,
                            new Rectangle(0, 0, surface.Description.Width, surface.Description.Height),
                            privateSurface,
                            new Rectangle(0, 0, privateSurface.Description.Width, privateSurface.Description.Height),
                            TextureFilter.None
                            );
                    }

                    hr = scene.DrawScene(device, privateTexture);
                    if (hr < 0)
                    {
                        return(hr);
                    }
                }
                else
                {
                    if (textures.ContainsKey(lpPresInfo.lpSurf))
                    {
                        hr = scene.DrawScene(device, textures[lpPresInfo.lpSurf] as Texture);
                        if (hr < 0)
                        {
                            return(hr);
                        }
                    }
                    else
                    {
                        hr = E_FAIL;
                    }
                }

                device.Present();
                return(0);
            }
            catch (DirectXException e)
            {
                return(e.ErrorCode);
            }
            catch
            {
                return(E_FAIL);
            }
        }
Example #5
0
        /// <summary>
        /// The PresentImage method is called at precisely the moment this video frame should be presented.
        /// </summary>
        /// <param name="dwUserID">
        /// An application-defined DWORD_PTR that uniquely identifies this instance of the VMR in scenarios when
        /// multiple instances of the VMR are being used with a single instance of an allocator-presenter.
        /// </param>
        /// <param name="lpPresInfo">
        /// Specifies a VMR9PresentationInfo structure that contains information about the video frame.
        /// </param>
        /// <returns>Returns an HRESULT</returns>
        public int PresentImage(IntPtr dwUserID, ref VMR9PresentationInfo lpPresInfo)
        {
            VMR9PresentationInfo presInfo = lpPresInfo;

            int hr = 0;

            try
            {
                lock (m_staticLock)
                {
                    /* Test to see if our device was lost, is so fix it */
                    TestRestoreLostDevice();

                    if (m_privateSurface != null)
                    {
                        hr = m_device.StretchRect(presInfo.lpSurf,
                                                  presInfo.rcSrc,
                                                  m_privateSurface,
                                                  presInfo.rcDst,
                                                  0);
                    }
                    if (hr < 0)
                    {
                        return(hr);
                    }
                }

                /* Notify to our listeners we just got a new frame */
                InvokeNewAllocatorFrame();

                hr = 0;
            }
            catch (Exception e)
            {
                logger.Fatal(e.Message);
                logger.Fatal(e.StackTrace);
                if (e.InnerException != null)
                {
                    logger.Fatal(e.InnerException.Message);
                    logger.Fatal(e.InnerException.StackTrace);
                }
                hr = E_FAIL;
            }

            return(hr);
        }