Esempio n. 1
0
        //-------------------------------------------------------------------
        // SetVideoType
        //
        // Set the video snapFormat.
        //-------------------------------------------------------------------
        public int SetVideoType(IMFMediaType pType)
        {
            Guid subtype;
            var  PAR = new MFRatio();

            // Find the video subtype.
            var hr = pType.GetGUID(MFAttributesClsid.MF_MT_SUBTYPE, out subtype);

            try
            {
                if (Failed(hr))
                {
                    throw new Exception();
                }

                // Choose a conversion function.
                // (This also validates the snapFormat type.)

                hr = SetConversionFunction(subtype);
                if (Failed(hr))
                {
                    throw new Exception();
                }

                //
                // Get some video attributes.
                //

                // Get the frame size.
                hr = CProcess.MfGetAttributeSize(pType, out width, out height);
                if (Failed(hr))
                {
                    throw new Exception();
                }

                // Get the image stride.
                hr = GetDefaultStride(pType, out lDefaultStride);
                if (Failed(hr))
                {
                    throw new Exception();
                }

                // Get the pixel aspect ratio. Default: Assume square pixels (1:1)
                hr = CProcess.MfGetAttributeRatio(pType, out PAR.Numerator, out PAR.Denominator);

                if (Succeeded(hr))
                {
                    pixelAR = PAR;
                }
                else
                {
                    pixelAR.Numerator = pixelAR.Denominator = 1;
                }

                var f = new FourCC(subtype);
                format = (Format)f.ToInt32();

                // Create Direct3D swap chains.

                hr = CreateSwapChains();
                if (Failed(hr))
                {
                    throw new Exception();
                }

                // Update the destination rectangle for the correct
                // aspect ratio.

                UpdateDestinationRect();
            }
            finally
            {
                if (Failed(hr))
                {
                    format      = Format.Unknown;
                    m_convertFn = null;
                }
            }
            return(hr);
        }