- Implement MIXER_GETLINEINFOF_COMPONENTTYPE for WdmAudGetLineInfo
authorJohannes Anderwald <johannes.anderwald@reactos.org>
Tue, 6 Oct 2009 18:16:21 +0000 (18:16 +0000)
committerJohannes Anderwald <johannes.anderwald@reactos.org>
Tue, 6 Oct 2009 18:16:21 +0000 (18:16 +0000)
- Implement MIXER_GETLINECONTROLSF_ONEBYID for WdmAudGetLineControls
- Clear MIXER_OBJECTF_HMIXER from Flags
- Fix a bug SetGetVolumeControlDetails which fixes retrieving current volume level (verified by sndvol32.exe from XP / mmsys.cpl ReactOS)

svn path=/trunk/; revision=43315

reactos/drivers/wdm/audio/legacy/wdmaud/mixer.c

index 4fc4775..2b0ced2 100644 (file)
@@ -96,9 +96,12 @@ GetMixerControlById(
         {
             if (MixerLineSrc->LineControls[Index].dwControlID == dwControlID)
             {
-                *MixerLine = MixerLineSrc;
-                *MixerControl = &MixerLineSrc->LineControls[Index];
-                *NodeId = MixerLineSrc->NodeIds[Index];
+                if (MixerLine)
+                    *MixerLine = MixerLineSrc;
+                if (MixerControl)
+                    *MixerControl = &MixerLineSrc->LineControls[Index];
+                if (NodeId)
+                    *NodeId = MixerLineSrc->NodeIds[Index];
                 return STATUS_SUCCESS;
             }
         }
@@ -108,7 +111,28 @@ GetMixerControlById(
     return STATUS_NOT_FOUND;
 }
 
+LPMIXERLINE_EXT
+GetSourceMixerLineByComponentType(
+    LPMIXER_INFO MixerInfo,
+    DWORD dwComponentType)
+{
+    PLIST_ENTRY Entry;
+    LPMIXERLINE_EXT MixerLineSrc;
+
+    /* get first entry */
+    Entry = MixerInfo->LineList.Flink;
+
+    while(Entry != &MixerInfo->LineList)
+    {
+        MixerLineSrc = (LPMIXERLINE_EXT)CONTAINING_RECORD(Entry, MIXERLINE_EXT, Entry);
+        if (MixerLineSrc->Line.dwComponentType == dwComponentType)
+            return MixerLineSrc;
+
+        Entry = Entry->Flink;
+    }
 
+    return NULL;
+}
 
 LPMIXERLINE_EXT
 GetSourceMixerLineByLineId(
@@ -1761,6 +1785,8 @@ WdmAudGetLineInfo(
     /* get device extension */
     DeviceExtension = (PWDMAUD_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
 
+    DeviceInfo->Flags &= ~MIXER_OBJECTF_HMIXER;
+
     if (DeviceInfo->Flags == MIXER_GETLINEINFOF_DESTINATION)
     {
         if ((ULONG)DeviceInfo->hDevice >= DeviceExtension->MixerInfoCount)
@@ -1822,7 +1848,21 @@ WdmAudGetLineInfo(
         RtlCopyMemory(&DeviceInfo->u.MixLine, &MixerLineSrc->Line, sizeof(MIXERLINEW));
         return SetIrpIoStatus(Irp, STATUS_SUCCESS, sizeof(WDMAUD_DEVICE_INFO));
     }
+    else if (DeviceInfo->Flags == MIXER_GETLINEINFOF_COMPONENTTYPE)
+    {
+        if ((ULONG)DeviceInfo->hDevice >= DeviceExtension->MixerInfoCount)
+        {
+            /* invalid parameter */
+            return SetIrpIoStatus(Irp, STATUS_INVALID_PARAMETER, 0);
+        }
+
+        MixerLineSrc = GetSourceMixerLineByComponentType(&DeviceExtension->MixerInfo[(ULONG)DeviceInfo->hDevice], DeviceInfo->u.MixLine.dwComponentType);
+        ASSERT(MixerLineSrc);
 
+        /* copy cached data */
+        RtlCopyMemory(&DeviceInfo->u.MixLine, &MixerLineSrc->Line, sizeof(MIXERLINEW));
+        return SetIrpIoStatus(Irp, STATUS_SUCCESS, sizeof(WDMAUD_DEVICE_INFO));
+    }
 
     DPRINT1("Flags %x\n", DeviceInfo->Flags);
     UNIMPLEMENTED;
@@ -1841,12 +1881,16 @@ WdmAudGetLineControls(
     IN  PWDMAUD_CLIENT ClientInfo)
 {
     LPMIXERLINE_EXT MixerLineSrc;
+    LPMIXERCONTROLW MixerControl;
     PWDMAUD_DEVICE_EXTENSION DeviceExtension;
     ULONG Index;
+    NTSTATUS Status;
 
     /* get device extension */
     DeviceExtension = (PWDMAUD_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
 
+    DeviceInfo->Flags &= ~MIXER_OBJECTF_HMIXER;
+
     if (DeviceInfo->Flags == MIXER_GETLINECONTROLSF_ALL)
     {
         if ((ULONG)DeviceInfo->hDevice >= DeviceExtension->MixerInfoCount)
@@ -1887,6 +1931,22 @@ WdmAudGetLineControls(
         DPRINT1("DeviceInfo->u.MixControls.dwControlType %x not found in Line %x cControls %u \n", DeviceInfo->u.MixControls.dwControlType, DeviceInfo->u.MixControls.dwLineID, MixerLineSrc->Line.cControls);
         return SetIrpIoStatus(Irp, STATUS_UNSUCCESSFUL, sizeof(WDMAUD_DEVICE_INFO));
     }
+    else if (DeviceInfo->Flags == MIXER_GETLINECONTROLSF_ONEBYID)
+    {
+        if ((ULONG)DeviceInfo->hDevice >= DeviceExtension->MixerInfoCount)
+        {
+            /* invalid parameter */
+            return SetIrpIoStatus(Irp, STATUS_INVALID_PARAMETER, 0);
+        }
+
+        Status = GetMixerControlById(&DeviceExtension->MixerInfo[(ULONG)DeviceInfo->hDevice], DeviceInfo->u.MixControls.dwControlID, NULL, &MixerControl, NULL);
+        if (NT_SUCCESS(Status))
+        {
+            RtlMoveMemory(DeviceInfo->u.MixControls.pamxctrl, MixerControl, sizeof(MIXERCONTROLW));
+        }
+        return SetIrpIoStatus(Irp, Status, sizeof(WDMAUD_DEVICE_INFO));
+    }
+
 
     UNIMPLEMENTED;
     //DbgBreakPoint();
@@ -2042,7 +2102,7 @@ SetGetVolumeControlDetails(
     {
         for(Index = 0; Index < VolumeData->ValuesCount; Index++)
         {
-            if (VolumeData->Values[Index] < Value)
+            if (VolumeData->Values[Index] > Value)
             {
                 /* FIXME SEH */
                 Input->dwValue = VolumeData->InputSteppingDelta * Index;
@@ -2069,6 +2129,8 @@ WdmAudSetControlDetails(
     PWDMAUD_DEVICE_EXTENSION DeviceExtension;
     NTSTATUS Status;
 
+    DeviceInfo->Flags &= ~MIXER_OBJECTF_HMIXER;
+
     DPRINT("cbStruct %u Expected %u dwControlID %u cChannels %u cMultipleItems %u cbDetails %u paDetails %p Flags %x\n", 
             DeviceInfo->u.MixDetails.cbStruct, sizeof(MIXERCONTROLDETAILS), DeviceInfo->u.MixDetails.dwControlID, DeviceInfo->u.MixDetails.cChannels, DeviceInfo->u.MixDetails.cMultipleItems, DeviceInfo->u.MixDetails.cbDetails, DeviceInfo->u.MixDetails.paDetails, DeviceInfo->Flags);
 
@@ -2119,6 +2181,8 @@ WdmAudGetControlDetails(
     PWDMAUD_DEVICE_EXTENSION DeviceExtension;
     NTSTATUS Status;
 
+    DeviceInfo->Flags &= ~MIXER_OBJECTF_HMIXER;
+
     DPRINT("cbStruct %u Expected %u dwControlID %u cChannels %u cMultipleItems %u cbDetails %u paDetails %p Flags %x\n", 
             DeviceInfo->u.MixDetails.cbStruct, sizeof(MIXERCONTROLDETAILS), DeviceInfo->u.MixDetails.dwControlID, DeviceInfo->u.MixDetails.cChannels, DeviceInfo->u.MixDetails.cMultipleItems, DeviceInfo->u.MixDetails.cbDetails, DeviceInfo->u.MixDetails.paDetails, DeviceInfo->Flags);