truehear-audio-library-node 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,420 @@
1
+ #ifndef TRUEHEAR_IPOLICY_CONFIG_H
2
+ #define TRUEHEAR_IPOLICY_CONFIG_H
3
+
4
+ #include <windows.h>
5
+ #include <mmdeviceapi.h>
6
+ #include <audioclient.h>
7
+ #include <propidl.h>
8
+
9
+ /*
10
+ * Undocumented Windows PolicyConfig COM interfaces.
11
+ *
12
+ * Windows does not provide an official public header for these interfaces,
13
+ * but they are commonly used to change the default audio endpoint.
14
+ *
15
+ * This header manually describes the COM vtable layout so we can call methods
16
+ * directly through the vtable:
17
+ *
18
+ * policy_config->lpVtbl->SetDefaultEndpoint(
19
+ * policy_config,
20
+ * device_id,
21
+ * eConsole
22
+ * );
23
+ *
24
+ * Important:
25
+ * - The method order in the vtable matters.
26
+ * - COM uses the vtable index to find the function.
27
+ * - Do not reorder methods unless you are intentionally changing the interface.
28
+ *
29
+ * GUIDs are only declared here as extern.
30
+ * They must be defined in exactly one .c file, for example:
31
+ *
32
+ * src/policy_config_guids.c
33
+ */
34
+
35
+ #ifdef __cplusplus
36
+ extern "C" {
37
+ #endif
38
+
39
+ /* ---------------------------------------------------------------------------------------------- */
40
+ /* GUID declarations */
41
+ /* ---------------------------------------------------------------------------------------------- */
42
+
43
+ /*
44
+ * Modern IPolicyConfig interface ID.
45
+ *
46
+ * Used with CoCreateInstance together with CLSID_CPolicyConfigClient.
47
+ */
48
+ extern const IID IID_IPolicyConfig;
49
+
50
+ /*
51
+ * Modern PolicyConfig COM class ID.
52
+ *
53
+ * Used to create the COM object:
54
+ *
55
+ * CoCreateInstance(
56
+ * &CLSID_CPolicyConfigClient,
57
+ * NULL,
58
+ * CLSCTX_ALL,
59
+ * &IID_IPolicyConfig,
60
+ * (void **)&policy_config
61
+ * );
62
+ */
63
+ extern const CLSID CLSID_CPolicyConfigClient;
64
+
65
+ /*
66
+ * Older Vista-era interface ID.
67
+ *
68
+ * Kept separately because the Vista vtable layout is not identical to the
69
+ * modern IPolicyConfig layout.
70
+ */
71
+ extern const IID IID_IPolicyConfigVista;
72
+
73
+ /*
74
+ * Older Vista-era PolicyConfig COM class ID.
75
+ */
76
+ extern const CLSID CLSID_CPolicyConfigVistaClient;
77
+
78
+ /* ---------------------------------------------------------------------------------------------- */
79
+ /* Forward declarations */
80
+ /* ---------------------------------------------------------------------------------------------- */
81
+
82
+ /*
83
+ * DeviceShareMode is part of the PolicyConfig interface.
84
+ *
85
+ * For now, we only need it as a pointer type in the vtable, so a forward
86
+ * declaration is enough.
87
+ */
88
+ typedef struct DeviceShareMode DeviceShareMode;
89
+
90
+ /*
91
+ * Modern PolicyConfig interface.
92
+ */
93
+ typedef struct IPolicyConfig IPolicyConfig;
94
+ typedef struct IPolicyConfigVtbl IPolicyConfigVtbl;
95
+
96
+ /*
97
+ * Vista-era PolicyConfig interface.
98
+ */
99
+ typedef struct IPolicyConfigVista IPolicyConfigVista;
100
+ typedef struct IPolicyConfigVistaVtbl IPolicyConfigVistaVtbl;
101
+
102
+ /* ---------------------------------------------------------------------------------------------- */
103
+ /* IPolicyConfig */
104
+ /* ---------------------------------------------------------------------------------------------- */
105
+
106
+ /*
107
+ * COM object layout.
108
+ *
109
+ * A COM object begins with a pointer to a vtable.
110
+ *
111
+ * We keep the traditional COM field name `lpVtbl`.
112
+ * That means calls look like:
113
+ *
114
+ * policy_config->lpVtbl->MethodName(policy_config, ...);
115
+ */
116
+ struct IPolicyConfig {
117
+ const IPolicyConfigVtbl *lpVtbl;
118
+ };
119
+
120
+ /*
121
+ * Vtable for the modern IPolicyConfig interface.
122
+ *
123
+ * The first three methods are the standard IUnknown methods:
124
+ *
125
+ * QueryInterface
126
+ * AddRef
127
+ * Release
128
+ *
129
+ * The later methods are PolicyConfig-specific methods.
130
+ */
131
+ struct IPolicyConfigVtbl {
132
+ /*
133
+ * Ask the COM object for another interface.
134
+ */
135
+ HRESULT(STDMETHODCALLTYPE *QueryInterface)(
136
+ IPolicyConfig *This,
137
+ REFIID riid,
138
+ void **ppvObject);
139
+
140
+ /*
141
+ * Increase the COM reference count.
142
+ */
143
+ ULONG(STDMETHODCALLTYPE *AddRef)(
144
+ IPolicyConfig *This);
145
+
146
+ /*
147
+ * Decrease the COM reference count.
148
+ *
149
+ * When you are done with the object, call:
150
+ *
151
+ * policy_config->lpVtbl->Release(policy_config);
152
+ */
153
+ ULONG(STDMETHODCALLTYPE *Release)(
154
+ IPolicyConfig *This);
155
+
156
+ /*
157
+ * Get the mix format for an audio endpoint.
158
+ */
159
+ HRESULT(STDMETHODCALLTYPE *GetMixFormat)(
160
+ IPolicyConfig *This,
161
+ PCWSTR wszDeviceId,
162
+ WAVEFORMATEX **ppFormat);
163
+
164
+ /*
165
+ * Get the device format for an audio endpoint.
166
+ */
167
+ HRESULT(STDMETHODCALLTYPE *GetDeviceFormat)(
168
+ IPolicyConfig *This,
169
+ PCWSTR wszDeviceId,
170
+ INT bDefault,
171
+ WAVEFORMATEX **ppFormat);
172
+
173
+ /*
174
+ * Reset the device format.
175
+ *
176
+ * This method exists in the modern IPolicyConfig layout.
177
+ */
178
+ HRESULT(STDMETHODCALLTYPE *ResetDeviceFormat)(
179
+ IPolicyConfig *This,
180
+ PCWSTR wszDeviceId);
181
+
182
+ /*
183
+ * Set the device format.
184
+ */
185
+ HRESULT(STDMETHODCALLTYPE *SetDeviceFormat)(
186
+ IPolicyConfig *This,
187
+ PCWSTR wszDeviceId,
188
+ WAVEFORMATEX *pEndpointFormat,
189
+ WAVEFORMATEX *pMixFormat);
190
+
191
+ /*
192
+ * Get the processing period for an audio endpoint.
193
+ */
194
+ HRESULT(STDMETHODCALLTYPE *GetProcessingPeriod)(
195
+ IPolicyConfig *This,
196
+ PCWSTR wszDeviceId,
197
+ INT bDefault,
198
+ PINT64 pmftDefaultPeriod,
199
+ PINT64 pmftMinimumPeriod);
200
+
201
+ /*
202
+ * Set the processing period for an audio endpoint.
203
+ */
204
+ HRESULT(STDMETHODCALLTYPE *SetProcessingPeriod)(
205
+ IPolicyConfig *This,
206
+ PCWSTR wszDeviceId,
207
+ PINT64 pmftPeriod);
208
+
209
+ /*
210
+ * Get the sharing mode for an audio endpoint.
211
+ */
212
+ HRESULT(STDMETHODCALLTYPE *GetShareMode)(
213
+ IPolicyConfig *This,
214
+ PCWSTR wszDeviceId,
215
+ DeviceShareMode *pMode);
216
+
217
+ /*
218
+ * Set the sharing mode for an audio endpoint.
219
+ */
220
+ HRESULT(STDMETHODCALLTYPE *SetShareMode)(
221
+ IPolicyConfig *This,
222
+ PCWSTR wszDeviceId,
223
+ DeviceShareMode *pMode);
224
+
225
+ /*
226
+ * Get a property value from an audio endpoint.
227
+ */
228
+ HRESULT(STDMETHODCALLTYPE *GetPropertyValue)(
229
+ IPolicyConfig *This,
230
+ PCWSTR wszDeviceId,
231
+ const PROPERTYKEY *key,
232
+ PROPVARIANT *pv);
233
+
234
+ /*
235
+ * Set a property value on an audio endpoint.
236
+ */
237
+ HRESULT(STDMETHODCALLTYPE *SetPropertyValue)(
238
+ IPolicyConfig *This,
239
+ PCWSTR wszDeviceId,
240
+ const PROPERTYKEY *key,
241
+ PROPVARIANT *pv);
242
+
243
+ /*
244
+ * Set the default audio endpoint for a specific Windows audio role.
245
+ *
246
+ * Common roles:
247
+ *
248
+ * eConsole
249
+ * Normal system/default device.
250
+ *
251
+ * eMultimedia
252
+ * Media playback device.
253
+ *
254
+ * eCommunications
255
+ * Calls/communication device.
256
+ *
257
+ * Usually, when changing the default device, you call this three times:
258
+ *
259
+ * policy_config->lpVtbl->SetDefaultEndpoint(policy_config, id, eConsole);
260
+ * policy_config->lpVtbl->SetDefaultEndpoint(policy_config, id, eMultimedia);
261
+ * policy_config->lpVtbl->SetDefaultEndpoint(policy_config, id, eCommunications);
262
+ */
263
+ HRESULT(STDMETHODCALLTYPE *SetDefaultEndpoint)(
264
+ IPolicyConfig *This,
265
+ PCWSTR wszDeviceId,
266
+ ERole eRole);
267
+
268
+ /*
269
+ * Show or hide an endpoint.
270
+ *
271
+ * Not needed for the first version of the library, but it belongs in the
272
+ * vtable because the real COM interface has it.
273
+ */
274
+ HRESULT(STDMETHODCALLTYPE *SetEndpointVisibility)(
275
+ IPolicyConfig *This,
276
+ PCWSTR wszDeviceId,
277
+ INT bVisible);
278
+ };
279
+
280
+ /* ---------------------------------------------------------------------------------------------- */
281
+ /* IPolicyConfigVista */
282
+ /* ---------------------------------------------------------------------------------------------- */
283
+
284
+ /*
285
+ * Vista-era COM object layout.
286
+ *
287
+ * Same idea as IPolicyConfig:
288
+ *
289
+ * vista_config->lpVtbl->SetDefaultEndpoint(vista_config, device_id, eConsole);
290
+ */
291
+ struct IPolicyConfigVista {
292
+ const IPolicyConfigVistaVtbl *lpVtbl;
293
+ };
294
+
295
+ /*
296
+ * Vtable for the older Vista-era PolicyConfig interface.
297
+ *
298
+ * Important difference:
299
+ * The Vista-era layout does not have ResetDeviceFormat in the same place as
300
+ * the modern IPolicyConfig interface.
301
+ *
302
+ * That is why this is defined separately.
303
+ */
304
+ struct IPolicyConfigVistaVtbl {
305
+ /*
306
+ * Standard COM IUnknown methods.
307
+ */
308
+ HRESULT(STDMETHODCALLTYPE *QueryInterface)(
309
+ IPolicyConfigVista *This,
310
+ REFIID riid,
311
+ void **ppvObject);
312
+
313
+ ULONG(STDMETHODCALLTYPE *AddRef)(
314
+ IPolicyConfigVista *This);
315
+
316
+ ULONG(STDMETHODCALLTYPE *Release)(
317
+ IPolicyConfigVista *This);
318
+
319
+ /*
320
+ * Get the mix format for an audio endpoint.
321
+ */
322
+ HRESULT(STDMETHODCALLTYPE *GetMixFormat)(
323
+ IPolicyConfigVista *This,
324
+ PCWSTR wszDeviceId,
325
+ WAVEFORMATEX **ppFormat);
326
+
327
+ /*
328
+ * Get the device format for an audio endpoint.
329
+ */
330
+ HRESULT(STDMETHODCALLTYPE *GetDeviceFormat)(
331
+ IPolicyConfigVista *This,
332
+ PCWSTR wszDeviceId,
333
+ INT bDefault,
334
+ WAVEFORMATEX **ppFormat);
335
+
336
+ /*
337
+ * Set the device format.
338
+ *
339
+ * Notice that ResetDeviceFormat is not here in the Vista-era layout.
340
+ */
341
+ HRESULT(STDMETHODCALLTYPE *SetDeviceFormat)(
342
+ IPolicyConfigVista *This,
343
+ PCWSTR wszDeviceId,
344
+ WAVEFORMATEX *pEndpointFormat,
345
+ WAVEFORMATEX *pMixFormat);
346
+
347
+ /*
348
+ * Get the processing period for an audio endpoint.
349
+ */
350
+ HRESULT(STDMETHODCALLTYPE *GetProcessingPeriod)(
351
+ IPolicyConfigVista *This,
352
+ PCWSTR wszDeviceId,
353
+ INT bDefault,
354
+ PINT64 pmftDefaultPeriod,
355
+ PINT64 pmftMinimumPeriod);
356
+
357
+ /*
358
+ * Set the processing period for an audio endpoint.
359
+ */
360
+ HRESULT(STDMETHODCALLTYPE *SetProcessingPeriod)(
361
+ IPolicyConfigVista *This,
362
+ PCWSTR wszDeviceId,
363
+ PINT64 pmftPeriod);
364
+
365
+ /*
366
+ * Get the sharing mode for an audio endpoint.
367
+ */
368
+ HRESULT(STDMETHODCALLTYPE *GetShareMode)(
369
+ IPolicyConfigVista *This,
370
+ PCWSTR wszDeviceId,
371
+ DeviceShareMode *pMode);
372
+
373
+ /*
374
+ * Set the sharing mode for an audio endpoint.
375
+ */
376
+ HRESULT(STDMETHODCALLTYPE *SetShareMode)(
377
+ IPolicyConfigVista *This,
378
+ PCWSTR wszDeviceId,
379
+ DeviceShareMode *pMode);
380
+
381
+ /*
382
+ * Get a property value from an audio endpoint.
383
+ */
384
+ HRESULT(STDMETHODCALLTYPE *GetPropertyValue)(
385
+ IPolicyConfigVista *This,
386
+ PCWSTR wszDeviceId,
387
+ const PROPERTYKEY *key,
388
+ PROPVARIANT *pv);
389
+
390
+ /*
391
+ * Set a property value on an audio endpoint.
392
+ */
393
+ HRESULT(STDMETHODCALLTYPE *SetPropertyValue)(
394
+ IPolicyConfigVista *This,
395
+ PCWSTR wszDeviceId,
396
+ const PROPERTYKEY *key,
397
+ PROPVARIANT *pv);
398
+
399
+ /*
400
+ * Set the default audio endpoint for a specific Windows audio role.
401
+ */
402
+ HRESULT(STDMETHODCALLTYPE *SetDefaultEndpoint)(
403
+ IPolicyConfigVista *This,
404
+ PCWSTR wszDeviceId,
405
+ ERole eRole);
406
+
407
+ /*
408
+ * Show or hide an endpoint.
409
+ */
410
+ HRESULT(STDMETHODCALLTYPE *SetEndpointVisibility)(
411
+ IPolicyConfigVista *This,
412
+ PCWSTR wszDeviceId,
413
+ INT bVisible);
414
+ };
415
+
416
+ #ifdef __cplusplus
417
+ }
418
+ #endif
419
+
420
+ #endif /* TRUEHEAR_IPOLICY_CONFIG_H */
@@ -0,0 +1,9 @@
1
+ #ifndef MMDEVICE_GUIDS_H
2
+ #define MMDEVICE_GUIDS_H
3
+
4
+ #include <windows.h>
5
+
6
+ extern const CLSID CLSID_MMDeviceEnumerator;
7
+ extern const IID IID_IMMDeviceEnumerator;
8
+
9
+ #endif