Beispiel #1
0
        /// <summary>
        /// Converts an audio media type to a WaveFormatEx structure.
        /// </summary>
        /// <param name="mediaType">A valid IMFMediaType instance.</param>
        /// <param name="flags">One member of the <see cref="MFWaveFormatExConvertFlags"/> enumaration.</param>
        /// <param name="waveFormatEx">Receives a WaveFormatEx structure representing this audio media type.</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 CreateWaveFormatEx(this IMFMediaType mediaType, MFWaveFormatExConvertFlags flags, out WaveFormatEx waveFormatEx)
        {
            if (mediaType == null)
            {
                throw new ArgumentNullException("mediaType");
            }

            int structSize;

            return(MFExtern.MFCreateWaveFormatExFromMFMediaType(mediaType, out waveFormatEx, out structSize, flags));
        }
Beispiel #2
0
        public unsafe WaveFormat ToWaveFormat(out int bufferSize, MFWaveFormatExConvertFlags flags)
        {
            IntPtr pointer = IntPtr.Zero;

            fixed(void *ptr = &bufferSize)
            {
                MediaFoundationException.Try(MFCreateWaveFormatExFromMFMediaType(BasePtr.ToPointer(), (void *)(&pointer), (void *)(ptr), (int)flags), "interop", "MFCreateWaveFormatExFromMFMediaType");
            }

            var waveformat = (WaveFormat)Marshal.PtrToStructure(pointer, typeof(WaveFormat)); //todo:

            if (waveformat.WaveFormatTag == AudioEncoding.Extensible)
            {
                waveformat = (WaveFormatExtensible)Marshal.PtrToStructure(pointer, typeof(WaveFormatExtensible));
            }
            return(waveformat);
        }
Beispiel #3
0
        /// <summary>
        /// Converts the <see cref="MFMediaType"/> to a <see cref="WaveFormat"/>.
        /// </summary>
        /// <param name="flags">Contains a flag from the <see cref="MFWaveFormatExConvertFlags"/> enumeration.</param>
        /// <returns>The <see cref="WaveFormat"/> which got created based on the <see cref="MFMediaType"/>.</returns>
        public unsafe WaveFormat ToWaveFormat(MFWaveFormatExConvertFlags flags)
        {
            IntPtr pointer = IntPtr.Zero;

            try
            {
                int cbSize;
                MediaFoundationException.Try(
                    NativeMethods.MFCreateWaveFormatExFromMFMediaType(BasePtr.ToPointer(), &pointer, &cbSize,
                                                                      (int)flags), "Interop", "MFCreateWaveFormatExFromMFMediaType");
            }
            finally
            {
                Marshal.FreeCoTaskMem(pointer);
            }
            //var waveformat = (WaveFormat)Marshal.PtrToStructure(pointer, typeof(WaveFormat));
            //if (waveformat.WaveFormatTag == AudioEncoding.Extensible)
            //    waveformat = (WaveFormatExtensible)Marshal.PtrToStructure(pointer, typeof(WaveFormatExtensible));
            //return waveformat;
            return(WaveFormatMarshaler.PointerToWaveFormat(pointer));
        }
Beispiel #4
0
 /// <summary>
 /// Converts the <see cref="MFMediaType"/> to a <see cref="WaveFormat"/>.
 /// </summary>
 /// <param name="flags">Contains a flag from the <see cref="MFWaveFormatExConvertFlags"/> enumeration.</param>
 /// <returns>The <see cref="WaveFormat"/> which got created based on the <see cref="MFMediaType"/>.</returns>
 public unsafe WaveFormat ToWaveFormat(MFWaveFormatExConvertFlags flags)
 {
     IntPtr pointer = IntPtr.Zero;
     try
     {
         int cbSize;
         MediaFoundationException.Try(
             NativeMethods.MFCreateWaveFormatExFromMFMediaType(BasePtr.ToPointer(), &pointer, &cbSize,
                 (int) flags), "Interop", "MFCreateWaveFormatExFromMFMediaType");
     }
     finally
     {
         Marshal.FreeCoTaskMem(pointer);
     }
     //var waveformat = (WaveFormat)Marshal.PtrToStructure(pointer, typeof(WaveFormat));
     //if (waveformat.WaveFormatTag == AudioEncoding.Extensible)
     //    waveformat = (WaveFormatExtensible)Marshal.PtrToStructure(pointer, typeof(WaveFormatExtensible));
     //return waveformat;
     return WaveFormatMarshaler.PointerToWaveFormat(pointer);
 }
Beispiel #5
0
 public static extern void MFCreateWaveFormatExFromMFMediaType(
     IMFMediaType pMFType,
     [Out, MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(WEMarshaler))] out WaveFormatEx ppWF,
     out int pcbSize,
     MFWaveFormatExConvertFlags Flags
     );
Beispiel #6
0
 public unsafe WaveFormat ToWaveFormat(out int bufferSize, MFWaveFormatExConvertFlags flags)
 {
     IntPtr pointer = IntPtr.Zero;
     fixed (void* ptr = &bufferSize)
     {
         MediaFoundationException.Try(MFCreateWaveFormatExFromMFMediaType(BasePtr.ToPointer(), (void*)(&pointer), (void*)(ptr), (int)flags), "interop", "MFCreateWaveFormatExFromMFMediaType");
     }
     var waveformat = (WaveFormat)Marshal.PtrToStructure(pointer, typeof(WaveFormat)); //todo:
     if (waveformat.WaveFormatTag == AudioEncoding.Extensible)
         waveformat = (WaveFormatExtensible)Marshal.PtrToStructure(pointer, typeof(WaveFormatExtensible));
     return waveformat;
 }