2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel Streaming
4 * FILE: lib/drivers/sound/mmixer/controls.c
5 * PURPOSE: Mixer Control Iteration Functions
6 * PROGRAMMER: Johannes Anderwald
12 MMixerGetTargetPinsByNodeConnectionIndex(
13 IN PMIXER_CONTEXT MixerContext
,
14 IN PKSMULTIPLE_ITEM NodeConnections
,
15 IN PKSMULTIPLE_ITEM NodeTypes
,
16 IN ULONG bUpDirection
,
17 IN ULONG NodeConnectionIndex
,
20 PKSTOPOLOGY_CONNECTION Connection
;
21 ULONG PinId
, NodeConnectionCount
, Index
;
22 PULONG NodeConnection
;
27 ASSERT(NodeConnectionIndex
< NodeConnections
->Count
);
29 Connection
= (PKSTOPOLOGY_CONNECTION
)(NodeConnections
+ 1);
31 //DPRINT("FromNode %u FromNodePin %u -> ToNode %u ToNodePin %u\n", Connection[NodeConnectionIndex].FromNode, Connection[NodeConnectionIndex].FromNodePin, Connection[NodeConnectionIndex].ToNode, Connection[NodeConnectionIndex].ToNodePin );
33 if ((Connection
[NodeConnectionIndex
].ToNode
== KSFILTER_NODE
&& bUpDirection
== FALSE
) ||
34 (Connection
[NodeConnectionIndex
].FromNode
== KSFILTER_NODE
&& bUpDirection
== TRUE
))
36 /* iteration stops here */
38 PinId
= Connection
[NodeConnectionIndex
].FromNodePin
;
40 PinId
= Connection
[NodeConnectionIndex
].ToNodePin
;
42 //DPRINT("GetTargetPinsByNodeIndex FOUND Target Pin %u Parsed %u\n", PinId, Pins[PinId]);
44 /* mark pin index as a target pin */
46 return MM_STATUS_SUCCESS
;
49 // get all node indexes referenced by that node
52 Status
= MMixerGetNodeIndexes(MixerContext
, NodeConnections
, Connection
[NodeConnectionIndex
].FromNode
, TRUE
, FALSE
, &NodeConnectionCount
, &NodeConnection
);
56 Status
= MMixerGetNodeIndexes(MixerContext
, NodeConnections
, Connection
[NodeConnectionIndex
].ToNode
, TRUE
, TRUE
, &NodeConnectionCount
, &NodeConnection
);
59 if (Status
== MM_STATUS_SUCCESS
)
61 for(Index
= 0; Index
< NodeConnectionCount
; Index
++)
63 // iterate recursively into the nodes
64 Status
= MMixerGetTargetPinsByNodeConnectionIndex(MixerContext
, NodeConnections
, NodeTypes
, bUpDirection
, NodeConnection
[Index
], Pins
);
65 ASSERT(Status
== MM_STATUS_SUCCESS
);
67 // free node connection indexes
68 MixerContext
->Free(NodeConnection
);
75 MMixerGetControlsFromPinByConnectionIndex(
76 IN PMIXER_CONTEXT MixerContext
,
77 IN PKSMULTIPLE_ITEM NodeConnections
,
78 IN PKSMULTIPLE_ITEM NodeTypes
,
79 IN ULONG bUpDirection
,
80 IN ULONG NodeConnectionIndex
,
83 PKSTOPOLOGY_CONNECTION CurConnection
;
87 ULONG NodeConnectionCount
, Index
;
88 PULONG NodeConnection
;
91 /* get current connection */
92 CurConnection
= MMixerGetConnectionByIndex(NodeConnections
, NodeConnectionIndex
);
95 NodeIndex
= CurConnection
->FromNode
;
97 NodeIndex
= CurConnection
->ToNode
;
99 if (NodeIndex
> NodeTypes
->Count
)
101 // reached end of pin connection
102 return MM_STATUS_SUCCESS
;
105 /* get target node type of current connection */
106 NodeType
= MMixerGetNodeType(NodeTypes
, NodeIndex
);
108 if (IsEqualGUIDAligned(NodeType
, &KSNODETYPE_SUM
) || IsEqualGUIDAligned(NodeType
, &KSNODETYPE_MUX
))
112 /* add the sum / mux node to destination line */
113 Nodes
[NodeIndex
] = TRUE
;
116 return MM_STATUS_SUCCESS
;
119 /* now add the node */
120 Nodes
[NodeIndex
] = TRUE
;
123 /* get all node indexes referenced by that node */
126 Status
= MMixerGetNodeIndexes(MixerContext
, NodeConnections
, NodeIndex
, TRUE
, FALSE
, &NodeConnectionCount
, &NodeConnection
);
130 Status
= MMixerGetNodeIndexes(MixerContext
, NodeConnections
, NodeIndex
, TRUE
, TRUE
, &NodeConnectionCount
, &NodeConnection
);
133 if (Status
== MM_STATUS_SUCCESS
)
135 for(Index
= 0; Index
< NodeConnectionCount
; Index
++)
137 /* iterate recursively into the nodes */
138 Status
= MMixerGetControlsFromPinByConnectionIndex(MixerContext
, NodeConnections
, NodeTypes
, bUpDirection
, NodeConnection
[Index
], Nodes
);
139 ASSERT(Status
== MM_STATUS_SUCCESS
);
141 /* free node connection indexes */
142 MixerContext
->Free(NodeConnection
);
149 MMixerAddMixerControl(
150 IN PMIXER_CONTEXT MixerContext
,
151 IN LPMIXER_INFO MixerInfo
,
153 IN PKSMULTIPLE_ITEM NodeTypes
,
155 IN LPMIXERLINE_EXT MixerLine
,
156 OUT LPMIXERCONTROLW MixerControl
)
164 /* initialize mixer control */
165 MixerControl
->cbStruct
= sizeof(MIXERCONTROLW
);
166 MixerControl
->dwControlID
= MixerInfo
->ControlId
;
169 NodeType
= MMixerGetNodeType(NodeTypes
, NodeIndex
);
170 /* store control type */
171 MixerControl
->dwControlType
= MMixerGetControlTypeFromTopologyNode(NodeType
);
173 MixerControl
->fdwControl
= MIXERCONTROL_CONTROLF_UNIFORM
; //FIXME
174 MixerControl
->cMultipleItems
= 0; //FIXME
176 if (MixerControl
->dwControlType
== MIXERCONTROL_CONTROLTYPE_MUTE
)
178 MixerControl
->Bounds
.dwMinimum
= 0;
179 MixerControl
->Bounds
.dwMaximum
= 1;
181 else if (MixerControl
->dwControlType
== MIXERCONTROL_CONTROLTYPE_VOLUME
)
183 MixerControl
->Bounds
.dwMinimum
= 0;
184 MixerControl
->Bounds
.dwMaximum
= 0xFFFF;
185 MixerControl
->Metrics
.cSteps
= 0xC0; //FIXME
188 /* setup request to retrieve name */
189 Node
.NodeId
= NodeIndex
;
190 Node
.Property
.Id
= KSPROPERTY_TOPOLOGY_NAME
;
191 Node
.Property
.Flags
= KSPROPERTY_TYPE_GET
;
192 Node
.Property
.Set
= KSPROPSETID_Topology
;
195 /* get node name size */
196 Status
= MixerContext
->Control(hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Node
, sizeof(KSP_NODE
), NULL
, 0, &BytesReturned
);
198 if (Status
== MM_STATUS_MORE_ENTRIES
)
200 ASSERT(BytesReturned
!= 0);
201 Name
= (LPWSTR
)MixerContext
->Alloc(BytesReturned
);
204 /* not enough memory */
205 return MM_STATUS_NO_MEMORY
;
209 Status
= MixerContext
->Control(hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Node
, sizeof(KSP_NODE
), (LPVOID
)Name
, BytesReturned
, &BytesReturned
);
210 if (Status
!= MM_STATUS_SUCCESS
)
212 MixerContext
->Copy(MixerControl
->szShortName
, Name
, (min(MIXER_SHORT_NAME_CHARS
, wcslen(Name
)+1)) * sizeof(WCHAR
));
213 MixerControl
->szShortName
[MIXER_SHORT_NAME_CHARS
-1] = L
'\0';
215 MixerContext
->Copy(MixerControl
->szName
, Name
, (min(MIXER_LONG_NAME_CHARS
, wcslen(Name
)+1)) * sizeof(WCHAR
));
216 MixerControl
->szName
[MIXER_LONG_NAME_CHARS
-1] = L
'\0';
219 /* free name buffer */
220 MixerContext
->Free(Name
);
223 MixerInfo
->ControlId
++;
225 if (MixerControl
->dwControlType
== MIXERCONTROL_CONTROLTYPE_MUX
)
227 KSNODEPROPERTY Property
;
230 /* setup the request */
231 RtlZeroMemory(&Property
, sizeof(KSNODEPROPERTY
));
233 Property
.NodeId
= NodeIndex
;
234 Property
.Property
.Id
= KSPROPERTY_AUDIO_MUX_SOURCE
;
235 Property
.Property
.Flags
= KSPROPERTY_TYPE_SET
;
236 Property
.Property
.Set
= KSPROPSETID_Audio
;
238 /* get node volume level info */
239 Status
= MixerContext
->Control(hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSNODEPROPERTY
), (PVOID
)&PinId
, sizeof(ULONG
), &BytesReturned
);
241 DPRINT1("Status %x NodeIndex %u PinId %u\n", Status
, NodeIndex
, PinId
);
245 if (MixerControl
->dwControlType
== MIXERCONTROL_CONTROLTYPE_VOLUME
)
247 KSNODEPROPERTY_AUDIO_CHANNEL Property
;
249 PKSPROPERTY_DESCRIPTION Desc
;
250 PKSPROPERTY_MEMBERSHEADER Members
;
251 PKSPROPERTY_STEPPING_LONG Range
;
253 Length
= sizeof(KSPROPERTY_DESCRIPTION
) + sizeof(KSPROPERTY_MEMBERSHEADER
) + sizeof(KSPROPERTY_STEPPING_LONG
);
254 Desc
= (PKSPROPERTY_DESCRIPTION
)MixerContext
->Alloc(Length
);
257 /* setup the request */
258 RtlZeroMemory(&Property
, sizeof(KSNODEPROPERTY_AUDIO_CHANNEL
));
260 Property
.NodeProperty
.NodeId
= NodeIndex
;
261 Property
.NodeProperty
.Property
.Id
= KSPROPERTY_AUDIO_VOLUMELEVEL
;
262 Property
.NodeProperty
.Property
.Flags
= KSPROPERTY_TYPE_BASICSUPPORT
;
263 Property
.NodeProperty
.Property
.Set
= KSPROPSETID_Audio
;
265 /* get node volume level info */
266 Status
= MixerContext
->Control(hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSNODEPROPERTY_AUDIO_CHANNEL
), Desc
, Length
, &BytesReturned
);
268 if (Status
== MM_STATUS_SUCCESS
)
270 LPMIXERVOLUME_DATA VolumeData
;
271 ULONG Steps
, MaxRange
, Index
;
274 Members
= (PKSPROPERTY_MEMBERSHEADER
)(Desc
+ 1);
275 Range
= (PKSPROPERTY_STEPPING_LONG
)(Members
+ 1);
277 DPRINT("NodeIndex %u Range Min %d Max %d Steps %x UMin %x UMax %x\n", NodeIndex
, Range
->Bounds
.SignedMinimum
, Range
->Bounds
.SignedMaximum
, Range
->SteppingDelta
, Range
->Bounds
.UnsignedMinimum
, Range
->Bounds
.UnsignedMaximum
);
279 MaxRange
= Range
->Bounds
.UnsignedMaximum
- Range
->Bounds
.UnsignedMinimum
;
284 VolumeData
= (LPMIXERVOLUME_DATA
)MixerContext
->Alloc(sizeof(MIXERVOLUME_DATA
));
286 return MM_STATUS_NO_MEMORY
;
288 Steps
= MaxRange
/ Range
->SteppingDelta
+ 1;
290 /* store mixer control info there */
291 VolumeData
->Header
.dwControlID
= MixerControl
->dwControlID
;
292 VolumeData
->SignedMaximum
= Range
->Bounds
.SignedMaximum
;
293 VolumeData
->SignedMinimum
= Range
->Bounds
.SignedMinimum
;
294 VolumeData
->SteppingDelta
= Range
->SteppingDelta
;
295 VolumeData
->ValuesCount
= Steps
;
296 VolumeData
->InputSteppingDelta
= 0x10000 / Steps
;
298 VolumeData
->Values
= (PLONG
)MixerContext
->Alloc(sizeof(LONG
) * Steps
);
299 if (!VolumeData
->Values
)
301 MixerContext
->Free(Desc
);
302 MixerContext
->Free(VolumeData
);
304 return MM_STATUS_NO_MEMORY
;
307 Value
= Range
->Bounds
.SignedMinimum
;
308 for(Index
= 0; Index
< Steps
; Index
++)
310 VolumeData
->Values
[Index
] = Value
;
311 Value
+= Range
->SteppingDelta
;
313 InsertTailList(&MixerLine
->LineControlsExtraData
, &VolumeData
->Header
.Entry
);
316 MixerContext
->Free(Desc
);
320 DPRINT("Status %x Name %S\n", Status
, MixerControl
->szName
);
321 return MM_STATUS_SUCCESS
;
325 MMixerAddMixerSourceLine(
326 IN PMIXER_CONTEXT MixerContext
,
327 IN OUT LPMIXER_INFO MixerInfo
,
329 IN PKSMULTIPLE_ITEM NodeConnections
,
330 IN PKSMULTIPLE_ITEM NodeTypes
,
335 LPMIXERLINE_EXT SrcLine
, DstLine
;
340 ULONG BytesReturned
, ControlCount
, Index
;
346 /* allocate src mixer line */
347 SrcLine
= (LPMIXERLINE_EXT
)MixerContext
->Alloc(sizeof(MIXERLINE_EXT
));
350 return MM_STATUS_NO_MEMORY
;
353 RtlZeroMemory(SrcLine
, sizeof(MIXERLINE_EXT
));
358 ASSERT(!IsListEmpty(&MixerInfo
->LineList
));
359 SrcLine
= MMixerGetSourceMixerLineByLineId(MixerInfo
, DESTINATION_LINE
);
362 /* get destination line */
363 DstLine
= MMixerGetSourceMixerLineByLineId(MixerInfo
, DESTINATION_LINE
);
369 /* initialize mixer src line */
370 SrcLine
->hDevice
= hDevice
;
371 SrcLine
->PinId
= PinId
;
372 SrcLine
->Line
.cbStruct
= sizeof(MIXERLINEW
);
374 /* initialize mixer destination line */
375 SrcLine
->Line
.cbStruct
= sizeof(MIXERLINEW
);
376 SrcLine
->Line
.dwDestination
= 0;
377 SrcLine
->Line
.dwSource
= DstLine
->Line
.cConnections
;
378 SrcLine
->Line
.dwLineID
= (DstLine
->Line
.cConnections
* 0x10000);
379 SrcLine
->Line
.fdwLine
= MIXERLINE_LINEF_ACTIVE
| MIXERLINE_LINEF_SOURCE
;
380 SrcLine
->Line
.dwUser
= 0;
381 SrcLine
->Line
.cChannels
= DstLine
->Line
.cChannels
;
382 SrcLine
->Line
.cConnections
= 0;
383 SrcLine
->Line
.Target
.dwType
= 1;
384 SrcLine
->Line
.Target
.dwDeviceID
= DstLine
->Line
.Target
.dwDeviceID
;
385 SrcLine
->Line
.Target
.wMid
= MixerInfo
->MixCaps
.wMid
;
386 SrcLine
->Line
.Target
.wPid
= MixerInfo
->MixCaps
.wPid
;
387 SrcLine
->Line
.Target
.vDriverVersion
= MixerInfo
->MixCaps
.vDriverVersion
;
388 InitializeListHead(&SrcLine
->LineControlsExtraData
);
389 wcscpy(SrcLine
->Line
.Target
.szPname
, MixerInfo
->MixCaps
.szPname
);
393 /* allocate a node arrary */
394 Nodes
= (PULONG
)MixerContext
->Alloc(sizeof(ULONG
) * NodeTypes
->Count
);
398 /* not enough memory */
401 MixerContext
->Free(SrcLine
);
403 return MM_STATUS_NO_MEMORY
;
406 Status
= MMixerGetControlsFromPin(MixerContext
, NodeConnections
, NodeTypes
, PinId
, bTargetPin
, Nodes
);
407 if (Status
!= MM_STATUS_SUCCESS
)
409 /* something went wrong */
412 MixerContext
->Free(SrcLine
);
414 MixerContext
->Free(Nodes
);
418 /* now count all nodes controlled by that pin */
420 for(Index
= 0; Index
< NodeTypes
->Count
; Index
++)
425 Node
= MMixerGetNodeType(NodeTypes
, Index
);
427 if (MMixerGetControlTypeFromTopologyNode(Node
))
429 // found a node which can be resolved to a type
435 /* now allocate the line controls */
438 SrcLine
->LineControls
= (LPMIXERCONTROLW
)MixerContext
->Alloc(sizeof(MIXERCONTROLW
) * ControlCount
);
440 if (!SrcLine
->LineControls
)
442 /* no memory available */
445 MixerContext
->Free(SrcLine
);
447 MixerContext
->Free(Nodes
);
448 return MM_STATUS_NO_MEMORY
;
451 SrcLine
->NodeIds
= (PULONG
)MixerContext
->Alloc(sizeof(ULONG
) * ControlCount
);
452 if (!SrcLine
->NodeIds
)
454 /* no memory available */
455 MixerContext
->Free(SrcLine
->LineControls
);
458 MixerContext
->Free(SrcLine
);
460 MixerContext
->Free(Nodes
);
461 return MM_STATUS_NO_MEMORY
;
464 /* zero line controls */
465 RtlZeroMemory(SrcLine
->LineControls
, sizeof(MIXERCONTROLW
) * ControlCount
);
466 RtlZeroMemory(SrcLine
->NodeIds
, sizeof(ULONG
) * ControlCount
);
469 for(Index
= 0; Index
< NodeTypes
->Count
; Index
++)
474 Node
= MMixerGetNodeType(NodeTypes
, Index
);
476 if (MMixerGetControlTypeFromTopologyNode(Node
))
478 /* store the node index for retrieving / setting details */
479 SrcLine
->NodeIds
[ControlCount
] = Index
;
481 Status
= MMixerAddMixerControl(MixerContext
, MixerInfo
, hDevice
, NodeTypes
, Index
, SrcLine
, &SrcLine
->LineControls
[ControlCount
]);
482 if (Status
== MM_STATUS_SUCCESS
)
484 /* increment control count on success */
490 /* store control count */
491 SrcLine
->Line
.cControls
= ControlCount
;
494 /* release nodes array */
495 MixerContext
->Free(Nodes
);
497 /* get pin category */
500 Pin
.Property
.Flags
= KSPROPERTY_TYPE_GET
;
501 Pin
.Property
.Set
= KSPROPSETID_Pin
;
502 Pin
.Property
.Id
= KSPROPERTY_PIN_CATEGORY
;
504 /* try get pin category */
505 Status
= MixerContext
->Control(hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Pin
, sizeof(KSP_PIN
), (LPVOID
)&NodeType
, sizeof(GUID
), &BytesReturned
);
506 if (Status
!= MM_STATUS_SUCCESS
)
512 /* retrieve pin name */
515 Pin
.Property
.Flags
= KSPROPERTY_TYPE_GET
;
516 Pin
.Property
.Set
= KSPROPSETID_Pin
;
517 Pin
.Property
.Id
= KSPROPERTY_PIN_NAME
;
519 /* try get pin name size */
520 Status
= MixerContext
->Control(hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Pin
, sizeof(KSP_PIN
), NULL
, 0, &BytesReturned
);
522 if (Status
== MM_STATUS_MORE_ENTRIES
)
524 PinName
= (LPWSTR
)MixerContext
->Alloc(BytesReturned
);
527 /* try get pin name */
528 Status
= MixerContext
->Control(hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Pin
, sizeof(KSP_PIN
), (LPVOID
)PinName
, BytesReturned
, &BytesReturned
);
530 if (Status
== MM_STATUS_SUCCESS
)
532 MixerContext
->Copy(SrcLine
->Line
.szShortName
, PinName
, (min(MIXER_SHORT_NAME_CHARS
, wcslen(PinName
)+1)) * sizeof(WCHAR
));
533 SrcLine
->Line
.szShortName
[MIXER_SHORT_NAME_CHARS
-1] = L
'\0';
535 MixerContext
->Copy(SrcLine
->Line
.szName
, PinName
, (min(MIXER_LONG_NAME_CHARS
, wcslen(PinName
)+1)) * sizeof(WCHAR
));
536 SrcLine
->Line
.szName
[MIXER_LONG_NAME_CHARS
-1] = L
'\0';
538 MixerContext
->Free(PinName
);
542 /* insert src line */
545 InsertTailList(&MixerInfo
->LineList
, &SrcLine
->Entry
);
546 DstLine
->Line
.cConnections
++;
549 return MM_STATUS_SUCCESS
;
553 MMixerCreateDestinationLine(
554 IN PMIXER_CONTEXT MixerContext
,
555 IN LPMIXER_INFO MixerInfo
,
556 IN ULONG bInputMixer
,
559 LPMIXERLINE_EXT DestinationLine
;
561 // allocate a mixer destination line
562 DestinationLine
= (LPMIXERLINE_EXT
) MixerContext
->Alloc(sizeof(MIXERLINE_EXT
));
566 return MM_STATUS_NO_MEMORY
;
569 /* initialize mixer destination line */
570 DestinationLine
->Line
.cbStruct
= sizeof(MIXERLINEW
);
571 DestinationLine
->Line
.dwSource
= MAXULONG
;
572 DestinationLine
->Line
.dwLineID
= DESTINATION_LINE
;
573 DestinationLine
->Line
.fdwLine
= MIXERLINE_LINEF_ACTIVE
;
574 DestinationLine
->Line
.dwUser
= 0;
575 DestinationLine
->Line
.dwComponentType
= (bInputMixer
== 0 ? MIXERLINE_COMPONENTTYPE_DST_SPEAKERS
: MIXERLINE_COMPONENTTYPE_DST_WAVEIN
);
576 DestinationLine
->Line
.cChannels
= 2; //FIXME
580 wcscpy(DestinationLine
->Line
.szShortName
, LineName
);
581 wcscpy(DestinationLine
->Line
.szName
, LineName
);
585 /* FIXME no name was found for pin */
586 wcscpy(DestinationLine
->Line
.szShortName
, L
"Summe");
587 wcscpy(DestinationLine
->Line
.szName
, L
"Summe");
590 DestinationLine
->Line
.Target
.dwType
= (bInputMixer
== 0 ? MIXERLINE_TARGETTYPE_WAVEOUT
: MIXERLINE_TARGETTYPE_WAVEIN
);
591 DestinationLine
->Line
.Target
.dwDeviceID
= !bInputMixer
;
592 DestinationLine
->Line
.Target
.wMid
= MixerInfo
->MixCaps
.wMid
;
593 DestinationLine
->Line
.Target
.wPid
= MixerInfo
->MixCaps
.wPid
;
594 DestinationLine
->Line
.Target
.vDriverVersion
= MixerInfo
->MixCaps
.vDriverVersion
;
595 wcscpy(DestinationLine
->Line
.Target
.szPname
, MixerInfo
->MixCaps
.szPname
);
598 // insert into mixer info
599 InsertHeadList(&MixerInfo
->LineList
, &DestinationLine
->Entry
);
602 return MM_STATUS_SUCCESS
;
606 MMixerGetControlsFromPin(
607 IN PMIXER_CONTEXT MixerContext
,
608 IN PKSMULTIPLE_ITEM NodeConnections
,
609 IN PKSMULTIPLE_ITEM NodeTypes
,
611 IN ULONG bUpDirection
,
614 ULONG NodeConnectionCount
, Index
;
616 PULONG NodeConnection
;
619 ASSERT(PinId
!= (ULONG
)-1);
621 /* get all node indexes referenced by that pin */
623 Status
= MMixerGetNodeIndexes(MixerContext
, NodeConnections
, PinId
, FALSE
, FALSE
, &NodeConnectionCount
, &NodeConnection
);
625 Status
= MMixerGetNodeIndexes(MixerContext
, NodeConnections
, PinId
, FALSE
, TRUE
, &NodeConnectionCount
, &NodeConnection
);
627 for(Index
= 0; Index
< NodeConnectionCount
; Index
++)
629 /* get all associated controls */
630 Status
= MMixerGetControlsFromPinByConnectionIndex(MixerContext
, NodeConnections
, NodeTypes
, bUpDirection
, NodeConnection
[Index
], Nodes
);
633 MixerContext
->Free(NodeConnection
);
642 MMixerAddMixerSourceLines(
643 IN PMIXER_CONTEXT MixerContext
,
644 IN OUT LPMIXER_INFO MixerInfo
,
646 IN PKSMULTIPLE_ITEM NodeConnections
,
647 IN PKSMULTIPLE_ITEM NodeTypes
,
649 IN ULONG BridgePinIndex
,
650 IN ULONG TargetPinIndex
,
655 for(Index
= PinsCount
; Index
> 0; Index
--)
657 DPRINT("MMixerAddMixerSourceLines Index %lu Pin %lu\n", Index
-1, Pins
[Index
-1]);
660 MMixerAddMixerSourceLine(MixerContext
, MixerInfo
, hDevice
, NodeConnections
, NodeTypes
, Index
-1, (Index
-1 == BridgePinIndex
), (Index
-1 == TargetPinIndex
));
663 return MM_STATUS_SUCCESS
;
668 MMixerHandlePhysicalConnection(
669 IN PMIXER_CONTEXT MixerContext
,
670 IN PMIXER_LIST MixerList
,
671 IN OUT LPMIXER_INFO MixerInfo
,
673 IN PKSPIN_PHYSICALCONNECTION OutConnection
)
675 PULONG PinsRef
= NULL
, PinConnectionIndex
= NULL
, PinsSrcRef
;
676 ULONG PinsRefCount
, Index
, PinConnectionIndexCount
;
678 PKSMULTIPLE_ITEM NodeTypes
= NULL
;
679 PKSMULTIPLE_ITEM NodeConnections
= NULL
;
680 PULONG MixerControls
;
681 ULONG MixerControlsCount
;
682 LPMIXER_DATA MixerData
;
685 // open the connected filter
686 OutConnection
->SymbolicLinkName
[1] = L
'\\';
687 MixerData
= MMixerGetDataByDeviceName(MixerList
, OutConnection
->SymbolicLinkName
);
690 // get connected filter pin count
691 PinsRefCount
= MMixerGetFilterPinCount(MixerContext
, MixerData
->hDevice
);
692 ASSERT(PinsRefCount
);
694 PinsRef
= (PULONG
)MixerContext
->Alloc(sizeof(ULONG
) * PinsRefCount
);
698 return MM_STATUS_UNSUCCESSFUL
;
701 // get topology node types
702 Status
= MMixerGetFilterTopologyProperty(MixerContext
, MixerData
->hDevice
, KSPROPERTY_TOPOLOGY_NODES
, &NodeTypes
);
703 if (Status
!= MM_STATUS_SUCCESS
)
705 MixerContext
->Free(PinsRef
);
709 // get topology connections
710 Status
= MMixerGetFilterTopologyProperty(MixerContext
, MixerData
->hDevice
, KSPROPERTY_TOPOLOGY_CONNECTIONS
, &NodeConnections
);
711 if (Status
!= MM_STATUS_SUCCESS
)
713 MixerContext
->Free(PinsRef
);
714 MixerContext
->Free(NodeTypes
);
717 // gets connection index of the bridge pin which connects to a node
718 DPRINT("Pin %lu\n", OutConnection
->Pin
);
720 Status
= MMixerGetNodeIndexes(MixerContext
, NodeConnections
, OutConnection
->Pin
, FALSE
, !bInput
, &PinConnectionIndexCount
, &PinConnectionIndex
);
721 if (Status
!= MM_STATUS_SUCCESS
)
723 MixerContext
->Free(PinsRef
);
724 MixerContext
->Free(NodeTypes
);
725 MixerContext
->Free(NodeConnections
);
729 /* there should be no split in the bride pin */
730 ASSERT(PinConnectionIndexCount
== 1);
732 /* find all target pins of this connection */
733 Status
= MMixerGetTargetPinsByNodeConnectionIndex(MixerContext
, NodeConnections
, NodeTypes
, FALSE
, PinConnectionIndex
[0], PinsRef
);
734 if (Status
!= MM_STATUS_SUCCESS
)
736 MixerContext
->Free(PinsRef
);
737 MixerContext
->Free(NodeTypes
);
738 MixerContext
->Free(NodeConnections
);
739 MixerContext
->Free(PinConnectionIndex
);
743 for(Index
= 0; Index
< PinsRefCount
; Index
++)
745 DPRINT("PinsRefCount %lu Index %lu Value %lu\n", PinsRefCount
, Index
, PinsRef
[Index
]);
748 // found a target pin, now get all references
749 Status
= MMixerGetNodeIndexes(MixerContext
, NodeConnections
, Index
, FALSE
, FALSE
, &MixerControlsCount
, &MixerControls
);
750 if (Status
!= MM_STATUS_SUCCESS
)
752 DPRINT("MMixerGetNodeIndexes failed with %u\n", Status
);
757 ASSERT(MixerControlsCount
== 1);
759 PinsSrcRef
= (PULONG
)MixerContext
->Alloc(PinsRefCount
* sizeof(ULONG
));
763 MixerContext
->Free(PinsRef
);
764 MixerContext
->Free(NodeTypes
);
765 MixerContext
->Free(NodeConnections
);
766 MixerContext
->Free(PinConnectionIndex
);
767 MixerContext
->Free(MixerControls
);
768 return MM_STATUS_NO_MEMORY
;
771 // now get all connected source pins
772 Status
= MMixerGetTargetPinsByNodeConnectionIndex(MixerContext
, NodeConnections
, NodeTypes
, TRUE
, MixerControls
[0], PinsSrcRef
);
773 if (Status
!= MM_STATUS_SUCCESS
)
776 MixerContext
->Free(PinsRef
);
777 MixerContext
->Free(NodeTypes
);
778 MixerContext
->Free(NodeConnections
);
779 MixerContext
->Free(PinConnectionIndex
);
780 MixerContext
->Free(MixerControls
);
781 MixerContext
->Free(PinsSrcRef
);
785 /* add pins from target line */
788 // dont add bridge pin for input mixers
789 PinsSrcRef
[Index
] = TRUE
;
790 PinsSrcRef
[OutConnection
->Pin
] = TRUE
;
792 PinsSrcRef
[OutConnection
->Pin
] = TRUE
;
794 Status
= MMixerAddMixerSourceLines(MixerContext
, MixerInfo
, MixerData
->hDevice
, NodeConnections
, NodeTypes
, PinsRefCount
, OutConnection
->Pin
, Index
, PinsSrcRef
);
796 MixerContext
->Free(MixerControls
);
797 MixerContext
->Free(PinsSrcRef
);
806 MMixerInitializeFilter(
807 IN PMIXER_CONTEXT MixerContext
,
808 IN PMIXER_LIST MixerList
,
809 IN LPMIXER_DATA MixerData
,
810 IN PKSMULTIPLE_ITEM NodeTypes
,
811 IN PKSMULTIPLE_ITEM NodeConnections
,
814 IN ULONG bInputMixer
)
816 LPMIXER_INFO MixerInfo
;
818 PKSPIN_PHYSICALCONNECTION OutConnection
;
824 LPWSTR Buffer
= NULL
;
826 // allocate a mixer info struct
827 MixerInfo
= (LPMIXER_INFO
) MixerContext
->Alloc(sizeof(MIXER_INFO
));
831 return MM_STATUS_NO_MEMORY
;
834 // intialize mixer caps */
835 MixerInfo
->MixCaps
.wMid
= MM_MICROSOFT
; //FIXME
836 MixerInfo
->MixCaps
.wPid
= MM_PID_UNMAPPED
; //FIXME
837 MixerInfo
->MixCaps
.vDriverVersion
= 1; //FIXME
838 MixerInfo
->MixCaps
.fdwSupport
= 0;
839 MixerInfo
->MixCaps
.cDestinations
= 1;
840 MixerInfo
->hMixer
= MixerData
->hDevice
;
843 MMixerGetDeviceName(MixerContext
, MixerInfo
, MixerData
->hDeviceInterfaceKey
);
845 // initialize line list
846 InitializeListHead(&MixerInfo
->LineList
);
848 // now allocate an array which will receive the indices of the pin
849 // which has a ADC / DAC nodetype in its path
850 Pins
= (PULONG
)MixerContext
->Alloc(PinCount
* sizeof(ULONG
));
855 MMixerFreeMixerInfo(MixerContext
, MixerInfo
);
856 return MM_STATUS_NO_MEMORY
;
859 // now get the target pins of the ADC / DAC node
860 Status
= MMixerGetTargetPins(MixerContext
, NodeTypes
, NodeConnections
, NodeIndex
, !bInputMixer
, Pins
, PinCount
);
862 for(Index
= 0; Index
< PinCount
; Index
++)
866 /* retrieve pin name */
869 Pin
.Property
.Flags
= KSPROPERTY_TYPE_GET
;
870 Pin
.Property
.Set
= KSPROPSETID_Pin
;
871 Pin
.Property
.Id
= KSPROPERTY_PIN_NAME
;
873 /* try get pin name size */
874 Status
= MixerContext
->Control(MixerData
->hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Pin
, sizeof(KSP_PIN
), NULL
, 0, &BytesReturned
);
876 if (Status
== MM_STATUS_MORE_ENTRIES
)
878 Buffer
= (LPWSTR
)MixerContext
->Alloc(BytesReturned
);
881 /* try get pin name */
882 Status
= MixerContext
->Control(MixerData
->hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Pin
, sizeof(KSP_PIN
), (PVOID
)Buffer
, BytesReturned
, &BytesReturned
);
883 if (Status
!= MM_STATUS_SUCCESS
)
885 MixerContext
->Free((PVOID
)Buffer
);
898 Status
= MMixerCreateDestinationLine(MixerContext
, MixerInfo
, bInputMixer
, Buffer
);
903 MixerContext
->Free(Buffer
);
906 if (Status
!= MM_STATUS_SUCCESS
)
908 // failed to create destination line
909 MixerContext
->Free(MixerInfo
);
910 MixerContext
->Free(Pins
);
915 RtlZeroMemory(Pins
, sizeof(ULONG
) * PinCount
);
916 // now get the target pins of the ADC / DAC node
917 Status
= MMixerGetTargetPins(MixerContext
, NodeTypes
, NodeConnections
, NodeIndex
, bInputMixer
, Pins
, PinCount
);
919 if (Status
!= MM_STATUS_SUCCESS
)
921 // failed to locate target pins
922 MixerContext
->Free(Pins
);
923 MMixerFreeMixerInfo(MixerContext
, MixerInfo
);
924 DPRINT("MMixerGetTargetPins failed with %u\n", Status
);
928 // filter hasnt been used
931 // now check all pins and generate new lines for destination lines
932 for(Index
= 0; Index
< PinCount
; Index
++)
934 DPRINT("Index %lu TargetPin %lu\n", Index
, Pins
[Index
]);
935 // is the current index a target pin
938 // check if the pin has a physical connection
939 Status
= MMixerGetPhysicalConnection(MixerContext
, MixerData
->hDevice
, Index
, &OutConnection
);
940 if (Status
== MM_STATUS_SUCCESS
)
942 // the pin has a physical connection
943 Status
= MMixerHandlePhysicalConnection(MixerContext
, MixerList
, MixerInfo
, bInputMixer
, OutConnection
);
944 DPRINT("MMixerHandlePhysicalConnection status %u\n", Status
);
945 MixerContext
->Free(OutConnection
);
950 // filter exposes the topology on the same filter
951 MMixerAddMixerSourceLine(MixerContext
, MixerInfo
, MixerData
->hDevice
, NodeConnections
, NodeTypes
, Index
, FALSE
, FALSE
);
956 MixerContext
->Free(Pins
);
960 // store mixer info in list
961 if (!bInputMixer
&& MixerList
->MixerListCount
== 1)
963 //FIXME preferred device should be inserted at front
964 //windows always inserts output mixer in front
965 InsertHeadList(&MixerList
->MixerList
, &MixerInfo
->Entry
);
969 InsertTailList(&MixerList
->MixerList
, &MixerInfo
->Entry
);
971 MixerList
->MixerListCount
++;
972 DPRINT("New MixerCount %lu\n", MixerList
->MixerListCount
);
976 // failed to create a mixer topology
977 MMixerFreeMixerInfo(MixerContext
, MixerInfo
);
986 IN PMIXER_CONTEXT MixerContext
,
987 IN PMIXER_LIST MixerList
,
988 IN LPMIXER_DATA MixerData
,
989 IN PULONG DeviceCount
)
991 PKSMULTIPLE_ITEM NodeTypes
, NodeConnections
;
996 // get number of pins
997 PinCount
= MMixerGetFilterPinCount(MixerContext
, MixerData
->hDevice
);
999 DPRINT("NumOfPins: %lu\n", PinCount
);
1001 // get filter node types
1002 Status
= MMixerGetFilterTopologyProperty(MixerContext
, MixerData
->hDevice
, KSPROPERTY_TOPOLOGY_NODES
, &NodeTypes
);
1003 if (Status
!= MM_STATUS_SUCCESS
)
1009 // get filter node connections
1010 Status
= MMixerGetFilterTopologyProperty(MixerContext
, MixerData
->hDevice
, KSPROPERTY_TOPOLOGY_CONNECTIONS
, &NodeConnections
);
1011 if (Status
!= MM_STATUS_SUCCESS
)
1014 MixerContext
->Free(NodeTypes
);
1018 // check if the filter has an wave out node
1019 NodeIndex
= MMixerGetIndexOfGuid(NodeTypes
, &KSNODETYPE_DAC
);
1020 if (NodeIndex
!= MAXULONG
)
1023 Status
= MMixerInitializeFilter(MixerContext
, MixerList
, MixerData
, NodeTypes
, NodeConnections
, PinCount
, NodeIndex
, FALSE
);
1024 DPRINT("MMixerInitializeFilter Status %u\n", Status
);
1025 // check for success
1026 if (Status
== MM_STATUS_SUCCESS
)
1028 // increment mixer count
1034 // check if the filter has an wave in node
1035 NodeIndex
= MMixerGetIndexOfGuid(NodeTypes
, &KSNODETYPE_ADC
);
1036 if (NodeIndex
!= MAXULONG
)
1039 Status
= MMixerInitializeFilter(MixerContext
, MixerList
, MixerData
, NodeTypes
, NodeConnections
, PinCount
, NodeIndex
, TRUE
);
1040 DPRINT("MMixerInitializeFilter Status %u\n", Status
);
1041 // check for success
1042 if (Status
== MM_STATUS_SUCCESS
)
1044 // increment mixer count
1051 MixerContext
->Free((PVOID
)NodeTypes
);
1052 MixerContext
->Free((PVOID
)NodeConnections
);