[KS]
[reactos.git] / reactos / drivers / ksfilter / ks / filter.c
index b18b763..7441e59 100644 (file)
@@ -6,8 +6,10 @@
  * PROGRAMMER:      Johannes Anderwald
  */
 
+#include "precomp.h"
 
-#include "priv.h"
+#define NDEBUG
+#include <debug.h>
 
 typedef struct
 {
@@ -43,6 +45,7 @@ const GUID IID_IKsControl = {0x28F54685L, 0x06FD, 0x11D2, {0xB2, 0x7A, 0x00, 0xA
 const GUID IID_IKsFilter  = {0x3ef6ee44L, 0x0D41, 0x11d2, {0xbe, 0xDA, 0x00, 0xc0, 0x4f, 0x8e, 0xF4, 0x57}};
 const GUID KSPROPSETID_Topology                = {0x720D4AC0L, 0x7533, 0x11D0, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}};
 const GUID KSPROPSETID_Pin                     = {0x8C134960L, 0x51AD, 0x11CF, {0x87, 0x8A, 0x94, 0xF8, 0x01, 0xC1, 0x00, 0x00}};
+const GUID KSPROPSETID_General =                 {0x1464EDA5L, 0x6A8F, 0x11D1, {0x9A, 0xA7, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}};
 
 VOID
 IKsFilter_RemoveFilterFromFilterFactory(
@@ -51,10 +54,11 @@ IKsFilter_RemoveFilterFromFilterFactory(
 
 NTSTATUS NTAPI FilterTopologyPropertyHandler(IN PIRP Irp, IN PKSIDENTIFIER  Request, IN OUT PVOID  Data);
 NTSTATUS NTAPI FilterPinPropertyHandler(IN PIRP Irp, IN PKSIDENTIFIER  Request, IN OUT PVOID  Data);
-
+NTSTATUS NTAPI FilterGeneralComponentIdHandler(IN PIRP Irp, IN PKSIDENTIFIER  Request, IN OUT PVOID  Data);
 
 DEFINE_KSPROPERTY_TOPOLOGYSET(IKsFilterTopologySet, FilterTopologyPropertyHandler);
 DEFINE_KSPROPERTY_PINPROPOSEDATAFORMAT(IKsFilterPinSet, FilterPinPropertyHandler, FilterPinPropertyHandler, FilterPinPropertyHandler);
+DEFINE_KSPROPERTY_GENEREAL_COMPONENTID(IKsFilterGeneralSet, FilterGeneralComponentIdHandler);
 
 KSPROPERTY_SET FilterPropertySet[] =
 {
@@ -71,6 +75,13 @@ KSPROPERTY_SET FilterPropertySet[] =
         (const KSPROPERTY_ITEM*)&IKsFilterPinSet,
         0,
         NULL
+    },
+    {
+        &KSPROPSETID_General,
+        sizeof(IKsFilterGeneralSet) / sizeof(KSPROPERTY_ITEM),
+        (const KSPROPERTY_ITEM*)&IKsFilterGeneralSet,
+        0,
+        NULL
     }
 };
 
@@ -877,7 +888,7 @@ KspHandleDataIntersection(
             break;
         }
 
-        DataRange =  UlongToPtr(PtrToUlong(DataRange) + DataRange->FormatSize);
+        DataRange = (PKSDATARANGE)((PUCHAR)DataRange + DataRange->FormatSize);
         /* FIXME make sure its 64 bit aligned */
         ASSERT(((ULONG_PTR)DataRange & 0x7) == 0);
     }
@@ -904,6 +915,39 @@ FilterTopologyPropertyHandler(
 
 }
 
+NTSTATUS
+NTAPI
+FilterGeneralComponentIdHandler(
+    IN PIRP Irp,
+    IN PKSIDENTIFIER  Request,
+    IN OUT PVOID  Data)
+{
+    PIO_STACK_LOCATION IoStack;
+    IKsFilterImpl * This;
+
+    /* get filter implementation */
+    This = (IKsFilterImpl*)KSPROPERTY_ITEM_IRP_STORAGE(Irp);
+
+    /* sanity check */
+    ASSERT(This);
+
+    /* get current stack location */
+    IoStack = IoGetCurrentIrpStackLocation(Irp);
+    ASSERT(IoStack->Parameters.DeviceIoControl.OutputBufferLength >= sizeof(KSCOMPONENTID));
+
+    if (This->Filter.Descriptor->ComponentId != NULL)
+    {
+        RtlMoveMemory(Data, This->Filter.Descriptor->ComponentId, sizeof(KSCOMPONENTID));
+        Irp->IoStatus.Information = sizeof(KSCOMPONENTID);
+        return STATUS_SUCCESS;
+    }
+    else
+    {
+        /* not valid */
+        return STATUS_NOT_FOUND;
+    }
+
+}
 
 NTSTATUS
 NTAPI
@@ -955,7 +999,7 @@ FilterPinPropertyHandler(
             UNIMPLEMENTED
             Status = STATUS_NOT_FOUND;
     }
-    //DPRINT("KspPinPropertyHandler Pins %lu Request->Id %lu Status %lx\n", This->PinDescriptorCount, Request->Id, Status);
+    DPRINT("KspPinPropertyHandler Pins %lu Request->Id %lu Status %lx\n", This->Filter.Descriptor->PinDescriptorsCount, Request->Id, Status);
 
 
     return Status;
@@ -975,6 +1019,7 @@ IKsFilter_DispatchDeviceIoControl(
     UNICODE_STRING GuidString;
     PKSPROPERTY Property;
     ULONG SetCount = 0;
+    //PKSP_NODE NodeProperty;
 
     /* obtain filter from object header */
     Status = IKsFilter_GetFilterFromIrp(Irp, &Filter);
@@ -1022,13 +1067,28 @@ IKsFilter_DispatchDeviceIoControl(
     {
         const KSPROPERTY_SET *PropertySet = NULL;
         ULONG PropertyItemSize = 0;
-
+#if 0
         /* check if the driver supports method sets */
+        if (Property->Flags & KSPROPERTY_TYPE_TOPOLOGY)
+        {
+            NodeProperty = (PKSP_NODE)Property;
+            if (FilterInstance->Descriptor->NodeDescriptors[NodeProperty->NodeId].AutomationTable != NULL)
+            {
+                SetCount = FilterInstance->Descriptor->NodeDescriptors[NodeProperty->NodeId].AutomationTable->PropertySetsCount;
+                PropertySet = FilterInstance->Descriptor->NodeDescriptors[NodeProperty->NodeId].AutomationTable->PropertySets;
+                PropertyItemSize = 0;
+            }
+                
+        } else 
+#endif
         if (FilterInstance->Descriptor->AutomationTable->PropertySetsCount)
         {
             SetCount = FilterInstance->Descriptor->AutomationTable->PropertySetsCount;
             PropertySet = FilterInstance->Descriptor->AutomationTable->PropertySets;
             PropertyItemSize = FilterInstance->Descriptor->AutomationTable->PropertyItemSize;
+            // FIXME: handle variable sized property items
+            ASSERT(PropertyItemSize == sizeof(KSPROPERTY_ITEM));
+            PropertyItemSize = 0;
         }
 
         /* needed for our property handlers */
@@ -1063,6 +1123,7 @@ IKsFilter_DispatchDeviceIoControl(
     }
 
     RtlStringFromGUID(&Property->Set, &GuidString);
+    DPRINT("IKsFilter_DispatchDeviceIoControl property PinCount %x\n", FilterInstance->Descriptor->PinDescriptorsCount);
     DPRINT("IKsFilter_DispatchDeviceIoControl property Set |%S| Id %u Flags %x Status %lx ResultLength %lu\n", GuidString.Buffer, Property->Id, Property->Flags, Status, Irp->IoStatus.Information);
     RtlFreeUnicodeString(&GuidString);
 
@@ -1104,6 +1165,7 @@ IKsFilter_CreateDescriptors(
 {
     ULONG Index = 0;
     NTSTATUS Status;
+    PKSNODE_DESCRIPTOR NodeDescriptor;
 
     /* initialize pin descriptors */
     This->FirstPin = NULL;
@@ -1190,8 +1252,8 @@ IKsFilter_CreateDescriptors(
         /* sanity check */
         ASSERT(FilterDescriptor->NodeDescriptors);
 
-        /* FIXME handle variable sized node descriptors */
-        ASSERT(FilterDescriptor->NodeDescriptorSize == sizeof(KSNODE_DESCRIPTOR));
+        /* sanity check */
+        ASSERT(FilterDescriptor->NodeDescriptorSize >= sizeof(KSNODE_DESCRIPTOR));
 
         This->Topology.TopologyNodes = AllocateItem(NonPagedPool, sizeof(GUID) * FilterDescriptor->NodeDescriptorsCount);
         /* allocate topology node types array */
@@ -1211,17 +1273,21 @@ IKsFilter_CreateDescriptors(
         }
 
         DPRINT("NodeDescriptorCount %lu\n", FilterDescriptor->NodeDescriptorsCount);
+        NodeDescriptor = (PKSNODE_DESCRIPTOR)FilterDescriptor->NodeDescriptors;
         for(Index = 0; Index < FilterDescriptor->NodeDescriptorsCount; Index++)
         {
-            DPRINT("Index %lu Type %p Name %p\n", Index, FilterDescriptor->NodeDescriptors[Index].Type, FilterDescriptor->NodeDescriptors[Index].Name);
+            DPRINT("Index %lu Type %p Name %p\n", Index, NodeDescriptor->Type, NodeDescriptor->Name);
 
             /* copy topology type */
-            if (FilterDescriptor->NodeDescriptors[Index].Type)
-                RtlMoveMemory((PVOID)&This->Topology.TopologyNodes[Index], FilterDescriptor->NodeDescriptors[Index].Type, sizeof(GUID));
+            if (NodeDescriptor->Type)
+                RtlMoveMemory((PVOID)&This->Topology.TopologyNodes[Index], NodeDescriptor->Type, sizeof(GUID));
 
             /* copy topology name */
-            if (FilterDescriptor->NodeDescriptors[Index].Name)
-                RtlMoveMemory((PVOID)&This->Topology.TopologyNodesNames[Index], FilterDescriptor->NodeDescriptors[Index].Name, sizeof(GUID));
+            if (NodeDescriptor->Name)
+                RtlMoveMemory((PVOID)&This->Topology.TopologyNodesNames[Index], NodeDescriptor->Name, sizeof(GUID));
+
+            // next node descriptor
+            NodeDescriptor = (PKSNODE_DESCRIPTOR)((ULONG_PTR)NodeDescriptor + FilterDescriptor->NodeDescriptorSize);
         }
     }
     /* done! */
@@ -1256,7 +1322,7 @@ IKsFilter_CopyFilterDescriptor(
 
     /* setup filter property sets */
     AutomationTable.PropertyItemSize = sizeof(KSPROPERTY_ITEM);
-    AutomationTable.PropertySetsCount = 2;
+    AutomationTable.PropertySetsCount = 3;
     AutomationTable.PropertySets = FilterPropertySet;
 
     /* merge filter automation table */