/// <summary>
        /// Gets an attribute from the underlying media source.
        /// </summary>
        /// <param name="sourceReader">A valid IMFSourceReader instance.</param></param>
        /// <param name="streamIndex">The streamIndex to query.</param>
        /// <param name="mediaTypeIndex">The zero-based index of the media type to retrieve.</param>
        /// <param name="mediaType">Receives an instance of the IMFMediaType interface.</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 GetPresentationAttribute(this IMFSourceReader sourceReader, SourceReaderFirstStreamOrMediaSource streamIndex, Guid guidAttribute, PropVariant attribute)
        {
            if (sourceReader == null)
            {
                throw new ArgumentNullException("sourceReader");
            }

            return(sourceReader.GetPresentationAttribute((int)streamIndex, guidAttribute, attribute));
        }
        /// <summary>
        /// Queries the underlying media source or decoder for an interface.
        /// </summary>
        /// <typeparam name="T">The COM interface being requested.</typeparam></typeparam>
        /// <param name="sourceReader">A valid IMFSourceReader instance.</param></param></param>
        /// <param name="streamIndex">The streamIndex or object to query.</param>
        /// <param name="guidService">A service identifier GUID.</param>
        /// <param name="service">Receives an instance of the requested interface.</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 GetServiceForStream <T>(this IMFSourceReader sourceReader, SourceReaderFirstStreamOrMediaSource streamIndex, Guid guidService, out T service) where T : class
        {
            if (sourceReader == null)
            {
                throw new ArgumentNullException("sourceReader");
            }

            Type typeOfT = typeof(T);

            if (!typeOfT.IsInterface)
            {
                throw new ArgumentOutOfRangeException("T", "T must be a COM visible interface.");
            }

            object tmp;

            HResult hr = sourceReader.GetServiceForStream((int)streamIndex, guidService, typeOfT.GUID, out tmp);

            service = hr.Succeeded() ? tmp as T : null;

            return(hr);
        }