[USBAUDIO]
[reactos.git] / reactos / drivers / usb / usbaudio / filter.c
index d314f00..93ad768 100644 (file)
@@ -25,9 +25,7 @@ GUID NodeTypeSubwoofer = { STATIC_KSNODETYPE_LOW_FREQUENCY_EFFECTS_SPEAKER };
 GUID NodeTypeCapture = { STATIC_PINNAME_CAPTURE };
 GUID NodeTypePlayback = { STATIC_KSCATEGORY_AUDIO };
 GUID GUID_KSCATEGORY_AUDIO = { STATIC_KSCATEGORY_AUDIO };
-GUID GUID_KSDATAFORMAT_TYPE_AUDIO = { STATIC_KSDATAFORMAT_TYPE_AUDIO };
-GUID GUID_KSDATAFORMAT_SUBTYPE_PCM = { STATIC_KSDATAFORMAT_SUBTYPE_PCM };
-GUID GUID_KSDATAFORMAT_SPECIFIER_WAVEFORMATEX = { STATIC_KSDATAFORMAT_SPECIFIER_WAVEFORMATEX };
+
 KSPIN_INTERFACE StandardPinInterface =
 {
      {STATIC_KSINTERFACESETID_Standard},
@@ -78,6 +76,21 @@ static KSFILTER_DISPATCH USBAudioFilterDispatch =
     NULL
 };
 
+static KSPIN_DISPATCH UsbAudioPinDispatch =
+{
+    USBAudioPinCreate,
+    USBAudioPinClose,
+    USBAudioPinProcess,
+    USBAudioPinReset,
+    USBAudioPinSetDataFormat,
+    USBAudioPinSetDeviceState,
+    NULL,
+    NULL,
+    NULL,
+    NULL
+};
+
+
 NTSTATUS
 BuildUSBAudioFilterTopology(
     PKSDEVICE Device)
@@ -92,7 +105,39 @@ USBAudioFilterCreate(
     PKSFILTER Filter,
     PIRP Irp)
 {
-    UNIMPLEMENTED
+    PKSFILTERFACTORY FilterFactory;
+    PKSDEVICE Device;
+    PFILTER_CONTEXT FilterContext;
+
+    FilterFactory = KsGetParent(Filter);
+    if (FilterFactory == NULL)
+    {
+        /* invalid parameter */
+        return STATUS_INVALID_PARAMETER;
+    }
+
+    Device = KsGetParent(FilterFactory);
+    if (Device == NULL)
+    {
+        /* invalid parameter */
+        return STATUS_INVALID_PARAMETER;
+    }
+
+    /* alloc filter context */
+    FilterContext = AllocFunction(sizeof(FILTER_CONTEXT));
+    if (FilterContext == NULL)
+    {
+        /* no memory */
+        return STATUS_INSUFFICIENT_RESOURCES;
+    }
+
+    /* init context */
+    FilterContext->DeviceExtension = Device->Context;
+    FilterContext->LowerDevice = Device->NextDeviceObject;
+    Filter->Context = FilterContext;
+
+    DPRINT("USBAudioFilterCreate FilterContext %p LowerDevice %p DeviceExtension %p\n", FilterContext, FilterContext->LowerDevice, FilterContext->DeviceExtension);
+    KsAddItemToObjectBag(Filter->Bag, FilterContext, ExFreePool);
     return STATUS_SUCCESS;
 }
 
@@ -321,9 +366,9 @@ UsbAudioGetDataRanges(
                     }
 
                     DataRangeAudio->DataRange.FormatSize = sizeof(KSDATARANGE_AUDIO);
-                    DataRangeAudio->DataRange.MajorFormat = GUID_KSDATAFORMAT_TYPE_AUDIO;
-                    DataRangeAudio->DataRange.SubFormat = GUID_KSDATAFORMAT_SUBTYPE_PCM;
-                    DataRangeAudio->DataRange.Specifier = GUID_KSDATAFORMAT_SPECIFIER_WAVEFORMATEX;
+                    DataRangeAudio->DataRange.MajorFormat = KSDATAFORMAT_TYPE_AUDIO;
+                    DataRangeAudio->DataRange.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
+                    DataRangeAudio->DataRange.Specifier = KSDATAFORMAT_SPECIFIER_WAVEFORMATEX;
                     DataRangeAudio->MaximumChannels = 1;
                     DataRangeAudio->MinimumBitsPerSample = StreamingFormatDescriptor->bBitResolution;
                     DataRangeAudio->MaximumBitsPerSample = StreamingFormatDescriptor->bBitResolution;
