Author: janderwald Date: Sun Mar 4 04:44:48 2012 New Revision: 55989
URL: http://svn.reactos.org/svn/reactos?rev=55989&view=rev Log: [KS] - Fix property item merge in KsMergeAutomationTable
Modified: trunk/reactos/drivers/ksfilter/ks/api.c trunk/reactos/drivers/ksfilter/ks/filter.c
Modified: trunk/reactos/drivers/ksfilter/ks/api.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/ksfilter/ks/api.c?r... ============================================================================== --- trunk/reactos/drivers/ksfilter/ks/api.c [iso-8859-1] (original) +++ trunk/reactos/drivers/ksfilter/ks/api.c [iso-8859-1] Sun Mar 4 04:44:48 2012 @@ -2087,15 +2087,100 @@ return STATUS_SUCCESS; }
+VOID +KspAddPropertyItem( + OUT PKSPROPERTY_SET OutPropertySet, + IN PKSPROPERTY_ITEM PropertyItem, + IN ULONG PropertyItemSize) +{ + PKSPROPERTY_ITEM CurrentPropertyItem; + ULONG Index; + + // check if the property item is already present + CurrentPropertyItem = (PKSPROPERTY_ITEM)OutPropertySet->PropertyItem; + for(Index = 0; Index < OutPropertySet->PropertiesCount; Index++) + { + if (CurrentPropertyItem->PropertyId == PropertyItem->PropertyId) + { + // item already present + return; + } + + // next item + CurrentPropertyItem = (PKSPROPERTY_ITEM)((ULONG_PTR)CurrentPropertyItem + PropertyItemSize); + } + // add item + RtlCopyMemory(CurrentPropertyItem, PropertyItem, PropertyItemSize); + OutPropertySet->PropertiesCount++; +} + +NTSTATUS +KspMergePropertySet( + OUT PKSAUTOMATION_TABLE Table, + OUT PKSPROPERTY_SET OutPropertySet, + IN PKSPROPERTY_SET PropertySetA, + IN PKSPROPERTY_SET PropertySetB, + IN KSOBJECT_BAG Bag OPTIONAL) +{ + ULONG PropertyCount, Index; + PKSPROPERTY_ITEM PropertyItem, CurrentPropertyItem; + NTSTATUS Status; + + // max properties + PropertyCount = PropertySetA->PropertiesCount + PropertySetB->PropertiesCount; + + // allocate items + PropertyItem = AllocateItem(NonPagedPool, Table->PropertyItemSize * PropertyCount); + if (!PropertyItem) + return STATUS_INSUFFICIENT_RESOURCES; + + if (Bag) + { + /* add table to object bag */ + Status = KsAddItemToObjectBag(Bag, PropertyItem, NULL); + /* check for success */ + if (!NT_SUCCESS(Status)) + { + /* free table */ + FreeItem(Table); + return Status; + } + } + + // copy entries from dominant table + RtlCopyMemory(PropertyItem, PropertySetA->PropertyItem, Table->PropertyItemSize * PropertySetA->PropertiesCount); + + // init property set + OutPropertySet->PropertiesCount = PropertySetA->PropertiesCount; + OutPropertySet->PropertyItem = PropertyItem; + + // copy other entries + CurrentPropertyItem = (PKSPROPERTY_ITEM)PropertySetB->PropertyItem; + for(Index = 0; Index < PropertySetB->PropertiesCount; Index++) + { + + // add entries + KspAddPropertyItem(OutPropertySet, CurrentPropertyItem, Table->PropertyItemSize); + + // next entry + CurrentPropertyItem = (PKSPROPERTY_ITEM)((ULONG_PTR)CurrentPropertyItem + Table->PropertyItemSize); + } + + // done + return STATUS_SUCCESS; +} +
NTSTATUS KspCopyPropertySets( OUT PKSAUTOMATION_TABLE Table, IN PKSAUTOMATION_TABLE AutomationTableA OPTIONAL, - IN PKSAUTOMATION_TABLE AutomationTableB OPTIONAL) + IN PKSAUTOMATION_TABLE AutomationTableB OPTIONAL, + IN KSOBJECT_BAG Bag OPTIONAL) { ULONG Index, SubIndex, Count; BOOL bFound; + NTSTATUS Status;
if (!AutomationTableA) { @@ -2137,6 +2222,17 @@ RtlMoveMemory((PVOID)&Table->PropertySets[Count], &AutomationTableB->PropertySets[Index], sizeof(KSPROPERTY_SET)); Count++; } + else + { + // merge property sets + Status = KspMergePropertySet(Table, (PKSPROPERTY_SET)&Table->PropertySets[SubIndex], (PKSPROPERTY_SET)&AutomationTableA->PropertySets[SubIndex], (PKSPROPERTY_SET)&AutomationTableB->PropertySets[Index], Bag); + if (!NT_SUCCESS(Status)) + { + // failed to merge + DPRINT1("[KS] Failed to merge %x\n", Status); + return Status; + } + } }
return STATUS_SUCCESS; @@ -2249,6 +2345,12 @@ { /* use item size from 2nd automation table */ Table->PropertyItemSize = AutomationTableB->PropertyItemSize; + } + + if (AutomationTableA && AutomationTableB) + { + // FIXME handle different propery item sizes + ASSERT(AutomationTableA->PropertyItemSize == AutomationTableB->PropertyItemSize); }
/* now allocate the property sets */ @@ -2272,7 +2374,7 @@ } } /* now copy the property sets */ - Status = KspCopyPropertySets(Table, AutomationTableA, AutomationTableB); + Status = KspCopyPropertySets(Table, AutomationTableA, AutomationTableB, Bag); if(!NT_SUCCESS(Status)) goto cleanup;
Modified: trunk/reactos/drivers/ksfilter/ks/filter.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/ksfilter/ks/filter.... ============================================================================== --- trunk/reactos/drivers/ksfilter/ks/filter.c [iso-8859-1] (original) +++ trunk/reactos/drivers/ksfilter/ks/filter.c [iso-8859-1] Sun Mar 4 04:44:48 2012 @@ -955,7 +955,7 @@ 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; @@ -1029,6 +1029,9 @@ 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 +1066,7 @@ }
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);