/// <summary>
        /// Retrieves an attribute at the specified index.
        /// </summary>
        /// <param name="attributes">A valid IMFAttributes instance.</param>
        /// <param name="index">The index to retrieve.</param>
        /// <param name="guidKey">The key of this attribute.</param>
        /// <param name="value">The value of this attribute.</param>
        /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns>
        public static HResult GetItemByIndex(this IMFAttributes attributes, int index, out Guid guidKey, out object value)
        {
            if (attributes == null)
            {
                throw new ArgumentNullException("attributes");
            }

            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            HResult hr = 0;

            value = null;

            using (PropVariant variant = new PropVariant())
            {
                hr = attributes.GetItemByIndex(index, out guidKey, variant);
                if (hr.Succeeded())
                {
                    value = variant.GetObject();
                }
            }

            return(hr);
        }
Ejemplo n.º 2
0
        public static IEnumerable <KeyValuePair <Guid, _MF_ATTRIBUTE_TYPE> > Enumerate(this IMFAttributes obj)
        {
            if (obj == null)
            {
                yield break;
            }

            for (int i = 0; i < Count(obj); i++)
            {
                obj.GetItemByIndex((uint)i, out Guid guid, null).ThrowOnError();
                obj.GetItemType(guid, out var type).ThrowOnError();
                yield return(new KeyValuePair <Guid, _MF_ATTRIBUTE_TYPE>(guid, type));
            }
        }
Ejemplo n.º 3
0
            private PropertySet PropSetFromAttributes(IMFAttributes attributes)
            {
                if (attributes == null)
                {
                    return(null);
                }
                var  retValue = new PropertySet();
                uint cCount   = 0;

                attributes.GetCount(out cCount);
                for (uint i = 0; i < cCount; i++)
                {
                    Guid   key;
                    Object item = null;
                    attributes.GetItemByIndex(i, out key, ref item);
                    retValue.Add(key.ToString(), item);
                }
                return(retValue);
            }
Ejemplo n.º 4
0
 public HResult GetItemByIndex(int unIndex,
                               out Guid pguidKey, PropVariant pValue)
 {
     return(m_Attribs.GetItemByIndex(unIndex, out pguidKey, pValue));
 }
Ejemplo n.º 5
0
        private string LogAttributeValueByIndex(IMFAttributes pAttr, int index, ref CaptureFormat capFormat)
        {
            //string pGuidName = null;
            //string pGuidValName = null;

            Guid guid = Guid.Empty;

            PropVariant var = new PropVariant();
            //PropVariantInit(&var);


            int hr = pAttr.GetItemByIndex(index, out guid, var);

            MFError.ThrowExceptionForHR(hr);



            if (guid == MFAttributesClsid.MF_MT_FRAME_RATE)
            {
                //Trace.WriteLine("MF_MT_FRAME_RATE");
                int lower = (int)var.GetULong();
                //Trace.WriteLine("LogAttr1_1 = " + lower.ToString());
                int upperbits = (int)(var.GetULong() >> 32);
                //Trace.WriteLine("LogAttr1_2 = " + upperbits.ToString());
                float fr = (float)upperbits / (float)lower;
                capFormat.Framerate = fr;
                Trace.WriteLine("FrameRate = " + fr.ToString());
                return("Framerate=" + fr.ToString() + ", ");
            }
            else if (guid == MFAttributesClsid.MF_MT_FRAME_RATE_RANGE_MAX)
            {
                //Trace.WriteLine("MF_MT_FRAME_RATE_RANGE_MAX");
                int lower = (int)var.GetULong();
                //Trace.WriteLine("LogAttr1_1 = " + lower.ToString());
                int upperbits = (int)(var.GetULong() >> 32);
                //Trace.WriteLine("LogAttr1_2 = " + upperbits.ToString());
                //return "MaxFramerate=" + fr.ToString() + ", ";
            }
            else if (guid == MFAttributesClsid.MF_MT_FRAME_RATE_RANGE_MIN)
            {
                //Trace.WriteLine("MF_MT_FRAME_RATE_RANGE_MIN");
                int lower = (int)var.GetULong();
                //Trace.WriteLine("LogAttr1_1 = " + lower.ToString());
                int   upperbits = (int)(var.GetULong() >> 32);
                float fr        = (float)upperbits / (float)lower;
                //return "MinFramerate=" + fr.ToString() + ", ";
                //Trace.WriteLine("LogAttr1_2 = " + upperbits.ToString());
            }
            else if (guid == MFAttributesClsid.MF_MT_FRAME_SIZE)
            {
                //Trace.WriteLine("MF_MT_FRAME_SIZE");
                int lower = (int)var.GetULong();
                // Trace.WriteLine("LogAttr1_1 = " + lower.ToString());
                int upperbits = (int)(var.GetULong() >> 32);
                //Trace.WriteLine("LogAttr1_2 = " + upperbits.ToString());
                capFormat.Height = lower;
                capFormat.Width  = upperbits;
                Trace.WriteLine("Resolution=" + lower.ToString() + "X" + upperbits.ToString());
                return("Resolution=" + lower.ToString() + "X" + upperbits.ToString());
            }
            else if (guid == MFAttributesClsid.MF_MT_PIXEL_ASPECT_RATIO)
            {
                //Trace.WriteLine("MF_MT_PIXEL_ASPECT_RATIO");
                int lower = (int)var.GetULong();
                //Trace.WriteLine("LogAttr1_1 = " + lower.ToString());
                int upperbits = (int)(var.GetULong() >> 32);
                //Trace.WriteLine("LogAttr1_2 = " + upperbits.ToString());
            }
            else if (guid == MFAttributesClsid.MF_MT_GEOMETRIC_APERTURE)
            {
                //Trace.WriteLine("MF_MT_GEOMETRIC_APERTURE");
                //Trace.WriteLine("LogAttr2 = " + var.ToString());
            }
            else if (guid == MFAttributesClsid.MF_MT_MINIMUM_DISPLAY_APERTURE)
            {
                //Trace.WriteLine("MF_MT_MINIMUM_DISPLAY_APERTURE");
                //Trace.WriteLine("LogAttr2 = " + var.ToString());
            }
            else if (guid == MFAttributesClsid.MF_MT_PAN_SCAN_APERTURE)
            {
                //Trace.WriteLine("MF_MT_PAN_SCAN_APERTURE");
                //Trace.WriteLine("LogAttr2 = " + var.ToString());
            }
            else if (guid == MFAttributesClsid.MF_MT_SUBTYPE)
            {
                capFormat.PixelFormat = var.GetGuid();
            }
            else
            {
                Trace.WriteLine("Unknown attr " + guid.ToString() + " val = " + var.ToString());
            }
            return("");
        }