-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoreAudioApi.cs
More file actions
89 lines (78 loc) · 3.21 KB
/
CoreAudioApi.cs
File metadata and controls
89 lines (78 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Runtime.InteropServices;
namespace AudioSwitcher;
[ComImport, Guid("BCDE0395-E52F-467C-8E3D-C4579291692E")]
internal class MMDeviceEnumeratorCom { }
[Guid("A95664D2-9614-4F35-A746-DE8DB63617E6")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IMMDeviceEnumerator
{
int EnumAudioEndpoints(EDataFlow dataFlow, uint stateMask, out IMMDeviceCollection devices);
int GetDefaultAudioEndpoint(EDataFlow dataFlow, ERole role, out IMMDevice device);
int GetDevice(string id, out IMMDevice device);
}
[Guid("0BD7A1BE-7A1A-44DB-8397-CC5392387B5E")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IMMDeviceCollection
{
int GetCount(out int count);
int Item(int index, out IMMDevice device);
}
[Guid("D666063F-1587-4E43-81F1-B948E807363F")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IMMDevice
{
int Activate(ref Guid iid, int clsCtx, IntPtr activationParams,
[MarshalAs(UnmanagedType.IUnknown)] out object iface);
int OpenPropertyStore(int access, out IPropertyStore properties);
int GetId([MarshalAs(UnmanagedType.LPWStr)] out string id);
int GetState(out int state);
}
[Guid("886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IPropertyStore
{
int GetCount(out int count);
int GetAt(int index, out PropertyKey key);
int GetValue(ref PropertyKey key, out PropVariant value);
int SetValue(ref PropertyKey key, ref PropVariant value);
int Commit();
}
[Guid("F8679F50-850A-41CF-9C72-430F290290C8")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IPolicyConfig
{
int GetMixFormat(string deviceId, IntPtr format);
int GetDeviceFormat(string deviceId, int isDefault, IntPtr format);
int ResetDeviceFormat(string deviceId);
int SetDeviceFormat(string deviceId, IntPtr endpointFormat, IntPtr mixFormat);
int GetProcessingPeriod(string deviceId, int isDefault, IntPtr defaultPeriod, IntPtr minPeriod);
int SetProcessingPeriod(string deviceId, IntPtr period);
int GetShareMode(string deviceId, IntPtr mode);
int SetShareMode(string deviceId, IntPtr mode);
int GetPropertyValue(string deviceId, int isStore, PropertyKey key, out PropVariant value);
int SetPropertyValue(string deviceId, int isStore, PropertyKey key, ref PropVariant value);
int SetDefaultEndpoint(string deviceId, ERole role);
int SetEndpointVisibility(string deviceId, int isVisible);
}
[ComImport, Guid("870AF99C-171D-4F9E-AF0D-E63DF40C2BC9")]
internal class PolicyConfigCom { }
internal enum EDataFlow { eRender = 0, eCapture = 1, eAll = 2 }
internal enum ERole { eConsole = 0, eMultimedia = 1, eCommunications = 2 }
[StructLayout(LayoutKind.Sequential)]
internal struct PropertyKey
{
public Guid fmtid;
public int pid;
public PropertyKey(Guid fmtid, int pid) { this.fmtid = fmtid; this.pid = pid; }
}
[StructLayout(LayoutKind.Sequential)]
internal struct PropVariant
{
public ushort vt;
private ushort wReserved1, wReserved2, wReserved3;
public IntPtr data1;
public IntPtr data2;
public string? StringValue =>
vt == 31 /* VT_LPWSTR */ ? Marshal.PtrToStringUni(data1) : null;
}