[USBAUDIO]
authorJohannes Anderwald <johannes.anderwald@reactos.org>
Mon, 19 Sep 2016 18:40:44 +0000 (18:40 +0000)
committerJohannes Anderwald <johannes.anderwald@reactos.org>
Mon, 19 Sep 2016 18:40:44 +0000 (18:40 +0000)
- fix minor bugs
- start implementing filter context

svn path=/trunk/; revision=72744

reactos/drivers/usb/usbaudio/filter.c
reactos/drivers/usb/usbaudio/usbaudio.c
reactos/drivers/usb/usbaudio/usbaudio.h

index 1c932d1..2ff6593 100644 (file)
@@ -17,6 +17,53 @@ BuildUSBAudioFilterTopology(
     return STATUS_NOT_IMPLEMENTED;
 }
 
+VOID
+CountTerminalUnits(
+    IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
+    OUT PULONG NonStreamingTerminalDescriptorCount,
+    OUT PULONG TotalTerminalDescriptorCount)
+{
+    PUSB_INTERFACE_DESCRIPTOR Descriptor;
+    PUSB_AUDIO_CONTROL_INTERFACE_HEADER_DESCRIPTOR InterfaceHeaderDescriptor;
+    PUSB_COMMON_DESCRIPTOR CommonDescriptor;
+    PUSB_AUDIO_CONTROL_INPUT_TERMINAL_DESCRIPTOR InputTerminalDescriptor;
+    ULONG NonStreamingTerminalCount = 0;
+    ULONG TotalTerminalCount = 0;
+
+    for(Descriptor = USBD_ParseConfigurationDescriptorEx(ConfigurationDescriptor, ConfigurationDescriptor, -1, -1, USB_DEVICE_CLASS_AUDIO, -1, -1);
+        Descriptor != NULL;
+        Descriptor = USBD_ParseConfigurationDescriptorEx(ConfigurationDescriptor, (PVOID)((ULONG_PTR)Descriptor + Descriptor->bLength), -1, -1, USB_DEVICE_CLASS_AUDIO, -1, -1))
+    {
+        if (Descriptor->bInterfaceSubClass == 0x01) /* AUDIO_CONTROL */
+        {
+            InterfaceHeaderDescriptor = USBD_ParseDescriptors(ConfigurationDescriptor, ConfigurationDescriptor->wTotalLength, Descriptor, USB_AUDIO_CONTROL_TERMINAL_DESCRIPTOR_TYPE);
+            if (InterfaceHeaderDescriptor != NULL)
+            {
+                CommonDescriptor = USBD_ParseDescriptors(InterfaceHeaderDescriptor, InterfaceHeaderDescriptor->wTotalLength, (PVOID)((ULONG_PTR)InterfaceHeaderDescriptor + InterfaceHeaderDescriptor->bLength), USB_AUDIO_CONTROL_TERMINAL_DESCRIPTOR_TYPE);
+                while (CommonDescriptor)
+                {
+                    InputTerminalDescriptor = (PUSB_AUDIO_CONTROL_INPUT_TERMINAL_DESCRIPTOR)CommonDescriptor;
+                    if (InputTerminalDescriptor->bDescriptorSubtype == 0x02 /* INPUT TERMINAL*/ || InputTerminalDescriptor->bDescriptorSubtype == 0x03 /* OUTPUT_TERMINAL*/)
+                    {
+                        if (InputTerminalDescriptor->wTerminalType != USB_AUDIO_STREAMING_TERMINAL_TYPE)
+                        {
+                            NonStreamingTerminalCount++;
+                        }
+                        TotalTerminalCount++;
+                    }
+                }
+            }
+        }
+        else if (Descriptor->bInterfaceSubClass == 0x03) /* MIDI_STREAMING */
+        {
+            UNIMPLEMENTED
+        }
+    }
+    *NonStreamingTerminalDescriptorCount = NonStreamingTerminalCount;
+    *TotalTerminalDescriptorCount = TotalTerminalCount;
+
+}
+
 NTSTATUS
 USBAudioPinBuildDescriptors(
     PKSDEVICE Device,
@@ -41,6 +88,7 @@ USBAudioInitComponentId(
     INIT_USBAUDIO_MID(&ComponentId->Manufacturer, DeviceExtension->DeviceDescriptor->idVendor);
     INIT_USBAUDIO_PID(&ComponentId->Product, DeviceExtension->DeviceDescriptor->idProduct);
 
+    UNIMPLEMENTED
     return STATUS_NOT_IMPLEMENTED;
 }
 
@@ -66,14 +114,14 @@ USBAudioCreateFilterContext(
     if (!ComponentId)
     {
         /* no memory */
-        return USBD_STATUS_INSUFFICIENT_RESOURCES;
+        return STATUS_INSUFFICIENT_RESOURCES;
     }
     Status = USBAudioInitComponentId(Device, ComponentId);
     if (!NT_SUCCESS(Status))
     {
         /* failed*/
-        FreeFunction(ComponentId);
-        return Status;
+        //FreeFunction(ComponentId);
+        //return Status;
     }
     FilterDescriptor.ComponentId = ComponentId;
 
index 5569ae1..3d0b9c3 100644 (file)
@@ -246,7 +246,7 @@ USBAudioStartDevice(
     }
 
     /* build descriptor request */
-    UsbBuildGetDescriptorRequest(Urb, sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST), USB_DEVICE_DESCRIPTOR_TYPE, 0, 0, ConfigurationDescriptor, NULL, sizeof(USB_CONFIGURATION_DESCRIPTOR), NULL);
+    UsbBuildGetDescriptorRequest(Urb, sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST), USB_CONFIGURATION_DESCRIPTOR_TYPE, 0, 0, ConfigurationDescriptor, NULL, sizeof(USB_CONFIGURATION_DESCRIPTOR), NULL);
 
     /* submit urb */
     Status = SubmitUrbSync(Device, Urb);
