[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 #include <pshpack1.h>
39
40 typedef struct
41 {
42 UCHAR bLength;
43 UCHAR bDescriptorType;
44 UCHAR bDescriptorSubtype;
45 USHORT bcdADC;
46 USHORT wTotalLength;
47 UCHAR bInCollection;
48 UCHAR baInterfaceNr;
49 }USB_AUDIO_CONTROL_INTERFACE_HEADER_DESCRIPTOR, *PUSB_AUDIO_CONTROL_INTERFACE_HEADER_DESCRIPTOR;
50
51 typedef struct
52 {
53 UCHAR bLength;
54 UCHAR bDescriptorType;
55 UCHAR bDescriptorSubtype;
56 UCHAR bTerminalID;
57 USHORT wTerminalType;
58 UCHAR bAssocTerminal;
59 UCHAR bSourceID;
60 UCHAR iTerminal;
61 }USB_AUDIO_CONTROL_OUTPUT_TERMINAL_DESCRIPTOR, *PUSB_AUDIO_CONTROL_OUTPUT_TERMINAL_DESCRIPTOR;
62
63
64 typedef struct
65 {
66 UCHAR bLength;
67 UCHAR bDescriptorType;
68 UCHAR bDescriptorSubtype;
69 UCHAR bTerminalID;
70 USHORT wTerminalType;
71 UCHAR bAssocTerminal;
72 UCHAR bNrChannels;
73 USHORT wChannelConfig;
74 UCHAR iChannelNames;
75 UCHAR iTerminal;
76 }USB_AUDIO_CONTROL_INPUT_TERMINAL_DESCRIPTOR, *PUSB_AUDIO_CONTROL_INPUT_TERMINAL_DESCRIPTOR;
77
78 typedef struct
79 {
80 UCHAR bLength;
81 UCHAR bDescriptorType;
82 UCHAR bDescriptorSubtype;
83 UCHAR bTerminalLink;
84 UCHAR bDelay;
85 USHORT wFormatTag;
86 }USB_AUDIO_STREAMING_INTERFACE_DESCRIPTOR, *PUSB_AUDIO_STREAMING_INTERFACE_DESCRIPTOR;
87
88 typedef struct
89 {
90 UCHAR bLength;
91 UCHAR bDescriptorType;
92 UCHAR bDescriptorSubtype;
93 UCHAR bFormatType;
94 UCHAR bNrChannels;
95 UCHAR bSubframeSize;
96 UCHAR bBitResolution;
97 UCHAR bSamFreqType;
98 UCHAR tSamFreq[1];
99 }USB_AUDIO_STREAMING_FORMAT_TYPE_DESCRIPTOR, *PUSB_AUDIO_STREAMING_FORMAT_TYPE_DESCRIPTOR;
100
101 #include <poppack.h>
102
103 typedef struct __DEVICE_EXTENSION__
104 {
105 PDEVICE_OBJECT LowerDevice; /* lower device*/
106 PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor; /* usb configuration descriptor */
107 PUSB_DEVICE_DESCRIPTOR DeviceDescriptor; /* usb device descriptor */
108 PUSBD_INTERFACE_INFORMATION InterfaceInfo; /* interface information */
109 USBD_CONFIGURATION_HANDLE ConfigurationHandle; /* configuration handle */
110
111 }DEVICE_EXTENSION, *PDEVICE_EXTENSION;
112
113 typedef struct
114 {
115 PDEVICE_EXTENSION DeviceExtension; /* device extension */
116 PDEVICE_OBJECT LowerDevice; /* lower device*/
117
118 }FILTER_CONTEXT, *PFILTER_CONTEXT;
119
120 typedef struct
121 {
122 PDEVICE_EXTENSION DeviceExtension; /* device extension */
123 PDEVICE_OBJECT LowerDevice; /* lower device*/
124 LIST_ENTRY IrpListHead; /* irp list*/
125 LIST_ENTRY DoneIrpListHead; /* irp done list head */
126 KSPIN_LOCK IrpListLock; /* irp list lock*/
127 PUCHAR Buffer; /* iso buffer*/
128 ULONG BufferSize; /* iso buffer size */
129 PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor; /* interface descriptor */
130 WORK_QUEUE_ITEM CaptureWorkItem; /* work item */
131 PKSWORKER CaptureWorker; /* capture worker */
132 WORK_QUEUE_ITEM StarvationWorkItem; /* work item */
133 PKSWORKER StarvationWorker; /* capture worker */
134 }PIN_CONTEXT, *PPIN_CONTEXT;
135
136 /* filter.c */
137
138 NTSTATUS
139 NTAPI
140 USBAudioCreateFilterContext(
141 PKSDEVICE Device);
142
143 /* pool.c */
144 PVOID
145 NTAPI
146 AllocFunction(
147 IN ULONG ItemSize);
148
149 VOID
150 NTAPI
151 FreeFunction(
152 IN PVOID Item);
153
154 /* usbaudio.c */
155
156 NTSTATUS
157 SubmitUrbSync(
158 IN PDEVICE_OBJECT Device,
159 IN PURB Urb);
160
161 NTSTATUS
162 NTAPI
163 USBAudioAddDevice(
164 _In_ PKSDEVICE Device
165 );
166
167 NTSTATUS
168 NTAPI
169 USBAudioPnPStart(
170 _In_ PKSDEVICE Device,
171 _In_ PIRP Irp,
172 _In_opt_ PCM_RESOURCE_LIST TranslatedResourceList,
173 _In_opt_ PCM_RESOURCE_LIST UntranslatedResourceList
174 );
175
176 NTSTATUS
177 NTAPI
178 USBAudioPnPQueryStop(
179 _In_ PKSDEVICE Device,
180 _In_ PIRP Irp
181 );
182
183 VOID
184 NTAPI
185 USBAudioPnPCancelStop(
186 _In_ PKSDEVICE Device,
187 _In_ PIRP Irp
188 );
189
190 VOID
191 NTAPI
192 USBAudioPnPStop(
193 _In_ PKSDEVICE Device,
194 _In_ PIRP Irp
195 );
196
197 NTSTATUS
198 NTAPI
199 USBAudioPnPQueryRemove(
200 _In_ PKSDEVICE Device,
201 _In_ PIRP Irp
202 );
203
204 VOID
205 NTAPI
206 USBAudioPnPCancelRemove(
207 _In_ PKSDEVICE Device,
208 _In_ PIRP Irp
209 );
210
211 VOID
212 NTAPI
213 USBAudioPnPRemove(
214 _In_ PKSDEVICE Device,
215 _In_ PIRP Irp
216 );
217
218 NTSTATUS
219 NTAPI
220 USBAudioPnPQueryCapabilities(
221 _In_ PKSDEVICE Device,
222 _In_ PIRP Irp,
223 _Inout_ PDEVICE_CAPABILITIES Capabilities
224 );
225
226 VOID
227 NTAPI
228 USBAudioPnPSurpriseRemoval(
229 _In_ PKSDEVICE Device,
230 _In_ PIRP Irp
231 );
232
233 NTSTATUS
234 NTAPI
235 USBAudioPnPQueryPower(
236 _In_ PKSDEVICE Device,
237 _In_ PIRP Irp,
238 _In_ DEVICE_POWER_STATE DeviceTo,
239 _In_ DEVICE_POWER_STATE DeviceFrom,
240 _In_ SYSTEM_POWER_STATE SystemTo,
241 _In_ SYSTEM_POWER_STATE SystemFrom,
242 _In_ POWER_ACTION Action
243 );
244
245 VOID
246 NTAPI
247 USBAudioPnPSetPower(
248 _In_ PKSDEVICE Device,
249 _In_ PIRP Irp,
250 _In_ DEVICE_POWER_STATE To,
251 _In_ DEVICE_POWER_STATE From
252 );
253
254 /* pin.c*/
255
256 NTSTATUS
257 NTAPI
258 UsbAudioCaptureComplete(
259 IN PDEVICE_OBJECT DeviceObject,
260 IN PIRP Irp,
261 IN PVOID Context);
262
263 NTSTATUS
264 NTAPI
265 USBAudioPinCreate(
266 _In_ PKSPIN Pin,
267 _In_ PIRP Irp);
268
269 NTSTATUS
270 NTAPI
271 USBAudioPinClose(
272 _In_ PKSPIN Pin,
273 _In_ PIRP Irp);
274
275 NTSTATUS
276 NTAPI
277 USBAudioPinProcess(
278 _In_ PKSPIN Pin);
279
280 VOID
281 NTAPI
282 USBAudioPinReset(
283 _In_ PKSPIN Pin);
284
285 NTSTATUS
286 NTAPI
287 USBAudioPinSetDataFormat(
288 _In_ PKSPIN Pin,
289 _In_opt_ PKSDATAFORMAT OldFormat,
290 _In_opt_ PKSMULTIPLE_ITEM OldAttributeList,
291 _In_ const KSDATARANGE* DataRange,
292 _In_opt_ const KSATTRIBUTE_LIST* AttributeRange);
293
294 NTSTATUS
295 NTAPI
296 USBAudioPinSetDeviceState(
297 _In_ PKSPIN Pin,
298 _In_ KSSTATE ToState,
299 _In_ KSSTATE FromState);
300