[MMIXER]
authorJohannes Anderwald <johannes.anderwald@reactos.org>
Thu, 10 Dec 2009 12:27:16 +0000 (12:27 +0000)
committerJohannes Anderwald <johannes.anderwald@reactos.org>
Thu, 10 Dec 2009 12:27:16 +0000 (12:27 +0000)
- Store MixerList in MixerContext member
- Fix a lot of bugs
- MMixer is now able to enumerate mixers and their associated controls

svn path=/trunk/; revision=44522

reactos/lib/drivers/sound/mmixer/controls.c
reactos/lib/drivers/sound/mmixer/filter.c
reactos/lib/drivers/sound/mmixer/mixer.c
reactos/lib/drivers/sound/mmixer/mmixer.h

index 62e0ade..631a82e 100644 (file)
@@ -413,7 +413,10 @@ MMixerAddMixerSourceLine(
     for(Index = 0; Index < NodeTypes->Count; Index++)
     {
         if (Nodes[Index])
+        {
+            // found a node
             ControlCount++;
+        }
     }
 
     /* now allocate the line controls */
@@ -458,7 +461,7 @@ MMixerAddMixerSourceLine(
                 SrcLine->NodeIds[ControlCount] = Index;
 
                 Status = MMixerAddMixerControl(MixerContext, MixerInfo, hDevice, NodeTypes, Index, SrcLine, &SrcLine->LineControls[ControlCount]);
-                if (Status != MM_STATUS_SUCCESS)
+                if (Status == MM_STATUS_SUCCESS)
                 {
                     /* increment control count on success */
                     ControlCount++;
@@ -497,12 +500,7 @@ MMixerAddMixerSourceLine(
     /* try get pin name size */
     Status = MixerContext->Control(hDevice, IOCTL_KS_PROPERTY, (PVOID)&Pin, sizeof(KSP_PIN), NULL, 0, &BytesReturned);
 
-    if (Status != STATUS_MORE_ENTRIES)
-    {
-        SrcLine->Line.szShortName[0] = L'\0';
-        SrcLine->Line.szName[0] = L'\0';
-    }
-    else
+    if (Status == MM_STATUS_MORE_ENTRIES)
     {
         PinName = (LPWSTR)MixerContext->Alloc(BytesReturned);
         if (PinName)
@@ -510,7 +508,7 @@ MMixerAddMixerSourceLine(
             /* try get pin name */
             Status = MixerContext->Control(hDevice, IOCTL_KS_PROPERTY, (PVOID)&Pin, sizeof(KSP_PIN), (LPVOID)PinName, BytesReturned, &BytesReturned);
 
-            if (Status != MM_STATUS_SUCCESS)
+            if (Status == MM_STATUS_SUCCESS)
             {
                 MixerContext->Copy(SrcLine->Line.szShortName, PinName, (min(MIXER_SHORT_NAME_CHARS, wcslen(PinName)+1)) * sizeof(WCHAR));
                 SrcLine->Line.szShortName[MIXER_SHORT_NAME_CHARS-1] = L'\0';
@@ -625,6 +623,7 @@ MMixerAddMixerSourceLines(
 
     for(Index = PinsCount; Index > 0; Index--)
     {
+        DPRINT("MMixerAddMixerSourceLines Index %lu Pin %lu\n", Index-1, Pins[Index-1]);
         if (Pins[Index-1])
         {
             MMixerAddMixerSourceLine(MixerContext, MixerInfo, hDevice, NodeConnections, NodeTypes, Index-1, (Index -1 == BridgePinIndex), (Index -1 == TargetPinIndex));
@@ -645,7 +644,6 @@ MMixerHandlePhysicalConnection(
     ULONG PinsRefCount, Index, PinConnectionIndexCount;
     MIXER_STATUS Status;
     HANDLE hDevice = NULL;
-    PFILE_OBJECT FileObject = NULL;
     PKSMULTIPLE_ITEM NodeTypes = NULL;
     PKSMULTIPLE_ITEM NodeConnections = NULL;
     PULONG MixerControls;
@@ -656,7 +654,7 @@ MMixerHandlePhysicalConnection(
     Status = MixerContext->Open(OutConnection->SymbolicLinkName, &hDevice);
     if (Status != MM_STATUS_SUCCESS)
     {
-        DPRINT1("OpenDevice failed with %x\n", Status);
+        DPRINT("OpenDevice failed with %x\n", Status);
         return Status;
     }
 
@@ -691,7 +689,7 @@ MMixerHandlePhysicalConnection(
         return Status;
     }
     //  gets connection index of the bridge pin which connects to a node
-    DPRINT("Pin %u\n", OutConnection->Pin);
+    DPRINT("Pin %lu\n", OutConnection->Pin);
 
     Status = MMixerGetNodeIndexes(MixerContext, NodeConnections, OutConnection->Pin, FALSE, !bInput, &PinConnectionIndexCount, &PinConnectionIndex);
     if (Status != MM_STATUS_SUCCESS)
@@ -720,12 +718,16 @@ MMixerHandlePhysicalConnection(
 
     for(Index = 0; Index < PinsRefCount; Index++)
     {
+        DPRINT("PinsRefCount %lu Index %lu Value %lu\n", PinsRefCount, Index, PinsRef[Index]);
         if (PinsRef[Index])
         {
             // found a target pin, now get all references
             Status = MMixerGetNodeIndexes(MixerContext, NodeConnections, Index, FALSE, FALSE, &MixerControlsCount, &MixerControls);
             if (Status != MM_STATUS_SUCCESS)
+            {
+                DPRINT("MMixerGetNodeIndexes failed with %u\n", Status);
                 break;
+            }
 
             /* sanity check */
             ASSERT(MixerControlsCount == 1);
@@ -767,7 +769,7 @@ MMixerHandlePhysicalConnection(
             }
             PinsSrcRef[OutConnection->Pin] = TRUE;
 
-            Status = MMixerAddMixerSourceLines(MixerContext, MixerInfo, FileObject, NodeConnections, NodeTypes, PinsRefCount, OutConnection->Pin, Index, PinsSrcRef);
+            Status = MMixerAddMixerSourceLines(MixerContext, MixerInfo, hDevice, NodeConnections, NodeTypes, PinsRefCount, OutConnection->Pin, Index, PinsSrcRef);
 
             MixerContext->Free(MixerControls);
             MixerContext->Free(PinsSrcRef);
@@ -795,6 +797,7 @@ MMixerInitializeFilter(
     PKSPIN_PHYSICALCONNECTION OutConnection;
     ULONG Index;
     ULONG * Pins;
+    ULONG bUsed;
 
     // allocate a mixer info struct
     MixerInfo = (LPMIXER_INFO) MixerContext->Alloc(sizeof(MIXER_INFO));
@@ -845,31 +848,47 @@ MMixerInitializeFilter(
         // failed to locate target pins
         MixerContext->Free(Pins);
         MMixerFreeMixerInfo(MixerContext, MixerInfo);
+        DPRINT("MMixerGetTargetPins failed with %u\n", Status);
         return Status;
     }
 
+    // filter hasnt been used
+    bUsed = FALSE;
+
     // now check all pins and generate new lines for destination lines
     for(Index = 0; Index < PinCount; Index++)
     {
+        DPRINT("Index %lu TargetPin %lu\n", Index, Pins[Index]);
         // is the current index a target pin
         if (Pins[Index])
         {
             // check if the pin has a physical connection
             Status = MMixerGetPhysicalConnection(MixerContext, hMixer, Index, &OutConnection);
-            if (Status != MM_STATUS_SUCCESS)
+            if (Status == MM_STATUS_SUCCESS)
             {
                 // the pin has a physical connection
                 Status = MMixerHandlePhysicalConnection(MixerContext, MixerInfo, bInputMixer, OutConnection);
-
+                DPRINT("MMixerHandlePhysicalConnection status %u\n", Status);
                 MixerContext->Free(OutConnection);
+                bUsed = TRUE;
             }
         }
     }
     MixerContext->Free(Pins);
 
-    // store mixer info in list
-    InsertTailList(&MixerList->MixerList, &MixerInfo->Entry);
-    MixerList->MixerListCount++;
+    if (bUsed)
+    {
+        // store mixer info in list
+        InsertTailList(&MixerList->MixerList, &MixerInfo->Entry);
+        MixerList->MixerListCount++;
+        DPRINT("New MixerCount %lu\n", MixerList->MixerListCount);
+    }
+    else
+    {
+        // TODO:
+        // filter exposes its topology on the same filter
+        MMixerFreeMixerInfo(MixerContext, MixerInfo);
+    }
 
     // done
     return Status;
@@ -891,7 +910,7 @@ MMixerSetupFilter(
     // get number of pins
     PinCount = MMixerGetFilterPinCount(MixerContext, hMixer);
     ASSERT(PinCount);
-
+    DPRINT("NumOfPins: %lu\n", PinCount);
 
     // get filter node types
     Status = MMixerGetFilterTopologyProperty(MixerContext, hMixer, KSPROPERTY_TOPOLOGY_NODES, &NodeTypes);
@@ -915,8 +934,9 @@ MMixerSetupFilter(
     if (NodeIndex != MAXULONG)
     {
         // it has
-        Status = MMixerInitializeFilter(MixerContext, MixerList, hMixer, DeviceName, NodeTypes, NodeConnections, PinCount, NodeIndex, FALSE);
 
+        Status = MMixerInitializeFilter(MixerContext, MixerList, hMixer, DeviceName, NodeTypes, NodeConnections, PinCount, NodeIndex, FALSE);
+        DPRINT("MMixerInitializeFilter Status %u\n", Status);
         // check for success
         if (Status == MM_STATUS_SUCCESS)
         {
@@ -932,7 +952,7 @@ MMixerSetupFilter(
     {
         // it has
         Status = MMixerInitializeFilter(MixerContext, MixerList, hMixer, DeviceName, NodeTypes, NodeConnections, PinCount, NodeIndex, TRUE);
-
+        DPRINT("MMixerInitializeFilter Status %u\n", Status);
         // check for success
         if (Status == MM_STATUS_SUCCESS)
         {
index b576a4c..d3abfb8 100644 (file)
@@ -109,7 +109,7 @@ MMixerGetPhysicalConnection(
         // pin does not have a physical connection
         return Status;
     }
-
+    DPRINT("Status %u BytesReturned %lu\n", Status, BytesReturned);
     Connection = (PKSPIN_PHYSICALCONNECTION)MixerContext->Alloc(BytesReturned);
     if (!Connection)
     {
@@ -123,6 +123,7 @@ MMixerGetPhysicalConnection(
     {
         // failed to query the physical connection
         MixerContext->Free(Connection);
+        DPRINT("Status %u\n", Status);
         return Status;
     }
 
index 303e043..e32777d 100644 (file)
@@ -438,10 +438,15 @@ MMixerInitialize(
      MixerList->MixerListCount = 0;
      InitializeListHead(&MixerList->MixerList);
 
+     // store mixer list
+     MixerContext->MixerContext = (PVOID)MixerList;
+
     // start enumerating all available devices
     Count = 0;
     DeviceIndex = 0;
 
+
+
     do
     {
         // enumerate a device
@@ -450,26 +455,21 @@ MMixerInitialize(
         if (Status != MM_STATUS_SUCCESS)
         {
             //check error code
-            if (Status != MM_STATUS_NO_MORE_DEVICES)
+            if (Status == MM_STATUS_NO_MORE_DEVICES)
             {
-                // enumeration has failed
-                return Status;
+                // enumeration has finished
+                break;
             }
-            // last device
-            break;
         }
-
+        else
+        {
+            MMixerSetupFilter(MixerContext, MixerList, hMixer, &Count, DeviceName);
+        }
 
         // increment device index
         DeviceIndex++;
-
-        Status = MMixerSetupFilter(MixerContext, MixerList, hMixer, &Count, DeviceName);
-
-        if (Status != MM_STATUS_SUCCESS)
-            break;
-
     }while(TRUE);
 
     // done
-    return Status;
+    return MM_STATUS_SUCCESS;
 }
index 51d9772..e5ed55a 100644 (file)
@@ -38,7 +38,7 @@ typedef MIXER_STATUS(*PMIXER_DEVICE_CONTROL)(
     PULONG lpBytesReturned);
 
 typedef MIXER_STATUS(*PMIXER_OPEN)(
-    IN LPCWSTR DevicePath,
+    IN LPWSTR DevicePath,
     OUT PHANDLE hDevice);
 
 typedef MIXER_STATUS(*PMIXER_CLOSE)(