Exemple #1
0
        public static ComObject <T> GetServiceForStream <T>(this IMFSinkWriter input, uint streamIndex, Guid serviceId, Guid interfaceId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            if (input.GetServiceForStream(streamIndex, serviceId, interfaceId, out var ppv).IsError)
            {
                return(null);
            }

            return(new ComObject <T>((T)ppv));
        }
        /// <summary>
        /// Queries the underlying media sink or encoder for an interface.
        /// </summary>
        /// <typeparam name="T">The COM interface being requested.</typeparam>
        /// <param name="sinkWriter">A valid IMFSinkWriter instance.</param>
        /// <param name="streamIndex">The zero-based index of a streamIndex to query or -1 to query the media sink itself.</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 IMFSinkWriter sinkWriter, int streamIndex, Guid guidService, out T service) where T : class
        {
            if (sinkWriter == null)
            {
                throw new ArgumentNullException("sinkWriter");
            }

            Type typeOfT = typeof(T);

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

            object tmp;

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

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

            return(hr);
        }