using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using NAudio.Wave;
using System.Runtime.InteropServices.ComTypes;
namespace NAudio.MediaFoundation
{
///
/// Interop definitions for MediaFoundation
/// thanks to Lucian Wischik for the initial work on many of these definitions (also various interfaces)
/// n.b. the goal is to make as much of this internal as possible, and provide
/// better .NET APIs using the MediaFoundationApi class instead
///
public static class MediaFoundationInterop
{
///
/// Initializes Microsoft Media Foundation.
///
[DllImport("mfplat.dll", ExactSpelling = true, PreserveSig = false)]
public static extern void MFStartup(int version, int dwFlags = 0);
///
/// Shuts down the Microsoft Media Foundation platform
///
[DllImport("mfplat.dll", ExactSpelling = true, PreserveSig = false)]
public static extern void MFShutdown();
///
/// Creates an empty media type.
///
[DllImport("mfplat.dll", ExactSpelling = true, PreserveSig = false)]
internal static extern void MFCreateMediaType(out IMFMediaType ppMFType);
///
/// Initializes a media type from a WAVEFORMATEX structure.
///
[DllImport("mfplat.dll", ExactSpelling = true, PreserveSig = false)]
internal static extern void MFInitMediaTypeFromWaveFormatEx([In] IMFMediaType pMFType, [In] WaveFormat pWaveFormat, [In] int cbBufSize);
///
/// Converts a Media Foundation audio media type to a WAVEFORMATEX structure.
///
/// TODO: try making second parameter out WaveFormatExtraData
[DllImport("mfplat.dll", ExactSpelling = true, PreserveSig = false)]
internal static extern void MFCreateWaveFormatExFromMFMediaType(IMFMediaType pMFType, ref IntPtr ppWF, ref int pcbSize, int flags = 0);
///
/// Creates the source reader from a URL.
///
[DllImport("mfreadwrite.dll", ExactSpelling = true, PreserveSig = false)]
public static extern void MFCreateSourceReaderFromURL([In, MarshalAs(UnmanagedType.LPWStr)] string pwszURL, [In] IMFAttributes pAttributes,
[Out, MarshalAs(UnmanagedType.Interface)] out IMFSourceReader ppSourceReader);
///
/// Creates the source reader from a byte stream.
///
[DllImport("mfreadwrite.dll", ExactSpelling = true, PreserveSig = false)]
public static extern void MFCreateSourceReaderFromByteStream([In] IMFByteStream pByteStream, [In] IMFAttributes pAttributes, [Out, MarshalAs(UnmanagedType.Interface)] out IMFSourceReader ppSourceReader);
///
/// Creates the sink writer from a URL or byte stream.
///
[DllImport("mfreadwrite.dll", ExactSpelling = true, PreserveSig = false)]
public static extern void MFCreateSinkWriterFromURL([In, MarshalAs(UnmanagedType.LPWStr)] string pwszOutputURL,
[In] IMFByteStream pByteStream, [In] IMFAttributes pAttributes, [Out] out IMFSinkWriter ppSinkWriter);
///
/// Creates a Microsoft Media Foundation byte stream that wraps an IRandomAccessStream object.
///
[DllImport("mfplat.dll", ExactSpelling = true, PreserveSig = false)]
public static extern void MFCreateMFByteStreamOnStreamEx([MarshalAs(UnmanagedType.IUnknown)] object punkStream, out IMFByteStream ppByteStream);
///
/// Creates a Microsoft Media Foundation byte stream that wraps an IRandomAccessStream object.
///
[DllImport("mfplat.dll", ExactSpelling = true, PreserveSig = false)]
public static extern void MFCreateMFByteStreamOnStream([In] IStream punkStream, out IMFByteStream ppByteStream);
///
/// Gets a list of Microsoft Media Foundation transforms (MFTs) that match specified search criteria.
///
[DllImport("mfplat.dll", ExactSpelling = true, PreserveSig = false)]
public static extern void MFTEnumEx([In] Guid guidCategory, [In] _MFT_ENUM_FLAG flags, [In] MFT_REGISTER_TYPE_INFO pInputType, [In] MFT_REGISTER_TYPE_INFO pOutputType,
[Out] out IntPtr pppMFTActivate, [Out] out int pcMFTActivate);
///
/// Creates an empty media sample.
///
[DllImport("mfplat.dll", ExactSpelling = true, PreserveSig = false)]
internal static extern void MFCreateSample([Out] out IMFSample ppIMFSample);
///
/// Allocates system memory and creates a media buffer to manage it.
///
[DllImport("mfplat.dll", ExactSpelling = true, PreserveSig = false)]
internal static extern void MFCreateMemoryBuffer(
int cbMaxLength, [Out] out IMFMediaBuffer ppBuffer);
///
/// Creates an empty attribute store.
///
[DllImport("mfplat.dll", ExactSpelling = true, PreserveSig = false)]
internal static extern void MFCreateAttributes(
[Out, MarshalAs(UnmanagedType.Interface)] out IMFAttributes ppMFAttributes,
[In] int cInitialSize);
///
/// Gets a list of output formats from an audio encoder.
///
[DllImport("mf.dll", ExactSpelling = true, PreserveSig = false)]
public static extern void MFTranscodeGetAudioOutputAvailableTypes(
[In, MarshalAs(UnmanagedType.LPStruct)] Guid guidSubType,
[In] _MFT_ENUM_FLAG dwMFTFlags,
[In] IMFAttributes pCodecConfig,
[Out, MarshalAs(UnmanagedType.Interface)] out IMFCollection ppAvailableTypes);
///
/// All streams
///
public const int MF_SOURCE_READER_ALL_STREAMS = unchecked((int)0xFFFFFFFE);
///
/// First audio stream
///
public const int MF_SOURCE_READER_FIRST_AUDIO_STREAM = unchecked((int)0xFFFFFFFD);
///
/// First video stream
///
public const int MF_SOURCE_READER_FIRST_VIDEO_STREAM = unchecked((int)0xFFFFFFFC);
///
/// Media source
///
public const int MF_SOURCE_READER_MEDIASOURCE = unchecked((int)0xFFFFFFFF);
///
/// Media Foundation SDK Version
///
public const int MF_SDK_VERSION = 0x2;
///
/// Media Foundation API Version
///
public const int MF_API_VERSION = 0x70;
///
/// Media Foundation Version
///
public const int MF_VERSION = (MF_SDK_VERSION << 16) | MF_API_VERSION;
}
}