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.
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);