Пример #1
0
        protected void IsMediaTypeSupported(IMFMediaType pMediaType)
        {
            VideoTypeBuilder pProposed = null;

            bool bCompressed = false;
            MFVideoInterlaceMode InterlaceMode = MFVideoInterlaceMode.Unknown;
            MFVideoArea VideoCropArea;
            int width = 0, height = 0;

            try
            {
                // Helper object for reading the proposed type.
                pProposed = new VideoTypeBuilder(pMediaType);

                // Reject compressed media types.
                pProposed.IsCompressedFormat(out bCompressed);
                if (bCompressed)
                {
                    throw new COMException("Compressed formats not supported", MFError.MF_E_INVALIDMEDIATYPE);
                }

                // Validate the format.
                int i;
                pProposed.GetFourCC(out i);

                // The D3DPresentEngine checks whether the format can be used as
                // the back-buffer format for the swap chains.
                m_pD3DPresentEngine.CheckFormat(i);

                // Reject interlaced formats.
                pProposed.GetInterlaceMode(out InterlaceMode);
                if (InterlaceMode != MFVideoInterlaceMode.Progressive)
                {
                    throw new COMException("Interlaced formats not supported", MFError.MF_E_INVALIDMEDIATYPE);
                }

                pProposed.GetFrameDimensions(out width, out height);

                // Validate the various apertures (cropping regions) against the frame size.
                // Any of these apertures may be unspecified in the media type, in which case
                // we ignore it. We just want to reject invalid apertures.

                try
                {
                    pProposed.GetPanScanAperture(out VideoCropArea);
                    ValidateVideoArea(VideoCropArea, width, height);
                }
                catch { }

                try
                {
                    pProposed.GetGeometricAperture(out VideoCropArea);
                    ValidateVideoArea(VideoCropArea, width, height);
                }
                catch { }

                try
                {
                    pProposed.GetMinDisplayAperture(out VideoCropArea);
                    ValidateVideoArea(VideoCropArea, width, height);
                }
                catch { }

            }
            finally
            {
                pProposed.Dispose();
                //SafeRelease(pMediaType);
            }
        }
Пример #2
0
        //-----------------------------------------------------------------------------
        // GetSwapChainPresentParameters
        //
        // Given a media type that describes the video format, fills in the
        // D3DPRESENT_PARAMETERS for creating a swap chain.
        //-----------------------------------------------------------------------------
        protected void GetSwapChainPresentParameters(IMFMediaType pType, out D3DPRESENT_PARAMETERS pPP)
        {
            pPP = new D3DPRESENT_PARAMETERS();
            // Caller holds the object lock.

            int width = 0, height = 0;
            int d3dFormat = 0;

            VideoTypeBuilder pTypeHelper = null;

            if (m_hwnd == IntPtr.Zero)
            {
                throw new COMException("D3DPresentEngine::GetSwapChainPresentParameters", MFError.MF_E_INVALIDREQUEST);
            }

            try
            {
                // Create the helper object for reading the proposed type.
                pTypeHelper = new VideoTypeBuilder(pType);

                // Get some information about the video format.
                pTypeHelper.GetFrameDimensions(out width, out height);
                pTypeHelper.GetFourCC(out d3dFormat);

                pPP.BackBufferWidth = width;
                pPP.BackBufferHeight = height;
                pPP.Windowed = true;
                pPP.SwapEffect = D3DSWAPEFFECT.Copy;
                pPP.BackBufferFormat = (D3DFORMAT)d3dFormat;
                pPP.hDeviceWindow = m_hwnd;
                pPP.Flags = D3DPRESENTFLAG.Video;
                pPP.PresentationInterval = D3DPRESENT_INTERVAL.Default;

                D3DDEVICE_CREATION_PARAMETERS dparams;
                m_pDevice.GetCreationParameters(out dparams);

                if (dparams.DeviceType != D3DDEVTYPE.HAL)
                {
                    pPP.Flags |= D3DPRESENTFLAG.LockableBackbuffer;
                }
            }
            catch { }

            //SafeRelease(pTypeHelper);
        }