Beispiel #1
0
        public HRESULT GetCount(out uint pcItems)
        {
            var hr = _type.GetCount(out pcItems);

            Trace("count: " + pcItems + " hr: " + hr);
            return(hr);
        }
 private string DescribeMediaType(IMFMediaType mediaType)
 {
     int attributeCount;
     mediaType.GetCount(out attributeCount);
     var sb = new StringBuilder();
     for (int n = 0; n < attributeCount; n++)
     {
         DescribeAttribute(mediaType, n, sb);
     }
     return sb.ToString();
 }
Beispiel #3
0
        private string DescribeMediaType(IMFMediaType mediaType)
        {
            int attributeCount;

            mediaType.GetCount(out attributeCount);
            var sb = new StringBuilder();

            for (int n = 0; n < attributeCount; n++)
            {
                DescribeAttribute(mediaType, n, sb);
            }
            return(sb.ToString());
        }
Beispiel #4
0
 private string DescribeMediaType(IMFMediaType mediaType)
 {
     int attributeCount;
     mediaType.GetCount(out attributeCount);
     var sb = new StringBuilder();
     for (int n = 0; n < attributeCount; n++)
     {
         Guid key;
         var val = new PropVariant();
         mediaType.GetItemByIndex(n, out key, ref val);
         string propertyName = FieldDescriptionHelper.Describe(typeof(MediaFoundationAttributes), key);
         sb.AppendFormat("{0}={1}\r\n", propertyName, val.Value);
         val.Clear();
     }
     return sb.ToString();
 }
Beispiel #5
0
        private string DescribeMediaType(IMFMediaType mediaType)
        {
            int attributeCount;

            mediaType.GetCount(out attributeCount);
            var sb = new StringBuilder();

            for (int n = 0; n < attributeCount; n++)
            {
                Guid key;
                var  val = new PropVariant();
                mediaType.GetItemByIndex(n, out key, ref val);
                string propertyName = FieldDescriptionHelper.Describe(typeof(MediaFoundationAttributes), key);
                sb.AppendFormat("{0}={1}\r\n", propertyName, val.Value);
                val.Clear();
            }
            return(sb.ToString());
        }
Beispiel #6
0
        private CaptureFormat LogMediaType(IMFMediaType pType)
        {
            int count = 0;

            int hr = pType.GetCount(out count);

            MFError.ThrowExceptionForHR(hr);

            if (count == 0)
            {
                Trace.WriteLine("Empty media type.");
            }
            CaptureFormat capFormat = new CaptureFormat();

            for (int i = 0; i < count; i++)
            {
                LogAttributeValueByIndex(pType, i, ref capFormat);
                MFError.ThrowExceptionForHR(hr);
            }
            return(capFormat);
        }