@@ -276,7 +276,7 @@ USBAudioStartDevice(
     }
 
     /* build descriptor request */
-    UsbBuildGetDescriptorRequest(Urb, sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST), USB_DEVICE_DESCRIPTOR_TYPE, 0, 0, ConfigurationDescriptor, NULL, Length, NULL);
+    UsbBuildGetDescriptorRequest(Urb, sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST), USB_CONFIGURATION_DESCRIPTOR_TYPE, 0, 0, ConfigurationDescriptor, NULL, Length, NULL);
 
     /* submit urb */
     Status = SubmitUrbSync(Device, Urb);
@@ -349,7 +349,7 @@ USBAudioPnPStart(
         if (NT_SUCCESS(Status))
         {
             /* TODO build filter topology and pin descriptors and retrieve interface */
-            UNIMPLEMENTED
+            Status = USBAudioCreateFilterContext(Device);
         }
     }
 
index fd74365..33b911c 100644 (file)
 #include <debug.h>
 
 #define USBAUDIO_TAG 'AbsU'
+#define USB_AUDIO_CONTROL_TERMINAL_DESCRIPTOR_TYPE (0x24)
+
+/* Universal Serial Bus Device Class Definition for Terminal Types Section 2.2 */
+#define USB_AUDIO_STREAMING_TERMINAL_TYPE (0x0101)
+
+#define USB_AUDIO_MICROPHONE_TERMINAL_TYPE (0x0201)
+#define USB_AUDIO_DESKTOP_MICROPHONE_TERMINAL_TYPE (0x0202)
+#define USB_AUDIO_PERSONAL_MICROPHONE_TERMINAL_TYPE (0x0203)
+#define USB_AUDIO_OMMNI_MICROPHONE_TERMINAL_TYPE (0x0204)
+#define USB_AUDIO_ARRAY_MICROPHONE_TERMINAL_TYPE (0x0205)
+#define USB_AUDIO_ARRAY_PROCESSING_MICROPHONE_TERMINAL_TYPE (0x0206)
+
+#define USB_AUDIO_SPEAKER_TERMINAL_TYPE (0x0301)
+#define USB_HEADPHONES_SPEAKER_TERMINAL_TYPE (0x0302)
+#define USB_AUDIO_HMDA_TERMINAL_TYPE (0x0303)
+#define USB_AUDIO_DESKTOP_SPEAKER_TERMINAL_TYPE (0x0304)
+#define USB_AUDIO_ROOM_SPEAKER_TERMINAL_TYPE (0x0305)
+#define USB_AUDIO_COMMUNICATION_SPEAKER_TERMINAL_TYPE (0x0306)
+#define USB_AUDIO_SUBWOOFER_TERMINAL_TYPE (0x0307)
+#define USB_AUDIO_UNDEFINED_TERMINAL_TYPE (0xFFFF)
+
+
+#include <pshpack1.h>
+
+typedef struct
+{
+    UCHAR bLength;
+    UCHAR bDescriptorType;
+    UCHAR bDescriptorSubtype;
+    USHORT bcdADC;
+    USHORT wTotalLength;
+    UCHAR bInCollection;
+    UCHAR baInterfaceNr;
+}USB_AUDIO_CONTROL_INTERFACE_HEADER_DESCRIPTOR, *PUSB_AUDIO_CONTROL_INTERFACE_HEADER_DESCRIPTOR;
+
+typedef struct
+{
+    UCHAR bLength;
+    UCHAR bDescriptorType;
+    UCHAR bDescriptorSubtype;
+    UCHAR bTerminalID;
+    USHORT wTerminalType;
+    UCHAR bAssocTerminal;
+    UCHAR bSourceID;
+    UCHAR iTerminal;
+}USB_AUDIO_CONTROL_OUTPUT_TERMINAL_DESCRIPTOR, *PUSB_AUDIO_CONTROL_OUTPUT_TERMINAL_DESCRIPTOR;
+
+
+typedef struct
+{
+    UCHAR bLength;
+    UCHAR bDescriptorType;
+    UCHAR bDescriptorSubtype;
+    UCHAR bTerminalID;
+    USHORT wTerminalType;
+    UCHAR bAssocTerminal;
+    UCHAR bNrChannels;
+    USHORT wChannelConfig;
+    UCHAR iChannelNames;
+    UCHAR iTerminal;
+}USB_AUDIO_CONTROL_INPUT_TERMINAL_DESCRIPTOR, *PUSB_AUDIO_CONTROL_INPUT_TERMINAL_DESCRIPTOR;
+#include <poppack.h>
 
 typedef struct __DEVICE_EXTENSION__
 {
@@ -22,6 +84,13 @@ typedef struct __DEVICE_EXTENSION__
 
 }DEVICE_EXTENSION, *PDEVICE_EXTENSION;
 
+/* filter.c */
+
+NTSTATUS
+NTAPI
+USBAudioCreateFilterContext(
+    PKSDEVICE Device);
+
 /* pool.c */
 PVOID
 NTAPI