[USBAUDIO]
[reactos.git] / reactos / drivers / usb / usbaudio / usbaudio.h
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
133 typedef struct
134 {
135 UCHAR bLength;
136 UCHAR bDescriptorType;
137 UCHAR bDescriptorSubtype;
138 UCHAR bTerminalLink;
139 UCHAR bDelay;
140 USHORT wFormatTag;
141 }USB_AUDIO_STREAMING_INTERFACE_DESCRIPTOR, *PUSB_AUDIO_STREAMING_INTERFACE_DESCRIPTOR;
142
143 typedef struct
144 {
145 UCHAR bLength;
146 UCHAR bDescriptorType;
147 UCHAR bDescriptorSubtype;
148 UCHAR bFormatType;
149 UCHAR bNrChannels;
150 UCHAR bSubframeSize;
151 UCHAR bBitResolution;
152 UCHAR bSamFreqType;
153 UCHAR tSamFreq[1];
154 }USB_AUDIO_STREAMING_FORMAT_TYPE_DESCRIPTOR, *PUSB_AUDIO_STREAMING_FORMAT_TYPE_DESCRIPTOR;
155
156 #include <poppack.h>
157
158 typedef struct
159 {
160 PUSB_COMMON_DESCRIPTOR Descriptor;
161 ULONG NodeCount;
162 ULONG Nodes[20];
163 }NODE_CONTEXT, *PNODE_CONTEXT;
164
165 typedef struct __DEVICE_EXTENSION__
166 {
167 PDEVICE_OBJECT LowerDevice; /* lower device*/
168 PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor; /* usb configuration descriptor */
169 PUSB_DEVICE_DESCRIPTOR DeviceDescriptor; /* usb device descriptor */
170 PUSBD_INTERFACE_INFORMATION InterfaceInfo; /* interface information */
171 USBD_CONFIGURATION_HANDLE ConfigurationHandle; /* configuration handle */
172 PNODE_CONTEXT NodeContext; /* node context */
173 ULONG NodeContextCount; /* node context count */
174 }DEVICE_EXTENSION, *PDEVICE_EXTENSION;
175
176 typedef struct
177 {
178 PDEVICE_EXTENSION DeviceExtension; /* device extension */
179 PDEVICE_OBJECT LowerDevice; /* lower device*/
180
181 }FILTER_CONTEXT, *PFILTER_CONTEXT;
182
183 typedef struct
184 {
185 PDEVICE_EXTENSION DeviceExtension; /* device extension */
186 PDEVICE_OBJECT LowerDevice; /* lower device*/
187 LIST_ENTRY IrpListHead; /* irp list*/
188 LIST_ENTRY DoneIrpListHead; /* irp done list head */
189 KSPIN_LOCK IrpListLock; /* irp list lock*/
190 PUCHAR Buffer; /* iso buffer*/
191 ULONG BufferSize; /* iso buffer size */
192 PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor; /* interface descriptor */
193 WORK_QUEUE_ITEM CaptureWorkItem; /* work item */
194 PKSWORKER CaptureWorker; /* capture worker */
195 WORK_QUEUE_ITEM StarvationWorkItem; /* work item */
196 PKSWORKER StarvationWorker; /* capture worker */
197 }PIN_CONTEXT, *PPIN_CONTEXT;
198
199 /* filter.c */
200
201 NTSTATUS
202 NTAPI
203 USBAudioCreateFilterContext(
204 PKSDEVICE Device);
205
206 /* pool.c */
207 PVOID
208 NTAPI
209 AllocFunction(
210 IN ULONG ItemSize);
211
212 VOID
213 NTAPI
214 FreeFunction(
215 IN PVOID Item);
216
217 VOID
218 NTAPI
219 CountTerminalUnits(
220 IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
221 OUT PULONG NonStreamingTerminalDescriptorCount,
222 OUT PULONG TotalTerminalDescriptorCount);
223
224 /* usbaudio.c */
225
226 NTSTATUS
227 SubmitUrbSync(
228 IN PDEVICE_OBJECT Device,
229 IN PURB Urb);
230
231 NTSTATUS
232 NTAPI
233 USBAudioAddDevice(
234 _In_ PKSDEVICE Device
235 );
236
237 NTSTATUS
238 NTAPI
239 USBAudioPnPStart(
240 _In_ PKSDEVICE Device,
241 _In_ PIRP Irp,
242 _In_opt_ PCM_RESOURCE_LIST TranslatedResourceList,
243 _In_opt_ PCM_RESOURCE_LIST UntranslatedResourceList
244 );
245
246 NTSTATUS
247 NTAPI
248 USBAudioPnPQueryStop(
249 _In_ PKSDEVICE Device,
250 _In_ PIRP Irp
251 );
252
253 VOID
254 NTAPI
255 USBAudioPnPCancelStop(
256 _In_ PKSDEVICE Device,
257 _In_ PIRP Irp
258 );
259
260 VOID
261 NTAPI
262 USBAudioPnPStop(
263 _In_ PKSDEVICE Device,
264 _In_ PIRP Irp
265 );
266
267 NTSTATUS
268 NTAPI
269 USBAudioPnPQueryRemove(
270 _In_ PKSDEVICE Device,
271 _In_ PIRP Irp
272 );
273
274 VOID
275 NTAPI
276 USBAudioPnPCancelRemove(
277 _In_ PKSDEVICE Device,
278 _In_ PIRP Irp
279 );
280
281 VOID
282 NTAPI
283 USBAudioPnPRemove(
284 _In_ PKSDEVICE Device,
285 _In_ PIRP Irp
286 );
287
288 NTSTATUS
289 NTAPI
290 USBAudioPnPQueryCapabilities(
291 _In_ PKSDEVICE Device,
292 _In_ PIRP Irp,
293 _Inout_ PDEVICE_CAPABILITIES Capabilities
294 );
295
296 VOID
297 NTAPI
298 USBAudioPnPSurpriseRemoval(
299 _In_ PKSDEVICE Device,
300 _In_ PIRP Irp
301 );
302
303 NTSTATUS
304 NTAPI
305 USBAudioPnPQueryPower(
306 _In_ PKSDEVICE Device,
307 _In_ PIRP Irp,
308 _In_ DEVICE_POWER_STATE DeviceTo,
309 _In_ DEVICE_POWER_STATE DeviceFrom,
310 _In_ SYSTEM_POWER_STATE SystemTo,
311 _In_ SYSTEM_POWER_STATE SystemFrom,
312 _In_ POWER_ACTION Action
313 );
314
315 VOID
316 NTAPI
317 USBAudioPnPSetPower(
318 _In_ PKSDEVICE Device,
319 _In_ PIRP Irp,
320 _In_ DEVICE_POWER_STATE To,
321 _In_ DEVICE_POWER_STATE From
322 );
323
324 /* pin.c*/
325
326 NTSTATUS
327 NTAPI
328 UsbAudioPinDataIntersect(
329 _In_ PVOID Context,
330 _In_ PIRP Irp,
331 _In_ PKSP_PIN Pin,
332 _In_ PKSDATARANGE DataRange,
333 _In_ PKSDATARANGE MatchingDataRange,
334 _In_ ULONG DataBufferSize,
335 _Out_ PVOID Data,
336 _Out_ PULONG DataSize);
337
338 NTSTATUS
339 NTAPI
340 UsbAudioCaptureComplete(
341 IN PDEVICE_OBJECT DeviceObject,
342 IN PIRP Irp,
343 IN PVOID Context);
344
345 NTSTATUS
346 NTAPI
347 USBAudioPinCreate(
348 _In_ PKSPIN Pin,
349 _In_ PIRP Irp);
350
351 NTSTATUS
352 NTAPI
353 USBAudioPinClose(
354 _In_ PKSPIN Pin,
355 _In_ PIRP Irp);
356
357 NTSTATUS
358 NTAPI
359 USBAudioPinProcess(
360 _In_ PKSPIN Pin);
361
362 VOID
363 NTAPI
364 USBAudioPinReset(
365 _In_ PKSPIN Pin);
366
367 NTSTATUS
368 NTAPI
369 USBAudioPinSetDataFormat(
370 _In_ PKSPIN Pin,
371 _In_opt_ PKSDATAFORMAT OldFormat,
372 _In_opt_ PKSMULTIPLE_ITEM OldAttributeList,
373 _In_ const KSDATARANGE* DataRange,
374 _In_opt_ const KSATTRIBUTE_LIST* AttributeRange);
375
376 NTSTATUS
377 NTAPI
378 USBAudioPinSetDeviceState(
379 _In_ PKSPIN Pin,
380 _In_ KSSTATE ToState,
381 _In_ KSSTATE FromState);
382