Beispiel #7
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Gets a list of all supported video formats from a media type
        /// as a nice displayable bit of text. outSb will never be null can be
        /// empty.
        ///
        /// Adapted from
        /// https://msdn.microsoft.com/en-us/library/windows/desktop/ee663602(v=vs.85).aspx
        /// </summary>
        /// <returns>S_OK for success, nz for fail</returns>
        /// <param name="mediaTypeObj">the media type object</param>
        /// <param name="outSb">The output string</param>
        /// <history>
        ///    01 Nov 18  Cynic - Started
        /// </history>
        public static HResult GetSupportedFormatsFromMediaTypeAsText(IMFMediaType mediaTypeObj, out StringBuilder outSb)
        {
            Guid majorType;
            Guid subType;
            int  attributeCount;
            int  frameSizeWidth;
            int  frameSizeHeight;
            int  frameRate;
            int  frameRateDenominator;
            int  frameRateMin;
            int  frameRateMinDenominator;
            int  frameRateMax;
            int  frameRateMaxDenominator;

            // we always return something here
            outSb = new StringBuilder();

            // sanity check
            if (mediaTypeObj == null)
            {
                return(HResult.E_FAIL);
            }

            // Retrieves the number of attributes that are set on this object.
            HResult hr = mediaTypeObj.GetCount(out attributeCount);

            if (hr != HResult.S_OK)
            {
                // if we failed here, bail out
                outSb.Append("failed getting attributeCount, retVal=" + hr.ToString());
                outSb.Append("\r\n");
                return(HResult.E_FAIL);
            }
            // put in this line now
            //   outSb.Append("attributeCount=" + attributeCount.ToString()+", ");

            // MF_MT_MAJOR_TYPE
            // Major type GUID, we return this as human readable text
            hr = mediaTypeObj.GetMajorType(out majorType);
            if (hr == HResult.S_OK)
            {
                // only report success
                outSb.Append("MF_MT_MAJOR_TYPE=" + TantaWMFUtils.ConvertGuidToName(majorType) + ", ");
            }

            // MF_MT_SUBTYPE
            // Subtype GUID which describes the basic media type, we return this as human readable text
            hr = mediaTypeObj.GetGUID(MFAttributesClsid.MF_MT_SUBTYPE, out subType);
            if (hr == HResult.S_OK)
            {
                // only report success
                outSb.Append("MF_MT_SUBTYPE=" + TantaWMFUtils.ConvertGuidToName(subType) + ", ");
            }

            // MF_MT_FRAME_SIZE
            // the Width and height of a video frame, in pixels
            hr = MFExtern.MFGetAttributeSize(mediaTypeObj, MFAttributesClsid.MF_MT_FRAME_SIZE, out frameSizeWidth, out frameSizeHeight);
            if (hr == HResult.S_OK)
            {
                // only report success
                outSb.Append("MF_MT_FRAME_SIZE (W,H)=(" + frameSizeWidth.ToString() + "," + frameSizeHeight.ToString() + "), ");
            }

            // MF_MT_FRAME_RATE
            // The frame rate is expressed as a ratio.The upper 32 bits of the attribute value contain the numerator and the lower 32 bits contain the denominator.
            // For example, if the frame rate is 30 frames per second(fps), the ratio is 30 / 1.If the frame rate is 29.97 fps, the ratio is 30,000 / 1001.
            // we report this back to the user as a decimal
            hr = MFExtern.MFGetAttributeRatio(mediaTypeObj, MFAttributesClsid.MF_MT_FRAME_RATE, out frameRate, out frameRateDenominator);
            if (hr == HResult.S_OK)
            {
                // only report success
                if (frameRateDenominator < 0)
                {
                    outSb.Append("MF_MT_FRAME_RATE (frames/s)=(undefined),");
                }
                else
                {
                    outSb.Append("MF_MT_FRAME_RATE=" + ((decimal)frameRate / (decimal)frameRateDenominator).ToString() + "f/s, ");
                }
            }

            // MF_MT_FRAME_RATE_RANGE_MIN
            // The frame rate is expressed as a ratio.The upper 32 bits of the attribute value contain the numerator and the lower 32 bits contain the denominator.
            // For example, if the frame rate is 30 frames per second(fps), the ratio is 30 / 1.If the frame rate is 29.97 fps, the ratio is 30,000 / 1001.
            // we report this back to the user as a decimal
            hr = MFExtern.MFGetAttributeRatio(mediaTypeObj, MFAttributesClsid.MF_MT_FRAME_RATE_RANGE_MIN, out frameRateMin, out frameRateMinDenominator);
            if (hr == HResult.S_OK)
            {
                // only report success
                if (frameRateMinDenominator < 0)
                {
                    outSb.Append("MF_MT_FRAME_RATE_RANGE_MIN (frames/s)=(undefined),");
                }
                else
                {
                    outSb.Append("MF_MT_FRAME_RATE_RANGE_MIN=" + ((decimal)frameRateMin / (decimal)frameRateMinDenominator).ToString() + "f/s, ");
                }
            }

            // MF_MT_FRAME_RATE_RANGE_MAX
            // The frame rate is expressed as a ratio.The upper 32 bits of the attribute value contain the numerator and the lower 32 bits contain the denominator.
            // For example, if the frame rate is 30 frames per second(fps), the ratio is 30 / 1.If the frame rate is 29.97 fps, the ratio is 30,000 / 1001.
            // we report this back to the user as a decimal
            hr = MFExtern.MFGetAttributeRatio(mediaTypeObj, MFAttributesClsid.MF_MT_FRAME_RATE_RANGE_MAX, out frameRateMax, out frameRateMaxDenominator);
            if (hr == HResult.S_OK)
            {
                // only report success
                if (frameRateMaxDenominator < 0)
                {
                    outSb.Append("MF_MT_FRAME_RATE_RANGE_MAX (frames/s)=(undefined),");
                }
                else
                {
                    outSb.Append("MF_MT_FRAME_RATE_RANGE_MAX=" + ((decimal)frameRateMax / (decimal)frameRateMaxDenominator).ToString() + "f/s, ");
                }
            }

            // enumerate all of the possible Attributes so we can see which ones are present that we did not report on
            StringBuilder allAttrs = new StringBuilder();

            hr = EnumerateAllAttributeNamesInMediaTypeAsText(mediaTypeObj, attributeCount, out allAttrs);
            if (hr == HResult.S_OK)
            {
                outSb.Append("\r\n");
                outSb.Append("         AllAttrs=" + allAttrs.ToString());
            }

            return(HResult.S_OK);
        }
