Пример #1
0
        protected void CalculateOutputRectangle(IMFMediaType pProposed, out MFRect prcOutput)
        {
            int srcWidth = 0, srcHeight = 0;

            MFRatio inputPAR;
            MFRatio outputPAR;
            MFRect rcOutput = new MFRect();

            MFVideoArea displayArea;

            VideoTypeBuilder pmtProposed = null;

            // Helper object to read the media type.
            pmtProposed = new VideoTypeBuilder(pProposed);

            // Get the source's frame dimensions.
            pmtProposed.GetFrameDimensions(out srcWidth, out srcHeight);

            // Get the source's display area.
            pmtProposed.GetVideoDisplayArea(out displayArea);

            // Calculate the x,y offsets of the display area.
            int offsetX = (int)displayArea.OffsetX.GetOffset();
            int offsetY = (int)displayArea.OffsetY.GetOffset();

            // Use the display area if valid. Otherwise, use the entire frame.
            if (displayArea.Area.Width != 0 &&
                displayArea.Area.Height != 0 &&
                offsetX + displayArea.Area.Width <= (srcWidth) &&
                offsetY + displayArea.Area.Height <= (srcHeight))
            {
                rcOutput.left = offsetX;
                rcOutput.right = offsetX + displayArea.Area.Width;
                rcOutput.top = offsetY;
                rcOutput.bottom = offsetY + displayArea.Area.Height;
            }
            else
            {
                rcOutput.left = 0;
                rcOutput.top = 0;
                rcOutput.right = srcWidth;
                rcOutput.bottom = srcHeight;
            }

            // rcOutput is now either a sub-rectangle of the video frame, or the entire frame.

            // If the pixel aspect ratio of the proposed media type is different from the monitor's,
            // letterbox the video. We stretch the image rather than shrink it.

            inputPAR = pmtProposed.GetPixelAspectRatio();    // Defaults to 1:1

            outputPAR.Denominator = outputPAR.Numerator = 1; // This is an assumption of the sample.

            // Adjust to get the correct picture aspect ratio.
            prcOutput = CorrectAspectRatio(rcOutput, inputPAR, outputPAR);

            pmtProposed.Dispose();
        }