1using System; 2using System.Runtime.InteropServices; 3 4namespace WindowCapture.Native 5{ 6 [StructLayout(LayoutKind.Sequential)] 7 public struct WAVEFORMATEX 8 { 9 public ushort wFormatTag; 10 public ushort nChannels; 11 public uint nSamplesPerSec; 12 public uint nAvgBytesPerSec; 13 public ushort nBlockAlign; 14 public ushort wBitsPerSample; 15 public ushort cbSize; 16 } 17 18 [ComImport, Guid("A95664D2-9614-4F35-A746-DE8DB63617E6"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 19 public interface IMMDeviceEnumerator 20 { 21 void EnumAudioEndpoints(int dataFlow, int dwStateMask, [MarshalAs(UnmanagedType.IUnknown)] out object ppDevices); 22 void GetDefaultAudioEndpoint(int dataFlow, int role, out IMMDevice ppEndpoint); 23 void GetDevice([MarshalAs(UnmanagedType.LPWStr)] string pwstrId, out IMMDevice ppDevice); 24 void RegisterEndpointNotificationCallback([MarshalAs(UnmanagedType.IUnknown)] object pClient); 25 void UnregisterEndpointNotificationCallback([MarshalAs(UnmanagedType.IUnknown)] object pClient); 26 } 27 28 [ComImport, Guid("D666063F-1587-4E43-81F1-B948E807363F"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 29 public interface IMMDevice 30 { 31 void Activate(ref Guid iid, int clsCtx, IntPtr pActivationParams, [MarshalAs(UnmanagedType.IUnknown)] out object ppInterface); 32 void OpenPropertyStore(int stgmAccess, [MarshalAs(UnmanagedType.IUnknown)] out object ppProperties); 33 void GetId([MarshalAs(UnmanagedType.LPWStr)] out string ppstrId); 34 void GetState(out int pdwState); 35 } 36 37 [ComImport, Guid("1CB9AD4C-DBFA-4C32-B178-C2F568A703B2"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 38 public interface IAudioClient 39 { 40 void Initialize(int ShareMode, int StreamFlags, long hnsBufferDuration, long hnsPeriodicity, IntPtr pFormat, IntPtr AudioSessionGuid); 41 void GetBufferSize(out uint pNumBufferFrames); 42 void GetStreamLatency(out long phnsLatency); 43 void GetCurrentPadding(out uint pNumPaddingFrames); 44 void IsFormatSupported(int ShareMode, ref WAVEFORMATEX pFormat, out IntPtr ppClosestMatch); 45 void GetMixFormat(out IntPtr ppDeviceFormat); 46 void GetDevicePeriod(out long phnsDefaultDevicePeriod, out long phnsMinimumDevicePeriod); 47 void Start(); 48 void Stop(); 49 void Reset(); 50 void SetEventHandle(IntPtr eventHandle); 51 void GetService(ref Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv); 52 } 53 54 [ComImport, Guid("C8ADBD64-E71E-48A0-A4DE-185C395CD317"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 55 public interface IAudioCaptureClient 56 { 57 void GetBuffer(out IntPtr ppData, out uint pNumFramesAvailable, out uint pdwFlags, out ulong pu64DevicePosition, out ulong pu64QPCPosition); 58 void ReleaseBuffer(uint NumFramesRead); 59 void GetNextPacketSize(out uint pNumFramesInNextPacket); 60 } 61 62 [ComImport, Guid("F294ACFC-3146-4483-A7BF-ADDCA7C260E2"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 63 public interface IAudioRenderClient 64 { 65 void GetBuffer(uint NumFramesRequested, out IntPtr ppData); 66 void ReleaseBuffer(uint NumFramesWritten, uint dwFlags); 67 } 68 69 [ComImport, Guid("87CE5498-68D6-44E5-9215-6DA47EF883D8"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 70 public interface ISimpleAudioVolume 71 { 72 void SetMasterVolume(float fLevel, ref Guid EventContext); 73 void GetMasterVolume(out float pfLevel); 74 void SetMute([MarshalAs(UnmanagedType.Bool)] bool bMute, ref Guid EventContext); 75 void GetMute([MarshalAs(UnmanagedType.Bool)] out bool pbMute); 76 } 77}