-
Notifications
You must be signed in to change notification settings - Fork 0
/
policyconfig.py
176 lines (150 loc) · 4.37 KB
/
policyconfig.py
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
## This module is in large chunks taken from https://github.com/kdschlosser/pyWinCoreAudio/blob/431d5d9b470083a6a5c51738e08b12009fa315eb/pyWinCoreAudio/__core_audio/policyconfig.py.
## This requires us to use comtypes alongside pywin32, which is somewhat of a duplication in depedencies.
## I think we could use pyWinCoreAudio instead of soundcard, but we will still likely need pywin32 for the service.
import comtypes, enum
from comtypes import COMMETHOD, GUID
import ctypes
from ctypes import (
POINTER,
HRESULT,
c_int as enum
)
from ctypes.wintypes import (
INT,
BOOL,
LPCWSTR,
WORD
)
IID_IPolicyConfig = GUID(
'{f8679f50-850a-41cf-9c72-430f290290c8}'
)
CLSID_PolicyConfigClient = GUID(
'{870af99c-171d-4f9e-af0d-e63df40c2bc9}'
)
REFERENCE_TIME = ctypes.c_longlong
LPCGUID = POINTER(GUID)
LPREFERENCE_TIME = POINTER(REFERENCE_TIME)
class DeviceSharedMode(ctypes.Structure):
_fields_ = [
('dummy_', INT)
]
PDeviceSharedMode = POINTER(DeviceSharedMode)
class WAVEFORMATEX(ctypes.Structure):
_fields_ = [
('wFormatTag', WORD),
('nChannels', WORD),
('nSamplesPerSec', WORD),
('nAvgBytesPerSec', WORD),
('nBlockAlign', WORD),
('wBitsPerSample', WORD),
('cbSize', WORD),
]
PWAVEFORMATEX = POINTER(WAVEFORMATEX)
class _tagpropertykey(ctypes.Structure):
pass
class tag_inner_PROPVARIANT(ctypes.Structure):
pass
PROPVARIANT = tag_inner_PROPVARIANT
PPROPVARIANT = POINTER(PROPVARIANT)
PROPERTYKEY = _tagpropertykey
PPROPERTYKEY = POINTER(_tagpropertykey)
class ERole(enum):
eConsole = 0
eMultimedia = 1
eCommunications = 2
ERole_enum_count = 3
class IPolicyConfig(comtypes.IUnknown):
_case_insensitive_ = True
_iid_ = IID_IPolicyConfig
_methods_ = (
COMMETHOD(
[],
HRESULT,
'GetMixFormat',
(['in'], LPCWSTR, 'pwstrDeviceId'),
(['out'], POINTER(PWAVEFORMATEX), 'pFormat')
),
COMMETHOD(
[],
HRESULT,
'GetDeviceFormat',
(['in'], LPCWSTR, 'pwstrDeviceId'),
(['in'], BOOL, 'bDefault'),
(['out'], POINTER(PWAVEFORMATEX), 'pFormat')
),
COMMETHOD(
[],
HRESULT,
'ResetDeviceFormat',
(['in'], LPCWSTR, 'pwstrDeviceId')
),
COMMETHOD(
[],
HRESULT,
'SetDeviceFormat',
(['in'], LPCWSTR, 'pwstrDeviceId'),
(['in'], PWAVEFORMATEX, 'pEndpointFormat'),
(['in'], PWAVEFORMATEX, 'pMixFormat')
),
COMMETHOD(
[],
HRESULT,
'GetProcessingPeriod',
(['in'], LPCWSTR, 'pwstrDeviceId'),
(['in'], BOOL, 'bDefault'),
(['out'], LPREFERENCE_TIME, 'hnsDefaultDevicePeriod'),
(['out'], LPREFERENCE_TIME, 'hnsMinimumDevicePeriod')
),
COMMETHOD(
[],
HRESULT,
'SetProcessingPeriod',
(['in'], LPCWSTR, 'pwstrDeviceId'),
(['in'], LPREFERENCE_TIME, 'hnsDevicePeriod')
),
COMMETHOD(
[],
HRESULT,
'GetShareMode',
(['in'], LPCWSTR, 'pwstrDeviceId'),
(['out'], PDeviceSharedMode, 'pMode')
),
COMMETHOD(
[],
HRESULT,
'SetShareMode',
(['in'], LPCWSTR, 'pwstrDeviceId'),
(['in'], PDeviceSharedMode, 'pMode')
),
COMMETHOD(
[],
HRESULT,
'GetPropertyValue',
(['in'], LPCWSTR, 'pwstrDeviceId'),
(['in'], PPROPERTYKEY, 'key'),
(['out'], PPROPVARIANT, 'pValue')
),
COMMETHOD(
[],
HRESULT,
'SetPropertyValue',
(['in'], LPCWSTR, 'pwstrDeviceId'),
(['in'], PPROPERTYKEY, 'key'),
(['in'], PPROPVARIANT, 'pValue')
),
COMMETHOD(
[],
HRESULT,
'SetDefaultEndpoint',
(['in'], LPCWSTR, 'pwstrDeviceId'),
(['in'], ERole, 'ERole')
),
COMMETHOD(
[],
HRESULT,
'SetEndpointVisibility',
(['in'], LPCWSTR, 'pwstrDeviceId'),
(['in'], BOOL, 'bVisible')
)
)
PIPolicyConfig = POINTER(IPolicyConfig)