Quantcast
Channel: NAudio
Viewing all articles
Browse latest Browse all 5831

New Post: MFCreateWaveFormatExFromMFMediaType exception

$
0
0
I'm trying to get a WaveFormat from a MediaType via MediaFoundationReader but I'm not sure if this is the correct way of doing it. StructureToPtr is throwing an exception.

Line: Marshal.StructureToPtr(wfed, waveFormatPointer, false);
Exception: System.AccessViolationException: Attempted to read or write protected memory.
            IMFMediaType uncompressedMediaType;
            
            
            reader.GetCurrentMediaType(MediaFoundationInterop.MF_SOURCE_READER_FIRST_AUDIO_STREAM, out uncompressedMediaType);

            WaveFormatExtraData wfed = new WaveFormatExtraData();
            IntPtr waveFormatPointer = new IntPtr(Marshal.SizeOf(wfed));
            Marshal.StructureToPtr(wfed, waveFormatPointer, false);

            
            int size = 0;
            MediaFoundationInterop.MFCreateWaveFormatExFromMFMediaType(uncompressedMediaType, ref waveFormatPointer, ref size, 0);
            
            WaveFormat waveFormat = WaveFormat.MarshalFromPtr(waveFormatPointer);

Viewing all articles
Browse latest Browse all 5831


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>