예제 #1
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);
        }
예제 #2
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));
        }