Ejemplo n.º 1
0
        /// <summary>
        /// Creates a source reader based on a byte stream
        /// </summary>
        /// <param name="byteStream">The byte stream</param>
        /// <returns>A media foundation source reader</returns>
        public static IMFSourceReader CreateSourceReaderFromByteStream(IMFByteStream byteStream)
        {
            IMFSourceReader reader;

            MediaFoundationInterop.MFCreateSourceReaderFromByteStream(byteStream, null, out reader);
            return(reader);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a Media type
        /// </summary>
        public static IMFMediaType CreateMediaType()
        {
            IMFMediaType mediaType;

            MediaFoundationInterop.MFCreateMediaType(out mediaType);
            return(mediaType);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a media foundation byte stream based on a stream object
        /// (usable with WinRT streams)
        /// </summary>
        /// <param name="stream">The input stream</param>
        /// <returns>A media foundation byte stream</returns>
        public static IMFByteStream CreateByteStream(object stream)
        {
            IMFByteStream byteStream;

            MediaFoundationInterop.MFCreateMFByteStreamOnStreamEx(stream, out byteStream);
            return(byteStream);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a new attributes store
        /// </summary>
        /// <param name="initialSize">Initial size</param>
        /// <returns>The attributes store</returns>
        public static IMFAttributes CreateAttributes(int initialSize)
        {
            IMFAttributes attributes;

            MediaFoundationInterop.MFCreateAttributes(out attributes, initialSize);
            return(attributes);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a sample object
        /// </summary>
        /// <returns>The sample object</returns>
        public static IMFSample CreateSample()
        {
            IMFSample sample;

            MediaFoundationInterop.MFCreateSample(out sample);
            return(sample);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a memory buffer of the specified size
        /// </summary>
        /// <param name="bufferSize">Memory buffer size in bytes</param>
        /// <returns>The memory buffer</returns>
        public static IMFMediaBuffer CreateMemoryBuffer(int bufferSize)
        {
            IMFMediaBuffer buffer;

            MediaFoundationInterop.MFCreateMemoryBuffer(bufferSize, out buffer);
            return(buffer);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// uninitializes MediaFoundation
 /// </summary>
 public static void Shutdown()
 {
     if (initialized)
     {
         MediaFoundationInterop.MFShutdown();
         initialized = false;
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// initializes MediaFoundation - only needs to be called once per process
 /// </summary>
 public static void Startup()
 {
     if (!initialized)
     {
         MediaFoundationInterop.MFStartup(MediaFoundationInterop.MF_VERSION, 0);
         initialized = true;
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates a media type from a WaveFormat
        /// </summary>
        public static IMFMediaType CreateMediaTypeFromWaveFormat(WaveFormat waveFormat)
        {
            var mediaType = CreateMediaType();

            try
            {
                MediaFoundationInterop.MFInitMediaTypeFromWaveFormatEx(mediaType, waveFormat, Marshal.SizeOf(waveFormat));
            }
            catch (Exception)
            {
                Marshal.ReleaseComObject(mediaType);
                throw;
            }
            return(mediaType);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Enumerate the installed MediaFoundation transforms in the specified category
        /// </summary>
        /// <param name="category">A category from MediaFoundationTransformCategories</param>
        /// <returns></returns>
        public static IEnumerable <IMFActivate> EnumerateTransforms(Guid category)
        {
            IntPtr interfacesPointer;
            int    interfaceCount;

            MediaFoundationInterop.MFTEnumEx(category, _MFT_ENUM_FLAG.MFT_ENUM_FLAG_ALL,
                                             null, null, out interfacesPointer, out interfaceCount);
            var interfaces = new IMFActivate[interfaceCount];

            for (int n = 0; n < interfaceCount; n++)
            {
                var ptr =
                    Marshal.ReadIntPtr(new IntPtr(interfacesPointer.ToInt64() + n * Marshal.SizeOf(interfacesPointer)));
                interfaces[n] = (IMFActivate)Marshal.GetObjectForIUnknown(ptr);
            }

            foreach (var i in interfaces)
            {
                yield return(i);
            }
            Marshal.FreeCoTaskMem(interfacesPointer);
        }