Exemplo n.º 1
0
        // Formats
        protected void CreateOptimalVideoType(IMFMediaType pProposed, out IMFMediaType ppOptimal)
        {
            try
            {
                MFRect rcOutput;
                MFVideoArea displayArea;

                IMFMediaType pOptimalType = null;

                // Create the helper object to manipulate the optimal type.
                VideoTypeBuilder pmtOptimal = new VideoTypeBuilder();

                // Clone the proposed type.
                pmtOptimal.CopyFrom(pProposed);

                // Modify the new type.

                // For purposes of this SDK sample, we assume
                // 1) The monitor's pixels are square.
                // 2) The presenter always preserves the pixel aspect ratio.

                // Set the pixel aspect ratio (PAR) to 1:1 (see assumption #1, above)
                pmtOptimal.SetPixelAspectRatio(1, 1);

                // Get the output rectangle.
                rcOutput = m_pD3DPresentEngine.GetDestinationRect();
                if (rcOutput.IsEmpty())
                {
                    // Calculate the output rectangle based on the media type.
                    CalculateOutputRectangle(pProposed, out rcOutput);
                }

                // Set the extended color information: Use BT.709
                pmtOptimal.SetYUVMatrix(MFVideoTransferMatrix.BT709);
                pmtOptimal.SetTransferFunction(MFVideoTransferFunction.Func709);
                pmtOptimal.SetVideoPrimaries(MFVideoPrimaries.BT709);
                pmtOptimal.SetVideoNominalRange(MFNominalRange.MFNominalRange_16_235);
                pmtOptimal.SetVideoLighting(MFVideoLighting.Dim);

                // Set the target rect dimensions.
                pmtOptimal.SetFrameDimensions(rcOutput.right, rcOutput.bottom);

                // Set the geometric aperture, and disable pan/scan.
                displayArea = new MFVideoArea(0, 0, rcOutput.right, rcOutput.bottom);

                pmtOptimal.SetPanScanEnabled(false);

                pmtOptimal.SetGeometricAperture(displayArea);

                // Set the pan/scan aperture and the minimum display aperture. We don't care
                // about them per se, but the mixer will reject the type if these exceed the
                // frame dimentions.
                pmtOptimal.SetPanScanAperture(displayArea);
                pmtOptimal.SetMinDisplayAperture(displayArea);

                // Return the pointer to the caller.
                pmtOptimal.GetMediaType(out pOptimalType);
                pmtOptimal.Dispose();

                ppOptimal = pOptimalType;
            }
            finally
            {
                //SafeRelease(pOptimalType);
                //SafeRelease(pmtOptimal);
            }
        }
Exemplo n.º 2
0
        protected void ValidateVideoArea(MFVideoArea area, int width, int height)
        {
            float fOffsetX = area.OffsetX.GetOffset();
            float fOffsetY = area.OffsetY.GetOffset();

            if (((int)fOffsetX + area.Area.Width > width) ||
                 ((int)fOffsetY + area.Area.Height > height))
            {
                throw new COMException("ValidateVideoArea", MFError.MF_E_INVALIDMEDIATYPE);
            }
        }
Exemplo n.º 3
0
 // Sets the the region that contains the valid portion of the signal.
 public void SetMinDisplayAperture(MFVideoArea area)
 {
     Utils.MFSetBlob(GetMediaType(), MFAttributesClsid.MF_MT_MINIMUM_DISPLAY_APERTURE, area);
 }
Exemplo n.º 4
0
 // Sets the 4×3 region of video that should be displayed in pan/scan mode.
 public void SetPanScanAperture(MFVideoArea area)
 {
     Utils.MFSetBlob(GetMediaType(), MFAttributesClsid.MF_MT_PAN_SCAN_APERTURE, area);
 }
Exemplo n.º 5
0
 // Sets the geometric aperture.
 public void SetGeometricAperture(MFVideoArea area)
 {
     Utils.MFSetBlob(GetMediaType(), MFAttributesClsid.MF_MT_GEOMETRIC_APERTURE, area);
 }
Exemplo n.º 6
0
        // Returns (in this order)
        // 1. The pan/scan region, only if pan/scan mode is enabled.
        // 2. The geometric aperture.
        // 3. The entire video area.
        public void GetVideoDisplayArea(out MFVideoArea pArea)
        {
            int hr = 0;
            bool bPanScan = false;
            int width = 0, height = 0;
            pArea = new MFVideoArea();

            bPanScan = Utils.MFGetAttributeUINT32(GetMediaType(), MFAttributesClsid.MF_MT_PAN_SCAN_ENABLED, 0) != 0;

            // In pan/scan mode, try to get the pan/scan region.
            if (bPanScan)
            {
                try
                {
                    Utils.MFGetBlob(GetMediaType(), MFAttributesClsid.MF_MT_PAN_SCAN_APERTURE, pArea);
                }
                catch (Exception e)
                {
                    hr = Marshal.GetHRForException(e);
                }
            }

            // If not in pan/scan mode, or there is not pan/scan region, get the geometric aperture.
            if (!bPanScan || hr == MFError.MF_E_ATTRIBUTENOTFOUND)
            {
                try
                {
                    Utils.MFGetBlob(GetMediaType(), MFAttributesClsid.MF_MT_GEOMETRIC_APERTURE, pArea);
                    hr = 0;
                }
                catch (Exception e)
                {
                    hr = Marshal.GetHRForException(e);
                }

                // Default: Use the entire video area.
                if (hr == MFError.MF_E_ATTRIBUTENOTFOUND)
                {
                    Utils.MFGetAttribute2UINT32asUINT64(GetMediaType(), MFAttributesClsid.MF_MT_FRAME_SIZE, out width, out height);
                    pArea.MakeArea(0, 0, width, height);
                }
            }
        }
Exemplo n.º 7
0
 // Queries the 4×3 region of video that should be displayed in pan/scan mode.
 public void GetPanScanAperture(out MFVideoArea pArea)
 {
     pArea = new MFVideoArea();
     Utils.MFGetBlob(GetMediaType(), MFAttributesClsid.MF_MT_PAN_SCAN_APERTURE, pArea);
 }
Exemplo n.º 8
0
 // Retrieves the region that contains the valid portion of the signal.
 public void GetMinDisplayAperture(out MFVideoArea pArea)
 {
     pArea = new MFVideoArea();
     Utils.MFGetBlob(GetMediaType(), MFAttributesClsid.MF_MT_MINIMUM_DISPLAY_APERTURE, pArea);
 }
Exemplo n.º 9
0
 // Queries the geometric aperture.
 public void GetGeometricAperture(out MFVideoArea pArea)
 {
     pArea = new MFVideoArea();
     Utils.MFGetBlob(GetMediaType(), MFAttributesClsid.MF_MT_GEOMETRIC_APERTURE, pArea);
 }