[USBAUDIO]
[reactos.git] / reactos / drivers / usb / usbaudio / filter.c
1 /*
2 * PROJECT: ReactOS Universal Audio Class Driver
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/usb/usbaudio/filter.c
5 * PURPOSE: USB Audio device driver.
6 * PROGRAMMERS:
7 * Johannes Anderwald (johannes.anderwald@reactos.org)
8 */
9
10 #include "usbaudio.h"
11
12 NTSTATUS
13 BuildUSBAudioFilterTopology(
14 PKSDEVICE Device)
15 {
16 UNIMPLEMENTED
17 return STATUS_NOT_IMPLEMENTED;
18 }
19
20 VOID
21 CountTerminalUnits(
22 IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
23 OUT PULONG NonStreamingTerminalDescriptorCount,
24 OUT PULONG TotalTerminalDescriptorCount)
25 {
26 PUSB_INTERFACE_DESCRIPTOR Descriptor;
27 PUSB_AUDIO_CONTROL_INTERFACE_HEADER_DESCRIPTOR InterfaceHeaderDescriptor;
28 PUSB_COMMON_DESCRIPTOR CommonDescriptor;
29 PUSB_AUDIO_CONTROL_INPUT_TERMINAL_DESCRIPTOR InputTerminalDescriptor;
30 ULONG NonStreamingTerminalCount = 0;
31 ULONG TotalTerminalCount = 0;
32
33 for(Descriptor = USBD_ParseConfigurationDescriptorEx(ConfigurationDescriptor, ConfigurationDescriptor, -1, -1, USB_DEVICE_CLASS_AUDIO, -1, -1);
34 Descriptor != NULL;
35 Descriptor = USBD_ParseConfigurationDescriptorEx(ConfigurationDescriptor, (PVOID)((ULONG_PTR)Descriptor + Descriptor->bLength), -1, -1, USB_DEVICE_CLASS_AUDIO, -1, -1))
36 {
37 if (Descriptor->bInterfaceSubClass == 0x01) /* AUDIO_CONTROL */
38 {
39 InterfaceHeaderDescriptor = USBD_ParseDescriptors(ConfigurationDescriptor, ConfigurationDescriptor->wTotalLength, Descriptor, USB_AUDIO_CONTROL_TERMINAL_DESCRIPTOR_TYPE);
40 if (InterfaceHeaderDescriptor != NULL)
41 {
42 CommonDescriptor = USBD_ParseDescriptors(InterfaceHeaderDescriptor, InterfaceHeaderDescriptor->wTotalLength, (PVOID)((ULONG_PTR)InterfaceHeaderDescriptor + InterfaceHeaderDescriptor->bLength), USB_AUDIO_CONTROL_TERMINAL_DESCRIPTOR_TYPE);
43 while (CommonDescriptor)
44 {
45 InputTerminalDescriptor = (PUSB_AUDIO_CONTROL_INPUT_TERMINAL_DESCRIPTOR)CommonDescriptor;
46 if (InputTerminalDescriptor->bDescriptorSubtype == 0x02 /* INPUT TERMINAL*/ || InputTerminalDescriptor->bDescriptorSubtype == 0x03 /* OUTPUT_TERMINAL*/)
47 {
48 if (InputTerminalDescriptor->wTerminalType != USB_AUDIO_STREAMING_TERMINAL_TYPE)
49 {
50 NonStreamingTerminalCount++;
51 }
52 TotalTerminalCount++;
53 }
54 }
55 }
56 }
57 else if (Descriptor->bInterfaceSubClass == 0x03) /* MIDI_STREAMING */
58 {
59 UNIMPLEMENTED
60 }
61 }
62 *NonStreamingTerminalDescriptorCount = NonStreamingTerminalCount;
63 *TotalTerminalDescriptorCount = TotalTerminalCount;
64
65 }
66
67 NTSTATUS
68 USBAudioPinBuildDescriptors(
69 PKSDEVICE Device,
70 PKSPIN_DESCRIPTOR_EX *PinDescriptors,
71 PULONG PinDescriptorsCount,
72 PULONG PinDescriptorSize)
73 {
74 UNIMPLEMENTED
75 return STATUS_NOT_IMPLEMENTED;
76 }
77
78 NTSTATUS
79 USBAudioInitComponentId(
80 PKSDEVICE Device,
81 IN PKSCOMPONENTID ComponentId)
82 {
83 PDEVICE_EXTENSION DeviceExtension;
84
85 /* get device extension */
86 DeviceExtension = Device->Context;
87
88 INIT_USBAUDIO_MID(&ComponentId->Manufacturer, DeviceExtension->DeviceDescriptor->idVendor);
89 INIT_USBAUDIO_PID(&ComponentId->Product, DeviceExtension->DeviceDescriptor->idProduct);
90
91 UNIMPLEMENTED
92 return STATUS_NOT_IMPLEMENTED;
93 }
94
95
96 NTSTATUS
97 NTAPI
98 USBAudioCreateFilterContext(
99 PKSDEVICE Device)
100 {
101 KSFILTER_DESCRIPTOR FilterDescriptor;
102 PKSCOMPONENTID ComponentId;
103 NTSTATUS Status;
104
105 /* clear filter descriptor */
106 RtlZeroMemory(&FilterDescriptor, sizeof(KSFILTER_DESCRIPTOR));
107
108 /* init filter descriptor*/
109 FilterDescriptor.Version = KSFILTER_DESCRIPTOR_VERSION;
110 FilterDescriptor.ReferenceGuid = &KSNAME_Filter;
111
112 /* init component id*/
113 ComponentId = AllocFunction(sizeof(KSCOMPONENTID));
114 if (!ComponentId)
115 {
116 /* no memory */
117 return STATUS_INSUFFICIENT_RESOURCES;
118 }
119 Status = USBAudioInitComponentId(Device, ComponentId);
120 if (!NT_SUCCESS(Status))
121 {
122 /* failed*/
123 //FreeFunction(ComponentId);
124 //return Status;
125 }
126 FilterDescriptor.ComponentId = ComponentId;
127
128 /* build pin descriptors */
129 Status = USBAudioPinBuildDescriptors(Device, (PKSPIN_DESCRIPTOR_EX *)&FilterDescriptor.PinDescriptors, &FilterDescriptor.PinDescriptorsCount, &FilterDescriptor.PinDescriptorSize);
130 if (!NT_SUCCESS(Status))
131 {
132 /* failed*/
133 FreeFunction(ComponentId);
134 return Status;
135 }
136
137 /* build topology */
138 Status = BuildUSBAudioFilterTopology(Device);
139 if (!NT_SUCCESS(Status))
140 {
141 /* failed*/
142 FreeFunction(ComponentId);
143 return Status;
144 }
145
146 return Status;
147 }
148
149