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

New Post: Odd byte[] array behaviour in WaveFormat

$
0
0
I'm doing it both ways actually:
public MediaFoundationDecoder(IMFMediaType inputMediaType, IMFMediaType outputMediaType)
public MediaFoundationDecoder(WaveFormat inputFormat, WaveFormat outputFormat)

But for some reason when I pass through the IMFMediaType I get this exception:
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'NAudio.MediaFoundation.IMFMediaType'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{44AE0FA8-EA31-4109-8D2E-4CAE4997C555}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

I made sure I wasn't calling Marshal.ReleaseComObject(inputMediaFormat) onto it. All I can think of is maybe the IMFMediaTypes must be created AFTER creating the Activator var comObject = CreateResamplerComObject();


Anyway I got WaveFormatExtraData working in MediaFoundation by removing the byte[] and adding simple bytes. It seems MediaFoundation checks the whole structure for arrays and refuses to handle them.
   [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 2)]
    public class WaveFormatExtraDataNEW : WaveFormat
    {
        // try with 100 bytes for now, increase if necessary
        //[MarshalAs(UnmanagedType.ByValArray, SizeConst = 14)]
        //private byte[] extraData = new byte[14];

        /// <summary>
        /// Allows the extra data to be read
        /// </summary>
        //public byte[] ExtraData { get { return extraData; } }
        
        
        
        public byte byte1;
        public byte byte2;
        public byte byte3;
        public byte byte4;
        public byte byte5;
        public byte byte6;
        public byte byte7;
        public byte byte8;
        public byte byte9;
        public byte byte10;
        public byte byte11;
        public byte byte12;
        public byte byte13;
        public byte byte14;

Viewing all articles
Browse latest Browse all 5831


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