sync with trunk (r49238)
[reactos.git] / lib / drivers / sound / mmixer / sup.c
index e864d1d..a557cf9 100644 (file)
@@ -54,9 +54,10 @@ MMixerFreeMixerInfo(
     IN PMIXER_CONTEXT MixerContext,
     IN LPMIXER_INFO MixerInfo)
 {
-    //UNIMPLEMENTED
-    // FIXME
-    // free all lines
+    /* UNIMPLEMENTED
+     * FIXME
+     * free all lines
+     */
 
     MixerContext->Free((PVOID)MixerInfo);
 }
@@ -71,7 +72,7 @@ MMixerGetMixerInfoByIndex(
     PMIXER_LIST MixerList;
     ULONG Index = 0;
 
-    // get mixer list
+    /* get mixer list */
     MixerList = (PMIXER_LIST)MixerContext->MixerContext;
 
     if (!MixerList->MixerListCount)
@@ -86,7 +87,7 @@ MMixerGetMixerInfoByIndex(
         if (Index == MixerIndex)
             return MixerInfo;
 
-        // move to next mixer entry
+        /* move to next mixer entry */
         Index++;
         Entry = Entry->Flink;
     }
@@ -141,42 +142,6 @@ MMixerGetSourceMixerLineByLineId(
     return NULL;
 }
 
-ULONG
-MMixerGetIndexOfGuid(
-    PKSMULTIPLE_ITEM MultipleItem,
-    LPCGUID NodeType)
-{
-    ULONG Index;
-    LPGUID Guid;
-
-    Guid = (LPGUID)(MultipleItem+1);
-
-    /* iterate through node type array */
-    for(Index = 0; Index < MultipleItem->Count; Index++)
-    {
-        if (IsEqualGUIDAligned(NodeType, Guid))
-        {
-            /* found matching guid */
-            return Index;
-        }
-        Guid++;
-    }
-    return MAXULONG;
-}
-
-PKSTOPOLOGY_CONNECTION
-MMixerGetConnectionByIndex(
-    IN PKSMULTIPLE_ITEM MultipleItem,
-    IN ULONG Index)
-{
-    PKSTOPOLOGY_CONNECTION Descriptor;
-
-    ASSERT(Index < MultipleItem->Count);
-
-    Descriptor = (PKSTOPOLOGY_CONNECTION)(MultipleItem + 1);
-    return &Descriptor[Index];
-}
-
 LPGUID
 MMixerGetNodeType(
     IN PKSMULTIPLE_ITEM MultipleItem,
@@ -190,183 +155,6 @@ MMixerGetNodeType(
     return &NodeType[Index];
 }
 
-MIXER_STATUS
-MMixerGetNodeIndexes(
-    IN PMIXER_CONTEXT MixerContext,
-    IN PKSMULTIPLE_ITEM MultipleItem,
-    IN ULONG NodeIndex,
-    IN ULONG bNode,
-    IN ULONG bFrom,
-    OUT PULONG NodeReferenceCount,
-    OUT PULONG *NodeReference)
-{
-    ULONG Index, Count = 0;
-    PKSTOPOLOGY_CONNECTION Connection;
-    PULONG Refs;
-
-    // KSMULTIPLE_ITEM is followed by several KSTOPOLOGY_CONNECTION
-    Connection = (PKSTOPOLOGY_CONNECTION)(MultipleItem + 1);
-
-    // first count all referenced nodes
-    for(Index = 0; Index < MultipleItem->Count; Index++)
-    {
-        if (bNode)
-        {
-            if (bFrom)
-            {
-                if (Connection->FromNode == NodeIndex)
-                {
-                    // node id has a connection
-                    Count++;
-                }
-            }
-            else
-            {
-                if (Connection->ToNode == NodeIndex)
-                {
-                    // node id has a connection
-                    Count++;
-                }
-            }
-        }
-        else
-        {
-            if (bFrom)
-            {
-                if (Connection->FromNodePin == NodeIndex && Connection->FromNode == KSFILTER_NODE)
-                {
-                    // node id has a connection
-                    Count++;
-                }
-            }
-            else
-            {
-                if (Connection->ToNodePin == NodeIndex && Connection->ToNode == KSFILTER_NODE)
-                {
-                    // node id has a connection
-                    Count++;
-                }
-            }
-        }
-
-
-        // move to next connection
-        Connection++;
-    }
-
-    if (!Count)
-    {
-        *NodeReferenceCount = 0;
-        *NodeReference = NULL;
-        return MM_STATUS_SUCCESS;
-    }
-
-    ASSERT(Count != 0);
-
-    /* now allocate node index array */
-    Refs = (PULONG)MixerContext->Alloc(sizeof(ULONG) * Count);
-    if (!Refs)
-    {
-        // not enough memory
-        return MM_STATUS_NO_MEMORY;
-    }
-
-    Count = 0;
-    Connection = (PKSTOPOLOGY_CONNECTION)(MultipleItem + 1);
-    for(Index = 0; Index < MultipleItem->Count; Index++)
-    {
-        if (bNode)
-        {
-            if (bFrom)
-            {
-                if (Connection->FromNode == NodeIndex)
-                {
-                    /* node id has a connection */
-                    Refs[Count] = Index;
-                    Count++;
-                }
-            }
-            else
-            {
-                if (Connection->ToNode == NodeIndex)
-                {
-                    /* node id has a connection */
-                    Refs[Count] = Index;
-                    Count++;
-                }
-            }
-        }
-        else
-        {
-            if (bFrom)
-            {
-                if (Connection->FromNodePin == NodeIndex && Connection->FromNode == KSFILTER_NODE)
-                {
-                    /* node id has a connection */
-                    Refs[Count] = Index;
-                    Count++;
-                }
-            }
-            else
-            {
-                if (Connection->ToNodePin == NodeIndex && Connection->ToNode == KSFILTER_NODE)
-                {
-                    /* node id has a connection */
-                    Refs[Count] = Index;
-                    Count++;
-                }
-            }
-        }
-
-        /* move to next connection */
-        Connection++;
-    }
-
-    /* store result */
-    *NodeReference = Refs;
-    *NodeReferenceCount = Count;
-
-    return MM_STATUS_SUCCESS;
-}
-
-MIXER_STATUS
-MMixerGetTargetPins(
-    IN PMIXER_CONTEXT MixerContext,
-    IN PKSMULTIPLE_ITEM NodeTypes,
-    IN PKSMULTIPLE_ITEM NodeConnections,
-    IN ULONG NodeIndex,
-    IN ULONG bUpDirection,
-    OUT PULONG Pins,
-    IN ULONG PinCount)
-{
-    ULONG NodeConnectionCount, Index;
-    MIXER_STATUS Status;
-    PULONG NodeConnection;
-
-    // sanity check */
-    ASSERT(NodeIndex != (ULONG)-1);
-
-    /* get all node indexes referenced by that pin */
-    if (bUpDirection)
-        Status = MMixerGetNodeIndexes(MixerContext, NodeConnections, NodeIndex, TRUE, FALSE, &NodeConnectionCount, &NodeConnection);
-    else
-        Status = MMixerGetNodeIndexes(MixerContext, NodeConnections, NodeIndex, TRUE, TRUE, &NodeConnectionCount, &NodeConnection);
-
-    //DPRINT("NodeIndex %u Status %x Count %u\n", NodeIndex, Status, NodeConnectionCount);
-
-    if (Status == MM_STATUS_SUCCESS)
-    {
-        for(Index = 0; Index < NodeConnectionCount; Index++)
-        {
-            Status = MMixerGetTargetPinsByNodeConnectionIndex(MixerContext, NodeConnections, NodeTypes, bUpDirection, NodeConnection[Index], PinCount, Pins);
-            ASSERT(Status == STATUS_SUCCESS);
-        }
-        MixerContext->Free((PVOID)NodeConnection);
-    }
-
-    return Status;
-}
-
 LPMIXERLINE_EXT
 MMixerGetSourceMixerLineByComponentType(
     LPMIXER_INFO MixerInfo,
@@ -445,10 +233,38 @@ MMixerGetVolumeControlIndex(
     return VolumeData->InputSteppingDelta * (VolumeData->ValuesCount-1);
 }
 
+VOID
+MMixerNotifyControlChange(
+    IN PMIXER_CONTEXT MixerContext,
+    IN LPMIXER_INFO MixerInfo,
+    IN ULONG NotificationType,
+    IN ULONG Value)
+{
+    PLIST_ENTRY Entry;
+    PEVENT_NOTIFICATION_ENTRY NotificationEntry;
+
+    /* enumerate list and add a notification entry */
+    Entry = MixerInfo->LineList.Flink;
+    while(Entry != &MixerInfo->EventList)
+    {
+        /* get notification entry offset */
+        NotificationEntry = (PEVENT_NOTIFICATION_ENTRY)CONTAINING_RECORD(Entry, EVENT_NOTIFICATION_ENTRY, Entry);
+
+        if (NotificationEntry->MixerEventRoutine)
+        {
+            /* now perform the callback */
+            NotificationEntry->MixerEventRoutine(NotificationEntry->MixerEventContext, (HANDLE)MixerInfo, NotificationType, Value);
+        }
+
+        /* move to next notification entry */
+        Entry = Entry->Flink;
+    }
+}
+
 MIXER_STATUS
 MMixerSetGetMuteControlDetails(
     IN PMIXER_CONTEXT MixerContext,
-    IN HANDLE hMixer,
+    IN LPMIXER_INFO MixerInfo,
     IN ULONG NodeId,
     IN ULONG dwLineID,
     IN LPMIXERCONTROLDETAILS MixerControlDetails,
@@ -469,7 +285,7 @@ MMixerSetGetMuteControlDetails(
         Value = Input->fValue;
 
     /* set control details */
-    Status = MMixerSetGetControlDetails(MixerContext, hMixer, NodeId, bSet, KSPROPERTY_AUDIO_MUTE, 0, &Value);
+    Status = MMixerSetGetControlDetails(MixerContext, MixerInfo->hMixer, NodeId, bSet, KSPROPERTY_AUDIO_MUTE, 0, &Value);
 
     if (Status != MM_STATUS_SUCCESS)
         return Status;
@@ -482,7 +298,8 @@ MMixerSetGetMuteControlDetails(
     }
     else
     {
-        // FIXME notify wdmaud clients MM_MIXM_LINE_CHANGE dwLineID
+        /* notify wdmaud clients MM_MIXM_LINE_CHANGE dwLineID */
+        MMixerNotifyControlChange(MixerContext, MixerInfo, MM_MIXM_LINE_CHANGE, dwLineID);
     }
 
     return Status;
@@ -491,7 +308,7 @@ MMixerSetGetMuteControlDetails(
 MIXER_STATUS
 MMixerSetGetVolumeControlDetails(
     IN PMIXER_CONTEXT MixerContext,
-    IN HANDLE hMixer,
+    IN LPMIXER_INFO MixerInfo,
     IN ULONG NodeId,
     IN ULONG bSet,
     LPMIXERCONTROLW MixerControl,
@@ -534,12 +351,12 @@ MMixerSetGetVolumeControlDetails(
     if (bSet)
     {
         /* TODO */
-        Status = MMixerSetGetControlDetails(MixerContext, hMixer, NodeId, bSet, KSPROPERTY_AUDIO_VOLUMELEVEL, 0, &Value);
-        Status = MMixerSetGetControlDetails(MixerContext, hMixer, NodeId, bSet, KSPROPERTY_AUDIO_VOLUMELEVEL, 1, &Value);
+        Status = MMixerSetGetControlDetails(MixerContext, MixerInfo->hMixer, NodeId, bSet, KSPROPERTY_AUDIO_VOLUMELEVEL, 0, &Value);
+        Status = MMixerSetGetControlDetails(MixerContext, MixerInfo->hMixer, NodeId, bSet, KSPROPERTY_AUDIO_VOLUMELEVEL, 1, &Value);
     }
     else
     {
-        Status = MMixerSetGetControlDetails(MixerContext, hMixer, NodeId, bSet, KSPROPERTY_AUDIO_VOLUMELEVEL, Channel, &Value);
+        Status = MMixerSetGetControlDetails(MixerContext, MixerInfo->hMixer, NodeId, bSet, KSPROPERTY_AUDIO_VOLUMELEVEL, Channel, &Value);
     }
 
     if (!bSet)
@@ -551,6 +368,7 @@ MMixerSetGetVolumeControlDetails(
     else
     {
         /* notify clients of a line change  MM_MIXM_CONTROL_CHANGE with MixerControl->dwControlID */
+        MMixerNotifyControlChange(MixerContext, MixerInfo, MM_MIXM_CONTROL_CHANGE, MixerControl->dwControlID);
     }
     return Status;
 }
@@ -590,7 +408,7 @@ MMixerGetDataByDeviceName(
         MixerData = (LPMIXER_DATA)CONTAINING_RECORD(Entry, MIXER_DATA, Entry);
         if (wcsicmp(&DeviceName[2], &MixerData->DeviceName[2]) == 0)
         {
-            // found entry
+            /* found entry */
             return MixerData;
         }
         Entry = Entry->Flink;
@@ -617,6 +435,7 @@ MMixerCreateMixerData(
     MixerData->DeviceName = DeviceName;
     MixerData->hDevice = hDevice;
     MixerData->hDeviceInterfaceKey = hKey;
+    MixerData->Topology = NULL;
 
     InsertTailList(&MixerList->MixerData, &MixerData->Entry);
     MixerList->MixerDataCount++;
@@ -638,16 +457,16 @@ MMixerGetDeviceName(
     Status = MixerContext->QueryKeyValue(hKey, L"FriendlyName", (PVOID*)&Name, &Length, &Type);
     if (Status == MM_STATUS_SUCCESS)
     {
-        // copy device name
+        /* copy device name */
         MixerContext->Copy(MixerInfo->MixCaps.szPname, Name, min(wcslen(Name), MAXPNAMELEN-1) * sizeof(WCHAR));
 
-        // make sure its null terminated
+        /* make sure its null terminated */
         MixerInfo->MixCaps.szPname[MAXPNAMELEN-1] = L'\0';
 
-        // free device name
+        /* free device name */
         MixerContext->Free(Name);
 
-        // done
+        /* done */
         return Status;
     }
 
@@ -658,13 +477,13 @@ MMixerGetDeviceName(
     Status = MixerContext->QueryKeyValue(hKey, L"FriendlyName", (PVOID*)&Name, &Length, &Type);
     if (Status == MM_STATUS_SUCCESS)
     {
-        // copy device name
+        /* copy device name */
         MixerContext->Copy(MixerInfo->MixCaps.szPname, Name, min(wcslen(Name), MAXPNAMELEN-1) * sizeof(WCHAR));
 
-        // make sure its null terminated
+        /* make sure its null terminated */
         MixerInfo->MixCaps.szPname[MAXPNAMELEN-1] = L'\0';
 
-        // free device name
+        /* free device name */
         MixerContext->Free(Name);
     }