xref: /reactos/drivers/usb/usbaudio/usbaudio.h (revision c2c66aff)
1 #pragma once
2 
3 #include <ntddk.h>
4 #include <portcls.h>
5 #include <ksmedia.h>
6 #include <hubbusif.h>
7 #include <usbbusif.h>
8 #include <usbioctl.h>
9 #include <usb.h>
10 #include <usbdlib.h>
11 #include <debug.h>
12 
13 #define USBAUDIO_TAG 'AbsU'
14 #define USB_AUDIO_CONTROL_TERMINAL_DESCRIPTOR_TYPE (0x24)
15 
16 /* Universal Serial Bus Device Class Definition for Terminal Types Section 2.2 */
17 #define USB_AUDIO_STREAMING_TERMINAL_TYPE (0x0101)
18 
19 #define USB_AUDIO_MICROPHONE_TERMINAL_TYPE (0x0201)
20 #define USB_AUDIO_DESKTOP_MICROPHONE_TERMINAL_TYPE (0x0202)
21 #define USB_AUDIO_PERSONAL_MICROPHONE_TERMINAL_TYPE (0x0203)
22 #define USB_AUDIO_OMMNI_MICROPHONE_TERMINAL_TYPE (0x0204)
23 #define USB_AUDIO_ARRAY_MICROPHONE_TERMINAL_TYPE (0x0205)
24 #define USB_AUDIO_ARRAY_PROCESSING_MICROPHONE_TERMINAL_TYPE (0x0206)
25 
26 #define USB_AUDIO_SPEAKER_TERMINAL_TYPE (0x0301)
27 #define USB_HEADPHONES_SPEAKER_TERMINAL_TYPE (0x0302)
28 #define USB_AUDIO_HMDA_TERMINAL_TYPE (0x0303)
29 #define USB_AUDIO_DESKTOP_SPEAKER_TERMINAL_TYPE (0x0304)
30 #define USB_AUDIO_ROOM_SPEAKER_TERMINAL_TYPE (0x0305)
31 #define USB_AUDIO_COMMUNICATION_SPEAKER_TERMINAL_TYPE (0x0306)
32 #define USB_AUDIO_SUBWOOFER_TERMINAL_TYPE (0x0307)
33 #define USB_AUDIO_UNDEFINED_TERMINAL_TYPE (0xFFFF)
34 
35 #define USB_AUDIO_INPUT_TERMINAL (0x02)
36 #define USB_AUDIO_OUTPUT_TERMINAL (0x03)
37 
38 #define DEFINE_KSPROPERTY_ITEM_AUDIO_VOLUME(Handler)\
39     DEFINE_KSPROPERTY_ITEM(\
40         KSPROPERTY_AUDIO_VOLUMELEVEL,\
41         (Handler),\
42         sizeof(KSNODEPROPERTY_AUDIO_CHANNEL),\
43         sizeof(LONG),\
44         (Handler), NULL, 0, NULL, NULL, 0)
45 
46 
47 #define DEFINE_KSPROPERTY_TABLE_AUDIO_VOLUME(TopologySet, Handler)\
48 DEFINE_KSPROPERTY_TABLE(TopologySet) {\
49     DEFINE_KSPROPERTY_ITEM_AUDIO_VOLUME(Handler)\
50 }
51 
52 #define DEFINE_KSPROPERTY_ITEM_AUDIO_MUTE(Handler)\
53     DEFINE_KSPROPERTY_ITEM(\
54         KSPROPERTY_AUDIO_MUTE,\
55         (Handler),\
56         sizeof(KSNODEPROPERTY_AUDIO_CHANNEL),\
57         sizeof(BOOL),\
58         (Handler), NULL, 0, NULL, NULL, 0)
59 
60 #define DEFINE_KSPROPERTY_TABLE_AUDIO_MUTE(TopologySet, Handler)\
61 DEFINE_KSPROPERTY_TABLE(TopologySet) {\
62     DEFINE_KSPROPERTY_ITEM_AUDIO_MUTE(Handler)\
63 }
64 
65 #include <pshpack1.h>
66 
67 typedef struct
68 {
69     UCHAR bLength;
70     UCHAR bDescriptorType;
71     UCHAR bDescriptorSubtype;
72     USHORT bcdADC;
73     USHORT wTotalLength;
74     UCHAR bInCollection;
75     UCHAR baInterfaceNr;
76 }USB_AUDIO_CONTROL_INTERFACE_HEADER_DESCRIPTOR, *PUSB_AUDIO_CONTROL_INTERFACE_HEADER_DESCRIPTOR;
77 
78 typedef struct
79 {
80     UCHAR bLength;
81     UCHAR bDescriptorType;
82     UCHAR bDescriptorSubtype;
83     UCHAR bTerminalID;
84     USHORT wTerminalType;
85     UCHAR bAssocTerminal;
86     UCHAR bSourceID;
87     UCHAR iTerminal;
88 }USB_AUDIO_CONTROL_OUTPUT_TERMINAL_DESCRIPTOR, *PUSB_AUDIO_CONTROL_OUTPUT_TERMINAL_DESCRIPTOR;
89 
90 
91 typedef struct
92 {
93     UCHAR bLength;
94     UCHAR bDescriptorType;
95     UCHAR bDescriptorSubtype;
96     UCHAR bTerminalID;
97     USHORT wTerminalType;
98     UCHAR bAssocTerminal;
99     UCHAR bNrChannels;
100     USHORT wChannelConfig;
101     UCHAR iChannelNames;
102     UCHAR iTerminal;
103 }USB_AUDIO_CONTROL_INPUT_TERMINAL_DESCRIPTOR, *PUSB_AUDIO_CONTROL_INPUT_TERMINAL_DESCRIPTOR;
104 
105 typedef struct
106 {
107     UCHAR bLength;
108     UCHAR bDescriptorType;
109     UCHAR bDescriptorSubtype;
110     UCHAR bUnitID;
111     UCHAR bSourceID;
112     UCHAR bControlSize;
113     UCHAR bmaControls[1];
114     UCHAR iFeature;
115 }USB_AUDIO_CONTROL_FEATURE_UNIT_DESCRIPTOR, *PUSB_AUDIO_CONTROL_FEATURE_UNIT_DESCRIPTOR;
116 
117 typedef struct
118 {
119     UCHAR bLength;
120     UCHAR bDescriptorType;
121     UCHAR bDescriptorSubtype;
122     UCHAR bUnitID;
123     UCHAR bNrInPins;
124     UCHAR baSourceID[1];
125     UCHAR bNrChannels;
126     USHORT wChannelConfig;
127     UCHAR iChannelNames;
128     UCHAR bmControls;
129     UCHAR iMixer;
130 }USB_AUDIO_CONTROL_MIXER_UNIT_DESCRIPTOR, *PUSB_AUDIO_CONTROL_MIXER_UNIT_DESCRIPTOR;
131 
132 typedef struct
133 {
134     UCHAR bLength;
135     UCHAR bDescriptorType;
136     UCHAR bDescriptorSubtype;
137     UCHAR bUnitID;
138     UCHAR bNrInPins;
139     UCHAR baSourceID[1];
140     UCHAR iSelector;
141 }USB_AUDIO_CONTROL_SELECTOR_UNIT_DESCRIPTOR, *PUSB_AUDIO_CONTROL_SELECTOR_UNIT_DESCRIPTOR;
142 
143 
144 typedef struct
145 {
146     UCHAR bLength;
147     UCHAR bDescriptorType;
148     UCHAR bDescriptorSubtype;
149     UCHAR bTerminalLink;
150     UCHAR bDelay;
151     USHORT wFormatTag;
152 }USB_AUDIO_STREAMING_INTERFACE_DESCRIPTOR, *PUSB_AUDIO_STREAMING_INTERFACE_DESCRIPTOR;
153 
154 typedef struct
155 {
156     UCHAR bLength;
157     UCHAR bDescriptorType;
158     UCHAR bDescriptorSubtype;
159     UCHAR bFormatType;
160     UCHAR bNrChannels;
161     UCHAR bSubframeSize;
162     UCHAR bBitResolution;
163     UCHAR bSamFreqType;
164     UCHAR tSamFreq[1];
165 }USB_AUDIO_STREAMING_FORMAT_TYPE_DESCRIPTOR, *PUSB_AUDIO_STREAMING_FORMAT_TYPE_DESCRIPTOR;
166 
167 #include <poppack.h>
168 
169 typedef struct
170 {
171     PUSB_COMMON_DESCRIPTOR Descriptor;
172     ULONG NodeCount;
173     ULONG Nodes[20];
174 }NODE_CONTEXT, *PNODE_CONTEXT;
175 
176 typedef struct __DEVICE_EXTENSION__
177 {
178     PDEVICE_OBJECT LowerDevice;                                  /* lower device*/
179     PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;       /* usb configuration descriptor */
180     PUSB_DEVICE_DESCRIPTOR DeviceDescriptor;                     /* usb device descriptor */
181     PUSBD_INTERFACE_INFORMATION InterfaceInfo;                   /* interface information */
182     USBD_CONFIGURATION_HANDLE ConfigurationHandle;               /* configuration handle */
183     PNODE_CONTEXT NodeContext;                                   /* node context */
184     ULONG NodeContextCount;                                      /* node context count */
185 }DEVICE_EXTENSION, *PDEVICE_EXTENSION;
186 
187 typedef struct
188 {
189     PDEVICE_EXTENSION DeviceExtension;                           /* device extension */
190     PDEVICE_OBJECT LowerDevice;                                  /* lower device*/
191 
192 }FILTER_CONTEXT, *PFILTER_CONTEXT;
193 
194 typedef struct
195 {
196     PDEVICE_EXTENSION DeviceExtension;                           /* device extension */
197     PDEVICE_OBJECT LowerDevice;                                  /* lower device*/
198     LIST_ENTRY IrpListHead;                                      /* irp list*/
199     LIST_ENTRY DoneIrpListHead;                                  /* irp done list head */
200     KSPIN_LOCK IrpListLock;                                      /* irp list lock*/
201     PUCHAR Buffer;                                               /* iso buffer*/
202     ULONG BufferSize;                                            /* iso buffer size */
203     ULONG BufferOffset;                                          /* buffer offset */
204     ULONG BufferLength;                                          /* remaining render bytes */
205     PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor;               /* interface descriptor */
206     WORK_QUEUE_ITEM  CaptureWorkItem;                            /* work item */
207     PKSWORKER        CaptureWorker;                              /* capture worker */
208     WORK_QUEUE_ITEM  StarvationWorkItem;                            /* work item */
209     PKSWORKER        StarvationWorker;                              /* capture worker */
210 }PIN_CONTEXT, *PPIN_CONTEXT;
211 
212 /* filter.c */
213 
214 NTSTATUS
215 NTAPI
216 USBAudioCreateFilterContext(
217     PKSDEVICE Device);
218 
219 PUSB_AUDIO_CONTROL_INPUT_TERMINAL_DESCRIPTOR
220 UsbAudioGetStreamingTerminalDescriptorByIndex(
221     IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
222     IN ULONG Index);
223 
224 /* pool.c */
225 PVOID
226 NTAPI
227 AllocFunction(
228     IN ULONG ItemSize);
229 
230 VOID
231 NTAPI
232 FreeFunction(
233     IN PVOID Item);
234 
235 VOID
236 NTAPI
237 CountTerminalUnits(
238     IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
239     OUT PULONG NonStreamingTerminalDescriptorCount,
240     OUT PULONG TotalTerminalDescriptorCount);
241 
242 /* usbaudio.c */
243 
244 NTSTATUS
245 SubmitUrbSync(
246     IN PDEVICE_OBJECT Device,
247     IN PURB Urb);
248 
249 NTSTATUS
250 NTAPI
251 USBAudioAddDevice(
252   _In_ PKSDEVICE Device
253 );
254 
255 NTSTATUS
256 NTAPI
257 USBAudioPnPStart(
258   _In_     PKSDEVICE         Device,
259   _In_     PIRP              Irp,
260   _In_opt_ PCM_RESOURCE_LIST TranslatedResourceList,
261   _In_opt_ PCM_RESOURCE_LIST UntranslatedResourceList
262 );
263 
264 NTSTATUS
265 NTAPI
266 USBAudioPnPQueryStop(
267   _In_ PKSDEVICE Device,
268   _In_ PIRP      Irp
269 );
270 
271 VOID
272 NTAPI
273 USBAudioPnPCancelStop(
274   _In_ PKSDEVICE Device,
275   _In_ PIRP      Irp
276 );
277 
278 VOID
279 NTAPI
280 USBAudioPnPStop(
281   _In_ PKSDEVICE Device,
282   _In_ PIRP      Irp
283 );
284 
285 NTSTATUS
286 NTAPI
287 USBAudioPnPQueryRemove(
288   _In_ PKSDEVICE Device,
289   _In_ PIRP      Irp
290 );
291 
292 VOID
293 NTAPI
294 USBAudioPnPCancelRemove(
295   _In_ PKSDEVICE Device,
296   _In_ PIRP      Irp
297 );
298 
299 VOID
300 NTAPI
301 USBAudioPnPRemove(
302   _In_ PKSDEVICE Device,
303   _In_ PIRP      Irp
304 );
305 
306 NTSTATUS
307 NTAPI
308 USBAudioPnPQueryCapabilities(
309   _In_    PKSDEVICE            Device,
310   _In_    PIRP                 Irp,
311   _Inout_ PDEVICE_CAPABILITIES Capabilities
312 );
313 
314 VOID
315 NTAPI
316 USBAudioPnPSurpriseRemoval(
317   _In_ PKSDEVICE Device,
318   _In_ PIRP      Irp
319 );
320 
321 NTSTATUS
322 NTAPI
323 USBAudioPnPQueryPower(
324   _In_ PKSDEVICE          Device,
325   _In_ PIRP               Irp,
326   _In_ DEVICE_POWER_STATE DeviceTo,
327   _In_ DEVICE_POWER_STATE DeviceFrom,
328   _In_ SYSTEM_POWER_STATE SystemTo,
329   _In_ SYSTEM_POWER_STATE SystemFrom,
330   _In_ POWER_ACTION       Action
331 );
332 
333 VOID
334 NTAPI
335 USBAudioPnPSetPower(
336   _In_ PKSDEVICE          Device,
337   _In_ PIRP               Irp,
338   _In_ DEVICE_POWER_STATE To,
339   _In_ DEVICE_POWER_STATE From
340 );
341 
342 /* pin.c*/
343 
344 NTSTATUS
345 NTAPI
346 UsbAudioPinDataIntersect(
347     _In_  PVOID        Context,
348     _In_  PIRP         Irp,
349     _In_  PKSP_PIN     Pin,
350     _In_  PKSDATARANGE DataRange,
351     _In_  PKSDATARANGE MatchingDataRange,
352     _In_  ULONG        DataBufferSize,
353     _Out_ PVOID        Data,
354     _Out_ PULONG       DataSize);
355 
356 NTSTATUS
357 NTAPI
358 UsbAudioCaptureComplete(
359 	IN PDEVICE_OBJECT DeviceObject,
360 	IN PIRP Irp,
361 	IN PVOID Context);
362 
363 NTSTATUS
364 NTAPI
365 UsbAudioRenderComplete(
366 	IN PDEVICE_OBJECT DeviceObject,
367 	IN PIRP Irp,
368 	IN PVOID Context);
369 
370 NTSTATUS
371 NTAPI
372 USBAudioPinCreate(
373     _In_ PKSPIN Pin,
374     _In_ PIRP Irp);
375 
376 NTSTATUS
377 NTAPI
378 USBAudioPinClose(
379     _In_ PKSPIN Pin,
380     _In_ PIRP Irp);
381 
382 NTSTATUS
383 NTAPI
384 USBAudioPinProcess(
385     _In_ PKSPIN Pin);
386 
387 VOID
388 NTAPI
389 USBAudioPinReset(
390     _In_ PKSPIN Pin);
391 
392 NTSTATUS
393 NTAPI
394 USBAudioPinSetDataFormat(
395     _In_ PKSPIN Pin,
396     _In_opt_ PKSDATAFORMAT OldFormat,
397     _In_opt_ PKSMULTIPLE_ITEM OldAttributeList,
398     _In_ const KSDATARANGE* DataRange,
399     _In_opt_ const KSATTRIBUTE_LIST* AttributeRange);
400 
401 NTSTATUS
402 NTAPI
403 USBAudioPinSetDeviceState(
404     _In_ PKSPIN Pin,
405     _In_ KSSTATE ToState,
406     _In_ KSSTATE FromState);
407 
408