Beispiel #8
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Gets a list of all supported video formats from a media type
        /// as a nice displayable bit of text. outSb will never be null can be
        /// empty.
        ///
        /// Adapted from
        /// https://msdn.microsoft.com/en-us/library/windows/desktop/ee663602(v=vs.85).aspx
        /// </summary>
        /// <returns>S_OK for success, nz for fail</returns>
        /// <param name="mediaTypeObj">the media type object</param>
        /// <param name="outSb">The output string</param>
        /// <history>
        ///    01 Nov 18  Cynic - Started
        /// </history>
        public static HResult GetSupportedFormatsFromMediaType(IMFMediaType mediaTypeObj, out Guid majorType, out Guid subType, out int attributeCount, out int frameSizeWidth, out int frameSizeHeight, out int frameRate, out int frameRateDenominator, out int frameRateMin, out int frameRateMinDenominator, out int frameRateMax, out int frameRateMaxDenominator)
        {
            // init these
            majorType               = Guid.Empty;
            subType                 = Guid.Empty;
            attributeCount          = 0;
            frameSizeWidth          = 0;
            frameSizeHeight         = 0;
            frameRate               = 0;
            frameRateDenominator    = 0;
            frameRateMin            = 0;
            frameRateMinDenominator = 0;
            frameRateMax            = 0;
            frameRateMaxDenominator = 0;

            // sanity check
            if (mediaTypeObj == null)
            {
                return(HResult.E_FAIL);
            }

            // Retrieves the number of attributes that are set on this object.
            HResult hr = mediaTypeObj.GetCount(out attributeCount);

            if (hr != HResult.S_OK)
            {
                // if we failed here, bail out
                return(HResult.E_FAIL);
            }
            // put in this line now
            //   outSb.Append("attributeCount=" + attributeCount.ToString()+", ");

            // MF_MT_MAJOR_TYPE
            // Major type GUID, we return this as human readable text
            hr = mediaTypeObj.GetMajorType(out majorType);
            if (hr != HResult.S_OK)
            {
                // if we failed here, bail out
                return(HResult.E_FAIL);
            }

            // MF_MT_SUBTYPE
            // Subtype GUID which describes the basic media type, we return this as human readable text
            hr = mediaTypeObj.GetGUID(MFAttributesClsid.MF_MT_SUBTYPE, out subType);
            if (hr != HResult.S_OK)
            {
                // if we failed here, bail out
                return(HResult.E_FAIL);
            }

            // MF_MT_FRAME_SIZE
            // the Width and height of a video frame, in pixels
            hr = MFExtern.MFGetAttributeSize(mediaTypeObj, MFAttributesClsid.MF_MT_FRAME_SIZE, out frameSizeWidth, out frameSizeHeight);
            if (hr != HResult.S_OK)
            {
                // if we failed here, bail out
                return(HResult.E_FAIL);
            }

            // MF_MT_FRAME_RATE
            // The frame rate is expressed as a ratio.The upper 32 bits of the attribute value contain the numerator and the lower 32 bits contain the denominator.
            // For example, if the frame rate is 30 frames per second(fps), the ratio is 30 / 1.If the frame rate is 29.97 fps, the ratio is 30,000 / 1001.
            // we report this back to the user as a decimal
            hr = MFExtern.MFGetAttributeRatio(mediaTypeObj, MFAttributesClsid.MF_MT_FRAME_RATE, out frameRate, out frameRateDenominator);
            if (hr != HResult.S_OK)
            {
                // if we failed here, bail out
                return(HResult.E_FAIL);
            }

            // MF_MT_FRAME_RATE_RANGE_MIN
            // The frame rate is expressed as a ratio.The upper 32 bits of the attribute value contain the numerator and the lower 32 bits contain the denominator.
            // For example, if the frame rate is 30 frames per second(fps), the ratio is 30 / 1.If the frame rate is 29.97 fps, the ratio is 30,000 / 1001.
            // we report this back to the user as a decimal
            hr = MFExtern.MFGetAttributeRatio(mediaTypeObj, MFAttributesClsid.MF_MT_FRAME_RATE_RANGE_MIN, out frameRateMin, out frameRateMinDenominator);
            if (hr != HResult.S_OK)
            {
                // if we failed here, bail out
                return(HResult.E_FAIL);
            }

            // MF_MT_FRAME_RATE_RANGE_MAX
            // The frame rate is expressed as a ratio.The upper 32 bits of the attribute value contain the numerator and the lower 32 bits contain the denominator.
            // For example, if the frame rate is 30 frames per second(fps), the ratio is 30 / 1.If the frame rate is 29.97 fps, the ratio is 30,000 / 1001.
            // we report this back to the user as a decimal
            hr = MFExtern.MFGetAttributeRatio(mediaTypeObj, MFAttributesClsid.MF_MT_FRAME_RATE_RANGE_MAX, out frameRateMax, out frameRateMaxDenominator);
            if (hr != HResult.S_OK)
            {
                // if we failed here, bail out
                return(HResult.E_FAIL);
            }

            return(HResult.S_OK);
        }