Exemple #1
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)
        {
            HResult 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 = (HResult)Marshal.GetHRForException(e);
                }
            }

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

                // Default: Use the entire video area.
                if (hr == HResult.MF_E_ATTRIBUTENOTFOUND)
                {
                    Utils.MFGetAttribute2UINT32asUINT64(GetMediaType(), MFAttributesClsid.MF_MT_FRAME_SIZE, out width, out height);
                    pArea.MakeArea(0, 0, width, height);
                }
            }
        }
Exemple #2
0
        protected override IMFMediaType CreateOutputFromInput()
        {
            // For some MFTs, the output type is the same as the input type.
            // However, since we are rotating, several attributes in the
            // media type (like frame size) must be different on our output.
            // This routine generates the appropriate output type for the
            // current input type, given the current state of m_WasOdd.

            IMFMediaType inType = InputType;

            IMFMediaType pOutputType = CloneMediaType(inType);

            if (m_WasOdd)
            {
                MFError throwonhr;
                int     h, w;

                // Intentionally backward
                throwonhr = MFExtern.MFGetAttributeSize(inType, MFAttributesClsid.MF_MT_FRAME_SIZE, out h, out w);

                throwonhr = MFExtern.MFSetAttributeSize(pOutputType, MFAttributesClsid.MF_MT_FRAME_SIZE, w, h);

                MFVideoArea a = GetArea(inType, MFAttributesClsid.MF_MT_GEOMETRIC_APERTURE);
                if (a != null)
                {
                    a.Area.Height = h;
                    a.Area.Width  = w;
                    SetArea(pOutputType, MFAttributesClsid.MF_MT_GEOMETRIC_APERTURE, a);
                }

                a = GetArea(inType, MFAttributesClsid.MF_MT_MINIMUM_DISPLAY_APERTURE);
                if (a != null)
                {
                    a.Area.Height = h;
                    a.Area.Width  = w;
                    SetArea(pOutputType, MFAttributesClsid.MF_MT_MINIMUM_DISPLAY_APERTURE, a);
                }

                throwonhr = pOutputType.SetUINT32(MFAttributesClsid.MF_MT_DEFAULT_STRIDE, w * bpp);
            }

            return(pOutputType);
        }
        // Formats
        protected HRESULT CreateOptimalVideoType(IMFMediaType pProposedType, out IMFMediaType ppOptimalType)
        {
            ppOptimalType = null;
            HRESULT hr = S_OK;

            DsRect rcOutput;
            MFVideoArea displayArea;

            MFHelper.VideoTypeBuilder pmtOptimal = null;

            // Create the helper object to manipulate the optimal type.
            hr = MFHelper.MediaTypeBuilder.Create(out pmtOptimal);
            if (hr.Failed) return hr;

            // Clone the proposed type.
            hr = pmtOptimal.CopyFrom(pProposedType);
            if (hr.Failed) return hr;

            // 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)
            hr = pmtOptimal.SetPixelAspectRatio(1, 1);
            if (hr.Failed) return hr;

            // Get the output rectangle.
            rcOutput = GetDestinationRect();

            if (rcOutput.IsEmpty())
            {
                // Calculate the output rectangle based on the media type.
                hr = CalculateOutputRectangle(pProposedType, out rcOutput);
                if (hr.Failed) return hr;
            }

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

            // Set the target rect dimensions.
            hr = pmtOptimal.SetFrameDimensions(rcOutput.right, rcOutput.bottom);
            if (hr.Failed) return hr;

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

            hr = pmtOptimal.SetPanScanEnabled(false);
            if (hr.Failed) return hr;
            hr = pmtOptimal.SetGeometricAperture(displayArea);
            if (hr.Failed) return hr;
            // 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.
            hr = pmtOptimal.SetPanScanAperture(displayArea);
            if (hr.Failed) return hr;
            hr = pmtOptimal.SetMinDisplayAperture(displayArea);
            if (hr.Failed) return hr;

            // Return the pointer to the caller.
            hr = pmtOptimal.GetMediaType(out ppOptimalType);

            return hr;
        }
Exemple #4
0
 // Sets the 4�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);
 }
Exemple #5
0
 // Queries the 4�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);
 }
Exemple #6
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);
 }
Exemple #7
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);
 }
Exemple #8
0
 // Sets the geometric aperture.
 public void SetGeometricAperture(MFVideoArea area)
 {
     Utils.MFSetBlob(GetMediaType(), MFAttributesClsid.MF_MT_GEOMETRIC_APERTURE, area);
 }
Exemple #9
0
 // Queries the geometric aperture.
 public void GetGeometricAperture(out MFVideoArea pArea)
 {
     pArea = new MFVideoArea();
     Utils.MFGetBlob(GetMediaType(), MFAttributesClsid.MF_MT_GEOMETRIC_APERTURE, pArea);
 }
Exemple #10
0
        private static void SetArea(IMFAttributes ia, Guid g, MFVideoArea a)
        {
            PropVariant pv = new PropVariant(a);

            MFError throwonhr = ia.SetItem(g, pv);
        }