@@ -382,6 +427,9 @@ USBAudioPinBuildDescriptors(
         {
             /* irp sink pins*/
             TerminalDescriptor = UsbAudioGetStreamingTerminalDescriptorByIndex(DeviceExtension->ConfigurationDescriptor, Index);
+            ASSERT(TerminalDescriptor != NULL);
+
+            Pins[Index].Dispatch = &UsbAudioPinDispatch;
             Pins[Index].PinDescriptor.InterfacesCount = 1;
             Pins[Index].PinDescriptor.Interfaces = &StandardPinInterface;
             Pins[Index].PinDescriptor.MediumsCount = 1;
@@ -400,8 +448,12 @@ USBAudioPinBuildDescriptors(
                 Pins[Index].PinDescriptor.DataFlow = KSPIN_DATAFLOW_IN;
             }
 
+
+            Pins[Index].Flags = KSPIN_FLAG_PROCESS_IN_RUN_STATE_ONLY | KSFILTER_FLAG_CRITICAL_PROCESSING;
+
             /* irp sinks / sources can be instantiated */
             Pins[Index].InstancesPossible = 1;
+            Pins[Index].InstancesNecessary = 1;
         }
         else
         {
@@ -459,20 +511,25 @@ NTAPI
 USBAudioCreateFilterContext(
     PKSDEVICE Device)
 {
-    KSFILTER_DESCRIPTOR FilterDescriptor;
+    PKSFILTER_DESCRIPTOR FilterDescriptor;
     PKSCOMPONENTID ComponentId;
     NTSTATUS Status;
 
-    /* clear filter descriptor */
-    RtlZeroMemory(&FilterDescriptor, sizeof(KSFILTER_DESCRIPTOR));
+    /* allocate descriptor */
+    FilterDescriptor = AllocFunction(sizeof(KSFILTER_DESCRIPTOR));
+    if (!FilterDescriptor)
+    {
+        /* no memory */
+        return USBD_STATUS_INSUFFICIENT_RESOURCES;
+    }
 
     /* init filter descriptor*/
-    FilterDescriptor.Version = KSFILTER_DESCRIPTOR_VERSION;
-    FilterDescriptor.Flags = 0;
-    FilterDescriptor.ReferenceGuid = &KSNAME_Filter;
-    FilterDescriptor.Dispatch = &USBAudioFilterDispatch;
-    FilterDescriptor.CategoriesCount = 1;
-    FilterDescriptor.Categories = &GUID_KSCATEGORY_AUDIO;
+    FilterDescriptor->Version = KSFILTER_DESCRIPTOR_VERSION;
+    FilterDescriptor->Flags = 0;
+    FilterDescriptor->ReferenceGuid = &KSNAME_Filter;
+    FilterDescriptor->Dispatch = &USBAudioFilterDispatch;
+    FilterDescriptor->CategoriesCount = 1;
+    FilterDescriptor->Categories = &GUID_KSCATEGORY_AUDIO;
 
     /* init component id*/
     ComponentId = AllocFunction(sizeof(KSCOMPONENTID));
@@ -488,10 +545,10 @@ USBAudioCreateFilterContext(
         //FreeFunction(ComponentId);
         //return Status;
     }
-    FilterDescriptor.ComponentId = ComponentId;
+    FilterDescriptor->ComponentId = ComponentId;
 
     /* build pin descriptors */
-    Status = USBAudioPinBuildDescriptors(Device, (PKSPIN_DESCRIPTOR_EX *)&FilterDescriptor.PinDescriptors, &FilterDescriptor.PinDescriptorsCount, &FilterDescriptor.PinDescriptorSize);
+    Status = USBAudioPinBuildDescriptors(Device, (PKSPIN_DESCRIPTOR_EX *)&FilterDescriptor->PinDescriptors, &FilterDescriptor->PinDescriptorsCount, &FilterDescriptor->PinDescriptorSize);
     if (!NT_SUCCESS(Status))
     {
         /* failed*/
@@ -499,7 +556,6 @@ USBAudioCreateFilterContext(
         return Status;
     }
 
-    DbgBreakPoint();
     /* build topology */
     Status = BuildUSBAudioFilterTopology(Device);
     if (!NT_SUCCESS(Status))
@@ -510,7 +566,7 @@ USBAudioCreateFilterContext(
     }
 
     /* lets create the filter */
-    Status = KsCreateFilterFactory(Device->FunctionalDeviceObject, &FilterDescriptor, ReferenceString, NULL, KSCREATE_ITEM_FREEONSTOP, NULL, NULL, NULL);
+    Status = KsCreateFilterFactory(Device->FunctionalDeviceObject, FilterDescriptor, ReferenceString, NULL, KSCREATE_ITEM_FREEONSTOP, NULL, NULL, NULL);
     DPRINT1("KsCreateFilterFactory: %x\n", Status);
 
     return Status;